@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,27 @@
1
+ import { CHARTKIT_ERROR_CODE, ChartKitError, isChartKitError } from '../chartkit-error';
2
+ describe('libs/chartkit-error', () => {
3
+ test.each([
4
+ [new ChartKitError(), true],
5
+ [new Error(), false],
6
+ [null, false],
7
+ [undefined, false],
8
+ ])('isChartKitError (args: %j)', (error, expected) => {
9
+ const result = isChartKitError(error);
10
+ expect(result).toEqual(expected);
11
+ });
12
+ test.each([
13
+ [undefined, CHARTKIT_ERROR_CODE.UNKNOWN],
14
+ [{ code: CHARTKIT_ERROR_CODE.NO_DATA }, CHARTKIT_ERROR_CODE.NO_DATA],
15
+ ])('check ChartKitError code (args: %j)', (args, expected) => {
16
+ let result = '';
17
+ try {
18
+ throw new ChartKitError(args);
19
+ }
20
+ catch (error) {
21
+ if (isChartKitError(error)) {
22
+ result = error.code;
23
+ }
24
+ }
25
+ expect(result).toEqual(expected);
26
+ });
27
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { settings } from '../settings';
2
+ const resetSettings = () => settings.set({ lang: 'en' });
3
+ describe('libs/settings', () => {
4
+ it('Default lang should be equal to en', () => {
5
+ const result = settings.get('lang');
6
+ expect(result).toBe('en');
7
+ });
8
+ it('Changed lang should be equal to ru', () => {
9
+ settings.set({
10
+ lang: 'ru',
11
+ });
12
+ const result = settings.get('lang');
13
+ expect(result).toBe('ru');
14
+ });
15
+ beforeAll(resetSettings);
16
+ afterEach(resetSettings);
17
+ });
@@ -0,0 +1,4 @@
1
+ import { Meta } from '@storybook/react';
2
+ export declare const CategoryXAxis: 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,75 @@
1
+ import React from 'react';
2
+ import { object, withKnobs } from '@storybook/addon-knobs';
3
+ import { Button } from '@gravity-ui/uikit';
4
+ import { settings } from '../../../../libs';
5
+ import { ChartKit } from '../../../../components/ChartKit';
6
+ import { D3Plugin } from '../..';
7
+ const Template = () => {
8
+ const [shown, setShown] = React.useState(false);
9
+ const chartkitRef = React.useRef();
10
+ const data = {
11
+ legend: { enabled: true },
12
+ tooltip: { enabled: false },
13
+ yAxis: [
14
+ {
15
+ type: 'linear',
16
+ labels: { enabled: true },
17
+ min: 0,
18
+ },
19
+ ],
20
+ series: {
21
+ data: [
22
+ {
23
+ type: 'bar-x',
24
+ visible: true,
25
+ data: [
26
+ {
27
+ category: 'A',
28
+ x: 10,
29
+ y: 100,
30
+ },
31
+ {
32
+ category: 'B',
33
+ x: 12,
34
+ y: 80,
35
+ },
36
+ ],
37
+ name: 'AB',
38
+ },
39
+ {
40
+ type: 'bar-x',
41
+ visible: true,
42
+ data: [
43
+ {
44
+ category: 'C',
45
+ x: 95.5,
46
+ y: 120,
47
+ },
48
+ ],
49
+ name: 'C',
50
+ },
51
+ ],
52
+ },
53
+ title: { text: 'Category axis' },
54
+ xAxis: {
55
+ type: 'category',
56
+ categories: ['A', 'B', 'C'],
57
+ labels: { enabled: true },
58
+ },
59
+ };
60
+ if (!shown) {
61
+ settings.set({ plugins: [D3Plugin] });
62
+ return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
63
+ }
64
+ return (React.createElement("div", { style: {
65
+ height: '80vh',
66
+ width: '100%',
67
+ } },
68
+ React.createElement(ChartKit, { ref: chartkitRef, type: "d3", data: object('data', data) })));
69
+ };
70
+ export const CategoryXAxis = Template.bind({});
71
+ const meta = {
72
+ title: 'Plugins/D3/Bar-X',
73
+ decorators: [withKnobs],
74
+ };
75
+ export default meta;
@@ -0,0 +1,4 @@
1
+ import { Meta } from '@storybook/react';
2
+ export declare const DatetimeXAxis: 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,71 @@
1
+ import React from 'react';
2
+ import { object, withKnobs } from '@storybook/addon-knobs';
3
+ import { Button } from '@gravity-ui/uikit';
4
+ import { settings } from '../../../../libs';
5
+ import { ChartKit } from '../../../../components/ChartKit';
6
+ import { D3Plugin } from '../..';
7
+ const Template = () => {
8
+ const [shown, setShown] = React.useState(false);
9
+ const chartkitRef = React.useRef();
10
+ const data = {
11
+ title: { text: 'DateTime axis' },
12
+ xAxis: {
13
+ type: 'datetime',
14
+ labels: { enabled: true },
15
+ },
16
+ legend: { enabled: true },
17
+ tooltip: { enabled: false },
18
+ yAxis: [
19
+ {
20
+ type: 'linear',
21
+ labels: { enabled: true },
22
+ min: 0,
23
+ },
24
+ ],
25
+ series: {
26
+ data: [
27
+ {
28
+ type: 'bar-x',
29
+ visible: true,
30
+ data: [
31
+ {
32
+ x: Number(new Date(2022, 10, 10)),
33
+ y: 100,
34
+ },
35
+ {
36
+ x: Number(new Date(2023, 2, 5)),
37
+ y: 80,
38
+ },
39
+ ],
40
+ name: 'AB',
41
+ },
42
+ {
43
+ type: 'bar-x',
44
+ visible: true,
45
+ data: [
46
+ {
47
+ x: Number(new Date(2022, 11, 25)),
48
+ y: 120,
49
+ },
50
+ ],
51
+ name: 'C',
52
+ },
53
+ ],
54
+ },
55
+ };
56
+ if (!shown) {
57
+ settings.set({ plugins: [D3Plugin] });
58
+ return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
59
+ }
60
+ return (React.createElement("div", { style: {
61
+ height: '80vh',
62
+ width: '100%',
63
+ } },
64
+ React.createElement(ChartKit, { ref: chartkitRef, type: "d3", data: object('data', data) })));
65
+ };
66
+ export const DatetimeXAxis = Template.bind({});
67
+ const meta = {
68
+ title: 'Plugins/D3/Bar-X',
69
+ decorators: [withKnobs],
70
+ };
71
+ export default meta;
@@ -0,0 +1,4 @@
1
+ import { Meta } from '@storybook/react';
2
+ export declare const LinearXAxis: 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,78 @@
1
+ import React from 'react';
2
+ import { withKnobs, object } from '@storybook/addon-knobs';
3
+ import { Button } from '@gravity-ui/uikit';
4
+ import { settings } from '../../../../libs';
5
+ import { ChartKit } from '../../../../components/ChartKit';
6
+ import { D3Plugin } from '../..';
7
+ const Template = () => {
8
+ const [shown, setShown] = React.useState(false);
9
+ const chartkitRef = React.useRef();
10
+ const data = {
11
+ series: {
12
+ data: [
13
+ {
14
+ type: 'bar-x',
15
+ visible: true,
16
+ data: [
17
+ {
18
+ category: 'A',
19
+ x: 10,
20
+ y: 100,
21
+ },
22
+ {
23
+ category: 'B',
24
+ x: 12,
25
+ y: 80,
26
+ },
27
+ ],
28
+ name: 'AB',
29
+ },
30
+ {
31
+ type: 'bar-x',
32
+ visible: true,
33
+ data: [
34
+ {
35
+ category: 'C',
36
+ x: 95.5,
37
+ y: 120,
38
+ },
39
+ ],
40
+ name: 'C',
41
+ },
42
+ ],
43
+ },
44
+ title: { text: 'Linear axis' },
45
+ xAxis: {
46
+ min: 0,
47
+ type: 'linear',
48
+ labels: { enabled: true },
49
+ },
50
+ yAxis: [
51
+ {
52
+ type: 'linear',
53
+ labels: { enabled: true },
54
+ min: 0,
55
+ ticks: {
56
+ pixelInterval: 100,
57
+ },
58
+ },
59
+ ],
60
+ legend: { enabled: true },
61
+ tooltip: { enabled: false },
62
+ };
63
+ if (!shown) {
64
+ settings.set({ plugins: [D3Plugin] });
65
+ return React.createElement(Button, { onClick: () => setShown(true) }, "Show chart");
66
+ }
67
+ return (React.createElement("div", { style: {
68
+ height: '80vh',
69
+ width: '100%',
70
+ } },
71
+ React.createElement(ChartKit, { ref: chartkitRef, type: "d3", data: object('data', data) })));
72
+ };
73
+ export const LinearXAxis = Template.bind({});
74
+ const meta = {
75
+ title: 'Plugins/D3/Bar-X',
76
+ decorators: [withKnobs],
77
+ };
78
+ export default meta;