Skip to content

Commit

Permalink
Fixed #18876, updating tooltip didn't work when wasn't declared.
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertkozik committed Apr 27, 2023
1 parent 85553ad commit 2f85184
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
16 changes: 9 additions & 7 deletions samples/unit-tests/tooltip/pointformat/demo.js
Expand Up @@ -11,23 +11,25 @@ QUnit.test('Repetetive formats', function (assert) {
width: 200,
height: 200
},
series: [{
data: [1.11]
}]
});

chart.update({
tooltip: {
headerFormat: '',
pointFormat: '{point.y} - {point.y}',
valuePrefix: 'NOK '
},
series: [
{
data: [1.11]
}
]
}
});

chart.series[0].points[0].onMouseOver();
assert.strictEqual(
chart.tooltip.label.text.element.textContent,
'NOK 1,11 - NOK 1,11',
'Formatting should be preserved when repeated (#8101)'
`Formatting should be preserved when repeated (#8101) and tooltip should
be updated (#18876).`
);

// Reset
Expand Down
52 changes: 32 additions & 20 deletions ts/Core/Series/Series.ts
Expand Up @@ -830,7 +830,8 @@ class Series {
const typeOptions = (e.plotOptions as any)[this.type],
userPlotOptions = (
userOptions.plotOptions || {} as SeriesTypePlotOptions
);
),
typeUserPlotOptions = userPlotOptions && userPlotOptions[this.type];

// use copy to prevent undetected changes (#9762)
/**
Expand All @@ -841,14 +842,16 @@ class Series {
this.userOptions = e.userOptions;

const options: SeriesTypeOptions = merge(
typeOptions,
(plotOptions as any).series,
// #3881, chart instance plotOptions[type] should trump
// plotOptions.series
userOptions.plotOptions &&
(userOptions.plotOptions as any)[this.type],
seriesUserOptions
);
typeOptions,
plotOptions && plotOptions.series,
// #3881, chart instance plotOptions[type] should trump
// plotOptions.series
typeUserPlotOptions,
seriesUserOptions
),
defaultTypePlotOptions = defaultOptions.plotOptions &&
defaultOptions.plotOptions[this.type],
typePlotOptions = plotOptions && plotOptions[this.type];

// The tooltip options are merged between global and series specific
// options. Importance order asscendingly:
Expand All @@ -858,22 +861,31 @@ class Series {
// (7)this series options
this.tooltipOptions = merge(
defaultOptions.tooltip, // 1
(defaultOptions.plotOptions as any).series &&
(defaultOptions.plotOptions as any).series.tooltip, // 2
(defaultOptions.plotOptions as any)[this.type].tooltip, // 3
(chartOptions.tooltip as any).userOptions, // 4
(plotOptions as any).series &&
(plotOptions as any).series.tooltip, // 5
(plotOptions as any)[this.type].tooltip, // 6
(seriesUserOptions.tooltip as any) // 7
) as any;
(
defaultOptions.plotOptions &&
defaultOptions.plotOptions.series &&
defaultOptions.plotOptions.series.tooltip
), // 2
defaultTypePlotOptions && defaultTypePlotOptions.tooltip, // 3
(
defaultOptions.tooltip &&
chartOptions.tooltip &&
cleanRecursively(chartOptions.tooltip, defaultOptions.tooltip)
), // 4 - #18876 take only "userOptions" (calculate them)
(
plotOptions &&
plotOptions.series &&
plotOptions.series.tooltip
), // 5
typePlotOptions && typePlotOptions.tooltip, // 6
seriesUserOptions.tooltip // 7
);

// When shared tooltip, stickyTracking is true by default,
// unless user says otherwise.
this.stickyTracking = pick(
seriesUserOptions.stickyTracking,
(userPlotOptions as any)[this.type] &&
(userPlotOptions as any)[this.type].stickyTracking,
typeUserPlotOptions && typeUserPlotOptions.stickyTracking,
userPlotOptions.series && userPlotOptions.series.stickyTracking,
(
this.tooltipOptions.shared && !this.noSharedTooltip ?
Expand Down
2 changes: 0 additions & 2 deletions ts/Core/Tooltip.ts
Expand Up @@ -1739,8 +1739,6 @@ class Tooltip {
*/
public update(options: TooltipOptions): void {
this.destroy();
// Update user options (#6218)
merge(true, (this.chart.options.tooltip as any).userOptions, options);
this.init(this.chart, merge(true, this.options, options));
}

Expand Down

0 comments on commit 2f85184

Please sign in to comment.