@fluentui/react-charting 5.23.85 → 5.23.86

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 (26) hide show
  1. package/CHANGELOG.json +34 -1
  2. package/CHANGELOG.md +14 -2
  3. package/dist/react-charting.js +1 -1
  4. package/dist/react-charting.min.js +1 -1
  5. package/lib/components/DeclarativeChart/DeclarativeChart.js +8 -3
  6. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  7. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +4 -3
  8. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  9. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +1 -2
  10. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +53 -47
  11. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  12. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js +7 -2
  13. package/lib-amd/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  14. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js +3 -2
  15. package/lib-amd/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  16. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +1 -2
  17. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +53 -47
  18. package/lib-amd/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  19. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +7 -2
  20. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  21. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +3 -2
  22. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  23. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.d.ts +1 -2
  24. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js +53 -47
  25. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.base.js.map +1 -1
  26. package/package.json +2 -2
@@ -18,11 +18,6 @@ var COMPONENT_NAME = 'VERTICAL STACKED BAR CHART';
18
18
  var barGapMultiplier = 0.2;
19
19
  var barGapMin = 1;
20
20
  var MIN_DOMAIN_MARGIN = 8;
21
- var CircleVisbility;
22
- (function (CircleVisbility) {
23
- CircleVisbility["show"] = "visibility";
24
- CircleVisbility["hide"] = "hidden";
25
- })(CircleVisbility || (CircleVisbility = {}));
26
21
  var VerticalStackedBarChartBase = /** @class */ (function (_super) {
27
22
  __extends(VerticalStackedBarChartBase, _super);
28
23
  function VerticalStackedBarChartBase(props) {
@@ -132,23 +127,28 @@ var VerticalStackedBarChartBase = /** @class */ (function (_super) {
132
127
  if (lineBorderWidth > 0) {
133
128
  borderForLines.push(React.createElement("line", { key: "".concat(index, "-").concat(i, "-BorderLine"), x1: x1, y1: y1, x2: x2, y2: y2, opacity: shouldHighlight ? 1 : 0.1, strokeWidth: 3 + lineBorderWidth * 2, fill: "transparent", strokeLinecap: "round", stroke: theme.semanticColors.bodyBackground, transform: "translate(".concat(xScaleBandwidthTranslate, ", 0)") }));
134
129
  }
135
- lines.push(React.createElement("line", __assign({ key: "".concat(index, "-").concat(i, "-line"), x1: x1, y1: y1, x2: x2, y2: y2, opacity: shouldHighlight ? 1 : 0.1, strokeWidth: (_b = (_a = lineObject[item][0].lineOptions) === null || _a === void 0 ? void 0 : _a.strokeWidth) !== null && _b !== void 0 ? _b : 3, strokeLinecap: (_d = (_c = lineObject[item][0].lineOptions) === null || _c === void 0 ? void 0 : _c.strokeLinecap) !== null && _d !== void 0 ? _d : 'round', strokeDasharray: (_e = lineObject[item][0].lineOptions) === null || _e === void 0 ? void 0 : _e.strokeDasharray, stroke: lineObject[item][i].color, transform: "translate(".concat(xScaleBandwidthTranslate, ", 0)") }, (_this._isLegendHighlighted(item) && {
136
- onMouseOver: _this._lineHover.bind(_this, lineObject[item][i - 1]),
137
- onMouseLeave: _this._lineHoverOut,
138
- }))));
130
+ lines.push(React.createElement("line", { key: "".concat(index, "-").concat(i, "-line"), x1: x1, y1: y1, x2: x2, y2: y2, opacity: shouldHighlight ? 1 : 0.1, strokeWidth: (_b = (_a = lineObject[item][0].lineOptions) === null || _a === void 0 ? void 0 : _a.strokeWidth) !== null && _b !== void 0 ? _b : 3, strokeLinecap: (_d = (_c = lineObject[item][0].lineOptions) === null || _c === void 0 ? void 0 : _c.strokeLinecap) !== null && _d !== void 0 ? _d : 'round', strokeDasharray: (_e = lineObject[item][0].lineOptions) === null || _e === void 0 ? void 0 : _e.strokeDasharray, stroke: lineObject[item][i].color, transform: "translate(".concat(xScaleBandwidthTranslate, ", 0)"), onMouseOver: _this._lineHover.bind(_this, lineObject[item][i - 1]), onMouseLeave: _this._handleMouseOut }));
139
131
  }
140
132
  });
141
133
  Object.keys(lineObject).forEach(function (item, index) {
142
134
  lineObject[item].forEach(function (circlePoint, subIndex) {
143
135
  // Create an object to store line point ref so that the object can be passed by reference to the focus handler
144
136
  var circleRef = { refElement: null };
137
+ var noBarsActive = circlePoint.xItem.chartData.filter(function (dataPoint) { return _this._noLegendHighlighted() || _this._isLegendHighlighted(dataPoint.legend); }).length === 0;
145
138
  dots.push(React.createElement("circle", __assign({ key: "".concat(index, "-").concat(subIndex, "-dot"), cx: xScale(circlePoint.xItem.xAxisPoint), cy: circlePoint.useSecondaryYScale && yScaleSecondary
146
139
  ? yScaleSecondary(circlePoint.y)
147
- : yScalePrimary(circlePoint.y), onMouseOver: _this._isLegendHighlighted(item)
148
- ? _this._lineHover.bind(_this, circlePoint)
149
- : _this._onStackHover.bind(_this, circlePoint.xItem) }, (_this._isLegendHighlighted(item) && {
150
- onMouseLeave: _this._lineHoverOut,
151
- }), { r: _this._getCircleVisibilityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).radius, stroke: circlePoint.color, fill: _this.props.theme.semanticColors.bodyBackground, strokeWidth: 3, visibility: _this._getCircleVisibilityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).visibility, transform: "translate(".concat(xScaleBandwidthTranslate, ", 0)"), "data-is-focusable": _this._isLegendHighlighted(item), ref: function (e) { return (circleRef.refElement = e); }, onFocus: _this._lineFocus.bind(_this, circlePoint, circleRef), onBlur: _this._lineHoverOut })));
140
+ : yScalePrimary(circlePoint.y), onMouseOver: _this._lineHover.bind(_this, circlePoint), onMouseLeave: _this._handleMouseOut, r: _this._getCircleOpacityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).radius, stroke: circlePoint.color, fill: _this.props.theme.semanticColors.bodyBackground, strokeWidth: 3,
141
+ // Elements with visibility: hidden cannot receive focus, so use opacity: 0 instead to hide them.
142
+ // For more information, see https://fuzzbomb.github.io/accessibility-demos/visually-hidden-focus-test.html
143
+ opacity: _this._getCircleOpacityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).opacity, transform: "translate(".concat(xScaleBandwidthTranslate, ", 0)"), ref: function (e) { return (circleRef.refElement = e); } }, (noBarsActive && (_this._noLegendHighlighted() || _this._isLegendHighlighted(item))
144
+ ? {
145
+ 'data-is-focusable': !_this.props.hideTooltip,
146
+ onFocus: _this._lineFocus.bind(_this, circlePoint, circleRef),
147
+ onBlur: _this._handleMouseOut,
148
+ role: 'img',
149
+ 'aria-label': _this._getAriaLabel(circlePoint.xItem, circlePoint, true),
150
+ }
151
+ : {}))));
152
152
  });
153
153
  });
154
154
  return (React.createElement(React.Fragment, null,
@@ -156,22 +156,22 @@ var VerticalStackedBarChartBase = /** @class */ (function (_super) {
156
156
  lines,
157
157
  dots));
158
158
  };
159
- _this._getCircleVisibilityAndRadius = function (xAxisPoint, legend) {
159
+ _this._getCircleOpacityAndRadius = function (xAxisPoint, legend) {
160
160
  var activeXAxisDataPoint = _this.state.activeXAxisDataPoint;
161
161
  if (!_this._noLegendHighlighted()) {
162
162
  if (xAxisPoint === activeXAxisDataPoint && _this._isLegendHighlighted(legend)) {
163
- return { visibility: CircleVisbility.show, radius: 8 };
163
+ return { opacity: 1, radius: 8 };
164
164
  }
165
165
  else if (_this._isLegendHighlighted(legend)) {
166
- return { visibility: CircleVisbility.show, radius: 0.3 };
166
+ return { opacity: 1, radius: 0.3 };
167
167
  }
168
168
  else {
169
- return { visibility: CircleVisbility.hide, radius: 0 };
169
+ return { opacity: 0, radius: 0 };
170
170
  }
171
171
  }
172
172
  else {
173
173
  return {
174
- visibility: activeXAxisDataPoint === xAxisPoint ? CircleVisbility.show : CircleVisbility.hide,
174
+ opacity: activeXAxisDataPoint === xAxisPoint ? 1 : 0,
175
175
  radius: 8,
176
176
  };
177
177
  }
@@ -191,30 +191,27 @@ var VerticalStackedBarChartBase = /** @class */ (function (_super) {
191
191
  mouseEvent.persist();
192
192
  _this._lineHoverFocus(lineData, mouseEvent);
193
193
  };
194
- _this._lineHoverOut = function () {
195
- _this.setState({
196
- refSelected: null,
197
- isCalloutVisible: false,
198
- xCalloutValue: '',
199
- yCalloutValue: '',
200
- activeXAxisDataPoint: '',
201
- color: '',
202
- });
203
- };
204
194
  _this._lineFocus = function (lineData, ref) {
205
195
  if (ref.refElement) {
206
196
  _this._lineHoverFocus(lineData, ref.refElement);
207
197
  }
208
198
  };
209
199
  _this._lineHoverFocus = function (lineData, refSelected) {
210
- _this.setState({
211
- refSelected: refSelected,
212
- isCalloutVisible: true,
213
- xCalloutValue: "".concat(lineData.xItem.xAxisPoint),
214
- yCalloutValue: "".concat(lineData.yAxisCalloutData || lineData.data || lineData.y),
215
- activeXAxisDataPoint: lineData.xItem.xAxisPoint,
216
- color: lineData.color,
217
- });
200
+ if (_this._getHighlightedLegend().length === 1) {
201
+ if (_this._noLegendHighlighted() || _this._isLegendHighlighted(lineData.legend)) {
202
+ _this.setState({
203
+ refSelected: refSelected,
204
+ isCalloutVisible: true,
205
+ xCalloutValue: "".concat(lineData.xItem.xAxisPoint),
206
+ yCalloutValue: "".concat(lineData.yAxisCalloutData || lineData.data || lineData.y),
207
+ activeXAxisDataPoint: lineData.xItem.xAxisPoint,
208
+ color: lineData.color,
209
+ });
210
+ }
211
+ }
212
+ else {
213
+ _this._onStackHoverFocus(lineData.xItem, refSelected);
214
+ }
218
215
  };
219
216
  _this._handleMouseOut = function () {
220
217
  /**/
@@ -275,8 +272,9 @@ var VerticalStackedBarChartBase = /** @class */ (function (_super) {
275
272
  shouldHighlight: shouldHighlight,
276
273
  href: _this.props.href,
277
274
  });
278
- var rectFocusProps = !shouldFocusWholeStack && {
279
- 'data-is-focusable': !_this.props.hideTooltip && shouldHighlight,
275
+ var rectFocusProps = !shouldFocusWholeStack &&
276
+ shouldHighlight && {
277
+ 'data-is-focusable': !_this.props.hideTooltip,
280
278
  'aria-label': _this._getAriaLabel(singleChartData, point),
281
279
  onMouseOver: _this._onRectHover.bind(_this, singleChartData.xAxisPoint, point, startColor),
282
280
  onMouseMove: _this._onRectHover.bind(_this, singleChartData.xAxisPoint, point, startColor),
@@ -323,7 +321,12 @@ var VerticalStackedBarChartBase = /** @class */ (function (_super) {
323
321
  React.createElement("rect", __assign({ className: _this._classNames.opacityChangeOnHover, x: xPoint, y: yPoint, width: _this._barWidth, height: barHeight, fill: _this.props.enableGradient ? "url(#".concat(gradientId, ")") : startColor, rx: _this.props.roundCorners ? 3 : 0, ref: function (e) { return (ref.refElement = e); } }, rectFocusProps, { transform: "translate(".concat(xScaleBandwidthTranslate, ", 0)") }))));
324
322
  });
325
323
  var groupRef = {};
326
- var stackFocusProps = shouldFocusWholeStack && {
324
+ var someBarsActive = singleChartData.chartData.filter(function (dataPoint) { return _this._noLegendHighlighted() || _this._isLegendHighlighted(dataPoint.legend); }).length > 0;
325
+ // FIXME: Making the entire stack focusable when stack callout is enabled adds unnecessary complexity
326
+ // and can reduce usability in certain scenarios. Instead, each individual element within the stack
327
+ // should be focusable on its own, with its own aria-label. This behavior is also seen in Highcharts.
328
+ var stackFocusProps = shouldFocusWholeStack &&
329
+ someBarsActive && {
327
330
  'data-is-focusable': !_this.props.hideTooltip,
328
331
  'aria-label': _this._getAriaLabel(singleChartData),
329
332
  onMouseOver: _this._onStackHover.bind(_this, singleChartData),
@@ -452,7 +455,7 @@ var VerticalStackedBarChartBase = /** @class */ (function (_super) {
452
455
  _this._noLegendHighlighted = function () {
453
456
  return _this._getHighlightedLegend().length === 0;
454
457
  };
455
- _this._getAriaLabel = function (singleChartData, point) {
458
+ _this._getAriaLabel = function (singleChartData, point, isLinePoint) {
456
459
  var _a, _b, _c;
457
460
  if (!point) {
458
461
  /** if shouldFocusWholeStack is true */
@@ -464,26 +467,29 @@ var VerticalStackedBarChartBase = /** @class */ (function (_super) {
464
467
  .map(function (pt) {
465
468
  var legend = pt.legend;
466
469
  var yValue = pt.yAxisCalloutData || pt.data;
467
- return "".concat(legend, ", ").concat(yValue, ".");
470
+ return _this._noLegendHighlighted() || _this._isLegendHighlighted(legend) ? "".concat(legend, ", ").concat(yValue, ".") : '';
468
471
  })
472
+ .filter(function (str) { return str !== ''; })
469
473
  .join(' ');
470
474
  var lineValues = (_a = singleChartData.lineData) === null || _a === void 0 ? void 0 : _a.map(function (ln) {
471
475
  var legend = ln.legend;
472
476
  var yValue = ln.yAxisCalloutData || ln.data || ln.y;
473
- return "".concat(legend, ", ").concat(yValue, ".");
474
- }).join(' ');
477
+ return _this._noLegendHighlighted() || _this._isLegendHighlighted(legend) ? "".concat(legend, ", ").concat(yValue, ".") : '';
478
+ }).filter(function (str) { return str !== ''; }).join(' ');
475
479
  return (((_b = singleChartData.stackCallOutAccessibilityData) === null || _b === void 0 ? void 0 : _b.ariaLabel) ||
476
480
  "".concat(xValue_1, ". ").concat(pointValues) + (lineValues ? " ".concat(lineValues) : ''));
477
481
  }
478
482
  /** if shouldFocusWholeStack is false */
479
483
  var xValue = singleChartData.xAxisCalloutData ||
480
- point.xAxisCalloutData ||
484
+ (!isLinePoint && point.xAxisCalloutData) ||
481
485
  (singleChartData.xAxisPoint instanceof Date
482
486
  ? formatDate(singleChartData.xAxisPoint)
483
487
  : singleChartData.xAxisPoint);
484
488
  var legend = point.legend;
485
- var yValue = point.yAxisCalloutData || point.data;
486
- return ((_c = point.callOutAccessibilityData) === null || _c === void 0 ? void 0 : _c.ariaLabel) || "".concat(xValue, ". ").concat(legend, ", ").concat(yValue, ".");
489
+ var yValue = point.yAxisCalloutData ||
490
+ (isLinePoint ? point.data || point.y : point.data);
491
+ return ((!isLinePoint && ((_c = point.callOutAccessibilityData) === null || _c === void 0 ? void 0 : _c.ariaLabel)) ||
492
+ "".concat(xValue, ". ").concat(legend, ", ").concat(yValue, "."));
487
493
  };
488
494
  _this._getDomainMargins = function (containerWidth) {
489
495
  var _a;