@fluentui/react-charts 9.2.1 → 9.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/dist/index.d.ts +79 -5
  3. package/lib/ChartTable.js +1 -0
  4. package/lib/ChartTable.js.map +1 -0
  5. package/lib/components/AreaChart/AreaChart.js.map +1 -1
  6. package/lib/components/ChartTable/ChartTable.js +57 -0
  7. package/lib/components/ChartTable/ChartTable.js.map +1 -0
  8. package/lib/components/ChartTable/ChartTable.types.js +1 -0
  9. package/lib/components/ChartTable/ChartTable.types.js.map +1 -0
  10. package/lib/components/ChartTable/index.js +3 -0
  11. package/lib/components/ChartTable/index.js.map +1 -0
  12. package/lib/components/ChartTable/useChartTableStyles.styles.js +93 -0
  13. package/lib/components/ChartTable/useChartTableStyles.styles.js.map +1 -0
  14. package/lib/components/ChartTable/useChartTableStyles.styles.raw.js +55 -0
  15. package/lib/components/ChartTable/useChartTableStyles.styles.raw.js.map +1 -0
  16. package/lib/components/CommonComponents/CartesianChart.js +110 -81
  17. package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
  18. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  19. package/lib/components/CommonComponents/ChartPopover.types.js.map +1 -1
  20. package/lib/components/DeclarativeChart/DeclarativeChart.js +20 -10
  21. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  22. package/lib/components/DeclarativeChart/PlotlyColorAdapter.js +95 -0
  23. package/lib/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -0
  24. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +164 -77
  25. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  26. package/lib/components/DonutChart/DonutChart.js.map +1 -1
  27. package/lib/components/DonutChart/DonutChart.types.js.map +1 -1
  28. package/lib/components/DonutChart/Pie/Pie.js.map +1 -1
  29. package/lib/components/FunnelChart/FunnelChart.js.map +1 -1
  30. package/lib/components/GanttChart/GanttChart.js.map +1 -1
  31. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +161 -141
  32. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  33. package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -1
  34. package/lib/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -1
  35. package/lib/components/HorizontalBarChart/HorizontalBarChart.types.js.map +1 -1
  36. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  37. package/lib/components/Legends/Legends.js.map +1 -1
  38. package/lib/components/Legends/OverflowMenu.js.map +1 -1
  39. package/lib/components/LineChart/LineChart.js.map +1 -1
  40. package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
  41. package/lib/components/VerticalBarChart/VerticalBarChart.js +12 -11
  42. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  43. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +57 -51
  44. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  45. package/lib/index.js +1 -0
  46. package/lib/index.js.map +1 -1
  47. package/lib/utilities/FocusableTooltipText.js.map +1 -1
  48. package/lib/utilities/utilities.js +26 -37
  49. package/lib/utilities/utilities.js.map +1 -1
  50. package/lib/utilities/vbc-utils.js +24 -0
  51. package/lib/utilities/vbc-utils.js.map +1 -1
  52. package/lib-commonjs/ChartTable.js +6 -0
  53. package/lib-commonjs/ChartTable.js.map +1 -0
  54. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
  55. package/lib-commonjs/components/ChartTable/ChartTable.js +68 -0
  56. package/lib-commonjs/components/ChartTable/ChartTable.js.map +1 -0
  57. package/lib-commonjs/components/ChartTable/ChartTable.types.js +6 -0
  58. package/lib-commonjs/components/ChartTable/ChartTable.types.js.map +1 -0
  59. package/lib-commonjs/components/ChartTable/index.js +8 -0
  60. package/lib-commonjs/components/ChartTable/index.js.map +1 -0
  61. package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.js +196 -0
  62. package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.js.map +1 -0
  63. package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.raw.js +69 -0
  64. package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.raw.js.map +1 -0
  65. package/lib-commonjs/components/CommonComponents/CartesianChart.js +109 -80
  66. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  67. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  68. package/lib-commonjs/components/CommonComponents/ChartPopover.types.js.map +1 -1
  69. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +19 -9
  70. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  71. package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js +120 -0
  72. package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -0
  73. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +164 -77
  74. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  75. package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
  76. package/lib-commonjs/components/DonutChart/DonutChart.types.js.map +1 -1
  77. package/lib-commonjs/components/DonutChart/Pie/Pie.js.map +1 -1
  78. package/lib-commonjs/components/FunnelChart/FunnelChart.js.map +1 -1
  79. package/lib-commonjs/components/GanttChart/GanttChart.js.map +1 -1
  80. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +159 -139
  81. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  82. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -1
  83. package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -1
  84. package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.types.js.map +1 -1
  85. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  86. package/lib-commonjs/components/Legends/Legends.js.map +1 -1
  87. package/lib-commonjs/components/Legends/OverflowMenu.js.map +1 -1
  88. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  89. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  90. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +11 -10
  91. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  92. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +56 -50
  93. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  94. package/lib-commonjs/index.js +1 -0
  95. package/lib-commonjs/index.js.map +1 -1
  96. package/lib-commonjs/utilities/FocusableTooltipText.js.map +1 -1
  97. package/lib-commonjs/utilities/utilities.js +29 -37
  98. package/lib-commonjs/utilities/utilities.js.map +1 -1
  99. package/lib-commonjs/utilities/vbc-utils.js +27 -0
  100. package/lib-commonjs/utilities/vbc-utils.js.map +1 -1
  101. package/package.json +9 -9
@@ -22,11 +22,6 @@ const _imageexportutils = require("../../utilities/image-export-utils");
22
22
  const barGapMultiplier = 0.2;
23
23
  const barGapMin = 1;
24
24
  const MIN_DOMAIN_MARGIN = 8;
25
- var CircleVisbility = /*#__PURE__*/ function(CircleVisbility) {
26
- CircleVisbility["show"] = "visibility";
27
- CircleVisbility["hide"] = "hidden";
28
- return CircleVisbility;
29
- }(CircleVisbility || {});
30
25
  const VerticalStackedBarChart = (props)=>{
31
26
  var _props_legendProps;
32
27
  const _isRtl = (0, _index1.useRtl)();
@@ -161,19 +156,29 @@ const VerticalStackedBarChart = (props)=>{
161
156
  activeLegend
162
157
  ] : [];
163
158
  }
164
- function _lineHoverOut() {
165
- setPopoverOpen(false);
166
- setXCalloutValue('');
167
- setYCalloutValue('');
168
- setActiveXAxisDataPoint('');
169
- setColor('');
170
- }
171
- function _lineHoverFocus(lineData) {
172
- setPopoverOpen(true);
173
- setXCalloutValue(`${lineData.xItem.xAxisPoint}`);
174
- setYCalloutValue(`${lineData.yAxisCalloutData || lineData.data || lineData.y}`);
175
- setActiveXAxisDataPoint(lineData.xItem.xAxisPoint);
176
- setColor(lineData.color);
159
+ function _lineHoverFocus(lineData, event) {
160
+ let clientX = 0;
161
+ let clientY = 0;
162
+ if ('clientX' in event) {
163
+ clientX = event.clientX;
164
+ clientY = event.clientY;
165
+ } else {
166
+ const boundingRect = event.target.getBoundingClientRect();
167
+ clientX = boundingRect.left + boundingRect.width / 2;
168
+ clientY = boundingRect.top + boundingRect.height / 2;
169
+ }
170
+ if (_getHighlightedLegend().length === 1) {
171
+ if (_noLegendHighlighted() || _isLegendHighlighted(lineData.legend)) {
172
+ _updatePosition(clientX, clientY);
173
+ setPopoverOpen(true);
174
+ setXCalloutValue(`${lineData.xItem.xAxisPoint}`);
175
+ setYCalloutValue(`${lineData.yAxisCalloutData || lineData.data || lineData.y}`);
176
+ setActiveXAxisDataPoint(lineData.xItem.xAxisPoint);
177
+ setColor(lineData.color);
178
+ }
179
+ } else {
180
+ _onStackHoverFocus(lineData.xItem, event);
181
+ }
177
182
  }
178
183
  function _onStackHoverFocus(stack, mouseEvent) {
179
184
  var _stack_lineData;
@@ -302,7 +307,7 @@ const VerticalStackedBarChart = (props)=>{
302
307
  */ function _noLegendHighlighted() {
303
308
  return _getHighlightedLegend().length === 0;
304
309
  }
305
- function _getAriaLabel(singleChartData, point) {
310
+ function _getAriaLabel(singleChartData, point, isLinePoint) {
306
311
  var _point_callOutAccessibilityData;
307
312
  if (!point) {
308
313
  var _singleChartData_lineData, _singleChartData_stackCallOutAccessibilityData;
@@ -310,19 +315,19 @@ const VerticalStackedBarChart = (props)=>{
310
315
  const pointValues = singleChartData.chartData.map((pt)=>{
311
316
  const legend = pt.legend;
312
317
  const yValue = pt.yAxisCalloutData || pt.data;
313
- return `${legend}, ${yValue}.`;
314
- }).join(' ');
318
+ return _noLegendHighlighted() || _isLegendHighlighted(legend) ? `${legend}, ${yValue}.` : '';
319
+ }).filter((str)=>str !== '').join(' ');
315
320
  const lineValues = (_singleChartData_lineData = singleChartData.lineData) === null || _singleChartData_lineData === void 0 ? void 0 : _singleChartData_lineData.map((ln)=>{
316
321
  const legend = ln.legend;
317
322
  const yValue = ln.yAxisCalloutData || ln.data || ln.y;
318
- return `${legend}, ${yValue}.`;
319
- }).join(' ');
323
+ return _noLegendHighlighted() || _isLegendHighlighted(legend) ? `${legend}, ${yValue}.` : '';
324
+ }).filter((str)=>str !== '').join(' ');
320
325
  return ((_singleChartData_stackCallOutAccessibilityData = singleChartData.stackCallOutAccessibilityData) === null || _singleChartData_stackCallOutAccessibilityData === void 0 ? void 0 : _singleChartData_stackCallOutAccessibilityData.ariaLabel) || `${xValue}. ${pointValues}` + (lineValues ? ` ${lineValues}` : '');
321
326
  }
322
- /** if shouldFocusWholeStack is false */ const xValue = singleChartData.xAxisCalloutData || point.xAxisCalloutData || (singleChartData.xAxisPoint instanceof Date ? (0, _index1.formatDate)(singleChartData.xAxisPoint) : singleChartData.xAxisPoint);
327
+ /** if shouldFocusWholeStack is false */ const xValue = singleChartData.xAxisCalloutData || !isLinePoint && point.xAxisCalloutData || (singleChartData.xAxisPoint instanceof Date ? (0, _index1.formatDate)(singleChartData.xAxisPoint) : singleChartData.xAxisPoint);
323
328
  const legend = point.legend;
324
- const yValue = point.yAxisCalloutData || point.data;
325
- return ((_point_callOutAccessibilityData = point.callOutAccessibilityData) === null || _point_callOutAccessibilityData === void 0 ? void 0 : _point_callOutAccessibilityData.ariaLabel) || `${xValue}. ${legend}, ${yValue}.`;
329
+ const yValue = point.yAxisCalloutData || (isLinePoint ? point.data || point.y : point.data);
330
+ return !isLinePoint && ((_point_callOutAccessibilityData = point.callOutAccessibilityData) === null || _point_callOutAccessibilityData === void 0 ? void 0 : _point_callOutAccessibilityData.ariaLabel) || `${xValue}. ${legend}, ${yValue}.`;
326
331
  }
327
332
  function _getCustomizedCallout() {
328
333
  const _isHavingLines = props.data.some((item)=>item.lineData && item.lineData.length > 0);
@@ -435,10 +440,8 @@ const VerticalStackedBarChart = (props)=>{
435
440
  strokeDasharray: (_lineObject_item__lineOptions2 = lineObject[item][0].lineOptions) === null || _lineObject_item__lineOptions2 === void 0 ? void 0 : _lineObject_item__lineOptions2.strokeDasharray,
436
441
  stroke: lineObject[item][i].color,
437
442
  transform: `translate(${xScaleBandwidthTranslate}, 0)`,
438
- ..._isLegendHighlighted(item) && {
439
- onMouseOver: _lineHover.bind(lineObject[item][i - 1]),
440
- onMouseLeave: _lineHoverOut
441
- }
443
+ onMouseOver: (event)=>_lineHover(lineObject[item][i - 1], event),
444
+ onMouseLeave: _handleMouseOut
442
445
  }));
443
446
  }
444
447
  });
@@ -452,15 +455,15 @@ const VerticalStackedBarChart = (props)=>{
452
455
  key: `${index}-${subIndex}-dot`,
453
456
  cx: xScale(circlePoint.xItem.xAxisPoint),
454
457
  cy: circlePoint.useSecondaryYScale && yScaleSecondary ? yScaleSecondary(circlePoint.y) : yScalePrimary(circlePoint.y),
455
- onMouseOver: _isLegendHighlighted(item) ? (event)=>_lineHover(circlePoint, event) : (event)=>_onStackHover(circlePoint.xItem, event),
456
- ..._isLegendHighlighted(item) && {
457
- onMouseLeave: _lineHoverOut
458
- },
459
- r: _getCircleVisibilityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).radius,
458
+ onMouseOver: (event)=>_lineHover(circlePoint, event),
459
+ onMouseLeave: _handleMouseOut,
460
+ r: _getCircleOpacityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).radius,
460
461
  stroke: circlePoint.color,
461
462
  fill: _reacttheme.tokens.colorNeutralBackground1,
462
463
  strokeWidth: 3,
463
- visibility: _getCircleVisibilityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).visibility,
464
+ // Elements with visibility: hidden cannot receive focus, so use opacity: 0 instead to hide them.
465
+ // For more information, see https://fuzzbomb.github.io/accessibility-demos/visually-hidden-focus-test.html
466
+ opacity: _getCircleOpacityAndRadius(circlePoint.xItem.xAxisPoint, circlePoint.legend).opacity,
464
467
  transform: `translate(${xScaleBandwidthTranslate}, 0)`,
465
468
  ref: (e)=>circleRef.refElement = e,
466
469
  ...noBarsAndLinesActive ? {
@@ -475,27 +478,27 @@ const VerticalStackedBarChart = (props)=>{
475
478
  });
476
479
  return /*#__PURE__*/ _react.createElement(_react.Fragment, null, borderForLines, lines, dots);
477
480
  }
478
- function _getCircleVisibilityAndRadius(xAxisPoint, legend) {
481
+ function _getCircleOpacityAndRadius(xAxisPoint, legend) {
479
482
  if (!_noLegendHighlighted()) {
480
483
  if (xAxisPoint === activeXAxisDataPoint && _isLegendHighlighted(legend)) {
481
484
  return {
482
- visibility: "visibility",
485
+ opacity: 1,
483
486
  radius: 8
484
487
  };
485
488
  } else if (_isLegendHighlighted(legend)) {
486
489
  return {
487
- visibility: "visibility",
490
+ opacity: 1,
488
491
  radius: 0.3
489
492
  };
490
493
  } else {
491
494
  return {
492
- visibility: "hidden",
495
+ opacity: 0,
493
496
  radius: 0
494
497
  };
495
498
  }
496
499
  } else {
497
500
  return {
498
- visibility: activeXAxisDataPoint === xAxisPoint ? "visibility" : "hidden",
501
+ opacity: activeXAxisDataPoint === xAxisPoint ? 1 : 0,
499
502
  radius: 8
500
503
  };
501
504
  }
@@ -548,11 +551,11 @@ const VerticalStackedBarChart = (props)=>{
548
551
  }
549
552
  function _lineHover(lineData, mouseEvent) {
550
553
  mouseEvent.persist();
551
- _lineHoverFocus(lineData);
554
+ _lineHoverFocus(lineData, mouseEvent);
552
555
  }
553
556
  function _lineFocus(event, lineData, ref) {
554
557
  if (ref.refElement) {
555
- _lineHoverFocus(lineData);
558
+ _lineHoverFocus(lineData, event);
556
559
  }
557
560
  }
558
561
  function _onStackHover(stack, mouseEvent) {
@@ -680,8 +683,7 @@ const VerticalStackedBarChart = (props)=>{
680
683
  }
681
684
  function _getDomainMargins(containerWidth) {
682
685
  _domainMargin = MIN_DOMAIN_MARGIN;
683
- /** Total width available to render the bars */ const totalWidth = containerWidth - (_margins.left + MIN_DOMAIN_MARGIN) - (_margins.right + MIN_DOMAIN_MARGIN);
684
- /** Rate at which the space between the bars changes wrt the bar width */ const barGapRate = _xAxisInnerPadding / (1 - _xAxisInnerPadding);
686
+ const totalWidth = (0, _index1.calcTotalWidth)(containerWidth, _margins, MIN_DOMAIN_MARGIN);
685
687
  if (_xAxisType === _index1.XAxisTypes.StringAxis) {
686
688
  if ((0, _index1.isScalePaddingDefined)(props.xAxisOuterPadding, props.xAxisPadding)) {
687
689
  // Setting the domain margin for string x-axis to 0 because the xAxisOuterPadding prop is now available
@@ -691,16 +693,16 @@ const VerticalStackedBarChart = (props)=>{
691
693
  // Update the bar width so that when CartesianChart rerenders,
692
694
  // the following calculations don't use the previous bar width.
693
695
  _barWidth = (0, _index1.getBarWidth)(props.barWidth, props.maxBarWidth);
694
- /** Total width required to render the bars. Directly proportional to bar width */ const reqWidth = (_xAxisLabels.length + (_xAxisLabels.length - 1) * barGapRate) * _barWidth;
696
+ /** Total width required to render the bars. Directly proportional to bar width */ const reqWidth = (0, _index1.calcRequiredWidth)(_barWidth, _xAxisLabels.length, _xAxisInnerPadding);
695
697
  if (totalWidth >= reqWidth) {
696
698
  // Center align the chart by setting equal left and right margins for domain
697
699
  _domainMargin = MIN_DOMAIN_MARGIN + (totalWidth - reqWidth) / 2;
698
700
  }
699
701
  } else if (props.mode === 'plotly' && _xAxisLabels.length > 1) {
700
702
  // Calculate the remaining width after rendering bars at their maximum allowable width
701
- const bandwidth = totalWidth / (_xAxisLabels.length + (_xAxisLabels.length - 1) * barGapRate);
703
+ const bandwidth = (0, _index1.calcBandwidth)(totalWidth, _xAxisLabels.length, _xAxisInnerPadding);
702
704
  const barWidth = (0, _index1.getBarWidth)(props.barWidth, props.maxBarWidth, bandwidth);
703
- let reqWidth = (_xAxisLabels.length + (_xAxisLabels.length - 1) * barGapRate) * barWidth;
705
+ let reqWidth = (0, _index1.calcRequiredWidth)(barWidth, _xAxisLabels.length, _xAxisInnerPadding);
704
706
  const margin1 = (totalWidth - reqWidth) / 2;
705
707
  let margin2 = Number.POSITIVE_INFINITY;
706
708
  if (!props.hideTickOverlap) {
@@ -757,7 +759,7 @@ const VerticalStackedBarChart = (props)=>{
757
759
  const startColor = point.color ? point.color : _colors[index];
758
760
  const ref = {};
759
761
  const shouldHighlight = _isLegendHighlighted(point.legend) || _noLegendHighlighted() ? true : false;
760
- const rectFocusProps = !shouldFocusWholeStack && {
762
+ const rectFocusProps = !shouldFocusWholeStack && shouldHighlight && {
761
763
  'aria-label': _getAriaLabel(singleChartData, point),
762
764
  onMouseOver: (event)=>_onRectHover(singleChartData.xAxisPoint, point, startColor, event),
763
765
  onMouseMove: (event)=>_onRectHover(singleChartData.xAxisPoint, point, startColor, event),
@@ -829,7 +831,11 @@ const VerticalStackedBarChart = (props)=>{
829
831
  }));
830
832
  });
831
833
  const groupRef = {};
832
- const stackFocusProps = shouldFocusWholeStack && {
834
+ const someBarsActive = singleChartData.chartData.filter((dataPoint)=>_noLegendHighlighted() || _isLegendHighlighted(dataPoint.legend)).length > 0;
835
+ // FIXME: Making the entire stack focusable when stack callout is enabled adds unnecessary complexity
836
+ // and can reduce usability in certain scenarios. Instead, each individual element within the stack
837
+ // should be focusable on its own, with its own aria-label. This behavior is also seen in Highcharts.
838
+ const stackFocusProps = shouldFocusWholeStack && someBarsActive && {
833
839
  'aria-label': _getAriaLabel(singleChartData),
834
840
  onMouseOver: (event)=>_onStackHover(singleChartData, event),
835
841
  onMouseMove: (event)=>_onStackHover(singleChartData, event),