Skip to content

Commit

Permalink
Fixed #6218, some tooltip options were not updated through chart.upda…
Browse files Browse the repository at this point in the history
…te().
  • Loading branch information
Kacper Madej authored and TorsteinHonsi committed Apr 18, 2017
1 parent a856aeb commit 83d6587
Show file tree
Hide file tree
Showing 9 changed files with 468 additions and 107 deletions.
19 changes: 18 additions & 1 deletion js/parts/Chart.js
Expand Up @@ -90,10 +90,27 @@ Chart.prototype = {

// Handle regular options
var options,
seriesOptions = userOptions.series; // skip merging data points to increase performance
type,
seriesOptions = userOptions.series, // skip merging data points to increase performance
userPlotOptions = userOptions.plotOptions || {};

userOptions.series = null;
options = merge(defaultOptions, userOptions); // do the merge

// Override (by copy of user options) or clear tooltip options
// in chart.options.plotOptions (#6218)
for (type in options.plotOptions) {
options.plotOptions[type].tooltip = (
userPlotOptions[type] &&
merge(userPlotOptions[type].tooltip) // override by copy
) || undefined; // or clear
}
// User options have higher priority than default options (#6218).
// In case of exporting: path is changed
options.tooltip.userOptions = (userOptions.chart &&
userOptions.chart.forExport && userOptions.tooltip.userOptions) ||
userOptions.tooltip;

options.series = userOptions.series = seriesOptions; // set back the series data
this.userOptions = userOptions;

Expand Down
24 changes: 13 additions & 11 deletions js/parts/Dynamics.js
Expand Up @@ -191,7 +191,8 @@ extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ {
* extended from plugins.
*/
propsRequireUpdateSeries: ['chart.inverted', 'chart.polar',
'chart.ignoreHiddenSeries', 'chart.type', 'colors', 'plotOptions'],
'chart.ignoreHiddenSeries', 'chart.type', 'colors', 'plotOptions',
'tooltip'],

/**
* Chart.update function that takes the whole options stucture.
Expand Down Expand Up @@ -248,6 +249,17 @@ extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ {
}
/*= } =*/
}

// Moved up, because tooltip needs updated plotOptions (#6218)
/*= if (build.classic) { =*/
if (options.colors) {
this.options.colors = options.colors;
}
/*= } =*/

if (options.plotOptions) {
merge(true, this.options.plotOptions, options.plotOptions);
}

// Some option stuctures correspond one-to-one to chart objects that have
// update methods, for example
Expand All @@ -273,16 +285,6 @@ extend(Chart.prototype, /** @lends Highcharts.Chart.prototype */ {
}
}

/*= if (build.classic) { =*/
if (options.colors) {
this.options.colors = options.colors;
}
/*= } =*/

if (options.plotOptions) {
merge(true, this.options.plotOptions, options.plotOptions);
}

// Setters for collections. For axes and series, each item is referred
// by an id. If the id is not found, it defaults to the corresponding
// item in the collection, so setting one series without an id, will
Expand Down
22 changes: 14 additions & 8 deletions js/parts/Series.js
Expand Up @@ -405,16 +405,22 @@ H.Series = H.seriesType('line', null, { // base series options
itemOptions
);

// The tooltip options are merged between global and series specific options
// The tooltip options are merged between global and series specific
// options. Importance order asscendingly:
// globals: (1)tooltip, (2)plotOptions.series, (3)plotOptions[this.type]
// init userOptions with possible later updates: 4-6 like 1-3 and
// (7)this series options
this.tooltipOptions = merge(
defaultOptions.tooltip,
defaultOptions.plotOptions[this.type].tooltip,
userOptions.tooltip,
userPlotOptions.series && userPlotOptions.series.tooltip,
userPlotOptions[this.type] && userPlotOptions[this.type].tooltip,
itemOptions.tooltip
defaultOptions.tooltip, // 1
defaultOptions.plotOptions.series &&
defaultOptions.plotOptions.series.tooltip, // 2
defaultOptions.plotOptions[this.type].tooltip, // 3
chartOptions.tooltip.userOptions, // 4
plotOptions.series && plotOptions.series.tooltip, // 5
plotOptions[this.type].tooltip, // 6
itemOptions.tooltip // 7
);

// When shared tooltip, stickyTracking is true by default,
// unless user says otherwise.
this.stickyTracking = pick(
Expand Down
2 changes: 2 additions & 0 deletions js/parts/Tooltip.js
Expand Up @@ -181,6 +181,8 @@ H.Tooltip.prototype = {

update: function (options) {
this.destroy();
// Update user options (#6218)
merge(true, this.chart.options.tooltip.userOptions, options);
this.init(this.chart, merge(true, this.options, options));
},

Expand Down
4 changes: 3 additions & 1 deletion samples/unit-tests/axis/category/demo.js
Expand Up @@ -542,7 +542,9 @@ QUnit.test(
}],

plotOptions: {
animation: false
series: {
animation: false
}
},

series: [{
Expand Down
6 changes: 6 additions & 0 deletions samples/unit-tests/tooltip/options-order/demo.details
@@ -0,0 +1,6 @@
---
resources:
- https://code.jquery.com/qunit/qunit-2.0.1.js
- https://code.jquery.com/qunit/qunit-2.0.1.css
js_wrap: b
...
6 changes: 6 additions & 0 deletions samples/unit-tests/tooltip/options-order/demo.html
@@ -0,0 +1,6 @@
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="qunit"></div>
<div id="qunit-fixture"></div>

<div id="container"></div>

0 comments on commit 83d6587

Please sign in to comment.