diff --git a/curvedLines.js b/curvedLines.js index c617b64..bfbca4d 100644 --- a/curvedLines.js +++ b/curvedLines.js @@ -167,10 +167,40 @@ ____________________________________________________ } } - + // split input data at datapoints with "null" values for x or y coordinate function calculateCurvePoints(datapoints, curvedLinesOptions, yPos) { - // typeof points[curX] === 'number' - return calculateCurvePointsSlice(datapoints.points, datapoints.pointsize, curvedLinesOptions, yPos) + var start = 0; + var slicing = false; + var points = datapoints.points; + var pointSize = datapoints.pointsize; + var result = []; + + for (var i = 0; i < points.length; i += pointSize) { + if (typeof points[i] === 'number' && typeof points[i + yPos] === 'number') { + if (!slicing) { + slicing = true; + start = i; + } + } else { + if (slicing) { + // a slice ends + slicing = false; + var slice = points.slice(start, i); + result = result.concat(calculateCurvePointsSlice(slice, pointSize, curvedLinesOptions, yPos)); + } + + // ensure that even defective points are included => line segment rendering + result = result.concat(points.slice(i, i + pointSize)) + } + } + + // last slice ends + if (slicing) { + var slice = points.slice(start, points.length); + result = result.concat(calculateCurvePointsSlice(slice, pointSize, curvedLinesOptions, yPos)); + } + + return result; } function calculateCurvePointsSlice(points, pointSize, curvedLinesOptions, yPos) { @@ -314,7 +344,7 @@ ____________________________________________________ //if fit option is selected additional datapoints get inserted before the curve calculations in nergal.dev s code. function calculateLegacyCurvePoints(points, pointSize, curvedLinesOptions, yPos) { - var num = Number(curvedLinesOptions.curvePointFactor) * (points.length / pointSize); + var num = Number(curvedLinesOptions.curvePointFactor) * (points.length / pointSize); var xdata = new Array; var ydata = new Array; diff --git a/tests/testNullFencepost.htm b/tests/testNullFencepost.htm index 890c37f..afb15e6 100644 --- a/tests/testNullFencepost.htm +++ b/tests/testNullFencepost.htm @@ -30,7 +30,7 @@ //curved line paramters var defaultParameters = { apply: true, - legacyOverride: false + legacyOverride: true } //plot function diff --git a/tests/testNullSplit.htm b/tests/testNullSplit.htm index 57f9e8f..3594be0 100644 --- a/tests/testNullSplit.htm +++ b/tests/testNullSplit.htm @@ -16,7 +16,7 @@