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 21, 2019
1 parent c8fc08a commit 92b0476
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/controllers/controller.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ module.exports = DatasetController.extend({
var yScale = me._yScale;
var sumPos = 0;
var sumNeg = 0;
var rightValue = +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
3 changes: 1 addition & 2 deletions src/scales/scale.linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ 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 = this._parseValue(data[i]);

if (isNaN(value.min) || isNaN(value.max) || meta.data[i].hidden) {
continue;
}
Expand Down

0 comments on commit 92b0476

Please sign in to comment.