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