import type { ReactNode } from 'react'; import type { ConvertibleUnit, FormatDateOptions, FormatOptions, Unit } from '@dynatrace-sdk/units'; import type { BAR_VARIANT_GROUP, BAR_VARIANT_SINGLE, BAR_VARIANT_STACK, BarSeriesVariant, SeriesCurve, XYChartAreaSeries, XYChartAreaSeriesActionItem, XYChartBarSeries, XYChartBarSeriesActionItem, XYChartColorPalette, XYChartData, XYChartDotSeries, XYChartDotSeriesActionItem, XYChartLineSeries, XYChartLineSeriesActionItem, XYChartRectSeries, XYChartRectSeriesActionItem, XYChartThresholdDynamicData, XYChartThresholdStaticData, XYChartTooltipPayload, XYChartXAxisPosition, XYChartYAxisPosition } from './xy-chart.js'; import { IntentProps } from '../../../core/slots/Intent/Intent.js'; import type { BehaviorTrackingProps } from '../../../core/types/behavior-tracking-props.js'; import type { MaskingProps } from '../../../core/types/masking-props.js'; import type { StylingProps } from '../../../core/types/styling-props.js'; import type { TruncationMode } from '../../../typography/text-ellipsis/TextEllipsis.js'; import type { TickLabelLayout } from '../../core/components/axes/types.js'; import type { PointsDisplay } from '../../core/components/canvas/types/canvas-shape.js'; import type { PointShapeType } from '../../core/components/shape/type.js'; import type { ChartUnit } from '../../core/types/chart-unit.js'; import type { ColorRuleProps } from '../../core/types/color-rule.js'; import type { CategoricalFormatter, Formatter, TimeFormatter } from '../../core/types/formatter.js'; import type { NumericalGapPolicy, TimeGapPolicy } from '../../core/types/gap-policy.js'; import type { ZoomChangeHandler } from '../../core/types/interactions.js'; import type { LegendProps } from '../../core/types/legend.js'; import type { MaxScaleBoundary, MinScaleBoundary } from '../../core/types/min-max-config.js'; import type { ValueRepresentation } from '../../core/types/scales.js'; import type { SeriesActionsTemplate } from '../../core/types/series-actions-template.js'; import { BaseThresholdConfig } from '../../core/types/thresholds.js'; import type { ChartToolbarConfig } from '../../core/types/toolbar.js'; import type { ChartTooltipConfigProps } from '../../core/types/tooltip.js'; import { XYChartAnnotationsConfigProps } from '../context/XYChartAnnotationsConfig.context.js'; import type { XYChartSelectProps } from '../slots/Select.js'; /** * Props for the xy chart. * @public */ export interface XYChartProps extends StylingProps, MaskingProps, BehaviorTrackingProps { /** * Data object for the xy chart. */ data: XYChartData[]; /** * Chart height. When a number is specified, it's treated as pixels, * otherwise a valid height string is expected. * @defaultValue 300px */ height?: number | string; /** * Chart width. When a number is specified, it's treated as pixels, * otherwise a valid width string is expected. * @defaultValue 100% */ width?: number | string; /** * Color palette for the xy chart. * @defaultValue 'blue' */ colorPalette?: XYChartColorPalette; /** Show the loading indicator when truthy. * @defaultValue false */ loading?: boolean; /** * Truncation mode to be used as start, middle or end, and applied to all the parts that truncate text. * @defaultValue 'middle' */ truncationMode?: TruncationMode; /** * Callback invoked when a download is triggered. Receives the CSV string * so the caller can drive the actual download (e.g. for migration purposes). * When provided, the default browser download is skipped. * @internal */ __downloadDataCallback?: () => void; } /** * Base series props for the XY chart * @public */ export interface XYChartSeriesBaseProps { /** * Data object for the xy chart. */ data?: XYChartData[]; /** * Unique Id required to attach the series to its x-axis. */ xAxisId: string; /** * Unique Id required to attach the series to its y-axis. */ yAxisId: string; /** * Accessor function to retrieve the data for the x0. */ x0Accessor: string; /** * Accessor function to retrieve the data for the y0. */ y0Accessor: string; /** * Color palette for the series. * @defaultValue 'blue' */ colorPalette?: XYChartColorPalette; } /** * Props for the rect slot of the xy chart. * @public */ export interface XYChartRectSeriesProps extends XYChartSeriesBaseProps { /** * Accessor function to retrieve the data for the x1. */ x1Accessor?: string; /** * Accessor function to retrieve the data for the y1. */ y1Accessor?: string; /** * Accessor function to retrieve the data for the value. */ valueAccessor: string; /** * A custom label to overwrite the valueAccessor when naming the value */ valueAccessorLabel?: string; /** * If specified, all values coming from the valueAccessor that are under this number will display a default color. * Doesn't apply for category values. */ valueMin?: number; /** * If specified, all values coming from the valueAccessor that are above this number will display a default color. * Doesn't apply for category values. */ valueMax?: number; /** * If specified, the value coming from the valueAccessor will be formatted with given formatter options. * Doesn't apply for string values. */ valueFormatter?: Formatter | FormatOptions; /** * A custom unit to be displayed in the Legend for number values */ valueUnit?: ChartUnit; /** * Custom actions to be shown in the tooltip and legend. * For tooltip, information about the selected datapoint is displayed. * For legend, the first parameter returns the first datapoint of the series and the second parameter returns the series object. */ actions?: (datapoint: XYChartRectSeriesActionItem, series?: XYChartRectSeries) => SeriesActionsTemplate; } /** * Color selection prop for the xy chart ensures that either a color or a color palette is used, but not both simultaneously. * @public * @deprecated - Use ShapeColorSelectionProp instead. This key will be removed in a future release. */ export type ColorSelectionProp = { /** Custom color to represent this series. Overrides the colorPalette config. Eg: '#e1e1e1'**/ color?: never; colorPalette?: XYChartColorPalette; } | { /** Custom color to represent this series. Overrides the colorPalette config. Eg: '#e1e1e1'**/ color?: string; colorPalette?: never; }; /** * Props for the dot series slot of the xy chart. * @public */ export type XYChartDotSeriesProps = XYChartSeriesBaseProps & ShapeColorSelectionProp & { /** * Series name. * @deprecated - Use nameAccessor instead. This key will be removed in a future release. */ name?: string; /** * Accessor function to retrieve the data for the x1. */ x1Accessor?: string; /** * Accessor function to retrieve the data for the y1. */ y1Accessor?: string; /** * Series ID accessor. */ seriesIdAccessor?: string; /** * Series name accessor. */ nameAccessor?: string; /** * Custom actions to be shown in the tooltip and legend. * For tooltip, information about the selected datapoint is displayed. * For legend, the first parameter returns the first datapoint of the series and the second parameter returns the series object. */ actions?: (datapoint: XYChartDotSeriesActionItem, series?: XYChartDotSeries) => SeriesActionsTemplate; /** * Determines the visual appearance of the dot, such as 'circle', 'square', 'diamond', or 'triangle'. * @defaultValue 'circle' */ shape?: PointShapeType; }; /** * Color options specific for the Line Series * @public */ export type XYShapeColorProp = string | ((d: XYChartData) => string); /** * Color Palette options specific for the Line Series * @public */ export type XYShapeColorPaletteProp = XYChartColorPalette | ((d: XYChartData) => XYChartColorPalette); /** * Color selection prop for the xy chart ensures that either a color or a color palette is used, but not both simultaneously. * @public */ export type ShapeColorSelectionProp = { color?: never; colorPalette?: XYShapeColorPaletteProp; } | { color?: XYShapeColorProp; colorPalette?: never; }; /** * Props for the line series slot of the xy chart. * @public */ export type XYChartLineSeriesProps = Omit & ShapeColorSelectionProp & { /** * Accessor function to retrieve the data for the x1. */ x1Accessor?: string; /** * Accessor function to retrieve the data for the y1. */ y1Accessor?: string; /** * Series ID accessor. */ seriesIdAccessor: string; /** * Series name accessor. */ nameAccessor: string; /** * Custom actions to be shown in the tooltip and legend. * For tooltip, information about the selected datapoint is displayed. * For legend, the first parameter returns the first datapoint of the series and the second parameter returns the series object. */ actions?: (datapoint: XYChartLineSeriesActionItem, series?: XYChartLineSeries) => SeriesActionsTemplate; /** * Show the datapoints always, never or auto based on a threshold amount. * @defaultValue 'auto' */ pointsDisplay?: PointsDisplay; /** * Line interpolation curve type */ curve?: SeriesCurve; }; /** * Configuration for the XYChart.Select slot component. * @public */ export type XYChartSelectConfig = XYChartSelectProps; /** * Props for the single and group bar series slot of the xy chart. * @public */ export type BaseBarSeriesProps = Omit & ShapeColorSelectionProp & { variant: BarSeriesVariant; seriesIdAccessor: string; nameAccessor: string; }; /** * Props for the vertical grouped bar series slot of the xy chart. * @public */ export type GroupBarVerticalProps = BaseBarSeriesProps & { variant: typeof BAR_VARIANT_GROUP; x0Accessor: string; y1Accessor: string; y0Accessor?: string; x1Accessor?: never; }; /** * Props for the horizontal grouped bar series slot of the xy chart. * @public */ export type GroupBarHorizontalProps = BaseBarSeriesProps & { variant: typeof BAR_VARIANT_GROUP; y0Accessor: string; x1Accessor: string; x0Accessor?: string; y1Accessor?: never; }; /** * Props for the grouped bar series slot of the xy chart. * @public */ export type GroupBarSeriesProps = GroupBarVerticalProps | GroupBarHorizontalProps; /** * Props for the single and group bar series slot of the xy chart. * @public */ export type SingleBarSeriesProps = BaseBarSeriesProps & { variant: typeof BAR_VARIANT_SINGLE; x0Accessor?: string; x1Accessor?: string; y0Accessor?: string; y1Accessor?: string; }; /** * Props for the vertical stacked bar series slot of the xy chart. * @public */ export type StackBarVerticalProps = BaseBarSeriesProps & { variant: typeof BAR_VARIANT_STACK; x0Accessor: string; y1Accessor: string; x1Accessor?: string; y0Accessor?: never; }; /** * Props for the horizontal stacked bar series slot of the xy chart. * @public */ export type StackBarHorizontalProps = BaseBarSeriesProps & { variant: typeof BAR_VARIANT_STACK; y0Accessor: string; x1Accessor: string; y1Accessor?: string; x0Accessor?: never; }; /** * Props for the stacked bar series slot of the xy chart. * @public */ export type StackBarSeriesProps = StackBarVerticalProps | StackBarHorizontalProps; /** * Maps each bar series variant to its corresponding props type. * @public */ export type BarSeriesVariantMap = { single: SingleBarSeriesProps; stack: StackBarSeriesProps; group: GroupBarSeriesProps; }; /** * Generic type for bar series props based on the variant. * @public */ export type BarSeriesProps = BarSeriesVariantMap[T]; /** * Props for the bar series slot of the xy chart. * @public */ export type XYChartBarSeriesProps = (BarSeriesProps | BarSeriesProps | BarSeriesProps) & { /** * Custom actions to be shown in the tooltip and legend. * For tooltip, information about the selected datapoint is displayed. * For legend, the first parameter returns the first datapoint of the series and the second parameter returns the series object. */ actions?: (datapoint: XYChartBarSeriesActionItem, series?: XYChartBarSeries) => SeriesActionsTemplate; }; /** * Props for the single area series slot of the xy chart. * @public */ export type XYChartAreaSeriesProps = Omit & ShapeColorSelectionProp & { x0Accessor?: string; y0Accessor?: string; x1Accessor?: string; y1Accessor?: string; seriesIdAccessor: string; nameAccessor: string; /** * Show the datapoints always, never or auto based on a threshold amount. * @defaultValue 'auto' */ pointsDisplay?: PointsDisplay; /** * Area interpolation curve type */ curve?: SeriesCurve; /** * Custom actions to be shown in the legend. * (Upcoming for tooltip) * For legend, the first parameter returns the first datapoint of the series and the second parameter returns the series object. */ actions?: (datapoint: XYChartAreaSeriesActionItem, series?: XYChartAreaSeries) => SeriesActionsTemplate; }; /** * Props for the x-axis of the xy chart. * @public */ export type XYChartAxisProps = XYChartAxisBaseProps & (XYChartNumericalAxisProps | XYChartLogAxisProps | XYChartCategoricalAxisProps | XYChartTimeAxisProps); /** * Props definition for the XYChart toolbar * @internal */ export type XYChartToolbar = Omit & BehaviorTrackingProps & { intents?: Array; }; /** * XYChart Log Axis Props * @public */ export interface XYChartLogAxisProps extends XYChartAxisBaseProps { /** * Specifies the type of axis, should be 'log' for a logarithmic scale. */ type: 'log'; /** * If specified, value will be formatted with given formatter options. */ formatter?: Formatter | FormatOptions; /** * The max value configuration to display in the axis * @defaultValue 'auto' */ max?: MaxScaleBoundary; /** * The min value configuration to display in the axis * @defaultValue 'auto' */ min?: MinScaleBoundary; /** * The unit for the xy chart axis ticks. */ unit?: ChartUnit; /** * Used to define how gaps in data should be handled * @defaultValue 'connect' */ gapPolicy?: NumericalGapPolicy; } /** * Base props for all axis types * @public */ export interface XYChartAxisBaseProps { /** * Id for the axis used to bind any series to it. */ id: string; /** * A text label to display alongside the axis. */ label?: string; /** * If true, will visually hide the whole axis. * @defaultValue false */ hidden?: boolean; /** * Whether to reverse the min and max values from the axis. * @defaultValue false */ reversed?: boolean; /** Max size in pixels. Size depends on the position this axis is assigned to – left and right axis will use width; bottom and top axis will use height. * If there's not enough space for this tickLabelMaxSize, the axis will only take the available space for it. */ tickLabelMaxSize?: number; } /** * XYChart Numerical Axis Props * @public */ export interface XYChartNumericalAxisProps extends XYChartAxisBaseProps { type: 'numerical'; /** * The max value configuration to display in the axis * @defaultValue 'auto' */ max?: MaxScaleBoundary; /** * The min value configuration to display in the axis * @defaultValue 'auto' */ min?: MinScaleBoundary; /** * If specified, value will be formatted with given formatter options. */ formatter?: Formatter | FormatOptions; /** * The unit for the xy chart axis ticks. */ unit?: ChartUnit; /** * Used to define how gaps in data should be handled * @defaultValue 'connect' */ gapPolicy?: NumericalGapPolicy; /** * Represents data as absolute or relative values. * @defaultValue 'absolute' */ valueRepresentation?: ValueRepresentation; } /** * Props for the categorical axis * @public */ export interface XYChartCategoricalAxisProps extends XYChartAxisBaseProps { type: 'categorical'; /** * If specified, categorical tick labels will be formatted with the given formatter function or options. */ formatter?: CategoricalFormatter | FormatOptions; } /** * XYChart Time based Axis Props * @public */ export interface XYChartTimeAxisProps extends XYChartAxisBaseProps { type: 'time'; /** * The max value configuration to display in the axis * @defaultValue 'auto' */ min?: 'auto' | 'data-min' | number | Date; /** * The min value configuration to display in the axis * @defaultValue 'auto' */ max?: 'auto' | 'data-max' | number | Date; /** * If specified, value will be formatted with given formatter options. */ formatter?: TimeFormatter | FormatDateOptions; /** * Used to define how gaps in data should be handled * @defaultValue 'gap' */ gapPolicy?: TimeGapPolicy; } /** * Configuration properties for the XY Charts. * @public */ export interface XYChartConfigProperties { /** * Legend configuration */ legend?: XYChartChartLegendProps; /** * Color Palette configuration */ colorPalette?: XYChartColorPalette; /** * X Axes configuration */ xAxes?: XYChartXAxisProps[]; /** * Toolbar configuration */ toolbar?: XYChartToolbarProps; truncationMode?: TruncationMode; /** * Y Axes configuration */ yAxes?: XYChartYAxisProps[]; /** * Threshold indicators configuration */ thresholdIndicators?: XYChartThresholdIndicatorProps[]; /** * Annotations configuration */ annotations?: XYChartAnnotationsConfigProps; /** * Select configuration */ select?: XYChartSelectConfig; /** * Color rules configuration */ colorRules?: ColorRuleProps[]; /** * Custom tooltip configuration * @deprecated Use `tooltip` in `XYChartConfigProperties` instead. (APPDEV-17650) */ customTooltip?: XYChartCustomTooltipProps; /** * Tooltip configuration */ tooltip?: ChartTooltipConfigProps; } /** * Props for the XYChart.CustomTooltip slot component * @public * @deprecated Use `XYChart.Tooltip` instead. The `CustomTooltip` slot will be removed in a future release. */ export type XYChartCustomTooltipProps = { /** * The children function receives the tooltip payload and returns custom tooltip content as React nodes. * Return null to hide the tooltip, or undefined to use the default. */ children?: (tooltipPayload: XYChartTooltipPayload) => ReactNode; }; /** * Props for the XYChart.Legend slot component * @public */ export type XYChartChartLegendProps = LegendProps; /** * Props for the x-axis of the xy chart. * @public */ export type XYChartXAxisProps = XYChartAxisProps & { /** * Whether the tick labels are displayed in a 'vertical' or 'horizontal' layout. * @defaultValue 'horizontal' */ tickLabelLayout?: TickLabelLayout; /** The position for the xy chart x-axis */ position: XYChartXAxisPosition; /** If true, the zoom interaction will be disabled * @defaultValue false */ disableZoom?: boolean; /** If true, the pan interaction will be disabled * @defaultValue false */ disablePan?: boolean; /** Sets the new zoom and pan domain boundaries, overwriting the ones that come from the data */ initialZoom?: [Date, Date] | [number, number]; /** Sets the domain of the axis to start at the specified values */ currentZoom?: [Date, Date] | [number, number]; /** If true, the chart will be able to zoom and pan outside the set boundaries * @defaultValue false */ infiniteZoom?: boolean; /** Handler triggered when there is a change on the time domain caused by a zoom action */ onZoomChange?: ZoomChangeHandler; }; /** * Props for the y-axis of the xy chart. * @public */ export type XYChartYAxisProps = XYChartAxisProps & { position: XYChartYAxisPosition; }; /** * Props for the XYChart config provider component * @public */ export type XYChartToolbarConfigProps = Omit & { /** Decides if the toolbar is visible or hidden * @defaultValue false */ hidden?: boolean; }; /** * Props for the XYChart config provider component * @deprecated - Use XYChartToolbarConfigProps instead. This Type will be removed in a future release. * @public */ export type XYChartToolbarProps = Omit & { /** Decides if the toolbar is visible or hidden * @defaultValue false */ hidden?: boolean; }; /** * Props for the XYChart.Toolbar slot component * @public */ export interface XYChartToolbarSlotProps extends Omit, BehaviorTrackingProps { /** * When enabled show the toolbar in collapsed state * @deprecated - This key will be removed in a future release */ collapsed?: boolean; } /** * Props for the XYChart.ThresholdIndicator slot component * @public */ export type XYChartThresholdIndicatorProps = XYChartThresholdStaticProps | XYChartThresholdDynamicProps; /** * Props for the Dynamic XYChart.ThresholdIndicator slot component * @public */ export type XYChartThresholdDynamicProps = BaseThresholdConfig & { data: XYChartThresholdDynamicData[]; xAxisId: string; yAxisId: string; }; /** * Props for the Static XYChart.ThresholdIndicator slot component * @public */ export type XYChartThresholdStaticProps = BaseThresholdConfig & { data: XYChartThresholdStaticData; yAxisId: string; };