]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Type fixes (#7759)
authoremmcbd <42184090+emmcbd@users.noreply.github.com>
Sun, 6 Sep 2020 20:43:38 +0000 (22:43 +0200)
committerGitHub <noreply@github.com>
Sun, 6 Sep 2020 20:43:38 +0000 (16:43 -0400)
* Some type fixes
* Fix missing property on tooltip option type

types/core/index.d.ts
types/interfaces.d.ts
types/plugins/index.d.ts
types/scales/index.d.ts

index 4b106e67100e8b53acb0a816bd9672e710e7bffd..10d063e28107c3184bd6d41438b02fd3da30957b 100644 (file)
@@ -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>
 > {
@@ -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;
@@ -254,6 +253,8 @@ export interface Chart<
   readonly scale: Scale | undefined;
   readonly attached: boolean;
 
+  options: ConfigurationOptions<C>;
+
   clear(): this;
   stop(): this;
 
@@ -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>;
index 66e925ac9973f1087efc6f020b0552e9ddce5a33..d9d9d99a7a8135c9b34fd06d496ba1da455f42cb 100644 (file)
@@ -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[];
 };
 
@@ -53,7 +53,7 @@ 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[];
@@ -61,6 +61,7 @@ export interface IChartData<T = number, L = string, DS extends IChartDataset<T>
 
 export type IChartOptions<O = {}> = DeepPartial<
   ICoreChartOptions &
+    IParsingOptions &
     ITooltipChartOptions &
     ILegendChartOptions &
     ITitleChartOptions &
@@ -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 = {}
index 12243491cd782a9c8dcb887bf9931bdd43d1a72c..055ddd79c6a33c09f3387444d690e0e12957ab6c 100644 (file)
@@ -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<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
@@ -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
index 31f994688c76d5756cc27fc2c7c751d29644cfbf..de939856009f07a7fb6758a8f25d3484e3ae2a5b 100644 (file)
@@ -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;
 
   /**
@@ -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