import React from 'react'; import type { LocaleInfo } from '../utilities/formatTimestamp'; import type { PlotDimensions } from '../TimeSeriesChart'; import type { VizTheme } from '../theme'; import type { AxisRange, GenericDataSet, ScaleConfig, SeriesConfig, StepPosition, TimestampFormat } from '../types'; export type PlotRendererFactoryOptions = { onReady?: (PlotUtilitiesFn: PlotUtilitiesFn, uplotref: uPlot | undefined) => void; onSetSize?: () => void; }; /** * Shared tick configuration properties for Y and Y2 axes */ export type AxisTickConfiguration = { /** Show major tick marks on the X-axis; default true */ showXMajorTicks?: boolean; /** Show major tick marks on the Y-axis; default false */ showYMajorTicks?: boolean; /** Show major tick marks on the Y2-axis (right axis); default false */ showY2MajorTicks?: boolean; /** Size (length) of major tick marks on the X-axis in pixels; uses uPlot default if not specified */ xAxisMajorTickSize?: number; /** Size (length) of major tick marks on the Y-axis in pixels; default 6 */ yAxisMajorTickSize?: number; /** Size (length) of major tick marks on the Y2-axis in pixels; default 6 */ y2AxisMajorTickSize?: number; /** Major tick interval for the Y-axis; controls spacing between ticks/labels */ yAxisMajorTickInterval?: number; /** Major tick interval for the Y2-axis; controls spacing between ticks/labels */ y2AxisMajorTickInterval?: number; /** Show minor tick marks on the Y-axis; default false */ showYMinorTicks?: boolean; /** Show minor tick marks on the Y2-axis (right axis); default false */ showY2MinorTicks?: boolean; /** Size (length) of minor tick marks on the Y-axis in pixels; default 4 */ yAxisMinorTickSize?: number; /** Size (length) of minor tick marks on the Y2-axis in pixels; default 4 */ y2AxisMinorTickSize?: number; /** Whether the Y-axis range includes zero; default false (data range only) */ showYAxisWithZero?: boolean; /** Whether the Y2-axis range includes zero; default false (data range only) */ showY2AxisWithZero?: boolean; }; export type SeriesInfo = { field: string; label?: string; fill?: string; stroke?: string; show: boolean; }; export type PlotUtilities = { dimensions: PlotDimensions; valToPos: (value: number, scaleKey: string) => number; posToVal: (position: number, scaleKey: string) => number; setCursor: (cursor: { left: number; top: number; }, fire?: boolean) => void; setFocusedSeries: (field: string | null) => void; setScale: (scaleKey: string, min: number, max: number) => void; resetScale: (scaleKey: string) => void; panLeft: (scaleKey: string) => boolean; panRight: (scaleKey: string) => boolean; getScaleRange: (scaleKey: string) => { min: number; max: number; } | undefined; /** * Subscribe to scale changes (e.g. zoom/pan) for the given scaleKey. Returns an unsubscribe function. * Useful for components that need to re-render when the visible range changes imperatively. */ subscribeToScale: (scaleKey: string, fn: () => void) => () => void; allSeries: SeriesInfo[]; el: HTMLElement; }; export type PlotUtilitiesFn = () => PlotUtilities | undefined; export type OnSetCursorFn = (cursor: { top: number; left: number; index: number; } | null) => void; export type OnFocusSeriesFn = (seriesIndex: number | null) => void; /** * Shared axis display properties for grid lines, ticks, and axis range options. * Used by both RenderProps and TimeSeriesChartProps to avoid duplication. */ export type AxisDisplayProps = { /** Show major grid lines on the X-axis; default false */ showXMajorGridLines?: boolean; /** Show major grid lines on the Y-axis; default true */ showYMajorGridLines?: boolean; /** Show major grid lines on the Y2-axis (right axis); default false */ showY2MajorGridLines?: boolean; /** Show minor grid lines on the Y-axis; default false */ showYMinorGridLines?: boolean; /** Show minor grid lines on the Y2-axis (right axis); default false */ showY2MinorGridLines?: boolean; /** Enable line smoothing with spline interpolation; default false */ showLineSmoothing?: boolean; /** Default step interpolation position for line/area series; per-series config can override */ stepPosition?: StepPosition; /** Data values display mode: 'off' (default), 'all', or 'minmax' */ dataValuesDisplay?: 'off' | 'all' | 'minmax'; /** Show X-axis line at bottom of chart; default true */ showXAxisLine?: boolean; /** Show Y-axis line at left of chart; default false */ showYAxisLine?: boolean; /** Show Y2-axis line at right of chart; default false */ showY2AxisLine?: boolean; /** The maximum number of time-parts for a tick label. default 3 */ xAxisMaxLabelParts?: number; } & AxisTickConfiguration; export type AreaOnlyOptions = { areaOpacity?: number; }; export type RenderProps = AxisDisplayProps & AreaOnlyOptions & { width: number; height: number; data: GenericDataSet; seriesConfig?: SeriesConfig; scaleConfig?: ScaleConfig; theme: VizTheme; interactiveEl?: HTMLElement; hideXAxis?: true; range?: AxisRange; hiddenSeries?: string[]; userLocale?: LocaleInfo; /** Maximum number of series that still allows for "closest series focus" functionality to be enabled. * defaults to FOCUS_MAX_SERIES (30) */ maxSeriesFocus?: number; rawXaxisValues?: (string | number | null)[]; timestampFormat?: TimestampFormat; seriesColors?: string[]; seriesColorsByField?: Record; /** Add additional uplot plugins */ plugins?: uPlot.Plugin[]; }; export type PlotRenderer = { component: React.FC; onSetCursor: (fn: OnSetCursorFn) => void; onFocusSeries: (fn: OnFocusSeriesFn) => void; }; export type PlotRendererFactory = (options: PlotRendererFactoryOptions) => { utils: PlotUtilitiesFn; renderer: PlotRenderer; };