@gravity-ui/chartkit 0.7.2
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 +127 -0
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/build/components/ChartKit.css +4 -0
- package/build/components/ChartKit.d.ts +19 -0
- package/build/components/ChartKit.js +42 -0
- package/build/components/ErrorBoundary/ErrorBoundary.d.ts +18 -0
- package/build/components/ErrorBoundary/ErrorBoundary.js +27 -0
- package/build/components/ErrorView/ErrorView.d.ts +7 -0
- package/build/components/ErrorView/ErrorView.js +6 -0
- package/build/components/Loader/Loader.css +7 -0
- package/build/components/Loader/Loader.d.ts +6 -0
- package/build/components/Loader/Loader.js +9 -0
- package/build/constants/common.d.ts +1 -0
- package/build/constants/common.js +2 -0
- package/build/constants/index.d.ts +1 -0
- package/build/constants/index.js +1 -0
- package/build/i18n/index.d.ts +7 -0
- package/build/i18n/index.js +10 -0
- package/build/i18n/keysets/en.json +11 -0
- package/build/i18n/keysets/ru.json +11 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +4 -0
- package/build/libs/chartkit-error/__tests__/chartkit-error.d.ts +1 -0
- package/build/libs/chartkit-error/__tests__/chartkit-error.js +27 -0
- package/build/libs/chartkit-error/chartkit-error.d.ts +16 -0
- package/build/libs/chartkit-error/chartkit-error.js +19 -0
- package/build/libs/index.d.ts +3 -0
- package/build/libs/index.js +2 -0
- package/build/libs/settings/__tests__/settings.test.d.ts +1 -0
- package/build/libs/settings/__tests__/settings.test.js +7 -0
- package/build/libs/settings/settings.d.ts +16 -0
- package/build/libs/settings/settings.js +43 -0
- package/build/plugins/index.d.ts +4 -0
- package/build/plugins/index.js +2 -0
- package/build/plugins/indicator/__stories__/Indicator.stories.d.ts +4 -0
- package/build/plugins/indicator/__stories__/Indicator.stories.js +45 -0
- package/build/plugins/indicator/index.d.ts +2 -0
- package/build/plugins/indicator/index.js +5 -0
- package/build/plugins/indicator/renderer/IndicatorItem.d.ts +6 -0
- package/build/plugins/indicator/renderer/IndicatorItem.js +15 -0
- package/build/plugins/indicator/renderer/IndicatorWidget.css +62 -0
- package/build/plugins/indicator/renderer/IndicatorWidget.d.ts +6 -0
- package/build/plugins/indicator/renderer/IndicatorWidget.js +28 -0
- package/build/plugins/indicator/types.d.ts +21 -0
- package/build/plugins/indicator/types.js +1 -0
- package/build/plugins/yagr/__stories__/Yagr.stories.d.ts +4 -0
- package/build/plugins/yagr/__stories__/Yagr.stories.js +21 -0
- package/build/plugins/yagr/__stories__/mocks/line10.d.ts +2 -0
- package/build/plugins/yagr/__stories__/mocks/line10.js +66 -0
- package/build/plugins/yagr/index.d.ts +2 -0
- package/build/plugins/yagr/index.js +5 -0
- package/build/plugins/yagr/renderer/YagrWidget.css +4 -0
- package/build/plugins/yagr/renderer/YagrWidget.d.ts +7 -0
- package/build/plugins/yagr/renderer/YagrWidget.js +196 -0
- package/build/plugins/yagr/renderer/polyfills.d.ts +1 -0
- package/build/plugins/yagr/renderer/polyfills.js +17 -0
- package/build/plugins/yagr/renderer/synchronizeTooltipTablesCellsWidth.d.ts +1 -0
- package/build/plugins/yagr/renderer/synchronizeTooltipTablesCellsWidth.js +43 -0
- package/build/plugins/yagr/renderer/tooltip/helpers/escapeHTML.d.ts +1 -0
- package/build/plugins/yagr/renderer/tooltip/helpers/escapeHTML.js +5 -0
- package/build/plugins/yagr/renderer/tooltip/tooltip.css +368 -0
- package/build/plugins/yagr/renderer/tooltip/tooltip.d.ts +141 -0
- package/build/plugins/yagr/renderer/tooltip/tooltip.js +229 -0
- package/build/plugins/yagr/types.d.ts +21 -0
- package/build/plugins/yagr/types.js +1 -0
- package/build/types/index.d.ts +33 -0
- package/build/types/index.js +1 -0
- package/build/types/widget.d.ts +13 -0
- package/build/types/widget.js +1 -0
- package/build/utils/__tests__/common.test.d.ts +1 -0
- package/build/utils/__tests__/common.test.js +9 -0
- package/build/utils/common.d.ts +1 -0
- package/build/utils/common.js +8 -0
- package/build/utils/index.d.ts +2 -0
- package/build/utils/index.js +2 -0
- package/build/utils/react.d.ts +1 -0
- package/build/utils/react.js +4 -0
- package/package.json +93 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.7.2](https://github.com/gravity-ui/chartkit/compare/v0.7.1...v0.7.2) (2022-10-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* package.json fixes ([#50](https://github.com/gravity-ui/chartkit/issues/50)) ([aca306d](https://github.com/gravity-ui/chartkit/commit/aca306dc8872951a48c1db0362ae1912138d72ed))
|
|
9
|
+
|
|
10
|
+
## [0.7.1](https://github.com/gravity-ui/chartkit/compare/v0.7.0...v0.7.1) (2022-10-03)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* move to gravity-ui configs ([#48](https://github.com/gravity-ui/chartkit/issues/48)) ([620587b](https://github.com/gravity-ui/chartkit/commit/620587b41febade698f12e67506aab683934e7b3))
|
|
16
|
+
|
|
17
|
+
## [0.7.0](https://github.com/yandex-cloud/chartkit/compare/v0.6.0...v0.7.0) (2022-10-01)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* use gravity-ui/uikit instead of yandex-cloud/uikit ([#46](https://github.com/yandex-cloud/chartkit/issues/46)) ([afb2300](https://github.com/yandex-cloud/chartkit/commit/afb230036bb26573159e5f03e0972653b6692d86))
|
|
23
|
+
|
|
24
|
+
## [0.6.0](https://github.com/yandex-cloud/chartkit/compare/v0.5.4...v0.6.0) (2022-08-12)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* remove uikit css variables proxing ([#43](https://github.com/yandex-cloud/chartkit/issues/43)) ([4d5131e](https://github.com/yandex-cloud/chartkit/commit/4d5131e0d77270e44bef94f0ba05c9fc5c317704))
|
|
30
|
+
|
|
31
|
+
## [0.5.4](https://github.com/yandex-cloud/chartkit/compare/v0.5.3...v0.5.4) (2022-08-08)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
* add Yagr type export ([#42](https://github.com/yandex-cloud/chartkit/issues/42)) ([a8b9475](https://github.com/yandex-cloud/chartkit/commit/a8b94755bbb0d42652db3e4266e0ca04481ad99f))
|
|
37
|
+
* npm vulnerabilities fixes ([#40](https://github.com/yandex-cloud/chartkit/issues/40)) ([1509bcf](https://github.com/yandex-cloud/chartkit/commit/1509bcf87a50d9281c3ea47074c694db429ad5d4))
|
|
38
|
+
|
|
39
|
+
## [0.5.3](https://github.com/yandex-cloud/chartkit/compare/v0.5.2...v0.5.3) (2022-08-01)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* dev and peer dependencies fixes ([#36](https://github.com/yandex-cloud/chartkit/issues/36)) ([faeccd9](https://github.com/yandex-cloud/chartkit/commit/faeccd9aca9b84ee02edeadef3db2d2abeedb143))
|
|
45
|
+
|
|
46
|
+
## [0.5.2](https://github.com/yandex-cloud/chartkit/compare/v0.5.1...v0.5.2) (2022-07-28)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Bug Fixes
|
|
50
|
+
|
|
51
|
+
* Indicator onLoad invocation fixes ([#34](https://github.com/yandex-cloud/chartkit/issues/34)) ([95fafc3](https://github.com/yandex-cloud/chartkit/commit/95fafc381bbafe47173f802310a67e7ced243d80))
|
|
52
|
+
|
|
53
|
+
## [0.5.1](https://github.com/yandex-cloud/chartkit/compare/v0.5.0...v0.5.1) (2022-07-27)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Bug Fixes
|
|
57
|
+
|
|
58
|
+
* error handling fixes ([#31](https://github.com/yandex-cloud/chartkit/issues/31)) ([e20fb9d](https://github.com/yandex-cloud/chartkit/commit/e20fb9df1d811efa08a8a68110b1a6819a384af4))
|
|
59
|
+
|
|
60
|
+
## [0.5.0](https://github.com/yandex-cloud/chartkit/compare/v0.4.0...v0.5.0) (2022-07-25)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Features
|
|
64
|
+
|
|
65
|
+
* add chartkit-error ([#28](https://github.com/yandex-cloud/chartkit/issues/28)) ([8342073](https://github.com/yandex-cloud/chartkit/commit/83420738dd431fa1ce2b96f18631f84ca36ed4af))
|
|
66
|
+
* add indicator chart ([#30](https://github.com/yandex-cloud/chartkit/issues/30)) ([4f465de](https://github.com/yandex-cloud/chartkit/commit/4f465de3afdee721f96868d975f3aee647177f76))
|
|
67
|
+
* change error handling ([#29](https://github.com/yandex-cloud/chartkit/issues/29)) ([993958a](https://github.com/yandex-cloud/chartkit/commit/993958a68e1c4376e037bd006d6b19f013b58cfb))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### Bug Fixes
|
|
71
|
+
|
|
72
|
+
* remove react-dom from peer dependencies ([#26](https://github.com/yandex-cloud/chartkit/issues/26)) ([22b6525](https://github.com/yandex-cloud/chartkit/commit/22b6525c767104e56cc51cf5dee5340253f7c080))
|
|
73
|
+
|
|
74
|
+
## [0.4.0](https://github.com/yandex-cloud/chartkit/compare/v0.3.1...v0.4.0) (2022-07-18)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### Features
|
|
78
|
+
|
|
79
|
+
* add onError property ([#24](https://github.com/yandex-cloud/chartkit/issues/24)) ([0b51f19](https://github.com/yandex-cloud/chartkit/commit/0b51f195612cb80ab8e40b5d115eb7650f986888))
|
|
80
|
+
|
|
81
|
+
## [0.3.1](https://github.com/yandex-cloud/chartkit/compare/v0.3.0...v0.3.1) (2022-07-14)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
### Bug Fixes
|
|
85
|
+
|
|
86
|
+
* add test for settings ([#21](https://github.com/yandex-cloud/chartkit/issues/21)) ([b848503](https://github.com/yandex-cloud/chartkit/commit/b8485032d9ab14edda0a8f193f9174e3a6c687bf))
|
|
87
|
+
* build task fixes ([#23](https://github.com/yandex-cloud/chartkit/issues/23)) ([2f13233](https://github.com/yandex-cloud/chartkit/commit/2f13233005d8fe7d10d496464ec3aed0a9ea5743))
|
|
88
|
+
|
|
89
|
+
## [0.3.0](https://github.com/yandex-cloud/chartkit/compare/v0.2.0...v0.3.0) (2022-07-13)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Features
|
|
93
|
+
|
|
94
|
+
* add root types export ([#18](https://github.com/yandex-cloud/chartkit/issues/18)) ([06265a1](https://github.com/yandex-cloud/chartkit/commit/06265a10f518836ac63f2b847e73dd19b3e2e8ca))
|
|
95
|
+
|
|
96
|
+
## [0.2.0](https://github.com/yandex-cloud/chartkit/compare/v0.1.1...v0.2.0) (2022-07-11)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### Features
|
|
100
|
+
|
|
101
|
+
* add cn lib ([#10](https://github.com/yandex-cloud/chartkit/issues/10)) ([796bdda](https://github.com/yandex-cloud/chartkit/commit/796bdda22fbf69ea8fc37965486e358ea3779a7e))
|
|
102
|
+
* add i18n ([#13](https://github.com/yandex-cloud/chartkit/issues/13)) ([3f0204b](https://github.com/yandex-cloud/chartkit/commit/3f0204bb949aeb596632b3479d7e5ee130d91225))
|
|
103
|
+
* add reflow handler ([#15](https://github.com/yandex-cloud/chartkit/issues/15)) ([80210af](https://github.com/yandex-cloud/chartkit/commit/80210af775ca7476f107f6ecc2ae9983baa9a8e3))
|
|
104
|
+
* add yagr plugin types export ([#17](https://github.com/yandex-cloud/chartkit/issues/17)) ([6e4cf1d](https://github.com/yandex-cloud/chartkit/commit/6e4cf1dc5cc584a9bda99b39122f489ed35f90e2))
|
|
105
|
+
* change lib structure ([#7](https://github.com/yandex-cloud/chartkit/issues/7)) ([dfb6ed8](https://github.com/yandex-cloud/chartkit/commit/dfb6ed839fd49a13006e75bca77abfd43849653b))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
### Bug Fixes
|
|
109
|
+
|
|
110
|
+
* change cn workflow ([#12](https://github.com/yandex-cloud/chartkit/issues/12)) ([aba5148](https://github.com/yandex-cloud/chartkit/commit/aba5148237aa0dd0bfd89744c77e30ebbcbcb90e))
|
|
111
|
+
* downgrade i18n to v0.5.0 ([#16](https://github.com/yandex-cloud/chartkit/issues/16)) ([454985a](https://github.com/yandex-cloud/chartkit/commit/454985a6c339775ebc0a96d77a20792b31b305c7))
|
|
112
|
+
* move all storybook decorators into one ([#14](https://github.com/yandex-cloud/chartkit/issues/14)) ([de1e8e9](https://github.com/yandex-cloud/chartkit/commit/de1e8e90325142e41ece8edc785119440b49fa0c))
|
|
113
|
+
|
|
114
|
+
### [0.1.1](https://www.github.com/yandex-cloud/ChartKit/compare/v0.1.0...v0.1.1) (2022-02-17)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
### Bug Fixes
|
|
118
|
+
|
|
119
|
+
* add publishConfig ([5cfdfff](https://www.github.com/yandex-cloud/ChartKit/commit/5cfdfffbdcafb8baeb05338ef07dd3a602c51797))
|
|
120
|
+
|
|
121
|
+
## 0.1.0 (2022-02-17)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### Bug Fixes
|
|
125
|
+
|
|
126
|
+
* init ([2804dac](https://www.github.com/yandex-cloud/ChartKit/commit/2804dacfd0f11e15cda6a84ca22172bf2d74b532))
|
|
127
|
+
* init ([4b747d4](https://www.github.com/yandex-cloud/ChartKit/commit/4b747d409122fc4ae330040e75e273ee9a602bcf))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 YANDEX LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @gravity-ui/chartkit · [](LICENSE) [](https://www.npmjs.com/package/@gravity-ui/chartkit)
|
|
2
|
+
|
|
3
|
+
React component used to render charts based on any sources you need
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npm i --save-dev @gravity-ui/chartkit @gravity-ui/uikit @gravity-ui/i18n
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import {ThemeProvider} from '@gravity-ui/uikit';
|
|
15
|
+
import ChartKit, {settings} from '@gravity-ui/chartkit';
|
|
16
|
+
import {YagrPlugin, YagrWidgetData} from '@gravity-ui/chartkit/build/plugins';
|
|
17
|
+
|
|
18
|
+
settings.set({plugins: [YagrPlugin]});
|
|
19
|
+
|
|
20
|
+
const data: YagrWidgetData = {
|
|
21
|
+
data: {
|
|
22
|
+
timeline: [
|
|
23
|
+
1636838612441, 1636925012441, 1637011412441, 1637097812441, 1637184212441, 1637270612441,
|
|
24
|
+
1637357012441, 1637443412441, 1637529812441, 1637616212441,
|
|
25
|
+
],
|
|
26
|
+
graphs: [
|
|
27
|
+
{
|
|
28
|
+
id: '0',
|
|
29
|
+
name: 'Serie 1',
|
|
30
|
+
color: '#6c59c2',
|
|
31
|
+
visible: true,
|
|
32
|
+
data: [25, 52, 89, 72, 39, 49, 82, 59, 36, 5],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: '1',
|
|
36
|
+
name: 'Serie 2',
|
|
37
|
+
color: '#6e8188',
|
|
38
|
+
visible: true,
|
|
39
|
+
data: [37, 6, 51, 10, 65, 35, 72, 0, 94, 54],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
libraryConfig: {
|
|
44
|
+
chart: {
|
|
45
|
+
type: 'line',
|
|
46
|
+
},
|
|
47
|
+
title: {
|
|
48
|
+
text: 'line: random 10 pts',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function App() {
|
|
54
|
+
return (
|
|
55
|
+
<ThemeProvider>
|
|
56
|
+
<div className="app" style={{height: 500}}>
|
|
57
|
+
<ChartKit type="yagr" data={data} />
|
|
58
|
+
</div>
|
|
59
|
+
</ThemeProvider>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default App;
|
|
64
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartkitType, ChartKitRef, ChartKitProps } from '../types';
|
|
3
|
+
import '@gravity-ui/uikit/styles/styles.css';
|
|
4
|
+
import './ChartKit.css';
|
|
5
|
+
declare type ChartKitComponentProps<T extends ChartkitType> = Omit<ChartKitProps<T>, 'onError'> & {
|
|
6
|
+
instanceRef?: React.ForwardedRef<ChartKitRef | undefined>;
|
|
7
|
+
};
|
|
8
|
+
declare const ChartKitComponent: <T extends keyof import("../types").ChartkitWidget>(props: ChartKitComponentProps<T>) => JSX.Element;
|
|
9
|
+
export declare const ChartKit: <T extends keyof import("../types").ChartkitWidget>(props: {
|
|
10
|
+
type: T;
|
|
11
|
+
data: import("../types").ChartkitWidget[T]["data"];
|
|
12
|
+
id?: string | undefined;
|
|
13
|
+
onLoad?: ((data?: import("../types").ChartKitOnLoadData<T> | undefined) => void) | undefined;
|
|
14
|
+
onError?: import("../types").ChartKitOnError | undefined;
|
|
15
|
+
formatNumber?: import("../types").ChartKitFormatNumber | undefined;
|
|
16
|
+
} & { [key in keyof Omit<import("../types").ChartkitWidget[T], "widget" | "data">]: import("../types").ChartkitWidget[T][key]; } & {
|
|
17
|
+
ref?: React.ForwardedRef<ChartKitRef | undefined> | undefined;
|
|
18
|
+
}) => ReturnType<typeof ChartKitComponent>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import block from 'bem-cn-lite';
|
|
4
|
+
import { i18n } from '../i18n';
|
|
5
|
+
import { CHARTKIT_ERROR_CODE, ChartKitError, settings } from '../libs';
|
|
6
|
+
import { getRandomCKId, typedMemo } from '../utils';
|
|
7
|
+
import { ErrorBoundary } from './ErrorBoundary/ErrorBoundary';
|
|
8
|
+
import { Loader } from './Loader/Loader';
|
|
9
|
+
import '@gravity-ui/uikit/styles/styles.css';
|
|
10
|
+
import './ChartKit.css';
|
|
11
|
+
const b = block('chartkit');
|
|
12
|
+
const ChartKitComponent = (props) => {
|
|
13
|
+
const widgetRef = React.useRef();
|
|
14
|
+
const { instanceRef, id = getRandomCKId(), type, data, onLoad } = props, restProps = __rest(props, ["instanceRef", "id", "type", "data", "onLoad"]);
|
|
15
|
+
const lang = settings.get('lang');
|
|
16
|
+
const plugins = settings.get('plugins');
|
|
17
|
+
const plugin = plugins.find((iteratedPlugin) => iteratedPlugin.type === type);
|
|
18
|
+
if (!plugin) {
|
|
19
|
+
throw new ChartKitError({
|
|
20
|
+
code: CHARTKIT_ERROR_CODE.UNKNOWN_PLUGIN,
|
|
21
|
+
message: i18n('error', 'label_unknown-plugin', { type }),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const ChartComponent = plugin.renderer;
|
|
25
|
+
React.useImperativeHandle(instanceRef, () => ({
|
|
26
|
+
reflow(details) {
|
|
27
|
+
var _a;
|
|
28
|
+
if ((_a = widgetRef.current) === null || _a === void 0 ? void 0 : _a.reflow) {
|
|
29
|
+
widgetRef.current.reflow(details);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
}), []);
|
|
33
|
+
return (React.createElement(React.Suspense, { fallback: React.createElement(Loader, null) },
|
|
34
|
+
React.createElement("div", { className: b() },
|
|
35
|
+
React.createElement(ChartComponent, Object.assign({ ref: widgetRef, id: id, lang: lang, data: data, onLoad: onLoad }, restProps)))));
|
|
36
|
+
};
|
|
37
|
+
const ChartKitComponentWithErrorBoundary = React.forwardRef((props, ref) => {
|
|
38
|
+
const { onError } = props, componentProps = __rest(props, ["onError"]);
|
|
39
|
+
return (React.createElement(ErrorBoundary, { onError: onError },
|
|
40
|
+
React.createElement(ChartKitComponent, Object.assign({ instanceRef: ref }, componentProps))));
|
|
41
|
+
}) /* https://stackoverflow.com/a/58473012 */;
|
|
42
|
+
export const ChartKit = typedMemo(ChartKitComponentWithErrorBoundary);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChartKitError } from '../../libs';
|
|
3
|
+
import type { ChartKitOnError } from '../../types';
|
|
4
|
+
declare type Props = {
|
|
5
|
+
onError?: ChartKitOnError;
|
|
6
|
+
};
|
|
7
|
+
declare type State = {
|
|
8
|
+
error?: ChartKitError | Error;
|
|
9
|
+
};
|
|
10
|
+
export declare class ErrorBoundary extends React.Component<Props, State> {
|
|
11
|
+
static getDerivedStateFromError(error: Error): {
|
|
12
|
+
error: Error;
|
|
13
|
+
};
|
|
14
|
+
state: State;
|
|
15
|
+
componentDidCatch(): void;
|
|
16
|
+
render(): React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ErrorView } from '../ErrorView/ErrorView';
|
|
3
|
+
export class ErrorBoundary extends React.Component {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(...arguments);
|
|
6
|
+
this.state = {
|
|
7
|
+
error: undefined,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
static getDerivedStateFromError(error) {
|
|
11
|
+
return { error };
|
|
12
|
+
}
|
|
13
|
+
componentDidCatch() {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const { error } = this.state;
|
|
16
|
+
if (error) {
|
|
17
|
+
(_b = (_a = this.props).onError) === null || _b === void 0 ? void 0 : _b.call(_a, { error });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
render() {
|
|
21
|
+
const { error } = this.state;
|
|
22
|
+
if (error) {
|
|
23
|
+
return React.createElement(ErrorView, { error: error });
|
|
24
|
+
}
|
|
25
|
+
return this.props.children;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import block from 'bem-cn-lite';
|
|
3
|
+
import { Loader as BaseLoader } from '@gravity-ui/uikit';
|
|
4
|
+
import './Loader.css';
|
|
5
|
+
const b = block('chartkit-loader');
|
|
6
|
+
export const Loader = (props) => {
|
|
7
|
+
return (React.createElement("div", { className: b() },
|
|
8
|
+
React.createElement(BaseLoader, Object.assign({}, props))));
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CHARTKIT_SCROLLABLE_NODE_CLASSNAME = "chartkit-scrollable-node";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CHARTKIT_SCROLLABLE_NODE_CLASSNAME } from './common';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CHARTKIT_SCROLLABLE_NODE_CLASSNAME } from './common';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { I18N, I18NFn } from '@yandex-cloud/i18n';
|
|
2
|
+
import en from './keysets/en.json';
|
|
3
|
+
declare type Keysets = typeof en;
|
|
4
|
+
declare type TypedI18n = I18NFn<Keysets>;
|
|
5
|
+
declare const i18nFactory: I18N;
|
|
6
|
+
declare const i18n: TypedI18n;
|
|
7
|
+
export { i18nFactory, i18n };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { I18N } from '@yandex-cloud/i18n';
|
|
2
|
+
import en from './keysets/en.json';
|
|
3
|
+
import ru from './keysets/ru.json';
|
|
4
|
+
const i18nFactory = new I18N();
|
|
5
|
+
const EN = 'en';
|
|
6
|
+
const RU = 'ru';
|
|
7
|
+
i18nFactory.registerKeysets(EN, en);
|
|
8
|
+
i18nFactory.registerKeysets(RU, ru);
|
|
9
|
+
const i18n = i18nFactory.i18n.bind(i18nFactory);
|
|
10
|
+
export { i18nFactory, i18n };
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ChartKit } from './components/ChartKit';
|
|
2
|
+
import { settings } from './libs';
|
|
3
|
+
export type { ChartKitLang, ChartKitOnLoadData, ChartKitPlugin, ChartKitProps, ChartKitRef, ChartKitWidgetRef, ChartkitType, ChartkitWidget, } from './types';
|
|
4
|
+
export { settings };
|
|
5
|
+
export default ChartKit;
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,16 @@
|
|
|
1
|
+
export declare type ChartKitErrorArgs = {
|
|
2
|
+
code?: number | string;
|
|
3
|
+
originalError?: Error;
|
|
4
|
+
message?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const CHARTKIT_ERROR_CODE: {
|
|
7
|
+
NO_DATA: string;
|
|
8
|
+
UNKNOWN: string;
|
|
9
|
+
UNKNOWN_PLUGIN: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class ChartKitError extends Error {
|
|
12
|
+
readonly code: number | string;
|
|
13
|
+
readonly isCustomError = true;
|
|
14
|
+
constructor({ originalError, message, code, }?: ChartKitErrorArgs);
|
|
15
|
+
}
|
|
16
|
+
export declare const isChartKitError: (error: unknown) => error is ChartKitError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const CHARTKIT_ERROR_CODE = {
|
|
2
|
+
NO_DATA: 'ERR.CK.NO_DATA',
|
|
3
|
+
UNKNOWN: 'ERR.CK.UNKNOWN_ERROR',
|
|
4
|
+
UNKNOWN_PLUGIN: 'ERR.CK.UNKNOWN_PLUGIN',
|
|
5
|
+
};
|
|
6
|
+
export class ChartKitError extends Error {
|
|
7
|
+
constructor({ originalError, message, code = CHARTKIT_ERROR_CODE.UNKNOWN, } = {}) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.isCustomError = true;
|
|
10
|
+
this.code = code;
|
|
11
|
+
if (originalError) {
|
|
12
|
+
this.name = originalError.name;
|
|
13
|
+
this.stack = originalError.stack;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const isChartKitError = (error) => {
|
|
18
|
+
return error instanceof Error && 'isCustomError' in error;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DEFAULT_LOCALE_SPECIFICATION, settings } from '../settings';
|
|
2
|
+
describe('libs/settings', () => {
|
|
3
|
+
it('Default locale should be equal DEFAULT_LOCALE_SPECIFICATION', () => {
|
|
4
|
+
const result = settings.get('locale');
|
|
5
|
+
expect(result).toBe(DEFAULT_LOCALE_SPECIFICATION);
|
|
6
|
+
});
|
|
7
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import type { ChartKitPlugin, ChartKitLang } from '../../types';
|
|
3
|
+
declare type Settings = {
|
|
4
|
+
plugins: ChartKitPlugin[];
|
|
5
|
+
lang: ChartKitLang;
|
|
6
|
+
locale?: moment.LocaleSpecification;
|
|
7
|
+
};
|
|
8
|
+
declare type SettingKey = keyof Settings;
|
|
9
|
+
export declare const DEFAULT_LOCALE_SPECIFICATION: moment.LocaleSpecification;
|
|
10
|
+
declare class ChartKitSettings {
|
|
11
|
+
private settings;
|
|
12
|
+
get<T extends SettingKey>(key: T): Settings[T];
|
|
13
|
+
set(updates: Partial<Settings>): void;
|
|
14
|
+
}
|
|
15
|
+
export declare const settings: ChartKitSettings;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import { configure } from '@gravity-ui/uikit';
|
|
3
|
+
import { i18nFactory } from '../../i18n';
|
|
4
|
+
export const DEFAULT_LOCALE_SPECIFICATION = { week: { dow: 1, doy: 7 } };
|
|
5
|
+
const removeUndefinedValues = (data) => {
|
|
6
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
|
7
|
+
if (typeof value !== 'undefined') {
|
|
8
|
+
acc[key] = value;
|
|
9
|
+
}
|
|
10
|
+
return acc;
|
|
11
|
+
}, {});
|
|
12
|
+
};
|
|
13
|
+
const updateLocale = (args) => {
|
|
14
|
+
const { lang, locale } = args;
|
|
15
|
+
if (locale) {
|
|
16
|
+
moment.updateLocale(lang, locale);
|
|
17
|
+
}
|
|
18
|
+
moment.locale(lang);
|
|
19
|
+
configure({ lang });
|
|
20
|
+
i18nFactory.setLang(lang);
|
|
21
|
+
};
|
|
22
|
+
class ChartKitSettings {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.settings = {
|
|
25
|
+
plugins: [],
|
|
26
|
+
lang: 'en',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
get(key) {
|
|
30
|
+
return this.settings[key];
|
|
31
|
+
}
|
|
32
|
+
set(updates) {
|
|
33
|
+
const filteredUpdates = removeUndefinedValues(updates);
|
|
34
|
+
if (filteredUpdates.lang || filteredUpdates.locale) {
|
|
35
|
+
const lang = filteredUpdates.lang || this.get('lang');
|
|
36
|
+
const locale = filteredUpdates.locale || this.get('locale');
|
|
37
|
+
updateLocale({ lang, locale });
|
|
38
|
+
}
|
|
39
|
+
this.settings = Object.assign(Object.assign({}, this.settings), filteredUpdates);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export const settings = new ChartKitSettings();
|
|
43
|
+
settings.set({ locale: DEFAULT_LOCALE_SPECIFICATION });
|