import { Group } from '@visx/visx'; import type { ScaleBand, ScaleLinear, ScaleTime } from 'd3-scale'; import { equals } from 'ramda'; import type { MutableRefObject, ReactElement, ReactNode } from 'react'; import { margin } from '../../Chart/common'; import type { ChartAxis } from '../../Chart/models'; import Axes from '../Axes'; import Grids from '../Grids'; import type { Line, TimeValue } from '../timeSeries/models'; import { useMarginTop } from '../useMarginTop'; import { computeGElementMarginLeft } from '../utils'; interface Props { allUnits: Array; axis?: ChartAxis; base?: number; children: ReactNode; displayedLines: Array; graphHeight: number; graphWidth: number; gridLinesType?: string; leftScale: ScaleLinear; orientation?: 'horizontal' | 'vertical'; rightScale: ScaleLinear; showGridLines: boolean; svgRef: MutableRefObject; timeSeries: Array; xScale: | ScaleTime | ScaleLinear | ScaleBand; maxLeftAxisCharacters?: number; title?: string; } const ChartSvgWrapper = ({ svgRef, graphHeight, leftScale, rightScale, xScale, graphWidth, showGridLines, gridLinesType, base = 1000, displayedLines, timeSeries, axis, children, orientation = 'horizontal', allUnits, maxLeftAxisCharacters = 0, title }: Props): ReactElement => { const isHorizontal = equals(orientation, 'horizontal'); const hasValidLeftScale = Boolean(leftScale); const hasValidXScale = Boolean(xScale); const canRenderAxes = hasValidLeftScale && hasValidXScale; const canRenderGridRows = Boolean(isHorizontal ? leftScale : xScale); const canRenderGridColumns = Boolean(isHorizontal ? xScale : leftScale); const marginTop = useMarginTop({ title, units: allUnits }); return ( chart {showGridLines && (canRenderGridRows || canRenderGridColumns) && ( )} {canRenderAxes && ( )} {children} ); }; export default ChartSvgWrapper;