Skip to content

Commit

Permalink
Added feature to let Series.update fall back to Series.setData if onl…
Browse files Browse the repository at this point in the history
…y the data is updated.
  • Loading branch information
TorsteinHonsi committed May 9, 2017
1 parent b7e1a42 commit 3a2a4d2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions js/parts/Dynamics.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ extend(Series.prototype, /** @lends Series.prototype */ {
preserve = ['group', 'markerGroup', 'dataLabelsGroup'],
n;

// Running Series.update to update the data only is an intuitive usage,
// so we want to make sure that when used like this, we run the
// cheaper setData function and allow animation instead of completely
// recreating the series instance.
if (Object.keys && Object.keys(newOptions).toString() === 'data') {
return this.setData(newOptions.data, redraw);
}

// If we're changing type or zIndex, create new groups (#3380, #3404)
if ((newType && newType !== oldType) || newOptions.zIndex !== undefined) {
preserve.length = 0;
Expand Down
33 changes: 33 additions & 0 deletions samples/unit-tests/series/update/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,36 @@ QUnit.test(

}
);

QUnit.test(
'Series.update with only data should redirect to setData',
function (assert) {
var chart = Highcharts.chart('container', {

xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},

series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5,
216.4, 194.1, 95.6, 54.4],
type: 'column'
}]

});

chart.series[0].points[0].kilroyWasHere = true;

chart.series[0].update({
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5,
216.4, 194.1, 95.6, 54.4].slice(0).reverse()
});

assert.strictEqual(
chart.series[0].points[0].kilroyWasHere,
true,
'Original point item is preserved'
);
}
);

0 comments on commit 3a2a4d2

Please sign in to comment.