-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Highcharts plugin): rework tooltip pinning api (#166)
- Loading branch information
Showing
7 changed files
with
107 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
src/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.test.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.ts
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
src/plugins/highcharts/renderer/helpers/config/utils/tooltip.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {HighchartsType} from '../../constants'; | ||
import {checkTooltipPinningAvailability, isTooltipShared} from './tooltip'; | ||
|
||
const chartTypes: [HighchartsType, boolean][] = [ | ||
[HighchartsType.Sankey, false], | ||
[HighchartsType.Xrange, false], | ||
[HighchartsType.Line, true], | ||
[HighchartsType.Area, true], | ||
[HighchartsType.Arearange, true], | ||
[HighchartsType.Bar, true], | ||
[HighchartsType.Column, true], | ||
[HighchartsType.Columnrange, true], | ||
[HighchartsType.Funnel, true], | ||
[HighchartsType.Pie, true], | ||
[HighchartsType.Map, true], | ||
[HighchartsType.Scatter, true], | ||
[HighchartsType.Bubble, true], | ||
[HighchartsType.Heatmap, true], | ||
[HighchartsType.Treemap, true], | ||
[HighchartsType.Networkgraph, true], | ||
[HighchartsType.Variwide, true], | ||
[HighchartsType.Waterfall, true], | ||
[HighchartsType.Streamgraph, true], | ||
[HighchartsType.Wordcloud, true], | ||
[HighchartsType.Boxplot, true], | ||
[HighchartsType.Timeline, true], | ||
]; | ||
|
||
describe('plugins/highcharts/config', () => { | ||
test.each(chartTypes)(`calculatePrecision for %s return %s`, (chartType, expected) => { | ||
expect(isTooltipShared(chartType)).toBe(expected); | ||
}); | ||
|
||
test.each([ | ||
[undefined, true], | ||
[{tooltip: {pin: {altKey: true}}, altKey: true}, true], | ||
[{tooltip: {pin: {metaKey: true}}, metaKey: true}, true], | ||
[{tooltip: {pin: {altKey: true, metaKey: true}}, altKey: true, metaKey: true}, true], | ||
[{tooltip: {pin: {enabled: false}}}, false], | ||
[{tooltip: {pin: {altKey: true}}, altKey: false}, false], | ||
[{tooltip: {pin: {metaKey: true}}, metaKey: false}, false], | ||
[{tooltip: {pin: {altKey: true, metaKey: true}}, altKey: false, metaKey: true}, false], | ||
[{tooltip: {pin: {altKey: true, metaKey: true}}, altKey: true, metaKey: false}, false], | ||
])(`checkTooltipPinningAvailability (args: %j)`, (args, expected) => { | ||
const result = checkTooltipPinningAvailability(args); | ||
expect(result).toBe(expected); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
src/plugins/highcharts/renderer/helpers/config/utils/tooltip.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {HighchartsWidgetData} from '../../../../types'; | ||
|
||
// In case of using 'sankey' or 'xrange', the shared property must be set to false, otherwise the tooltip behaves incorrectly: | ||
// Point.onMouseOver -> Highcharts.Pointer.runPointActions -> H.Tooltip.refresh -> Cannot read property 'series' of undefined | ||
export const isTooltipShared = (chartType: string) => { | ||
if (['sankey', 'xrange'].includes(chartType)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
export const checkTooltipPinningAvailability = ( | ||
args: { | ||
tooltip?: HighchartsWidgetData['config']['tooltip']; | ||
altKey?: boolean; | ||
metaKey?: boolean; | ||
} = {}, | ||
) => { | ||
const {tooltip, altKey, metaKey} = args; | ||
const enabled = tooltip?.pin?.enabled ?? true; | ||
const shouldAltKeyBePressed = tooltip?.pin?.altKey ?? false; | ||
const shouldMetaKeyBePressed = tooltip?.pin?.metaKey ?? false; | ||
|
||
if (!enabled) { | ||
return false; | ||
} | ||
|
||
if (shouldAltKeyBePressed && !altKey) { | ||
return false; | ||
} | ||
|
||
if (shouldMetaKeyBePressed && !metaKey) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters