import { type ReactElement, type ReactNode } from 'react'; import type { StylingProps, MaskingProps, DataTestId } from '@dynatrace/strato-components/core'; import type { TruncationMode } from '@dynatrace/strato-components/typography'; import type { ConvertibleUnit, FormatOptions, Unit } from '@dynatrace-sdk/units'; import type { PieChartToolbarConfig } from './toolbar.js'; import type { CustomColorPalette, ColorPalette } from '../../core/types/color-palette.js'; import type { Formatter } from '../../core/types/formatter.js'; import type { LegendProps } from '../../core/types/legend.js'; /** * @public */ export type SliceUnit = string; /** * @public */ export interface SliceData { /** The category of the slice*/ category: string; /** The value of the slice */ value: number; /** The color of the slice. Overrides the color assigned from the color palette. */ color?: string; } /** * @public */ export interface PieChartData { /** Slice data array */ slices: SliceData[]; /** The unit of the slices */ unit?: SliceUnit; } /** * @public */ export interface PieChartProps extends StylingProps, MaskingProps, DataTestId { /** * Categorical data of the chart. */ data: PieChartData; /** * Chart width. A number in pixels is expected. Otherwise, it will take the full width of the container. */ width?: number; /** The height of the chart. If a number is passed, it will be treated as px. * @defaultValue 300px. */ height?: number | string; /** * Set of Color palette to be used in charts. * @defaultValue 'categorical'. */ colorPalette?: ColorPalette | CustomColorPalette; /** * Custom Formatter for the chart */ formatter?: Formatter | FormatOptions; /** * Truncation mode to use (start, middle, end) * Applied to all the parts that truncate text. * @defaultValue 'middle' */ truncationMode?: TruncationMode; /** Exposed callback to display series actions for a slice */ seriesActions?: (slice: SliceData) => ReactElement; /** Show the loading indicator when truly. * @defaultValue false */ loading?: boolean; } /** * @public */ export interface PieChartContextConfig { /** * Set of Color palette to be used in charts. * @defaultValue 'categorical'. */ colorPalette?: ColorPalette | CustomColorPalette; /** * Config for the labels of the pie chart slices. */ labels?: LabelsConfig; /** * Group configuration for the pie chart. * Aggregates multiple slices into a group (matches threshold config). */ grouping?: GroupConfig; /** * Legend configuration for the pie chart */ legend?: PieChartLegendConfig; /** * Custom Formatter for the chart */ formatter?: Formatter | FormatOptions; /** * Truncation mode to use (start, middle, end) * Applied to all the parts that truncate text. * @defaultValue 'middle' */ truncationMode?: TruncationMode; /** * Toolbar configuration */ toolbar?: PieChartToolbarConfig; /** Callback to display series actions for a slice */ seriesActions?: (slice: SliceData) => ReactElement; } /** * @internal */ export type DonutChartContextConfig = PieChartContextConfig; /** * @public */ export interface PieChartConfiguration extends PieChartContextConfig { /** The height of the chart. If a number is passed, it will be treated as px. * @defaultValue 300px. */ height?: number | string; } /** * @internal */ export type DonutChartConfiguration = PieChartConfiguration; /** * @internal */ export type RequiredPieChartConfiguration = Required> & { toolbar?: PieChartToolbarConfig; innerElement?: InnerHandler | ReactNode; }; /** * @internal */ export type RequiredDonutChartConfiguration = RequiredPieChartConfiguration; /** * @internal */ export type NotRequiredPieChartConfiguration = { seriesActions?: (slice: SliceData) => ReactElement; }; /** * @internal */ export type NotRequiredDonutChartConfiguration = NotRequiredPieChartConfiguration; /** * @internal */ export type PieDonutConfig = (RequiredPieChartConfiguration | RequiredDonutChartConfiguration) & (NotRequiredPieChartConfiguration | NotRequiredDonutChartConfiguration); /** * @public */ export type LabelTypeOptions = 'absolute' | 'relative'; /** * @public */ export interface LabelsConfig { /** * Hides the slice labels. * @defaultValue false (all the labels are displayed). */ hidden?: boolean; /** * Display the label with a relative or absolute value. * @defaultValue 'relative' */ valueType?: LabelTypeOptions; } /** * @public */ export declare const thresholdTypeOptions: readonly ["absolute", "relative", "number-of-slices"]; /** * @public */ export type ThresholdType = (typeof thresholdTypeOptions)[number]; /** * @public */ export interface ThresholdConfig { /** * Type of the grouping threshold. Can be "relative", "absolute" or "number-of-slices". * @defaultValue 'relative'. */ type: ThresholdType; /** * Value of the group threshold. * Default is dynamically calculated depending on the chart size for relative and absolute. 10 in case of number-of-slices. */ value: number; } /** * @public */ export interface GroupConfig { /** * Name of the group. * @defaultValue 'Other'. */ name?: string; /** * The threshold for the group. */ threshold: ThresholdConfig; } /** * @public */ export type PieChartLegendConfig = LegendProps; /** * @public */ export type DonutChartData = PieChartData; /** * @public */ export interface DonutChartProps extends StylingProps, MaskingProps, DataTestId { /** * Categorical data of the chart. */ data: DonutChartData; /** * Chart width. A number in pixels is expected. Otherwise, it will take the full width of the container. */ width?: number; /** The height of the chart. If a number is passed, it will be treated as px. * @defaultValue 300px. */ height?: number | string; /** * Set of Color palette to be used in charts. * @defaultValue 'categorical'. */ colorPalette?: ColorPalette | CustomColorPalette; /** * Custom Formatter for the chart */ formatter?: Formatter | FormatOptions; /** * Truncation mode to use (start, middle, end) * Applied to all the parts that truncate text. * @defaultValue 'middle' */ truncationMode?: TruncationMode; /** Exposed callback to display series actions for a slice */ seriesActions?: (slice: SliceData) => ReactElement; /** Show the loading indicator when truly. * @defaultValue false */ loading?: boolean; } /** * @public */ export type DonutChartLegendConfig = PieChartLegendConfig; /** * @internal */ export interface PieChartSlots { labels: Partial; grouping: Partial; legend: Partial; toolbar: Partial | undefined; innerElement?: InnerHandler | ReactNode; } /** * @internal */ export type DonutChartSlots = PieChartSlots; /** * @public */ export type InnerHandler = (value: InnerParams) => ReactNode; /** * @public */ export type InnerParams = { absoluteValue: number; relativeValue: number; dimensions: { width: number; height: number; }; };