import { Point2D, Range2D, Size } from '../../utilities'; import { ReactNode } from 'react'; export interface OptionalPlotProps { [key: string]: any; } /** * Properties of the Plot component. * @member innerSize the internal size of the SVG the component renders, to which all children are relative. */ export interface PlotProps extends OptionalPlotProps { innerSize: Size; } /** * Properties of the SelectionRect component. * @member dimensions total size of the area available to select, relative to the containing SVG. * @member domain the domain of the underlying data; selections are mapped into this space when they complete. * @member onSelectionEnd when a selection ends, receives the selection coordinates, relative to the underlying data. * @member onFreeformSelectionEnd when a freeform selection ends, receives the selection coordinates, relative to the underlying data. * @member color if passed, color to use for the rectangle around the active selection. * @member withGuideLines if set, guide lines are shown as the mouse moves across the plot, showing the current coordinates. * @member guideLineProps if set, props to pass to guide lines; only used if withGuideLines is true. * @member freeform if set, allows the user to draw a selection polygon rather than a rectangle. * @member freeformProps if set, custom properties to apply to the freeform selection path. */ export type SelectionRectProps = { dimensions: Size; domain: Range2D; onSelectionEnd?: (selection: Range2D) => void; onFreeformSelectionEnd?: (selection: Point2D[]) => void; onMouseMove?: (e: React.MouseEvent, location: Point2D, dataLocation: Point2D) => void; color?: string; withGuideLines?: boolean; guideLineProps?: { [key: string]: any }; freeform?: boolean; freeformProps?: { [key: string]: any }; }; /** * State of the SelectionRect component. * @member selecting whether or not a selection is in progress. * @member selectionStart if set, starting position of the current selection, relative to the containing SVG. * @member mousePosition if set, current position of the mouse, relative to the contianing SVG. * @member transform used to map points from the SVG's coordinate system into the domain of the plotted data. */ export type SelectionRectState = { selecting: boolean; selectionStart?: Point2D | null; mouseLocation?: Point2D | null; transform: (point: Point2D) => Point2D; selection: Point2D[]; }; /** * Optional properties for customizing PlotArea components. * @member scatterData array of arrays of scatter plot data, with coordinates relative to the domain; necessary only if selection events are used. * @member lineData array of arrays of scatter line data, with coordinates relative to the domain; necessary only if selection events are used. * @member onSelectionEnd when a selection ends, receives the selection coordinates and any data falling within the selection; outer indices match scatterData. * @member onFreeformSelectionEnd when a freeform selection ends, receives the selection coordinates, relative to the underlying data. * @member nonSelectable if set, a selection rectangle is not made available for selection. * @member withGuideLines if set, guide lines are shown as the mouse moves across the plot, showing the current coordinates. * @member guideLineProps if set, props to pass to guide lines; only used if withGuideLines is true. * @member freeformSelection if set, the selection rectangle will use freeform rather than rectangular selections. * @member freeformSelectionProps if set, custom properties to apply to the freeform selection path. */ export interface OptionalPlotAreaProps { scatterData?: Point2D[][]; lineData?: Point2D[][]; onSelectionEnd?: (selection: Range2D, data: number[][]) => void; onFreeformSelectionEnd?: (selection: Point2D[], data: number[][]) => void; onMouseMove?: (e: React.MouseEvent, location: Point2D, dataLocation: Point2D) => void; nonSelectable?: boolean; withGuideLines?: boolean; guideLineProps?: { [key: string]: any }; freeformSelection?: boolean; freeformSelectionProps?: { [key: string]: any }; [key: string]: any; } /** * Properties of the SelectionRect component. * @member dimensions total size of the area available to select, relative to the containing SVG. * @member domain the domain of the underlying data; selections are mapped into this space when they complete. */ export interface PlotAreaProps extends OptionalPlotAreaProps { domain: Range2D; dimensions: Size; children: PlotAreaChildren | ReactNode; } export interface PlotAreaChildData { data: any; [key: string]: any } export interface PlotAreaChildPoint { x: number; y: number; [key: string]: any } export interface PlotAreaChildLine { x1: number; y1: number; x2: number; y2: number; [key: string]: any } export interface PlotAreaChildCircle { cx: number; cy: number; [key: string]: any } export interface PlotAreaChildCoordinates { x: { start: number }; y: {start: number }; [key: string]: any } export type PlotAreaChildProps = PlotAreaChildData | PlotAreaChildPoint | PlotAreaChildLine | PlotAreaChildCircle | PlotAreaChildCoordinates | any; export type PlotAreaChildren = React.ReactElement | Array> | null | undefined; /** * Optional properties of the GuideLines component. * @member lineProps if set, overrides the style of the elements. * @member hideHorizontal if set, the horizontal guide line will not be shown. * @member hideVertical if set, the vertical guide line will not be shown. */ export interface OptionalGuideLineProps { lineProps?: { [key: string]: any }; hideHorizontal?: boolean; hideVertical?: boolean; } /** * Properties of the GuideLines component. * @member dimensions total size of the plot area, relative to the containing SVG. * @member position the current position where the lines should center, relative to the SVG. */ export interface GuideLineProps extends OptionalGuideLineProps { dimensions: Size; position: Point2D; } /** * Required properties for 2-dimensional plots. * @member data the data to plot. * @member transform function for mapping data points into the parent's coordinate space. The parent PlotArea will pass this. */ export interface GenericPlotProps { data: Point2D[]; transform?: (point: Point2D) => Point2D; [key: string]: any; }