import React from 'react' import { DataAccessor, Getter, KeyAccessor, AnimationProps, } from '../../lib/types' import { AnimatedDataset } from '../../components/AnimatedDataset' import { useSanitizedCascadingAnimation } from '../../components/Animation' import { useCartesianContext } from '../../components/internal' import { useComputableStyle } from './Style' import { StyleProps } from '../lib/types' import { buildComputePos } from '../lib/scales' /** @deprecated */ export interface LabelsDataProps extends StyleProps, AnimationProps { data: T[] dataX?: DataAccessor dataY?: DataAccessor dataKey?: KeyAccessor positionX?: Getter positionY?: Getter offsetX?: Getter offsetY?: Getter text: DataAccessor } /** @deprecated since v0.2.0. Use `Texts` instead. Will be removed in v1.0.0 */ export function LabelsData({ data, dataX, dataY, dataKey, positionX, positionY, offsetX, offsetY, text, enter = {}, delay, duration, ...props }: LabelsDataProps) { const { xScale, yScale, colorScale } = useCartesianContext() const style = useComputableStyle(props, colorScale) const animation = useSanitizedCascadingAnimation({ delay, duration }) const computeXPos = buildComputePos(dataX, positionX, offsetX, xScale, 'X') const computeYPos = buildComputePos(dataY, positionY, offsetY, yScale, 'Y') return ( computeXPos(d, 'center'), y: (d: T) => computeYPos(d, 'center'), text, ...style, }} init={enter} keyFn={(d: T, i: number) => dataKey?.(d, i) ?? i} {...(animation as any)} /> ) }