Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #185 from flant/fix_discrete_mode_regression
Browse files Browse the repository at this point in the history
fix: use == operator instead of strict equal
  • Loading branch information
diafour committed Feb 18, 2021
2 parents 8c28d33 + 6372ddf commit e9e36d7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/color_mode_discrete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ColorModeDiscrete {

for (let i = 0; i < thresholds.length; i++) {
for (let j = 0; j < values.length; j++) {
if (values[j] === thresholds[i].value) {
if (this.isEqualValues(values[j], thresholds[i].value)) {
tooltips.push({
tooltip: thresholds[i].tooltip ? thresholds[i].tooltip : values[j],
color: thresholds[i].color,
Expand All @@ -43,18 +43,16 @@ export class ColorModeDiscrete {
return tooltips;
}

convertValueToTooltips(values) {
convertValueToTooltips(value) {
let thresholds = this.panel.color.thresholds;
let tooltips = [];

for (let i = 0; i < thresholds.length; i++) {
//for (let j = 0; j < values.length; j++) {
if (values === thresholds[i].value) {
if (this.isEqualValues(value, thresholds[i].value)) {
tooltips.push({
tooltip: thresholds[i].tooltip ? thresholds[i].tooltip : values,
tooltip: thresholds[i].tooltip ? thresholds[i].tooltip : value,
color: thresholds[i].color,
});
//}
}
}
return tooltips;
Expand Down Expand Up @@ -135,7 +133,7 @@ export class ColorModeDiscrete {

for (let i = 0; i < thresholds.length; i++) {
for (let j = 0; j < values.length; j++) {
if (values[j] === thresholds[i].value) {
if (this.isEqualValues(values[j], thresholds[i].value)) {
return this.getDiscreteColor(i);
}
}
Expand Down Expand Up @@ -199,7 +197,7 @@ export class ColorModeDiscrete {

let thresholds = this.panel.color.thresholds;
for (let k = 0; k < thresholds.length; k++) {
if (value === thresholds[k].value) {
if (this.isEqualValues(value, thresholds[k].value)) {
return thresholds[k];
}
}
Expand All @@ -218,6 +216,13 @@ export class ColorModeDiscrete {
return thresholds[index];
}

isEqualValues(val1, val2) {
// Relaxed equal operator here is important.
// threshold.value can be a number or a string and input value can be a number or a string.
/* eslint-disable eqeqeq */
return val1 == val2;
}

roundIntervalCeil(interval) {
switch (true) {
case interval <= 10:
Expand Down

0 comments on commit e9e36d7

Please sign in to comment.