Skip to content

Commit

Permalink
feat(Higcharts plugin): add type for manageTooltipConfig (#139)
Browse files Browse the repository at this point in the history
* feat(Higcharts plugin): add type for manageTooltipConfig

* fix(Higcharts plugin): fix manageTooltipConfig
  • Loading branch information
korvin89 authored Mar 21, 2023
1 parent 07f610e commit f781cca
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/plugins/highcharts/mocks/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ export const data: HighchartsWidgetData = {
hideHolidays: false,
normalizeDiv: false,
normalizeSub: false,
manageTooltipConfig: (config) => {
config.lines.forEach((line, index) => {
line.commentText = `Some comment ${index + 1}`;
});

return config;
},
},
libraryConfig: {
chart: {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/highcharts/renderer/helpers/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ function fixTooltip(tooltip, options, event) {
tooltip.preFixationHeight = height;
}

tooltip.lastVisibleRowIndex = null;
tooltip.lastVisibleRowIndex = undefined;
tooltip.update({
style: {
...tooltip.style,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function initHighcharts({isMobile}) {

Highcharts.wrap(Highcharts.Tooltip.prototype, 'hide', function (proceed, ...rest) {
if (this.lastVisibleRowIndex) {
this.lastVisibleRowIndex = null;
this.lastVisibleRowIndex = undefined;
}

if (this.scrollHandler && !this.fixed) {
Expand Down Expand Up @@ -311,7 +311,7 @@ function initHighcharts({isMobile}) {

if ((!this.fixed || isFixation) && points) {
if (isFixation) {
this.lastVisibleRowIndex = null;
this.lastVisibleRowIndex = undefined;
}

proceed.apply(this, [points, ...rest]);
Expand Down Expand Up @@ -366,7 +366,7 @@ function initHighcharts({isMobile}) {
`.${TOOLTIP_LIST_CLASS_NAME} .${TOOLTIP_ROW_CLASS_NAME}`,
);

let lastVisibleRowIndex = null;
let lastVisibleRowIndex;

const selectedSeriesIndex = this.chart.hoverPoints.indexOf(this.chart.hoverPoint);

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/highcharts/renderer/helpers/tooltip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ export const formatTooltip = (
cellsRenderers,
useCompareFrom: data.useCompareFrom,
isSelectedLine: true,
allowComment: selectedLineIndex > tooltip.lastVisibleRowIndex,
allowComment:
typeof tooltip.lastVisibleRowIndex === 'number' &&
selectedLineIndex > tooltip.lastVisibleRowIndex,
};

// @ts-ignore
Expand Down
30 changes: 30 additions & 0 deletions src/plugins/highcharts/types/widget.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
import type {Highcharts} from './lib';
import type {HighchartsComment} from './comments';
import type {DrillDownConfig, StringParams} from './misc';
import type {TooltipData, TooltipLine} from '../renderer/helpers/tooltip/types';

export type CkHighchartsSeriesOptionsType = Highcharts.SeriesOptionsType & {
title?: string;
sname?: string;
fname?: string;
};

export type HighchartsManageTooltipConfigOptions = {
count: number;
lines: TooltipLine[];
shared: boolean;
this: {
x: string;
y: number;
points: Highcharts.Point[];
};
activeRowAlwaysFirstInTooltip?: boolean;
hiddenRowsNumber?: number;
hiddenRowsSum?: string;
splitTooltip?: boolean;
tooltipHeader?: string;
unsafe?: boolean;
useCompareFrom?: boolean;
withPercent?: boolean;
xComments?: TooltipData['xComments'];
};

export type HighchartsManageTooltipConfig = (
options: HighchartsManageTooltipConfigOptions,
chart: Highcharts.Chart,
) => HighchartsManageTooltipConfigOptions;

export type HighchartsWidgetData = {
data: (
| CkHighchartsSeriesOptionsType[]
Expand Down Expand Up @@ -63,6 +89,10 @@ export type HighchartsWidgetData = {
drillDown?: DrillDownConfig;
enableSum?: boolean;
unsafe?: boolean;
/**
* Used to modify tooltip data
*/
manageTooltipConfig?: HighchartsManageTooltipConfig;
};
libraryConfig: Highcharts.Options;
params?: StringParams;
Expand Down

0 comments on commit f781cca

Please sign in to comment.