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
|
||||||
? this.dataTooltip.provideTooltipLabelCallback()
|
? this.dataTooltip.provideTooltipLabelCallback()
|
||||||
: ((label: string, value) => label + ' : ' + value);
|
: ((label: string, formattedValue: string) => label + ' : ' + formattedValue);
|
||||||
|
|
||||||
chartOptions.plugins.tooltip.callbacks = {
|
chartOptions.plugins.tooltip.callbacks = {
|
||||||
label: function (tooltipItem) {
|
label: function (tooltipItem) {
|
||||||
const dataset = tooltipItem.dataset;
|
const dataset = tooltipItem.dataset;
|
||||||
let label: string;
|
let label: string;
|
||||||
let value;
|
let raw: unknown;
|
||||||
if (dataset.type == 'bar' || dataset.type == 'line') {
|
if (dataset.type == 'bar' || dataset.type == 'line') {
|
||||||
label = dataset.label;
|
label = dataset.label;
|
||||||
value = dataset.data[tooltipItem.dataIndex].x.toLocaleString();
|
raw = tooltipItem.raw.x;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const dataLabels = tooltipItem.chart.config.data.dataLabels;
|
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 = dataLabels[tooltipItem.datasetIndex][tooltipItem.dataIndex];
|
||||||
}
|
}
|
||||||
label = label ? label : tooltipItem.label;
|
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,35 +4,29 @@ import {TooltipCallbacksProvider} from "./TooltipCallbacksProvider";
|
||||||
export class DigitDependentTooltipLabelProvider implements TooltipCallbacksProvider {
|
export class DigitDependentTooltipLabelProvider implements TooltipCallbacksProvider {
|
||||||
public templates: DigitDependentLabelTemplate[] = [];
|
public templates: DigitDependentLabelTemplate[] = [];
|
||||||
|
|
||||||
provideTooltipLabelCallback(): (label: string, value: string) => string {
|
provideTooltipLabelCallback(): (label: string, formattedValue: string, raw: number) => string {
|
||||||
const templates: DigitDependentLabelTemplate[] = this.templates;
|
const templates: DigitDependentLabelTemplate[] = this.templates;
|
||||||
const excludedNumbers: number[] = [11, 12, 13, 14];
|
const excludedNumbers: number[] = [11, 12, 13, 14];
|
||||||
|
|
||||||
return function (label: string, value: string) {
|
return function (label: string, formattedValue: string, raw: number) {
|
||||||
if (value) {
|
if (raw) {
|
||||||
const template: DigitDependentLabelTemplate = templates
|
const template: DigitDependentLabelTemplate = templates
|
||||||
.find(element => element.initialLabel === label);
|
.find(element => element.initialLabel === label);
|
||||||
|
|
||||||
if (template) {
|
if (template) {
|
||||||
const number: number = Number.parseInt(value);
|
const lastDigit = Math.abs(raw) % 10;
|
||||||
const lastDigit = Math.abs(number) % 10;
|
const lastTwoDigits = Math.abs(raw) % 100;
|
||||||
const lastTwoDigits = Math.abs(number) % 100;
|
|
||||||
|
|
||||||
return value + " " + (excludedNumbers.includes(lastTwoDigits)
|
return formattedValue + " " + (excludedNumbers.includes(lastTwoDigits)
|
||||||
? template.otherDigitLabel
|
? template.otherDigitLabel
|
||||||
: lastDigit == 1
|
: lastDigit == 1
|
||||||
? template.oneDigitLabel
|
? template.oneDigitLabel
|
||||||
: lastDigit > 1 && lastDigit < 5
|
: lastDigit > 1 && lastDigit < 5
|
||||||
? template.fromTwoToFourDigitLabel
|
? template.fromTwoToFourDigitLabel
|
||||||
: template.otherDigitLabel);
|
: template.otherDigitLabel);
|
||||||
}
|
|
||||||
else {
|
|
||||||
return value + " " + label;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
return formattedValue ? formattedValue + " " + label : label;
|
||||||
return label;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
export interface TooltipCallbacksProvider {
|
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";
|
import {TooltipCallbacksProvider} from "./TooltipCallbacksProvider";
|
||||||
|
|
||||||
export class ValueBeforeDataTooltip implements TooltipCallbacksProvider {
|
export class ValueBeforeDataTooltip implements TooltipCallbacksProvider {
|
||||||
provideTooltipLabelCallback(): (label: string, value: string) => string {
|
provideTooltipLabelCallback(): (label: string, formattedValue: string) => string {
|
||||||
return (label: string, value: string) => value + " " + label;
|
return (label: string, formattedValue: string) => formattedValue + " " + label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue