import { ReactNode } from 'react' ; import { $Values } from 'utility-types' ; import { ChartType } from '../..' ; import { Color } from '../../../common/colors' ; import { TooltipPortalSettings } from '../../../components/portal/types' ; import { LogScaleOptions , ScaleContinuousType } from '../../../scales' ; import { ScaleType } from '../../../scales/constants' ; import { Spec } from '../../../specs' ; import { SpecType } from '../../../specs/constants' ; import { AccessorFormat , AccessorFn , Accessor } from '../../../utils/accessor' ; import { RecursivePartial , Position , Datum } from '../../../utils/common' ; import { CurveType } from '../../../utils/curves' ; import { OrdinalDomain } from '../../../utils/domain' ; import { AxisId , GroupId } from '../../../utils/ids' ; import { AreaSeriesStyle , BarSeriesStyle , GridLineStyle , LineAnnotationStyle , LineSeriesStyle , PointStyle , RectAnnotationStyle , BubbleSeriesStyle , AxisStyle , } from '../../../utils/themes/theme' ; import { PrimitiveValue } from '../../partition_chart/layout/utils/group_by_rollup' ; import { AnnotationTooltipFormatter , ComponentWithAnnotationDatum , CustomAnnotationTooltip , } from '../annotations/types' ; import { XYChartSeriesIdentifier , DataSeriesDatum } from './series' ; public export type BarStyleOverride = RecursivePartial < BarSeriesStyle > | Color | null ; public export type PointStyleOverride = RecursivePartial < PointStyle > | Color | null ; public export const SeriesType = Object . freeze ( { Area : 'area' as const , Bar : 'bar' as const , Line : 'line' as const , Bubble : 'bubble' as const , } ) ; public export type SeriesType = $Values < typeof SeriesType > ; public export const StackMode = Object . freeze ( { /** Applies a zero baseline and normalizes the values for each point such that the topline is always one. */ Percentage : 'percentage' as const , /** Shifts the baseline so as to minimize the weighted wiggle of layers. */ Wiggle : 'wiggle' as const , /** Shifts the baseline down such that the center of the streamgraph is always at zero. */ Silhouette : 'silhouette' as const , } ) ; public export type StackMode = $Values < typeof StackMode > ; public export type BarStyleAccessor = ( datum : DataSeriesDatum , seriesIdentifier : XYChartSeriesIdentifier ) => BarStyleOverride ; public export type PointStyleAccessor = ( datum : DataSeriesDatum , seriesIdentifier : XYChartSeriesIdentifier ) => PointStyleOverride ; public export const DEFAULT_GLOBAL_ID = '__global__' ; public export type FilterPredicate = ( series : XYChartSeriesIdentifier ) => boolean ; public export type SeriesName = string | number | null ; public export type SeriesNameFn = ( series : XYChartSeriesIdentifier , isTooltip : boolean ) => SeriesName ; public export interface SeriesNameConfig { /**
     * accessor key (i.e. `yAccessors` and `seriesSplitAccessors`)
     */ accessor : string | number ; /**
     * Accessor value (i.e. values from `seriesSplitAccessors`)
     */ value ? : string | number ; /**
     * New name for Accessor value
     *
     * If not provided, the original value will be used
     */ name ? : string | number ; /**
     * Sort order of name, overrides order listed in array.
     *
     * lower values - left-most
     * higher values - right-most
     */ sortIndex ? : number ; } public export interface SeriesNameConfigOptions { /**
     * Array of accessor naming configs to replace series names
     *
     * Only provided configs will be included
     * (i.e. if you only provide a single mapping for `yAccessor`, all other series accessor names will be ignored)
     *
     * The order of configs is the order in which the resulting names will
     * be joined, if no `sortIndex` is specified.
     *
     * If no values are found for a giving mapping in a series, the mapping will be ignored.
     */ names ? : SeriesNameConfig [ ] ; defaultValue delimiter ? : string ; } public export type SeriesNameAccessor = string | SeriesNameFn | SeriesNameConfigOptions ; public export const Fit = Object . freeze ( { example None : 'none' as const , remarks example Carry : 'carry' as const , remarks example Lookahead : 'lookahead' as const , example Nearest : 'nearest' as const , example Average : 'average' as const , example Linear : 'linear' as const , example Zero : 'zero' as const , example Explicit : 'explicit' as const , } ) ; public export type Fit = $Values < typeof Fit > ; public export interface DomainRange { /**
     * Custom minInterval for the domain which will affect data bin size.
     * `min: NaN` or `max: NaN` can be used for either or both extrema, when unbounded.
     * The minInterval cannot be greater than the computed minimum interval between any two adjacent data points.
     * Further, if you specify a custom numeric minInterval for a time-series, please note that due to the restriction
     * above, the specified numeric minInterval will be interpreted as a fixed interval.
     * This means that, for example, if you have yearly time-series data that ranges from 2016 to 2019 and you manually
     * compute the interval between 2016 and 2017, you'll have 366 days due to 2016 being a leap year.  This will not
     * be a valid interval because it is greater than the computed minInterval of 365 days between the other years.
     */ min : number ; max : number ; minInterval ? : number ; } public export const DomainPaddingUnit = Object . freeze ( { /**
     * Raw value in the domain space.
     *
     * Example:
     *
     * If your domain is `[20, 40]` and your padding value is `10`.
     * The resulting domain would be `[10, 50]`
     */ Domain : 'domain' as const , alpha Pixel : 'pixel' as const , /**
     * Ratio of total domain relative to domain space
     *
     * Example:
     *
     * If your domain is `[20, 40]` and your padding value is `0.1`.
     * The resulting padding would be 2 (i.e. `0.1 * (40 - 20)`)
     * resulting in a domain of `[18, 42]`
     */ DomainRatio : 'domainRatio' as const , } ) ; public export type DomainPaddingUnit = $Values < typeof DomainPaddingUnit > ; public export interface YDomainBase { defaultValue fit ? : boolean ; /**
     * Padding for computed domain as positive number.
     * Applied to domain __before__ nicing
     *
     * Setting `max` or `min` will override this functionality.
     */ padding ? : number ; defaultValue paddingUnit ? : DomainPaddingUnit ; defaultValue constrainPadding ? : boolean ; } public export type YDomainRange = YDomainBase & DomainRange & LogScaleOptions ; public export type CustomXDomain = ( DomainRange & Pick < LogScaleOptions , 'logBase' > ) | OrdinalDomain ; public export const LabelOverflowConstraint = Object . freeze ( { BarGeometry : 'barGeometry' as const , ChartEdges : 'chartEdges' as const , } ) ; public export type LabelOverflowConstraint = $Values < typeof LabelOverflowConstraint > ; public export interface DisplayValueSpec { defaultValue showValueLabel ? : boolean ; defaultValue isAlternatingValueLabel ? : boolean ; defaultValue valueFormatter ? : TickFormatter ; deprecated defaultValue isValueContainedInElement ? : boolean ; defaultValue overflowConstraints ? : Array < LabelOverflowConstraint > ; } public export interface SeriesSpec < D extends BaseDatum = Datum > extends Spec { specType : typeof SpecType . Series ; chartType : typeof ChartType . XYAxis ; /**
     * The name of the spec. Also a mechanism to provide custom series names.
     */ name ? : SeriesNameAccessor ; defaultValue DEFAULT_GLOBAL_ID groupId : string ; /**
     * When specify a groupId on this series, this option can be used to compute this series domain as it was part
     * of the default group (when using the boolean value true)
     * or as the series was part of the specified group (when issuing a string)
     */ useDefaultGroupDomain ? : boolean | string ; /** An array of data */ data : D [ ] ; /** The type of series you are looking to render */ seriesType : SeriesType ; /** Set colors for specific series */ color ? : SeriesColorAccessor ; defaultValue hideInLegend ? : boolean ; deprecated sortIndex ? : number ; displayValueSettings ? : DisplayValueSpec ; defaultValue y0AccessorFormat ? : AccessorFormat ; defaultValue y1AccessorFormat ? : AccessorFormat ; /**
     * Hide series in tooltip
     */ filterSeriesInTooltip ? : FilterPredicate ; /**
     * A function called to format every value label.
     * Uses axis `tickFormat` when not provided.
     */ tickFormat ? : TickFormatter ; } public export interface Postfixes { defaultValue y0AccessorFormat ? : string ; defaultValue y1AccessorFormat ? : string ; } public export type SeriesColorsArray = string [ ] ; public export type SeriesColorAccessorFn = ( seriesIdentifier : XYChartSeriesIdentifier ) => string | null ; public export type SeriesColorAccessor = string | SeriesColorsArray | SeriesColorAccessorFn ; public export interface SeriesAccessors < D extends BaseDatum = any > { /** The field name of the x value on Datum object */ xAccessor : Accessor < D > | AccessorFn < D > ; /** An array of field names one per y metric value */ yAccessors : ( Accessor < D > | AccessorFn < D > ) [ ] ; /** An optional accessor of the y0 value: base point for area/bar charts  */ y0Accessors ? : ( Accessor < D > | AccessorFn < D > ) [ ] ; /** An array of fields thats indicates the datum series membership */ splitSeriesAccessors ? : ( Accessor < D > | AccessorFn < D > ) [ ] ; /**
     * An array of fields thats indicates the stack membership.
     * Does not depend on datum at the moment.
     *
     * TODO pass datum to accessors when applicable
     */ stackAccessors ? : ( Accessor < any > | AccessorFn < any > ) [ ] ; /**
     * Field name of mark size metric on `Datum`
     *
     * Only used with line/area series
     */ markSizeAccessor ? : Accessor < D > | AccessorFn < D > ; } public export type XScaleType = typeof ScaleType . Ordinal | ScaleContinuousType ; public export interface SeriesScales { defaultValue `ordinal`  {@link (ScaleType:type) | ScaleType.Ordinal} xScaleType : XScaleType ; defaultValue xNice ? : boolean ; defaultValue timeZone ? : string ; defaultValue `linear`  {@link (ScaleType:type) | ScaleType.Linear} yScaleType : ScaleContinuousType ; defaultValue yNice ? : boolean ; } type MarkFormatter < Type extends string = '' > = Type extends 'bar' ? { } : { /**
     * A function called to format every single mark value
     *
     * Only used with line/area series
     */ markFormat ? : TickFormatter < number > ; } ; public export type BasicSeriesSpec < D extends BaseDatum = Datum , Type extends string = '' > = SeriesSpec < D > & SeriesAccessors < D > & SeriesScales & MarkFormatter < Type > ; public export type SeriesSpecs < D extends BaseDatum = Datum , S extends BasicSeriesSpec < D > = BasicSeriesSpec < D > > = Array < S > ; public export type BaseDatum = Record < string , any > | any [ ] ; public export type BarSeriesSpec < D extends BaseDatum = Datum > = BasicSeriesSpec < D , 'bar' > & Postfixes & { defaultValue `bar`  {@link (SeriesType:type) | SeriesType.Bar} seriesType : typeof SeriesType . Bar ; /** If true, will stack all BarSeries and align bars to ticks (instead of centered on ticks) */ enableHistogramMode ? : boolean ; barSeriesStyle ? : RecursivePartial < BarSeriesStyle > ; /**
     * Stack each series using a specific mode: Percentage, Wiggle, Silhouette.
     * The last two modes are generally used for stream graphs
     */ stackMode ? : StackMode ; /**
     * Functional accessor to return custom color or style for bar datum
     */ styleAccessor ? : BarStyleAccessor ; remarks minBarHeight ? : number ; } ; public export type HistogramBarSeriesSpec < D extends BaseDatum = Datum > = Omit < BarSeriesSpec < D > , 'stackAccessors' > & { enableHistogramMode : true ; } ; public export type FitConfig = { /**
     * Fit type for data with null values
     */ type : Fit ; /**
     * Fit value used when `type` is set to `Fit.Explicit`
     */ value ? : number ; /**
     * Value used for first and last point if fitting is not possible
     *
     * `'nearest'` will set indeterminate end values to the closes _visible_ point.
     *
     * Note: Computed fit values will always take precedence over `endValues`
     */ endValue ? : number | 'nearest' ; } ; public export type LineSeriesSpec < D extends BaseDatum = Datum > = BasicSeriesSpec < D , 'line' > & HistogramConfig & { defaultValue `line`  {@link (SeriesType:type) | SeriesType.Line} seriesType : typeof SeriesType . Line ; curve ? : CurveType ; lineSeriesStyle ? : RecursivePartial < LineSeriesStyle > ; /**
     * An optional functional accessor to return custom color or style for point datum
     */ pointStyleAccessor ? : PointStyleAccessor ; /**
     * Fit config to fill `null` values in dataset
     */ fit ? : Exclude < Fit , 'explicit' > | FitConfig ; } ; alpha export type BubbleSeriesSpec < D extends BaseDatum = Datum > = BasicSeriesSpec < D , 'bubble' > & { defaultValue `bubble`  {@link (SeriesType:type) | SeriesType.Bubble} seriesType : typeof SeriesType . Bubble ; bubbleSeriesStyle ? : RecursivePartial < BubbleSeriesStyle > ; /**
     * An optional functional accessor to return custom color or style for point datum
     */ pointStyleAccessor ? : PointStyleAccessor ; } ; public export type AreaSeriesSpec < D extends BaseDatum = Datum > = BasicSeriesSpec < D , 'area' > & HistogramConfig & Postfixes & { defaultValue `area`  {@link (SeriesType:type) | SeriesType.Area} seriesType : typeof SeriesType . Area ; /** The type of interpolator to be used to interpolate values between points */ curve ? : CurveType ; areaSeriesStyle ? : RecursivePartial < AreaSeriesStyle > ; /**
     * Stack each series using a specific mode: Percentage, Wiggle, Silhouette.
     * The last two modes are generally used for stream graphs
     */ stackMode ? : StackMode ; /**
     * An optional functional accessor to return custom color or style for point datum
     */ pointStyleAccessor ? : PointStyleAccessor ; /**
     * Fit config to fill `null` values in dataset
     */ fit ? : Exclude < Fit , 'explicit' > | FitConfig ; } ; public export interface HistogramConfig { defaultValue histogramModeAlignment ? : HistogramModeAlignment ; } public export const HistogramModeAlignments = Object . freeze ( { Start : 'start' as HistogramModeAlignment , Center : 'center' as HistogramModeAlignment , End : 'end' as HistogramModeAlignment , } ) ; public export type HistogramModeAlignment = 'start' | 'center' | 'end' ; public export interface AxisSpec extends Spec { specType : typeof SpecType . Axis ; chartType : typeof ChartType . XYAxis ; /** The ID of the spec */ id : AxisId ; /** Style options for grid line */ gridLine ? : Partial < GridLineStyle > ; defaultValue DEFAULT_GLOBAL_ID groupId : GroupId ; /** Hide this axis */ hide : boolean ; /** shows all ticks and gridlines, including those belonging to labels that got culled due to overlapping with other labels */ showOverlappingTicks : boolean ; /** Shows all labels, also the overlapping ones */ showOverlappingLabels : boolean ; defaultValue deprecated showGridLines ? : boolean ; /** Where the axis appear on the chart */ position : Position ; /**
     * A function called to format every tick value label.
     * Uses first series spec `tickFormat` when not provided.
     *
     * used in tooltip when no `tickFormat` is provided from series spec
     */ tickFormat ? : TickFormatter ; /**
     * A function called to format every label  (excludes tooltip)
     *
     * overrides tickFormat for axis labels
     */ labelFormat ? : TickFormatter ; /** An approximate count of how many ticks will be generated */ ticks ? : number ; /** The axis title */ title ? : string ; /** Custom style overrides */ style ? : RecursivePartial < Omit < AxisStyle , 'gridLine' > > ; /** If specified, it constrains the domain for these values */ domain ? : YDomainRange ; /** Show only integar values * */ integersOnly ? : boolean ; defaultValue showDuplicatedTicks ? : boolean ; alpha defaultValue timeAxisLayerCount : number ; } public export type TickFormatterOptions = { timeZone ? : string ; } ; public export type TickFormatter < V = any > = ( value : V , options ? : TickFormatterOptions ) => string ; public export const AnnotationType = Object . freeze ( { Line : 'line' as const , Rectangle : 'rectangle' as const , Text : 'text' as const , } ) ; public export type AnnotationType = $Values < typeof AnnotationType > ; public export const AnnotationDomainType = Object . freeze ( { XDomain : 'xDomain' as const , YDomain : 'yDomain' as const , } ) ; public export type AnnotationDomainType = $Values < typeof AnnotationDomainType > ; public export interface LineAnnotationDatum < D = any > { /**
     * The value on the x or y axis according to the domainType configured
     */ dataValue : D ; /**
     * A textual description of the annotation
     */ details ? : string ; /**
     * An header of the annotation. If undefined, than the formatted dataValue will be used
     */ header ? : string ; } public export type LineAnnotationSpec < D = any > = BaseAnnotationSpec < typeof AnnotationType . Line , LineAnnotationDatum < D > , LineAnnotationStyle , D > & { domainType : AnnotationDomainType ; /** Optional Custom marker icon centered on data value */ marker ? : ReactNode | ComponentWithAnnotationDatum < D > ; /** Optional marker body, always contained within chart area */ markerBody ? : ReactNode | ComponentWithAnnotationDatum < D > ; /**
     * Custom marker dimensions; will be computed internally
     * Any user-supplied values will be overwritten
     */ markerDimensions ? : { width : number ; height : number ; } ; remarks markerPosition ? : Position ; /** Annotation lines are hidden */ hideLines ? : boolean ; defaultValue hideLinesTooltips ? : boolean ; defaultValue zIndex ? : number ; } ; public export interface RectAnnotationDatum { /**
     * The coordinates for the 4 rectangle points.
     */ coordinates : { /**
         * The minuimum value on the x axis. If undefined, the minuimum value of the x domain will be used.
         */ x0 ? : PrimitiveValue ; /**
         * The maximum value on the x axis. If undefined, the maximum value of the x domain will be used.
         */ x1 ? : PrimitiveValue ; /**
         * The minimum value on the y axis. If undefined, the minimum value of the y domain will be used.
         */ y0 ? : PrimitiveValue ; /**
         * The maximum value on the y axis. If undefined, the maximum value of the y domain will be used.
         */ y1 ? : PrimitiveValue ; } ; /**
     * A textual description of the annotation
     */ details ? : string ; } public export type RectAnnotationSpec = BaseAnnotationSpec < typeof AnnotationType . Rectangle , RectAnnotationDatum , RectAnnotationStyle > & { deprecated renderTooltip ? : AnnotationTooltipFormatter ; defaultValue zIndex ? : number ; defaultValue outside ? : boolean ; /**
     * Dimension, either height or width, of outside annotation
     */ outsideDimension ? : number ; } ; public export type AnnotationPortalSettings = TooltipPortalSettings < 'chart' > & { public customTooltip ? : CustomAnnotationTooltip ; public customTooltipDetails ? : AnnotationTooltipFormatter ; } ; public export interface BaseAnnotationSpec < T extends typeof AnnotationType . Rectangle | typeof AnnotationType . Line , AD extends RectAnnotationDatum | LineAnnotationDatum < D > , S extends RectAnnotationStyle | LineAnnotationStyle , D = never > extends Spec , AnnotationPortalSettings { chartType : typeof ChartType . XYAxis ; specType : typeof SpecType . Annotation ; /**
     * Annotation type: line, rectangle
     */ annotationType : T ; defaultValue DEFAULT_GLOBAL_ID groupId : GroupId ; /**
     * Data values defined with coordinates and details
     */ dataValues : AD [ ] ; /**
     * Custom annotation style
     */ style ? : Partial < S > ; /**
     * Toggles tooltip annotation visibility
     */ hideTooltips ? : boolean ; /**
     * z-index of the annotation relative to other elements in the chart
     * Default specified per specific annotation spec.
     */ zIndex ? : number ; } public export type AnnotationSpec < D extends BaseDatum = any > = LineAnnotationSpec < D > | RectAnnotationSpec ; internal export function isLineAnnotation < D > ( spec ) { return spec . annotationType === AnnotationType . Line ; } internal export function isRectAnnotation ( spec ) { return spec . annotationType === AnnotationType . Rectangle ; } internal export function isBarSeriesSpec < D extends BaseDatum > ( spec ) { return spec . seriesType === SeriesType . Bar ; } internal export function isBubbleSeriesSpec < D extends BaseDatum > ( spec ) { return spec . seriesType === SeriesType . Bubble ; } internal export function isLineSeriesSpec < D extends BaseDatum > ( spec ) { return spec . seriesType === SeriesType . Line ; } internal export function isAreaSeriesSpec < D extends BaseDatum > ( spec ) { return spec . seriesType === SeriesType . Area ; }