@gravity-ui/chartkit 1.6.2 → 1.6.4

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.6.4](https://github.com/gravity-ui/chartkit/compare/v1.6.3...v1.6.4) (2023-02-09)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **Highcharts plugin:** fix on legend item click when it has duplicate name ([#123](https://github.com/gravity-ui/chartkit/issues/123)) ([005b9d2](https://github.com/gravity-ui/chartkit/commit/005b9d20d0613f3e98d487c8c72c50ec713870ec))
9
+
10
+ ## [1.6.3](https://github.com/gravity-ui/chartkit/compare/v1.6.2...v1.6.3) (2023-02-08)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **Highcharts plugin:** fix updating point x value ([#121](https://github.com/gravity-ui/chartkit/issues/121)) ([0ffe89f](https://github.com/gravity-ui/chartkit/commit/0ffe89fb9f6112166765dd997cf549c6ca2665d9))
16
+
3
17
  ## [1.6.2](https://github.com/gravity-ui/chartkit/compare/v1.6.1...v1.6.2) (2023-01-24)
4
18
 
5
19
 
@@ -0,0 +1,4 @@
1
+ import { Story, Meta } from '@storybook/react';
2
+ declare const _default: Meta<import("@storybook/react").Args>;
3
+ export default _default;
4
+ export declare const ComboChart: Story<any>;
@@ -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,2 @@
1
+ import { HighchartsWidgetData } from '../../types';
2
+ export declare const data: HighchartsWidgetData;
@@ -0,0 +1,438 @@
1
+ export const data = {
2
+ data: {
3
+ graphs: [
4
+ {
5
+ title: 'Office Supplies',
6
+ tooltip: {
7
+ chartKitFormatting: true,
8
+ chartKitPrecision: 2,
9
+ },
10
+ data: [
11
+ {
12
+ y: 506.3000054359436,
13
+ dataLabels: {
14
+ enabled: false,
15
+ },
16
+ x: 1483228800000,
17
+ },
18
+ {
19
+ y: 453.8000063896179,
20
+ dataLabels: {
21
+ enabled: false,
22
+ },
23
+ x: 1483315200000,
24
+ },
25
+ {
26
+ y: 2070.3000507354736,
27
+ dataLabels: {
28
+ enabled: false,
29
+ },
30
+ x: 1483401600000,
31
+ },
32
+ {
33
+ y: 33.70000076293945,
34
+ dataLabels: {
35
+ enabled: false,
36
+ },
37
+ x: 1483660800000,
38
+ },
39
+ {
40
+ y: 335.6000015735626,
41
+ dataLabels: {
42
+ enabled: false,
43
+ },
44
+ x: 1483747200000,
45
+ },
46
+ {
47
+ y: 274.5,
48
+ dataLabels: {
49
+ enabled: false,
50
+ },
51
+ x: 1483920000000,
52
+ },
53
+ {
54
+ y: 810.899998664856,
55
+ dataLabels: {
56
+ enabled: false,
57
+ },
58
+ x: 1484179200000,
59
+ },
60
+ {
61
+ y: 4406.299995422363,
62
+ dataLabels: {
63
+ enabled: false,
64
+ },
65
+ x: 1484265600000,
66
+ },
67
+ {
68
+ y: 508.30000019073486,
69
+ dataLabels: {
70
+ enabled: false,
71
+ },
72
+ x: 1484352000000,
73
+ },
74
+ {
75
+ y: 2029.7999515533447,
76
+ dataLabels: {
77
+ enabled: false,
78
+ },
79
+ x: 1484438400000,
80
+ },
81
+ ],
82
+ legendTitle: 'Office Supplies',
83
+ drillDownFilterValue: 'Office Supplies',
84
+ colorGuid: 'ac8dd226-3372-4212-bde7-17afc792a728',
85
+ yAxis: 0,
86
+ colorValue: 'Office Supplies',
87
+ shapeValue: 'Sales',
88
+ color: '#4DA2F1',
89
+ dashStyle: 'Solid',
90
+ type: 'line',
91
+ },
92
+ {
93
+ title: 'Technology',
94
+ tooltip: {
95
+ chartKitFormatting: true,
96
+ chartKitPrecision: 2,
97
+ },
98
+ data: [
99
+ {
100
+ y: 712.300012588501,
101
+ dataLabels: {
102
+ enabled: false,
103
+ },
104
+ x: 1483315200000,
105
+ },
106
+ {
107
+ y: 3060,
108
+ dataLabels: {
109
+ enabled: false,
110
+ },
111
+ x: 1483747200000,
112
+ },
113
+ {
114
+ y: 528.7000126838684,
115
+ dataLabels: {
116
+ enabled: false,
117
+ },
118
+ x: 1484352000000,
119
+ },
120
+ {
121
+ y: 110.5999984741211,
122
+ dataLabels: {
123
+ enabled: false,
124
+ },
125
+ x: 1484438400000,
126
+ },
127
+ ],
128
+ legendTitle: 'Technology',
129
+ drillDownFilterValue: 'Technology',
130
+ colorGuid: 'ac8dd226-3372-4212-bde7-17afc792a728',
131
+ yAxis: 0,
132
+ colorValue: 'Technology',
133
+ shapeValue: 'Sales',
134
+ color: '#FF3D64',
135
+ dashStyle: 'Solid',
136
+ type: 'line',
137
+ },
138
+ {
139
+ title: 'Furniture',
140
+ tooltip: {
141
+ chartKitFormatting: true,
142
+ chartKitPrecision: 2,
143
+ },
144
+ data: [
145
+ {
146
+ y: 975.4000015258789,
147
+ dataLabels: {
148
+ enabled: false,
149
+ },
150
+ x: 1483228800000,
151
+ },
152
+ {
153
+ y: 913.4000244140625,
154
+ dataLabels: {
155
+ enabled: false,
156
+ },
157
+ x: 1483315200000,
158
+ },
159
+ {
160
+ y: 893,
161
+ dataLabels: {
162
+ enabled: false,
163
+ },
164
+ x: 1483833600000,
165
+ },
166
+ {
167
+ y: 37.70000076293945,
168
+ dataLabels: {
169
+ enabled: false,
170
+ },
171
+ x: 1484179200000,
172
+ },
173
+ {
174
+ y: 212.89999389648438,
175
+ dataLabels: {
176
+ enabled: false,
177
+ },
178
+ x: 1484265600000,
179
+ },
180
+ {
181
+ y: 19,
182
+ dataLabels: {
183
+ enabled: false,
184
+ },
185
+ x: 1484352000000,
186
+ },
187
+ ],
188
+ legendTitle: 'Furniture',
189
+ drillDownFilterValue: 'Furniture',
190
+ colorGuid: 'ac8dd226-3372-4212-bde7-17afc792a728',
191
+ yAxis: 0,
192
+ colorValue: 'Furniture',
193
+ shapeValue: 'Sales',
194
+ color: '#8AD554',
195
+ dashStyle: 'Solid',
196
+ type: 'line',
197
+ },
198
+ {
199
+ title: 'Furniture',
200
+ tooltip: {
201
+ chartKitFormatting: true,
202
+ chartKitPrecision: 0,
203
+ },
204
+ data: [
205
+ {
206
+ y: -8,
207
+ dataLabels: {
208
+ enabled: false,
209
+ },
210
+ x: 1483228800000,
211
+ },
212
+ {
213
+ y: -170,
214
+ dataLabels: {
215
+ enabled: false,
216
+ },
217
+ x: 1483315200000,
218
+ },
219
+ {
220
+ y: 80,
221
+ dataLabels: {
222
+ enabled: false,
223
+ },
224
+ x: 1483833600000,
225
+ },
226
+ {
227
+ y: 15,
228
+ dataLabels: {
229
+ enabled: false,
230
+ },
231
+ x: 1484179200000,
232
+ },
233
+ {
234
+ y: 53,
235
+ dataLabels: {
236
+ enabled: false,
237
+ },
238
+ x: 1484265600000,
239
+ },
240
+ {
241
+ y: 8,
242
+ dataLabels: {
243
+ enabled: false,
244
+ },
245
+ x: 1484352000000,
246
+ },
247
+ ],
248
+ legendTitle: 'Furniture',
249
+ drillDownFilterValue: 'Furniture',
250
+ colorGuid: 'ac8dd226-3372-4212-bde7-17afc792a728',
251
+ yAxis: 0,
252
+ colorValue: 'Furniture',
253
+ shapeValue: 'Profit',
254
+ color: '#4DA2F1',
255
+ type: 'column',
256
+ stack: 'c44bfc70-a7a5-11ed-96a0-9bb7dddec993__',
257
+ },
258
+ {
259
+ title: 'Office Supplies',
260
+ tooltip: {
261
+ chartKitFormatting: true,
262
+ chartKitPrecision: 0,
263
+ },
264
+ data: [
265
+ {
266
+ y: -177,
267
+ dataLabels: {
268
+ enabled: false,
269
+ },
270
+ x: 1483228800000,
271
+ },
272
+ {
273
+ y: -18,
274
+ dataLabels: {
275
+ enabled: false,
276
+ },
277
+ x: 1483315200000,
278
+ },
279
+ {
280
+ y: 703,
281
+ dataLabels: {
282
+ enabled: false,
283
+ },
284
+ x: 1483401600000,
285
+ },
286
+ {
287
+ y: 15,
288
+ dataLabels: {
289
+ enabled: false,
290
+ },
291
+ x: 1483660800000,
292
+ },
293
+ {
294
+ y: 76,
295
+ dataLabels: {
296
+ enabled: false,
297
+ },
298
+ x: 1483747200000,
299
+ },
300
+ {
301
+ y: -229,
302
+ dataLabels: {
303
+ enabled: false,
304
+ },
305
+ x: 1483920000000,
306
+ },
307
+ {
308
+ y: -1119,
309
+ dataLabels: {
310
+ enabled: false,
311
+ },
312
+ x: 1484179200000,
313
+ },
314
+ {
315
+ y: 152,
316
+ dataLabels: {
317
+ enabled: false,
318
+ },
319
+ x: 1484265600000,
320
+ },
321
+ {
322
+ y: 128,
323
+ dataLabels: {
324
+ enabled: false,
325
+ },
326
+ x: 1484352000000,
327
+ },
328
+ {
329
+ y: 266,
330
+ dataLabels: {
331
+ enabled: false,
332
+ },
333
+ x: 1484438400000,
334
+ },
335
+ ],
336
+ legendTitle: 'Office Supplies',
337
+ drillDownFilterValue: 'Office Supplies',
338
+ colorGuid: 'ac8dd226-3372-4212-bde7-17afc792a728',
339
+ yAxis: 0,
340
+ colorValue: 'Office Supplies',
341
+ shapeValue: 'Profit',
342
+ color: '#FF3D64',
343
+ type: 'column',
344
+ stack: 'c44bfc70-a7a5-11ed-96a0-9bb7dddec993__',
345
+ },
346
+ {
347
+ title: 'Technology',
348
+ tooltip: {
349
+ chartKitFormatting: true,
350
+ chartKitPrecision: 0,
351
+ },
352
+ data: [
353
+ {
354
+ y: -23,
355
+ dataLabels: {
356
+ enabled: false,
357
+ },
358
+ x: 1483315200000,
359
+ },
360
+ {
361
+ y: 680,
362
+ dataLabels: {
363
+ enabled: false,
364
+ },
365
+ x: 1483747200000,
366
+ },
367
+ {
368
+ y: 65,
369
+ dataLabels: {
370
+ enabled: false,
371
+ },
372
+ x: 1484352000000,
373
+ },
374
+ {
375
+ y: 27,
376
+ dataLabels: {
377
+ enabled: false,
378
+ },
379
+ x: 1484438400000,
380
+ },
381
+ ],
382
+ legendTitle: 'Technology',
383
+ drillDownFilterValue: 'Technology',
384
+ colorGuid: 'ac8dd226-3372-4212-bde7-17afc792a728',
385
+ yAxis: 0,
386
+ colorValue: 'Technology',
387
+ shapeValue: 'Profit',
388
+ color: '#8AD554',
389
+ type: 'column',
390
+ stack: 'c44bfc70-a7a5-11ed-96a0-9bb7dddec993__',
391
+ },
392
+ ],
393
+ },
394
+ config: {
395
+ withoutLineLimit: true,
396
+ hideHolidaysBands: true,
397
+ enableSum: true,
398
+ precision: 2,
399
+ hideHolidays: false,
400
+ normalizeDiv: false,
401
+ normalizeSub: false,
402
+ },
403
+ libraryConfig: {
404
+ chart: {
405
+ type: '',
406
+ zoomType: 'xy',
407
+ },
408
+ legend: {
409
+ symbolWidth: 38,
410
+ },
411
+ xAxis: {
412
+ endOnTick: false,
413
+ },
414
+ yAxis: {
415
+ opposite: false,
416
+ labels: {
417
+ y: 3,
418
+ },
419
+ type: 'linear',
420
+ },
421
+ tooltip: {},
422
+ plotOptions: {
423
+ series: {
424
+ dataGrouping: {
425
+ enabled: false,
426
+ },
427
+ dataLabels: {
428
+ allowOverlap: false,
429
+ },
430
+ },
431
+ },
432
+ axesFormatting: {
433
+ xAxis: [],
434
+ yAxis: [],
435
+ },
436
+ enableSum: true,
437
+ },
438
+ };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ChartCallbackFunction, Options, Chart } from 'highcharts';
2
+ import Highcharts, { ChartCallbackFunction, Options, Chart } from 'highcharts';
3
3
  import type { ChartKitProps } from '../../../../types';
4
4
  import type { HighchartsWidgetData, StringParams } from '../../types';
5
5
  import './HighchartsComponent.css';
@@ -360,7 +360,7 @@ export declare class HighchartsComponent extends React.PureComponent<Props, Stat
360
360
  };
361
361
  series: {
362
362
  events: {
363
- legendItemClick: (event: any) => void;
363
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
364
364
  mouseOver: () => void;
365
365
  mouseOut: () => void;
366
366
  click: (event: any) => void;
@@ -386,7 +386,7 @@ export declare class HighchartsComponent extends React.PureComponent<Props, Stat
386
386
  pie: {
387
387
  point: {
388
388
  events: {
389
- legendItemClick: (event: any) => void;
389
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
390
390
  };
391
391
  };
392
392
  };
@@ -518,7 +518,7 @@ export function prepareConfig(data: any, options: any, isMobile: any, holidays:
518
518
  };
519
519
  series: {
520
520
  events: {
521
- legendItemClick: (event: any) => void;
521
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
522
522
  mouseOver: () => void;
523
523
  mouseOut: () => void;
524
524
  click: (event: any) => void;
@@ -544,7 +544,7 @@ export function prepareConfig(data: any, options: any, isMobile: any, holidays:
544
544
  pie: {
545
545
  point: {
546
546
  events: {
547
- legendItemClick: (event: any) => void;
547
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
548
548
  };
549
549
  };
550
550
  };
@@ -580,3 +580,4 @@ export function prepareConfig(data: any, options: any, isMobile: any, holidays:
580
580
  export const chartTypesWithoutCrosshair: string[];
581
581
  export const chartTypesWithoutYCrosshair: string[];
582
582
  export const chartTypesWithNativeTooltip: string[];
583
+ import Highcharts from "highcharts";
@@ -1 +1,2 @@
1
- export function handleLegendItemClick(event: any): void;
1
+ import Highcharts from 'highcharts';
2
+ export declare const handleLegendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
@@ -1,29 +1,32 @@
1
1
  import { drawComments, hideComments } from '../comments/drawing';
2
2
  import { isNavigatorSeries } from './utils';
3
- const needSetVisible = (serieName, serieVisible, chartSeries) => {
4
- if (!serieVisible) {
3
+ const getUniqueSeriesName = (series) => {
4
+ return `${series.name}__${series.index}`;
5
+ };
6
+ const needSetVisible = (seriesName, seriesVisible, chartSeries) => {
7
+ if (!seriesVisible) {
5
8
  return false;
6
9
  }
7
10
  const hasAnotherVisibleSeries = chartSeries
8
- .filter((serie) => serie.options.showInLegend !== false && serie.name !== serieName)
9
- .some((serie) => serie.visible);
10
- return serieVisible && !hasAnotherVisibleSeries;
11
+ .filter((series) => series.options.showInLegend !== false && getUniqueSeriesName(series) !== seriesName)
12
+ .some((series) => series.visible);
13
+ return seriesVisible && !hasAnotherVisibleSeries;
11
14
  };
12
- const updateSeries = (serie, chart, chartSeries, type) => {
13
- const serieName = serie.name;
15
+ const updateSeries = (series, chartSeries, type) => {
16
+ const clickedSeriesName = getUniqueSeriesName(series);
14
17
  switch (type) {
15
18
  case 'extended': {
16
19
  chartSeries.forEach((item) => {
17
- if (item.name === serieName) {
20
+ if (getUniqueSeriesName(item) === clickedSeriesName) {
18
21
  item.setVisible(!item.visible, false);
19
22
  }
20
23
  });
21
24
  break;
22
25
  }
23
26
  case 'default': {
24
- const visible = needSetVisible(serie.name, serie.visible, chartSeries);
27
+ const visible = needSetVisible(getUniqueSeriesName(series), series.visible, chartSeries);
25
28
  chartSeries.forEach((item) => {
26
- if (item.name === serieName) {
29
+ if (getUniqueSeriesName(item) === clickedSeriesName) {
27
30
  item.setVisible(true, false);
28
31
  }
29
32
  else {
@@ -43,15 +46,17 @@ const updateComments = (chart) => {
43
46
  // https://api.highcharts.com/class-reference/Highcharts#.SeriesLegendItemClickCallbackFunction
44
47
  export const handleLegendItemClick = (event) => {
45
48
  event.preventDefault();
46
- const serie = event.target;
47
- const chart = serie.chart ? serie.chart : serie.series.chart;
48
- const chartSeries = serie.chart ? chart.series : serie.series.data;
49
- if (isNavigatorSeries(serie)) {
49
+ const series = event.target;
50
+ const chart = series.chart ? series.chart : series.series.chart;
51
+ const chartSeries = series.chart
52
+ ? chart.series
53
+ : series.series.data;
54
+ if (isNavigatorSeries(series)) {
50
55
  return;
51
56
  }
52
- const isExteded = event.browserEvent.ctrlKey || event.browserEvent.metaKey;
53
- const type = isExteded ? 'extended' : 'default';
54
- updateSeries(serie, chart, chartSeries, type);
57
+ const isExtended = event.browserEvent.ctrlKey || event.browserEvent.metaKey;
58
+ const type = isExtended ? 'extended' : 'default';
59
+ updateSeries(series, chartSeries, type);
55
60
  updateComments(chart);
56
61
  chart.redraw();
57
62
  };
@@ -1,5 +1,5 @@
1
1
  import type { ChartKitHolidays } from '../../../../types';
2
- import type { HighchartsWidgetData, HighchartsComment, ExtendedHChart } from '../../types';
2
+ import type { Highcharts, HighchartsWidgetData, HighchartsComment, ExtendedHChart } from '../../types';
3
3
  import type { ConfigOptions } from './types';
4
4
  import './graph.css';
5
5
  declare type GetGraphArgs = {
@@ -354,7 +354,7 @@ declare function getGraph({ options, data, comments, isMobile, holidays }: GetGr
354
354
  };
355
355
  series: {
356
356
  events: {
357
- legendItemClick: (event: any) => void;
357
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
358
358
  mouseOver: () => void;
359
359
  mouseOut: () => void;
360
360
  click: (event: any) => void;
@@ -380,7 +380,7 @@ declare function getGraph({ options, data, comments, isMobile, holidays }: GetGr
380
380
  pie: {
381
381
  point: {
382
382
  events: {
383
- legendItemClick: (event: any) => void;
383
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
384
384
  };
385
385
  };
386
386
  };
@@ -35,7 +35,10 @@ function getGraph({ options, data, comments, isMobile, holidays }) {
35
35
  data[index - 1].y == null) &&
36
36
  // eslint-disable-next-line eqeqeq, no-eq-null
37
37
  (index === data.length - 1 || data[index + 1].y == null)) {
38
- point.update({ marker: { enabled: true } }, false, false);
38
+ point.update({
39
+ marker: { enabled: true },
40
+ x: point.x,
41
+ }, false, false);
39
42
  needRedraw = true;
40
43
  }
41
44
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "React component used to render charts based on any sources you need",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:gravity-ui/ChartKit.git",