Skip to content

Commit a173943

Browse files
authored
Split the TimeScaleOptions type into composable sub types (#11187)
1 parent f2cfb93 commit a173943

File tree

1 file changed

+57
-53
lines changed

1 file changed

+57
-53
lines changed

src/types/index.d.ts

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,6 +3308,61 @@ export declare const LogarithmicScale: ChartComponent & {
33083308
new <O extends LogarithmicScaleOptions = LogarithmicScaleOptions>(cfg: AnyObject): LogarithmicScale<O>;
33093309
};
33103310

3311+
export type TimeScaleTimeOptions = {
3312+
/**
3313+
* Custom parser for dates.
3314+
*/
3315+
parser: string | ((v: unknown) => number);
3316+
/**
3317+
* If defined, dates will be rounded to the start of this unit. See Time Units below for the allowed units.
3318+
*/
3319+
round: false | TimeUnit;
3320+
/**
3321+
* 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.
3322+
* If `number`, the index of the first day of the week (0 - Sunday, 6 - Saturday).
3323+
* @default false
3324+
*/
3325+
isoWeekday: boolean | number;
3326+
/**
3327+
* Sets how different time units are displayed.
3328+
*/
3329+
displayFormats: {
3330+
[key: string]: string;
3331+
};
3332+
/**
3333+
* The format string to use for the tooltip.
3334+
*/
3335+
tooltipFormat: string;
3336+
/**
3337+
* If defined, will force the unit to be a certain type. See Time Units section below for details.
3338+
* @default false
3339+
*/
3340+
unit: false | TimeUnit;
3341+
/**
3342+
* The minimum display format to be used for a time unit.
3343+
* @default 'millisecond'
3344+
*/
3345+
minUnit: TimeUnit;
3346+
};
3347+
3348+
export type TimeScaleTickOptions = {
3349+
/**
3350+
* Ticks generation input values:
3351+
* - 'auto': generates "optimal" ticks based on scale size and time options.
3352+
* - 'data': generates ticks from data (including labels from data `{t|x|y}` objects).
3353+
* - 'labels': generates ticks from user given `data.labels` values ONLY.
3354+
* @see https://github.com/chartjs/Chart.js/pull/4507
3355+
* @since 2.7.0
3356+
* @default 'auto'
3357+
*/
3358+
source: 'labels' | 'auto' | 'data';
3359+
/**
3360+
* The number of units between grid lines.
3361+
* @default 1
3362+
*/
3363+
stepSize: number;
3364+
};
3365+
33113366
export type TimeScaleOptions = Omit<CartesianScaleOptions, 'min' | 'max'> & {
33123367
min: string | number;
33133368
max: string | number;
@@ -3336,60 +3391,9 @@ export type TimeScaleOptions = Omit<CartesianScaleOptions, 'min' | 'max'> & {
33363391
date: unknown;
33373392
};
33383393

3339-
time: {
3340-
/**
3341-
* Custom parser for dates.
3342-
*/
3343-
parser: string | ((v: unknown) => number);
3344-
/**
3345-
* If defined, dates will be rounded to the start of this unit. See Time Units below for the allowed units.
3346-
*/
3347-
round: false | TimeUnit;
3348-
/**
3349-
* 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.
3350-
* If `number`, the index of the first day of the week (0 - Sunday, 6 - Saturday).
3351-
* @default false
3352-
*/
3353-
isoWeekday: boolean | number;
3354-
/**
3355-
* Sets how different time units are displayed.
3356-
*/
3357-
displayFormats: {
3358-
[key: string]: string;
3359-
};
3360-
/**
3361-
* The format string to use for the tooltip.
3362-
*/
3363-
tooltipFormat: string;
3364-
/**
3365-
* If defined, will force the unit to be a certain type. See Time Units section below for details.
3366-
* @default false
3367-
*/
3368-
unit: false | TimeUnit;
3369-
/**
3370-
* The minimum display format to be used for a time unit.
3371-
* @default 'millisecond'
3372-
*/
3373-
minUnit: TimeUnit;
3374-
};
3394+
time: TimeScaleTimeOptions;
33753395

3376-
ticks: {
3377-
/**
3378-
* Ticks generation input values:
3379-
* - 'auto': generates "optimal" ticks based on scale size and time options.
3380-
* - 'data': generates ticks from data (including labels from data `{t|x|y}` objects).
3381-
* - 'labels': generates ticks from user given `data.labels` values ONLY.
3382-
* @see https://github.com/chartjs/Chart.js/pull/4507
3383-
* @since 2.7.0
3384-
* @default 'auto'
3385-
*/
3386-
source: 'labels' | 'auto' | 'data';
3387-
/**
3388-
* The number of units between grid lines.
3389-
* @default 1
3390-
*/
3391-
stepSize: number;
3392-
};
3396+
ticks: TimeScaleTickOptions;
33933397
};
33943398

33953399
export interface TimeScale<O extends TimeScaleOptions = TimeScaleOptions> extends Scale<O> {

0 commit comments

Comments
 (0)