Skip to content

Commit

Permalink
Merge remote-tracking branch 'chartjs-origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
slinhart committed Jul 6, 2016
2 parents df7582a + c6e28f2 commit ff2a2bf
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/controllers/controller.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,20 @@ module.exports = function(Chart) {
ds = chart.data.datasets[i];
dsMeta = chart.getDatasetMeta(i);
if (dsMeta.type === 'line' && chart.isDatasetVisible(i)) {
if (ds.data[index] < 0) {
sumNeg += ds.data[index] || 0;
var stackedRightValue = yScale.getRightValue(ds.data[index]);
if (stackedRightValue < 0) {
sumNeg += stackedRightValue || 0;
} else {
sumPos += ds.data[index] || 0;
sumPos += stackedRightValue || 0;
}
}
}

if (value < 0) {
return yScale.getPixelForValue(sumNeg + value);
var rightValue = yScale.getRightValue(value);
if (rightValue < 0) {
return yScale.getPixelForValue(sumNeg + rightValue);
} else {
return yScale.getPixelForValue(sumPos + value);
return yScale.getPixelForValue(sumPos + rightValue);
}
}

Expand Down
70 changes: 70 additions & 0 deletions test/controller.line.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,76 @@ describe('Line controller tests', function() {

});

it('should update elements when the y scale is stacked and datasets is scatter data', function() {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [{
x: 0,
y: 10
}, {
x: 1,
y: -10
}, {
x: 2,
y: 10
}, {
x: 3,
y: -10
}],
label: 'dataset1'
}, {
data: [{
x: 0,
y: 10
}, {
x: 1,
y: 15
}, {
x: 2,
y: 0
}, {
x: 3,
y: -4
}],
label: 'dataset2'
}],
labels: ['label1', 'label2', 'label3', 'label4']
},
options: {
scales: {
yAxes: [{
stacked: true
}]
}
}
});

var meta0 = chart.getDatasetMeta(0);

[ { x: 38, y: 161 },
{ x: 189, y: 419 },
{ x: 341, 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: 38, y: 32 },
{ x: 189, y: 97 },
{ x: 341, 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 find the correct scale zero when the data is all positive', function() {
var chart = window.acquireChart({
type: 'line',
Expand Down

0 comments on commit ff2a2bf

Please sign in to comment.