]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Proper line and bar stacking order
authorTanner Linsley <tannerlinsley@gmail.com>
Wed, 17 Feb 2016 19:41:32 +0000 (12:41 -0700)
committerTanner Linsley <tannerlinsley@gmail.com>
Wed, 17 Feb 2016 19:41:32 +0000 (12:41 -0700)
Stacked line and bar charts now behave predictably with the first
dataset on the bottom stacked upwards.

src/controllers/controller.line.js
src/core/core.controller.js
test/controller.line.tests.js

index 381224c031e7db3fafd0f479386e9255abf7e17c..dcce78f995eafacc642694edb03d18af010b1b22 100644 (file)
@@ -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
+};
index b1dc8351b26edff7b6b1a8a00634db1595da6823..fc5bbdedc5c900491de90cd08ce62a5b91a78a86 100644 (file)
@@ -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
+};
index 40c7c2bb0534cdcc34f59bda670226cb5813af8a..0b8cc79218d783ba13c2026c7708c6b0034807eb 100644 (file)
@@ -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() {