@gravity-ui/chartkit 2.7.2 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/build/plugins/highcharts/renderer/helpers/config/config.js +10 -4
- package/build/plugins/highcharts/renderer/helpers/config/utils/index.d.ts +1 -1
- package/build/plugins/highcharts/renderer/helpers/config/utils/index.js +1 -1
- package/build/plugins/highcharts/renderer/helpers/config/utils/tooltip.d.ts +7 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/tooltip.js +25 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/tooltip.test.js +45 -0
- package/build/plugins/highcharts/types/widget.d.ts +10 -1
- package/package.json +1 -1
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.d.ts +0 -1
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.js +0 -8
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.test.js +0 -31
- /package/build/plugins/highcharts/renderer/helpers/config/utils/{isTooltipShared.test.d.ts → tooltip.test.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.8.0](https://github.com/gravity-ui/chartkit/compare/v2.7.2...v2.8.0) (2023-05-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **Highcharts plugin:** rework tooltip pinning api ([#166](https://github.com/gravity-ui/chartkit/issues/166)) ([9ca62e4](https://github.com/gravity-ui/chartkit/commit/9ca62e4d01d62f36de0c4866e0d21728ca2aa25c))
|
|
9
|
+
|
|
3
10
|
## [2.7.2](https://github.com/gravity-ui/chartkit/compare/v2.7.1...v2.7.2) (2023-05-17)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -16,7 +16,7 @@ import { formatNumber } from '../../../../shared';
|
|
|
16
16
|
import { getCommentsOnLine, drawComments, hideComments, drawOnlyRendererComments, } from '../comments/drawing';
|
|
17
17
|
import formatTooltip, { TOOLTIP_ROW_CLASS_NAME, SERIES_NAME_DATA_ATTRIBUTE, TOOLTIP_HEADER_CLASS_NAME, TOOLTIP_LIST_CLASS_NAME, TOOLTIP_FOOTER_CLASS_NAME, TOOLTIP_CONTAINER_CLASS_NAME, TOOLTIP_ROW_NAME_CLASS_NANE, } from '../tooltip';
|
|
18
18
|
import defaultOptions from './options';
|
|
19
|
-
import { calculatePrecision, isTooltipShared, isSafari, mergeArrayWithObject, concatStrings, buildNavigatorFallback, addShowInNavigatorToSeries, setNavigatorDefaultPeriod, numberFormat, getFormatOptionsFromLine, } from './utils';
|
|
19
|
+
import { calculatePrecision, isTooltipShared, isSafari, mergeArrayWithObject, concatStrings, buildNavigatorFallback, addShowInNavigatorToSeries, setNavigatorDefaultPeriod, numberFormat, getFormatOptionsFromLine, checkTooltipPinningAvailability, } from './utils';
|
|
20
20
|
import { handleLegendItemClick } from './handleLegendItemClick';
|
|
21
21
|
import { getChartKitFormattedValue } from './utils/getChartKitFormattedValue';
|
|
22
22
|
const b = block('chartkit-tooltip');
|
|
@@ -876,7 +876,9 @@ export function hideFixedTooltip(tooltip, isMobile) {
|
|
|
876
876
|
tooltip.hide();
|
|
877
877
|
if (Array.isArray(tooltip.pointsOnFixedTooltip)) {
|
|
878
878
|
tooltip.pointsOnFixedTooltip.forEach((point) => {
|
|
879
|
-
point.setState
|
|
879
|
+
if (typeof point.setState === 'function') {
|
|
880
|
+
point.setState('');
|
|
881
|
+
}
|
|
880
882
|
});
|
|
881
883
|
}
|
|
882
884
|
else {
|
|
@@ -898,8 +900,12 @@ export function hideFixedTooltip(tooltip, isMobile) {
|
|
|
898
900
|
}
|
|
899
901
|
}
|
|
900
902
|
function fixTooltip(tooltip, options, event) {
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
+
const availableToPin = checkTooltipPinningAvailability({
|
|
904
|
+
tooltip: options.tooltip,
|
|
905
|
+
altKey: event.altKey,
|
|
906
|
+
metaKey: event.metaKey,
|
|
907
|
+
});
|
|
908
|
+
if (options.splitTooltip || (!availableToPin && !tooltip.fixed)) {
|
|
903
909
|
return false;
|
|
904
910
|
}
|
|
905
911
|
if (tooltip.fixed) {
|
|
@@ -5,7 +5,7 @@ export { concatStrings } from './concatStrings';
|
|
|
5
5
|
export { getChartKitFormattedValue } from './getChartKitFormattedValue';
|
|
6
6
|
export { getFormatOptionsFromLine } from './getFormatOptionsFromLine';
|
|
7
7
|
export { getXAxisThresholdValue } from './getXAxisThresholdValue';
|
|
8
|
-
export
|
|
8
|
+
export * from './tooltip';
|
|
9
9
|
export { isNavigatorSeries } from './isNavigatorSeries';
|
|
10
10
|
export { isSafari } from './isSafari';
|
|
11
11
|
export { mergeArrayWithObject } from './mergeArrayWithObject';
|
|
@@ -5,7 +5,7 @@ export { concatStrings } from './concatStrings';
|
|
|
5
5
|
export { getChartKitFormattedValue } from './getChartKitFormattedValue';
|
|
6
6
|
export { getFormatOptionsFromLine } from './getFormatOptionsFromLine';
|
|
7
7
|
export { getXAxisThresholdValue } from './getXAxisThresholdValue';
|
|
8
|
-
export
|
|
8
|
+
export * from './tooltip';
|
|
9
9
|
export { isNavigatorSeries } from './isNavigatorSeries';
|
|
10
10
|
export { isSafari } from './isSafari';
|
|
11
11
|
export { mergeArrayWithObject } from './mergeArrayWithObject';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HighchartsWidgetData } from '../../../../types';
|
|
2
|
+
export declare const isTooltipShared: (chartType: string) => boolean;
|
|
3
|
+
export declare const checkTooltipPinningAvailability: (args?: {
|
|
4
|
+
tooltip?: HighchartsWidgetData['config']['tooltip'];
|
|
5
|
+
altKey?: boolean;
|
|
6
|
+
metaKey?: boolean;
|
|
7
|
+
}) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// In case of using 'sankey' or 'xrange', the shared property must be set to false, otherwise the tooltip behaves incorrectly:
|
|
2
|
+
// Point.onMouseOver -> Highcharts.Pointer.runPointActions -> H.Tooltip.refresh -> Cannot read property 'series' of undefined
|
|
3
|
+
export const isTooltipShared = (chartType) => {
|
|
4
|
+
if (['sankey', 'xrange'].includes(chartType)) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return true;
|
|
8
|
+
};
|
|
9
|
+
export const checkTooltipPinningAvailability = (args = {}) => {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f;
|
|
11
|
+
const { tooltip, altKey, metaKey } = args;
|
|
12
|
+
const enabled = (_b = (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.pin) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true;
|
|
13
|
+
const shouldAltKeyBePressed = (_d = (_c = tooltip === null || tooltip === void 0 ? void 0 : tooltip.pin) === null || _c === void 0 ? void 0 : _c.altKey) !== null && _d !== void 0 ? _d : false;
|
|
14
|
+
const shouldMetaKeyBePressed = (_f = (_e = tooltip === null || tooltip === void 0 ? void 0 : tooltip.pin) === null || _e === void 0 ? void 0 : _e.metaKey) !== null && _f !== void 0 ? _f : false;
|
|
15
|
+
if (!enabled) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (shouldAltKeyBePressed && !altKey) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (shouldMetaKeyBePressed && !metaKey) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { HighchartsType } from '../../constants';
|
|
2
|
+
import { checkTooltipPinningAvailability, isTooltipShared } from './tooltip';
|
|
3
|
+
const chartTypes = [
|
|
4
|
+
[HighchartsType.Sankey, false],
|
|
5
|
+
[HighchartsType.Xrange, false],
|
|
6
|
+
[HighchartsType.Line, true],
|
|
7
|
+
[HighchartsType.Area, true],
|
|
8
|
+
[HighchartsType.Arearange, true],
|
|
9
|
+
[HighchartsType.Bar, true],
|
|
10
|
+
[HighchartsType.Column, true],
|
|
11
|
+
[HighchartsType.Columnrange, true],
|
|
12
|
+
[HighchartsType.Funnel, true],
|
|
13
|
+
[HighchartsType.Pie, true],
|
|
14
|
+
[HighchartsType.Map, true],
|
|
15
|
+
[HighchartsType.Scatter, true],
|
|
16
|
+
[HighchartsType.Bubble, true],
|
|
17
|
+
[HighchartsType.Heatmap, true],
|
|
18
|
+
[HighchartsType.Treemap, true],
|
|
19
|
+
[HighchartsType.Networkgraph, true],
|
|
20
|
+
[HighchartsType.Variwide, true],
|
|
21
|
+
[HighchartsType.Waterfall, true],
|
|
22
|
+
[HighchartsType.Streamgraph, true],
|
|
23
|
+
[HighchartsType.Wordcloud, true],
|
|
24
|
+
[HighchartsType.Boxplot, true],
|
|
25
|
+
[HighchartsType.Timeline, true],
|
|
26
|
+
];
|
|
27
|
+
describe('plugins/highcharts/config', () => {
|
|
28
|
+
test.each(chartTypes)(`calculatePrecision for %s return %s`, (chartType, expected) => {
|
|
29
|
+
expect(isTooltipShared(chartType)).toBe(expected);
|
|
30
|
+
});
|
|
31
|
+
test.each([
|
|
32
|
+
[undefined, true],
|
|
33
|
+
[{ tooltip: { pin: { altKey: true } }, altKey: true }, true],
|
|
34
|
+
[{ tooltip: { pin: { metaKey: true } }, metaKey: true }, true],
|
|
35
|
+
[{ tooltip: { pin: { altKey: true, metaKey: true } }, altKey: true, metaKey: true }, true],
|
|
36
|
+
[{ tooltip: { pin: { enabled: false } } }, false],
|
|
37
|
+
[{ tooltip: { pin: { altKey: true } }, altKey: false }, false],
|
|
38
|
+
[{ tooltip: { pin: { metaKey: true } }, metaKey: false }, false],
|
|
39
|
+
[{ tooltip: { pin: { altKey: true, metaKey: true } }, altKey: false, metaKey: true }, false],
|
|
40
|
+
[{ tooltip: { pin: { altKey: true, metaKey: true } }, altKey: true, metaKey: false }, false],
|
|
41
|
+
])(`checkTooltipPinningAvailability (args: %j)`, (args, expected) => {
|
|
42
|
+
const result = checkTooltipPinningAvailability(args);
|
|
43
|
+
expect(result).toBe(expected);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -80,10 +80,19 @@ export declare type HighchartsWidgetData = {
|
|
|
80
80
|
enableSum?: boolean;
|
|
81
81
|
unsafe?: boolean;
|
|
82
82
|
/**
|
|
83
|
+
* @experimental
|
|
83
84
|
* Tooltip config
|
|
84
85
|
*/
|
|
85
86
|
tooltip?: {
|
|
86
|
-
|
|
87
|
+
/** Pin config */
|
|
88
|
+
pin?: {
|
|
89
|
+
/** Enable tooltip`s pinning by click */
|
|
90
|
+
enabled?: boolean;
|
|
91
|
+
/** Pin tooltip with pressed alt key */
|
|
92
|
+
altKey?: boolean;
|
|
93
|
+
/** Pin tooltip with pressed meta key */
|
|
94
|
+
metaKey?: boolean;
|
|
95
|
+
};
|
|
87
96
|
};
|
|
88
97
|
/**
|
|
89
98
|
* Used to modify tooltip data
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isTooltipShared: (chartType: string) => boolean;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// In case of using 'sankey' or 'xrange', the shared property must be set to false, otherwise the tooltip behaves incorrectly:
|
|
2
|
-
// Point.onMouseOver -> Highcharts.Pointer.runPointActions -> H.Tooltip.refresh -> Cannot read property 'series' of undefined
|
|
3
|
-
export const isTooltipShared = (chartType) => {
|
|
4
|
-
if (['sankey', 'xrange'].includes(chartType)) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
return true;
|
|
8
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { HighchartsType } from '../../constants';
|
|
2
|
-
import { isTooltipShared } from './isTooltipShared';
|
|
3
|
-
const chartTypes = [
|
|
4
|
-
[HighchartsType.Sankey, false],
|
|
5
|
-
[HighchartsType.Xrange, false],
|
|
6
|
-
[HighchartsType.Line, true],
|
|
7
|
-
[HighchartsType.Area, true],
|
|
8
|
-
[HighchartsType.Arearange, true],
|
|
9
|
-
[HighchartsType.Bar, true],
|
|
10
|
-
[HighchartsType.Column, true],
|
|
11
|
-
[HighchartsType.Columnrange, true],
|
|
12
|
-
[HighchartsType.Funnel, true],
|
|
13
|
-
[HighchartsType.Pie, true],
|
|
14
|
-
[HighchartsType.Map, true],
|
|
15
|
-
[HighchartsType.Scatter, true],
|
|
16
|
-
[HighchartsType.Bubble, true],
|
|
17
|
-
[HighchartsType.Heatmap, true],
|
|
18
|
-
[HighchartsType.Treemap, true],
|
|
19
|
-
[HighchartsType.Networkgraph, true],
|
|
20
|
-
[HighchartsType.Variwide, true],
|
|
21
|
-
[HighchartsType.Waterfall, true],
|
|
22
|
-
[HighchartsType.Streamgraph, true],
|
|
23
|
-
[HighchartsType.Wordcloud, true],
|
|
24
|
-
[HighchartsType.Boxplot, true],
|
|
25
|
-
[HighchartsType.Timeline, true],
|
|
26
|
-
];
|
|
27
|
-
describe('plugins/highcharts/config/calculatePrecision', () => {
|
|
28
|
-
test.each(chartTypes)(`for %s return %s`, (chartType, assert) => {
|
|
29
|
-
expect(isTooltipShared(chartType)).toBe(assert);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
File without changes
|