@gravity-ui/chartkit 1.5.2 → 1.6.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/CHANGELOG.md +15 -0
- package/README.md +1 -1
- package/build/components/ChartKit.d.ts +2 -0
- package/build/components/ChartKit.js +2 -2
- package/build/index.d.ts +1 -1
- package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.d.ts +4 -0
- package/build/plugins/highcharts/__stories__/complex/TwoAxis.stories.js +12 -0
- package/build/plugins/highcharts/__stories__/mocks/complex.d.ts +2 -0
- package/build/plugins/highcharts/__stories__/mocks/complex.js +323 -0
- package/build/plugins/highcharts/renderer/HighchartsWidget.d.ts +2 -0
- package/build/plugins/highcharts/renderer/components/HighchartsComponent.js +24 -1
- package/build/plugins/indicator/renderer/IndicatorWidget.d.ts +2 -0
- package/build/plugins/indicator/renderer/IndicatorWidget.js +1 -0
- package/build/plugins/yagr/renderer/YagrWidget.d.ts +2 -0
- package/build/plugins/yagr/renderer/YagrWidget.js +6 -1
- package/build/types/index.d.ts +21 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.6.1](https://github.com/gravity-ui/chartkit/compare/v1.6.0...v1.6.1) (2023-01-24)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* add export type for onChartLoad & onRender ([#117](https://github.com/gravity-ui/chartkit/issues/117)) ([e8b4f58](https://github.com/gravity-ui/chartkit/commit/e8b4f586335581df82f13b3f476afb0316e6e598))
|
|
9
|
+
* add types export ([e8b4f58](https://github.com/gravity-ui/chartkit/commit/e8b4f586335581df82f13b3f476afb0316e6e598))
|
|
10
|
+
|
|
11
|
+
## [1.6.0](https://github.com/gravity-ui/chartkit/compare/v1.5.2...v1.6.0) (2023-01-23)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* add onRender & onChartLoad calbacks ([#111](https://github.com/gravity-ui/chartkit/issues/111)) ([f23c008](https://github.com/gravity-ui/chartkit/commit/f23c008c5c049c813e6704edb1654c90707d00af))
|
|
17
|
+
|
|
3
18
|
## [1.5.2](https://github.com/gravity-ui/chartkit/compare/v1.5.1...v1.5.2) (2022-12-20)
|
|
4
19
|
|
|
5
20
|
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @gravity-ui/chartkit · [](LICENSE) [](https://www.npmjs.com/package/@gravity-ui/chartkit)
|
|
1
|
+
# @gravity-ui/chartkit · [](LICENSE) [](https://www.npmjs.com/package/@gravity-ui/chartkit) [](https://preview.gravity-ui.com/chartkit/)
|
|
2
2
|
|
|
3
3
|
React component used to render charts based on any sources you need
|
|
4
4
|
|
|
@@ -11,6 +11,8 @@ export declare const ChartKit: <T extends keyof import("../types").ChartKitWidge
|
|
|
11
11
|
id?: string | undefined;
|
|
12
12
|
isMobile?: boolean | undefined;
|
|
13
13
|
onLoad?: ((data?: import("../types").ChartKitOnLoadData<T> | undefined) => void) | undefined;
|
|
14
|
+
onRender?: ((data: import("../types").ChartKitOnRenderData) => void) | undefined;
|
|
15
|
+
onChartLoad?: ((data: import("../types").ChartKitOnChartLoad<T>) => void) | undefined;
|
|
14
16
|
onError?: import("../types").ChartKitOnError | undefined;
|
|
15
17
|
} & { [key in keyof Omit<import("../types").ChartKitWidget[T], "widget" | "data">]: import("../types").ChartKitWidget[T][key]; } & {
|
|
16
18
|
ref?: React.ForwardedRef<ChartKitRef | undefined> | undefined;
|
|
@@ -10,7 +10,7 @@ import './ChartKit.css';
|
|
|
10
10
|
const b = block('chartkit');
|
|
11
11
|
const ChartKitComponent = (props) => {
|
|
12
12
|
const widgetRef = React.useRef();
|
|
13
|
-
const { instanceRef, id: propsId, type,
|
|
13
|
+
const { instanceRef, id: propsId, type, isMobile } = props, restProps = __rest(props, ["instanceRef", "id", "type", "isMobile"]);
|
|
14
14
|
const ckId = React.useMemo(() => getRandomCKId(), []);
|
|
15
15
|
const id = propsId || ckId;
|
|
16
16
|
const lang = settings.get('lang');
|
|
@@ -33,7 +33,7 @@ const ChartKitComponent = (props) => {
|
|
|
33
33
|
}), []);
|
|
34
34
|
return (React.createElement(React.Suspense, { fallback: React.createElement(Loader, null) },
|
|
35
35
|
React.createElement("div", { className: b({ mobile: isMobile }, 'chartkit-theme_common') },
|
|
36
|
-
React.createElement(ChartComponent, Object.assign({ ref: widgetRef, id: id, lang: lang
|
|
36
|
+
React.createElement(ChartComponent, Object.assign({ ref: widgetRef, id: id, lang: lang }, restProps)))));
|
|
37
37
|
};
|
|
38
38
|
const ChartKitComponentWithErrorBoundary = React.forwardRef(function ChartKitComponentWithErrorBoundary(props, ref) {
|
|
39
39
|
return (React.createElement(ErrorBoundary, { onError: props.onError },
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChartKit } from './components/ChartKit';
|
|
2
2
|
import { settings } from './libs';
|
|
3
|
-
export type { ChartKitLang, ChartKitOnLoadData, ChartKitOnError, ChartKitPlugin, ChartKitProps, ChartKitRef, ChartKitWidgetRef, ChartKitType, ChartKitWidget, } from './types';
|
|
3
|
+
export type { ChartKitLang, ChartKitOnLoadData, ChartKitOnRenderData, ChartKitOnChartLoad, ChartKitOnError, ChartKitPlugin, ChartKitProps, ChartKitRef, ChartKitWidgetRef, ChartKitType, ChartKitWidget, } from './types';
|
|
4
4
|
export { settings };
|
|
5
5
|
export default ChartKit;
|
|
@@ -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,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the X coordinate of the intersection of the two lines 1-2 and 3-4.
|
|
3
|
+
* @param x1 {number} X-coordinate of the first point of the first line.
|
|
4
|
+
* @param y1 {number} Y-coordinate of the first point of the first line.
|
|
5
|
+
* @param x2 {number} X-coordinate of the second point of the first line.
|
|
6
|
+
* @param y2 {number} Y-coordinate of the second point of the first line.
|
|
7
|
+
* @param x3 {number} X-coordinate of the first point of the second line.
|
|
8
|
+
* @param y3 {number} Y-coordinate of the first point of the second line.
|
|
9
|
+
* @param x4 {number} X-coordinate of the second point of the second line.
|
|
10
|
+
* @param y4 {number} Y-coordinate of the second point of the second line.
|
|
11
|
+
* @returns {number} X-coordinate of the intersection.
|
|
12
|
+
*/
|
|
13
|
+
function getIntersectionX(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
14
|
+
return Math.trunc(((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) /
|
|
15
|
+
((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the colored zones for the area chart.
|
|
19
|
+
* @param counts {object} Area chart data.
|
|
20
|
+
* @param createdColor {string} Color (html notation) for the positive zone.
|
|
21
|
+
* @param resolvedColor {string} Color (html notation) for the negative zone.
|
|
22
|
+
* @returns {SeriesZonesOptionsObject[]} Highcharts zones for area chart.
|
|
23
|
+
*/
|
|
24
|
+
function getZones(counts, createdColor, resolvedColor) {
|
|
25
|
+
const zones = [];
|
|
26
|
+
let positive;
|
|
27
|
+
let color;
|
|
28
|
+
let prev;
|
|
29
|
+
for (const count of counts) {
|
|
30
|
+
const isPositive = count.created - count.resolved >= 0;
|
|
31
|
+
if (isPositive !== positive) {
|
|
32
|
+
if (color && prev) {
|
|
33
|
+
const value = getIntersectionX(prev.to, prev.created, count.to, count.created, prev.to, prev.resolved, count.to, count.resolved);
|
|
34
|
+
zones.push({ color, value });
|
|
35
|
+
}
|
|
36
|
+
positive = isPositive;
|
|
37
|
+
color = isPositive ? createdColor : resolvedColor;
|
|
38
|
+
}
|
|
39
|
+
prev = count;
|
|
40
|
+
}
|
|
41
|
+
if (color) {
|
|
42
|
+
zones.push({ color });
|
|
43
|
+
}
|
|
44
|
+
return zones;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get parameters for a rectangle between two charts. This rectangle
|
|
48
|
+
* is used to visually separate the areas of the two charts.
|
|
49
|
+
* @param chart {Chart} Highcharts chart object.
|
|
50
|
+
* @returns {object} Parameters for rectangle.
|
|
51
|
+
*/
|
|
52
|
+
function getDividerRect(chart) {
|
|
53
|
+
const gridLineWidth = 1;
|
|
54
|
+
const xAxis = chart.xAxis[0];
|
|
55
|
+
const yAxis0 = chart.yAxis[0];
|
|
56
|
+
const yAxis1 = chart.yAxis[1];
|
|
57
|
+
const x = xAxis.left;
|
|
58
|
+
const y = yAxis0.top + yAxis0.height + gridLineWidth;
|
|
59
|
+
const width = xAxis.width;
|
|
60
|
+
const height = yAxis1.top - yAxis0.top - yAxis0.height - gridLineWidth * 2;
|
|
61
|
+
return { x, y, width, height };
|
|
62
|
+
}
|
|
63
|
+
const rawData = [
|
|
64
|
+
{
|
|
65
|
+
from: '2020-04-01T00:00:00Z',
|
|
66
|
+
to: '2020-05-01T00:00:00Z',
|
|
67
|
+
created: 42,
|
|
68
|
+
resolved: 10,
|
|
69
|
+
trend: 32,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
from: '2020-05-01T00:00:00Z',
|
|
73
|
+
to: '2020-06-01T00:00:00Z',
|
|
74
|
+
created: 53,
|
|
75
|
+
resolved: 30,
|
|
76
|
+
trend: 55,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
from: '2020-06-01T00:00:00Z',
|
|
80
|
+
to: '2020-07-01T00:00:00Z',
|
|
81
|
+
created: 35,
|
|
82
|
+
resolved: 28,
|
|
83
|
+
trend: 62,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
from: '2020-07-01T00:00:00Z',
|
|
87
|
+
to: '2020-08-01T00:00:00Z',
|
|
88
|
+
created: 30,
|
|
89
|
+
resolved: 19,
|
|
90
|
+
trend: 73,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
from: '2020-08-01T00:00:00Z',
|
|
94
|
+
to: '2020-09-01T00:00:00Z',
|
|
95
|
+
created: 18,
|
|
96
|
+
resolved: 23,
|
|
97
|
+
trend: 68,
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
from: '2020-09-01T00:00:00Z',
|
|
101
|
+
to: '2020-10-01T00:00:00Z',
|
|
102
|
+
created: 29,
|
|
103
|
+
resolved: 22,
|
|
104
|
+
trend: 75,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
from: '2020-10-01T00:00:00Z',
|
|
108
|
+
to: '2020-11-01T00:00:00Z',
|
|
109
|
+
created: 24,
|
|
110
|
+
resolved: 26,
|
|
111
|
+
trend: 73,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
from: '2020-11-01T00:00:00Z',
|
|
115
|
+
to: '2020-12-01T00:00:00Z',
|
|
116
|
+
created: 19,
|
|
117
|
+
resolved: 21,
|
|
118
|
+
trend: 71,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
from: '2020-12-01T00:00:00Z',
|
|
122
|
+
to: '2021-01-01T00:00:00Z',
|
|
123
|
+
created: 22,
|
|
124
|
+
resolved: 22,
|
|
125
|
+
trend: 71,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
from: '2021-01-01T00:00:00Z',
|
|
129
|
+
to: '2021-02-01T00:00:00Z',
|
|
130
|
+
created: 17,
|
|
131
|
+
resolved: 17,
|
|
132
|
+
trend: 71,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
from: '2021-02-01T00:00:00Z',
|
|
136
|
+
to: '2021-03-01T00:00:00Z',
|
|
137
|
+
created: 30,
|
|
138
|
+
resolved: 26,
|
|
139
|
+
trend: 75,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
from: '2021-03-01T00:00:00Z',
|
|
143
|
+
to: '2021-04-01T00:00:00Z',
|
|
144
|
+
created: 28,
|
|
145
|
+
resolved: 12,
|
|
146
|
+
trend: 91,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
from: '2021-04-01T00:00:00Z',
|
|
150
|
+
to: '2021-05-01T00:00:00Z',
|
|
151
|
+
created: 11,
|
|
152
|
+
resolved: 15,
|
|
153
|
+
trend: 87,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
from: '2021-05-01T00:00:00Z',
|
|
157
|
+
to: '2021-06-01T00:00:00Z',
|
|
158
|
+
created: 9,
|
|
159
|
+
resolved: 4,
|
|
160
|
+
trend: 92,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
from: '2021-06-01T00:00:00Z',
|
|
164
|
+
to: '2021-07-01T00:00:00Z',
|
|
165
|
+
created: 12,
|
|
166
|
+
resolved: 12,
|
|
167
|
+
trend: 92,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
from: '2021-07-01T00:00:00Z',
|
|
171
|
+
to: '2021-08-01T00:00:00Z',
|
|
172
|
+
created: 13,
|
|
173
|
+
resolved: 17,
|
|
174
|
+
trend: 88,
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
from: '2021-08-01T00:00:00Z',
|
|
178
|
+
to: '2021-09-01T00:00:00Z',
|
|
179
|
+
created: 3,
|
|
180
|
+
resolved: 14,
|
|
181
|
+
trend: 77,
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
const counts = rawData.map(({ created, resolved, trend, from, to }) => ({
|
|
185
|
+
created,
|
|
186
|
+
resolved,
|
|
187
|
+
trend,
|
|
188
|
+
from: Date.parse(from),
|
|
189
|
+
to: Date.parse(to),
|
|
190
|
+
}));
|
|
191
|
+
const arearange = counts.map(({ created, resolved, to }) => [to, resolved, created]);
|
|
192
|
+
const createdLine = counts.map(({ created, to }) => [to, created]);
|
|
193
|
+
const resolvedLine = counts.map(({ resolved, to }) => [to, resolved]);
|
|
194
|
+
const trends = counts.map(({ trend, to }) => [to, trend]);
|
|
195
|
+
export const data = {
|
|
196
|
+
data: {
|
|
197
|
+
graphs: [
|
|
198
|
+
{
|
|
199
|
+
type: 'arearange',
|
|
200
|
+
data: arearange,
|
|
201
|
+
yAxis: 0,
|
|
202
|
+
opacity: 0.5,
|
|
203
|
+
zones: getZones(counts, '#FF3D64', '#8AD554'),
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
type: 'line',
|
|
207
|
+
name: 'Resolved',
|
|
208
|
+
color: '#8AD554',
|
|
209
|
+
data: resolvedLine,
|
|
210
|
+
yAxis: 0,
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
type: 'line',
|
|
214
|
+
name: 'Created',
|
|
215
|
+
color: '#FF3D64',
|
|
216
|
+
data: createdLine,
|
|
217
|
+
yAxis: 0,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
type: 'line',
|
|
221
|
+
name: 'Average',
|
|
222
|
+
color: '#4DA2F1',
|
|
223
|
+
data: trends,
|
|
224
|
+
yAxis: 1,
|
|
225
|
+
marker: {
|
|
226
|
+
enabled: false,
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
},
|
|
231
|
+
config: {
|
|
232
|
+
hideHolidays: false,
|
|
233
|
+
normalizeDiv: false,
|
|
234
|
+
normalizeSub: false,
|
|
235
|
+
hideHolidaysBands: true,
|
|
236
|
+
},
|
|
237
|
+
libraryConfig: {
|
|
238
|
+
chart: {
|
|
239
|
+
animation: false,
|
|
240
|
+
events: {
|
|
241
|
+
load: function (_event) {
|
|
242
|
+
const rect = getDividerRect(this);
|
|
243
|
+
this.renderer
|
|
244
|
+
.rect(rect.x, rect.y, rect.width, rect.height)
|
|
245
|
+
.addClass('highcharts-axis-grid-divider')
|
|
246
|
+
.attr({
|
|
247
|
+
fill: 'var(--yc-color-base-background)',
|
|
248
|
+
zIndex: 8,
|
|
249
|
+
})
|
|
250
|
+
.add();
|
|
251
|
+
},
|
|
252
|
+
redraw: function (_event) {
|
|
253
|
+
const rect = getDividerRect(this);
|
|
254
|
+
const element = this.container.querySelector('.highcharts-axis-grid-divider');
|
|
255
|
+
if (element) {
|
|
256
|
+
element.setAttribute('x', String(rect.x));
|
|
257
|
+
element.setAttribute('y', String(rect.y));
|
|
258
|
+
element.setAttribute('width', String(rect.width));
|
|
259
|
+
element.setAttribute('height', String(rect.height));
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
xAxis: {
|
|
265
|
+
type: 'datetime',
|
|
266
|
+
minPadding: 0.05,
|
|
267
|
+
maxPadding: 0.05,
|
|
268
|
+
},
|
|
269
|
+
yAxis: [
|
|
270
|
+
{
|
|
271
|
+
height: '70%',
|
|
272
|
+
labels: {
|
|
273
|
+
x: -14,
|
|
274
|
+
},
|
|
275
|
+
offset: 0,
|
|
276
|
+
lineWidth: 1,
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
height: '20%',
|
|
280
|
+
top: '80%',
|
|
281
|
+
labels: {
|
|
282
|
+
x: -14,
|
|
283
|
+
},
|
|
284
|
+
offset: 0,
|
|
285
|
+
lineWidth: 1,
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
plotOptions: {
|
|
289
|
+
series: {
|
|
290
|
+
states: {
|
|
291
|
+
inactive: {
|
|
292
|
+
opacity: 0.5,
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
arearange: {
|
|
297
|
+
showInLegend: false,
|
|
298
|
+
enableMouseTracking: false,
|
|
299
|
+
lineWidth: 0,
|
|
300
|
+
marker: {
|
|
301
|
+
enabled: false,
|
|
302
|
+
},
|
|
303
|
+
zoneAxis: 'x',
|
|
304
|
+
},
|
|
305
|
+
line: {
|
|
306
|
+
lineWidth: 1,
|
|
307
|
+
marker: {
|
|
308
|
+
enabled: true,
|
|
309
|
+
symbol: 'circle',
|
|
310
|
+
},
|
|
311
|
+
states: {
|
|
312
|
+
hover: {
|
|
313
|
+
lineWidth: 1,
|
|
314
|
+
lineWidthPlus: 0,
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
legend: {
|
|
320
|
+
enabled: false,
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
};
|
|
@@ -6,6 +6,8 @@ declare const HighchartsWidget: React.ForwardRefExoticComponent<{
|
|
|
6
6
|
id?: string | undefined;
|
|
7
7
|
isMobile?: boolean | undefined;
|
|
8
8
|
onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"highcharts"> | undefined) => void) | undefined;
|
|
9
|
+
onRender?: ((data: import("../../../types").ChartKitOnRenderData) => void) | undefined;
|
|
10
|
+
onChartLoad?: ((data: import("../../../types").ChartKitOnChartLoad<"highcharts">) => void) | undefined;
|
|
9
11
|
onError?: import("../../../types").ChartKitOnError | undefined;
|
|
10
12
|
} & {
|
|
11
13
|
hoistConfigError?: boolean | undefined;
|
|
@@ -81,9 +81,32 @@ export class HighchartsComponent extends React.PureComponent {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
componentDidMount() {
|
|
84
|
-
|
|
84
|
+
var _a, _b;
|
|
85
|
+
if (!this.props.onChartLoad) {
|
|
86
|
+
this.onLoad();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const needCallbacks = !this.state.isError && !this.props.splitTooltip;
|
|
90
|
+
if (!needCallbacks) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const widget = this.chartComponent.current ? this.chartComponent.current.chart : null;
|
|
94
|
+
if (this.state.callback && widget) {
|
|
95
|
+
this.state.callback(widget);
|
|
96
|
+
}
|
|
97
|
+
(_b = (_a = this.props).onChartLoad) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
98
|
+
widget,
|
|
99
|
+
});
|
|
85
100
|
}
|
|
86
101
|
componentDidUpdate() {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
const needRenderCallback = this.props.onRender && !this.state.isError && !this.props.splitTooltip;
|
|
104
|
+
if (needRenderCallback) {
|
|
105
|
+
(_b = (_a = this.props).onRender) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
106
|
+
renderTime: getChartPerformanceDuration(this.getId()),
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
87
110
|
this.onLoad();
|
|
88
111
|
}
|
|
89
112
|
render() {
|
|
@@ -7,6 +7,8 @@ declare const IndicatorWidget: React.ForwardRefExoticComponent<{
|
|
|
7
7
|
id?: string | undefined;
|
|
8
8
|
isMobile?: boolean | undefined;
|
|
9
9
|
onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"indicator"> | undefined) => void) | undefined;
|
|
10
|
+
onRender?: ((data: import("../../../types").ChartKitOnRenderData) => void) | undefined;
|
|
11
|
+
onChartLoad?: ((data: import("../../../types").ChartKitOnChartLoad<"indicator">) => void) | undefined;
|
|
10
12
|
onError?: import("../../../types").ChartKitOnError | undefined;
|
|
11
13
|
} & {
|
|
12
14
|
formatNumber?: (<T = any>(value: number, options?: T | undefined) => string) | undefined;
|
|
@@ -15,6 +15,7 @@ function IndicatorWidgetInner(props, _ref) {
|
|
|
15
15
|
React.useLayoutEffect(() => {
|
|
16
16
|
// TODO: swap to onRender after https://github.com/gravity-ui/chartkit/issues/33
|
|
17
17
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad();
|
|
18
|
+
// TODO: add onRender with renderTime Issue #114
|
|
18
19
|
});
|
|
19
20
|
if (isEmpty(data)) {
|
|
20
21
|
throw new ChartKitError({
|
|
@@ -9,6 +9,8 @@ declare const YagrWidget: React.ForwardRefExoticComponent<{
|
|
|
9
9
|
id?: string | undefined;
|
|
10
10
|
isMobile?: boolean | undefined;
|
|
11
11
|
onLoad?: ((data?: import("../../../types").ChartKitOnLoadData<"yagr"> | undefined) => void) | undefined;
|
|
12
|
+
onRender?: ((data: import("../../../types").ChartKitOnRenderData) => void) | undefined;
|
|
13
|
+
onChartLoad?: ((data: import("../../../types").ChartKitOnChartLoad<"yagr">) => void) | undefined;
|
|
12
14
|
onError?: import("../../../types").ChartKitOnError | undefined;
|
|
13
15
|
} & {} & {
|
|
14
16
|
id: string;
|
|
@@ -9,7 +9,7 @@ import './polyfills';
|
|
|
9
9
|
import '@gravity-ui/yagr/dist/index.css';
|
|
10
10
|
import './YagrWidget.css';
|
|
11
11
|
const YagrWidget = React.forwardRef((props, forwardedRef) => {
|
|
12
|
-
const { id, data: { data }, onLoad, } = props;
|
|
12
|
+
const { id, data: { data }, onLoad, onRender, onChartLoad, } = props;
|
|
13
13
|
const yagrRef = React.useRef(null);
|
|
14
14
|
if (!data || isEmpty(data)) {
|
|
15
15
|
throw new ChartKitError({
|
|
@@ -20,6 +20,7 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
|
|
|
20
20
|
const { config, debug } = useWidgetData(Object.assign(Object.assign({}, props.data), { id }));
|
|
21
21
|
const handleChartLoading = React.useCallback((chart, { renderTime }) => {
|
|
22
22
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad(Object.assign(Object.assign({}, data), { widget: chart, widgetRendering: renderTime }));
|
|
23
|
+
onRender === null || onRender === void 0 ? void 0 : onRender({ renderTime });
|
|
23
24
|
}, [onLoad, data]);
|
|
24
25
|
const onWindowResize = React.useCallback(() => {
|
|
25
26
|
var _a;
|
|
@@ -67,6 +68,10 @@ const YagrWidget = React.forwardRef((props, forwardedRef) => {
|
|
|
67
68
|
}
|
|
68
69
|
});
|
|
69
70
|
});
|
|
71
|
+
React.useLayoutEffect(() => {
|
|
72
|
+
var _a;
|
|
73
|
+
onChartLoad === null || onChartLoad === void 0 ? void 0 : onChartLoad({ widget: (_a = yagrRef.current) === null || _a === void 0 ? void 0 : _a.chart });
|
|
74
|
+
}, []);
|
|
70
75
|
return (React.createElement(YagrComponent, { ref: yagrRef, id: id, config: config, debug: debug, onChartLoad: handleChartLoading }));
|
|
71
76
|
});
|
|
72
77
|
export default YagrWidget;
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import type { ChartKitWidget } from './widget';
|
|
3
3
|
export type { ChartKitHolidays } from './misc';
|
|
4
4
|
export declare type ChartKitLang = 'ru' | 'en';
|
|
@@ -13,6 +13,12 @@ export declare type ChartKitOnLoadData<T extends ChartKitType> = {
|
|
|
13
13
|
widget?: ChartKitWidget[T]['widget'];
|
|
14
14
|
widgetRendering?: number;
|
|
15
15
|
};
|
|
16
|
+
export declare type ChartKitOnRenderData = {
|
|
17
|
+
renderTime?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare type ChartKitOnChartLoad<T extends ChartKitType> = {
|
|
20
|
+
widget?: ChartKitWidget[T]['widget'] | null;
|
|
21
|
+
};
|
|
16
22
|
export declare type ChartKitOnError = (data: {
|
|
17
23
|
error: any;
|
|
18
24
|
}) => void;
|
|
@@ -21,7 +27,21 @@ export declare type ChartKitProps<T extends ChartKitType> = {
|
|
|
21
27
|
data: ChartKitWidget[T]['data'];
|
|
22
28
|
id?: string;
|
|
23
29
|
isMobile?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @depricated please use onRender & onChartLoad instead
|
|
32
|
+
* @param data
|
|
33
|
+
*/
|
|
24
34
|
onLoad?: (data?: ChartKitOnLoadData<T>) => void;
|
|
35
|
+
/**
|
|
36
|
+
* called on each render
|
|
37
|
+
* @param data
|
|
38
|
+
*/
|
|
39
|
+
onRender?: (data: ChartKitOnRenderData) => void;
|
|
40
|
+
/**
|
|
41
|
+
* called on chart mount
|
|
42
|
+
* @param data
|
|
43
|
+
*/
|
|
44
|
+
onChartLoad?: (data: ChartKitOnChartLoad<T>) => void;
|
|
25
45
|
onError?: ChartKitOnError;
|
|
26
46
|
} & {
|
|
27
47
|
[key in keyof Omit<ChartKitWidget[T], 'data' | 'widget'>]: ChartKitWidget[T][key];
|
package/package.json
CHANGED