UNPKG

react-native-chart-kit

Version:

Beautiful React Native charts for dashboards, reports, and data-rich mobile apps.

52 lines (51 loc) 1.68 kB
import { buildAreaPath } from "./areaPath"; import { buildLinePath } from "./linePath"; const isFinitePosition = (value) => { return typeof value === "number" && Number.isFinite(value); }; const projectPoint = (series, point, xScale, yScale, dataIndexOffset) => { const projectedX = xScale(point.x, point); const projectedY = point.value === null ? undefined : yScale(point.value, point); const defined = point.defined && isFinitePosition(projectedX) && isFinitePosition(projectedY); return { index: point.index + dataIndexOffset, dataIndex: point.index + dataIndexOffset, seriesKey: series.key, xValue: point.x, x: projectedX ?? 0, y: projectedY ?? 0, value: point.value, defined, raw: point.raw }; }; export const buildLineSeriesGeometry = ({ series, xScale, yScale, curve = "linear", connectNulls = false, dataIndexOffset = 0, pathDecimation, areaBaselineY }) => { const points = series.points.map((point) => projectPoint(series, point, xScale, yScale, dataIndexOffset)); const line = buildLinePath({ points, curve, connectNulls, decimation: pathDecimation }); const geometry = { key: series.key, label: series.label, points, line }; if (series.color !== undefined) { geometry.color = series.color; } if (areaBaselineY !== undefined) { geometry.area = buildAreaPath({ points, curve, connectNulls, decimation: pathDecimation, baselineY: areaBaselineY }); } return geometry; };