import { Point2D, Range2D, Range, Size } from '../../utilities'; import { OptionalPlotAreaProps, PlotAreaChildren } from '../plot/types'; import { OptionalAxisProps } from '../axes/types'; import { OptionalPlotProps } from '../plot/types'; import { OptionalScatterProps } from '../scatter/types'; import { OptionalLegendProps } from '../legend'; import React, { ReactNode } from 'react'; /** * Optional properties of a chart component. * @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 marginFraction if set, the fraction of the SVG viewBox to be used for axes, calculated relative to the larger dimension. * @member plotProps additional properties to pass to the component * @member plotAreaProps additional properties to pass to the component. * @member xAxisProps additional properties to pass to the component. * @member yAxisProps additional properties to pass to the component. */ export interface OptionalChartProps { scatterData?: Point2D[][]; lineData?: Point2D[][]; marginFraction?: number; plotProps?: OptionalPlotProps; plotAreaProps?: OptionalPlotAreaProps; xAxisProps?: OptionalAxisProps; yAxisProps?: OptionalAxisProps; } /** * Optional properties of a multidimensional chart component. * @member axisTitles if set, axis titles to use for each dimension. Defaults to "dimension #". * @member domainExpansionFactor percentage by which to expand domain widths so extreme points aren't drawn right at the edges. Defaults to 10%. * @member domains if set, sets explicit domains for each dimension rather than use their extrema; causes domainExpansionFactor to be ignored. * @member scatterProps if set, properties to apply to the scatter plot. * @member onSelectionEnd when a selection ends, receives the selection coordinates and any data falling within the selection. * @member onFreeformSelectionEnd when a freeform selection ends, receives the selection coordinates, relative to the underlying data. */ export interface OptionalMultidimensionalChartProps extends OptionalChartProps { axisTitles?: string[]; domainExpansionFactor?: number; domains?: Range[]; scatterProps?: OptionalScatterProps; onSelectionEnd?: (selection: Range2D, data: number[]) => void; onFreeformSelectionEnd?: (selection: Point2D[], data: number[]) => void; } /** * Properties of a Chart component. * @member data array of points representing the chart's data. * @member domain the range of x and y values that should be displayed within the chart. * @member innerSize coordinate system to use for the chart's SVG. */ export interface ChartProps extends OptionalChartProps { domain: Range2D; innerSize: Size; children: PlotAreaChildren | ReactNode; } export interface HistogramChartProps { domain?: Range2D; innerSize: Size; data: { bin: number; count: number; barProps?: React.SVGProps; }[]; marginFraction?: number; plotAreaProps?: OptionalPlotAreaProps; xAxisProps?: OptionalAxisProps; yAxisProps?: OptionalAxisProps; children: PlotAreaChildren | ReactNode; } /** * Properties of a MultidimensionalChart component. * @member data matrix of points representing the chart's data. Outer index is points, inner index is dimensions. * @member innerSize coordinate system to use for the chart's SVG. * @member xDimension dimension currently displayed on the x-axis. * @member yDimension dimension currently displayed on the y-axis. */ export interface MultidimensionalChartProps extends OptionalMultidimensionalChartProps { data: number[][]; innerSize: Size; xDimension: number; yDimension: number; } /** * State of a MultidimensionalChart component. * @member domains pre-computed domains for each dimension, updated when new data is passed. * @member data matrix of points representing the chart's data. Outer index is points, inner index is dimensions. * @member displayData pre-computed array of points currently being displayed by the chart. */ export interface MultidimensionalChartState { domains: Range[]; data: number[][]; displayData: Point2D[]; } /** * Utility interface for forwarding refs through class components. * @member innerRef the ref to forward. */ export interface InnerRef { innerRef: React.Ref; } /** * Represents a single entry in a MultiXLine chart. * @member data array of data points for this entry. * @member label the title of this entry. * @member color the color to use when drawing this entry's line. */ export interface MultiXLineEntry { data: number[]; label: string; color: string; } /** * Optional properties of a multidimensional chart component. * @member domainExpansionFactor percentage by which to expand the y domain so extreme points aren't drawn right at the edges. Defaults to 10%. * @member yDomain if set, explicit y domain within which to render data. * @member lineProps used to customize rendered elements. */ export interface OptionalMultiXLineChartProps extends OptionalChartProps { domainExpansionFactor?: number; yDomain?: Range; lineProps?: { [key: string]: any }; onSelectionEnd?: (selection: Range2D, data: number[]) => void; onFreeformSelectionEnd?: (selection: Point2D[], data: number[]) => void; } /** * Properties of the MultiXLine chart. * @member data array of lines to render; must all have the same number of data points. * @member xDomain used to map data indexes to x coordinates. */ export interface MultiXLineChartProps extends OptionalMultiXLineChartProps { data: MultiXLineEntry[]; xDomain: Range; innerSize: Size; legendProps?: OptionalLegendProps; } /** * State of a MultiXLine component. * @member data the data currently being displayed. * @member domain the current x and y domains. * @member mouseLocation if set, the current location of the mouse pointer; null if the plot is not moused over. * @member reverseTransform used to map x coordinates to data array indexes. * @member transform used to map data array indexes to x coordinates. */ export interface MultiXLineChartState { data: MultiXLineEntry[]; domain: Range2D; mouseLocation?: Point2D | null; mouseDataLocation?: Point2D | null; reverseTransform: (x: number) => number; transform: (x: number) => number; } export type MultiXLineMouseLocation = { mouseLocation: Point2D; mouseDataLocation: Point2D; };