@gravity-ui/chartkit 3.2.0-beta.2 → 3.3.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.
Files changed (72) hide show
  1. package/build/libs/chartkit-error/__tests__/chartkit-error.js +27 -0
  2. package/build/libs/settings/__tests__/settings.test.d.ts +1 -0
  3. package/build/libs/settings/__tests__/settings.test.js +17 -0
  4. package/build/plugins/d3/__stories__/bar-x/category.stories.d.ts +4 -0
  5. package/build/plugins/d3/__stories__/bar-x/category.stories.js +75 -0
  6. package/build/plugins/d3/__stories__/bar-x/datetime.stories.d.ts +4 -0
  7. package/build/plugins/d3/__stories__/bar-x/datetime.stories.js +71 -0
  8. package/build/plugins/d3/__stories__/bar-x/linear.stories.d.ts +4 -0
  9. package/build/plugins/d3/__stories__/bar-x/linear.stories.js +78 -0
  10. package/build/plugins/d3/__stories__/penguins.json +3098 -0
  11. package/build/plugins/d3/__stories__/scatter/LinearCategories.stories.d.ts +4 -0
  12. package/build/plugins/d3/__stories__/scatter/LinearCategories.stories.js +100 -0
  13. package/build/plugins/d3/__stories__/scatter/Timestamp.stories.d.ts +4 -0
  14. package/build/plugins/d3/__stories__/scatter/Timestamp.stories.js +108 -0
  15. package/build/plugins/d3/renderer/components/AxisX.js +15 -5
  16. package/build/plugins/d3/renderer/components/AxisY.js +18 -8
  17. package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +15 -8
  18. package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +7 -0
  19. package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +8 -0
  20. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +7 -0
  21. package/build/plugins/d3/renderer/hooks/useScales/index.js +13 -10
  22. package/build/plugins/d3/renderer/hooks/useShapes/{bar.d.ts → bar-x.d.ts} +3 -3
  23. package/build/plugins/d3/renderer/hooks/useShapes/{bar.js → bar-x.js} +1 -1
  24. package/build/plugins/d3/renderer/hooks/useShapes/index.js +3 -3
  25. package/build/plugins/highcharts/__stories__/Line.stories.d.ts +3 -0
  26. package/build/plugins/highcharts/__stories__/Line.stories.js +12 -0
  27. package/build/plugins/highcharts/__stories__/Pie.stories.d.ts +3 -0
  28. package/build/plugins/highcharts/__stories__/Pie.stories.js +12 -0
  29. package/build/plugins/highcharts/__stories__/area/Range.stories.d.ts +3 -0
  30. package/build/plugins/highcharts/__stories__/area/Range.stories.js +12 -0
  31. package/build/plugins/highcharts/__stories__/area/Stacked.stories.d.ts +3 -0
  32. package/build/plugins/highcharts/__stories__/area/Stacked.stories.js +12 -0
  33. package/build/plugins/highcharts/__stories__/column/HorizontalStacked.stories.d.ts +3 -0
  34. package/build/plugins/highcharts/__stories__/column/HorizontalStacked.stories.js +12 -0
  35. package/build/plugins/highcharts/__stories__/column/Vertical.stories.d.ts +3 -0
  36. package/build/plugins/highcharts/__stories__/column/Vertical.stories.js +12 -0
  37. package/build/plugins/highcharts/__stories__/column/VerticalStacked.stories.d.ts +3 -0
  38. package/build/plugins/highcharts/__stories__/column/VerticalStacked.stories.js +12 -0
  39. package/build/plugins/highcharts/__stories__/combined/ComboChartWithSameLegendValues.stories.d.ts +3 -0
  40. package/build/plugins/highcharts/__stories__/combined/ComboChartWithSameLegendValues.stories.js +12 -0
  41. package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.d.ts +3 -0
  42. package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.js +12 -0
  43. package/build/plugins/highcharts/__stories__/components/ChartStory.d.ts +12 -0
  44. package/build/plugins/highcharts/__stories__/components/ChartStory.js +28 -0
  45. package/build/plugins/highcharts/__stories__/constants/story-settings.d.ts +42 -0
  46. package/build/plugins/highcharts/__stories__/constants/story-settings.js +42 -0
  47. package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.d.ts +3 -0
  48. package/build/plugins/highcharts/__stories__/custom-error-render/custom-error-render.stories.js +41 -0
  49. package/build/plugins/highcharts/__stories__/no-data/no-data.stories.d.ts +3 -0
  50. package/build/plugins/highcharts/__stories__/no-data/no-data.stories.js +20 -0
  51. package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.d.ts +3 -0
  52. package/build/plugins/highcharts/__stories__/pie/WithTotals.stories.js +12 -0
  53. package/build/plugins/highcharts/__tests__/prepare-data.test.d.ts +1 -0
  54. package/build/plugins/highcharts/__tests__/prepare-data.test.js +13 -0
  55. package/build/plugins/indicator/__stories__/Indicator.stories.d.ts +4 -0
  56. package/build/plugins/indicator/__stories__/Indicator.stories.js +45 -0
  57. package/build/plugins/yagr/__stories__/Yagr.stories.d.ts +6 -0
  58. package/build/plugins/yagr/__stories__/Yagr.stories.js +90 -0
  59. package/build/plugins/yagr/__stories__/mocks/line10.d.ts +53 -0
  60. package/build/plugins/yagr/__stories__/mocks/line10.js +78 -0
  61. package/build/plugins/yagr/__tests__/utils.test.d.ts +1 -0
  62. package/build/plugins/yagr/__tests__/utils.test.js +26 -0
  63. package/build/types/widget-data/axis.d.ts +18 -0
  64. package/build/types/widget-data/{bar.d.ts → bar-x.d.ts} +4 -4
  65. package/build/types/widget-data/bar-x.js +1 -0
  66. package/build/types/widget-data/index.d.ts +1 -1
  67. package/build/types/widget-data/index.js +1 -1
  68. package/build/types/widget-data/series.d.ts +3 -3
  69. package/build/utils/__tests__/common.test.d.ts +1 -0
  70. package/build/utils/__tests__/common.test.js +9 -0
  71. package/package.json +2 -7
  72. /package/build/{types/widget-data/bar.js → libs/chartkit-error/__tests__/chartkit-error.d.ts} +0 -0
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { data } from '../../mocks/combo-chart-with-same-legend-titles';
4
+ import { ChartStory } from '../components/ChartStory';
5
+ export default {
6
+ title: 'Plugins/Highcharts/Combined Charts',
7
+ component: ChartKit,
8
+ };
9
+ const Template = () => {
10
+ return React.createElement(ChartStory, { height: "500px", data: data });
11
+ };
12
+ export const ComboChart = Template.bind({});
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
2
+ export default _default;
3
+ export declare const TwoAxis: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { ChartStory } from '../components/ChartStory';
4
+ import { data } from '../../mocks/complex';
5
+ export default {
6
+ title: 'Plugins/Highcharts/TwoAxis',
7
+ component: ChartKit,
8
+ };
9
+ const Template = () => {
10
+ return React.createElement(ChartStory, { data: data, height: "500px" });
11
+ };
12
+ export const TwoAxis = Template.bind({});
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { RenderError } from '../../../../types';
3
+ import { HighchartsWidgetData } from '../../types';
4
+ export type ChartStoryProps = {
5
+ data: HighchartsWidgetData;
6
+ withoutPlugin?: boolean;
7
+ visible?: boolean;
8
+ height?: string;
9
+ width?: string;
10
+ renderError?: RenderError;
11
+ };
12
+ export declare const ChartStory: React.FC<ChartStoryProps>;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { Button } from '@gravity-ui/uikit';
3
+ import { settings } from '../../../../libs';
4
+ import { HighchartsPlugin } from '../../index';
5
+ import holidays from '../../mocks/holidays';
6
+ import { ChartKit } from '../../../../components/ChartKit';
7
+ const DEFAULT_STORY_HEIGHT = '300px';
8
+ const DEFAULT_STORY_WIDTH = '100%';
9
+ export const ChartStory = (props) => {
10
+ const { height, width, data } = props;
11
+ const initRef = React.useRef(false);
12
+ const [visible, setVisible] = React.useState(Boolean(props.visible));
13
+ const chartKitRef = React.useRef();
14
+ if (!initRef.current) {
15
+ if (!props.withoutPlugin) {
16
+ settings.set({ plugins: [HighchartsPlugin], extra: { holidays } });
17
+ }
18
+ initRef.current = true;
19
+ }
20
+ if (!visible) {
21
+ return React.createElement(Button, { onClick: () => setVisible(true) }, "Show chart");
22
+ }
23
+ return (React.createElement("div", { style: {
24
+ height: height || DEFAULT_STORY_HEIGHT,
25
+ width: width || DEFAULT_STORY_WIDTH,
26
+ } },
27
+ React.createElement(ChartKit, { ref: chartKitRef, type: "highcharts", data: data, renderError: props.renderError })));
28
+ };
@@ -0,0 +1,42 @@
1
+ export declare const defaultChartKitPropsControlsState: {
2
+ ref: {
3
+ table: {
4
+ disable: boolean;
5
+ };
6
+ };
7
+ hoistConfigError: {
8
+ table: {
9
+ disable: boolean;
10
+ };
11
+ };
12
+ onError: {
13
+ table: {
14
+ disable: boolean;
15
+ };
16
+ };
17
+ data: {
18
+ table: {
19
+ disable: boolean;
20
+ };
21
+ };
22
+ type: {
23
+ table: {
24
+ disable: boolean;
25
+ };
26
+ };
27
+ id: {
28
+ table: {
29
+ disable: boolean;
30
+ };
31
+ };
32
+ isMobile: {
33
+ table: {
34
+ disable: boolean;
35
+ };
36
+ };
37
+ onLoad: {
38
+ table: {
39
+ disable: boolean;
40
+ };
41
+ };
42
+ };
@@ -0,0 +1,42 @@
1
+ export const defaultChartKitPropsControlsState = {
2
+ ref: {
3
+ table: {
4
+ disable: true,
5
+ },
6
+ },
7
+ hoistConfigError: {
8
+ table: {
9
+ disable: true,
10
+ },
11
+ },
12
+ onError: {
13
+ table: {
14
+ disable: true,
15
+ },
16
+ },
17
+ data: {
18
+ table: {
19
+ disable: true,
20
+ },
21
+ },
22
+ type: {
23
+ table: {
24
+ disable: true,
25
+ },
26
+ },
27
+ id: {
28
+ table: {
29
+ disable: true,
30
+ },
31
+ },
32
+ isMobile: {
33
+ table: {
34
+ disable: true,
35
+ },
36
+ },
37
+ onLoad: {
38
+ table: {
39
+ disable: true,
40
+ },
41
+ },
42
+ };
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
2
+ export default _default;
3
+ export declare const CustomErrorRender: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { ChartStory } from '../components/ChartStory';
4
+ import { Button } from '@gravity-ui/uikit';
5
+ import { CHARTKIT_ERROR_CODE, settings } from '../../../../libs';
6
+ import { HighchartsPlugin } from '../../index';
7
+ import holidays from '../../mocks/holidays';
8
+ import { noData, filledData } from '../../mocks/custom-error-render';
9
+ export default {
10
+ title: 'Plugins/Highcharts/CustomErrorRender',
11
+ component: ChartKit,
12
+ };
13
+ const Template = () => {
14
+ const [data, setData] = React.useState(noData);
15
+ const renderErrorView = React.useCallback(({ error, message, resetError }) => {
16
+ function renderFixButton() {
17
+ if (!('code' in error)) {
18
+ return null;
19
+ }
20
+ switch (error.code) {
21
+ case CHARTKIT_ERROR_CODE.UNKNOWN_PLUGIN:
22
+ return (React.createElement(Button, { onClick: () => {
23
+ settings.set({ plugins: [HighchartsPlugin], extra: { holidays } });
24
+ resetError();
25
+ } }, "Add highcharts plugin"));
26
+ case CHARTKIT_ERROR_CODE.NO_DATA:
27
+ return (React.createElement(Button, { onClick: () => {
28
+ setData(filledData);
29
+ } }, "Add data"));
30
+ default:
31
+ return null;
32
+ }
33
+ }
34
+ return (React.createElement("div", null,
35
+ React.createElement("h2", null, message),
36
+ renderFixButton()));
37
+ }, []);
38
+ return (React.createElement("div", null,
39
+ React.createElement(ChartStory, { withoutPlugin: true, data: data, visible: true, renderError: renderErrorView })));
40
+ };
41
+ export const CustomErrorRender = Template.bind({});
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
2
+ export default _default;
3
+ export declare const NoData: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { noData, filledData } from '../../mocks/no-data';
4
+ import { ChartStory } from '../components/ChartStory';
5
+ import { Button } from '@gravity-ui/uikit';
6
+ export default {
7
+ title: 'Plugins/Highcharts/NoData',
8
+ component: ChartKit,
9
+ };
10
+ const Template = () => {
11
+ const [data, setData] = React.useState(noData);
12
+ const handleUpdateData = React.useCallback(() => {
13
+ setData(filledData);
14
+ }, []);
15
+ return (React.createElement("div", null,
16
+ React.createElement("div", { style: { marginBottom: 12 } },
17
+ React.createElement(Button, { onClick: handleUpdateData }, "Add data")),
18
+ React.createElement(ChartStory, { data: data, visible: true })));
19
+ };
20
+ export const NoData = Template.bind({});
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
2
+ export default _default;
3
+ export declare const WithTotals: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { ChartKit } from '../../../../components/ChartKit';
3
+ import { data } from '../../mocks/pie-with-totals';
4
+ import { ChartStory } from '../components/ChartStory';
5
+ export default {
6
+ title: 'Plugins/Highcharts/Pie',
7
+ component: ChartKit,
8
+ };
9
+ const Template = () => {
10
+ return React.createElement(ChartStory, { data: data });
11
+ };
12
+ export const WithTotals = Template.bind({});
@@ -0,0 +1,13 @@
1
+ import { prepareData } from '../renderer/helpers/prepare-data';
2
+ import { data } from '../mocks/line';
3
+ describe('plugins/highcharts/helpers', () => {
4
+ describe('prepareData', () => {
5
+ it('should not throw an error', () => {
6
+ expect(() => prepareData(data.data, data.config)).not.toThrowError();
7
+ });
8
+ it('should throw an error', () => {
9
+ const configWithLinesLimit = Object.assign(Object.assign({}, data.config), { linesLimit: 1 });
10
+ expect(() => prepareData(data.data, configWithLinesLimit)).toThrowError();
11
+ });
12
+ });
13
+ });
@@ -0,0 +1,4 @@
1
+ import { Meta } from '@storybook/react';
2
+ export declare const Showcase: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
3
+ declare const meta: Meta;
4
+ export default meta;
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { withKnobs, boolean, color as colorKnob, radios, text } from '@storybook/addon-knobs';
3
+ import { cloneDeep } from 'lodash';
4
+ import { Button } from '@gravity-ui/uikit';
5
+ import { settings } from '../../../libs';
6
+ import { ChartKit } from '../../../components/ChartKit';
7
+ import { IndicatorPlugin } from '../';
8
+ const data = {
9
+ data: [
10
+ {
11
+ content: {
12
+ current: {
13
+ value: 1539577973,
14
+ },
15
+ },
16
+ },
17
+ ],
18
+ };
19
+ const Template = () => {
20
+ const [shown, setShown] = React.useState(false);
21
+ const chartkitRef = React.useRef();
22
+ const color = colorKnob('color', '#4da2f1');
23
+ const size = radios('size', { s: 's', m: 'm', l: 'l', xl: 'xl' }, 'm');
24
+ const title = text('title', 'Value title');
25
+ const nowrap = boolean('nowrap', false);
26
+ const resultData = cloneDeep(data);
27
+ if (resultData.data) {
28
+ resultData.data[0].size = size;
29
+ resultData.data[0].color = color;
30
+ resultData.data[0].title = title;
31
+ resultData.data[0].nowrap = nowrap;
32
+ }
33
+ if (!shown) {
34
+ settings.set({ plugins: [IndicatorPlugin] });
35
+ return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
36
+ }
37
+ return (React.createElement("div", { style: { height: 300, width: '100%' } },
38
+ React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "indicator", data: resultData })));
39
+ };
40
+ export const Showcase = Template.bind({});
41
+ const meta = {
42
+ title: 'Plugins/Indicator',
43
+ decorators: [withKnobs],
44
+ };
45
+ export default meta;
@@ -0,0 +1,6 @@
1
+ import '@gravity-ui/yagr/dist/index.css';
2
+ declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-0a347bb9").R, import("@storybook/types").Args>;
3
+ export default _default;
4
+ export declare const Line: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
5
+ export declare const Updates: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
6
+ export declare const CustomTooltip: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-0a347bb9").R, any>;
@@ -0,0 +1,90 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Button } from '@gravity-ui/uikit';
3
+ import { settings } from '../../../libs';
4
+ import { YagrPlugin } from '../../../plugins';
5
+ import { ChartKit } from '../../../components/ChartKit';
6
+ import { getNewConfig, line10 } from './mocks/line10';
7
+ import '@gravity-ui/yagr/dist/index.css';
8
+ import placement from '@gravity-ui/yagr/dist/YagrCore/plugins/tooltip/placement';
9
+ import { dateTime } from '@gravity-ui/date-utils';
10
+ export default {
11
+ title: 'Plugins/Yagr',
12
+ component: ChartKit,
13
+ };
14
+ const LineTemplate = () => {
15
+ const [shown, setShown] = React.useState(false);
16
+ const chartkitRef = React.useRef();
17
+ if (!shown) {
18
+ settings.set({ plugins: [YagrPlugin] });
19
+ return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
20
+ }
21
+ return (React.createElement("div", { style: { height: 300, width: '100%' } },
22
+ React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: line10 })));
23
+ };
24
+ const UpdatesTemplate = () => {
25
+ const [shown, setShown] = React.useState(false);
26
+ const chartkitRef = React.useRef();
27
+ const [state, setState] = React.useState(line10);
28
+ const onStartUpdates = React.useCallback(() => {
29
+ setInterval(() => {
30
+ setState(getNewConfig());
31
+ }, 1000);
32
+ }, []);
33
+ if (!shown) {
34
+ settings.set({ plugins: [YagrPlugin] });
35
+ return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
36
+ }
37
+ return (React.createElement("div", { style: { height: 300, width: '100%' } },
38
+ React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: state }),
39
+ React.createElement(Button, { onClick: onStartUpdates }, "Start Updates"),
40
+ React.createElement(Button, { onClick: () => setState(getNewConfig()) }, "Once")));
41
+ };
42
+ function Tooltip({ yagr }) {
43
+ const [x, setX] = useState(null);
44
+ const [visible, setVisible] = useState(false);
45
+ const tooltipRef = React.useRef(null);
46
+ useEffect(() => {
47
+ var _a, _b, _c;
48
+ if (!yagr) {
49
+ return;
50
+ }
51
+ const onChange = (_, data) => {
52
+ var _a, _b;
53
+ setX((_a = data.data) === null || _a === void 0 ? void 0 : _a.x);
54
+ setVisible(data.state.visible);
55
+ if (data.state.visible && tooltipRef.current && ((_b = data.data) === null || _b === void 0 ? void 0 : _b.anchor)) {
56
+ placement(tooltipRef.current, data.data.anchor, 'right', {
57
+ xOffset: 24,
58
+ yOffset: 24,
59
+ });
60
+ }
61
+ };
62
+ (_a = yagr.plugins.tooltip) === null || _a === void 0 ? void 0 : _a.on('render', onChange);
63
+ (_b = yagr.plugins.tooltip) === null || _b === void 0 ? void 0 : _b.on('show', onChange);
64
+ (_c = yagr.plugins.tooltip) === null || _c === void 0 ? void 0 : _c.on('hide', onChange);
65
+ }, [yagr]);
66
+ if (!visible) {
67
+ return null;
68
+ }
69
+ return (React.createElement("div", { style: {
70
+ zIndex: 1000,
71
+ backgroundColor: 'white',
72
+ padding: 8,
73
+ pointerEvents: 'none',
74
+ }, ref: tooltipRef }, dateTime({ input: x !== null && x !== void 0 ? x : 0 }).format('DD MMMM YYYY HH:mm:ss')));
75
+ }
76
+ const CustomTooltipImpl = () => {
77
+ const [shown, setShown] = React.useState(false);
78
+ const chartkitRef = React.useRef();
79
+ const [state, setState] = React.useState(line10);
80
+ if (!shown) {
81
+ settings.set({ plugins: [YagrPlugin] });
82
+ return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
83
+ }
84
+ return (React.createElement("div", { style: { height: 300, width: '100%' } },
85
+ React.createElement(ChartKit, { ref: chartkitRef, id: "1", type: "yagr", data: state, tooltip: (props) => React.createElement(Tooltip, Object.assign({}, props)) }),
86
+ React.createElement(Button, { onClick: () => setState(getNewConfig()) }, "Change data")));
87
+ };
88
+ export const Line = LineTemplate.bind({});
89
+ export const Updates = UpdatesTemplate.bind({});
90
+ export const CustomTooltip = CustomTooltipImpl.bind({});
@@ -0,0 +1,53 @@
1
+ import type { YagrWidgetData } from '../../types';
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
+ title?: string | ((sIdx: number) => string) | undefined;
34
+ show?: boolean | undefined;
35
+ color?: string | undefined;
36
+ spanGaps?: boolean | undefined;
37
+ cursorOptions?: Pick<import("@gravity-ui/yagr/dist/YagrCore/plugins/cursor/cursor").CursorOptions, "snapToValues" | "markersSize"> | undefined;
38
+ formatter?: ((value: string | number | null, serie: import("uplot").Series) => string) | undefined;
39
+ precision?: number | undefined;
40
+ snapToValues?: false | import("@gravity-ui/yagr/dist/YagrCore/types").SnapToValue | undefined;
41
+ stackGroup?: number | 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
+ postProcess?: ((data: (number | null)[], idx: number, y: import("@gravity-ui/yagr/dist/YagrCore").default<import("@gravity-ui/yagr/dist/YagrCore/types").MinimalValidConfig>) => (number | null)[]) | undefined;
45
+ type?: import("@gravity-ui/yagr/dist/YagrCore/types").ChartType | undefined;
46
+ }[];
47
+ };
48
+ sources?: Record<number, {
49
+ data: {
50
+ program: string;
51
+ };
52
+ }> | undefined;
53
+ };
@@ -0,0 +1,78 @@
1
+ export const line10 = {
2
+ data: {
3
+ timeline: [
4
+ 1636838612441, 1636925012441, 1637011412441, 1637097812441, 1637184212441,
5
+ 1637270612441, 1637357012441, 1637443412441, 1637529812441, 1637616212441,
6
+ ],
7
+ graphs: [
8
+ {
9
+ id: '0',
10
+ name: 'Serie 1',
11
+ color: '#6c59c2',
12
+ data: [45, 52, 89, 72, 39, 49, 82, 59, 36, 5],
13
+ },
14
+ {
15
+ id: '1',
16
+ name: 'Serie 2',
17
+ color: '#6e8188',
18
+ data: [37, 6, 51, 10, 65, 35, 72, 0, 94, 54],
19
+ },
20
+ {
21
+ id: '2',
22
+ name: 'Serie 3',
23
+ color: '#e21576',
24
+ data: [26, 54, 15, 40, 43, 18, 65, 46, 51, 33],
25
+ },
26
+ ],
27
+ },
28
+ libraryConfig: {
29
+ chart: {
30
+ series: {
31
+ type: 'line',
32
+ },
33
+ select: {
34
+ zoom: false,
35
+ },
36
+ },
37
+ title: {
38
+ text: 'line: random 10 pts',
39
+ },
40
+ axes: {
41
+ x: {},
42
+ },
43
+ scales: {
44
+ x: {},
45
+ y: {
46
+ type: 'linear',
47
+ range: 'nice',
48
+ },
49
+ },
50
+ cursor: {
51
+ x: {
52
+ visible: true,
53
+ style: 'solid 2px rgba(230, 2, 7, 0.3)',
54
+ },
55
+ },
56
+ tooltip: {
57
+ show: true,
58
+ tracking: 'sticky',
59
+ },
60
+ legend: {},
61
+ processing: {},
62
+ },
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
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { shapeYagrConfig } from '../renderer/utils';
2
+ const DATA = {
3
+ timeline: [1],
4
+ graphs: [{ data: [45] }],
5
+ };
6
+ describe('plugins/yagr/utils', () => {
7
+ describe('shapeYagrConfig > check chart property', () => {
8
+ test.each([
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
+ [
13
+ { series: { type: 'dots' }, select: { zoom: false }, timeMultiplier: 1 },
14
+ {
15
+ appearance: { locale: 'en', theme: 'dark' },
16
+ series: { type: 'dots' },
17
+ select: { zoom: false },
18
+ timeMultiplier: 1,
19
+ },
20
+ ],
21
+ ])('(args: %j)', (chart, expected) => {
22
+ const config = shapeYagrConfig({ data: DATA, libraryConfig: { chart }, theme: 'dark' });
23
+ expect(config.chart).toEqual(expected);
24
+ });
25
+ });
26
+ });
@@ -21,4 +21,22 @@ export type ChartKitWidgetAxis = {
21
21
  };
22
22
  /** The minimum value of the axis. If undefined the min value is automatically calculate */
23
23
  min?: number;
24
+ grid?: {
25
+ /** Enable or disable the grid lines.
26
+ *
27
+ * Defaults to true.
28
+ * */
29
+ enabled?: boolean;
30
+ };
31
+ ticks?: {
32
+ /** Pixel interval of the tick marks. Not applicable to categorized axis.
33
+ * The specified value is only a hint; the interval between ticks can be greater or less depending on the data. */
34
+ pixelInterval?: number;
35
+ };
36
+ /** Padding of the max value relative to the length of the axis.
37
+ * A padding of 0.05 will make a 100px axis 5px longer.
38
+ *
39
+ * Defaults to 0.05 for Y axis and to 0.01 for X axis
40
+ * */
41
+ maxPadding?: number;
24
42
  };
@@ -1,6 +1,6 @@
1
1
  import type { BaseSeries, BaseSeriesData } from './base';
2
2
  import type { ChartKitWidgetSeriesOptions } from './series';
3
- export type BarSeriesData<T = any> = BaseSeriesData<T> & {
3
+ export type BarXSeriesData<T = any> = BaseSeriesData<T> & {
4
4
  /** The x value of the point */
5
5
  x?: number;
6
6
  /** The y value of the point */
@@ -8,9 +8,9 @@ export type BarSeriesData<T = any> = BaseSeriesData<T> & {
8
8
  /** Corresponding value of axis category */
9
9
  category?: string;
10
10
  };
11
- export type BarSeries<T = any> = BaseSeries & {
12
- type: 'bar';
13
- data: BarSeriesData<T>[];
11
+ export type BarXSeries<T = any> = BaseSeries & {
12
+ type: 'bar-x';
13
+ data: BarXSeriesData<T>[];
14
14
  /** The name of the series (used in legend) */
15
15
  name: string;
16
16
  /** The main color of the series (hex, rgba) */
@@ -0,0 +1 @@
1
+ export {};
@@ -10,7 +10,7 @@ export * from './chart';
10
10
  export * from './legend';
11
11
  export * from './pie';
12
12
  export * from './scatter';
13
- export * from './bar';
13
+ export * from './bar-x';
14
14
  export * from './series';
15
15
  export * from './title';
16
16
  export * from './tooltip';
@@ -4,7 +4,7 @@ export * from './chart';
4
4
  export * from './legend';
5
5
  export * from './pie';
6
6
  export * from './scatter';
7
- export * from './bar';
7
+ export * from './bar-x';
8
8
  export * from './series';
9
9
  export * from './title';
10
10
  export * from './tooltip';