From f60344dfdb92d5759f99dc94f78475a68a3bcbac Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Thu, 28 Jul 2016 18:10:07 -0400 Subject: [PATCH] Fix line controller stacking with multiple axes and add a test --- src/controllers/controller.line.js | 2 +- test/controller.line.tests.js | 53 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 5fa91107a..54bbb2308 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -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; diff --git a/test/controller.line.tests.js b/test/controller.line.tests.js index 041705475..7f0f43903 100644 --- a/test/controller.line.tests.js +++ b/test/controller.line.tests.js @@ -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', -- 2.47.2