@gravity-ui/chartkit 2.2.1 → 2.2.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.2](https://github.com/gravity-ui/chartkit/compare/v2.2.1...v2.2.2) (2023-03-28)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **Highcharts plugin:** fix legend item click ([#142](https://github.com/gravity-ui/chartkit/issues/142)) ([a64f1b9](https://github.com/gravity-ui/chartkit/commit/a64f1b962bec45bfd2568110c1c9050fc9d75807))
9
+
3
10
  ## [2.2.1](https://github.com/gravity-ui/chartkit/compare/v2.2.0...v2.2.1) (2023-03-27)
4
11
 
5
12
 
@@ -360,7 +360,7 @@ export declare class HighchartsComponent extends React.PureComponent<Props, Stat
360
360
  };
361
361
  series: {
362
362
  events: {
363
- legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
363
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject | Highcharts.PointLegendItemClickEventObject) => 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: Highcharts.SeriesLegendItemClickEventObject) => void;
389
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject | Highcharts.PointLegendItemClickEventObject) => 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: Highcharts.SeriesLegendItemClickEventObject) => void;
521
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject | Highcharts.PointLegendItemClickEventObject) => 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: Highcharts.SeriesLegendItemClickEventObject) => void;
547
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject | Highcharts.PointLegendItemClickEventObject) => void;
548
548
  };
549
549
  };
550
550
  };
@@ -1,2 +1,2 @@
1
1
  import Highcharts from 'highcharts';
2
- export declare const handleLegendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
2
+ export declare const handleLegendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject | Highcharts.PointLegendItemClickEventObject) => void;
@@ -1,12 +1,18 @@
1
1
  import { drawComments, hideComments } from '../comments/drawing';
2
2
  import { isNavigatorSeries } from './utils';
3
- const getSeriesIdentifier = (series) => {
4
- return series.userOptions.id || series.name;
3
+ import Highcharts from 'highcharts';
4
+ const getSeriesIdentifier = (item) => {
5
+ if (item instanceof Highcharts.Point) {
6
+ return item.name;
7
+ }
8
+ return item.userOptions.id || item.name;
5
9
  };
6
10
  const needSetVisible = (seriesName, seriesVisible, chartSeries) => {
7
11
  if (!seriesVisible) {
8
12
  return false;
9
13
  }
14
+ // TypeScript have problems when filter/map/reduce with union type arrays.
15
+ // https://github.com/microsoft/TypeScript/issues/44373
10
16
  const hasAnotherVisibleSeries = chartSeries
11
17
  .filter((series) => series.options.showInLegend !== false && getSeriesIdentifier(series) !== seriesName)
12
18
  .some((series) => series.visible);
@@ -18,6 +24,10 @@ const updateSeries = (series, chartSeries, type) => {
18
24
  case 'extended': {
19
25
  chartSeries.forEach((item) => {
20
26
  if (getSeriesIdentifier(item) === clickedSeriesName) {
27
+ // Highcharts.Series has serVisible in types
28
+ // Highcharts.Point doesn't have this method in types
29
+ // but it has this method in __proto__ and it works
30
+ // @ts-ignore
21
31
  item.setVisible(!item.visible, false);
22
32
  }
23
33
  });
@@ -27,9 +37,11 @@ const updateSeries = (series, chartSeries, type) => {
27
37
  const visible = needSetVisible(getSeriesIdentifier(series), series.visible, chartSeries);
28
38
  chartSeries.forEach((item) => {
29
39
  if (getSeriesIdentifier(item) === clickedSeriesName) {
40
+ // @ts-ignore
30
41
  item.setVisible(true, false);
31
42
  }
32
43
  else {
44
+ // @ts-ignore
33
45
  item.setVisible(visible, false);
34
46
  }
35
47
  });
@@ -47,10 +59,8 @@ const updateComments = (chart) => {
47
59
  export const handleLegendItemClick = (event) => {
48
60
  event.preventDefault();
49
61
  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;
62
+ const chart = series instanceof Highcharts.Point ? series.series.chart : series.chart;
63
+ const chartSeries = series instanceof Highcharts.Point ? series.series.data : series.chart.series;
54
64
  if (isNavigatorSeries(series)) {
55
65
  return;
56
66
  }
@@ -1,2 +1,2 @@
1
1
  import type { Highcharts } from '../../../../types';
2
- export declare const isNavigatorSeries: (series?: Highcharts.Series | undefined) => boolean;
2
+ export declare const isNavigatorSeries: (series?: Highcharts.Point | Highcharts.Series | undefined) => boolean;
@@ -354,7 +354,7 @@ declare function getGraph({ options, data, comments, isMobile, holidays }: GetGr
354
354
  };
355
355
  series: {
356
356
  events: {
357
- legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject) => void;
357
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject | Highcharts.PointLegendItemClickEventObject) => 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: Highcharts.SeriesLegendItemClickEventObject) => void;
383
+ legendItemClick: (event: Highcharts.SeriesLegendItemClickEventObject | Highcharts.PointLegendItemClickEventObject) => void;
384
384
  };
385
385
  };
386
386
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
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",