UNPKG

@graphique/geom-area

Version:

For area charts, stacked area charts, or streamgraphs

81 lines (76 loc) 4 kB
import React, { SVGAttributes, CSSProperties } from 'react'; import { Aes, DataValue, BrushAction, LegendOrientation } from '@graphique/graphique'; import { CurveFactory } from 'd3-shape'; type GeomAes<Datum> = Omit<Aes<Datum>, 'x' | 'size'> & { x?: DataValue<Datum>; /** a functional mapping to `data` representing an initial **y** value */ y0?: DataValue<Datum>; /** a functional mapping to `data` representing a secondary **y** value */ y1?: DataValue<Datum>; }; declare enum Position { /** groups are overlaid directly "on top" of each other (no effect on y scale) */ IDENTITY = "identity", /** groups are stacked vertically after any previous groups (additive effect on y scale) */ STACK = "stack", /** groups are stacked vertically as proportion of group total after any previous groups (y scale domain set to [0, 1]) */ FILL = "fill", /** groups are stacked vertically in a streamgraph (y scale domain set to a relatively meaningless/uninterpretable domain based on streamgraph layout) */ STREAM = "stream" } interface GeomProps<Datum> { /** * **data used by this Geom** * * This will overwrite top-level `data` passed to `GG` as it relates to mappings defined in `aes`. */ data?: Datum[]; /** * **functional mapping applied to `data` for this Geom** * * This extends the top-level `aes` passed to `GG`. Any repeated mappings defined here will take precedence within the Geom. */ aes?: GeomAes<Datum>; /** attributes passed to the underlying SVG elements */ attr?: SVGAttributes<SVGPathElement>; /** determines how grouped elements are positioned relative to each other (_default_: `Position.IDENTITY`) */ position?: Position; /** should this Geom have a tooltip associated with it (_default_: `true`) */ showTooltip?: boolean; /** determines what happens when brushing (clicking and dragging) over the drawing area */ brushAction?: BrushAction; /** [d3 curve](https://d3js.org/d3-shape/curve) factory imported from `d3-shape` (_default_: `curveLinear`) */ curve?: CurveFactory; /** should this Geom have a line marker for its focused data (_default_: `true`) */ showLineMarker?: boolean; /** radius in px of the line marker's points (_default_: `3.5`) */ markerRadius?: number; /** stroke color of the line marker's points (_default_: `"#ffffff"`) */ markerStroke?: string; /** callback called for mousemove events on the drawing area when focusing data */ onDatumFocus?: (data: Datum[], index: number[]) => void; /** callback called for click events on the drawing area when selecting focused data */ onDatumSelection?: (data: Datum[], index: number[]) => void; /** callback called for mouseleave events on the drawing area */ onExit?: () => void; /** should elements enter/update/exit with animated transitions (_default_: `true`) */ isAnimated?: boolean; } declare const GeomArea: { <Datum>({ data: localData, aes: localAes, brushAction, curve, onDatumFocus, onDatumSelection, onExit, attr, showTooltip, showLineMarker, markerRadius, markerStroke, position, isAnimated, }: GeomProps<Datum>): React.JSX.Element | null; displayName: string; }; interface LegendProps { /** title of legend */ title?: React.ReactNode; /** determines vertical/horizontal orientation of legend members (_default_: `LegendOrientation.V`) */ orientation?: LegendOrientation; /** function for formatting legend member labels */ format?: (v: string, i?: number) => string; /** callback called for click events on legend members */ onSelection?: (v: string) => void; /** additional styles passed to legend container */ style?: CSSProperties; } declare const Legend: <Datum>({ title, orientation, format, onSelection, style, }: LegendProps) => React.JSX.Element | null; export { type GeomAes, GeomArea, type GeomProps, Legend, type LegendProps, Position };