@gravity-ui/chartkit 2.11.0 → 3.0.0-beta.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 +1 -2
- package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.js +4 -1
- package/build/plugins/yagr/__stories__/Yagr.stories.d.ts +2 -0
- package/build/plugins/yagr/__stories__/Yagr.stories.js +23 -3
- package/build/plugins/yagr/__stories__/mocks/line10.d.ts +50 -0
- package/build/plugins/yagr/__stories__/mocks/line10.js +15 -0
- package/build/plugins/yagr/__tests__/utils.test.js +4 -4
- package/build/plugins/yagr/renderer/YagrWidget.js +10 -8
- package/build/plugins/yagr/renderer/tooltip/renderTooltip.js +4 -4
- package/build/plugins/yagr/renderer/utils.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
### Features
|
|
7
7
|
|
|
8
8
|
* add renderError property ([#175](https://github.com/gravity-ui/chartkit/issues/175)) ([84c03a9](https://github.com/gravity-ui/chartkit/commit/84c03a9f8516e9fb846e25a920aa82b00c660a02))
|
|
9
|
-
* **main:** Add renderErrorView prop for custom render and handle errors ([15e314f](https://github.com/gravity-ui/chartkit/commit/15e314f40c378aa65c4d83055760f49fb56af539))
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
### Bug Fixes
|
|
13
12
|
|
|
14
|
-
*
|
|
13
|
+
* reset "No data" error on change data ([ac0da94](https://github.com/gravity-ui/chartkit/commit/ac0da94fd21ff558a739c00b8904645d5ba006ef))
|
|
15
14
|
|
|
16
15
|
## [2.10.1](https://github.com/gravity-ui/chartkit/compare/v2.10.0...v2.10.1) (2023-06-19)
|
|
17
16
|
|
|
@@ -43,6 +43,9 @@ function getPointsForInitialRefresh(chart) {
|
|
|
43
43
|
}
|
|
44
44
|
function forceHoverState(chart, activePoints) {
|
|
45
45
|
const chartType = get(chart, 'userOptions.chart.type');
|
|
46
|
+
if (!chartType) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
46
49
|
if (chartType === 'pie') {
|
|
47
50
|
chart.tooltip.refresh(activePoints);
|
|
48
51
|
chart.pointsForInitialRefresh = activePoints;
|
|
@@ -205,6 +208,6 @@ export const withSplitPane = (ComposedComponent) => {
|
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
210
|
return React.forwardRef((props, ref) => {
|
|
208
|
-
return React.createElement(WithSplitPane, Object.assign({ forwardedRef: ref }
|
|
211
|
+
return React.createElement(WithSplitPane, Object.assign({}, props, { forwardedRef: ref }));
|
|
209
212
|
});
|
|
210
213
|
};
|
|
@@ -3,12 +3,13 @@ import { Button } from '@gravity-ui/uikit';
|
|
|
3
3
|
import { settings } from '../../../libs';
|
|
4
4
|
import { YagrPlugin } from '../../../plugins';
|
|
5
5
|
import { ChartKit } from '../../../components/ChartKit';
|
|
6
|
-
import { line10 } from './mocks/line10';
|
|
6
|
+
import { getNewConfig, line10 } from './mocks/line10';
|
|
7
|
+
import '@gravity-ui/yagr/dist/index.css';
|
|
7
8
|
export default {
|
|
8
9
|
title: 'Plugins/Yagr',
|
|
9
10
|
component: ChartKit,
|
|
10
11
|
};
|
|
11
|
-
const
|
|
12
|
+
const LineTemplate = () => {
|
|
12
13
|
const [shown, setShown] = React.useState(false);
|
|
13
14
|
const chartkitRef = React.useRef();
|
|
14
15
|
if (!shown) {
|
|
@@ -18,4 +19,23 @@ const Template = () => {
|
|
|
18
19
|
return (React.createElement("div", { style: { height: 300, width: '100%' } },
|
|
19
20
|
React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: line10 })));
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
+
const UpdatesTemplate = () => {
|
|
23
|
+
const [shown, setShown] = React.useState(false);
|
|
24
|
+
const chartkitRef = React.useRef();
|
|
25
|
+
const [state, setState] = React.useState(line10);
|
|
26
|
+
const onStartUpdates = React.useCallback(() => {
|
|
27
|
+
setInterval(() => {
|
|
28
|
+
setState(getNewConfig());
|
|
29
|
+
}, 1000);
|
|
30
|
+
}, []);
|
|
31
|
+
if (!shown) {
|
|
32
|
+
settings.set({ plugins: [YagrPlugin] });
|
|
33
|
+
return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
|
|
34
|
+
}
|
|
35
|
+
return (React.createElement("div", { style: { height: 300, width: '100%' } },
|
|
36
|
+
React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: state }),
|
|
37
|
+
React.createElement(Button, { onClick: onStartUpdates }, "Start Updates"),
|
|
38
|
+
React.createElement(Button, { onClick: () => setState(getNewConfig()) }, "Once")));
|
|
39
|
+
};
|
|
40
|
+
export const Line = LineTemplate.bind({});
|
|
41
|
+
export const Updates = UpdatesTemplate.bind({});
|
|
@@ -1,2 +1,52 @@
|
|
|
1
1
|
import type { YagrWidgetData } from '../../types';
|
|
2
2
|
export declare const line10: YagrWidgetData;
|
|
3
|
+
export declare const getNewConfig: () => {
|
|
4
|
+
libraryConfig: {
|
|
5
|
+
title: {
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
chart?: import("@gravity-ui/yagr/dist/YagrCore/types").YagrChartOptions | undefined;
|
|
9
|
+
legend?: import("@gravity-ui/yagr/dist/YagrCore/plugins/legend/legend").LegendOptions | undefined;
|
|
10
|
+
axes?: Record<string, import("@gravity-ui/yagr/dist/YagrCore/types").AxisOptions> | undefined;
|
|
11
|
+
cursor?: import("@gravity-ui/yagr/dist/YagrCore/plugins/cursor/cursor").CursorOptions | undefined;
|
|
12
|
+
timeline?: number[] | undefined;
|
|
13
|
+
tooltip?: Partial<import("@gravity-ui/yagr/dist/YagrCore/plugins/tooltip/types").TooltipOptions> | undefined;
|
|
14
|
+
grid?: import("uplot").Axis.Grid | undefined;
|
|
15
|
+
markers?: import("@gravity-ui/yagr/dist/YagrCore/types").MarkersOptions | undefined;
|
|
16
|
+
scales?: Record<string, import("@gravity-ui/yagr/dist/YagrCore/types").Scale> | undefined;
|
|
17
|
+
series?: import("@gravity-ui/yagr/dist/YagrCore/types").RawSerieData<Omit<import("@gravity-ui/yagr/dist/YagrCore/types").SeriesOptions, "type"> & {
|
|
18
|
+
type?: import("@gravity-ui/yagr/dist/YagrCore/types").ChartType | undefined;
|
|
19
|
+
}>[] | undefined;
|
|
20
|
+
hooks?: import("@gravity-ui/yagr/dist/YagrCore/types").YagrHooks | undefined;
|
|
21
|
+
processing?: import("@gravity-ui/yagr/dist/YagrCore/types").ProcessingSettings | undefined;
|
|
22
|
+
editUplotOptions?: ((opts: import("uplot").Options) => import("uplot").Options) | undefined;
|
|
23
|
+
plugins?: Record<string, import("@gravity-ui/yagr/dist/YagrCore/types").YagrPlugin<{}, []>> | undefined;
|
|
24
|
+
};
|
|
25
|
+
data: {
|
|
26
|
+
timeline: number[];
|
|
27
|
+
graphs: {
|
|
28
|
+
data: number[];
|
|
29
|
+
name?: string | undefined;
|
|
30
|
+
id?: string | undefined;
|
|
31
|
+
scale?: string | undefined;
|
|
32
|
+
focus?: boolean | undefined;
|
|
33
|
+
show?: boolean | undefined;
|
|
34
|
+
color?: string | undefined;
|
|
35
|
+
spanGaps?: boolean | undefined;
|
|
36
|
+
cursorOptions?: Pick<import("@gravity-ui/yagr/dist/YagrCore/plugins/cursor/cursor").CursorOptions, "snapToValues" | "markersSize"> | undefined;
|
|
37
|
+
formatter?: ((value: string | number | null, serie: import("uplot").Series) => string) | undefined;
|
|
38
|
+
precision?: number | undefined;
|
|
39
|
+
snapToValues?: false | import("@gravity-ui/yagr/dist/YagrCore/types").SnapToValue | undefined;
|
|
40
|
+
stackGroup?: number | undefined;
|
|
41
|
+
title?: string | ((sIdx: number) => string) | undefined;
|
|
42
|
+
transform?: ((val: string | number | null, series: import("@gravity-ui/yagr/dist/YagrCore/types").DataSeries[], idx: number) => number | null) | undefined;
|
|
43
|
+
showInTooltip?: boolean | undefined;
|
|
44
|
+
type?: import("@gravity-ui/yagr/dist/YagrCore/types").ChartType | undefined;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
sources?: Record<number, {
|
|
48
|
+
data: {
|
|
49
|
+
program: string;
|
|
50
|
+
};
|
|
51
|
+
}> | undefined;
|
|
52
|
+
};
|
|
@@ -61,3 +61,18 @@ export const line10 = {
|
|
|
61
61
|
processing: {},
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
|
+
export const getNewConfig = () => {
|
|
65
|
+
const startPoint = (Math.random() * 10 ** 5) >> 0; // eslint-disable-line no-bitwise
|
|
66
|
+
return Object.assign(Object.assign({}, line10), { libraryConfig: Object.assign(Object.assign({}, line10.libraryConfig), { title: {
|
|
67
|
+
text: 'line: random 100 pts',
|
|
68
|
+
} }), data: {
|
|
69
|
+
timeline: new Array(100).fill(0).map((_, i) => {
|
|
70
|
+
return startPoint + i * 1000;
|
|
71
|
+
}),
|
|
72
|
+
graphs: line10.data.graphs.map((graph) => {
|
|
73
|
+
return Object.assign(Object.assign({}, graph), { data: new Array(100).fill(0).map(() => {
|
|
74
|
+
return (Math.random() * 100) >> 0; // eslint-disable-line no-bitwise
|
|
75
|
+
}) });
|
|
76
|
+
}),
|
|
77
|
+
} });
|
|
78
|
+
};
|
|
@@ -6,13 +6,13 @@ const DATA = {
|
|
|
6
6
|
describe('plugins/yagr/utils', () => {
|
|
7
7
|
describe('shapeYagrConfig > check chart property', () => {
|
|
8
8
|
test.each([
|
|
9
|
-
[{}, {
|
|
10
|
-
[{
|
|
11
|
-
[{
|
|
9
|
+
[{}, { appearance: { locale: 'en', theme: 'dark' } }],
|
|
10
|
+
[{ appearance: { locale: 'ru' } }, { appearance: { locale: 'ru', theme: 'dark' } }],
|
|
11
|
+
[{ appearance: { theme: 'light' } }, { appearance: { locale: 'en', theme: 'light' } }],
|
|
12
12
|
[
|
|
13
13
|
{ series: { type: 'dots' }, select: { zoom: false }, timeMultiplier: 1 },
|
|
14
14
|
{
|
|
15
|
-
|
|
15
|
+
appearance: { locale: 'en', theme: 'dark' },
|
|
16
16
|
series: { type: 'dots' },
|
|
17
17
|
select: { zoom: false },
|
|
18
18
|
timeMultiplier: 1,
|
|
@@ -23,9 +23,11 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
|
|
|
23
23
|
onRender === null || onRender === void 0 ? void 0 : onRender({ renderTime });
|
|
24
24
|
}, [onLoad, data]);
|
|
25
25
|
const onWindowResize = React.useCallback(() => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (yagrRef.current) {
|
|
27
|
+
const chart = yagrRef.current.yagr();
|
|
28
|
+
if (!chart) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
29
31
|
const root = chart.root;
|
|
30
32
|
const height = root.offsetHeight;
|
|
31
33
|
const width = root.offsetWidth;
|
|
@@ -38,9 +40,9 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
|
|
|
38
40
|
onWindowResize();
|
|
39
41
|
},
|
|
40
42
|
}), [onWindowResize]);
|
|
41
|
-
React.
|
|
43
|
+
React.useEffect(() => {
|
|
42
44
|
var _a, _b, _c, _d;
|
|
43
|
-
const yagr = (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.
|
|
45
|
+
const yagr = (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.yagr();
|
|
44
46
|
if (!yagr) {
|
|
45
47
|
return;
|
|
46
48
|
}
|
|
@@ -67,11 +69,11 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
|
|
|
67
69
|
handlers.mouseDown = null;
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
|
-
});
|
|
72
|
+
}, []);
|
|
71
73
|
React.useLayoutEffect(() => {
|
|
72
74
|
var _a;
|
|
73
|
-
onChartLoad === null || onChartLoad === void 0 ? void 0 : onChartLoad({ widget: (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.
|
|
74
|
-
}, []);
|
|
75
|
+
onChartLoad === null || onChartLoad === void 0 ? void 0 : onChartLoad({ widget: (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.yagr() });
|
|
76
|
+
}, [yagrRef, onChartLoad]);
|
|
75
77
|
return (React.createElement(YagrComponent, { ref: yagrRef, id: id, config: config, debug: debug, onChartLoad: handleChartLoading }));
|
|
76
78
|
});
|
|
77
79
|
export default YagrWidget;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
2
|
import { formatTooltip } from './tooltip';
|
|
3
3
|
const calcOption = (d) => {
|
|
4
|
-
return typeof d === 'object'
|
|
4
|
+
return typeof d === 'object' && d !== null
|
|
5
5
|
? Object.values(d).reduce((_, t) => {
|
|
6
6
|
return t;
|
|
7
7
|
})
|
|
@@ -16,7 +16,7 @@ export const renderTooltip = (data) => {
|
|
|
16
16
|
const cfg = data.yagr.config;
|
|
17
17
|
const timeMultiplier = cfg.chart.timeMultiplier || 1;
|
|
18
18
|
const opts = data.options;
|
|
19
|
-
const { x,
|
|
19
|
+
const { x, state } = data;
|
|
20
20
|
let sumTotal = 0;
|
|
21
21
|
const rows = Object.values(data.scales).reduce((acc, scale) => {
|
|
22
22
|
sumTotal += scale.sum || 0;
|
|
@@ -27,7 +27,7 @@ export const renderTooltip = (data) => {
|
|
|
27
27
|
const maxLines = calcOption(opts.maxLines);
|
|
28
28
|
const valueFormatter = calcOption(opts.value);
|
|
29
29
|
// eslint-disable-next-line no-nested-ternary
|
|
30
|
-
const hiddenRowsNumber = pinned
|
|
30
|
+
const hiddenRowsNumber = state.pinned
|
|
31
31
|
? undefined
|
|
32
32
|
: lines > maxLines
|
|
33
33
|
? Math.abs(maxLines - lines)
|
|
@@ -50,6 +50,6 @@ export const renderTooltip = (data) => {
|
|
|
50
50
|
tooltipFormatOptions.sum = valueFormatter(sumTotal);
|
|
51
51
|
}
|
|
52
52
|
return formatTooltip(tooltipFormatOptions, {
|
|
53
|
-
lastVisibleRowIndex: pinned ? rows.length - 1 : maxLines - 1,
|
|
53
|
+
lastVisibleRowIndex: state.pinned ? rows.length - 1 : maxLines - 1,
|
|
54
54
|
});
|
|
55
55
|
};
|
|
@@ -87,7 +87,7 @@ export const shapeYagrConfig = (args) => {
|
|
|
87
87
|
const { data, libraryConfig, theme } = args;
|
|
88
88
|
const config = Object.assign(Object.assign({}, libraryConfig), { timeline: data.timeline, series: data.graphs });
|
|
89
89
|
const chart = {
|
|
90
|
-
|
|
90
|
+
appearance: {
|
|
91
91
|
locale: settings.get('lang'),
|
|
92
92
|
theme,
|
|
93
93
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/chartkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "React component used to render charts based on any sources you need",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "git@github.com:gravity-ui/ChartKit.git",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@gravity-ui/yagr": "^
|
|
16
|
+
"@gravity-ui/yagr": "^3.1.0",
|
|
17
17
|
"bem-cn-lite": "^4.1.0",
|
|
18
18
|
"highcharts": "^8.2.2",
|
|
19
19
|
"highcharts-react-official": "^3.0.0",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"typescript": "^4.2.3"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"
|
|
68
|
+
"@gravity-ui/uikit": "^4.0.0",
|
|
69
69
|
"moment": "^2.19.3",
|
|
70
|
-
"
|
|
70
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"test": "jest",
|