UNPKG

react-native-chart-kit

Version:

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

37 lines (36 loc) 1.2 kB
import { getDecimatedLinePathSegments } from "./lineDecimation"; import { buildLineSegmentPath } from "./linePath"; import { pointCommand } from "./path"; const getBaselineY = (baselineY, point) => { return typeof baselineY === "function" ? baselineY(point) : baselineY; }; const closeAreaPath = (linePath, points, baselineY) => { const first = points[0]; const last = points[points.length - 1]; if (!first || !last) { return ""; } return [ linePath, pointCommand("L", last.x, getBaselineY(baselineY, last)), pointCommand("L", first.x, getBaselineY(baselineY, first)), "Z" ].join(" "); }; export const buildAreaPath = ({ points, curve = "linear", connectNulls = false, decimation, baselineY }) => { const segments = getDecimatedLinePathSegments({ points, connectNulls, decimation }).map((segment) => { const linePath = buildLineSegmentPath(segment, curve); return { points: segment, path: closeAreaPath(linePath, segment, baselineY) }; }); return { segments, path: segments.map((segment) => segment.path).join(" ") }; };