diff --git a/samples/unit-tests/tooltip/pointformat/demo.js b/samples/unit-tests/tooltip/pointformat/demo.js index 2f1b57d0478..c01be9fa901 100644 --- a/samples/unit-tests/tooltip/pointformat/demo.js +++ b/samples/unit-tests/tooltip/pointformat/demo.js @@ -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 diff --git a/ts/Core/Series/Series.ts b/ts/Core/Series/Series.ts index aaf802c02eb..d300a54cb24 100644 --- a/ts/Core/Series/Series.ts +++ b/ts/Core/Series/Series.ts @@ -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) /** @@ -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: @@ -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 ? diff --git a/ts/Core/Tooltip.ts b/ts/Core/Tooltip.ts index 9eca162b982..aa883f0defb 100644 --- a/ts/Core/Tooltip.ts +++ b/ts/Core/Tooltip.ts @@ -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)); }