import type { SVGAttributes } from 'react'; import { useMemo } from 'react'; import { usePlotContext } from '../contexts/plotContext.js'; import type { SeriesPointWithError } from '../types.js'; import { validateAxis, validateSeriesPointError } from '../utils.js'; export interface ErrorBarsProps { data: readonly SeriesPointWithError[]; transform?: string; xAxis?: string; yAxis?: string; hidden?: boolean; style?: SVGAttributes; capSize?: number; capStyle?: SVGAttributes; } interface PointBarsProps { origin: { x: number; y: number }; top: number | null; bottom: number | null; left: number | null; right: number | null; style?: SVGAttributes; capSize?: number; capStyle?: SVGAttributes; } export default function ErrorBars(props: ErrorBarsProps) { const { xAxis = 'x', yAxis = 'y', data, hidden, transform, ...otherProps } = props; const { axisContext } = usePlotContext(); const [xScale, yScale] = validateAxis(axisContext, xAxis, yAxis); const points = useMemo(() => { if (hidden) return null; if (xScale === undefined || yScale === undefined) { return null; } const pointBars = data.map((point, i) => { const xError = validateSeriesPointError(point.xError); const yError = validateSeriesPointError(point.yError); return ( ); }); return pointBars; }, [data, xScale, yScale, hidden, otherProps]); return {points}; } function PointBars(props: PointBarsProps) { const { origin, top, bottom, left, right, style, capSize = 10, capStyle, } = props; const defaultColor = 'black'; return ( {top != null && ( )} {bottom != null && ( )} {left != null && ( )} {right != null && ( )} ); }