mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Proper line and bar stacking order
Stacked line and bar charts now behave predictably with the first dataset on the bottom stacked upwards.
This commit is contained in:
parent
d31db87115
commit
ac5be9bde2
@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user