import {Fragment, useRef} from 'react'; import { uniqueId, ChartState, DEFAULT_CHART_PROPS, usePolarisVizContext, } from '@shopify/polaris-viz-core'; import type { XAxisOptions, YAxisOptions, ChartProps, } from '@shopify/polaris-viz-core'; import {fillMissingDataPoints} from '../../utilities/fillMissingDataPoints'; import { getXAxisOptionsWithDefaults, getYAxisOptionsWithDefaults, normalizeData, } from '../../utilities'; import {ChartContainer} from '../ChartContainer'; import {ChartSkeleton} from '../ChartSkeleton'; import {SkipLink} from '../SkipLink'; import type { Annotation, RenderLegendContent, TooltipOptions, } from '../../types'; import {useRenderTooltipContent} from '../../hooks'; import {Chart} from './Chart'; export type StackedAreaChartProps = { annotations?: Annotation[]; tooltipOptions?: TooltipOptions; state?: ChartState; errorText?: string; renderLegendContent?: RenderLegendContent; showLegend?: boolean; skipLinkText?: string; theme?: string; xAxisOptions?: Partial; yAxisOptions?: Partial; } & ChartProps; export function StackedAreaChart(props: StackedAreaChartProps) { const {defaultTheme} = usePolarisVizContext(); const { annotations = [], xAxisOptions, yAxisOptions, data: dataSeries, state, errorText, onError, tooltipOptions, isAnimated, renderLegendContent, showLegend = true, skipLinkText, theme = defaultTheme, } = { ...DEFAULT_CHART_PROPS, ...props, }; const data = fillMissingDataPoints(dataSeries); const skipLinkAnchorId = useRef(uniqueId('stackedAreaChart')); const renderTooltip = useRenderTooltipContent({tooltipOptions, theme, data}); if (data.length === 0) { return null; } const xAxisOptionsWithDefaults = getXAxisOptionsWithDefaults(xAxisOptions); const yAxisOptionsWithDefaults = getYAxisOptionsWithDefaults(yAxisOptions); const annotationsLookupTable = normalizeData(annotations, 'startKey'); return ( {skipLinkText == null || skipLinkText.length === 0 ? null : ( {skipLinkText} )} {state !== ChartState.Success ? ( ) : ( )} {skipLinkText == null || skipLinkText.length === 0 ? null : ( )} ); }