From 034fad22e9bb0592b155cfcefedfa7f037ae508f Mon Sep 17 00:00:00 2001 From: Amir Date: Thu, 16 Jul 2015 15:14:33 -0700 Subject: [PATCH] Update getShapeOffset() to allow data series with unequal amount of x-values Refs issue#1065 --- src/shape.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/shape.js b/src/shape.js index fd40598..8210fb6 100644 --- a/src/shape.js +++ b/src/shape.js @@ -41,8 +41,23 @@ c3_chart_internal_fn.getShapeOffset = function (typeFilter, indices, isSub) { var values = $$.isStepType(d) ? $$.convertValuesToStep(t.values) : t.values; if (t.id === d.id || indices[t.id] !== indices[d.id]) { return; } if (targetIds.indexOf(t.id) < targetIds.indexOf(d.id)) { - if (values[i].value * d.value >= 0) { - offset += scale(values[i].value) - y0; + // check if the x values line up + if (typeof values[i] === 'undefined' || + (values[i].x !== d.x) && (values[i].x - d.x !== 0)) { + // if not, try to find the value that does line up + i = -1; + for (var j in values) { + if ((values[j].x === d.x) || (values[j].x - d.x === 0)) { + i = j; + break; + } + } + } + + if (i in values) { + if (values[i].value * d.value >= 0) { + offset += scale(values[i].value) - y0; + } } } });