Skip to content

Commit

Permalink
Fix unneeded reverse loop, shorten cotroller.line
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed May 13, 2019
1 parent 74ff647 commit fab25e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/controllers/controller.line.js
Expand Up @@ -183,9 +183,10 @@ module.exports = DatasetController.extend({
var yScale = me._yScale;
var sumPos = 0;
var sumNeg = 0;
var rightValue = Number(yScale.getRightValue(value));
var metasets = chart._getSortedVisibleDatasetMetas();
var ilen = metasets.length;
var i, ds, dsMeta;
var i, ds, dsMeta, stackedRightValue;

if (yScale.options.stacked) {
for (i = 0; i < ilen; ++i) {
Expand All @@ -196,7 +197,7 @@ module.exports = DatasetController.extend({

ds = chart.data.datasets[dsMeta.index];
if (dsMeta.type === 'line' && dsMeta.yAxisID === yScale.id) {
var stackedRightValue = Number(yScale.getRightValue(ds.data[index]));
stackedRightValue = +yScale.getRightValue(ds.data[index]);
if (stackedRightValue < 0) {
sumNeg += stackedRightValue || 0;
} else {
Expand All @@ -205,14 +206,11 @@ module.exports = DatasetController.extend({
}
}

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

return yScale.getPixelForValue(value);
return yScale.getPixelForValue(sumPos + rightValue);
},

updateBezierControlPoints: function() {
Expand Down
2 changes: 1 addition & 1 deletion src/scales/scale.linear.js
Expand Up @@ -50,7 +50,7 @@ function stackData(scale, stacks, meta, data) {
var ilen = data.length;
var i, value;

for (i = ilen - 1; i >= 0; --i) {
for (i = 0; i < ilen; ++i) {
value = +scale.getRightValue(data[i]);
if (isNaN(value) || meta.data[i].hidden) {
continue;
Expand Down

0 comments on commit fab25e7

Please sign in to comment.