UNPKG

react-native-chart-kit

Version:

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

27 lines (26 loc) 2.29 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { View } from "react-native"; import { getLineChartRenderer } from "./renderer"; import { getStickyYAxisBackgroundHeight } from "./stickyYAxisLayout"; import { getFontFamilyProps } from "./text"; export const StickyYAxis = ({ fadeHeight, fadeOpacity, fadeWidth, fadeY, gradientId, mainHeight, model, renderer: rendererProp, width, yAxisLabels }) => { const { boxes, resolvedTheme } = model; const renderer = getLineChartRenderer(rendererProp); const { Defs, Group, Rect, Surface, Text } = renderer; const Layer = renderer.Layer ?? Group; const LinearGradient = renderer.LinearGradient; const canRenderText = renderer.capabilities?.text !== false; const supportsGradients = renderer.capabilities?.gradients !== false && Boolean(LinearGradient); return (_jsx(View, { pointerEvents: "none", style: { left: 0, position: "absolute", top: 0, width, height: mainHeight }, children: _jsxs(Surface, { width: width, height: mainHeight, children: [_jsx(Defs, { children: supportsGradients && LinearGradient ? (_jsx(LinearGradient, { id: gradientId, x1: "0%", x2: "100%", y1: "0%", y2: "0%", stops: [ { offset: "0%", color: resolvedTheme.background, opacity: 1 }, { offset: "100%", color: resolvedTheme.background, opacity: 0 } ] })) : null }), _jsxs(Layer, { name: "background", children: [_jsx(Rect, { x: 0, y: 0, width: boxes.plot.x, height: getStickyYAxisBackgroundHeight({ fadeY, mainHeight }), fill: resolvedTheme.background }), supportsGradients && fadeWidth > 0 ? (_jsx(Rect, { x: boxes.plot.x, y: fadeY, width: fadeWidth, height: fadeHeight, fill: `url(#${gradientId})`, opacity: fadeOpacity })) : null] }), _jsx(Layer, { name: "axes", children: canRenderText ? yAxisLabels.map((label) => (_jsx(Text, { x: boxes.plot.x - 8, y: label.y, fill: resolvedTheme.mutedText, fontSize: resolvedTheme.typography.axisLabelSize, opacity: label.opacity, textAnchor: "end", ...getFontFamilyProps(resolvedTheme.typography.fontFamily), children: label.text }, `sticky-label-y-${label.key}`))) : null })] }) })); };