UNPKG

@semcore/chart

Version:
27 lines (26 loc) 785 B
import hasNull from './hasNull'; /** * Divides an array of plot points into an array with arrays of points * separated by segments of no data points 🤯 * @param {Point[]} points - array of points * @param {String} dataKey - data key * @return {Point[][]} */ export default function computeDefinedSegments(points, dataKey) { var startNewSegment = true; return points.reduce(function (segments, point) { if (hasNull(point, dataKey)) { startNewSegment = true; return segments; } if (startNewSegment) { segments.push([point]); startNewSegment = false; } else { var lastSegment = segments[segments.length - 1]; lastSegment.push(point); } return segments; }, []); } //# sourceMappingURL=computeDefinedSegments.js.map