Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/controllers/controller.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this affect stacked area charts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the datasets are now being passed into the core.controller updater function in reversed order (this ensures the datasets are drawn on top of each other instead of behind each other). The change here is just compensating for that reversal by traversing down dataset values, instead of up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! You're good to merge then

var ds = this.chart.data.datasets[i];
if (ds.type === 'line' && helpers.isDatasetVisible(ds)) {
if (ds.data[index] < 0) {
Expand Down Expand Up @@ -287,4 +287,4 @@ module.exports = function(Chart) {
point._model.borderWidth = this.getPointBorderWidth(point, index);
}
});
};
};
4 changes: 2 additions & 2 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -557,4 +557,4 @@ module.exports = function(Chart) {
return this;
}
});
};
};
6 changes: 5 additions & 1 deletion src/core/core.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function(Chart) {
display: true,
position: 'top',
fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
reverse: false,

// a callback that will handle
onClick: function(e, legendItem) {
Expand Down Expand Up @@ -143,6 +144,9 @@ module.exports = function(Chart) {
beforeBuildLabels: helpers.noop,
buildLabels: function() {
this.legendItems = this.options.labels.generateLabels.call(this, this.chart.data);
if(this.options.reverse){
this.legendItems.reverse();
}
},
afterBuildLabels: helpers.noop,

Expand Down Expand Up @@ -321,4 +325,4 @@ module.exports = function(Chart) {
}
});

};
};
6 changes: 3 additions & 3 deletions src/core/core.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ module.exports = function(Chart) {
datasetIndex: datasetIndex
});
}
});
}, null, element._yScale.options.stacked);

helpers.each(this._active, function(active) {
if (active) {
Expand All @@ -262,7 +262,7 @@ module.exports = function(Chart) {
backgroundColor: active._view.backgroundColor
});
}
});
}, null, element._yScale.options.stacked);

tooltipPosition = this.getAveragePosition(this._active);
tooltipPosition.y = this._active[0]._yScale.getPixelForDecimal(0.5);
Expand Down Expand Up @@ -609,4 +609,4 @@ module.exports = function(Chart) {
}
}
});
};
};
32 changes: 30 additions & 2 deletions test/controller.line.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion test/core.legend.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Legend block tests', function() {
display: true,
position: 'top',
fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
reverse: false,

// a callback that will handle
onClick: jasmine.any(Function),
Expand Down Expand Up @@ -305,4 +306,4 @@ describe('Legend block tests', function() {
"args": ["dataset3", 228, 132]
}]);
});
});
});