SUPPORT-9216: fix for parsing of local string formatted number value
This commit is contained in:
parent
fd9cfd69bf
commit
9933195a8e
4 changed files with 22 additions and 28 deletions
|
|
@ -262,19 +262,19 @@ export class ErvuChartV2 extends Control implements Filterable {
|
|||
}
|
||||
};
|
||||
|
||||
const tooltipLabelCallback: (label: string, value) => string
|
||||
const tooltipLabelCallback: (label: string, formattedValue: string, raw?: unknown) => string
|
||||
= this.dataTooltip
|
||||
? this.dataTooltip.provideTooltipLabelCallback()
|
||||
: ((label: string, value) => label + ' : ' + value);
|
||||
: ((label: string, formattedValue: string) => label + ' : ' + formattedValue);
|
||||
|
||||
chartOptions.plugins.tooltip.callbacks = {
|
||||
label: function (tooltipItem) {
|
||||
const dataset = tooltipItem.dataset;
|
||||
let label: string;
|
||||
let value;
|
||||
let raw: unknown;
|
||||
if (dataset.type == 'bar' || dataset.type == 'line') {
|
||||
label = dataset.label;
|
||||
value = dataset.data[tooltipItem.dataIndex].x.toLocaleString();
|
||||
raw = tooltipItem.raw.x;
|
||||
}
|
||||
else {
|
||||
const dataLabels = tooltipItem.chart.config.data.dataLabels;
|
||||
|
|
@ -282,9 +282,9 @@ export class ErvuChartV2 extends Control implements Filterable {
|
|||
label = dataLabels[tooltipItem.datasetIndex][tooltipItem.dataIndex];
|
||||
}
|
||||
label = label ? label : tooltipItem.label;
|
||||
value = dataset.data[tooltipItem.dataIndex].toLocaleString();
|
||||
raw = tooltipItem.raw;
|
||||
}
|
||||
return tooltipLabelCallback(label, value);
|
||||
return tooltipLabelCallback(label, tooltipItem.formattedValue, raw);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,21 +4,20 @@ import {TooltipCallbacksProvider} from "./TooltipCallbacksProvider";
|
|||
export class DigitDependentTooltipLabelProvider implements TooltipCallbacksProvider {
|
||||
public templates: DigitDependentLabelTemplate[] = [];
|
||||
|
||||
provideTooltipLabelCallback(): (label: string, value: string) => string {
|
||||
provideTooltipLabelCallback(): (label: string, formattedValue: string, raw: number) => string {
|
||||
const templates: DigitDependentLabelTemplate[] = this.templates;
|
||||
const excludedNumbers: number[] = [11, 12, 13, 14];
|
||||
|
||||
return function (label: string, value: string) {
|
||||
if (value) {
|
||||
return function (label: string, formattedValue: string, raw: number) {
|
||||
if (raw) {
|
||||
const template: DigitDependentLabelTemplate = templates
|
||||
.find(element => element.initialLabel === label);
|
||||
|
||||
if (template) {
|
||||
const number: number = Number.parseInt(value);
|
||||
const lastDigit = Math.abs(number) % 10;
|
||||
const lastTwoDigits = Math.abs(number) % 100;
|
||||
const lastDigit = Math.abs(raw) % 10;
|
||||
const lastTwoDigits = Math.abs(raw) % 100;
|
||||
|
||||
return value + " " + (excludedNumbers.includes(lastTwoDigits)
|
||||
return formattedValue + " " + (excludedNumbers.includes(lastTwoDigits)
|
||||
? template.otherDigitLabel
|
||||
: lastDigit == 1
|
||||
? template.oneDigitLabel
|
||||
|
|
@ -26,13 +25,8 @@ export class DigitDependentTooltipLabelProvider implements TooltipCallbacksProvi
|
|||
? template.fromTwoToFourDigitLabel
|
||||
: template.otherDigitLabel);
|
||||
}
|
||||
else {
|
||||
return value + " " + label;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return label;
|
||||
}
|
||||
return formattedValue ? formattedValue + " " + label : label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
export interface TooltipCallbacksProvider {
|
||||
provideTooltipLabelCallback(): (label: string, value: string) => string;
|
||||
provideTooltipLabelCallback(): (label: string, formattedValue: string, raw?: unknown) => string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {TooltipCallbacksProvider} from "./TooltipCallbacksProvider";
|
||||
|
||||
export class ValueBeforeDataTooltip implements TooltipCallbacksProvider {
|
||||
provideTooltipLabelCallback(): (label: string, value: string) => string {
|
||||
return (label: string, value: string) => value + " " + label;
|
||||
provideTooltipLabelCallback(): (label: string, formattedValue: string) => string {
|
||||
return (label: string, formattedValue: string) => formattedValue + " " + label;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue