@fluentui/react-charting 5.23.77 → 5.23.79

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 (53) hide show
  1. package/CHANGELOG.json +43 -1
  2. package/CHANGELOG.md +22 -2
  3. package/dist/react-charting.js +1 -1
  4. package/dist/react-charting.min.js +1 -1
  5. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +10 -23
  6. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  7. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -4
  8. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +119 -117
  9. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  10. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  11. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +89 -26
  12. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  13. package/lib/components/LineChart/eventAnnotation/LabelLink.js +1 -1
  14. package/lib/components/LineChart/eventAnnotation/LabelLink.js.map +1 -1
  15. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +2 -0
  16. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +29 -11
  17. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  18. package/lib/utilities/utilities.d.ts +6 -3
  19. package/lib/utilities/utilities.js +16 -11
  20. package/lib/utilities/utilities.js.map +1 -1
  21. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +10 -23
  22. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  23. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -4
  24. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +119 -117
  25. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  26. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  27. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +88 -25
  28. package/lib-amd/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  29. package/lib-amd/components/LineChart/eventAnnotation/LabelLink.js +1 -1
  30. package/lib-amd/components/LineChart/eventAnnotation/LabelLink.js.map +1 -1
  31. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +2 -0
  32. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +29 -11
  33. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  34. package/lib-amd/utilities/utilities.d.ts +6 -3
  35. package/lib-amd/utilities/utilities.js +18 -13
  36. package/lib-amd/utilities/utilities.js.map +1 -1
  37. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +10 -23
  38. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  39. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +3 -4
  40. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +119 -117
  41. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  42. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.d.ts +3 -1
  43. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js +88 -25
  44. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.base.js.map +1 -1
  45. package/lib-commonjs/components/LineChart/eventAnnotation/LabelLink.js +1 -1
  46. package/lib-commonjs/components/LineChart/eventAnnotation/LabelLink.js.map +1 -1
  47. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +2 -0
  48. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +29 -11
  49. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  50. package/lib-commonjs/utilities/utilities.d.ts +6 -3
  51. package/lib-commonjs/utilities/utilities.js +18 -13
  52. package/lib-commonjs/utilities/utilities.js.map +1 -1
  53. package/package.json +1 -1
@@ -17,12 +17,15 @@ var X1_INNER_PADDING = 0.1;
17
17
  // => space_between_bars = (x1_inner_padding / (1 - x1_inner_padding)) * bar_width
18
18
  /** Rate at which the space between the bars in a group changes wrt the bar width */
19
19
  var BAR_GAP_RATE = X1_INNER_PADDING / (1 - X1_INNER_PADDING);
20
+ var VERTICAL_BAR_GAP = 1;
21
+ var MIN_BAR_HEIGHT = 1;
20
22
  var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
21
23
  __extends(GroupedVerticalBarChartBase, _super);
22
24
  function GroupedVerticalBarChartBase(props) {
23
25
  var _a;
24
26
  var _this = _super.call(this, props) || this;
25
27
  _this._isRtl = getRTL();
28
+ _this._legendColorMap = {};
26
29
  _this.toImage = function (opts) {
27
30
  var _a, _b;
28
31
  return toImage((_a = _this._cartesianChartRef.current) === null || _a === void 0 ? void 0 : _a.chartContainer, (_b = _this._legendsRef.current) === null || _b === void 0 ? void 0 : _b.toSVG, _this._isRtl, opts);
@@ -54,8 +57,8 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
54
57
  var xScale0 = _this._createX0Scale(containerWidth);
55
58
  // Setting the bar width here is safe because there are no dependencies earlier in the code
56
59
  // that rely on the width of bars in vertical bar charts with string x-axis.
57
- _this._barWidth = getBarWidth(_this.props.barwidth, _this.props.maxBarWidth, xScale0.bandwidth() / (_this._keys.length + (_this._keys.length - 1) * BAR_GAP_RATE));
58
- _this._groupWidth = (_this._keys.length + (_this._keys.length - 1) * BAR_GAP_RATE) * _this._barWidth;
60
+ _this._barWidth = getBarWidth(_this.props.barwidth, _this.props.maxBarWidth, xScale0.bandwidth() / (_this._legends.length + (_this._legends.length - 1) * BAR_GAP_RATE));
61
+ _this._groupWidth = (_this._legends.length + (_this._legends.length - 1) * BAR_GAP_RATE) * _this._barWidth;
59
62
  var xScale1 = _this._createX1Scale();
60
63
  var allGroupsBars = [];
61
64
  _this._datasetForBars.forEach(function (singleSet) {
@@ -65,14 +68,16 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
65
68
  };
66
69
  _this._getMargins = function (margins) { return (_this.margins = margins); };
67
70
  _this._createDataSetOfGVBC = function (points) {
68
- var keys = [];
71
+ var legends = new Set();
69
72
  var xAxisLabels = points.map(function (singlePoint) { return singlePoint.name; });
70
- points[0].series.forEach(function (singleKey) {
71
- keys.push(singleKey.key);
73
+ points.forEach(function (point) {
74
+ point.series.forEach(function (seriesPoint) {
75
+ legends.add(seriesPoint.legend);
76
+ });
72
77
  });
73
78
  var datasetForBars = _this._createDataset(points);
74
79
  return {
75
- keys: keys,
80
+ legends: Array.from(legends),
76
81
  xAxisLabels: xAxisLabels,
77
82
  datasetForBars: datasetForBars,
78
83
  };
@@ -82,10 +87,6 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
82
87
  ? _this.props.onRenderCalloutPerDataPoint(_this.state.dataPointCalloutProps)
83
88
  : null;
84
89
  };
85
- _this._getOpacity = function (legendTitle) {
86
- var opacity = _this._legendHighlighted(legendTitle) || _this._noLegendHighlighted() ? '' : '0.1';
87
- return opacity;
88
- };
89
90
  _this._onBarHover = function (pointData,
90
91
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
92
  groupData, mouseEvent) {
@@ -119,26 +120,22 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
119
120
  };
120
121
  _this._onBarFocus = function (pointData,
121
122
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
- groupData, refArrayIndexNumber) {
123
- _this._refArray.forEach(function (obj, index) {
124
- if (obj.index === pointData.legend && refArrayIndexNumber === index) {
125
- _this.setState({
126
- refSelected: obj.refElement,
127
- /** Show the callout if highlighted bar is focused and Hide it if unhighlighted bar is focused */
128
- isCalloutVisible: _this._noLegendHighlighted() || _this._legendHighlighted(pointData.legend),
129
- calloutLegend: pointData.legend,
130
- dataForHoverCard: pointData.data,
131
- color: pointData.color,
132
- xCalloutValue: pointData.xAxisCalloutData,
133
- yCalloutValue: pointData.yAxisCalloutData,
134
- dataPointCalloutProps: pointData,
135
- callOutAccessibilityData: _this.props.isCalloutForStack
136
- ? groupData.stackCallOutAccessibilityData
137
- : pointData.callOutAccessibilityData,
138
- YValueHover: groupData.groupSeries,
139
- hoverXValue: pointData.xAxisCalloutData,
140
- });
141
- }
123
+ groupData, focusEvent) {
124
+ _this.setState({
125
+ refSelected: focusEvent.currentTarget,
126
+ /** Show the callout if highlighted bar is focused and Hide it if unhighlighted bar is focused */
127
+ isCalloutVisible: _this._noLegendHighlighted() || _this._legendHighlighted(pointData.legend),
128
+ calloutLegend: pointData.legend,
129
+ dataForHoverCard: pointData.data,
130
+ color: pointData.color,
131
+ xCalloutValue: pointData.xAxisCalloutData,
132
+ yCalloutValue: pointData.yAxisCalloutData,
133
+ dataPointCalloutProps: pointData,
134
+ callOutAccessibilityData: _this.props.isCalloutForStack
135
+ ? groupData.stackCallOutAccessibilityData
136
+ : pointData.callOutAccessibilityData,
137
+ YValueHover: groupData.groupSeries,
138
+ hoverXValue: pointData.xAxisCalloutData,
142
139
  });
143
140
  };
144
141
  _this._redirectToUrl = function (href) {
@@ -153,40 +150,41 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
153
150
  xScale1, yScalePrimary, yScaleSecondary, containerHeight, xElement) {
154
151
  var singleGroup = [];
155
152
  var barLabelsForGroup = [];
156
- var tempDataSet = Object.keys(_this._datasetForBars[0]).splice(0, _this._keys.length);
157
- tempDataSet.forEach(function (datasetKey, index) {
158
- var _a, _b, _c, _d, _e;
159
- var refIndexNumber = singleSet.indexNum * tempDataSet.length + index;
160
- var pointData = singleSet[datasetKey];
161
- if (pointData) {
162
- var yBarScale = pointData.useSecondaryYScale && yScaleSecondary ? yScaleSecondary : yScalePrimary;
153
+ _this._legends.forEach(function (legendTitle, legendIndex) {
154
+ var barPoints = singleSet[legendTitle];
155
+ if (barPoints) {
156
+ var yBarScale_1 = barPoints[0].useSecondaryYScale && yScaleSecondary ? yScaleSecondary : yScalePrimary;
163
157
  // To align the centers of the generated bandwidth and the calculated one when they differ,
164
158
  // use the following addend.
165
- var xPoint = xScale1(datasetKey) + (xScale1.bandwidth() - _this._barWidth) / 2;
166
- var yPoint = Math.max(yBarScale(pointData.data), 0);
167
- var startColor = pointData.color ? pointData.color : getNextColor(index, 0, (_a = _this.props.theme) === null || _a === void 0 ? void 0 : _a.isInverted);
168
- var endColor = startColor;
159
+ var xPoint_1 = xScale1(legendTitle) + (xScale1.bandwidth() - _this._barWidth) / 2;
160
+ var isLegendActive_1 = _this._legendHighlighted(legendTitle) || _this._noLegendHighlighted();
161
+ var barOpacity_1 = isLegendActive_1 ? '' : '0.1';
162
+ var gradientId_1 = getId('GVBC_Gradient') + "_".concat(singleSet.indexNum, "_").concat(legendIndex);
163
+ var startColor_1 = barPoints[0].color;
164
+ var endColor = startColor_1;
169
165
  if (_this.props.enableGradient) {
170
- startColor = ((_b = pointData.gradient) === null || _b === void 0 ? void 0 : _b[0]) || getNextGradient(index, 0, (_c = _this.props.theme) === null || _c === void 0 ? void 0 : _c.isInverted)[0];
171
- endColor = ((_d = pointData.gradient) === null || _d === void 0 ? void 0 : _d[1]) || getNextGradient(index, 0, (_e = _this.props.theme) === null || _e === void 0 ? void 0 : _e.isInverted)[1];
172
- pointData.color = startColor;
166
+ startColor_1 = barPoints[0].gradient[0];
167
+ endColor = barPoints[0].gradient[1];
168
+ singleGroup.push(React.createElement("linearGradient", { key: gradientId_1, id: gradientId_1, x1: "0%", y1: "100%", x2: "0%", y2: "0%" },
169
+ React.createElement("stop", { offset: "0", stopColor: startColor_1 }),
170
+ React.createElement("stop", { offset: "100%", stopColor: endColor })));
173
171
  }
174
- var gradientId = getId('GVBC_Gradient') + "_".concat(singleSet.indexNum, "_").concat(index);
175
- // Not rendering data with 0.
176
- pointData.data &&
177
- singleGroup.push(React.createElement(React.Fragment, { key: "".concat(singleSet.indexNum, "-").concat(index) },
178
- _this.props.enableGradient && (React.createElement("defs", null,
179
- React.createElement("linearGradient", { id: gradientId, x1: "0%", y1: "100%", x2: "0%", y2: "0%" },
180
- React.createElement("stop", { offset: "0", stopColor: startColor }),
181
- React.createElement("stop", { offset: "100%", stopColor: endColor })))),
182
- React.createElement("rect", { className: _this._classNames.opacityChangeOnHover, height: Math.max(containerHeight - _this.margins.bottom - yBarScale(pointData.data), 0), width: _this._barWidth, x: xPoint, y: yPoint, "data-is-focusable": !_this.props.hideTooltip && (_this._legendHighlighted(pointData.legend) || _this._noLegendHighlighted()), opacity: _this._getOpacity(pointData.legend), ref: function (e) {
183
- _this._refCallback(e, pointData.legend, refIndexNumber);
184
- }, fill: _this.props.enableGradient ? "url(#".concat(gradientId, ")") : startColor, rx: _this.props.roundCorners ? 3 : 0, onMouseOver: _this._onBarHover.bind(_this, pointData, singleSet), onMouseMove: _this._onBarHover.bind(_this, pointData, singleSet), onMouseOut: _this._onBarLeave, onFocus: _this._onBarFocus.bind(_this, pointData, singleSet, refIndexNumber), onBlur: _this._onBarLeave, onClick: _this.props.href ? _this._redirectToUrl.bind(_this, _this.props.href) : pointData.onClick, "aria-label": _this._getAriaLabel(pointData, singleSet.xAxisPoint), role: "img" })));
185
- if (pointData.data &&
186
- !_this.props.hideLabels &&
187
- _this._barWidth >= 16 &&
188
- (_this._legendHighlighted(pointData.legend) || _this._noLegendHighlighted())) {
189
- barLabelsForGroup.push(React.createElement("text", { key: "".concat(singleSet.indexNum, "-").concat(index), x: xPoint + _this._barWidth / 2, y: yPoint - 6, textAnchor: "middle", className: _this._classNames.barLabel, "aria-hidden": true }, formatValueWithSIPrefix(pointData.data)));
172
+ var prevYPoint_1 = yBarScale_1(0);
173
+ var barTotalValue_1 = 0;
174
+ barPoints.forEach(function (pointData, pointIndex) {
175
+ if (!pointData.data) {
176
+ // Not rendering data with 0.
177
+ return;
178
+ }
179
+ var barGapTop = (VERTICAL_BAR_GAP / 2) * (pointIndex < barPoints.length - 1 ? 1 : 0);
180
+ var barGapBottom = (VERTICAL_BAR_GAP / 2) * (pointIndex > 0 ? 1 : 0);
181
+ var height = Math.max(yBarScale_1(0) - yBarScale_1(pointData.data) - barGapTop - barGapBottom, MIN_BAR_HEIGHT);
182
+ singleGroup.push(React.createElement("rect", { key: "".concat(singleSet.indexNum, "-").concat(legendIndex, "-").concat(pointIndex), className: _this._classNames.opacityChangeOnHover, height: height, width: _this._barWidth, x: xPoint_1, y: prevYPoint_1 - (height + barGapBottom), "data-is-focusable": !_this.props.hideTooltip && isLegendActive_1, opacity: barOpacity_1, fill: _this.props.enableGradient ? "url(#".concat(gradientId_1, ")") : startColor_1, rx: _this.props.roundCorners ? 3 : 0, onMouseOver: _this._onBarHover.bind(_this, pointData, singleSet), onMouseMove: _this._onBarHover.bind(_this, pointData, singleSet), onMouseOut: _this._onBarLeave, onFocus: _this._onBarFocus.bind(_this, pointData, singleSet), onBlur: _this._onBarLeave, onClick: _this.props.href ? _this._redirectToUrl.bind(_this, _this.props.href) : pointData.onClick, "aria-label": _this._getAriaLabel(pointData, singleSet.xAxisPoint), role: "img" }));
183
+ prevYPoint_1 = prevYPoint_1 - (height + barGapTop + barGapBottom);
184
+ barTotalValue_1 += pointData.data;
185
+ });
186
+ if (barTotalValue_1 && !_this.props.hideLabels && _this._barWidth >= 16 && isLegendActive_1) {
187
+ barLabelsForGroup.push(React.createElement("text", { key: "".concat(singleSet.indexNum, "-").concat(legendIndex), x: xPoint_1 + _this._barWidth / 2, y: prevYPoint_1 - 6, textAnchor: "middle", className: _this._classNames.barLabel, "aria-hidden": true }, formatValueWithSIPrefix(barTotalValue_1)));
190
188
  }
191
189
  }
192
190
  });
@@ -212,28 +210,25 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
212
210
  _this._createDataset = function (points) {
213
211
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
214
212
  var datasetForBars = [];
215
- var dataset = [];
216
213
  points.forEach(function (point, index) {
217
- var singleDatasetPoint = {};
218
214
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
219
215
  var singleDatasetPointForBars = {};
220
- var singleDataSeries = [];
221
- point.series.forEach(function (seriesPoint, seriesIndex) {
222
- var _a, _b;
223
- if (_this.props.enableGradient) {
224
- seriesPoint.color =
225
- ((_a = seriesPoint.gradient) === null || _a === void 0 ? void 0 : _a[0]) || getNextGradient(seriesIndex, 0, (_b = _this.props.theme) === null || _b === void 0 ? void 0 : _b.isInverted)[0];
216
+ var legendToBarPoint = {};
217
+ point.series.forEach(function (seriesPoint) {
218
+ if (!singleDatasetPointForBars[seriesPoint.legend]) {
219
+ singleDatasetPointForBars[seriesPoint.legend] = [__assign({}, seriesPoint)];
220
+ legendToBarPoint[seriesPoint.legend] = __assign({}, seriesPoint);
221
+ }
222
+ else {
223
+ singleDatasetPointForBars[seriesPoint.legend].push(__assign({}, seriesPoint));
224
+ legendToBarPoint[seriesPoint.legend].data += seriesPoint.data;
226
225
  }
227
- singleDatasetPoint[seriesPoint.key] = seriesPoint.data;
228
- singleDatasetPointForBars[seriesPoint.key] = __assign({}, seriesPoint);
229
- singleDataSeries.push(seriesPoint);
230
226
  });
231
227
  singleDatasetPointForBars.xAxisPoint = point.name;
232
228
  singleDatasetPointForBars.indexNum = index;
233
- singleDatasetPointForBars.groupSeries = singleDataSeries;
229
+ singleDatasetPointForBars.groupSeries = Object.values(legendToBarPoint);
234
230
  singleDatasetPointForBars.stackCallOutAccessibilityData = point.stackCallOutAccessibilityData;
235
231
  datasetForBars.push(singleDatasetPointForBars);
236
- dataset.push(singleDatasetPoint);
237
232
  });
238
233
  return datasetForBars;
239
234
  };
@@ -252,7 +247,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
252
247
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
253
248
  _this._createX1Scale = function () {
254
249
  return (d3ScaleBand()
255
- .domain(_this._keys)
250
+ .domain(_this._legends)
256
251
  // When there is only one group, xScale0 adds padding around it,
257
252
  // causing the bandwidth to become smaller than the actual group width.
258
253
  // So to render bars in the group correctly, use groupWidth instead of the generated scale bandwidth.
@@ -264,35 +259,21 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
264
259
  isCalloutVisible: false,
265
260
  });
266
261
  };
267
- _this._getLegendData = function (points, palette) {
268
- var data = points;
269
- var defaultPalette = [palette.blueLight, palette.blue, palette.blueMid, palette.red, palette.black];
262
+ _this._getLegendData = function () {
270
263
  var actions = [];
271
- data.forEach(function (singleChartData) {
272
- singleChartData.series.forEach(function (point) {
273
- var _a, _b, _c;
274
- var color = point.color ? point.color : defaultPalette[Math.floor(Math.random() * 4 + 1)];
275
- if (_this.props.enableGradient) {
276
- var pointIndex = Math.max(((_a = singleChartData.series) === null || _a === void 0 ? void 0 : _a.findIndex(function (item) { return item.legend === point.legend; })) || 0, 0);
277
- color = ((_b = point.gradient) === null || _b === void 0 ? void 0 : _b[0]) || getNextGradient(pointIndex, 0, (_c = _this.props.theme) === null || _c === void 0 ? void 0 : _c.isInverted)[0];
278
- }
279
- var checkSimilarLegends = actions.filter(function (leg) { return leg.title === point.legend && leg.color === color; });
280
- if (checkSimilarLegends.length > 0) {
281
- return;
282
- }
283
- var legend = {
284
- title: point.legend,
285
- color: color,
286
- hoverAction: function () {
287
- _this._handleChartMouseLeave();
288
- _this._onLegendHover(point.legend);
289
- },
290
- onMouseOutAction: function () {
291
- _this._onLegendLeave();
292
- },
293
- };
294
- actions.push(legend);
295
- });
264
+ _this._legends.forEach(function (legendTitle) {
265
+ var legend = {
266
+ title: legendTitle,
267
+ color: _this._legendColorMap[legendTitle][0],
268
+ hoverAction: function () {
269
+ _this._handleChartMouseLeave();
270
+ _this._onLegendHover(legendTitle);
271
+ },
272
+ onMouseOutAction: function () {
273
+ _this._onLegendLeave();
274
+ },
275
+ };
276
+ actions.push(legend);
296
277
  });
297
278
  return (React.createElement(Legends, __assign({ legends: actions, overflowProps: _this.props.legendsOverflowProps, enabledWrapLines: _this.props.enabledLegendsWrapLines, focusZonePropsInHoverCard: _this.props.focusZonePropsForLegendsInHoverCard }, _this.props.legendProps, { onChange: _this._onLegendSelectionChange.bind(_this), ref: _this._legendsRef })));
298
279
  };
@@ -340,7 +321,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
340
321
  // Update the bar width so that when CartesianChart rerenders,
341
322
  // the following calculations don't use the previous bar width.
342
323
  _this._barWidth = getBarWidth(_this.props.barwidth, _this.props.maxBarWidth);
343
- var groupWidth = (_this._keys.length + (_this._keys.length - 1) * BAR_GAP_RATE) * _this._barWidth;
324
+ var groupWidth = (_this._legends.length + (_this._legends.length - 1) * BAR_GAP_RATE) * _this._barWidth;
344
325
  /** Total width required to render the groups. Directly proportional to group width */
345
326
  var reqWidth = (_this._xAxisLabels.length + (_this._xAxisLabels.length - 1) * groupGapRate) * groupWidth;
346
327
  if (totalWidth >= reqWidth) {
@@ -351,9 +332,9 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
351
332
  else if (_this.props.mode === 'plotly' && _this._xAxisLabels.length > 1) {
352
333
  // Calculate the remaining width after rendering groups at their maximum allowable width
353
334
  var groupBandwidth = totalWidth / (_this._xAxisLabels.length + (_this._xAxisLabels.length - 1) * groupGapRate);
354
- var barBandwidth = groupBandwidth / (_this._keys.length + (_this._keys.length - 1) * BAR_GAP_RATE);
335
+ var barBandwidth = groupBandwidth / (_this._legends.length + (_this._legends.length - 1) * BAR_GAP_RATE);
355
336
  var barWidth = getBarWidth(_this.props.barwidth, _this.props.maxBarWidth, barBandwidth);
356
- var groupWidth = (_this._keys.length + (_this._keys.length - 1) * BAR_GAP_RATE) * barWidth;
337
+ var groupWidth = (_this._legends.length + (_this._legends.length - 1) * BAR_GAP_RATE) * barWidth;
357
338
  var reqWidth = (_this._xAxisLabels.length + (_this._xAxisLabels.length - 1) * groupGapRate) * groupWidth;
358
339
  var margin1 = (totalWidth - reqWidth) / 2;
359
340
  var margin2 = Number.POSITIVE_INFINITY;
@@ -371,7 +352,32 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
371
352
  _this._getChartTitle = function () {
372
353
  var chartTitle = _this.props.chartTitle;
373
354
  return ((chartTitle ? "".concat(chartTitle, ". ") : '') +
374
- "Vertical bar chart with ".concat(_this._xAxisLabels.length, " groups of ").concat(_this._keys.length, " bars each. "));
355
+ "Vertical bar chart with ".concat(_this._xAxisLabels.length, " groups of ").concat(_this._legends.length, " bars each. "));
356
+ };
357
+ _this._addDefaultColors = function (data) {
358
+ var _a;
359
+ _this._legendColorMap = {};
360
+ var colorIndex = 0;
361
+ return ((_a = data === null || data === void 0 ? void 0 : data.map(function (point) {
362
+ var _a, _b;
363
+ return __assign(__assign({}, point), { series: (_b = (_a = point.series) === null || _a === void 0 ? void 0 : _a.map(function (seriesPoint) {
364
+ var _a, _b, _c, _d;
365
+ if (!_this._legendColorMap[seriesPoint.legend]) {
366
+ var startColor = seriesPoint.color
367
+ ? seriesPoint.color
368
+ : getNextColor(colorIndex, 0, (_a = _this.props.theme) === null || _a === void 0 ? void 0 : _a.isInverted);
369
+ var endColor = startColor;
370
+ if (_this.props.enableGradient) {
371
+ var nextGradient = getNextGradient(colorIndex, 0, (_b = _this.props.theme) === null || _b === void 0 ? void 0 : _b.isInverted);
372
+ startColor = ((_c = seriesPoint.gradient) === null || _c === void 0 ? void 0 : _c[0]) || nextGradient[0];
373
+ endColor = ((_d = seriesPoint.gradient) === null || _d === void 0 ? void 0 : _d[1]) || nextGradient[1];
374
+ }
375
+ _this._legendColorMap[seriesPoint.legend] = [startColor, endColor];
376
+ colorIndex += 1;
377
+ }
378
+ return __assign(__assign(__assign({}, seriesPoint), { color: _this._legendColorMap[seriesPoint.legend][0] }), (_this.props.enableGradient ? { gradient: _this._legendColorMap[seriesPoint.legend] } : {}));
379
+ })) !== null && _b !== void 0 ? _b : [] });
380
+ })) !== null && _a !== void 0 ? _a : []);
375
381
  };
376
382
  initializeComponentRef(_this);
377
383
  _this._createSet = memoizeFunction(function (data) { return _this._createDataSetOfGVBC(data); });
@@ -395,7 +401,6 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
395
401
  showXAxisGridLines: 'Dont use this property. Handling with default value.',
396
402
  legendColor: 'Dont use this property. colour will pick from given data.',
397
403
  });
398
- _this._refArray = [];
399
404
  _this._calloutId = getId('callout');
400
405
  _this._tooltipId = getId('GVBCTooltipId_');
401
406
  _this._emptyChartId = getId('_GVBC_empty');
@@ -414,13 +419,13 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
414
419
  };
415
420
  GroupedVerticalBarChartBase.prototype.render = function () {
416
421
  var _this = this;
417
- var points = this.props.data;
418
- var _a = this._createSet(points), keys = _a.keys, xAxisLabels = _a.xAxisLabels, datasetForBars = _a.datasetForBars;
419
- this._keys = keys;
422
+ var points = this._addDefaultColors(this.props.data);
423
+ var _a = this._createSet(points), legends = _a.legends, xAxisLabels = _a.xAxisLabels, datasetForBars = _a.datasetForBars;
424
+ this._legends = legends;
420
425
  this._xAxisLabels = xAxisLabels;
421
426
  this._datasetForBars = datasetForBars;
422
427
  this._xAxisType = getTypeOfAxis(points[0].name, true);
423
- var legends = this._getLegendData(points, this.props.theme.palette);
428
+ var legendBars = this._getLegendData();
424
429
  this._adjustProps();
425
430
  // The maxOfYVal prop is only required for the primary y-axis, so yMax should be calculated
426
431
  // using only the data points associated with the primary y-axis.
@@ -436,7 +441,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
436
441
  tickValues: this.props.tickValues,
437
442
  tickFormat: this.props.tickFormat,
438
443
  };
439
- return !this._isChartEmpty() ? (React.createElement(CartesianChart, __assign({}, this.props, { chartTitle: this._getChartTitle(), points: this._datasetForBars, chartType: ChartTypes.GroupedVerticalBarChart, calloutProps: calloutProps, legendBars: legends, xAxisType: this._xAxisType, createYAxis: createNumericYAxis, datasetForXAxisDomain: this._xAxisLabels, tickParams: tickParams, getDomainNRangeValues: this._getDomainNRangeValues, getMinMaxOfYAxis: this._getMinMaxOfYAxis, createStringYAxis: createStringYAxis, tickPadding: this.props.tickPadding || 5, maxOfYVal: this._yMax, svgFocusZoneProps: {
444
+ return !this._isChartEmpty() ? (React.createElement(CartesianChart, __assign({}, this.props, { chartTitle: this._getChartTitle(), points: this._datasetForBars, chartType: ChartTypes.GroupedVerticalBarChart, calloutProps: calloutProps, legendBars: legendBars, xAxisType: this._xAxisType, createYAxis: createNumericYAxis, datasetForXAxisDomain: this._xAxisLabels, tickParams: tickParams, getDomainNRangeValues: this._getDomainNRangeValues, getMinMaxOfYAxis: this._getMinMaxOfYAxis, createStringYAxis: createStringYAxis, tickPadding: this.props.tickPadding || 5, maxOfYVal: this._yMax, svgFocusZoneProps: {
440
445
  direction: FocusZoneDirection.horizontal,
441
446
  }, customizedCallout: this._getCustomizedCallout(), getmargins: this._getMargins, getGraphData: this._getGraphData, getAxisData: this._getAxisData, onChartMouseLeave: this._handleChartMouseLeave, getDomainMargins: this._getDomainMargins }, (this._xAxisType === XAxisTypes.StringAxis && {
442
447
  xAxisInnerPadding: this._xAxisInnerPadding,
@@ -455,9 +460,6 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
455
460
  enumerable: false,
456
461
  configurable: true
457
462
  });
458
- GroupedVerticalBarChartBase.prototype._refCallback = function (element, legendTitle, refIndexNumber) {
459
- this._refArray[refIndexNumber] = { index: legendTitle, refElement: element };
460
- };
461
463
  GroupedVerticalBarChartBase.prototype._onLegendHover = function (legendTitle) {
462
464
  this.setState({
463
465
  activeLegend: legendTitle,
@@ -496,8 +498,8 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
496
498
  this._barWidth = getBarWidth(this.props.barwidth, this.props.maxBarWidth);
497
499
  // x0_inner_padding = space_between_groups / (space_between_groups + group_width)
498
500
  // space_between_groups = 2 * bar_width
499
- // group_width = this._keys.length * bar_width + (this._keys.length - 1) * space_between_bars
500
- this._xAxisInnerPadding = getScalePadding(this.props.xAxisInnerPadding, undefined, 2 / (2 + this._keys.length + (this._keys.length - 1) * BAR_GAP_RATE));
501
+ // group_width = this._legends.length * bar_width + (this._legends.length - 1) * space_between_bars
502
+ this._xAxisInnerPadding = getScalePadding(this.props.xAxisInnerPadding, undefined, 2 / (2 + this._legends.length + (this._legends.length - 1) * BAR_GAP_RATE));
501
503
  this._xAxisOuterPadding = getScalePadding(this.props.xAxisOuterPadding);
502
504
  };
503
505
  GroupedVerticalBarChartBase.defaultProps = {