From 2a5eaca310d7ce51f1e8392242e792a2df16ced2 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sat, 11 Mar 2023 08:30:33 -0500 Subject: [PATCH] Split the TimeScaleOptions type into composable sub types --- src/types/index.d.ts | 110 ++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/src/types/index.d.ts b/src/types/index.d.ts index c4f042ec16e..224482bd571 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -3298,6 +3298,61 @@ export declare const LogarithmicScale: ChartComponent & { new (cfg: AnyObject): LogarithmicScale; }; +export type TimeScaleTimeOptions = { + /** + * Custom parser for dates. + */ + parser: string | ((v: unknown) => number); + /** + * If defined, dates will be rounded to the start of this unit. See Time Units below for the allowed units. + */ + round: false | TimeUnit; + /** + * If boolean and true and the unit is set to 'week', then the first day of the week will be Monday. Otherwise, it will be Sunday. + * If `number`, the index of the first day of the week (0 - Sunday, 6 - Saturday). + * @default false + */ + isoWeekday: boolean | number; + /** + * Sets how different time units are displayed. + */ + displayFormats: { + [key: string]: string; + }; + /** + * The format string to use for the tooltip. + */ + tooltipFormat: string; + /** + * If defined, will force the unit to be a certain type. See Time Units section below for details. + * @default false + */ + unit: false | TimeUnit; + /** + * The minimum display format to be used for a time unit. + * @default 'millisecond' + */ + minUnit: TimeUnit; +}; + +export type TimeScaleTickOptions = { + /** + * Ticks generation input values: + * - 'auto': generates "optimal" ticks based on scale size and time options. + * - 'data': generates ticks from data (including labels from data `{t|x|y}` objects). + * - 'labels': generates ticks from user given `data.labels` values ONLY. + * @see https://github.com/chartjs/Chart.js/pull/4507 + * @since 2.7.0 + * @default 'auto' + */ + source: 'labels' | 'auto' | 'data'; + /** + * The number of units between grid lines. + * @default 1 + */ + stepSize: number; +}; + export type TimeScaleOptions = Omit & { min: string | number; max: string | number; @@ -3326,60 +3381,9 @@ export type TimeScaleOptions = Omit & { date: unknown; }; - time: { - /** - * Custom parser for dates. - */ - parser: string | ((v: unknown) => number); - /** - * If defined, dates will be rounded to the start of this unit. See Time Units below for the allowed units. - */ - round: false | TimeUnit; - /** - * If boolean and true and the unit is set to 'week', then the first day of the week will be Monday. Otherwise, it will be Sunday. - * If `number`, the index of the first day of the week (0 - Sunday, 6 - Saturday). - * @default false - */ - isoWeekday: boolean | number; - /** - * Sets how different time units are displayed. - */ - displayFormats: { - [key: string]: string; - }; - /** - * The format string to use for the tooltip. - */ - tooltipFormat: string; - /** - * If defined, will force the unit to be a certain type. See Time Units section below for details. - * @default false - */ - unit: false | TimeUnit; - /** - * The minimum display format to be used for a time unit. - * @default 'millisecond' - */ - minUnit: TimeUnit; - }; + time: TimeScaleTimeOptions; - ticks: { - /** - * Ticks generation input values: - * - 'auto': generates "optimal" ticks based on scale size and time options. - * - 'data': generates ticks from data (including labels from data `{t|x|y}` objects). - * - 'labels': generates ticks from user given `data.labels` values ONLY. - * @see https://github.com/chartjs/Chart.js/pull/4507 - * @since 2.7.0 - * @default 'auto' - */ - source: 'labels' | 'auto' | 'data'; - /** - * The number of units between grid lines. - * @default 1 - */ - stepSize: number; - }; + ticks: TimeScaleTickOptions; }; export interface TimeScale extends Scale {