From: Tanner Linsley Date: Wed, 17 Feb 2016 19:41:32 +0000 (-0700) Subject: Proper line and bar stacking order X-Git-Tag: v2.0.0~37^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac5be9bde20aa148eab929b2f356834150dec447;p=thirdparty%2FChart.js.git Proper line and bar stacking order Stacked line and bar charts now behave predictably with the first dataset on the bottom stacked upwards. --- diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 381224c03..dcce78f99 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -205,7 +205,7 @@ module.exports = function(Chart) { var sumPos = 0, sumNeg = 0; - for (var i = this.chart.data.datasets.length - 1; i > datasetIndex; i--) { + for (var i = 0; i < datasetIndex; i++) { var ds = this.chart.data.datasets[i]; if (ds.type === 'line' && helpers.isDatasetVisible(ds)) { if (ds.data[index] < 0) { @@ -287,4 +287,4 @@ module.exports = function(Chart) { point._model.borderWidth = this.getPointBorderWidth(point, index); } }); -}; \ No newline at end of file +}; diff --git a/src/core/core.controller.js b/src/core/core.controller.js index b1dc8351b..fc5bbdedc 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -314,7 +314,7 @@ module.exports = function(Chart) { if (helpers.isDatasetVisible(dataset)) { dataset.controller.draw(ease); } - }); + }, null, true); // Finally draw the tooltip this.tooltip.transition(easingDecimal).draw(); @@ -557,4 +557,4 @@ module.exports = function(Chart) { return this; } }); -}; \ No newline at end of file +}; diff --git a/test/controller.line.tests.js b/test/controller.line.tests.js index 40c7c2bb0..0b8cc7921 100644 --- a/test/controller.line.tests.js +++ b/test/controller.line.tests.js @@ -655,7 +655,9 @@ describe('Line controller tests', function() { }; var controller = new Chart.controllers.line(chart, 0); + var controller2 = new Chart.controllers.line(chart, 1); controller.update(); + controller2.update(); // Line element expect(chart.data.datasets[0].metaDataset._model).toEqual(jasmine.objectContaining({ @@ -667,13 +669,13 @@ describe('Line controller tests', function() { expect(chart.data.datasets[0].metaData[0]._model).toEqual(jasmine.objectContaining({ // Point x: 91, - y: 30, + y: 77, })); expect(chart.data.datasets[0].metaData[1]._model).toEqual(jasmine.objectContaining({ // Point x: 141, - y: 18, + y: 65, })); expect(chart.data.datasets[0].metaData[2]._model).toEqual(jasmine.objectContaining({ @@ -683,10 +685,36 @@ describe('Line controller tests', function() { })); expect(chart.data.datasets[0].metaData[3]._model).toEqual(jasmine.objectContaining({ + // Point + x: 242, + y: 109, + })); + + expect(chart.data.datasets[1].metaData[0]._model).toEqual(jasmine.objectContaining({ + // Point + x: 91, + y: 30, + })); + + expect(chart.data.datasets[1].metaData[1]._model).toEqual(jasmine.objectContaining({ + // Point + x: 141, + y: 18, + })); + + expect(chart.data.datasets[1].metaData[2]._model).toEqual(jasmine.objectContaining({ + // Point + x: 192, + y: 30, + })); + + expect(chart.data.datasets[1].metaData[3]._model).toEqual(jasmine.objectContaining({ // Point x: 242, y: 180, })); + + }); it('should find the correct scale zero when the data is all positive', function() {