@gravity-ui/charts 1.24.2 → 1.26.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.
Files changed (103) hide show
  1. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +3 -3
  2. package/dist/cjs/components/ChartInner/useChartInnerProps.js +34 -16
  3. package/dist/cjs/components/Legend/index.js +50 -28
  4. package/dist/cjs/hooks/useAxis/index.js +0 -1
  5. package/dist/cjs/hooks/useAxis/x-axis.d.ts +1 -3
  6. package/dist/cjs/hooks/useAxis/x-axis.js +3 -4
  7. package/dist/cjs/hooks/useAxisScales/index.d.ts +1 -3
  8. package/dist/cjs/hooks/useAxisScales/index.js +6 -35
  9. package/dist/cjs/hooks/useChartDimensions/index.js +16 -1
  10. package/dist/cjs/hooks/useRangeSlider/index.js +0 -1
  11. package/dist/cjs/hooks/useSeries/index.js +8 -8
  12. package/dist/cjs/hooks/useSeries/prepare-area.js +7 -5
  13. package/dist/cjs/hooks/useSeries/prepare-bar-x.js +8 -6
  14. package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +2 -0
  15. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +7 -5
  16. package/dist/cjs/hooks/useSeries/prepare-funnel.js +14 -10
  17. package/dist/cjs/hooks/useSeries/prepare-heatmap.js +9 -7
  18. package/dist/cjs/hooks/useSeries/prepare-legend.js +75 -15
  19. package/dist/cjs/hooks/useSeries/prepare-line.js +6 -4
  20. package/dist/cjs/hooks/useSeries/prepare-pie.js +10 -6
  21. package/dist/cjs/hooks/useSeries/prepare-radar.js +7 -5
  22. package/dist/cjs/hooks/useSeries/prepare-sankey.js +3 -1
  23. package/dist/cjs/hooks/useSeries/prepare-scatter.js +4 -1
  24. package/dist/cjs/hooks/useSeries/prepare-treemap.js +4 -2
  25. package/dist/cjs/hooks/useSeries/prepare-waterfall.js +13 -8
  26. package/dist/cjs/hooks/useSeries/types.d.ts +5 -0
  27. package/dist/cjs/hooks/useSeries/utils.d.ts +7 -3
  28. package/dist/cjs/hooks/useSeries/utils.js +2 -2
  29. package/dist/cjs/hooks/useShapes/area/prepare-data.js +3 -0
  30. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +24 -46
  31. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +0 -3
  32. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +4 -1
  33. package/dist/cjs/hooks/utils/bar-x.d.ts +3 -2
  34. package/dist/cjs/hooks/utils/bar-x.js +8 -6
  35. package/dist/cjs/hooks/utils/bar-y.d.ts +0 -1
  36. package/dist/cjs/hooks/utils/bar-y.js +3 -3
  37. package/dist/cjs/types/chart/area.d.ts +3 -3
  38. package/dist/cjs/types/chart/axis.d.ts +1 -0
  39. package/dist/cjs/types/chart/bar-x.d.ts +3 -3
  40. package/dist/cjs/types/chart/bar-y.d.ts +3 -3
  41. package/dist/cjs/types/chart/base.d.ts +9 -0
  42. package/dist/cjs/types/chart/funnel.d.ts +10 -6
  43. package/dist/cjs/types/chart/heatmap.d.ts +3 -3
  44. package/dist/cjs/types/chart/legend.d.ts +12 -10
  45. package/dist/cjs/types/chart/line.d.ts +3 -3
  46. package/dist/cjs/types/chart/pie.d.ts +10 -6
  47. package/dist/cjs/types/chart/radar.d.ts +3 -3
  48. package/dist/cjs/types/chart/sankey.d.ts +3 -3
  49. package/dist/cjs/types/chart/scatter.d.ts +3 -3
  50. package/dist/cjs/types/chart/treemap.d.ts +3 -3
  51. package/dist/cjs/types/chart/waterfall.d.ts +2 -2
  52. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +3 -3
  53. package/dist/esm/components/ChartInner/useChartInnerProps.js +34 -16
  54. package/dist/esm/components/Legend/index.js +50 -28
  55. package/dist/esm/hooks/useAxis/index.js +0 -1
  56. package/dist/esm/hooks/useAxis/x-axis.d.ts +1 -3
  57. package/dist/esm/hooks/useAxis/x-axis.js +3 -4
  58. package/dist/esm/hooks/useAxisScales/index.d.ts +1 -3
  59. package/dist/esm/hooks/useAxisScales/index.js +6 -35
  60. package/dist/esm/hooks/useChartDimensions/index.js +16 -1
  61. package/dist/esm/hooks/useRangeSlider/index.js +0 -1
  62. package/dist/esm/hooks/useSeries/index.js +8 -8
  63. package/dist/esm/hooks/useSeries/prepare-area.js +7 -5
  64. package/dist/esm/hooks/useSeries/prepare-bar-x.js +8 -6
  65. package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +2 -0
  66. package/dist/esm/hooks/useSeries/prepare-bar-y.js +7 -5
  67. package/dist/esm/hooks/useSeries/prepare-funnel.js +14 -10
  68. package/dist/esm/hooks/useSeries/prepare-heatmap.js +9 -7
  69. package/dist/esm/hooks/useSeries/prepare-legend.js +75 -15
  70. package/dist/esm/hooks/useSeries/prepare-line.js +6 -4
  71. package/dist/esm/hooks/useSeries/prepare-pie.js +10 -6
  72. package/dist/esm/hooks/useSeries/prepare-radar.js +7 -5
  73. package/dist/esm/hooks/useSeries/prepare-sankey.js +3 -1
  74. package/dist/esm/hooks/useSeries/prepare-scatter.js +4 -1
  75. package/dist/esm/hooks/useSeries/prepare-treemap.js +4 -2
  76. package/dist/esm/hooks/useSeries/prepare-waterfall.js +13 -8
  77. package/dist/esm/hooks/useSeries/types.d.ts +5 -0
  78. package/dist/esm/hooks/useSeries/utils.d.ts +7 -3
  79. package/dist/esm/hooks/useSeries/utils.js +2 -2
  80. package/dist/esm/hooks/useShapes/area/prepare-data.js +3 -0
  81. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +24 -46
  82. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +0 -3
  83. package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +4 -1
  84. package/dist/esm/hooks/utils/bar-x.d.ts +3 -2
  85. package/dist/esm/hooks/utils/bar-x.js +8 -6
  86. package/dist/esm/hooks/utils/bar-y.d.ts +0 -1
  87. package/dist/esm/hooks/utils/bar-y.js +3 -3
  88. package/dist/esm/types/chart/area.d.ts +3 -3
  89. package/dist/esm/types/chart/axis.d.ts +1 -0
  90. package/dist/esm/types/chart/bar-x.d.ts +3 -3
  91. package/dist/esm/types/chart/bar-y.d.ts +3 -3
  92. package/dist/esm/types/chart/base.d.ts +9 -0
  93. package/dist/esm/types/chart/funnel.d.ts +10 -6
  94. package/dist/esm/types/chart/heatmap.d.ts +3 -3
  95. package/dist/esm/types/chart/legend.d.ts +12 -10
  96. package/dist/esm/types/chart/line.d.ts +3 -3
  97. package/dist/esm/types/chart/pie.d.ts +10 -6
  98. package/dist/esm/types/chart/radar.d.ts +3 -3
  99. package/dist/esm/types/chart/sankey.d.ts +3 -3
  100. package/dist/esm/types/chart/scatter.d.ts +3 -3
  101. package/dist/esm/types/chart/treemap.d.ts +3 -3
  102. package/dist/esm/types/chart/waterfall.d.ts +2 -2
  103. package/package.json +1 -1
@@ -13,7 +13,7 @@ function prepareSeriesData(series) {
13
13
  return data.map((p) => { var _a; return (Object.assign(Object.assign({}, p), { x: (_a = p.x) !== null && _a !== void 0 ? _a : 0 })); });
14
14
  case 'skip':
15
15
  default:
16
- return data.filter((p) => p.x !== null);
16
+ return data;
17
17
  }
18
18
  }
19
19
  async function prepareDataLabels(series) {
@@ -46,7 +46,7 @@ async function prepareDataLabels(series) {
46
46
  export function prepareBarYSeries(args) {
47
47
  const { colorScale, series: seriesList, seriesOptions, legend } = args;
48
48
  return Promise.all(seriesList.map(async (series) => {
49
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
49
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
50
50
  const name = series.name || '';
51
51
  const color = series.color || colorScale(name);
52
52
  return {
@@ -58,15 +58,17 @@ export function prepareBarYSeries(args) {
58
58
  legend: {
59
59
  enabled: get(series, 'legend.enabled', legend.enabled),
60
60
  symbol: prepareLegendSymbol(series),
61
+ groupId: (_b = (_a = series.legend) === null || _a === void 0 ? void 0 : _a.groupId) !== null && _b !== void 0 ? _b : getUniqId(),
62
+ itemText: (_d = (_c = series.legend) === null || _c === void 0 ? void 0 : _c.itemText) !== null && _d !== void 0 ? _d : name,
61
63
  },
62
64
  data: prepareSeriesData(series),
63
65
  stacking: series.stacking,
64
66
  stackId: getSeriesStackId(series),
65
67
  dataLabels: await prepareDataLabels(series),
66
68
  cursor: get(series, 'cursor', null),
67
- borderRadius: (_c = (_a = series.borderRadius) !== null && _a !== void 0 ? _a : (_b = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _b === void 0 ? void 0 : _b.borderRadius) !== null && _c !== void 0 ? _c : 0,
68
- borderWidth: (_f = (_d = series.borderWidth) !== null && _d !== void 0 ? _d : (_e = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _e === void 0 ? void 0 : _e.borderWidth) !== null && _f !== void 0 ? _f : 0,
69
- borderColor: (_j = (_g = series.borderColor) !== null && _g !== void 0 ? _g : (_h = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _h === void 0 ? void 0 : _h.borderColor) !== null && _j !== void 0 ? _j : 'var(--gcharts-shape-border-color)',
69
+ borderRadius: (_g = (_e = series.borderRadius) !== null && _e !== void 0 ? _e : (_f = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _f === void 0 ? void 0 : _f.borderRadius) !== null && _g !== void 0 ? _g : 0,
70
+ borderWidth: (_k = (_h = series.borderWidth) !== null && _h !== void 0 ? _h : (_j = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _j === void 0 ? void 0 : _j.borderWidth) !== null && _k !== void 0 ? _k : 0,
71
+ borderColor: (_o = (_l = series.borderColor) !== null && _l !== void 0 ? _l : (_m = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions['bar-y']) === null || _m === void 0 ? void 0 : _m.borderColor) !== null && _o !== void 0 ? _o : 'var(--gcharts-shape-border-color)',
70
72
  tooltip: series.tooltip,
71
73
  };
72
74
  }));
@@ -10,7 +10,7 @@ export function prepareFunnelSeries(args) {
10
10
  const colorScale = scaleOrdinal(dataNames, colors);
11
11
  const isConnectorsEnabled = (_b = (_a = series.connectors) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true;
12
12
  const preparedSeries = series.data.map((dataItem) => {
13
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
13
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
14
14
  const id = getUniqId();
15
15
  const color = dataItem.color || colorScale(dataItem.name);
16
16
  const result = {
@@ -28,20 +28,24 @@ export function prepareFunnelSeries(args) {
28
28
  id,
29
29
  color,
30
30
  legend: {
31
- enabled: get(series, 'legend.enabled', legend.enabled),
32
- symbol: prepareLegendSymbol(series),
31
+ enabled: (_h = (_f = (_e = dataItem.legend) === null || _e === void 0 ? void 0 : _e.enabled) !== null && _f !== void 0 ? _f : (_g = series.legend) === null || _g === void 0 ? void 0 : _g.enabled) !== null && _h !== void 0 ? _h : legend.enabled,
32
+ symbol: ((_j = dataItem.legend) === null || _j === void 0 ? void 0 : _j.symbol)
33
+ ? prepareLegendSymbol(dataItem)
34
+ : prepareLegendSymbol(series),
35
+ groupId: (_l = (_k = dataItem.legend) === null || _k === void 0 ? void 0 : _k.groupId) !== null && _l !== void 0 ? _l : getUniqId(),
36
+ itemText: (_o = (_m = dataItem.legend) === null || _m === void 0 ? void 0 : _m.itemText) !== null && _o !== void 0 ? _o : dataItem.name,
33
37
  },
34
38
  cursor: get(series, 'cursor', null),
35
39
  tooltip: series.tooltip,
36
40
  connectors: {
37
41
  enabled: isConnectorsEnabled,
38
- height: isConnectorsEnabled ? ((_f = (_e = series.connectors) === null || _e === void 0 ? void 0 : _e.height) !== null && _f !== void 0 ? _f : '25%') : 0,
39
- lineDashStyle: (_h = (_g = series.connectors) === null || _g === void 0 ? void 0 : _g.lineDashStyle) !== null && _h !== void 0 ? _h : 'Dash',
40
- lineOpacity: (_k = (_j = series.connectors) === null || _j === void 0 ? void 0 : _j.lineOpacity) !== null && _k !== void 0 ? _k : 1,
41
- lineColor: (_m = (_l = series.connectors) === null || _l === void 0 ? void 0 : _l.lineColor) !== null && _m !== void 0 ? _m : 'var(--g-color-line-generic-active)',
42
- areaColor: (_p = (_o = series.connectors) === null || _o === void 0 ? void 0 : _o.areaColor) !== null && _p !== void 0 ? _p : color,
43
- areaOpacity: (_r = (_q = series.connectors) === null || _q === void 0 ? void 0 : _q.areaOpacity) !== null && _r !== void 0 ? _r : 0.25,
44
- lineWidth: (_t = (_s = series.connectors) === null || _s === void 0 ? void 0 : _s.lineWidth) !== null && _t !== void 0 ? _t : 1,
42
+ height: isConnectorsEnabled ? ((_q = (_p = series.connectors) === null || _p === void 0 ? void 0 : _p.height) !== null && _q !== void 0 ? _q : '25%') : 0,
43
+ lineDashStyle: (_s = (_r = series.connectors) === null || _r === void 0 ? void 0 : _r.lineDashStyle) !== null && _s !== void 0 ? _s : 'Dash',
44
+ lineOpacity: (_u = (_t = series.connectors) === null || _t === void 0 ? void 0 : _t.lineOpacity) !== null && _u !== void 0 ? _u : 1,
45
+ lineColor: (_w = (_v = series.connectors) === null || _v === void 0 ? void 0 : _v.lineColor) !== null && _w !== void 0 ? _w : 'var(--g-color-line-generic-active)',
46
+ areaColor: (_y = (_x = series.connectors) === null || _x === void 0 ? void 0 : _x.areaColor) !== null && _y !== void 0 ? _y : color,
47
+ areaOpacity: (_0 = (_z = series.connectors) === null || _z === void 0 ? void 0 : _z.areaOpacity) !== null && _0 !== void 0 ? _0 : 0.25,
48
+ lineWidth: (_2 = (_1 = series.connectors) === null || _1 === void 0 ? void 0 : _1.lineWidth) !== null && _2 !== void 0 ? _2 : 1,
45
49
  },
46
50
  };
47
51
  return result;
@@ -18,7 +18,7 @@ function prepareSeriesData(series) {
18
18
  export function prepareHeatmapSeries(args) {
19
19
  const { colorScale, series: seriesList, seriesOptions, legend } = args;
20
20
  return seriesList.map((series) => {
21
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
21
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
22
22
  const name = series.name || '';
23
23
  const color = series.color || colorScale(name);
24
24
  return {
@@ -30,20 +30,22 @@ export function prepareHeatmapSeries(args) {
30
30
  legend: {
31
31
  enabled: get(series, 'legend.enabled', legend.enabled),
32
32
  symbol: prepareLegendSymbol(series),
33
+ groupId: (_b = (_a = series.legend) === null || _a === void 0 ? void 0 : _a.groupId) !== null && _b !== void 0 ? _b : getUniqId(),
34
+ itemText: (_d = (_c = series.legend) === null || _c === void 0 ? void 0 : _c.itemText) !== null && _d !== void 0 ? _d : name,
33
35
  },
34
36
  data: prepareSeriesData(series),
35
37
  dataLabels: {
36
- enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || false,
37
- style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.style),
38
+ enabled: ((_e = series.dataLabels) === null || _e === void 0 ? void 0 : _e.enabled) || false,
39
+ style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_f = series.dataLabels) === null || _f === void 0 ? void 0 : _f.style),
38
40
  padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
39
- html: (_d = (_c = series.dataLabels) === null || _c === void 0 ? void 0 : _c.html) !== null && _d !== void 0 ? _d : false,
40
- format: (_e = series.dataLabels) === null || _e === void 0 ? void 0 : _e.format,
41
+ html: (_h = (_g = series.dataLabels) === null || _g === void 0 ? void 0 : _g.html) !== null && _h !== void 0 ? _h : false,
42
+ format: (_j = series.dataLabels) === null || _j === void 0 ? void 0 : _j.format,
41
43
  },
42
44
  cursor: get(series, 'cursor', null),
43
45
  yAxis: get(series, 'yAxis', 0),
44
46
  tooltip: series.tooltip,
45
- borderColor: (_h = (_f = series.borderColor) !== null && _f !== void 0 ? _f : (_g = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions.heatmap) === null || _g === void 0 ? void 0 : _g.borderColor) !== null && _h !== void 0 ? _h : 'var(--gcharts-shape-border-color)',
46
- borderWidth: (_l = (_j = series.borderWidth) !== null && _j !== void 0 ? _j : (_k = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions.heatmap) === null || _k === void 0 ? void 0 : _k.borderWidth) !== null && _l !== void 0 ? _l : 0,
47
+ borderColor: (_m = (_k = series.borderColor) !== null && _k !== void 0 ? _k : (_l = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions.heatmap) === null || _l === void 0 ? void 0 : _l.borderColor) !== null && _m !== void 0 ? _m : 'var(--gcharts-shape-border-color)',
48
+ borderWidth: (_q = (_o = series.borderWidth) !== null && _o !== void 0 ? _o : (_p = seriesOptions === null || seriesOptions === void 0 ? void 0 : seriesOptions.heatmap) === null || _p === void 0 ? void 0 : _p.borderWidth) !== null && _q !== void 0 ? _q : 0,
47
49
  };
48
50
  }, []);
49
51
  }
@@ -1,4 +1,5 @@
1
1
  import { select } from 'd3';
2
+ import { groupBy } from 'lodash';
2
3
  import clone from 'lodash/clone';
3
4
  import get from 'lodash/get';
4
5
  import merge from 'lodash/merge';
@@ -11,7 +12,10 @@ export async function getPreparedLegend(args) {
11
12
  const defaultItemStyle = clone(legendDefaults.itemStyle);
12
13
  const itemStyle = get(legend, 'itemStyle');
13
14
  const computedItemStyle = merge(defaultItemStyle, itemStyle);
14
- const lineHeight = (await getLabelsSize({ labels: ['Tmp'], style: computedItemStyle })).maxHeight;
15
+ const { maxHeight: lineHeight, maxWidth: lineWidth } = await getLabelsSize({
16
+ labels: ['Tmp'],
17
+ style: computedItemStyle,
18
+ });
15
19
  const legendType = get(legend, 'type', 'discrete');
16
20
  const isTitleEnabled = Boolean((_a = legend === null || legend === void 0 ? void 0 : legend.title) === null || _a === void 0 ? void 0 : _a.text);
17
21
  const titleMargin = isTitleEnabled ? get(legend, 'title.margin', 4) : 0;
@@ -33,9 +37,11 @@ export async function getPreparedLegend(args) {
33
37
  stops: [],
34
38
  };
35
39
  let height = 0;
40
+ let legendWidth = 0;
36
41
  if (enabled) {
37
42
  height += titleHeight + titleMargin;
38
43
  if (legendType === 'continuous') {
44
+ legendWidth = get(legend, 'width', CONTINUOUS_LEGEND_SIZE.width);
39
45
  height += CONTINUOUS_LEGEND_SIZE.height;
40
46
  height += ticks.labelsLineHeight + ticks.labelsMargin;
41
47
  colorScale.colors = (_c = (_b = legend === null || legend === void 0 ? void 0 : legend.colorScale) === null || _b === void 0 ? void 0 : _b.colors) !== null && _c !== void 0 ? _c : [];
@@ -46,9 +52,9 @@ export async function getPreparedLegend(args) {
46
52
  }
47
53
  else {
48
54
  height += lineHeight;
55
+ legendWidth = get(legend, 'width', lineWidth);
49
56
  }
50
57
  }
51
- const legendWidth = get(legend, 'width', CONTINUOUS_LEGEND_SIZE.width);
52
58
  return {
53
59
  align: get(legend, 'align', legendDefaults.align),
54
60
  justifyContent: get(legend, 'justifyContent', legendDefaults.justifyContent),
@@ -75,10 +81,11 @@ export async function getPreparedLegend(args) {
75
81
  };
76
82
  }
77
83
  function getFlattenLegendItems(series, preparedLegend) {
78
- return series.reduce((acc, s) => {
79
- const legendEnabled = get(s, 'legend.enabled', true);
80
- if (legendEnabled) {
81
- acc.push(Object.assign(Object.assign({}, s), { height: preparedLegend.lineHeight, symbol: s.legend.symbol }));
84
+ const grouped = groupBy(series, (s) => s.legend.groupId);
85
+ return Object.values(grouped).reduce((acc, items) => {
86
+ const s = items.find((item) => item.legend.enabled);
87
+ if (s) {
88
+ acc.push(Object.assign(Object.assign({}, s), { id: s.legend.groupId, name: s.legend.itemText, height: preparedLegend.lineHeight, symbol: s.legend.symbol }));
82
89
  }
83
90
  return acc;
84
91
  }, []);
@@ -166,10 +173,61 @@ function getPagination(args) {
166
173
  });
167
174
  return { pages };
168
175
  }
176
+ function getLegendOffset(args) {
177
+ const { position, chartWidth, chartHeight, chartMargin, legendWidth, legendHeight } = args;
178
+ switch (position) {
179
+ case 'top':
180
+ return {
181
+ top: chartMargin.top,
182
+ left: chartMargin.left,
183
+ };
184
+ case 'right':
185
+ return {
186
+ top: chartMargin.top,
187
+ left: chartWidth - chartMargin.right - legendWidth,
188
+ };
189
+ case 'left':
190
+ return {
191
+ top: chartMargin.top,
192
+ left: chartMargin.left,
193
+ };
194
+ case 'bottom':
195
+ default:
196
+ return {
197
+ top: chartHeight - chartMargin.bottom - legendHeight,
198
+ left: chartMargin.left,
199
+ };
200
+ }
201
+ }
202
+ function getMaxLegendWidth(args) {
203
+ const { chartWidth, chartMargin, preparedLegend, isVerticalPosition } = args;
204
+ if (isVerticalPosition) {
205
+ return (chartWidth - chartMargin.right - chartMargin.left - preparedLegend.margin) / 2;
206
+ }
207
+ return chartWidth - chartMargin.right - chartMargin.left;
208
+ }
209
+ function getMaxLegendHeight(args) {
210
+ const { chartHeight, chartMargin, preparedLegend, isVerticalPosition } = args;
211
+ if (isVerticalPosition) {
212
+ return chartHeight - chartMargin.top - chartMargin.bottom;
213
+ }
214
+ return (chartHeight - chartMargin.top - chartMargin.bottom - preparedLegend.margin) / 2;
215
+ }
169
216
  export function getLegendComponents(args) {
170
217
  const { chartWidth, chartHeight, chartMargin, series, preparedLegend } = args;
171
- const maxLegendWidth = chartWidth - chartMargin.right - chartMargin.left;
172
- const maxLegendHeight = (chartHeight - chartMargin.top - chartMargin.bottom - preparedLegend.margin) / 2;
218
+ const isVerticalPosition = preparedLegend.position === 'right' || preparedLegend.position === 'left';
219
+ const maxLegendWidth = getMaxLegendWidth({
220
+ chartWidth,
221
+ chartMargin,
222
+ preparedLegend,
223
+ isVerticalPosition,
224
+ });
225
+ const maxLegendHeight = getMaxLegendHeight({
226
+ chartHeight,
227
+ chartMargin,
228
+ preparedLegend,
229
+ isVerticalPosition,
230
+ });
173
231
  const flattenLegendItems = getFlattenLegendItems(series, preparedLegend);
174
232
  const items = getGroupedLegendItems({
175
233
  maxLegendWidth,
@@ -195,13 +253,15 @@ export function getLegendComponents(args) {
195
253
  });
196
254
  }
197
255
  preparedLegend.height = legendHeight;
256
+ preparedLegend.width = Math.max(maxLegendWidth, preparedLegend.width);
198
257
  }
199
- const top = preparedLegend.position === 'top'
200
- ? chartMargin.top
201
- : chartHeight - chartMargin.bottom - preparedLegend.height;
202
- const offset = {
203
- left: chartMargin.left,
204
- top,
205
- };
258
+ const offset = getLegendOffset({
259
+ position: preparedLegend.position,
260
+ chartWidth,
261
+ chartHeight,
262
+ chartMargin,
263
+ legendWidth: preparedLegend.width,
264
+ legendHeight: preparedLegend.height,
265
+ });
206
266
  return { legendConfig: { offset, pagination, maxWidth: maxLegendWidth }, legendItems: items };
207
267
  }
@@ -60,7 +60,7 @@ export function prepareLineSeries(args) {
60
60
  const defaultLineWidth = get(seriesOptions, 'line.lineWidth', DEFAULT_LINE_WIDTH);
61
61
  const defaultDashStyle = get(seriesOptions, 'line.dashStyle', DEFAULT_DASH_STYLE);
62
62
  return seriesList.map((series) => {
63
- var _a, _b, _c;
63
+ var _a, _b, _c, _d, _e, _f, _g;
64
64
  const id = getUniqId();
65
65
  const name = series.name || '';
66
66
  const color = series.color || colorScale(name);
@@ -75,15 +75,17 @@ export function prepareLineSeries(args) {
75
75
  legend: {
76
76
  enabled: get(series, 'legend.enabled', legend.enabled),
77
77
  symbol: prepareLineLegendSymbol(series, seriesOptions),
78
+ groupId: (_b = (_a = series.legend) === null || _a === void 0 ? void 0 : _a.groupId) !== null && _b !== void 0 ? _b : getUniqId(),
79
+ itemText: (_d = (_c = series.legend) === null || _c === void 0 ? void 0 : _c.itemText) !== null && _d !== void 0 ? _d : name,
78
80
  },
79
81
  data: prepareSeriesData(series),
80
82
  dataLabels: {
81
- enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || false,
82
- style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.style),
83
+ enabled: ((_e = series.dataLabels) === null || _e === void 0 ? void 0 : _e.enabled) || false,
84
+ style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_f = series.dataLabels) === null || _f === void 0 ? void 0 : _f.style),
83
85
  padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
84
86
  allowOverlap: get(series, 'dataLabels.allowOverlap', false),
85
87
  html: get(series, 'dataLabels.html', false),
86
- format: (_c = series.dataLabels) === null || _c === void 0 ? void 0 : _c.format,
88
+ format: (_g = series.dataLabels) === null || _g === void 0 ? void 0 : _g.format,
87
89
  },
88
90
  marker: prepareMarker(series, seriesOptions),
89
91
  dashStyle: dashStyle,
@@ -24,7 +24,7 @@ export function preparePieSeries(args) {
24
24
  const stackId = getUniqId();
25
25
  const seriesHoverState = get(seriesOptions, 'pie.states.hover');
26
26
  const preparedSeries = preparedData.map((dataItem) => {
27
- var _a, _b, _c, _d, _e, _f;
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
28
28
  const id = getUniqId();
29
29
  const result = {
30
30
  type: 'pie',
@@ -48,14 +48,18 @@ export function preparePieSeries(args) {
48
48
  id,
49
49
  color: dataItem.color || colorScale(dataItem.name),
50
50
  legend: {
51
- enabled: get(series, 'legend.enabled', legend.enabled),
52
- symbol: prepareLegendSymbol(series),
51
+ enabled: (_f = (_d = (_c = dataItem.legend) === null || _c === void 0 ? void 0 : _c.enabled) !== null && _d !== void 0 ? _d : (_e = series.legend) === null || _e === void 0 ? void 0 : _e.enabled) !== null && _f !== void 0 ? _f : legend.enabled,
52
+ symbol: ((_g = dataItem.legend) === null || _g === void 0 ? void 0 : _g.symbol)
53
+ ? prepareLegendSymbol(dataItem)
54
+ : prepareLegendSymbol(series),
55
+ groupId: (_j = (_h = dataItem.legend) === null || _h === void 0 ? void 0 : _h.groupId) !== null && _j !== void 0 ? _j : getUniqId(),
56
+ itemText: (_l = (_k = dataItem.legend) === null || _k === void 0 ? void 0 : _k.itemText) !== null && _l !== void 0 ? _l : dataItem.name,
53
57
  },
54
58
  center: series.center || ['50%', '50%'],
55
59
  borderColor: series.borderColor || '',
56
- borderRadius: (_c = series.borderRadius) !== null && _c !== void 0 ? _c : 0,
57
- borderWidth: (_d = series.borderWidth) !== null && _d !== void 0 ? _d : 1,
58
- radius: (_f = (_e = dataItem.radius) !== null && _e !== void 0 ? _e : series.radius) !== null && _f !== void 0 ? _f : '100%',
60
+ borderRadius: (_m = series.borderRadius) !== null && _m !== void 0 ? _m : 0,
61
+ borderWidth: (_o = series.borderWidth) !== null && _o !== void 0 ? _o : 1,
62
+ radius: (_q = (_p = dataItem.radius) !== null && _p !== void 0 ? _p : series.radius) !== null && _q !== void 0 ? _q : '100%',
59
63
  innerRadius: series.innerRadius || 0,
60
64
  minRadius: series.minRadius,
61
65
  stackId,
@@ -30,7 +30,7 @@ export function prepareRadarSeries(args) {
30
30
  const colorScale = scaleOrdinal(radarSeries.map((s, index) => { var _a; return (_a = s.name) !== null && _a !== void 0 ? _a : `Series ${index + 1}`; }), colors);
31
31
  const categories = (_b = (_a = radarSeries.find((s) => s.categories)) === null || _a === void 0 ? void 0 : _a.categories) !== null && _b !== void 0 ? _b : [];
32
32
  return radarSeries.map((series, index) => {
33
- var _a, _b, _c, _d, _e, _f;
33
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
34
34
  const name = (_a = series.name) !== null && _a !== void 0 ? _a : `Series ${index + 1}`;
35
35
  const color = (_b = series.color) !== null && _b !== void 0 ? _b : colorScale(name);
36
36
  const preparedSeries = {
@@ -44,17 +44,19 @@ export function prepareRadarSeries(args) {
44
44
  legend: {
45
45
  enabled: get(series, 'legend.enabled', legend.enabled),
46
46
  symbol: prepareLegendSymbol(series),
47
+ groupId: (_d = (_c = series.legend) === null || _c === void 0 ? void 0 : _c.groupId) !== null && _d !== void 0 ? _d : getUniqId(),
48
+ itemText: (_f = (_e = series.legend) === null || _e === void 0 ? void 0 : _e.itemText) !== null && _f !== void 0 ? _f : name,
47
49
  },
48
50
  borderColor: series.borderColor || color,
49
- borderWidth: (_c = series.borderWidth) !== null && _c !== void 0 ? _c : 1,
50
- fillOpacity: (_d = series.fillOpacity) !== null && _d !== void 0 ? _d : 0.25,
51
+ borderWidth: (_g = series.borderWidth) !== null && _g !== void 0 ? _g : 1,
52
+ fillOpacity: (_h = series.fillOpacity) !== null && _h !== void 0 ? _h : 0.25,
51
53
  dataLabels: {
52
54
  enabled: get(series, 'dataLabels.enabled', true),
53
- style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_e = series.dataLabels) === null || _e === void 0 ? void 0 : _e.style),
55
+ style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_j = series.dataLabels) === null || _j === void 0 ? void 0 : _j.style),
54
56
  padding: get(series, 'dataLabels.padding', DEFAULT_DATALABELS_PADDING),
55
57
  allowOverlap: get(series, 'dataLabels.allowOverlap', false),
56
58
  html: get(series, 'dataLabels.html', false),
57
- format: (_f = series.dataLabels) === null || _f === void 0 ? void 0 : _f.format,
59
+ format: (_k = series.dataLabels) === null || _k === void 0 ? void 0 : _k.format,
58
60
  },
59
61
  cursor: get(series, 'cursor', null),
60
62
  marker: prepareMarker(series, seriesOptions),
@@ -5,7 +5,7 @@ import { prepareLegendSymbol } from './utils';
5
5
  export function prepareSankeySeries(args) {
6
6
  const { colorScale, legend, series } = args;
7
7
  return series.map((s) => {
8
- var _a, _b;
8
+ var _a, _b, _c, _d, _e, _f;
9
9
  const id = getUniqId();
10
10
  const name = s.name || '';
11
11
  const color = colorScale(name);
@@ -31,6 +31,8 @@ export function prepareSankeySeries(args) {
31
31
  legend: {
32
32
  enabled: get(s, 'legend.enabled', legend.enabled),
33
33
  symbol: prepareLegendSymbol(s),
34
+ groupId: (_d = (_c = s.legend) === null || _c === void 0 ? void 0 : _c.groupId) !== null && _d !== void 0 ? _d : getUniqId(),
35
+ itemText: (_f = (_e = s.legend) === null || _e === void 0 ? void 0 : _e.itemText) !== null && _f !== void 0 ? _f : name,
34
36
  },
35
37
  cursor: get(s, 'cursor', null),
36
38
  tooltip: s.tooltip,
@@ -39,6 +39,7 @@ function prepareSeriesData(series) {
39
39
  export function prepareScatterSeries(args) {
40
40
  const { colorScale, series, seriesOptions, legend } = args;
41
41
  return series.map((s, index) => {
42
+ var _a, _b, _c, _d, _e, _f;
42
43
  const id = getUniqId();
43
44
  const name = 'name' in s && s.name ? s.name : '';
44
45
  const symbolType = s.symbolType || getSymbolType(index);
@@ -49,8 +50,10 @@ export function prepareScatterSeries(args) {
49
50
  color: get(s, 'color', colorScale(name)),
50
51
  visible: get(s, 'visible', true),
51
52
  legend: {
52
- enabled: get(s, 'legend.enabled', legend.enabled),
53
+ enabled: (_b = (_a = s.legend) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : legend.enabled,
53
54
  symbol: prepareLegendSymbol(s, symbolType),
55
+ groupId: (_d = (_c = s.legend) === null || _c === void 0 ? void 0 : _c.groupId) !== null && _d !== void 0 ? _d : getUniqId(),
56
+ itemText: (_f = (_e = s.legend) === null || _e === void 0 ? void 0 : _e.itemText) !== null && _f !== void 0 ? _f : name,
54
57
  },
55
58
  data: prepareSeriesData(s),
56
59
  marker: prepareMarker(s, seriesOptions, index),
@@ -6,7 +6,7 @@ import { prepareLegendSymbol } from './utils';
6
6
  export function prepareTreemap(args) {
7
7
  const { colorScale, legend, series } = args;
8
8
  return series.map((s) => {
9
- var _a, _b, _c;
9
+ var _a, _b, _c, _d, _e, _f, _g;
10
10
  const id = getUniqId();
11
11
  const name = s.name || '';
12
12
  const color = s.color || colorScale(name);
@@ -29,8 +29,10 @@ export function prepareTreemap(args) {
29
29
  legend: {
30
30
  enabled: get(s, 'legend.enabled', legend.enabled),
31
31
  symbol: prepareLegendSymbol(s),
32
+ groupId: (_d = (_c = s.legend) === null || _c === void 0 ? void 0 : _c.groupId) !== null && _d !== void 0 ? _d : getUniqId(),
33
+ itemText: (_f = (_e = s.legend) === null || _e === void 0 ? void 0 : _e.itemText) !== null && _f !== void 0 ? _f : name,
32
34
  },
33
- levels: (_c = s.levels) !== null && _c !== void 0 ? _c : [],
35
+ levels: (_g = s.levels) !== null && _g !== void 0 ? _g : [],
34
36
  layoutAlgorithm: get(s, 'layoutAlgorithm', LayoutAlgorithm.Binary),
35
37
  cursor: get(s, 'cursor', null),
36
38
  sorting: Object.assign({ enabled: false, direction: 'desc' }, s.sorting),
@@ -19,7 +19,7 @@ function prepareSeriesData(series) {
19
19
  }
20
20
  }
21
21
  export function prepareWaterfallSeries(args) {
22
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
22
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
23
23
  const { colorScale, series: seriesList, legend, colors } = args;
24
24
  const [, negativeColor, positiveColor] = colors;
25
25
  const series = seriesList[0];
@@ -29,10 +29,6 @@ export function prepareWaterfallSeries(args) {
29
29
  type: series.type,
30
30
  name: series.name,
31
31
  visible: get(series, 'visible', true),
32
- legend: {
33
- enabled: get(series, 'legend.enabled', legend.enabled),
34
- symbol: prepareLegendSymbol(series),
35
- },
36
32
  dataLabels: {
37
33
  enabled: ((_a = series.dataLabels) === null || _a === void 0 ? void 0 : _a.enabled) || true,
38
34
  style: Object.assign({}, DEFAULT_DATALABELS_STYLE, (_b = series.dataLabels) === null || _b === void 0 ? void 0 : _b.style),
@@ -41,13 +37,22 @@ export function prepareWaterfallSeries(args) {
41
37
  html: get(series, 'dataLabels.html', false),
42
38
  format: (_d = series.dataLabels) === null || _d === void 0 ? void 0 : _d.format,
43
39
  },
40
+ legend: {
41
+ enabled: get(series, 'legend.enabled', legend.enabled),
42
+ symbol: prepareLegendSymbol(series),
43
+ groupId: '',
44
+ itemText: '',
45
+ },
44
46
  cursor: get(series, 'cursor', null),
45
47
  data: [],
46
48
  tooltip: series.tooltip,
47
49
  };
48
- const positive = Object.assign(Object.assign({}, common), { name: (_g = (_f = (_e = series.legend) === null || _e === void 0 ? void 0 : _e.itemText) === null || _f === void 0 ? void 0 : _f.positive) !== null && _g !== void 0 ? _g : `${series.name} ↑`, id: getUniqId(), color: series.positiveColor || positiveColor, data: [] });
49
- const negative = Object.assign(Object.assign({}, common), { name: (_k = (_j = (_h = series.legend) === null || _h === void 0 ? void 0 : _h.itemText) === null || _j === void 0 ? void 0 : _j.negative) !== null && _k !== void 0 ? _k : `${series.name} ↓`, id: getUniqId(), color: series.negativeColor || negativeColor, data: [] });
50
- const totals = Object.assign(Object.assign({}, common), { name: (_o = (_m = (_l = series.legend) === null || _l === void 0 ? void 0 : _l.itemText) === null || _m === void 0 ? void 0 : _m.totals) !== null && _o !== void 0 ? _o : series.name, id: getUniqId(), data: [] });
50
+ const positiveName = (_g = (_f = (_e = series.legend) === null || _e === void 0 ? void 0 : _e.itemText) === null || _f === void 0 ? void 0 : _f.positive) !== null && _g !== void 0 ? _g : `${series.name} ↑`;
51
+ const positive = Object.assign(Object.assign({}, common), { name: positiveName, legend: Object.assign(Object.assign({}, common.legend), { groupId: getUniqId(), itemText: (_k = (_j = (_h = series.legend) === null || _h === void 0 ? void 0 : _h.itemText) === null || _j === void 0 ? void 0 : _j.positive) !== null && _k !== void 0 ? _k : positiveName }), id: getUniqId(), color: series.positiveColor || positiveColor, data: [] });
52
+ const negativeName = (_o = (_m = (_l = series.legend) === null || _l === void 0 ? void 0 : _l.itemText) === null || _m === void 0 ? void 0 : _m.negative) !== null && _o !== void 0 ? _o : `${series.name} ↓`;
53
+ const negative = Object.assign(Object.assign({}, common), { name: negativeName, legend: Object.assign(Object.assign({}, common.legend), { groupId: getUniqId(), itemText: (_r = (_q = (_p = series.legend) === null || _p === void 0 ? void 0 : _p.itemText) === null || _q === void 0 ? void 0 : _q.negative) !== null && _r !== void 0 ? _r : negativeName }), id: getUniqId(), color: series.negativeColor || negativeColor, data: [] });
54
+ const totalsName = (_u = (_t = (_s = series.legend) === null || _s === void 0 ? void 0 : _s.itemText) === null || _t === void 0 ? void 0 : _t.totals) !== null && _u !== void 0 ? _u : series.name;
55
+ const totals = Object.assign(Object.assign({}, common), { name: totalsName, legend: Object.assign(Object.assign({}, common.legend), { groupId: getUniqId(), itemText: (_x = (_w = (_v = series.legend) === null || _v === void 0 ? void 0 : _v.itemText) === null || _w === void 0 ? void 0 : _w.totals) !== null && _x !== void 0 ? _x : totalsName }), id: getUniqId(), data: [] });
51
56
  const preparedData = prepareSeriesData(series);
52
57
  preparedData.forEach((d, index) => {
53
58
  var _a;
@@ -35,10 +35,12 @@ export type PreparedLegend = Required<Omit<ChartLegend, 'title' | 'colorScale'>>
35
35
  };
36
36
  };
37
37
  export type OnLegendItemClick = (data: {
38
+ id: string;
38
39
  name: string;
39
40
  metaKey: boolean;
40
41
  }) => void;
41
42
  export type LegendItem = {
43
+ id: string;
42
44
  color: string;
43
45
  height: number;
44
46
  name: string;
@@ -72,6 +74,8 @@ type BasePreparedSeries = {
72
74
  id: string;
73
75
  visible: boolean;
74
76
  legend: {
77
+ groupId: string;
78
+ itemText: string;
75
79
  enabled: boolean;
76
80
  symbol: PreparedLegendSymbol;
77
81
  };
@@ -228,6 +232,7 @@ export type PreparedAreaSeries = {
228
232
  stackId: string;
229
233
  lineWidth: number;
230
234
  opacity: number;
235
+ nullMode: AreaSeries['nullMode'];
231
236
  dataLabels: {
232
237
  enabled: boolean;
233
238
  style: BaseTextStyle;
@@ -1,7 +1,11 @@
1
1
  import { SymbolType } from '../../constants';
2
- import type { ChartSeries } from '../../types';
3
- import type { PreparedLegendSymbol, PreparedSeries, StackedSeries } from './types';
2
+ import type { RectLegendSymbolOptions } from '../../types';
3
+ import type { PathLegendSymbol, PreparedLegendSymbol, PreparedSeries, StackedSeries } from './types';
4
4
  export declare const getActiveLegendItems: (series: PreparedSeries[]) => string[];
5
5
  export declare const getAllLegendItems: (series: PreparedSeries[]) => string[];
6
- export declare function prepareLegendSymbol(series: ChartSeries, symbolType?: `${SymbolType}`): PreparedLegendSymbol;
6
+ export declare function prepareLegendSymbol(series: {
7
+ legend?: {
8
+ symbol?: RectLegendSymbolOptions | PathLegendSymbol;
9
+ };
10
+ }, symbolType?: `${SymbolType}`): PreparedLegendSymbol;
7
11
  export declare function getSeriesStackId(series: StackedSeries): string;
@@ -5,13 +5,13 @@ import { DEFAULT_LEGEND_SYMBOL_PADDING, DEFAULT_LEGEND_SYMBOL_SIZE } from './con
5
5
  export const getActiveLegendItems = (series) => {
6
6
  return series.reduce((acc, s) => {
7
7
  if (s.legend.enabled && s.visible) {
8
- acc.push(s.name);
8
+ acc.push(s.legend.groupId);
9
9
  }
10
10
  return acc;
11
11
  }, []);
12
12
  };
13
13
  export const getAllLegendItems = (series) => {
14
- return series.map((s) => s.name);
14
+ return series.map((s) => s.legend.groupId);
15
15
  };
16
16
  export function prepareLegendSymbol(series, symbolType) {
17
17
  var _a;
@@ -133,6 +133,9 @@ export const prepareAreaData = async (args) => {
133
133
  if (yPointValue !== null) {
134
134
  accumulatedYValues.set(x, yMin - yPointValue);
135
135
  }
136
+ if (s.nullMode === 'connect' && yPointValue === null) {
137
+ return pointsAcc;
138
+ }
136
139
  pointsAcc.push({
137
140
  y0: yAxisTop + yMin - accumulatedYValue,
138
141
  x: xValue,