UNPKG

@semcore/chart

Version:
45 lines (44 loc) 1.73 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import hasNull from './hasNull'; function replaceNullValue(targetPoint, sourcePoint) { var field; if (targetPoint.x === null || targetPoint.value && targetPoint.value[0] === 0) field = 'x'; if (targetPoint.y === null || targetPoint.value && targetPoint.value[0] === 0) field = 'y'; return Object.assign({}, targetPoint, field ? _defineProperty({}, field, sourcePoint[field]) : {}); } /** * Normalizes the array of points for the plot. * Fills points without data with points from neighboring ones. * It is necessary to continue the dotted line in those places where there is no data on the edges. * @param points * @param dataKey */ export default function normalizeCurvePoints(points, dataKey) { var curvePoints = Array.from(points); if (hasNull(curvePoints[0], dataKey)) { var firstDefinedIndex = points.findIndex(function (point) { return !hasNull(point, dataKey); }); curvePoints.forEach(function (point, index) { if (index < firstDefinedIndex) { curvePoints[index] = replaceNullValue(point, points[firstDefinedIndex]); } }); } var length = curvePoints.length; if (hasNull(curvePoints[length - 1], dataKey)) { var definedIndex = curvePoints.map(function (i) { return i; }).reverse().findIndex(function (point) { return !hasNull(point, dataKey); }); var _firstDefinedIndex = length - 1 - definedIndex; curvePoints.forEach(function (point, index) { if (index > _firstDefinedIndex) { curvePoints[index] = replaceNullValue(point, points[_firstDefinedIndex]); } }); } return curvePoints; } //# sourceMappingURL=normalizeCurvePoints.js.map