import { useMeasure } from '@react-hookz/web'; import { Canvas } from '@react-three/fiber'; import type { PropsWithChildren } from 'react'; import { useState } from 'react'; import InteractionsProvider from '../../interactions/InteractionsProvider'; import type { AxisConfig } from '../models'; import { getSizeToFit, getAxisOffsets } from '../utils'; import AxisSystem from './AxisSystem'; import AxisSystemProvider from './AxisSystemProvider'; import RatioEnforcer from './RatioEnforcer'; import ThresholdAdjuster from './ThresholdAdjuster'; import ViewportCenterer from './ViewportCenterer'; import styles from './VisCanvas.module.css'; interface Props { title?: string; canvasRatio?: number | undefined; visRatio?: number | undefined; abscissaConfig: AxisConfig; ordinateConfig: AxisConfig; raycasterThreshold?: number; } function VisCanvas(props: PropsWithChildren) { const { title, canvasRatio, visRatio, abscissaConfig, ordinateConfig, raycasterThreshold, children, } = props; const shouldMeasure = !!canvasRatio; const [areaSize, areaRef] = useMeasure(shouldMeasure); const canvasSize = areaSize && getSizeToFit(areaSize, canvasRatio); const axisOffsets = getAxisOffsets({ left: !!ordinateConfig.label, bottom: !!abscissaConfig.label, top: !!title, }); const [floatingToolbar, setFloatingToolbar] = useState(); return (
{(!shouldMeasure || canvasSize) && (
{children} {raycasterThreshold !== undefined && ( )}
setFloatingToolbar(elem || undefined)} className={styles.floatingToolbar} />
)}
); } export type { Props as VisCanvasProps }; export default VisCanvas;