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

Type fixes #7759

Merged
merged 3 commits into from
Sep 6, 2020
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions types/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export interface IParsingOptions {
}

export interface Chart<
T = number,
T = unknown,
L = string,
C extends IChartConfiguration<string, T, L> = IChartConfiguration<string, T, L>
> {
Expand All @@ -245,7 +245,6 @@ export interface Chart<
readonly width: number;
readonly height: number;
readonly aspectRatio: number;
readonly options: ConfigurationOptions<C>;
readonly boxes: ILayoutItem[];
readonly currentDevicePixelRatio: number;
readonly chartArea: IChartArea;
Expand All @@ -254,6 +253,8 @@ export interface Chart<
readonly scale: Scale | undefined;
readonly attached: boolean;

options: ConfigurationOptions<C>;

clear(): this;
stop(): this;

Expand Down Expand Up @@ -300,7 +301,7 @@ export declare type ChartItem =

export const Chart: {
prototype: Chart;
new <T = number, L = string, C extends IChartConfiguration<string, T, L> = IChartConfiguration<string, T, L>>(
new <T = unknown, L = string, C extends IChartConfiguration<string, T, L> = IChartConfiguration<string, T, L>>(
item: ChartItem,
config: C
): Chart<T, L, C>;
Expand Down
7 changes: 4 additions & 3 deletions types/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type DeepPartial<T> = T extends {}
}
: T;

export type IChartDataset<T = number, O = {}> = DeepPartial<IControllerDatasetOptions & IParsingOptions & O> & {
export type IChartDataset<T = unknown, O = {}> = DeepPartial<IControllerDatasetOptions & IParsingOptions & O> & {
data: T[];
};

Expand All @@ -53,14 +53,15 @@ export type IDoughnutControllerDataset<T = IDoughnutDataPoint> = IChartDataset<T
export type IPolarAreaControllerDataset<T = number> = IChartDataset<T, IPolarAreaControllerDatasetOptions>;
export type IRadarControllerDataset<T = number> = IChartDataset<T, IRadarControllerDatasetOptions>;

export interface IChartData<T = number, L = string, DS extends IChartDataset<T> = IChartDataset<T>>
export interface IChartData<T = unknown, L = string, DS extends IChartDataset<T> = IChartDataset<T>>
extends DeepPartial<IParsingOptions> {
labels: L[];
datasets: DS[];
}

export type IChartOptions<O = {}> = DeepPartial<
ICoreChartOptions &
IParsingOptions &
ITooltipChartOptions &
ILegendChartOptions &
ITitleChartOptions &
Expand All @@ -72,7 +73,7 @@ export type IChartOptions<O = {}> = DeepPartial<

export interface IChartConfiguration<
TYPE = string,
T = number,
T = unknown,
L = string,
DS extends IChartDataset<T> = IChartDataset<T>,
O = {}
Expand Down
16 changes: 4 additions & 12 deletions types/plugins/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Chart, Element, IAnimationSpecContainer, InteractionMode, LayoutPosition, IPlugin } from '../core';
import { Color, IChartArea, IFontSpec, Scriptable, TextAlign, IEvent } from '../core/interfaces';
import { Color, IChartArea, IFontSpec, Scriptable, TextAlign, IEvent, IHoverInteractionOptions } from '../core/interfaces';
import { PointStyle } from '../elements';
import { IChartData } from '../interfaces';
import { IChartData, IChartDataset } from '../interfaces';

export const Filler: IPlugin;

Expand Down Expand Up @@ -325,7 +325,7 @@ export interface ITooltipPlugin<O = {}> {
afterTooltipDraw?(chart: Chart, args: { tooltip: TooltipModel }, options: O): void;
}

export interface ITooltipOptions {
export interface ITooltipOptions extends IHoverInteractionOptions {
/**
* Are on-canvas tooltips enabled?
* @default true
Expand All @@ -335,18 +335,10 @@ export interface ITooltipOptions {
* See custom tooltip section.
*/
custom(this: TooltipModel, args: { chart: Chart; tooltip: TooltipModel }): void;
/**
* Sets which elements appear in the tooltip.
*/
mode: InteractionMode;
/**
* The mode for positioning the tooltip
*/
position: 'average' | 'nearest';
/**
* If true, the tooltip mode applies only when the mouse position intersects with an element. If false, the mode will be applied at all times.
*/
intersect: boolean;

/**
* Sort tooltip items.
Expand Down Expand Up @@ -514,7 +506,7 @@ export interface ITooltipItem {
/**
* The dataset the item comes from
*/
dataset: object;
dataset: IChartDataset;

/**
* Index of the dataset the item comes from
Expand Down
8 changes: 6 additions & 2 deletions types/scales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const CategoryScale: IChartComponent & {
new <O extends ICategoryScaleOptions = ICategoryScaleOptions>(cfg: any): CategoryScale<O>;
};

export type ILinearScaleOptions = IScaleOptions & {
export type ILinearScaleOptions = ICartesianScaleOptions & {
stacked?: boolean;

/**
Expand Down Expand Up @@ -281,12 +281,16 @@ export type ITimeScaleOptions = ICartesianScaleOptions & {
*/
isoWeekday: false | string;
/**
* Sets how different time units are displayed.
* Sets how different time units are displayed.
* @see https://www.chartjs.org/docs/next/axes/cartesian/time#display-formats
*/
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
Expand Down