From 03697d03990957a7ca744845f5550b77ef00b133 Mon Sep 17 00:00:00 2001 From: Alexey Gryzin <62965405+feelsbadmans@users.noreply.github.com> Date: Thu, 19 Oct 2023 10:19:55 +0300 Subject: [PATCH] feat: added options for custom tooltip tracking fn (#171) Co-authored-by: Alexey Gryzin --- src/YagrCore/plugins/tooltip/tooltip.ts | 9 ++++++++- src/YagrCore/plugins/tooltip/types.ts | 13 ++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/YagrCore/plugins/tooltip/tooltip.ts b/src/YagrCore/plugins/tooltip/tooltip.ts index 6045452..cc67920 100644 --- a/src/YagrCore/plugins/tooltip/tooltip.ts +++ b/src/YagrCore/plugins/tooltip/tooltip.ts @@ -409,7 +409,14 @@ class YagrTooltip { } else if (tracking === 'sticky') { activeIndex = findSticky(section, cursorValue); } else if (typeof tracking === 'function') { - activeIndex = tracking(section, cursorValue); + activeIndex = tracking(section, cursorValue, { + x: u.posToVal(left, 'x'), + y: u.posToVal(top, scale), + idx, + scale, + series: this.yagr.series, + interpolation: this.interpolation, + }); } if (activeIndex !== null) { diff --git a/src/YagrCore/plugins/tooltip/types.ts b/src/YagrCore/plugins/tooltip/types.ts index 412f1be..e4f5969 100644 --- a/src/YagrCore/plugins/tooltip/types.ts +++ b/src/YagrCore/plugins/tooltip/types.ts @@ -1,4 +1,15 @@ +import {AlignedData} from 'uplot'; import Yagr from '../../index'; +import {ProcessingInterpolation} from 'src/types'; + +type CustomTrackingFunctionOptions = { + x: number; + y: number; + idx: number; + scale: string; + series: AlignedData; + interpolation?: ProcessingInterpolation; +}; export type TrackingOptions = /** Tracks serie only if mouse hovered on series' area */ @@ -6,7 +17,7 @@ export type TrackingOptions = /** Tracks mouse to closest line */ | 'sticky' /** Custom tracking function */ - | ((s: TooltipSection, y: number) => number | null); + | ((s: TooltipSection, y: number, options: CustomTrackingFunctionOptions) => number | null); export interface TooltipRenderOpts { /** Tooltip option */ options: TooltipOptions;