]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix line controller stacking with multiple axes and add a test 3052/head
authorEvert Timberg <evert.timberg+github@gmail.com>
Thu, 28 Jul 2016 22:10:07 +0000 (18:10 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Thu, 28 Jul 2016 22:10:07 +0000 (18:10 -0400)
src/controllers/controller.line.js
test/controller.line.tests.js

index 5fa91107a935fd6af65b92540c33feaa691915d3..54bbb2308fc56289d9e9dfd7158cabb3385049df 100644 (file)
@@ -222,7 +222,7 @@ module.exports = function(Chart) {
                                for (i = 0; i < datasetIndex; i++) {
                                        ds = chart.data.datasets[i];
                                        dsMeta = chart.getDatasetMeta(i);
-                                       if (dsMeta.type === 'line' && chart.isDatasetVisible(i)) {
+                                       if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id && chart.isDatasetVisible(i)) {
                                                var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
                                                if (stackedRightValue < 0) {
                                                        sumNeg += stackedRightValue || 0;
index 0417054758e1b965bc25bd18f4b29bcbee819071..7f0f439033af843d078a7295761db72772bb8091 100644 (file)
@@ -278,6 +278,59 @@ describe('Line controller tests', function() {
                
        });
 
+       it('should update elements when the y scale is stacked with multiple axes', function() {
+               var chart = window.acquireChart({
+                       type: 'line',
+                       data: {
+                               datasets: [{
+                                       data: [10, -10, 10, -10],
+                                       label: 'dataset1'
+                               }, {
+                                       data: [10, 15, 0, -4],
+                                       label: 'dataset2'
+                               }, {
+                                       data: [10, 10, -10, -10],
+                                       label: 'dataset3',
+                                       yAxisID: 'secondAxis'
+                               }],
+                               labels: ['label1', 'label2', 'label3', 'label4']
+                       },
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               stacked: true
+                                       }, {
+                                               type: 'linear',
+                                               id: 'secondAxis'
+                                       }]
+                               }
+                       }
+               });
+               
+               var meta0 = chart.getDatasetMeta(0);
+
+               [       { x:  76, y: 161 },
+                       { x: 215, y: 419 },
+                       { x: 353, y: 161 },
+                       { x: 492, y: 419 }
+               ].forEach(function(values, i) {
+                               expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
+                               expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
+               });
+
+               var meta1 = chart.getDatasetMeta(1);
+
+               [       { x:  76, y:  32 },
+                       { x: 215, y:  97 },
+                       { x: 353, y: 161 },
+                       { x: 492, y: 471 }
+               ].forEach(function(values, i) {
+                               expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
+                               expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
+               });
+               
+       });
+
        it('should update elements when the y scale is stacked and datasets is scatter data', function() {
                var chart = window.acquireChart({
                        type: 'line',