@fluentui/react-charting 5.24.30 → 5.24.32

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 (73) hide show
  1. package/CHANGELOG.json +43 -1
  2. package/CHANGELOG.md +22 -2
  3. package/dist/react-charting.d.ts +135 -2
  4. package/dist/react-charting.js +1 -1
  5. package/dist/react-charting.min.js +1 -1
  6. package/etc/react-charting.api.md +45 -2
  7. package/lib/components/AreaChart/AreaChart.base.js +18 -22
  8. package/lib/components/AreaChart/AreaChart.base.js.map +1 -1
  9. package/lib/components/DeclarativeChart/DeclarativeChart.js +1 -4
  10. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  11. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +93 -50
  12. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  13. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +13 -2
  14. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +260 -100
  15. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  16. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.d.ts +7 -2
  17. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js.map +1 -1
  18. package/lib/components/LineChart/LineChart.base.js +59 -42
  19. package/lib/components/LineChart/LineChart.base.js.map +1 -1
  20. package/lib/components/ScatterChart/ScatterChart.base.js +5 -11
  21. package/lib/components/ScatterChart/ScatterChart.base.js.map +1 -1
  22. package/lib/index.d.ts +1 -1
  23. package/lib/index.js.map +1 -1
  24. package/lib/types/IDataPoint.d.ts +125 -1
  25. package/lib/types/IDataPoint.js.map +1 -1
  26. package/lib/utilities/utilities.d.ts +18 -4
  27. package/lib/utilities/utilities.js +14 -5
  28. package/lib/utilities/utilities.js.map +1 -1
  29. package/lib-amd/components/AreaChart/AreaChart.base.js +16 -20
  30. package/lib-amd/components/AreaChart/AreaChart.base.js.map +1 -1
  31. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +1 -4
  32. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  33. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +92 -49
  34. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  35. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +13 -2
  36. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +257 -97
  37. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  38. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.d.ts +7 -2
  39. package/lib-amd/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js.map +1 -1
  40. package/lib-amd/components/LineChart/LineChart.base.js +58 -41
  41. package/lib-amd/components/LineChart/LineChart.base.js.map +1 -1
  42. package/lib-amd/components/ScatterChart/ScatterChart.base.js +3 -9
  43. package/lib-amd/components/ScatterChart/ScatterChart.base.js.map +1 -1
  44. package/lib-amd/index.d.ts +1 -1
  45. package/lib-amd/index.js.map +1 -1
  46. package/lib-amd/types/IDataPoint.d.ts +125 -1
  47. package/lib-amd/types/IDataPoint.js.map +1 -1
  48. package/lib-amd/utilities/utilities.d.ts +18 -4
  49. package/lib-amd/utilities/utilities.js +16 -6
  50. package/lib-amd/utilities/utilities.js.map +1 -1
  51. package/lib-commonjs/components/AreaChart/AreaChart.base.js +16 -20
  52. package/lib-commonjs/components/AreaChart/AreaChart.base.js.map +1 -1
  53. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +1 -4
  54. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  55. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +92 -49
  56. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  57. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.d.ts +13 -2
  58. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js +257 -97
  59. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.base.js.map +1 -1
  60. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.d.ts +7 -2
  61. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.types.js.map +1 -1
  62. package/lib-commonjs/components/LineChart/LineChart.base.js +58 -41
  63. package/lib-commonjs/components/LineChart/LineChart.base.js.map +1 -1
  64. package/lib-commonjs/components/ScatterChart/ScatterChart.base.js +3 -9
  65. package/lib-commonjs/components/ScatterChart/ScatterChart.base.js.map +1 -1
  66. package/lib-commonjs/index.d.ts +1 -1
  67. package/lib-commonjs/index.js.map +1 -1
  68. package/lib-commonjs/types/IDataPoint.d.ts +125 -1
  69. package/lib-commonjs/types/IDataPoint.js.map +1 -1
  70. package/lib-commonjs/utilities/utilities.d.ts +18 -4
  71. package/lib-commonjs/utilities/utilities.js +16 -6
  72. package/lib-commonjs/utilities/utilities.js.map +1 -1
  73. package/package.json +2 -2
@@ -6,11 +6,13 @@ export interface IGroupedVerticalBarChartState extends IBasestate {
6
6
  callOutAccessibilityData?: IAccessibilityProps;
7
7
  calloutLegend: string;
8
8
  selectedLegends: string[];
9
+ activeLinePoint: string;
9
10
  }
10
11
  export declare class GroupedVerticalBarChartBase extends React.Component<IGroupedVerticalBarChartProps, IGroupedVerticalBarChartState> implements IChart {
11
12
  static defaultProps: Partial<IGroupedVerticalBarChartProps>;
12
13
  private _createSet;
13
- private _legends;
14
+ private _barLegends;
15
+ private _lineLegends;
14
16
  private _xAxisLabels;
15
17
  private _datasetForBars;
16
18
  private margins;
@@ -32,6 +34,8 @@ export declare class GroupedVerticalBarChartBase extends React.Component<IGroupe
32
34
  private _legendsRef;
33
35
  private _legendColorMap;
34
36
  private readonly Y_ORIGIN;
37
+ private _rectRef;
38
+ private _uniqDotId;
35
39
  constructor(props: IGroupedVerticalBarChartProps);
36
40
  componentDidUpdate(prevProps: IGroupedVerticalBarChartProps): void;
37
41
  render(): React.ReactNode;
@@ -76,7 +80,14 @@ export declare class GroupedVerticalBarChartBase extends React.Component<IGroupe
76
80
  private _adjustProps;
77
81
  private _getChartTitle;
78
82
  private _adjustColor;
79
- private _addDefaultColors;
83
+ private _prepareChartData;
80
84
  private _getOrderedXAxisLabels;
81
85
  private _mapCategoryToValues;
86
+ private _createLines;
87
+ private _onLineHover;
88
+ private _onLineFocus;
89
+ private _showCalloutForLines;
90
+ private _showCallout;
91
+ private _getDotId;
92
+ private _processDataV2;
82
93
  }
@@ -27,6 +27,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
27
27
  _this._isRtl = (0, Utilities_1.getRTL)();
28
28
  _this._legendColorMap = {};
29
29
  _this.Y_ORIGIN = 0;
30
+ _this._uniqDotId = (0, Utilities_1.getId)('gvbc_dot_');
30
31
  _this.toImage = function (opts) {
31
32
  var _a, _b;
32
33
  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);
@@ -58,8 +59,8 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
58
59
  var xScale0 = _this._createX0Scale(containerWidth);
59
60
  // Setting the bar width here is safe because there are no dependencies earlier in the code
60
61
  // that rely on the width of bars in vertical bar charts with string x-axis.
61
- _this._barWidth = (0, index_1.getBarWidth)(_this.props.barwidth, _this.props.maxBarWidth, (0, index_1.calcBandwidth)(xScale0.bandwidth(), _this._legends.length, X1_INNER_PADDING));
62
- _this._groupWidth = (0, index_1.calcRequiredWidth)(_this._barWidth, _this._legends.length, X1_INNER_PADDING);
62
+ _this._barWidth = (0, index_1.getBarWidth)(_this.props.barwidth, _this.props.maxBarWidth, (0, index_1.calcBandwidth)(xScale0.bandwidth(), _this._barLegends.length, X1_INNER_PADDING));
63
+ _this._groupWidth = (0, index_1.calcRequiredWidth)(_this._barWidth, _this._barLegends.length, X1_INNER_PADDING);
63
64
  var xScale1 = _this._createX1Scale();
64
65
  // eslint-disable-next-line @typescript-eslint/no-deprecated
65
66
  var allGroupsBars = [];
@@ -69,17 +70,19 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
69
70
  _this._groupedVerticalBarGraph = allGroupsBars;
70
71
  };
71
72
  _this._getMargins = function (margins) { return (_this.margins = margins); };
72
- _this._createDataSetOfGVBC = function (points) {
73
- var legends = new Set();
74
- var xAxisLabels = _this._getOrderedXAxisLabels(points);
75
- points.forEach(function (point) {
73
+ _this._createDataSetOfGVBC = function (barData, lineData) {
74
+ var barLegends = new Set();
75
+ barData.forEach(function (point) {
76
76
  point.series.forEach(function (seriesPoint) {
77
- legends.add(seriesPoint.legend);
77
+ barLegends.add(seriesPoint.legend);
78
78
  });
79
79
  });
80
- var datasetForBars = _this._createDataset(points);
80
+ var lineLegends = new Set(lineData.map(function (series) { return series.legend; }));
81
+ var xAxisLabels = _this._getOrderedXAxisLabels(barData, lineData);
82
+ var datasetForBars = _this._createDataset(barData, lineData);
81
83
  return {
82
- legends: Array.from(legends),
84
+ barLegends: Array.from(barLegends),
85
+ lineLegends: Array.from(lineLegends),
83
86
  xAxisLabels: xAxisLabels,
84
87
  datasetForBars: datasetForBars,
85
88
  };
@@ -95,22 +98,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
95
98
  mouseEvent.persist();
96
99
  if (_this._calloutAnchorPoint !== pointData) {
97
100
  _this._calloutAnchorPoint = pointData;
98
- _this.setState({
99
- refSelected: mouseEvent,
100
- /** Show the callout if highlighted bar is hovered and Hide it if unhighlighted bar is hovered */
101
- isCalloutVisible: _this._noLegendHighlighted() || _this._legendHighlighted(pointData.legend),
102
- calloutLegend: pointData.legend,
103
- dataForHoverCard: pointData.data,
104
- color: pointData.color,
105
- xCalloutValue: pointData.xAxisCalloutData,
106
- yCalloutValue: pointData.yAxisCalloutData,
107
- dataPointCalloutProps: pointData,
108
- callOutAccessibilityData: _this.props.isCalloutForStack
109
- ? groupData.stackCallOutAccessibilityData
110
- : pointData.callOutAccessibilityData,
111
- YValueHover: groupData.groupSeries,
112
- hoverXValue: pointData.xAxisCalloutData,
113
- });
101
+ _this._showCallout(mouseEvent, pointData, groupData);
114
102
  }
115
103
  };
116
104
  _this._onBarLeave = function () {
@@ -123,22 +111,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
123
111
  _this._onBarFocus = function (pointData,
124
112
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
125
113
  groupData, focusEvent) {
126
- _this.setState({
127
- refSelected: focusEvent.currentTarget,
128
- /** Show the callout if highlighted bar is focused and Hide it if unhighlighted bar is focused */
129
- isCalloutVisible: _this._noLegendHighlighted() || _this._legendHighlighted(pointData.legend),
130
- calloutLegend: pointData.legend,
131
- dataForHoverCard: pointData.data,
132
- color: pointData.color,
133
- xCalloutValue: pointData.xAxisCalloutData,
134
- yCalloutValue: pointData.yAxisCalloutData,
135
- dataPointCalloutProps: pointData,
136
- callOutAccessibilityData: _this.props.isCalloutForStack
137
- ? groupData.stackCallOutAccessibilityData
138
- : pointData.callOutAccessibilityData,
139
- YValueHover: groupData.groupSeries,
140
- hoverXValue: pointData.xAxisCalloutData,
141
- });
114
+ _this._showCallout(focusEvent.currentTarget, pointData, groupData);
142
115
  };
143
116
  _this._redirectToUrl = function (href) {
144
117
  href ? (window.location.href = href) : '';
@@ -155,7 +128,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
155
128
  // eslint-disable-next-line @typescript-eslint/no-deprecated
156
129
  var barLabelsForGroup = [];
157
130
  // Get the actual legends present at this x-axis point
158
- var presentLegends = Object.keys(singleSet).filter(function (key) { return key in _this._legendColorMap; });
131
+ var presentLegends = _this._barLegends.filter(function (key) { return key in singleSet; });
159
132
  var effectiveGroupWidth = (0, index_1.calcRequiredWidth)(_this._barWidth, presentLegends.length, X1_INNER_PADDING);
160
133
  // For stacked bars, center the single bar group in the available space
161
134
  // Instead of using the global legend position, use the local position within present legends
@@ -163,7 +136,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
163
136
  .domain(presentLegends)
164
137
  .range(_this._isRtl ? [effectiveGroupWidth, 0] : [0, effectiveGroupWidth])
165
138
  .paddingInner(X1_INNER_PADDING);
166
- _this._legends.forEach(function (legendTitle, legendIndex) {
139
+ _this._barLegends.forEach(function (legendTitle, legendIndex) {
167
140
  var _a;
168
141
  var barPoints = singleSet[legendTitle];
169
142
  if (barPoints) {
@@ -231,10 +204,21 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
231
204
  singleGroup,
232
205
  barLabelsForGroup));
233
206
  };
234
- _this._createDataset = function (points) {
207
+ _this._createDataset = function (barData, lineData) {
235
208
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
236
209
  var datasetForBars = [];
237
- points.forEach(function (point, index) {
210
+ var linePointsByX = {};
211
+ var visitedX = new Set();
212
+ lineData.forEach(function (series) {
213
+ series.data.forEach(function (point) {
214
+ if (!linePointsByX[point.x]) {
215
+ linePointsByX[point.x] = [];
216
+ }
217
+ linePointsByX[point.x].push(tslib_1.__assign(tslib_1.__assign({}, point), { legend: series.legend, color: series.color, data: point.y, useSecondaryYScale: series.useSecondaryYScale }));
218
+ });
219
+ });
220
+ barData.forEach(function (point, index) {
221
+ var _a;
238
222
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
239
223
  var singleDatasetPointForBars = {};
240
224
  var legendToBarPoint = {};
@@ -250,9 +234,18 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
250
234
  });
251
235
  singleDatasetPointForBars.xAxisPoint = point.name;
252
236
  singleDatasetPointForBars.indexNum = index;
253
- singleDatasetPointForBars.groupSeries = Object.values(legendToBarPoint);
237
+ singleDatasetPointForBars.groupSeries = tslib_1.__spreadArray(tslib_1.__spreadArray([], Object.values(legendToBarPoint), true), ((_a = linePointsByX[point.name]) !== null && _a !== void 0 ? _a : []), true);
254
238
  singleDatasetPointForBars.stackCallOutAccessibilityData = point.stackCallOutAccessibilityData;
255
239
  datasetForBars.push(singleDatasetPointForBars);
240
+ visitedX.add(point.name);
241
+ });
242
+ Object.keys(linePointsByX).forEach(function (xPoint) {
243
+ if (!visitedX.has(xPoint)) {
244
+ datasetForBars.push({
245
+ xAxisPoint: xPoint,
246
+ groupSeries: linePointsByX[xPoint],
247
+ });
248
+ }
256
249
  });
257
250
  return datasetForBars;
258
251
  };
@@ -271,7 +264,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
271
264
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
272
265
  _this._createX1Scale = function () {
273
266
  return ((0, d3_scale_1.scaleBand)()
274
- .domain(_this._legends)
267
+ .domain(_this._barLegends)
275
268
  // When there is only one group, xScale0 adds padding around it,
276
269
  // causing the bandwidth to become smaller than the actual group width.
277
270
  // So to render bars in the group correctly, use groupWidth instead of the generated scale bandwidth.
@@ -286,10 +279,11 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
286
279
  // eslint-disable-next-line @typescript-eslint/no-deprecated
287
280
  _this._getLegendData = function () {
288
281
  var actions = [];
289
- _this._legends.forEach(function (legendTitle) {
282
+ var addLegendButton = function (legendTitle, isLineLegendInBarChart) {
290
283
  var legend = {
291
284
  title: legendTitle,
292
285
  color: _this._legendColorMap[legendTitle][0],
286
+ isLineLegendInBarChart: isLineLegendInBarChart,
293
287
  hoverAction: function () {
294
288
  _this._handleChartMouseLeave();
295
289
  _this._onLegendHover(legendTitle);
@@ -299,7 +293,9 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
299
293
  },
300
294
  };
301
295
  actions.push(legend);
302
- });
296
+ };
297
+ _this._lineLegends.forEach(function (legendTitle) { return addLegendButton(legendTitle, true); });
298
+ _this._barLegends.forEach(function (legendTitle) { return addLegendButton(legendTitle); });
303
299
  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 })));
304
300
  };
305
301
  _this._getAxisData = function (yAxisData) {
@@ -344,7 +340,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
344
340
  // Update the bar width so that when CartesianChart rerenders,
345
341
  // the following calculations don't use the previous bar width.
346
342
  _this._barWidth = (0, index_1.getBarWidth)(_this.props.barwidth, _this.props.maxBarWidth);
347
- var groupWidth = (0, index_1.calcRequiredWidth)(_this._barWidth, _this._legends.length, X1_INNER_PADDING);
343
+ var groupWidth = (0, index_1.calcRequiredWidth)(_this._barWidth, _this._barLegends.length, X1_INNER_PADDING);
348
344
  /** Total width required to render the groups. Directly proportional to group width */
349
345
  var reqWidth = (0, index_1.calcRequiredWidth)(groupWidth, _this._xAxisLabels.length, _this._xAxisInnerPadding);
350
346
  if (totalWidth >= reqWidth) {
@@ -355,9 +351,9 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
355
351
  else if (_this.props.mode === 'plotly' && _this._xAxisLabels.length > 1) {
356
352
  // Calculate the remaining width after rendering groups at their maximum allowable width
357
353
  var groupBandwidth = (0, index_1.calcBandwidth)(totalWidth, _this._xAxisLabels.length, _this._xAxisInnerPadding);
358
- var barBandwidth = (0, index_1.calcBandwidth)(groupBandwidth, _this._legends.length, X1_INNER_PADDING);
354
+ var barBandwidth = (0, index_1.calcBandwidth)(groupBandwidth, _this._barLegends.length, X1_INNER_PADDING);
359
355
  var barWidth = (0, index_1.getBarWidth)(_this.props.barwidth, _this.props.maxBarWidth, barBandwidth);
360
- var groupWidth = (0, index_1.calcRequiredWidth)(barWidth, _this._legends.length, X1_INNER_PADDING);
356
+ var groupWidth = (0, index_1.calcRequiredWidth)(barWidth, _this._barLegends.length, X1_INNER_PADDING);
361
357
  var reqWidth = (0, index_1.calcRequiredWidth)(groupWidth, _this._xAxisLabels.length, _this._xAxisInnerPadding);
362
358
  var margin1 = (totalWidth - reqWidth) / 2;
363
359
  // Calculate the remaining width after accounting for the space required to render x-axis labels
@@ -372,7 +368,8 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
372
368
  _this._getChartTitle = function () {
373
369
  var chartTitle = _this.props.chartTitle;
374
370
  return ((chartTitle ? "".concat(chartTitle, ". ") : '') +
375
- "Vertical bar chart with ".concat(_this._xAxisLabels.length, " groups of ").concat(_this._legends.length, " bars each. "));
371
+ "Vertical bar chart with ".concat(_this._barLegends.length, " grouped bar series") +
372
+ (_this._lineLegends.length > 0 ? " and ".concat(_this._lineLegends.length, " line series. ") : '. '));
376
373
  };
377
374
  // Lighten/Darken a color by a given percentage using d3-scale
378
375
  _this._adjustColor = function (color, percentage, lightenColor, isDarkTheme) {
@@ -380,48 +377,71 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
380
377
  var colorInterpolator = (0, d3_scale_1.scaleLinear)().domain([0, 1]).range([color, targetColor]);
381
378
  return (0, d3_color_1.rgb)(colorInterpolator(percentage)).formatRgb();
382
379
  };
383
- _this._addDefaultColors = function (data) {
380
+ _this._prepareChartData = function () {
384
381
  var _a;
382
+ var _b, _c;
383
+ var barData = _this.props.data;
384
+ var lineData;
385
+ if (Array.isArray(_this.props.dataV2) && _this.props.dataV2.length > 0) {
386
+ (_a = _this._processDataV2(_this.props.dataV2), barData = _a.barData, lineData = _a.lineData);
387
+ }
385
388
  _this._legendColorMap = {};
386
389
  var colorIndex = 0;
387
- return ((_a = data === null || data === void 0 ? void 0 : data.map(function (point) {
388
- var _a, _b;
389
- return tslib_1.__assign(tslib_1.__assign({}, point), { series: (_b = (_a = point.series) === null || _a === void 0 ? void 0 : _a.map(function (seriesPoint) {
390
- var _a, _b, _c, _d, _e, _f, _g;
391
- var startColor = seriesPoint.color
392
- ? seriesPoint.color
393
- : (0, index_1.getNextColor)(colorIndex, 0, (_a = _this.props.theme) === null || _a === void 0 ? void 0 : _a.isInverted);
394
- var endColor = startColor;
395
- if (_this.props.enableGradient) {
396
- if (seriesPoint.color) {
397
- // Generate gradient colors based on seriesPoint.color
398
- startColor = _this._adjustColor(seriesPoint.color || endColor, 0.2, false, (_b = _this.props.theme) === null || _b === void 0 ? void 0 : _b.isInverted);
399
- endColor = _this._adjustColor(seriesPoint.color || startColor, 0.2, true, (_c = _this.props.theme) === null || _c === void 0 ? void 0 : _c.isInverted);
390
+ return {
391
+ barData: (_b = barData === null || barData === void 0 ? void 0 : barData.map(function (point) {
392
+ var _a, _b;
393
+ return tslib_1.__assign(tslib_1.__assign({}, point), { series: (_b = (_a = point.series) === null || _a === void 0 ? void 0 : _a.map(function (seriesPoint) {
394
+ var _a, _b, _c, _d, _e, _f, _g;
395
+ var startColor = seriesPoint.color
396
+ ? seriesPoint.color
397
+ : (0, index_1.getNextColor)(colorIndex, 0, (_a = _this.props.theme) === null || _a === void 0 ? void 0 : _a.isInverted);
398
+ var endColor = startColor;
399
+ if (_this.props.enableGradient) {
400
+ if (seriesPoint.color) {
401
+ // Generate gradient colors based on seriesPoint.color
402
+ startColor = _this._adjustColor(seriesPoint.color || endColor, 0.2, false, (_b = _this.props.theme) === null || _b === void 0 ? void 0 : _b.isInverted);
403
+ endColor = _this._adjustColor(seriesPoint.color || startColor, 0.2, true, (_c = _this.props.theme) === null || _c === void 0 ? void 0 : _c.isInverted);
404
+ }
405
+ else {
406
+ var nextGradient = (0, index_1.getNextGradient)(colorIndex, 0, (_d = _this.props.theme) === null || _d === void 0 ? void 0 : _d.isInverted);
407
+ startColor = ((_e = seriesPoint.gradient) === null || _e === void 0 ? void 0 : _e[0]) || nextGradient[0];
408
+ endColor = ((_f = seriesPoint.gradient) === null || _f === void 0 ? void 0 : _f[1]) || nextGradient[1];
409
+ }
400
410
  }
401
- else {
402
- var nextGradient = (0, index_1.getNextGradient)(colorIndex, 0, (_d = _this.props.theme) === null || _d === void 0 ? void 0 : _d.isInverted);
403
- startColor = ((_e = seriesPoint.gradient) === null || _e === void 0 ? void 0 : _e[0]) || nextGradient[0];
404
- endColor = ((_f = seriesPoint.gradient) === null || _f === void 0 ? void 0 : _f[1]) || nextGradient[1];
411
+ var pointGradient = [startColor, endColor];
412
+ if (!_this._legendColorMap[seriesPoint.legend]) {
413
+ _this._legendColorMap[seriesPoint.legend] = [startColor, endColor];
405
414
  }
406
- }
407
- var pointGradient = [startColor, endColor];
408
- if (!_this._legendColorMap[seriesPoint.legend]) {
409
- _this._legendColorMap[seriesPoint.legend] = [startColor, endColor];
410
- }
411
- colorIndex += 1;
412
- return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, seriesPoint), { color: (_g = seriesPoint.color) !== null && _g !== void 0 ? _g : _this._legendColorMap[seriesPoint.legend][0] }), (_this.props.enableGradient ? { gradient: pointGradient } : {}));
413
- })) !== null && _b !== void 0 ? _b : [] });
414
- })) !== null && _a !== void 0 ? _a : []);
415
+ colorIndex += 1;
416
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, seriesPoint), { color: (_g = seriesPoint.color) !== null && _g !== void 0 ? _g : _this._legendColorMap[seriesPoint.legend][0] }), (_this.props.enableGradient ? { gradient: pointGradient } : {}));
417
+ })) !== null && _b !== void 0 ? _b : [] });
418
+ })) !== null && _b !== void 0 ? _b : [],
419
+ lineData: (_c = lineData === null || lineData === void 0 ? void 0 : lineData.map(function (series) {
420
+ var _a, _b;
421
+ var color;
422
+ if (typeof series.color === 'undefined') {
423
+ color = (0, index_1.getNextColor)(colorIndex, 0, (_a = _this.props.theme) === null || _a === void 0 ? void 0 : _a.isInverted);
424
+ }
425
+ else {
426
+ color = (0, index_1.getColorFromToken)(series.color, (_b = _this.props.theme) === null || _b === void 0 ? void 0 : _b.isInverted);
427
+ }
428
+ if (!_this._legendColorMap[series.legend]) {
429
+ _this._legendColorMap[series.legend] = [color, color];
430
+ }
431
+ colorIndex += 1;
432
+ return tslib_1.__assign(tslib_1.__assign({}, series), { color: _this._legendColorMap[series.legend][0] });
433
+ })) !== null && _c !== void 0 ? _c : [],
434
+ };
415
435
  };
416
- _this._getOrderedXAxisLabels = function (points) {
436
+ _this._getOrderedXAxisLabels = function (barData, lineData) {
417
437
  if (_this._xAxisType !== index_1.XAxisTypes.StringAxis) {
418
438
  return [];
419
439
  }
420
- return (0, index_1.sortAxisCategories)(_this._mapCategoryToValues(points), _this.props.xAxisCategoryOrder);
440
+ return (0, index_1.sortAxisCategories)(_this._mapCategoryToValues(barData, lineData), _this.props.xAxisCategoryOrder);
421
441
  };
422
- _this._mapCategoryToValues = function (points) {
442
+ _this._mapCategoryToValues = function (barData, lineData) {
423
443
  var categoryToValues = {};
424
- points.forEach(function (point) {
444
+ barData.forEach(function (point) {
425
445
  if (!categoryToValues[point.name]) {
426
446
  categoryToValues[point.name] = [];
427
447
  }
@@ -429,10 +449,143 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
429
449
  categoryToValues[point.name].push(seriesPoint.data);
430
450
  });
431
451
  });
452
+ lineData.forEach(function (series) {
453
+ series.data.forEach(function (point) {
454
+ if (!categoryToValues[point.x]) {
455
+ categoryToValues[point.x] = [];
456
+ }
457
+ categoryToValues[point.x].push(point.y);
458
+ });
459
+ });
432
460
  return categoryToValues;
433
461
  };
462
+ _this._createLines = function (lineData, xScale, yScalePrimary, yScaleSecondary) {
463
+ var lineBorders = [];
464
+ var lines = [];
465
+ var dots = [];
466
+ var scaleLineX = function (x) { return xScale(x) + xScale.bandwidth() / 2; };
467
+ lineData.forEach(function (series, seriesIdx) {
468
+ var _a;
469
+ var lineBorderGroup = [];
470
+ var lineGroup = [];
471
+ var dotGroup = [];
472
+ var lineBorderWidth = ((_a = series.lineOptions) === null || _a === void 0 ? void 0 : _a.lineBorderWidth)
473
+ ? Number.parseFloat(series.lineOptions.lineBorderWidth.toString())
474
+ : 0;
475
+ var yScale = series.useSecondaryYScale && yScaleSecondary ? yScaleSecondary : yScalePrimary;
476
+ var shouldHighlight = _this._legendHighlighted(series.legend) || _this._noLegendHighlighted();
477
+ series.data.forEach(function (point, pointIdx) {
478
+ var _a, _b, _c, _d, _e, _f, _g;
479
+ var x2 = scaleLineX(point.x);
480
+ var y2 = yScale(point.y);
481
+ if (pointIdx > 0) {
482
+ var x1 = scaleLineX(series.data[pointIdx - 1].x);
483
+ var y1 = yScale(series.data[pointIdx - 1].y);
484
+ if (lineBorderWidth > 0) {
485
+ lineBorderGroup.push(React.createElement("line", { key: "lineBorder-".concat(seriesIdx, "-").concat(pointIdx), x1: x1, y1: y1, x2: x2, y2: y2, fill: "transparent", stroke: (_b = (_a = series.lineOptions) === null || _a === void 0 ? void 0 : _a.lineBorderColor) !== null && _b !== void 0 ? _b : _this.props.theme.semanticColors.bodyBackground, strokeWidth: 3 + lineBorderWidth * 2, strokeLinecap: "round", opacity: shouldHighlight ? 1 : 0.1 }));
486
+ }
487
+ lineGroup.push(React.createElement("line", { key: "line-".concat(seriesIdx, "-").concat(pointIdx), x1: x1, y1: y1, x2: x2, y2: y2, stroke: series.color, strokeWidth: (_d = (_c = series.lineOptions) === null || _c === void 0 ? void 0 : _c.strokeWidth) !== null && _d !== void 0 ? _d : 3, strokeLinecap: (_f = (_e = series.lineOptions) === null || _e === void 0 ? void 0 : _e.strokeLinecap) !== null && _f !== void 0 ? _f : 'round', strokeDasharray: (_g = series.lineOptions) === null || _g === void 0 ? void 0 : _g.strokeDasharray, opacity: shouldHighlight ? 1 : 0.1, onMouseOver: function (e) { return _this._onLineHover(e, series, seriesIdx, pointIdx, scaleLineX); }, onMouseLeave: _this._onBarLeave }));
488
+ }
489
+ var dotId = _this._getDotId(seriesIdx, pointIdx);
490
+ var activeLinePoint = _this.state.activeLinePoint;
491
+ var isLinePointActive = activeLinePoint === point.x || activeLinePoint === dotId;
492
+ dotGroup.push(React.createElement("circle", { key: dotId, id: dotId, cx: x2, cy: y2, r: shouldHighlight && isLinePointActive ? 8 : 0.3, fill: _this.props.theme.semanticColors.bodyBackground, stroke: series.color, strokeWidth: 3, opacity: shouldHighlight ? 1 : 0.1, onMouseOver: function (e) { return _this._onLineHover(e, series, seriesIdx, pointIdx, scaleLineX); }, onMouseLeave: _this._onBarLeave, "data-is-focusable": shouldHighlight, onFocus: function (e) { return _this._onLineFocus(e, series, seriesIdx, pointIdx); }, onBlur: _this._onBarLeave, role: "img", "aria-label": _this._getAriaLabel({
493
+ xAxisCalloutData: point.xAxisCalloutData,
494
+ legend: series.legend,
495
+ yAxisCalloutData: point.yAxisCalloutData,
496
+ data: point.y,
497
+ callOutAccessibilityData: point.callOutAccessibilityData,
498
+ }, point.x) }));
499
+ });
500
+ lineBorders.push(React.createElement("g", { key: "lineBorderGroup-".concat(seriesIdx) }, lineBorderGroup));
501
+ lines.push(React.createElement("g", { key: "lineGroup-".concat(seriesIdx) }, lineGroup));
502
+ dots.push(React.createElement("g", { key: "dotGroup-".concat(seriesIdx) }, dotGroup));
503
+ });
504
+ return dots.length > 0 ? (React.createElement("g", null,
505
+ lineBorders.length > 0 ? React.createElement("g", null, lineBorders) : null,
506
+ lines.length > 0 ? React.createElement("g", null, lines) : null,
507
+ React.createElement("g", null, dots))) : null;
508
+ };
509
+ _this._onLineHover = function (event, series, seriesIdx, pointIdx, scaleLineX) {
510
+ var pointerX = (0, d3_selection_1.pointer)(event, _this._rectRef.current)[0];
511
+ var closestPointIdx = pointIdx;
512
+ if (pointIdx > 0) {
513
+ var currPointPos = scaleLineX(series.data[pointIdx].x);
514
+ var prevPointPos = scaleLineX(series.data[pointIdx - 1].x);
515
+ if (Math.abs(prevPointPos - pointerX) < Math.abs(currPointPos - pointerX)) {
516
+ closestPointIdx = pointIdx - 1;
517
+ }
518
+ }
519
+ event.persist();
520
+ _this._showCalloutForLines(event, series, seriesIdx, closestPointIdx);
521
+ };
522
+ _this._onLineFocus = function (event, series, seriesIdx, pointIdx) {
523
+ _this._showCalloutForLines(event.currentTarget, series, seriesIdx, pointIdx);
524
+ };
525
+ _this._showCalloutForLines = function (target, series, seriesIdx, pointIdx) {
526
+ var point = series.data[pointIdx];
527
+ var pointData = tslib_1.__assign(tslib_1.__assign({}, point), { legend: series.legend, color: series.color, key: series.legend, data: point.y, yAxisCalloutData: point.yAxisCalloutData });
528
+ var groupData = _this._datasetForBars.find(function (singleSet) { return singleSet.xAxisPoint === point.x; });
529
+ _this._showCallout(target, pointData, groupData, _this._getDotId(seriesIdx, pointIdx));
530
+ };
531
+ _this._showCallout = function (target, pointData,
532
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
533
+ groupData, activeLinePoint) {
534
+ var _a, _b;
535
+ if (activeLinePoint === void 0) { activeLinePoint = ''; }
536
+ _this.setState({
537
+ refSelected: target,
538
+ isCalloutVisible: _this._noLegendHighlighted() || _this._legendHighlighted(pointData.legend),
539
+ calloutLegend: pointData.legend,
540
+ dataForHoverCard: pointData.data,
541
+ color: pointData.color,
542
+ xCalloutValue: (_a = pointData.xAxisCalloutData) !== null && _a !== void 0 ? _a : groupData.xAxisPoint,
543
+ yCalloutValue: pointData.yAxisCalloutData,
544
+ dataPointCalloutProps: pointData,
545
+ callOutAccessibilityData: _this.props.isCalloutForStack
546
+ ? groupData.stackCallOutAccessibilityData
547
+ : pointData.callOutAccessibilityData,
548
+ YValueHover: groupData.groupSeries.filter(function (item) { return _this._noLegendHighlighted() || _this._legendHighlighted(item.legend); }),
549
+ hoverXValue: (_b = pointData.xAxisCalloutData) !== null && _b !== void 0 ? _b : groupData.xAxisPoint,
550
+ activeLinePoint: _this.props.isCalloutForStack ? groupData.xAxisPoint : activeLinePoint,
551
+ });
552
+ };
553
+ _this._getDotId = function (seriesIdx, pointIdx) {
554
+ return _this._uniqDotId + "-".concat(seriesIdx, "-").concat(pointIdx);
555
+ };
556
+ _this._processDataV2 = function (dataV2) {
557
+ var barPointsByX = {};
558
+ var lineData = [];
559
+ dataV2.forEach(function (series) {
560
+ if (series.type === 'bar') {
561
+ series.data.forEach(function (point) {
562
+ var _a, _b;
563
+ if (!barPointsByX[point.x]) {
564
+ barPointsByX[point.x] = { name: point.x, series: [] };
565
+ }
566
+ barPointsByX[point.x].series.push({
567
+ key: (_a = series.key) !== null && _a !== void 0 ? _a : series.legend,
568
+ data: point.y,
569
+ color: (_b = point.color) !== null && _b !== void 0 ? _b : series.color,
570
+ gradient: series.gradient,
571
+ legend: series.legend,
572
+ xAxisCalloutData: point.xAxisCalloutData,
573
+ yAxisCalloutData: point.yAxisCalloutData,
574
+ onClick: point.onClick,
575
+ useSecondaryYScale: series.useSecondaryYScale,
576
+ });
577
+ });
578
+ }
579
+ else if (series.type === 'line') {
580
+ lineData.push(series);
581
+ }
582
+ });
583
+ return { barData: Object.values(barPointsByX), lineData: lineData };
584
+ };
434
585
  (0, Utilities_1.initializeComponentRef)(_this);
435
- _this._createSet = (0, Utilities_1.memoizeFunction)(function (data) { return _this._createDataSetOfGVBC(data); });
586
+ _this._createSet = (0, Utilities_1.memoizeFunction)(function (barData, lineData) {
587
+ return _this._createDataSetOfGVBC(barData, lineData);
588
+ });
436
589
  _this.state = {
437
590
  color: '',
438
591
  dataForHoverCard: 0,
@@ -445,6 +598,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
445
598
  hoverXValue: '',
446
599
  calloutLegend: '',
447
600
  activeLegend: '',
601
+ activeLinePoint: '',
448
602
  };
449
603
  (0, Utilities_1.warnDeprecations)(COMPONENT_NAME, props, {
450
604
  showYAxisGridLines: 'Dont use this property. Lines are drawn by default',
@@ -459,6 +613,7 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
459
613
  _this._domainMargin = MIN_DOMAIN_MARGIN;
460
614
  _this._cartesianChartRef = React.createRef();
461
615
  _this._legendsRef = React.createRef();
616
+ _this._rectRef = React.createRef();
462
617
  return _this;
463
618
  }
464
619
  GroupedVerticalBarChartBase.prototype.componentDidUpdate = function (prevProps) {
@@ -471,10 +626,11 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
471
626
  };
472
627
  GroupedVerticalBarChartBase.prototype.render = function () {
473
628
  var _this = this;
474
- var points = this._addDefaultColors(this.props.data);
475
- this._xAxisType = (0, index_1.getTypeOfAxis)(points[0].name, true);
476
- var _a = this._createSet(points), legends = _a.legends, xAxisLabels = _a.xAxisLabels, datasetForBars = _a.datasetForBars;
477
- this._legends = legends;
629
+ var _a = this._prepareChartData(), barData = _a.barData, lineData = _a.lineData;
630
+ this._xAxisType = (0, index_1.getTypeOfAxis)(barData[0].name, true);
631
+ var _b = this._createSet(barData, lineData), barLegends = _b.barLegends, lineLegends = _b.lineLegends, xAxisLabels = _b.xAxisLabels, datasetForBars = _b.datasetForBars;
632
+ this._barLegends = barLegends;
633
+ this._lineLegends = lineLegends;
478
634
  this._xAxisLabels = xAxisLabels;
479
635
  this._datasetForBars = datasetForBars;
480
636
  // eslint-disable-next-line @typescript-eslint/no-deprecated
@@ -494,15 +650,18 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
494
650
  tickValues: this.props.tickValues,
495
651
  tickFormat: this.props.tickFormat,
496
652
  };
497
- 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: {
653
+ return !this._isChartEmpty(barData, lineData) ? (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: {
498
654
  direction: react_focus_1.FocusZoneDirection.horizontal,
499
655
  }, customizedCallout: this._getCustomizedCallout(), getmargins: this._getMargins, getGraphData: this._getGraphData, getAxisData: this._getAxisData, onChartMouseLeave: this._handleChartMouseLeave, getDomainMargins: this._getDomainMargins }, (this._xAxisType === index_1.XAxisTypes.StringAxis && {
500
656
  xAxisInnerPadding: this._xAxisInnerPadding,
501
657
  xAxisOuterPadding: this._xAxisOuterPadding,
502
658
  }), { barwidth: this._barWidth, ref: this._cartesianChartRef,
503
659
  /* eslint-disable react/jsx-no-bind */
504
- children: function () {
505
- return React.createElement("g", null, _this._groupedVerticalBarGraph);
660
+ children: function (props) {
661
+ return (React.createElement(React.Fragment, null,
662
+ React.createElement("rect", { ref: _this._rectRef, width: "100%", height: "100%", fill: "transparent", style: { pointerEvents: 'none' } }),
663
+ React.createElement("g", null, _this._groupedVerticalBarGraph),
664
+ _this._createLines(lineData, props.xScale, props.yScalePrimary, props.yScaleSecondary)));
506
665
  } }))) : (React.createElement("div", { id: this._emptyChartId, role: 'alert', style: { opacity: '0' }, "aria-label": 'Graph has no data to display' }));
507
666
  };
508
667
  Object.defineProperty(GroupedVerticalBarChartBase.prototype, "chartContainer", {
@@ -542,17 +701,18 @@ var GroupedVerticalBarChartBase = /** @class */ (function (_super) {
542
701
  ? [this.state.activeLegend]
543
702
  : [];
544
703
  };
545
- GroupedVerticalBarChartBase.prototype._isChartEmpty = function () {
546
- return !(this.props.data &&
547
- this.props.data.length > 0 &&
548
- this.props.data.filter(function (item) { return item.series.length; }).length > 0);
704
+ GroupedVerticalBarChartBase.prototype._isChartEmpty = function (barData, lineData) {
705
+ return !((barData &&
706
+ barData.length > 0 &&
707
+ barData.filter(function (item) { return item.series.length; }).length > 0) ||
708
+ (lineData && lineData.length > 0 && lineData.some(function (series) { return series.data.length > 0; })));
549
709
  };
550
710
  GroupedVerticalBarChartBase.prototype._adjustProps = function () {
551
711
  this._barWidth = (0, index_1.getBarWidth)(this.props.barwidth, this.props.maxBarWidth);
552
712
  // x0_inner_padding = space_between_groups / (space_between_groups + group_width)
553
713
  // space_between_groups = 2 * bar_width
554
714
  // group_width = this._legends.length * bar_width + (this._legends.length - 1) * space_between_bars
555
- this._xAxisInnerPadding = (0, index_1.getScalePadding)(this.props.xAxisInnerPadding, undefined, 2 / (2 + (0, index_1.calcTotalBandUnits)(this._legends.length, X1_INNER_PADDING)));
715
+ this._xAxisInnerPadding = (0, index_1.getScalePadding)(this.props.xAxisInnerPadding, undefined, 2 / (2 + (0, index_1.calcTotalBandUnits)(this._barLegends.length, X1_INNER_PADDING)));
556
716
  this._xAxisOuterPadding = (0, index_1.getScalePadding)(this.props.xAxisOuterPadding);
557
717
  };
558
718
  GroupedVerticalBarChartBase.defaultProps = {