From: emmcbd <42184090+emmcbd@users.noreply.github.com> Date: Sun, 6 Sep 2020 20:43:38 +0000 (+0200) Subject: Type fixes (#7759) X-Git-Tag: v3.0.0-beta.2~1^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2fc8a4f17d002d3a119ebecc74252f67434b56d;p=thirdparty%2FChart.js.git Type fixes (#7759) * Some type fixes * Fix missing property on tooltip option type --- diff --git a/types/core/index.d.ts b/types/core/index.d.ts index 4b106e671..10d063e28 100644 --- a/types/core/index.d.ts +++ b/types/core/index.d.ts @@ -233,7 +233,7 @@ export interface IParsingOptions { } export interface Chart< - T = number, + T = unknown, L = string, C extends IChartConfiguration = IChartConfiguration > { @@ -245,7 +245,6 @@ export interface Chart< readonly width: number; readonly height: number; readonly aspectRatio: number; - readonly options: ConfigurationOptions; readonly boxes: ILayoutItem[]; readonly currentDevicePixelRatio: number; readonly chartArea: IChartArea; @@ -254,6 +253,8 @@ export interface Chart< readonly scale: Scale | undefined; readonly attached: boolean; + options: ConfigurationOptions; + clear(): this; stop(): this; @@ -300,7 +301,7 @@ export declare type ChartItem = export const Chart: { prototype: Chart; - new = IChartConfiguration>( + new = IChartConfiguration>( item: ChartItem, config: C ): Chart; diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index 66e925ac9..d9d9d99a7 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -37,7 +37,7 @@ export type DeepPartial = T extends {} } : T; -export type IChartDataset = DeepPartial & { +export type IChartDataset = DeepPartial & { data: T[]; }; @@ -53,7 +53,7 @@ export type IDoughnutControllerDataset = IChartDataset = IChartDataset; export type IRadarControllerDataset = IChartDataset; -export interface IChartData = IChartDataset> +export interface IChartData = IChartDataset> extends DeepPartial { labels: L[]; datasets: DS[]; @@ -61,6 +61,7 @@ export interface IChartData export type IChartOptions = DeepPartial< ICoreChartOptions & + IParsingOptions & ITooltipChartOptions & ILegendChartOptions & ITitleChartOptions & @@ -72,7 +73,7 @@ export type IChartOptions = DeepPartial< export interface IChartConfiguration< TYPE = string, - T = number, + T = unknown, L = string, DS extends IChartDataset = IChartDataset, O = {} diff --git a/types/plugins/index.d.ts b/types/plugins/index.d.ts index 12243491c..055ddd79c 100644 --- a/types/plugins/index.d.ts +++ b/types/plugins/index.d.ts @@ -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; @@ -325,7 +325,7 @@ export interface ITooltipPlugin { afterTooltipDraw?(chart: Chart, args: { tooltip: TooltipModel }, options: O): void; } -export interface ITooltipOptions { +export interface ITooltipOptions extends IHoverInteractionOptions { /** * Are on-canvas tooltips enabled? * @default true @@ -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. @@ -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 diff --git a/types/scales/index.d.ts b/types/scales/index.d.ts index 31f994688..de9398560 100644 --- a/types/scales/index.d.ts +++ b/types/scales/index.d.ts @@ -180,7 +180,7 @@ export const CategoryScale: IChartComponent & { new (cfg: any): CategoryScale; }; -export type ILinearScaleOptions = IScaleOptions & { +export type ILinearScaleOptions = ICartesianScaleOptions & { stacked?: boolean; /** @@ -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