Skip to content

Commit

Permalink
Convert actual values with provided "convert" function too
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Dec 18, 2024
1 parent 8a4a7ad commit a303881
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ You can debug view charts locally with:
### **WORK IN PROGRESS**
-->
## Changelog
### **WORK IN PROGRESS**
* (bluefox) Convert actual values with provided "convert" function too

### 1.9.2 (2024-09-10)
* (bluefox) Fixed polar and bar charts

Expand Down
36 changes: 35 additions & 1 deletion src-chart/src/Components/ChartModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,41 @@ class ChartModel {
}

if (this.actualValues && this.actualValues[m] !== state.val) {
this.actualValues[m] = state.val;
// actual values must be converted too
let convertFunc;
if (this.config.l[m].convert) {
let convert = this.config.l[m].convert;
if (!convert.includes('return')) {
convert = `return ${convert}`;
}
try {
// eslint-disable-next-line no-new-func
convertFunc = new Function('val', convert);
} catch (e) {
console.error(`[ChartModel] Cannot parse convert function: ${e}`);
}
}

let value = state.val;

// Convert boolean values to numbers
if (value === 'true' || value === true) {
value = 1;
} else if (value === 'false' || value === false) {
value = 0;
} else if (typeof value === 'string') {
value = parseFloat(value);
}
if (this.config.l[m].chartType !== 'polar') {
let val;
if (convertFunc) {
val = value !== null ? convertFunc(value + this.config.l[m].yOffset) : null;
} else {
val = value !== null ? value + this.config.l[m].yOffset : null;
}
}

this.actualValues[m] = value;
changed = true;
}
break;
Expand Down

0 comments on commit a303881

Please sign in to comment.