Skip to content

Commit

Permalink
feat: added options for custom tooltip tracking fn (#171)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Gryzin <[email protected]>
  • Loading branch information
feelsbadmans and Alexey Gryzin authored Oct 19, 2023
1 parent 3174fd1 commit 03697d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/YagrCore/plugins/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion src/YagrCore/plugins/tooltip/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
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 */
| 'area'
/** 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;
Expand Down

0 comments on commit 03697d0

Please sign in to comment.