Skip to content

Commit

Permalink
do not normalize all values if we don't care about the target
Browse files Browse the repository at this point in the history
  • Loading branch information
panthony committed Sep 11, 2019
1 parent 9d8bc27 commit 115cb29
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,35 @@ ChartInternal.prototype.getShapeOffset = function (typeFilter, indices, isSub) {
var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id),
y0 = scale(0), offset = y0;
targets.forEach(function (t) {
// skip if not part of offset (part1)
if (t.id === d.id || indices[t.id] !== indices[d.id]) {
return;
}

// skip if not part of offset (part 2)
if (targetIds.indexOf(t.id) >= targetIds.indexOf(d.id)) {
return;
}

const rowValues = $$.isStepType(d) ? $$.convertValuesToStep(t.values) : t.values;
const isTargetNormalized = $$.isTargetNormalized(d.id);
const values = rowValues.map(v => (isTargetNormalized ? $$.getRatio("index", v, true) : v.value));

if (t.id === d.id || indices[t.id] !== indices[d.id]) { return; }
if (targetIds.indexOf(t.id) < targetIds.indexOf(d.id)) {
// check if the x values line up
if (isUndefined(rowValues[i]) || +rowValues[i].x !== +d.x) { // "+" for timeseries
// if not, try to find the value that does line up
i = -1;
rowValues.forEach(function (v, j) {
const x1 = v.x.constructor === Date ? +v.x : v.x;
const x2 = d.x.constructor === Date ? +d.x : d.x;
// check if the x values line up
if (isUndefined(rowValues[i]) || +rowValues[i].x !== +d.x) { // "+" for timeseries
// if not, try to find the value that does line up
i = -1;
rowValues.forEach(function (v, j) {
const x1 = v.x.constructor === Date ? +v.x : v.x;
const x2 = d.x.constructor === Date ? +d.x : d.x;

if (x1 === x2) {
i = j;
}
});
}
if (i in rowValues && rowValues[i].value * d.value >= 0) {
offset += scale(values[i]) - y0;
}
if (x1 === x2) {
i = j;
}
});
}
if (i in rowValues && rowValues[i].value * d.value >= 0) {
offset += scale(values[i]) - y0;
}
});
return offset;
Expand Down

0 comments on commit 115cb29

Please sign in to comment.