import type { ChartsColor } from '@mui/x-charts/colorPalettes'; import type { CommonSeriesType, CartesianSeriesType, SeriesId, CommonDefaultizedProps, DatasetElementType } from '@mui/x-charts/internals'; import type { DefaultizedProps } from '@mui/x-internals/types'; /** * Type representing the values of a single OHLC element. * The array contains four numbers in the following order: * [open, high, low, close]. */ export type OHLCValueType = [number, number, number, number]; /** * The OHLC fields that can be formatted individually. */ export type OHLCField = 'open' | 'high' | 'low' | 'close'; export interface OHLCSeriesType extends Omit, 'valueFormatter'>, CartesianSeriesType { type: 'ohlc'; /** * The OHLC data points. */ data?: ReadonlyArray; /** * The label to display on the tooltip or the legend. It can be a string or a function. */ label?: string | ((location: 'tooltip' | 'legend') => string); /** * Formatter used to render values in tooltip or other data display. * @param {number | null} value The individual OHLC field value to render. * @param {object} context The rendering context of the value. * @param {number} context.dataIndex The index of the data point in the series. * @param {OHLCField} context.field The OHLC field being formatted ('open', 'high', 'low', or 'close'). * @returns {string | null} The string to display or null if the value should not be shown. */ valueFormatter?: (value: number | null, context: { dataIndex: number; field: OHLCField; }) => string | null; /** * A function to transform the dataset item into an OHLC value. * @param {DatasetElementType} item The full dataset item. * @returns {OHLCValueType | null} The transformed value. */ valueGetter?: (item: DatasetElementType) => OHLCValueType | null; /** * The keys used to retrieve data from the dataset. * When provided, all of `open`, `high`, `low`, and `close` must be specified. */ datasetKeys?: { open: string; high: string; low: string; close: string; }; /** * The color of the candle body when the close price is greater than or equal to the open price. * @default (mode) => mode === 'dark' ? '#66bb6a' : '#2e7d32' */ upColor?: ChartsColor; /** * The color of the candle body when the close price is less than the open price. * @default (mode) => mode === 'dark' ? '#f44336' : '#d32f2f' */ downColor?: ChartsColor; } /** * The structured tooltip value for OHLC series. */ export type OHLCTooltipValue = Record; /** * The structured formatted tooltip value for OHLC series. */ export type OHLCFormattedValue = Record; /** * An object that allows to identify a single bar. * Used for item interaction */ export type OHLCItemIdentifier = { type: 'ohlc'; seriesId: SeriesId; dataIndex: number; }; export interface DefaultizedOHLCSeriesType extends DefaultizedProps { hidden: boolean; /** * The color of the candle body when the close price is greater than or equal to the open price. */ upColor: string; /** * The color of the candle body when the close price is less than the open price. */ downColor: string; }