]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Add data.datasets[].tooltip.callbacks to Typescript types (#12099) master
authorBojidar Marinov <bojidar.marinov.bg@gmail.com>
Fri, 11 Jul 2025 19:53:20 +0000 (22:53 +0300)
committerGitHub <noreply@github.com>
Fri, 11 Jul 2025 19:53:20 +0000 (21:53 +0200)
src/types/index.d.ts

index 69a4cfccbc51fdebd485bd24e270c49556525525..e96fddadc61523fa39455e5489a3c60aac0eb873 100644 (file)
@@ -2678,10 +2678,23 @@ export interface Tooltip extends Plugin {
 
 export declare const Tooltip: Tooltip;
 
-export interface TooltipCallbacks<
+export interface TooltipDatasetCallbacks<
   TType extends ChartType,
   Model = TooltipModel<TType>,
   Item = TooltipItem<TType>> {
+  beforeLabel(this: Model, tooltipItem: Item): string | string[] | void;
+  label(this: Model, tooltipItem: Item): string | string[] | void;
+  afterLabel(this: Model, tooltipItem: Item): string | string[] | void;
+
+  labelColor(this: Model, tooltipItem: Item): TooltipLabelStyle | void;
+  labelTextColor(this: Model, tooltipItem: Item): Color | void;
+  labelPointStyle(this: Model, tooltipItem: Item): { pointStyle: PointStyle; rotation: number } | void;
+}
+
+export interface TooltipCallbacks<
+  TType extends ChartType,
+  Model = TooltipModel<TType>,
+  Item = TooltipItem<TType>> extends TooltipDatasetCallbacks<TType, Model, Item> {
 
   beforeTitle(this: Model, tooltipItems: Item[]): string | string[] | void;
   title(this: Model, tooltipItems: Item[]): string | string[] | void;
@@ -2913,6 +2926,10 @@ export interface TooltipOptions<TType extends ChartType = ChartType> extends Cor
   callbacks: TooltipCallbacks<TType>;
 }
 
+export interface TooltipDatasetOptions<TType extends ChartType = ChartType> {
+  callbacks: TooltipDatasetCallbacks<TType>;
+}
+
 export interface TooltipItem<TType extends ChartType> {
   /**
    * The chart the tooltip is being shown on
@@ -2960,6 +2977,10 @@ export interface TooltipItem<TType extends ChartType> {
   element: Element;
 }
 
+export interface PluginDatasetOptionsByType<TType extends ChartType> {
+  tooltip: TooltipDatasetOptions<TType>;
+}
+
 export interface PluginOptionsByType<TType extends ChartType> {
   colors: ColorsPluginOptions;
   decimation: DecimationOptions;
@@ -3800,6 +3821,8 @@ export type ChartDataset<
   TData = DefaultDataPoint<TType>
 > = DeepPartial<
 { [key in ChartType]: { type: key } & ChartTypeRegistry[key]['datasetOptions'] }[TType]
+> & DeepPartial<
+PluginDatasetOptionsByType<TType>
 > & ChartDatasetProperties<TType, TData>;
 
 export type ChartDatasetCustomTypesPerDataset<
@@ -3807,6 +3830,8 @@ export type ChartDatasetCustomTypesPerDataset<
   TData = DefaultDataPoint<TType>
 > = DeepPartial<
 { [key in ChartType]: { type: key } & ChartTypeRegistry[key]['datasetOptions'] }[TType]
+> & DeepPartial<
+PluginDatasetOptionsByType<TType>
 > & ChartDatasetPropertiesCustomTypesPerDataset<TType, TData>;
 
 /**