Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split the TimeScaleOptions type into composable sub types #11187

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 57 additions & 53 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,61 @@ export declare const LogarithmicScale: ChartComponent & {
new <O extends LogarithmicScaleOptions = LogarithmicScaleOptions>(cfg: AnyObject): LogarithmicScale<O>;
};

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<CartesianScaleOptions, 'min' | 'max'> & {
min: string | number;
max: string | number;
Expand Down Expand Up @@ -3326,60 +3381,9 @@ export type TimeScaleOptions = Omit<CartesianScaleOptions, 'min' | 'max'> & {
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<O extends TimeScaleOptions = TimeScaleOptions> extends Scale<O> {
Expand Down