Skip to content

Typescript type for Tooltip custom positioner #9782

Description

@elinake

Documentation Is:

  • Missing or needed

Please Explain in Detail...

The documents suggest using tooltip custom positioner like this:

const tooltipPlugin = Chart.registry.getPlugin('tooltip');
tooltipPlugin.positioners.myCustomPositioner = function(elements, eventPosition) {
    /** @type {Tooltip} */
    var tooltip = this;

getRegistry returns the tooltip as Plugin,

The element that can be used for customized positioning like above, is

export const Tooltip: Plugin & {
  readonly positioners: {
    [key: string]: (items: readonly ActiveElement[], eventPosition: { x: number; y: number }) => { x: number; y: number } | false;
  };

  getActiveElements(): ActiveElement[];
  setActiveElements(active: ActiveDataPoint[], eventPosition: { x: number, y: number }): void;
};

Typescript 4.3.5 cannot cast the return object of getPlugin into an object with those functions. And if I mark the return object as type Plugin, typescript gives an error for not having those functions.

Your Proposal for Changes

Add interface Tooltip instead of const Tooltip

Example

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions