@gravity-ui/chartkit 4.21.1 → 4.22.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.
@@ -13,6 +13,7 @@ import { getPreparedYAxis } from '../hooks/useChartOptions/y-axis';
13
13
  import './styles.css';
14
14
  const b = block('d3');
15
15
  export const Chart = (props) => {
16
+ var _a, _b;
16
17
  const { width, height, data } = props;
17
18
  const svgRef = React.useRef(null);
18
19
  const dispatcher = React.useMemo(() => {
@@ -60,15 +61,15 @@ export const Chart = (props) => {
60
61
  yScale,
61
62
  svgContainer: svgRef.current,
62
63
  });
64
+ const clickHandler = (_b = (_a = data.chart) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.click;
63
65
  React.useEffect(() => {
64
- var _a, _b, _c, _d;
65
- if ((_b = (_a = data.chart) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.click) {
66
- dispatcher.on('click-chart', (_d = (_c = data.chart) === null || _c === void 0 ? void 0 : _c.events) === null || _d === void 0 ? void 0 : _d.click);
66
+ if (clickHandler) {
67
+ dispatcher.on('click-chart', clickHandler);
67
68
  }
68
69
  return () => {
69
70
  dispatcher.on('click-chart', null);
70
71
  };
71
- }, [dispatcher]);
72
+ }, [dispatcher, clickHandler]);
72
73
  const boundsOffsetTop = chart.margin.top;
73
74
  const boundsOffsetLeft = chart.margin.left + getWidthOccupiedByYAxis({ preparedAxis: yAxis });
74
75
  return (React.createElement(React.Fragment, null,
@@ -54,6 +54,7 @@ export function prepareArea(args) {
54
54
  allowOverlap: get(series, 'dataLabels.allowOverlap', false),
55
55
  },
56
56
  marker: prepareMarker(series, seriesOptions),
57
+ cursor: get(series, 'cursor', null),
57
58
  };
58
59
  return prepared;
59
60
  }, []);
@@ -30,6 +30,7 @@ export function prepareBarXSeries(args) {
30
30
  allowOverlap: ((_e = series.dataLabels) === null || _e === void 0 ? void 0 : _e.allowOverlap) || false,
31
31
  padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
32
32
  },
33
+ cursor: get(series, 'cursor', null),
33
34
  };
34
35
  }, []);
35
36
  }
@@ -40,6 +40,7 @@ export function prepareBarYSeries(args) {
40
40
  stacking: series.stacking,
41
41
  stackId: getSeriesStackId(series),
42
42
  dataLabels: prepareDataLabels(series),
43
+ cursor: get(series, 'cursor', null),
43
44
  };
44
45
  }, []);
45
46
  }
@@ -73,6 +73,7 @@ export function prepareLineSeries(args) {
73
73
  dashStyle: dashStyle,
74
74
  linecap: prepareLinecap(dashStyle, series, seriesOptions),
75
75
  opacity: get(series, 'opacity', null),
76
+ cursor: get(series, 'cursor', null),
76
77
  };
77
78
  return prepared;
78
79
  }, []);
@@ -53,6 +53,7 @@ export function preparePieSeries(args) {
53
53
  },
54
54
  renderCustomShape: series.renderCustomShape,
55
55
  opacity: get(dataItem, 'opacity', null),
56
+ cursor: get(series, 'cursor', null),
56
57
  };
57
58
  return result;
58
59
  });
@@ -39,6 +39,7 @@ export function prepareScatterSeries(args) {
39
39
  },
40
40
  data: s.data,
41
41
  marker: prepareMarker(s, seriesOptions, index),
42
+ cursor: get(s, 'cursor', null),
42
43
  };
43
44
  return prepared;
44
45
  }, []);
@@ -10,7 +10,7 @@ export function prepareTreemap(args) {
10
10
  const id = getRandomCKId();
11
11
  const name = s.name || '';
12
12
  const color = s.color || colorScale(name);
13
- return {
13
+ const preparedSeries = {
14
14
  color,
15
15
  data: s.data,
16
16
  dataLabels: {
@@ -29,6 +29,8 @@ export function prepareTreemap(args) {
29
29
  },
30
30
  levels: s.levels,
31
31
  layoutAlgorithm: get(s, 'layoutAlgorithm', LayoutAlgorithm.Binary),
32
+ cursor: get(s, 'cursor', null),
32
33
  };
34
+ return preparedSeries;
33
35
  });
34
36
  }
@@ -53,6 +53,7 @@ type BasePreparedSeries = {
53
53
  enabled: boolean;
54
54
  symbol: PreparedLegendSymbol;
55
55
  };
56
+ cursor: string | null;
56
57
  };
57
58
  export type PreparedScatterSeries = {
58
59
  type: ScatterSeries['type'];
@@ -206,7 +207,7 @@ export type PreparedTreemapSeries = {
206
207
  allowOverlap: boolean;
207
208
  };
208
209
  layoutAlgorithm: `${LayoutAlgorithm}`;
209
- } & BasePreparedSeries & TreemapSeries;
210
+ } & BasePreparedSeries & Omit<TreemapSeries, keyof BasePreparedSeries>;
210
211
  export type PreparedSeries = PreparedScatterSeries | PreparedBarXSeries | PreparedBarYSeries | PreparedPieSeries | PreparedLineSeries | PreparedAreaSeries | PreparedTreemapSeries;
211
212
  export type PreparedSeriesOptions = SeriesOptionsDefaults;
212
213
  export type StackedSeries = BarXSeries | AreaSeries | BarYSeries;
@@ -25,7 +25,8 @@ export const AreaSeriesShapes = (args) => {
25
25
  .selectAll('shape')
26
26
  .data(preparedData)
27
27
  .join('g')
28
- .attr('class', b('series'));
28
+ .attr('class', b('series'))
29
+ .attr('cursor', (d) => d.series.cursor);
29
30
  shapeSelection
30
31
  .append('path')
31
32
  .attr('class', b('line'))
@@ -28,7 +28,8 @@ export const BarXSeriesShapes = (args) => {
28
28
  .attr('height', (d) => d.height)
29
29
  .attr('width', (d) => d.width)
30
30
  .attr('fill', (d) => d.data.color || d.series.color)
31
- .attr('opacity', (d) => d.opacity);
31
+ .attr('opacity', (d) => d.opacity)
32
+ .attr('cursor', (d) => d.series.cursor);
32
33
  let dataLabels = preparedData.map((d) => d.label).filter(Boolean);
33
34
  if (!((_a = preparedData[0]) === null || _a === void 0 ? void 0 : _a.series.dataLabels.allowOverlap)) {
34
35
  dataLabels = filterOverlappingLabels(dataLabels);
@@ -24,7 +24,8 @@ export const BarYSeriesShapes = (args) => {
24
24
  .attr('height', (d) => d.height)
25
25
  .attr('width', (d) => d.width)
26
26
  .attr('fill', (d) => d.color)
27
- .attr('opacity', (d) => d.data.opacity || null);
27
+ .attr('opacity', (d) => d.data.opacity || null)
28
+ .attr('cursor', (d) => d.series.cursor);
28
29
  const dataLabels = preparedData.filter((d) => d.series.dataLabels.enabled);
29
30
  const labelSelection = svgElement
30
31
  .selectAll('text')
@@ -32,7 +32,8 @@ export const LineSeriesShapes = (args) => {
32
32
  .attr('stroke-linejoin', (d) => d.linecap)
33
33
  .attr('stroke-linecap', (d) => d.linecap)
34
34
  .attr('stroke-dasharray', (d) => getLineDashArray(d.dashStyle, d.width))
35
- .attr('opacity', (d) => d.opacity);
35
+ .attr('opacity', (d) => d.opacity)
36
+ .attr('cursor', (d) => d.series.cursor);
36
37
  let dataLabels = preparedData.reduce((acc, d) => {
37
38
  return acc.concat(d.labels);
38
39
  }, []);
@@ -33,7 +33,8 @@ export function PieSeriesShapes(args) {
33
33
  return `translate(${x}, ${y})`;
34
34
  })
35
35
  .style('stroke', (pieData) => pieData.borderColor)
36
- .style('stroke-width', (pieData) => pieData.borderWidth);
36
+ .style('stroke-width', (pieData) => pieData.borderWidth)
37
+ .attr('cursor', (pieData) => pieData.series.cursor);
37
38
  // Render halo appearing outside the hovered slice
38
39
  shapesSelection
39
40
  .selectAll('halo')
@@ -23,7 +23,8 @@ export function ScatterSeriesShape(props) {
23
23
  .join('g')
24
24
  .call(renderMarker)
25
25
  .attr('fill', (d) => d.point.data.color || d.point.series.color || '')
26
- .attr('opacity', (d) => d.point.opacity);
26
+ .attr('opacity', (d) => d.point.opacity)
27
+ .attr('cursor', (d) => d.point.series.cursor);
27
28
  const getSelectedPoint = (element) => {
28
29
  return select(element).datum();
29
30
  };
@@ -18,7 +18,8 @@ export const TreemapSeriesShape = (props) => {
18
18
  .selectAll('g')
19
19
  .data(leaves)
20
20
  .join('g')
21
- .attr('transform', (d) => `translate(${d.x0},${d.y0})`);
21
+ .attr('transform', (d) => `translate(${d.x0},${d.y0})`)
22
+ .attr('cursor', series.cursor);
22
23
  const rectSelection = leaf
23
24
  .append('rect')
24
25
  .attr('id', (d) => d.id || d.name)
@@ -22,6 +22,8 @@ export type BaseSeries = {
22
22
  * */
23
23
  allowOverlap?: boolean;
24
24
  };
25
+ /** You can set the cursor to "pointer" if you have click events attached to the series, to signal to the user that the points and lines can be clicked. */
26
+ cursor?: string;
25
27
  };
26
28
  export type BaseSeriesData<T = any> = {
27
29
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "4.21.1",
3
+ "version": "4.22.0",
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",