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

Typescript type for Tooltip custom positioner #9782

Closed
1 task
elinake opened this issue Oct 20, 2021 · 0 comments · Fixed by #9944
Closed
1 task

Typescript type for Tooltip custom positioner #9782

elinake opened this issue Oct 20, 2021 · 0 comments · Fixed by #9944
Labels
type: documentation type: types Typescript type changes
Milestone

Comments

@elinake
Copy link

elinake commented Oct 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation type: types Typescript type changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants