UNPKG

victory-native

Version:

A charting library for React Native with a focus on performance and customization.

63 lines (62 loc) 2.91 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useHorizontalBarPath = void 0; const React = __importStar(require("react")); const react_native_skia_1 = require("@shopify/react-native-skia"); const createRoundedRectPath_1 = require("../../utils/createRoundedRectPath"); const CartesianChartContext_1 = require("../contexts/CartesianChartContext"); const getBarThickness_1 = require("../utils/getBarThickness"); const getHorizontalBarRect_1 = require("../utils/getHorizontalBarRect"); const useHorizontalBarPath = (points, chartBounds, innerPadding = 0.2, roundedCorners, customBarWidth, barCount) => { const { xScale } = (0, CartesianChartContext_1.useCartesianChartContext)(); const barWidth = (0, getBarThickness_1.getBarThickness)({ points, axisStart: chartBounds.top, axisEnd: chartBounds.bottom, innerPadding, customBarThickness: customBarWidth, barCount, }); const path = React.useMemo(() => { const path = react_native_skia_1.Skia.Path.Make(); const baselineX = xScale(0); points.forEach((point) => { const rect = (0, getHorizontalBarRect_1.getHorizontalBarRect)(point, baselineX, barWidth); if (!rect) return; if (roundedCorners) { const nonUniformRoundedRect = (0, createRoundedRectPath_1.createRoundedRectPath)(rect.x, rect.y, rect.width, rect.height, roundedCorners, Number(point.yValue), "horizontal"); path.addRRect(nonUniformRoundedRect); } else { path.addRect(react_native_skia_1.Skia.XYWHRect(rect.x, rect.y, rect.width, rect.height)); } }); return path; }, [barWidth, points, roundedCorners, xScale]); return { path, barWidth }; }; exports.useHorizontalBarPath = useHorizontalBarPath;