@fluentui/react-charts 9.2.0 → 9.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 +38 -3
- package/dist/index.d.ts +84 -5
- package/lib/ChartTable.js +1 -0
- package/lib/ChartTable.js.map +1 -0
- package/lib/components/AreaChart/AreaChart.js.map +1 -1
- package/lib/components/ChartTable/ChartTable.js +57 -0
- package/lib/components/ChartTable/ChartTable.js.map +1 -0
- package/lib/components/ChartTable/ChartTable.types.js +1 -0
- package/lib/components/ChartTable/ChartTable.types.js.map +1 -0
- package/lib/components/ChartTable/index.js +3 -0
- package/lib/components/ChartTable/index.js.map +1 -0
- package/lib/components/ChartTable/useChartTableStyles.styles.js +93 -0
- package/lib/components/ChartTable/useChartTableStyles.styles.js.map +1 -0
- package/lib/components/ChartTable/useChartTableStyles.styles.raw.js +55 -0
- package/lib/components/ChartTable/useChartTableStyles.styles.raw.js.map +1 -0
- package/lib/components/CommonComponents/CartesianChart.js +110 -81
- package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib/components/CommonComponents/ChartPopover.types.js.map +1 -1
- package/lib/components/DeclarativeChart/DeclarativeChart.js +20 -10
- package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib/components/DeclarativeChart/PlotlyColorAdapter.js +95 -0
- package/lib/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -0
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +204 -87
- package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.js.map +1 -1
- package/lib/components/DonutChart/DonutChart.types.js.map +1 -1
- package/lib/components/DonutChart/Pie/Pie.js.map +1 -1
- package/lib/components/FunnelChart/FunnelChart.js.map +1 -1
- package/lib/components/GanttChart/GanttChart.js.map +1 -1
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +161 -141
- package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -1
- package/lib/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -1
- package/lib/components/HorizontalBarChart/HorizontalBarChart.types.js.map +1 -1
- package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib/components/Legends/Legends.js.map +1 -1
- package/lib/components/Legends/OverflowMenu.js.map +1 -1
- package/lib/components/LineChart/LineChart.js.map +1 -1
- package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib/components/VerticalBarChart/VerticalBarChart.js +12 -11
- package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +57 -51
- package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/types/DataPoint.js.map +1 -1
- package/lib/utilities/FocusableTooltipText.js.map +1 -1
- package/lib/utilities/utilities.js +26 -37
- package/lib/utilities/utilities.js.map +1 -1
- package/lib/utilities/vbc-utils.js +24 -0
- package/lib/utilities/vbc-utils.js.map +1 -1
- package/lib-commonjs/ChartTable.js +6 -0
- package/lib-commonjs/ChartTable.js.map +1 -0
- package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
- package/lib-commonjs/components/ChartTable/ChartTable.js +68 -0
- package/lib-commonjs/components/ChartTable/ChartTable.js.map +1 -0
- package/lib-commonjs/components/ChartTable/ChartTable.types.js +6 -0
- package/lib-commonjs/components/ChartTable/ChartTable.types.js.map +1 -0
- package/lib-commonjs/components/ChartTable/index.js +8 -0
- package/lib-commonjs/components/ChartTable/index.js.map +1 -0
- package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.js +196 -0
- package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.js.map +1 -0
- package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.raw.js +69 -0
- package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.raw.js.map +1 -0
- package/lib-commonjs/components/CommonComponents/CartesianChart.js +109 -80
- package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
- package/lib-commonjs/components/CommonComponents/ChartPopover.types.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +19 -9
- package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
- package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js +120 -0
- package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -0
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +204 -87
- package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
- package/lib-commonjs/components/DonutChart/DonutChart.types.js.map +1 -1
- package/lib-commonjs/components/DonutChart/Pie/Pie.js.map +1 -1
- package/lib-commonjs/components/FunnelChart/FunnelChart.js.map +1 -1
- package/lib-commonjs/components/GanttChart/GanttChart.js.map +1 -1
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +159 -139
- package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.types.js.map +1 -1
- package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
- package/lib-commonjs/components/Legends/Legends.js.map +1 -1
- package/lib-commonjs/components/Legends/OverflowMenu.js.map +1 -1
- package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
- package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +11 -10
- package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +56 -50
- package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
- package/lib-commonjs/index.js +1 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types/DataPoint.js.map +1 -1
- package/lib-commonjs/utilities/FocusableTooltipText.js.map +1 -1
- package/lib-commonjs/utilities/utilities.js +29 -37
- package/lib-commonjs/utilities/utilities.js.map +1 -1
- package/lib-commonjs/utilities/vbc-utils.js +27 -0
- package/lib-commonjs/utilities/vbc-utils.js.map +1 -1
- package/package.json +9 -9
|
@@ -20,9 +20,6 @@ const _index1 = require("../../index");
|
|
|
20
20
|
const _imageexportutils = require("../../utilities/image-export-utils");
|
|
21
21
|
const MIN_DOMAIN_MARGIN = 8;
|
|
22
22
|
const X1_INNER_PADDING = 0.1;
|
|
23
|
-
// x1_inner_padding = space_between_bars / (space_between_bars + bar_width)
|
|
24
|
-
// => space_between_bars = (x1_inner_padding / (1 - x1_inner_padding)) * bar_width
|
|
25
|
-
/** Rate at which the space between the bars in a group changes wrt the bar width */ const BAR_GAP_RATE = X1_INNER_PADDING / (1 - X1_INNER_PADDING);
|
|
26
23
|
const VERTICAL_BAR_GAP = 1;
|
|
27
24
|
const MIN_BAR_HEIGHT = 1;
|
|
28
25
|
const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
@@ -33,7 +30,6 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
33
30
|
const _emptyChartId = (0, _reactutilities.useId)('_GVBC_empty');
|
|
34
31
|
const _useRtl = (0, _index.useRtl)();
|
|
35
32
|
let _domainMargin = MIN_DOMAIN_MARGIN;
|
|
36
|
-
let _keys = [];
|
|
37
33
|
let _xAxisLabels = [];
|
|
38
34
|
let _datasetForBars = [];
|
|
39
35
|
let _margins = {
|
|
@@ -43,13 +39,14 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
43
39
|
left: 0
|
|
44
40
|
};
|
|
45
41
|
let _groupedVerticalBarGraph = [];
|
|
46
|
-
let _refArray = [];
|
|
47
42
|
let _yMax = 0;
|
|
48
43
|
let _calloutAnchorPoint = null;
|
|
49
44
|
let _barWidth = 0;
|
|
50
45
|
let _groupWidth = 0;
|
|
51
46
|
let _xAxisInnerPadding = 0;
|
|
52
47
|
let _xAxisOuterPadding = 0;
|
|
48
|
+
let _legends = [];
|
|
49
|
+
let _legendColorMap = {};
|
|
53
50
|
const cartesianChartRef = _react.useRef(null);
|
|
54
51
|
const Y_ORIGIN = 0;
|
|
55
52
|
const _legendsRef = _react.useRef(null);
|
|
@@ -93,44 +90,53 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
93
90
|
_barWidth = (0, _index.getBarWidth)(props.barWidth, props.maxBarWidth);
|
|
94
91
|
// x0_inner_padding = space_between_groups / (space_between_groups + group_width)
|
|
95
92
|
// space_between_groups = 2 * bar_width
|
|
96
|
-
// group_width =
|
|
97
|
-
_xAxisInnerPadding = (0, _index.getScalePadding)(props.xAxisInnerPadding, undefined, 2 / (2 +
|
|
93
|
+
// group_width = _legends.length * bar_width + (_legends.length - 1) * space_between_bars
|
|
94
|
+
_xAxisInnerPadding = (0, _index.getScalePadding)(props.xAxisInnerPadding, undefined, 2 / (2 + (0, _index.calcTotalBandUnits)(_legends.length, X1_INNER_PADDING)));
|
|
98
95
|
_xAxisOuterPadding = (0, _index.getScalePadding)(props.xAxisOuterPadding);
|
|
99
96
|
};
|
|
100
97
|
const _createDataset = (points)=>{
|
|
101
98
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
99
|
const datasetForBars = [];
|
|
103
|
-
const dataset = [];
|
|
104
100
|
points.forEach((point, index)=>{
|
|
105
|
-
const singleDatasetPoint = {};
|
|
106
101
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
102
|
const singleDatasetPointForBars = {};
|
|
108
|
-
const
|
|
109
|
-
point.series.forEach((seriesPoint
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
const legendToBarPoint = {};
|
|
104
|
+
point.series.forEach((seriesPoint)=>{
|
|
105
|
+
if (!singleDatasetPointForBars[seriesPoint.legend]) {
|
|
106
|
+
singleDatasetPointForBars[seriesPoint.legend] = [
|
|
107
|
+
{
|
|
108
|
+
...seriesPoint
|
|
109
|
+
}
|
|
110
|
+
];
|
|
111
|
+
legendToBarPoint[seriesPoint.legend] = {
|
|
112
|
+
...seriesPoint
|
|
113
|
+
};
|
|
114
|
+
} else {
|
|
115
|
+
singleDatasetPointForBars[seriesPoint.legend].push({
|
|
116
|
+
...seriesPoint
|
|
117
|
+
});
|
|
118
|
+
legendToBarPoint[seriesPoint.legend].data += seriesPoint.data;
|
|
119
|
+
}
|
|
115
120
|
});
|
|
116
121
|
singleDatasetPointForBars.xAxisPoint = point.name;
|
|
117
122
|
singleDatasetPointForBars.indexNum = index;
|
|
118
|
-
singleDatasetPointForBars.groupSeries =
|
|
123
|
+
singleDatasetPointForBars.groupSeries = Object.values(legendToBarPoint);
|
|
119
124
|
singleDatasetPointForBars.stackCallOutAccessibilityData = point.stackCallOutAccessibilityData;
|
|
120
125
|
datasetForBars.push(singleDatasetPointForBars);
|
|
121
|
-
dataset.push(singleDatasetPoint);
|
|
122
126
|
});
|
|
123
127
|
return datasetForBars;
|
|
124
128
|
};
|
|
125
129
|
const _createDataSetOfGVBC = (points)=>{
|
|
126
|
-
const
|
|
130
|
+
const legends = new Set();
|
|
127
131
|
const xAxisLabels = points.map((singlePoint)=>singlePoint.name);
|
|
128
|
-
points
|
|
129
|
-
|
|
132
|
+
points.forEach((point)=>{
|
|
133
|
+
point.series.forEach((seriesPoint)=>{
|
|
134
|
+
legends.add(seriesPoint.legend);
|
|
135
|
+
});
|
|
130
136
|
});
|
|
131
137
|
const datasetForBars = _createDataset(points);
|
|
132
138
|
return {
|
|
133
|
-
|
|
139
|
+
legends: Array.from(legends),
|
|
134
140
|
xAxisLabels,
|
|
135
141
|
datasetForBars
|
|
136
142
|
};
|
|
@@ -146,36 +152,22 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
146
152
|
props.legendProps.onChange(selectedLegends, event, currentLegend);
|
|
147
153
|
}
|
|
148
154
|
};
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
149
156
|
const _getLegendData = (points)=>{
|
|
150
|
-
const data = points;
|
|
151
|
-
const defaultPalette = [
|
|
152
|
-
(0, _index1.getColorFromToken)(_index1.DataVizPalette.color1),
|
|
153
|
-
(0, _index1.getColorFromToken)(_index1.DataVizPalette.color2),
|
|
154
|
-
(0, _index1.getColorFromToken)(_index1.DataVizPalette.color3),
|
|
155
|
-
(0, _index1.getColorFromToken)(_index1.DataVizPalette.color4),
|
|
156
|
-
(0, _index1.getColorFromToken)(_index1.DataVizPalette.color5)
|
|
157
|
-
];
|
|
158
157
|
const actions = [];
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
158
|
+
_legends.forEach((legendTitle)=>{
|
|
159
|
+
const legend = {
|
|
160
|
+
title: legendTitle,
|
|
161
|
+
color: _legendColorMap[legendTitle][0],
|
|
162
|
+
hoverAction: ()=>{
|
|
163
|
+
_handleChartMouseLeave();
|
|
164
|
+
_onLegendHover(legendTitle);
|
|
165
|
+
},
|
|
166
|
+
onMouseOutAction: ()=>{
|
|
167
|
+
_onLegendLeave();
|
|
165
168
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
color,
|
|
169
|
-
hoverAction: ()=>{
|
|
170
|
-
_handleChartMouseLeave();
|
|
171
|
-
_onLegendHover(point.legend);
|
|
172
|
-
},
|
|
173
|
-
onMouseOutAction: ()=>{
|
|
174
|
-
_onLegendLeave();
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
actions.push(legend);
|
|
178
|
-
});
|
|
169
|
+
};
|
|
170
|
+
actions.push(legend);
|
|
179
171
|
});
|
|
180
172
|
return /*#__PURE__*/ _react.createElement(_index1.Legends, {
|
|
181
173
|
legends: actions,
|
|
@@ -186,13 +178,40 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
186
178
|
legendRef: _legendsRef
|
|
187
179
|
});
|
|
188
180
|
};
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
181
|
+
const _addDefaultColors = (data)=>{
|
|
182
|
+
_legendColorMap = {};
|
|
183
|
+
let colorIndex = 0;
|
|
184
|
+
var _data_map;
|
|
185
|
+
return (_data_map = data === null || data === void 0 ? void 0 : data.map((point)=>{
|
|
186
|
+
var _point_series;
|
|
187
|
+
var _point_series_map;
|
|
188
|
+
return {
|
|
189
|
+
...point,
|
|
190
|
+
series: (_point_series_map = (_point_series = point.series) === null || _point_series === void 0 ? void 0 : _point_series.map((seriesPoint)=>{
|
|
191
|
+
if (!_legendColorMap[seriesPoint.legend]) {
|
|
192
|
+
let startColor = seriesPoint.color ? seriesPoint.color : (0, _index.getNextColor)(colorIndex, 0);
|
|
193
|
+
let endColor = startColor;
|
|
194
|
+
_legendColorMap[seriesPoint.legend] = [
|
|
195
|
+
startColor,
|
|
196
|
+
endColor
|
|
197
|
+
];
|
|
198
|
+
colorIndex += 1;
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
...seriesPoint,
|
|
202
|
+
color: _legendColorMap[seriesPoint.legend][0]
|
|
203
|
+
};
|
|
204
|
+
})) !== null && _point_series_map !== void 0 ? _point_series_map : []
|
|
205
|
+
};
|
|
206
|
+
})) !== null && _data_map !== void 0 ? _data_map : [];
|
|
207
|
+
};
|
|
208
|
+
const points = _addDefaultColors(props.data);
|
|
209
|
+
const { legends, xAxisLabels, datasetForBars } = _createDataSetOfGVBC(points);
|
|
210
|
+
_legends = legends;
|
|
192
211
|
_xAxisLabels = xAxisLabels;
|
|
193
212
|
_datasetForBars = datasetForBars;
|
|
194
213
|
const _xAxisType = (0, _index.getTypeOfAxis)(points[0].name, true);
|
|
195
|
-
const
|
|
214
|
+
const legendBars = _getLegendData(points);
|
|
196
215
|
_adjustProps();
|
|
197
216
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Add commentMore actions
|
|
198
217
|
function _getMinMaxOfYAxis(datasetForBars, yAxisType, useSecondaryYScale) {
|
|
@@ -252,8 +271,8 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
252
271
|
const xScale0 = _createX0Scale(containerWidth);
|
|
253
272
|
// Setting the bar width here is safe because there are no dependencies earlier in the code
|
|
254
273
|
// that rely on the width of bars in vertical bar charts with string x-axis.
|
|
255
|
-
_barWidth = (0, _index.getBarWidth)(props.barWidth, props.maxBarWidth, xScale0.bandwidth()
|
|
256
|
-
_groupWidth = (
|
|
274
|
+
_barWidth = (0, _index.getBarWidth)(props.barWidth, props.maxBarWidth, (0, _index.calcBandwidth)(xScale0.bandwidth(), _legends.length, X1_INNER_PADDING));
|
|
275
|
+
_groupWidth = (0, _index.calcRequiredWidth)(_barWidth, _legends.length, X1_INNER_PADDING);
|
|
257
276
|
const xScale1 = _createX1Scale();
|
|
258
277
|
const allGroupsBars = [];
|
|
259
278
|
_datasetForBars.forEach((singleSet)=>{
|
|
@@ -264,10 +283,6 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
264
283
|
const _getMargins = (margins)=>{
|
|
265
284
|
_margins = margins;
|
|
266
285
|
};
|
|
267
|
-
const _getOpacity = (legendTitle)=>{
|
|
268
|
-
const opacity = _legendHighlighted(legendTitle) || _noLegendHighlighted() ? '' : '0.1';
|
|
269
|
-
return opacity;
|
|
270
|
-
};
|
|
271
286
|
function updatePosition(newX, newY) {
|
|
272
287
|
const threshold = 1; // Set a threshold for movement
|
|
273
288
|
const { x, y } = clickPosition;
|
|
@@ -304,93 +319,99 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
304
319
|
_calloutAnchorPoint = null;
|
|
305
320
|
setPopoverOpen(false);
|
|
306
321
|
};
|
|
307
|
-
const onBarFocus = (event, pointData, groupData
|
|
322
|
+
const onBarFocus = (event, pointData, groupData)=>{
|
|
308
323
|
let x = 0;
|
|
309
324
|
let y = 0;
|
|
310
325
|
const targetRect = event.target.getBoundingClientRect();
|
|
311
326
|
x = targetRect.left + targetRect.width / 2;
|
|
312
327
|
y = targetRect.top + targetRect.height / 2;
|
|
313
328
|
updatePosition(x, y);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
setYValueHover(groupData.groupSeries);
|
|
324
|
-
setHoverXValue(pointData.xAxisCalloutData);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
};
|
|
328
|
-
const _refCallback = (element, legendTitle, refIndexNumber)=>{
|
|
329
|
-
_refArray[refIndexNumber] = {
|
|
330
|
-
index: legendTitle,
|
|
331
|
-
refElement: element
|
|
332
|
-
};
|
|
329
|
+
setPopoverOpen(_noLegendHighlighted() || _legendHighlighted(pointData.legend));
|
|
330
|
+
setCalloutLegend(pointData.legend);
|
|
331
|
+
setDataForHoverCard(pointData.data);
|
|
332
|
+
setColor(pointData.color);
|
|
333
|
+
setXCalloutValue(pointData.xAxisCalloutData);
|
|
334
|
+
setYCalloutValue(pointData.yAxisCalloutData);
|
|
335
|
+
setCallOutAccessibilityData(props.isCalloutForStack ? groupData.stackCallOutAccessibilityData : pointData.callOutAccessibilityData);
|
|
336
|
+
setYValueHover(groupData.groupSeries);
|
|
337
|
+
setHoverXValue(pointData.xAxisCalloutData);
|
|
333
338
|
};
|
|
334
339
|
const _buildGraph = (singleSet, xScale0, xScale1, yScalePrimary, yScaleSecondary, containerHeight, xElement)=>{
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
335
341
|
const singleGroup = [];
|
|
342
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
336
343
|
const barLabelsForGroup = [];
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
344
|
+
// Get the actual legends present at this x-axis point
|
|
345
|
+
const presentLegends = Object.keys(singleSet).filter((key)=>key in _legendColorMap);
|
|
346
|
+
const effectiveGroupWidth = (0, _index.calcRequiredWidth)(_barWidth, presentLegends.length, X1_INNER_PADDING);
|
|
347
|
+
// For stacked bars, center the single bar group in the available space
|
|
348
|
+
// Instead of using the global legend position, use the local position within present legends
|
|
349
|
+
const localScale = (0, _d3scale.scaleBand)().domain(presentLegends).range(_useRtl ? [
|
|
350
|
+
effectiveGroupWidth,
|
|
351
|
+
0
|
|
352
|
+
] : [
|
|
353
|
+
0,
|
|
354
|
+
effectiveGroupWidth
|
|
355
|
+
]).paddingInner(X1_INNER_PADDING);
|
|
356
|
+
_legends.forEach((legendTitle, legendIndex)=>{
|
|
357
|
+
const barPoints = singleSet[legendTitle];
|
|
358
|
+
if (barPoints) {
|
|
359
|
+
const yBarScale = barPoints[0].useSecondaryYScale && yScaleSecondary ? yScaleSecondary : yScalePrimary;
|
|
360
|
+
var _localScale;
|
|
361
|
+
const xPoint = ((_localScale = localScale(legendTitle)) !== null && _localScale !== void 0 ? _localScale : 0) + (localScale.bandwidth() - _barWidth) / 2;
|
|
362
|
+
const isLegendActive = _legendHighlighted(legendTitle) || _noLegendHighlighted();
|
|
363
|
+
const barOpacity = isLegendActive ? '' : '0.1';
|
|
364
|
+
let barTotalValue = 0;
|
|
347
365
|
const yBaseline = yBarScale(Y_ORIGIN);
|
|
348
366
|
let yPositiveStart = yBaseline;
|
|
349
367
|
let yNegativeStart = yBaseline;
|
|
350
368
|
let yPoint = Y_ORIGIN;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
369
|
+
barPoints.forEach((pointData, pointIndex)=>{
|
|
370
|
+
if (!pointData.data) {
|
|
371
|
+
// Not rendering data with 0.
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const barGap = VERTICAL_BAR_GAP / 2 * (pointIndex > 0 ? 2 : 0);
|
|
375
|
+
const height = Math.max(yBarScale(Y_ORIGIN) - yBarScale(Math.abs(pointData.data)), MIN_BAR_HEIGHT);
|
|
376
|
+
const pointColor = pointData.color; // Use the color of the current point
|
|
377
|
+
if (pointData.data >= Y_ORIGIN) {
|
|
378
|
+
yPositiveStart -= height + barGap;
|
|
379
|
+
yPoint = yPositiveStart;
|
|
380
|
+
} else {
|
|
381
|
+
yPoint = yNegativeStart + barGap;
|
|
382
|
+
yNegativeStart = yPoint + height;
|
|
383
|
+
}
|
|
384
|
+
singleGroup.push(/*#__PURE__*/ _react.createElement("rect", {
|
|
385
|
+
key: `${singleSet.indexNum}-${legendIndex}-${pointIndex}`,
|
|
386
|
+
className: classes.opacityChangeOnHover,
|
|
387
|
+
height: height,
|
|
388
|
+
width: _barWidth,
|
|
389
|
+
x: xPoint,
|
|
390
|
+
y: yPoint,
|
|
391
|
+
opacity: barOpacity,
|
|
392
|
+
fill: pointColor,
|
|
393
|
+
rx: 0,
|
|
394
|
+
onMouseOver: (event)=>onBarHover(pointData, singleSet, event),
|
|
395
|
+
onMouseMove: (event)=>onBarHover(pointData, singleSet, event),
|
|
396
|
+
onMouseOut: _onBarLeave,
|
|
397
|
+
onFocus: (event)=>onBarFocus(event, pointData, singleSet),
|
|
398
|
+
onBlur: _onBarLeave,
|
|
399
|
+
onClick: pointData.onClick,
|
|
400
|
+
"aria-label": getAriaLabel(pointData, singleSet.xAxisPoint),
|
|
401
|
+
tabIndex: _legendHighlighted(pointData.legend) || _noLegendHighlighted() ? 0 : undefined,
|
|
402
|
+
role: "img"
|
|
403
|
+
}));
|
|
404
|
+
barTotalValue += pointData.data;
|
|
405
|
+
});
|
|
406
|
+
if (barTotalValue !== null && !props.hideLabels && _barWidth >= 16 && isLegendActive) {
|
|
386
407
|
barLabelsForGroup.push(/*#__PURE__*/ _react.createElement("text", {
|
|
387
|
-
key: `${singleSet.indexNum}-${
|
|
408
|
+
key: `${singleSet.indexNum}-${legendIndex}`,
|
|
388
409
|
x: xPoint + _barWidth / 2,
|
|
389
|
-
y:
|
|
410
|
+
y: barTotalValue >= Y_ORIGIN ? yPositiveStart - 6 : yNegativeStart + 12,
|
|
390
411
|
textAnchor: "middle",
|
|
391
412
|
className: classes.barLabel,
|
|
392
413
|
"aria-hidden": true
|
|
393
|
-
}, typeof props.yAxisTickFormat === 'function' ? props.yAxisTickFormat(
|
|
414
|
+
}, typeof props.yAxisTickFormat === 'function' ? props.yAxisTickFormat(barTotalValue) : (0, _index.formatScientificLimitWidth)(barTotalValue)));
|
|
394
415
|
}
|
|
395
416
|
}
|
|
396
417
|
});
|
|
@@ -410,7 +431,7 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
410
431
|
}
|
|
411
432
|
return /*#__PURE__*/ _react.createElement("g", {
|
|
412
433
|
key: singleSet.indexNum,
|
|
413
|
-
transform: `translate(${xScale0(singleSet.xAxisPoint) + (xScale0.bandwidth() -
|
|
434
|
+
transform: `translate(${xScale0(singleSet.xAxisPoint) + (xScale0.bandwidth() - effectiveGroupWidth) / 2}, 0)`
|
|
414
435
|
}, singleGroup, barLabelsForGroup);
|
|
415
436
|
};
|
|
416
437
|
// For grouped vertical bar chart, First need to define total scale (from start to end)
|
|
@@ -427,7 +448,7 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
427
448
|
};
|
|
428
449
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
429
450
|
const _createX1Scale = ()=>{
|
|
430
|
-
return (0, _d3scale.scaleBand)().domain(
|
|
451
|
+
return (0, _d3scale.scaleBand)().domain(_legends) // When there is only one group, xScale0 adds padding around it,
|
|
431
452
|
// causing the bandwidth to become smaller than the actual group width.
|
|
432
453
|
// So to render bars in the group correctly, use groupWidth instead of the generated scale bandwidth.
|
|
433
454
|
.range(_useRtl ? [
|
|
@@ -478,8 +499,7 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
478
499
|
return ((_point_callOutAccessibilityData = point.callOutAccessibilityData) === null || _point_callOutAccessibilityData === void 0 ? void 0 : _point_callOutAccessibilityData.ariaLabel) || `${xValue}. ${legend}, ${yValue}.`;
|
|
479
500
|
};
|
|
480
501
|
const _getDomainMargins = (containerWidth)=>{
|
|
481
|
-
/** Total width available to render the bars */ const totalWidth =
|
|
482
|
-
/** Rate at which the space between the groups changes wrt the group width */ const groupGapRate = _xAxisInnerPadding / (1 - _xAxisInnerPadding);
|
|
502
|
+
/** Total width available to render the bars */ const totalWidth = (0, _index.calcTotalWidth)(containerWidth, _margins, MIN_DOMAIN_MARGIN);
|
|
483
503
|
if (_xAxisType === _index.XAxisTypes.StringAxis) {
|
|
484
504
|
if ((0, _index.isScalePaddingDefined)(props.xAxisOuterPadding)) {
|
|
485
505
|
// Setting the domain margin for string x-axis to 0 because the xAxisOuterPadding prop is now available
|
|
@@ -489,19 +509,19 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
489
509
|
// Update the bar width so that when CartesianChart rerenders,
|
|
490
510
|
// the following calculations don't use the previous bar width.
|
|
491
511
|
_barWidth = (0, _index.getBarWidth)(props.barWidth, props.maxBarWidth);
|
|
492
|
-
const groupWidth = (
|
|
493
|
-
/** Total width required to render the groups. Directly proportional to group width */ const reqWidth = (
|
|
512
|
+
const groupWidth = (0, _index.calcRequiredWidth)(_barWidth, _legends.length, X1_INNER_PADDING);
|
|
513
|
+
/** Total width required to render the groups. Directly proportional to group width */ const reqWidth = (0, _index.calcRequiredWidth)(groupWidth, _xAxisLabels.length, _xAxisInnerPadding);
|
|
494
514
|
if (totalWidth >= reqWidth) {
|
|
495
515
|
// Center align the chart by setting equal left and right margins for domain
|
|
496
516
|
_domainMargin = MIN_DOMAIN_MARGIN + (totalWidth - reqWidth) / 2;
|
|
497
517
|
}
|
|
498
518
|
} else if (props.mode === 'plotly' && xAxisLabels.length > 1) {
|
|
499
519
|
// Calculate the remaining width after rendering groups at their maximum allowable width
|
|
500
|
-
const groupBandwidth =
|
|
501
|
-
const barBandwidth =
|
|
520
|
+
const groupBandwidth = (0, _index.calcBandwidth)(totalWidth, _xAxisLabels.length, _xAxisInnerPadding);
|
|
521
|
+
const barBandwidth = (0, _index.calcBandwidth)(groupBandwidth, _legends.length, X1_INNER_PADDING);
|
|
502
522
|
const barWidth = (0, _index.getBarWidth)(props.barWidth, props.maxBarWidth, barBandwidth);
|
|
503
|
-
const groupWidth = (
|
|
504
|
-
let reqWidth = (
|
|
523
|
+
const groupWidth = (0, _index.calcRequiredWidth)(barWidth, _legends.length, X1_INNER_PADDING);
|
|
524
|
+
let reqWidth = (0, _index.calcRequiredWidth)(groupWidth, _xAxisLabels.length, _xAxisInnerPadding);
|
|
505
525
|
const margin1 = (totalWidth - reqWidth) / 2;
|
|
506
526
|
let margin2 = Number.POSITIVE_INFINITY;
|
|
507
527
|
if (!props.hideTickOverlap) {
|
|
@@ -523,7 +543,7 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
523
543
|
return !(props.data && props.data.length > 0 && props.data.filter((item)=>item.series.length).length > 0);
|
|
524
544
|
};
|
|
525
545
|
const _getChartTitle = ()=>{
|
|
526
|
-
return (props.chartTitle ? `${props.chartTitle}. ` : '') + `Vertical bar chart with ${_xAxisLabels.length} groups of ${
|
|
546
|
+
return (props.chartTitle ? `${props.chartTitle}. ` : '') + `Vertical bar chart with ${_xAxisLabels.length} groups of ${_legends.length} bars each. `;
|
|
527
547
|
};
|
|
528
548
|
return !_isChartEmpty() ? /*#__PURE__*/ _react.createElement(_index1.CartesianChart, {
|
|
529
549
|
...props,
|
|
@@ -534,7 +554,7 @@ const GroupedVerticalBarChart = /*#__PURE__*/ _react.forwardRef((props = {
|
|
|
534
554
|
getMinMaxOfYAxis: _getMinMaxOfYAxis,
|
|
535
555
|
createStringYAxis: _index.createStringYAxis,
|
|
536
556
|
calloutProps: calloutProps,
|
|
537
|
-
legendBars:
|
|
557
|
+
legendBars: legendBars,
|
|
538
558
|
xAxisType: _xAxisType,
|
|
539
559
|
createYAxis: _index.createNumericYAxis,
|
|
540
560
|
datasetForXAxisDomain: _xAxisLabels,
|