@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
@@ -1,8 +1,9 @@
1
- import { ascending, descending, max, sort } from 'd3';
1
+ import { ascending, descending, sort } from 'd3';
2
2
  import get from 'lodash/get';
3
3
  import { getDataCategoryValue, getLabelsSize } from '../../../utils';
4
4
  import { getFormattedValue } from '../../../utils/chart/format';
5
- import { MIN_BAR_GAP, MIN_BAR_GROUP_GAP, MIN_BAR_WIDTH } from '../../constants';
5
+ import { getSeriesStackId } from '../../useSeries/utils';
6
+ import { getBarXLayout } from '../../utils/bar-x';
6
7
  const isSeriesDataValid = (d) => d.y !== null;
7
8
  async function getLabelData(d) {
8
9
  if (!d.series.dataLabels.enabled) {
@@ -33,13 +34,10 @@ async function getLabelData(d) {
33
34
  }
34
35
  // eslint-disable-next-line complexity
35
36
  export const prepareBarXData = async (args) => {
36
- var _a, _b, _c;
37
+ var _a, _b, _c, _d;
37
38
  const { series, seriesOptions, xAxis, xScale, yAxis, yScale, boundsHeight: plotHeight, split, } = args;
38
39
  const stackGap = seriesOptions['bar-x'].stackGap;
39
- const categories = get(xAxis, 'categories', []);
40
- const barMaxWidth = get(seriesOptions, 'bar-x.barMaxWidth');
41
- const barPadding = get(seriesOptions, 'bar-x.barPadding');
42
- const groupPadding = get(seriesOptions, 'bar-x.groupPadding');
40
+ const categories = (_a = xAxis === null || xAxis === void 0 ? void 0 : xAxis.categories) !== null && _a !== void 0 ? _a : [];
43
41
  const sortingOptions = get(seriesOptions, 'bar-x.dataSorting');
44
42
  const comparator = (sortingOptions === null || sortingOptions === void 0 ? void 0 : sortingOptions.direction) === 'desc' ? descending : ascending;
45
43
  const sortKey = (() => {
@@ -70,51 +68,31 @@ export const prepareBarXData = async (args) => {
70
68
  if (!isSeriesDataValid(d)) {
71
69
  return;
72
70
  }
73
- const xValue = xAxis.type === 'category'
71
+ const key = xAxis.type === 'category'
74
72
  ? getDataCategoryValue({ axisDirection: 'x', categories, data: d })
75
73
  : d.x;
76
- if (xValue) {
77
- if (!data[xValue]) {
78
- data[xValue] = {};
74
+ if (key !== undefined) {
75
+ if (!data[key]) {
76
+ data[key] = {};
79
77
  }
80
- const xGroup = data[xValue];
81
- if (!xGroup[s.stackId]) {
82
- xGroup[s.stackId] = [];
78
+ const stackId = getSeriesStackId(s);
79
+ if (!data[key][stackId]) {
80
+ data[key][stackId] = [];
83
81
  }
84
- xGroup[s.stackId].push({ data: d, series: s });
82
+ data[key][stackId].push({ data: d, series: s });
85
83
  }
86
84
  });
87
85
  });
88
- let bandWidth = Infinity;
89
- if (xAxis.type === 'category') {
90
- const xBandScale = xScale;
91
- bandWidth = xBandScale.bandwidth();
92
- }
93
- else {
94
- const xLinearScale = xScale;
95
- const xValues = series.reduce((acc, s) => {
96
- s.data.forEach((dataItem) => acc.push(Number(dataItem.x)));
97
- return acc;
98
- }, []);
99
- xValues.sort().forEach((xValue, index) => {
100
- if (index > 0 && xValue !== xValues[index - 1]) {
101
- const dist = xLinearScale(xValue) - xLinearScale(xValues[index - 1]);
102
- if (dist < bandWidth) {
103
- bandWidth = dist;
104
- }
105
- }
106
- });
107
- }
108
86
  const result = [];
109
87
  const plotIndexes = Array.from(dataByPlots.keys());
110
88
  for (let plotDataIndex = 0; plotDataIndex < plotIndexes.length; plotDataIndex++) {
111
- const data = (_a = dataByPlots.get(plotIndexes[plotDataIndex])) !== null && _a !== void 0 ? _a : {};
112
- const maxGroupSize = max(Object.values(data), (d) => Object.values(d).length) || 1;
113
- const groupGap = Math.max(bandWidth * groupPadding, MIN_BAR_GROUP_GAP);
114
- const groupWidth = bandWidth - groupGap;
115
- const rectGap = Math.max(bandWidth * barPadding, MIN_BAR_GAP);
116
- const rectWidth = Math.max(MIN_BAR_WIDTH, Math.min(groupWidth / maxGroupSize - rectGap, barMaxWidth));
89
+ const data = (_b = dataByPlots.get(plotIndexes[plotDataIndex])) !== null && _b !== void 0 ? _b : {};
117
90
  const groupedData = Object.entries(data);
91
+ const { bandSize, barGap: rectGap, barSize: rectWidth, } = getBarXLayout({
92
+ groupedData: data,
93
+ seriesOptions,
94
+ scale: xScale,
95
+ });
118
96
  for (let groupedDataIndex = 0; groupedDataIndex < groupedData.length; groupedDataIndex++) {
119
97
  const [xValue, val] = groupedData[groupedDataIndex];
120
98
  const stacks = Object.values(val);
@@ -134,7 +112,7 @@ export const prepareBarXData = async (args) => {
134
112
  continue;
135
113
  }
136
114
  const seriesYAxis = yAxis[yAxisIndex];
137
- const yAxisTop = ((_b = split.plots[seriesYAxis.plotIndex]) === null || _b === void 0 ? void 0 : _b.top) || 0;
115
+ const yAxisTop = ((_c = split.plots[seriesYAxis.plotIndex]) === null || _c === void 0 ? void 0 : _c.top) || 0;
138
116
  let xCenter;
139
117
  if (xAxis.type === 'category') {
140
118
  const xBandScale = xScale;
@@ -142,14 +120,14 @@ export const prepareBarXData = async (args) => {
142
120
  if (xBandScaleDomain.indexOf(xValue) === -1) {
143
121
  continue;
144
122
  }
145
- xCenter = (xBandScale(xValue) || 0) + xBandScale.bandwidth() / 2;
123
+ xCenter = (xBandScale(xValue) || 0) + bandSize / 2;
146
124
  }
147
125
  else {
148
- const xLinearScale = xScale;
149
- xCenter = xLinearScale(Number(xValue));
126
+ const scale = xScale;
127
+ xCenter = scale(Number(xValue));
150
128
  }
151
129
  const x = xCenter - currentGroupWidth / 2 + (rectWidth + rectGap) * groupItemIndex;
152
- const yDataValue = ((_c = yValue.data.y) !== null && _c !== void 0 ? _c : 0);
130
+ const yDataValue = ((_d = yValue.data.y) !== null && _d !== void 0 ? _d : 0);
153
131
  const y = seriesYScale(yDataValue);
154
132
  const base = seriesYScale(0);
155
133
  const isLastStackItem = yValueIndex === sortedData.length - 1;
@@ -17,7 +17,6 @@ export async function prepareBarYData(args) {
17
17
  htmlElements: [],
18
18
  };
19
19
  }
20
- const yScaleRange = yLinearScale.range();
21
20
  const sortingOptions = get(seriesOptions, 'bar-y.dataSorting');
22
21
  const comparator = (sortingOptions === null || sortingOptions === void 0 ? void 0 : sortingOptions.direction) === 'desc' ? descending : ascending;
23
22
  const sortKey = (() => {
@@ -34,11 +33,9 @@ export async function prepareBarYData(args) {
34
33
  }
35
34
  })();
36
35
  const groupedData = groupBarYDataByYValue(series, yAxis);
37
- const plotHeight = Math.abs(yScaleRange[0] - yScaleRange[1]);
38
36
  const { bandSize, barGap, barSize } = getBarYLayout({
39
37
  groupedData,
40
38
  seriesOptions,
41
- plotHeight,
42
39
  scale: yScale,
43
40
  });
44
41
  const result = [];
@@ -86,7 +86,10 @@ export const prepareWaterfallData = async (args) => {
86
86
  if (typeof item.data.y !== 'number' && !item.data.total) {
87
87
  continue;
88
88
  }
89
- if (!item.data.total) {
89
+ if (item.data.total) {
90
+ item.data.y = totalValue;
91
+ }
92
+ else {
90
93
  totalValue += Number(item.data.y);
91
94
  }
92
95
  const prevPoint = result[result.length - 1];
@@ -1,14 +1,15 @@
1
1
  import type { BarXSeries, BarXSeriesData } from '../../types';
2
2
  import type { PreparedXAxis } from '../useAxis/types';
3
+ import type { ChartScale } from '../useAxisScales';
3
4
  import type { PreparedBarXSeries, PreparedSeriesOptions } from '../useSeries/types';
4
5
  export declare function groupBarXDataByXValue<T extends BarXSeries | PreparedBarXSeries>(series: T[], xAxis: PreparedXAxis): Record<string | number, Record<string, {
5
6
  data: BarXSeriesData;
6
7
  series: T;
7
8
  }[]>>;
8
- export declare function getBarXLayoutForNumericScale(args: {
9
- plotWidth: number;
9
+ export declare function getBarXLayout(args: {
10
10
  seriesOptions: PreparedSeriesOptions;
11
11
  groupedData: ReturnType<typeof groupBarXDataByXValue>;
12
+ scale: ChartScale | undefined;
12
13
  }): {
13
14
  bandSize: number;
14
15
  barGap: number;
@@ -1,7 +1,9 @@
1
+ import { max } from 'd3';
1
2
  import get from 'lodash/get';
2
3
  import { getDataCategoryValue } from '../../utils';
3
4
  import { MIN_BAR_GAP, MIN_BAR_GROUP_GAP, MIN_BAR_WIDTH } from '../constants';
4
5
  import { getSeriesStackId } from '../useSeries/utils';
6
+ import { getBandSize } from './get-band-size';
5
7
  export function groupBarXDataByXValue(series, xAxis) {
6
8
  const data = {};
7
9
  series.forEach((s) => {
@@ -25,17 +27,17 @@ export function groupBarXDataByXValue(series, xAxis) {
25
27
  });
26
28
  return data;
27
29
  }
28
- export function getBarXLayoutForNumericScale(args) {
29
- const { plotWidth, groupedData, seriesOptions } = args;
30
+ export function getBarXLayout(args) {
31
+ const { groupedData, seriesOptions, scale } = args;
30
32
  const barMaxWidth = get(seriesOptions, 'bar-x.barMaxWidth');
31
33
  const barPadding = get(seriesOptions, 'bar-x.barPadding');
32
34
  const groupPadding = get(seriesOptions, 'bar-x.groupPadding');
33
- const groups = Object.values(groupedData);
34
- const maxGroupItemCount = groups.reduce((acc, items) => Math.max(acc, Object.keys(items).length), 0);
35
- const bandSize = plotWidth / groups.length;
35
+ const domain = Object.keys(groupedData);
36
+ const bandSize = getBandSize({ domain, scale: scale });
36
37
  const groupGap = Math.max(bandSize * groupPadding, MIN_BAR_GROUP_GAP);
38
+ const maxGroupSize = max(Object.values(groupedData), (d) => Object.values(d).length) || 1;
37
39
  const groupSize = bandSize - groupGap;
38
40
  const barGap = Math.max(bandSize * barPadding, MIN_BAR_GAP);
39
- const barSize = Math.max(MIN_BAR_WIDTH, Math.min((groupSize - barGap) / maxGroupItemCount, barMaxWidth));
41
+ const barSize = Math.max(MIN_BAR_WIDTH, Math.min(groupSize / maxGroupSize - barGap, barMaxWidth));
40
42
  return { bandSize, barGap, barSize };
41
43
  }
@@ -13,7 +13,6 @@ export declare function groupBarYDataByYValue<T extends BarYSeries | PreparedBar
13
13
  series: T;
14
14
  }[]>>;
15
15
  export declare function getBarYLayout(args: {
16
- plotHeight: number;
17
16
  seriesOptions: PreparedSeriesOptions;
18
17
  groupedData: ReturnType<typeof groupBarYDataByYValue>;
19
18
  scale: ChartScale | undefined;
@@ -8,13 +8,13 @@ const isSeriesDataValid = (d) => d.x !== null;
8
8
  export function groupBarYDataByYValue(series, yAxis) {
9
9
  const data = {};
10
10
  series.forEach((s) => {
11
+ const axisIndex = get(s, 'yAxis', 0);
12
+ const seriesYAxis = yAxis[axisIndex];
13
+ const categories = get(seriesYAxis, 'categories', []);
11
14
  s.data.forEach((d) => {
12
15
  if (!isSeriesDataValid(d)) {
13
16
  return;
14
17
  }
15
- const axisIndex = get(s, 'yAxis', 0);
16
- const seriesYAxis = yAxis[axisIndex];
17
- const categories = get(seriesYAxis, 'categories', []);
18
18
  const key = seriesYAxis.type === 'category'
19
19
  ? getDataCategoryValue({ axisDirection: 'y', categories, data: d })
20
20
  : d.y;
@@ -1,7 +1,7 @@
1
1
  import type { SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  import type { PointMarkerOptions } from './marker';
6
6
  import type { ChartSeriesRangeSliderOptions } from './series';
7
7
  export interface AreaSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
@@ -67,7 +67,7 @@ export interface AreaSeries<T = MeaningfulAny> extends BaseSeries {
67
67
  * */
68
68
  lineWidth?: number;
69
69
  /** Individual series legend options. Has higher priority than legend options in widget data */
70
- legend?: ChartLegend & {
70
+ legend?: BaseSeriesLegend & {
71
71
  symbol?: RectLegendSymbolOptions;
72
72
  };
73
73
  /** Options for the point markers of line in area series */
@@ -145,6 +145,7 @@ export interface ChartAxis {
145
145
  };
146
146
  /** Padding of the max value relative to the length of the axis.
147
147
  * A padding of 0.05 will make a 100px axis 5px longer.
148
+ * Does not apply for series with data normalization along on a specific axis (stacking: 'percent').
148
149
  * @default 0.05 for Y axis, 0.01 for X axis
149
150
  */
150
151
  maxPadding?: number;
@@ -1,7 +1,7 @@
1
1
  import type { SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  import type { ChartSeriesOptions, ChartSeriesRangeSliderOptions } from './series';
6
6
  export interface BarXSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
7
7
  /**
@@ -64,7 +64,7 @@ export interface BarXSeries<T = MeaningfulAny> extends BaseSeries {
64
64
  inside?: boolean;
65
65
  };
66
66
  /** Individual series legend options. Has higher priority than legend options in widget data */
67
- legend?: ChartLegend & {
67
+ legend?: BaseSeriesLegend & {
68
68
  symbol?: RectLegendSymbolOptions;
69
69
  };
70
70
  /** Y-axis index (when using two axes) */
@@ -1,7 +1,7 @@
1
1
  import type { SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  export interface BarYSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  /**
7
7
  * The `x` value of the bar. Depending on the context , it may represents:
@@ -68,7 +68,7 @@ export interface BarYSeries<T = MeaningfulAny> extends BaseSeries {
68
68
  inside?: boolean;
69
69
  };
70
70
  /** Individual series legend options. Has higher priority than legend options in widget data */
71
- legend?: ChartLegend & {
71
+ legend?: BaseSeriesLegend & {
72
72
  symbol?: RectLegendSymbolOptions;
73
73
  };
74
74
  /**
@@ -1,5 +1,6 @@
1
1
  import type { FormatNumberOptions } from '../formatter';
2
2
  import type { MeaningfulAny } from '../misc';
3
+ import type { ChartLegendItem } from './legend';
3
4
  type NumberFormat = {
4
5
  type: 'number';
5
6
  } & FormatNumberOptions;
@@ -67,6 +68,14 @@ export interface BaseSeriesData<T = MeaningfulAny> {
67
68
  /** Individual color for the data chunk (point in scatter, segment in pie, bar etc) */
68
69
  color?: string;
69
70
  }
71
+ export interface BaseSeriesLegend extends ChartLegendItem {
72
+ /** For multiple series with the same groupId, only one label in the legend will be displayed.
73
+ * The legend element uses the name and symbol from the first series of the group.
74
+ */
75
+ groupId?: string;
76
+ /** The text is displayed in the legend instead of the series name. */
77
+ itemText?: string;
78
+ }
70
79
  export interface BaseTextStyle {
71
80
  fontSize: string;
72
81
  fontWeight?: string;
@@ -1,7 +1,7 @@
1
1
  import type { DashStyle, SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseDataLabels, BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseDataLabels, BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { ChartLegendItem, RectLegendSymbolOptions } from './legend';
5
5
  export interface FunnelSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  /** The value of the funnel segment. */
7
7
  value: number;
@@ -9,6 +9,10 @@ export interface FunnelSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
9
9
  name: string;
10
10
  /** Initial data label of the funnel segment. If not specified, the value is used. */
11
11
  label?: string;
12
+ /** Individual series legend options. Has higher priority than legend options in series data */
13
+ legend?: BaseSeriesLegend & {
14
+ symbol?: RectLegendSymbolOptions;
15
+ };
12
16
  }
13
17
  export interface FunnelSeries<T = MeaningfulAny> extends Omit<BaseSeries, 'dataLabels'> {
14
18
  type: typeof SERIES_TYPE.Funnel;
@@ -17,10 +21,6 @@ export interface FunnelSeries<T = MeaningfulAny> extends Omit<BaseSeries, 'dataL
17
21
  name?: string;
18
22
  /** The color of the funnel series. */
19
23
  color?: string;
20
- /** Individual series legend options. Has higher priority than legend options in widget data */
21
- legend?: ChartLegend & {
22
- symbol?: RectLegendSymbolOptions;
23
- };
24
24
  /** Lines or areas connecting the funnel segments. */
25
25
  connectors?: {
26
26
  enabled?: boolean;
@@ -43,4 +43,8 @@ export interface FunnelSeries<T = MeaningfulAny> extends Omit<BaseSeries, 'dataL
43
43
  /** Horizontal alignment of the data labels. */
44
44
  align?: 'left' | 'center' | 'right';
45
45
  };
46
+ /** Individual series legend options. Has higher priority than legend options in widget data */
47
+ legend?: ChartLegendItem & {
48
+ symbol?: RectLegendSymbolOptions;
49
+ };
46
50
  }
@@ -1,7 +1,7 @@
1
1
  import type { SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  export interface HeatmapSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  /**
7
7
  * The `x` value of the heatmap cell. Depending on the context, it may represents:
@@ -31,7 +31,7 @@ export interface HeatmapSeries<T = MeaningfulAny> extends BaseSeries {
31
31
  color?: string;
32
32
  dataLabels?: BaseSeries['dataLabels'];
33
33
  /** Individual series legend options. Has higher priority than legend options in widget data */
34
- legend?: ChartLegend & {
34
+ legend?: BaseSeriesLegend & {
35
35
  symbol?: RectLegendSymbolOptions;
36
36
  };
37
37
  /**
@@ -1,6 +1,16 @@
1
1
  import type { BaseTextStyle } from './base';
2
- export interface ChartLegend {
2
+ export interface ChartLegendItem {
3
3
  enabled?: boolean;
4
+ /**
5
+ * Defines the pixel distance between each legend item
6
+ *
7
+ * @default 20
8
+ * */
9
+ itemDistance?: number;
10
+ /** CSS styles for each legend item */
11
+ itemStyle?: BaseTextStyle;
12
+ }
13
+ export interface ChartLegend extends ChartLegendItem {
4
14
  /**
5
15
  * Different types for different color schemes.
6
16
  * If the color scheme is continuous, a gradient legend will be drawn.
@@ -21,14 +31,6 @@ export interface ChartLegend {
21
31
  * @default center
22
32
  * */
23
33
  justifyContent?: 'start' | 'center';
24
- /**
25
- * Defines the pixel distance between each legend item
26
- *
27
- * @default 20
28
- * */
29
- itemDistance?: number;
30
- /** CSS styles for each legend item */
31
- itemStyle?: BaseTextStyle;
32
34
  /**
33
35
  * The space between the legend and the axis labels or chart area.
34
36
  *
@@ -64,7 +66,7 @@ export interface ChartLegend {
64
66
  *
65
67
  * @default 'bottom'
66
68
  * */
67
- position?: 'top' | 'bottom';
69
+ position?: 'top' | 'bottom' | 'left' | 'right';
68
70
  }
69
71
  export interface BaseLegendSymbol {
70
72
  /**
@@ -1,7 +1,7 @@
1
1
  import type { DashStyle, LineCap, SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  import type { PointMarkerOptions } from './marker';
6
6
  import type { ChartSeriesRangeSliderOptions } from './series';
7
7
  export interface LineSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
@@ -42,7 +42,7 @@ export interface LineSeries<T = MeaningfulAny> extends BaseSeries {
42
42
  * */
43
43
  lineWidth?: number;
44
44
  /** Individual series legend options. Has higher priority than legend options in widget data */
45
- legend?: ChartLegend & {
45
+ legend?: BaseSeriesLegend & {
46
46
  symbol?: RectLegendSymbolOptions;
47
47
  };
48
48
  /** Options for the point markers of line series */
@@ -1,8 +1,8 @@
1
1
  import type { BaseType } from 'd3';
2
2
  import type { SERIES_TYPE } from '../../constants';
3
3
  import type { MeaningfulAny } from '../misc';
4
- import type { BaseSeries, BaseSeriesData } from './base';
5
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
4
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
5
+ import type { ChartLegendItem, RectLegendSymbolOptions } from './legend';
6
6
  export interface PieSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
7
7
  /** The value of the pie segment. */
8
8
  value: number | null;
@@ -16,6 +16,10 @@ export interface PieSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
16
16
  opacity?: number;
17
17
  /** The individual radius of the pie segment. The default value is series.radius */
18
18
  radius?: string | number;
19
+ /** Individual series legend options. Has higher priority than legend options in series data */
20
+ legend?: BaseSeriesLegend & {
21
+ symbol?: RectLegendSymbolOptions;
22
+ };
19
23
  }
20
24
  export type ConnectorShape = 'straight-line' | 'polyline';
21
25
  export type ConnectorCurve = 'linear' | 'basic';
@@ -54,10 +58,6 @@ export interface PieSeries<T = MeaningfulAny> extends BaseSeries {
54
58
  * If not specified, the minimum radius is calculated as 30% of the height or width of the chart (the minimum value is taken) minus the halo effect.
55
59
  */
56
60
  minRadius?: string | number;
57
- /** Individual series legend options. Has higher priority than legend options in widget data */
58
- legend?: ChartLegend & {
59
- symbol?: RectLegendSymbolOptions;
60
- };
61
61
  dataLabels?: BaseSeries['dataLabels'] & {
62
62
  /**
63
63
  * The distance of the data label from the pie's edge.
@@ -85,6 +85,10 @@ export interface PieSeries<T = MeaningfulAny> extends BaseSeries {
85
85
  * */
86
86
  connectorCurve?: ConnectorCurve;
87
87
  };
88
+ /** Individual series legend options. Has higher priority than legend options in chart data */
89
+ legend?: ChartLegendItem & {
90
+ symbol?: RectLegendSymbolOptions;
91
+ };
88
92
  /**
89
93
  * Function for adding custom svg nodes for a series
90
94
  *
@@ -1,7 +1,7 @@
1
1
  import type { SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  import type { PointMarkerOptions } from './marker';
6
6
  export interface RadarSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
7
7
  /** The value of the radar point. */
@@ -42,7 +42,7 @@ export interface RadarSeries<T = MeaningfulAny> extends BaseSeries {
42
42
  */
43
43
  fillOpacity?: number;
44
44
  /** Individual series legend options. Has higher priority than legend options in widget data */
45
- legend?: ChartLegend & {
45
+ legend?: BaseSeriesLegend & {
46
46
  symbol?: RectLegendSymbolOptions;
47
47
  };
48
48
  /** Options for the point markers of line in radar series */
@@ -1,7 +1,7 @@
1
1
  import type { SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  export interface SankeySeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  name: string;
7
7
  color?: string;
@@ -16,7 +16,7 @@ export interface SankeySeries<T = MeaningfulAny> extends BaseSeries {
16
16
  name: string;
17
17
  data: SankeySeriesData<T>[];
18
18
  /** Individual series legend options. Has higher priority than legend options in widget data. */
19
- legend?: ChartLegend & {
19
+ legend?: BaseSeriesLegend & {
20
20
  symbol?: RectLegendSymbolOptions;
21
21
  };
22
22
  }
@@ -1,7 +1,7 @@
1
1
  import type { SERIES_TYPE, SymbolType } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  import type { ChartSeriesRangeSliderOptions } from './series';
6
6
  export interface ScatterSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
7
7
  /**
@@ -39,7 +39,7 @@ export interface ScatterSeries<T = MeaningfulAny> extends BaseSeries {
39
39
  /** A predefined shape or symbol for the dot */
40
40
  symbolType?: `${SymbolType}`;
41
41
  /** Individual series legend options. Has higher priority than legend options in widget data */
42
- legend?: ChartLegend & {
42
+ legend?: BaseSeriesLegend & {
43
43
  symbol?: RectLegendSymbolOptions;
44
44
  };
45
45
  /** Y-axis index (when using two axes) */
@@ -1,7 +1,7 @@
1
1
  import type { LayoutAlgorithm, SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
- import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
3
+ import type { BaseSeries, BaseSeriesData, BaseSeriesLegend } from './base';
4
+ import type { RectLegendSymbolOptions } from './legend';
5
5
  export interface TreemapSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  /** The name of the node (used in legend, tooltip etc). */
7
7
  name: string | string[];
@@ -23,7 +23,7 @@ export interface TreemapSeries<T = MeaningfulAny> extends BaseSeries {
23
23
  /** The main color of the series (hex, rgba). */
24
24
  color?: string;
25
25
  /** Individual series legend options. Has higher priority than legend options in widget data. */
26
- legend?: ChartLegend & {
26
+ legend?: BaseSeriesLegend & {
27
27
  symbol?: RectLegendSymbolOptions;
28
28
  };
29
29
  /** Set options on specific levels. Takes precedence over series options, but not point options. */
@@ -1,7 +1,7 @@
1
1
  import type { SERIES_TYPE } from '../../constants';
2
2
  import type { MeaningfulAny } from '../misc';
3
3
  import type { BaseSeries, BaseSeriesData } from './base';
4
- import type { ChartLegend, RectLegendSymbolOptions } from './legend';
4
+ import type { ChartLegendItem, RectLegendSymbolOptions } from './legend';
5
5
  export interface WaterfallSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
6
6
  /**
7
7
  * The `x` value. Depending on the context , it may represents:
@@ -34,7 +34,7 @@ export interface WaterfallSeries<T = MeaningfulAny> extends BaseSeries {
34
34
  /** The color used for negative values. If it is not specified, the general color of the series is used. */
35
35
  negativeColor?: string;
36
36
  /** Individual series legend options. Has higher priority than legend options in widget data. */
37
- legend?: ChartLegend & {
37
+ legend?: ChartLegendItem & {
38
38
  symbol?: RectLegendSymbolOptions;
39
39
  /** The legend item text for positive, negative values and totals. */
40
40
  itemText?: {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { Dispatch } from 'd3';
3
- import type { RangeSliderState, ZoomState } from '../../hooks';
3
+ import type { PreparedLegend, RangeSliderState, ZoomState } from '../../hooks';
4
4
  import type { ChartInnerProps } from './types';
5
5
  type Props = ChartInnerProps & {
6
6
  clipPathId: string;
@@ -35,7 +35,7 @@ export declare function useChartInnerProps(props: Props): {
35
35
  } | undefined;
36
36
  legendItems: never[] | import("../../hooks").LegendItem[][];
37
37
  preparedChart: import("../../hooks").PreparedChart;
38
- preparedLegend: import("../../hooks").PreparedLegend | null;
38
+ preparedLegend: PreparedLegend | null;
39
39
  preparedSeries: import("../../hooks").PreparedSeries[];
40
40
  preparedSeriesOptions: import("../../constants").SeriesOptionsDefaults;
41
41
  preparedSplit: import("../../hooks").PreparedSplit;
@@ -52,7 +52,7 @@ export declare function useChartInnerProps(props: Props): {
52
52
  xScale: import("../../hooks").ChartScale | undefined;
53
53
  yAxis: (Omit<import("../..").ChartAxis, "type" | "labels" | "plotLines" | "plotBands"> & {
54
54
  type: import("../..").ChartAxisType;
55
- labels: Omit<import("../..").ChartAxisLabels, "enabled" | "style" | "padding" | "autoRotation"> & Required<Pick<import("../..").ChartAxisLabels, "enabled" | "html" | "padding" | "margin" | "rotation">> & {
55
+ labels: Omit<import("../..").ChartAxisLabels, "enabled" | "style" | "padding" | "autoRotation"> & Required<Pick<import("../..").ChartAxisLabels, "margin" | "html" | "enabled" | "padding" | "rotation">> & {
56
56
  style: import("../..").BaseTextStyle;
57
57
  rotation: number;
58
58
  height: number;