UNPKG

react-plot

Version:

Library of React components to render SVG 2D plots.

83 lines 3.2 kB
import type { ScaleContinuousNumeric, ScaleLinear, ScaleLogarithmic, ScaleOrdinal, ScaleTime } from 'd3-scale'; import type { Dispatch } from 'react'; import type { AxisScale } from '../components/Axis/Axis.js'; import type { LegendPosition } from '../components/Legend.js'; import type { ActionType, Position, ScalarValue, SeriesPoint, TickLabelFormat, VerticalPosition } from '../types.js'; import type { PlotAxesOverrides } from './plotController/usePlotOverrides.js'; export interface PlotState { headingPosition: VerticalPosition | null; legendPosition: LegendPosition | null; legendMargin: number; series: PlotSeriesState[]; axes: Record<string, PlotAxisState>; } export interface PlotSeriesState { id: string; x: PlotSeriesStateAxis; y: PlotSeriesStateAxis; label?: string; data?: readonly SeriesPoint[]; } interface PlotSeriesStateAxis { min: number; max: number; shift: ScalarValue; axisId: string; } export interface PlotAxisState { id: string; position: Position; min?: number; max?: number; flip: boolean; scale: AxisScale; innerOffset: number; paddingStart: ScalarValue; paddingEnd: ScalarValue; tickLabelFormat: TickLabelFormat | TickLabelFormat<Date> | undefined; } export type PlotReducerActions = ActionType<'addSeries', PlotSeriesState> | ActionType<'removeSeries', { id: string; }> | ActionType<'addAxis', PlotAxisState> | ActionType<'removeAxis', { id: string; }> | ActionType<'addHeading', { position: VerticalPosition; }> | ActionType<'removeHeading'> | ActionType<'addLegend', { position: LegendPosition; margin: number; }> | ActionType<'removeLegend'>; interface PlotAxisContextGeneric<Scale extends ScaleContinuousNumeric<number, number> | ScaleTime<number, number>> { scale: Scale; domain: readonly [number, number]; clampInDomain: (value: number) => number; tickLabelFormat: TickLabelFormat | TickLabelFormat<Date> | undefined; position: Position; } export type PlotAxisContext = ({ type: 'linear'; } & PlotAxisContextGeneric<ScaleLinear<number, number>>) | ({ type: 'log'; } & PlotAxisContextGeneric<ScaleLogarithmic<number, number>>) | ({ type: 'time'; } & PlotAxisContextGeneric<ScaleTime<number, number>>); export interface PlotContext { width: number; height: number; plotWidth: number; plotHeight: number; colorScaler: ScaleOrdinal<string, string>; axisContext: Record<string, PlotAxisContext>; } export declare function plotReducer(state: PlotState, action: PlotReducerActions): void; type PlotDispatch = Dispatch<PlotReducerActions>; export declare const plotContext: import("react").Context<PlotContext>; export declare const plotDispatchContext: import("react").Context<PlotDispatch>; export declare function usePlotContext(): PlotContext; export declare function usePlotDispatchContext(): PlotDispatch; interface SizeProps { plotWidth: number; plotHeight: number; } export declare function useAxisContext(state: PlotState, axesOverrides: PlotAxesOverrides, { plotWidth, plotHeight }: SizeProps): Record<string, PlotAxisContext>; export {}; //# sourceMappingURL=plotContext.d.ts.map