Fixed locale issues for balance chart tooltip and x-axis labels
This commit is contained in:
parent
955169112d
commit
338e6f5fa9
|
@ -11569,7 +11569,6 @@ var Scale = core_element.extend({
|
|||
// Generate labels using all non-skipped ticks
|
||||
labels = me._convertTicksToLabels(me._ticksToDraw);
|
||||
}
|
||||
|
||||
me.ticks = labels; // BACKWARD COMPATIBILITY
|
||||
|
||||
// IMPORTANT: after this point, we consider that `this.ticks` will NEVER change!
|
||||
|
@ -13052,7 +13051,12 @@ var scale_linear = scale_linearbase.extend({
|
|||
},
|
||||
|
||||
getLabelForIndex: function(index, datasetIndex) {
|
||||
return this._getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]);
|
||||
var scaleLabel = this._getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]);
|
||||
var optionsTooltips = this.chart.options.tooltips;
|
||||
if (optionsTooltips && optionsTooltips.format && optionsTooltips.format.enabled && optionsTooltips.format.valueCallback) {
|
||||
return optionsTooltips.format.valueCallback(scaleLabel);
|
||||
}
|
||||
return scaleLabel;
|
||||
},
|
||||
|
||||
// Utils
|
||||
|
@ -14566,6 +14570,11 @@ var scale_time = core_scale.extend({
|
|||
if (typeof label === 'string') {
|
||||
return label;
|
||||
}
|
||||
var tooltipsFormat = me.chart.options.tooltips.format;
|
||||
if (tooltipsFormat && tooltipsFormat.enabled && tooltipsFormat.callback) {
|
||||
return tooltipsFormat.callback(label)
|
||||
}
|
||||
|
||||
return adapter.format(toTimestamp(me, label), timeOpts.displayFormats.datetime);
|
||||
},
|
||||
|
||||
|
@ -14584,7 +14593,13 @@ var scale_time = core_scale.extend({
|
|||
var tick = ticks[index];
|
||||
var tickOpts = options.ticks;
|
||||
var major = majorUnit && majorFormat && tick && tick.major;
|
||||
var label = adapter.format(time, format ? format : major ? majorFormat : minorFormat);
|
||||
var labelFormat = me.chart.options.scales.labelFormat;
|
||||
var label;
|
||||
if (labelFormat && labelFormat.enabled && labelFormat.callback)
|
||||
label = labelFormat.callback(time);
|
||||
else
|
||||
label = adapter.format(time, format ? format : major ? majorFormat : minorFormat);
|
||||
|
||||
var nestedTickOpts = major ? tickOpts.major : tickOpts.minor;
|
||||
var formatter = resolve$5([
|
||||
nestedTickOpts.callback,
|
||||
|
|
|
@ -132,6 +132,13 @@ Item {
|
|||
|
||||
chart.animateToNewData()
|
||||
}
|
||||
|
||||
readonly property var dateToShortLabel: function (value) {
|
||||
const range = balanceStore.timeRangeStrToEnum(graphDetail.selectedTimeRange)
|
||||
return range === ChartStoreBase.TimeRange.Weekly || range === ChartStoreBase.TimeRange.Monthly ?
|
||||
LocaleUtils.getDayMonth(value) :
|
||||
LocaleUtils.getMonthYear(value)
|
||||
}
|
||||
chart.chartType: 'line'
|
||||
chart.chartData: {
|
||||
return {
|
||||
|
@ -170,6 +177,15 @@ Item {
|
|||
//},
|
||||
//pan:{enabled:true,mode:'x'},
|
||||
tooltips: {
|
||||
format: {
|
||||
enabled: graphDetail.selectedGraphType === AssetsDetailView.GraphType.Balance,
|
||||
callback: function (value) {
|
||||
return graphDetail.dateToShortLabel(value)
|
||||
},
|
||||
valueCallback: function(value) {
|
||||
return LocaleUtils.currencyAmountToLocaleString({ amount: value, symbol: RootStore.currencyStore.currentCurrencySymbol, displayDecimals: 2 })
|
||||
}
|
||||
},
|
||||
intersect: false,
|
||||
displayColors: false,
|
||||
callbacks: {
|
||||
|
@ -179,12 +195,21 @@ Item {
|
|||
label += ': ';
|
||||
}
|
||||
|
||||
const value = LocaleUtils.currencyAmountToLocaleString({ amount: tooltipItem.yLabel.toFixed(2), symbol: RootStore.currencyStore.currentCurrencySymbol })
|
||||
if (graphDetail.selectedGraphType === AssetsDetailView.GraphType.Balance)
|
||||
return label + tooltipItem.yLabel // already formatted in tooltips.value.callback
|
||||
|
||||
const value = LocaleUtils.currencyAmountToLocaleString({ amount: tooltipItem.yLabel, symbol: RootStore.currencyStore.currentCurrencySymbol, displayDecimals: 2 })
|
||||
return label + value
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
labelFormat: {
|
||||
callback: function (value) {
|
||||
return graphDetail.dateToShortLabel(value)
|
||||
},
|
||||
enabled: graphDetail.selectedGraphType === AssetsDetailView.GraphType.Balance,
|
||||
},
|
||||
xAxes: [{
|
||||
id: 'x-axis-1',
|
||||
position: 'bottom',
|
||||
|
|
Loading…
Reference in New Issue