@gravity-ui/chartkit 4.22.1 → 4.23.1
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/build/plugins/d3/renderer/D3Widget.js +4 -4
- package/build/plugins/d3/renderer/components/styles.css +4 -0
- package/build/plugins/yagr/renderer/tooltip/renderTooltip.d.ts +2 -2
- package/build/plugins/yagr/renderer/tooltip/renderTooltip.js +23 -2
- package/build/plugins/yagr/renderer/utils.js +1 -1
- package/build/plugins/yagr/types.d.ts +12 -2
- package/package.json +1 -1
|
@@ -28,9 +28,9 @@ const D3Widget = React.forwardRef(function D3Widget(props, forwardedRef) {
|
|
|
28
28
|
}, [handleResize]);
|
|
29
29
|
React.useImperativeHandle(forwardedRef, () => ({
|
|
30
30
|
reflow() {
|
|
31
|
-
|
|
31
|
+
debuncedHandleResize();
|
|
32
32
|
},
|
|
33
|
-
}), [
|
|
33
|
+
}), [debuncedHandleResize]);
|
|
34
34
|
React.useEffect(() => {
|
|
35
35
|
const selection = select(window);
|
|
36
36
|
// https://github.com/d3/d3-selection/blob/main/README.md#handling-events
|
|
@@ -43,8 +43,8 @@ const D3Widget = React.forwardRef(function D3Widget(props, forwardedRef) {
|
|
|
43
43
|
}, [debuncedHandleResize]);
|
|
44
44
|
React.useEffect(() => {
|
|
45
45
|
// dimensions initialize
|
|
46
|
-
|
|
47
|
-
}, [
|
|
46
|
+
debuncedHandleResize();
|
|
47
|
+
}, [debuncedHandleResize]);
|
|
48
48
|
if (validatedData.current !== data) {
|
|
49
49
|
validateData(data);
|
|
50
50
|
validatedData.current = data;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { TooltipRenderOptions } from '../../types';
|
|
2
|
-
export declare const getRenderTooltip: (
|
|
1
|
+
import type { TooltipRenderOptions, YagrWidgetData } from '../../types';
|
|
2
|
+
export declare const getRenderTooltip: (userData: YagrWidgetData['data']) => (data: TooltipRenderOptions) => string;
|
|
@@ -7,12 +7,33 @@ const calcOption = (d) => {
|
|
|
7
7
|
})
|
|
8
8
|
: d;
|
|
9
9
|
};
|
|
10
|
+
const getSeriesColorProperty = (args) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const { data, userData, row, rowIndex } = args;
|
|
13
|
+
const userSeries = userData.graphs[rowIndex];
|
|
14
|
+
const lineColor = (_a = data.yagr.getSeriesById(row.id)) === null || _a === void 0 ? void 0 : _a.lineColor;
|
|
15
|
+
let seriesColor = row.color;
|
|
16
|
+
switch (userSeries === null || userSeries === void 0 ? void 0 : userSeries.legendColorKey) {
|
|
17
|
+
case 'lineColor': {
|
|
18
|
+
if (lineColor) {
|
|
19
|
+
seriesColor = lineColor;
|
|
20
|
+
}
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'color':
|
|
24
|
+
default: {
|
|
25
|
+
seriesColor = row.color;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return seriesColor;
|
|
29
|
+
};
|
|
10
30
|
/*
|
|
11
31
|
* Default tooltip renderer.
|
|
12
32
|
* Adapter between native Yagr tooltip config and ChartKit
|
|
13
33
|
* tooltip renderer.
|
|
14
34
|
*/
|
|
15
|
-
export const getRenderTooltip = (
|
|
35
|
+
export const getRenderTooltip = (userData) => (data) => {
|
|
36
|
+
const { timeZone } = userData;
|
|
16
37
|
const cfg = data.yagr.config;
|
|
17
38
|
const timeMultiplier = cfg.chart.timeMultiplier || 1;
|
|
18
39
|
const opts = data.options;
|
|
@@ -41,7 +62,7 @@ export const getRenderTooltip = (timeZone) => (data) => {
|
|
|
41
62
|
activeRowAlwaysFirstInTooltip: rows.length > 1,
|
|
42
63
|
tooltipHeader: dateTime({ input: x / timeMultiplier, timeZone }).format('DD MMMM YYYY HH:mm:ss'),
|
|
43
64
|
shared: true,
|
|
44
|
-
lines: rows.map((row, i) => (Object.assign(Object.assign({}, row), { seriesName: row.name || 'Serie ' + (i + 1), seriesColor: row
|
|
65
|
+
lines: rows.map((row, i) => (Object.assign(Object.assign({}, row), { seriesName: row.name || 'Serie ' + (i + 1), seriesColor: getSeriesColorProperty({ data, userData, row, rowIndex: i }), selectedSeries: row.active, seriesIdx: row.seriesIdx, percentValue: typeof row.transformed === 'number' ? row.transformed.toFixed(1) : '' }))),
|
|
45
66
|
withPercent: calcOption(opts.percent),
|
|
46
67
|
hiddenRowsNumber: hiddenRowsNumber,
|
|
47
68
|
hiddenRowsSum,
|
|
@@ -111,7 +111,7 @@ export const shapeYagrConfig = (args) => {
|
|
|
111
111
|
config.chart = chart;
|
|
112
112
|
if ((_a = config.tooltip) === null || _a === void 0 ? void 0 : _a.show) {
|
|
113
113
|
config.tooltip = config.tooltip || {};
|
|
114
|
-
config.tooltip.render = ((_b = config.tooltip) === null || _b === void 0 ? void 0 : _b.render) || getRenderTooltip(
|
|
114
|
+
config.tooltip.render = ((_b = config.tooltip) === null || _b === void 0 ? void 0 : _b.render) || getRenderTooltip(data);
|
|
115
115
|
if (!config.tooltip.className) {
|
|
116
116
|
// "className" property prevent default yagr styles adding
|
|
117
117
|
config.tooltip.className = 'chartkit-yagr-tooltip';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MinimalValidConfig, RawSerieData, YagrConfig } from '@gravity-ui/yagr';
|
|
1
|
+
import type { MinimalValidConfig, RawSerieData, SeriesOptions, YagrConfig } from '@gravity-ui/yagr';
|
|
2
2
|
import type Yagr from '@gravity-ui/yagr';
|
|
3
3
|
import { ChartKitProps } from 'src/types';
|
|
4
4
|
export type { default as Yagr } from '@gravity-ui/yagr';
|
|
@@ -10,9 +10,19 @@ export interface CustomTooltipProps {
|
|
|
10
10
|
export type YagrWidgetProps = ChartKitProps<'yagr'> & {
|
|
11
11
|
id: string;
|
|
12
12
|
};
|
|
13
|
+
export type YagrSeriesData<T = Omit<SeriesOptions, 'type'>> = RawSerieData<T> & {
|
|
14
|
+
/**
|
|
15
|
+
* Determines what data value should be used to get a color for tooltip series. Does not work in case of using custom tooltip rendered via `tooltip` property.
|
|
16
|
+
* - `lineColor` indicates that lineColor property should be used
|
|
17
|
+
* - `color` indicates that color property should be used
|
|
18
|
+
*
|
|
19
|
+
* @default 'color'
|
|
20
|
+
*/
|
|
21
|
+
legendColorKey?: 'color' | 'lineColor';
|
|
22
|
+
};
|
|
13
23
|
export type YagrWidgetData = {
|
|
14
24
|
data: {
|
|
15
|
-
graphs:
|
|
25
|
+
graphs: YagrSeriesData[];
|
|
16
26
|
timeline: number[];
|
|
17
27
|
/**
|
|
18
28
|
* Allow to setup timezone for X axis and tooltip's header.
|
package/package.json
CHANGED