import type { PropsWithChildren, ReactElement } from 'react'; import type { MaskingProps, StylingProps } from '@dynatrace/strato-components/core'; import type { TruncationMode } from '@dynatrace/strato-components/typography'; import type { ConvertibleUnit, FormatDateOptions, FormatOptions, Unit } from '@dynatrace-sdk/units'; import type { XYAxisTypeLinear, XYAxisTypeLog } from './axis.js'; import type { TickLabelLayout } from '../../core/components/axes/types.js'; import type { CanvasShapeType } from '../../core/components/canvas/utils/shapes/symbol-canvas.js'; import type { ChartUnit } from '../../core/types/chart-unit.js'; import type { ColorPalette, CustomColorPalette } from '../../core/types/color-palette.js'; import type { ColoredRange } from '../../core/types/colored-range.js'; import type { Formatter, TimeFormatter } from '../../core/types/formatter.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 { BaseThresholdConfig } from '../../core/types/thresholds.js'; import type { ChartToolbarConfig } from '../../core/types/toolbar.js'; import { ProgrammaticZoomHandlers } from '../../core/types/zoom.js'; import { XYChartAnnotationsConfigProps } from '../context/XYChartAnnotationsConfig.context.js'; /** * Props for the xy chart. * @public */ export interface XYChartProps extends StylingProps, MaskingProps { /** * 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. A number in pixels is expected. Otherwise, it will take the full width of the container * @defaultValue 100% */ width?: number; /** * 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; } /** * Data type for the XY chart * @public */ export type XYChartData = Record; /** * 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 */ actions?: (datapoint: XYChartRectSeriesActionItem) => ReactElement; } /** * 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 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 & ColorSelectionProp & { /** * Series name. */ name: string; /** * Accessor function to retrieve the data for the x1. */ x1Accessor?: string; /** * Accessor function to retrieve the data for the y1. */ y1Accessor?: string; /** * Custom actions to be shown in the tooltip */ actions?: (datapoint: XYChartDotSeriesActionItem) => ReactElement; /** * Determines the visual appearance of the dot, such as 'circle', 'square', 'diamond', or 'triangle'. * @defaultValue 'circle' */ shape?: CanvasShapeType; }; /** * Props for the x-axis of the xy chart. * @public */ export type XYChartAxisProps = XYChartAxisBaseProps & (XYChartNumericalAxisProps | XYChartLogAxisProps | XYChartCategoricalAxisProps | XYChartTimeAxisProps); export interface XYChartLinearAxisInternalProps extends Omit { type: XYAxisTypeLinear; } export interface XYChartLogAxisInternalProps extends Omit { type: XYAxisTypeLog; } /** * 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; } /** * 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; } /** * Props for the categorical axis * @public */ export interface XYChartCategoricalAxisProps extends XYChartAxisBaseProps { type: 'categorical'; } /** * 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; } /** * Color palette options for XYChart. * @public */ export type XYChartColorPalette = ColorPalette | CustomColorPalette | ColoredRange[]; /** * Props definition for the XYChartToolbarContext * @internal */ export type XYChartToolbar = XYChartToolbarProps; /** * Props definition for the XYChartLegendContext * @internal */ export type XYChartLegend = { /** * The truncation mode to be used as start, middle or end in the long legend * labels * @defaultValue 'middle' */ truncationMode: TruncationMode; }; /** * 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[]; thresholds?: XYChartThresholdProps[]; /** * Annotations configuration */ annotations?: XYChartAnnotationsConfigProps; } /** * XYChart Ref * @public */ export interface XYChartRef extends ProgrammaticZoomHandlers { /** Chart div element. */ element: HTMLDivElement | null; /** Returns the current serialized config of the XYChart. */ getConfig: () => string; /** Downloads series. */ downloadData: () => void; } /** * Props for the XYChart.Legend slot component * @public */ export type XYChartChartLegendProps = LegendProps; /** * The position for the xy chart x-axis * @public */ export type XYChartXAxisPosition = typeof BOTTOM_POSITION | typeof TOP_POSITION | typeof BOTH_POSITION; /** * The position for the xy chart y-axis * @public */ export type XYChartYAxisPosition = typeof LEFT_POSITION | typeof RIGHT_POSITION | typeof BOTH_POSITION; /** * 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.Toolbar slot component * @public */ export type XYChartToolbarProps = Omit & { /** Decides if the toolbar is visible or hidden * @defaultValue false */ hidden?: boolean; }; /** * The numerical scale type for the xy chart axis * @public */ export declare const NUMERICAL_SCALE_TYPE: "numerical"; /** * The log scale type for the xy chart axis * @public */ export declare const LOG_SCALE_TYPE: "log"; /** * The time scale type for the xy chart axis * @public */ export declare const TIME_SCALE_TYPE: "time"; /** * The categorical scale type for the xy chart axis * @public */ export declare const CATEGORICAL_SCALE_TYPE: "categorical"; /** * The data type for the xy chart axis * @public */ export type XYChartAxisType = typeof LOG_SCALE_TYPE | typeof NUMERICAL_SCALE_TYPE | typeof TIME_SCALE_TYPE | typeof CATEGORICAL_SCALE_TYPE; /** * The top position for the xy chart x-axis * @public */ export declare const TOP_POSITION: "top"; /** * The bottom position for the xy chart x-axis * @public */ export declare const BOTTOM_POSITION: "bottom"; /** * The left position for the xy chart x-axis * @public */ export declare const LEFT_POSITION: "left"; /** * The right position for the xy chart x-axis * @public */ export declare const RIGHT_POSITION: "right"; /** * The both position for the xy chart x-axis * @public */ export declare const BOTH_POSITION: "both"; /** * The valid data types for x and y accessors * @public */ export type XYAccessorDataTypes = string | number | Date; /** * The base selected datapoint information * @public */ export interface BaseDatapoint extends Record { /** * datapoint x0 value */ x0: XYAccessorDataTypes; /** * datapoint y0 value */ y0: XYAccessorDataTypes; } /** * The selected rect datapoint information * @public */ export interface RectDatapoint extends BaseDatapoint { /** * datapoint x1 value */ x1?: XYAccessorDataTypes; /** * datapoint y1 value */ y1?: XYAccessorDataTypes; /** * datapoint value */ value: number | string; } /** * The selected dot series datapoint information * @public */ export interface DotDatapoint extends BaseDatapoint { /** * datapoint x1 value, exclusive to timeframe datapoints */ x1?: Date; /** * datapoint y1 value, exclusive to timeframe datapoints */ y1?: Date; } /** * The selected dot datapoint displayed on the action * @public */ export type XYChartDotSeriesActionItem = DotDatapoint & { /** * series name */ name: string; }; /** * The selected rect datapoint displayed on the action * @public */ export type XYChartRectSeriesActionItem = RectDatapoint; /** * Props for the XYChart._Threshold slot component * @public */ export type XYChartThresholdProps = XYChartThresholdStaticProps | XYChartThresholdDynamicProps; /** * Props for the Dynamic XYChart.Threshold slot component * @public */ export type XYChartThresholdDynamicProps = BaseThresholdConfig & { data: XYChartThresholdDynamicData[]; xAxisId: string; yAxisId: string; }; /** * Props for the Static XYChart.Threshold slot component * @public */ export type XYChartThresholdStaticProps = BaseThresholdConfig & { data: XYChartThresholdStaticData; yAxisId: string; }; /** * Static threshold data: a single value or a range. * @public */ export type XYChartThresholdStaticData = XYChartThresholdDataLineStatic | XYChartThresholdDataRangeStatic; /** * Dynamic threshold data: a single value or a range, with an x coordinate. * @public */ export type XYChartThresholdDynamicData = XYChartThresholdDataLineDynamic | XYChartThresholdDataRangeDynamic; /** * All possible threshold data types for XYChart. * @public */ export type XYChartThresholdData = XYChartThresholdStaticData | XYChartThresholdDynamicData[]; /** * A single threshold datapoint (static or dynamic). * @public */ export type XYChartThresholdDatapoint = XYChartThresholdStaticData | XYChartThresholdDynamicData; /** * Value type for a threshold (number or Date). * @public */ export type XYChartThresholdValue = number | Date; /** * Base type for a line threshold (single value). * @public */ export type XYChartThresholdLineBase = { y: XYChartThresholdValue; }; /** * Base type for a range threshold (min/max). * @public */ export type XYChartThresholdRangeBase = { yMin: number | Date; yMax: number | Date; }; /** * Static line threshold data. * @public */ export type XYChartThresholdDataLineStatic = XYChartThresholdLineBase; /** * Static range threshold data. * @public */ export type XYChartThresholdDataRangeStatic = XYChartThresholdRangeBase; /** * Dynamic line threshold data (with x). * @public */ export type XYChartThresholdDataLineDynamic = XYChartThresholdLineBase & { x: XYChartThresholdValue; }; /** * Dynamic range threshold data (with x). * @public */ export type XYChartThresholdDataRangeDynamic = XYChartThresholdRangeBase & { x: XYChartThresholdValue; };