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

feat: added tooltip.omitBy option to omit arbitrary line from tooltip by predicate #152

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/en/plugins/tooltip.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Configuration for this example:
- `tooltip.precision?: PerScale<number>` - decimals count in numbers when formatting in the tooltip
- `tooltip.value: PerScale<ValueFormatter>`- formatter for line values
- `tooltip.onUpdate: 'none' | 'reset'` - how to update tooltip when data is updated. `none` - do nothing, `reset` - reset tooltip state
- `tooltip.omitBy: (row: TooltipRow) => boolean` - omit row from tooltip if this function returns `true`


```ts
type ValueFormatter = (value: string | number | null, precision?: number) => string;
Expand Down
5 changes: 5 additions & 0 deletions src/YagrCore/plugins/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class YagrTooltip {
const rowData: TooltipRow = {
id: serie.id,
name: serie.name,
dataValue: serie.$c[idx],
originalValue: value,
value: displayValue,
y: yValue,
Expand All @@ -389,6 +390,10 @@ class YagrTooltip {
rowData.transformed = seriesData[idx];
}

if (opts.omitBy && opts.omitBy(rowData)) {
continue;
}

section.rows.push(rowData);
}

Expand Down
6 changes: 5 additions & 1 deletion src/YagrCore/plugins/tooltip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export interface TooltipOptions {
sort?: PerScale<SortFn>;
/** Custom tooltip renderer */
render: (data: TooltipRenderOptions) => string;
/** Hide line in tooltip by predicate */
omitBy?: (row: TooltipRow) => boolean;
/** @deprecated Is tooltip pinable */
pinable: boolean;
/**
Expand Down Expand Up @@ -167,10 +169,12 @@ export interface TooltipRow {
seriesIdx: number;
/** Index of row in section */
rowIdx: number;
/** Original value before all transormations */
/** Original value in Y scales */
originalValue?: number | null;
/** Transformed value */
transformed?: number | null | string;
/** Original value before all transormations */
dataValue?: number | null | string;
}

export interface TooltipSection {
Expand Down