@fluentui/react-charts 9.0.2 → 9.0.3

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 (185) hide show
  1. package/CHANGELOG.md +48 -7
  2. package/dist/index.d.ts +767 -0
  3. package/lib/AreaChart.js +1 -0
  4. package/lib/AreaChart.js.map +1 -0
  5. package/lib/HeatMapChart.js +1 -0
  6. package/lib/HeatMapChart.js.map +1 -0
  7. package/lib/HorizontalBarChartWithAxis.js +1 -0
  8. package/lib/HorizontalBarChartWithAxis.js.map +1 -0
  9. package/lib/SankeyChart.js +1 -0
  10. package/lib/SankeyChart.js.map +1 -0
  11. package/lib/VerticalStackedBarChart.js +1 -0
  12. package/lib/VerticalStackedBarChart.js.map +1 -0
  13. package/lib/components/AreaChart/AreaChart.js +775 -0
  14. package/lib/components/AreaChart/AreaChart.js.map +1 -0
  15. package/lib/components/AreaChart/AreaChart.types.js +4 -0
  16. package/lib/components/AreaChart/AreaChart.types.js.map +1 -0
  17. package/lib/components/AreaChart/index.js +3 -0
  18. package/lib/components/AreaChart/index.js.map +1 -0
  19. package/lib/components/AreaChart/useAreaChartStyles.styles.js +64 -0
  20. package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
  21. package/lib/components/CommonComponents/CartesianChart.js +30 -14
  22. package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
  23. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  24. package/lib/components/DeclarativeChart/DeclarativeChart.js +112 -65
  25. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  26. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +570 -159
  27. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  28. package/lib/components/DonutChart/Arc/Arc.js +1 -1
  29. package/lib/components/DonutChart/Arc/Arc.js.map +1 -1
  30. package/lib/components/DonutChart/DonutChart.js +1 -1
  31. package/lib/components/DonutChart/DonutChart.js.map +1 -1
  32. package/lib/components/GaugeChart/GaugeChart.js +3 -0
  33. package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
  34. package/lib/components/GaugeChart/GaugeChart.types.js.map +1 -1
  35. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
  36. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  37. package/lib/components/HeatMapChart/HeatMapChart.js +588 -0
  38. package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -0
  39. package/lib/components/HeatMapChart/HeatMapChart.types.js +4 -0
  40. package/lib/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
  41. package/lib/components/HeatMapChart/index.js +3 -0
  42. package/lib/components/HeatMapChart/index.js.map +1 -0
  43. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js +46 -0
  44. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
  45. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +571 -0
  46. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
  47. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +4 -0
  48. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
  49. package/lib/components/HorizontalBarChartWithAxis/index.js +3 -0
  50. package/lib/components/HorizontalBarChartWithAxis/index.js.map +1 -0
  51. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +76 -0
  52. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
  53. package/lib/components/Legends/Legends.js +38 -37
  54. package/lib/components/Legends/Legends.js.map +1 -1
  55. package/lib/components/LineChart/LineChart.js +43 -35
  56. package/lib/components/LineChart/LineChart.js.map +1 -1
  57. package/lib/components/SankeyChart/SankeyChart.js +1022 -0
  58. package/lib/components/SankeyChart/SankeyChart.js.map +1 -0
  59. package/lib/components/SankeyChart/SankeyChart.types.js +3 -0
  60. package/lib/components/SankeyChart/SankeyChart.types.js.map +1 -0
  61. package/lib/components/SankeyChart/index.js +3 -0
  62. package/lib/components/SankeyChart/index.js.map +1 -0
  63. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +109 -0
  64. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
  65. package/lib/components/ScatterChart/ScatterChart.js +46 -59
  66. package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
  67. package/lib/components/VerticalBarChart/VerticalBarChart.js +165 -88
  68. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  69. package/lib/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
  70. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +904 -0
  71. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
  72. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +1 -0
  73. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
  74. package/lib/components/VerticalStackedBarChart/index.js +3 -0
  75. package/lib/components/VerticalStackedBarChart/index.js.map +1 -0
  76. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +73 -0
  77. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
  78. package/lib/index.js +5 -0
  79. package/lib/index.js.map +1 -1
  80. package/lib/types/DataPoint.js +1 -3
  81. package/lib/types/DataPoint.js.map +1 -1
  82. package/lib/utilities/SVGTooltipText.js +49 -4
  83. package/lib/utilities/SVGTooltipText.js.map +1 -1
  84. package/lib/utilities/colors.js +20 -0
  85. package/lib/utilities/colors.js.map +1 -1
  86. package/lib/utilities/string.js +32 -0
  87. package/lib/utilities/string.js.map +1 -0
  88. package/lib/utilities/test-data.js +53 -0
  89. package/lib/utilities/test-data.js.map +1 -1
  90. package/lib/utilities/utilities.js +90 -18
  91. package/lib/utilities/utilities.js.map +1 -1
  92. package/lib-commonjs/AreaChart.js +6 -0
  93. package/lib-commonjs/AreaChart.js.map +1 -0
  94. package/lib-commonjs/HeatMapChart.js +6 -0
  95. package/lib-commonjs/HeatMapChart.js.map +1 -0
  96. package/lib-commonjs/HorizontalBarChartWithAxis.js +6 -0
  97. package/lib-commonjs/HorizontalBarChartWithAxis.js.map +1 -0
  98. package/lib-commonjs/SankeyChart.js +6 -0
  99. package/lib-commonjs/SankeyChart.js.map +1 -0
  100. package/lib-commonjs/VerticalStackedBarChart.js +6 -0
  101. package/lib-commonjs/VerticalStackedBarChart.js.map +1 -0
  102. package/lib-commonjs/components/AreaChart/AreaChart.js +781 -0
  103. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -0
  104. package/lib-commonjs/components/AreaChart/AreaChart.types.js +7 -0
  105. package/lib-commonjs/components/AreaChart/AreaChart.types.js.map +1 -0
  106. package/lib-commonjs/components/AreaChart/index.js +8 -0
  107. package/lib-commonjs/components/AreaChart/index.js.map +1 -0
  108. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +104 -0
  109. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -0
  110. package/lib-commonjs/components/CommonComponents/CartesianChart.js +29 -14
  111. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  112. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  113. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +120 -73
  114. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  115. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +592 -178
  116. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  117. package/lib-commonjs/components/DonutChart/Arc/Arc.js +1 -1
  118. package/lib-commonjs/components/DonutChart/Arc/Arc.js.map +1 -1
  119. package/lib-commonjs/components/DonutChart/DonutChart.js +1 -1
  120. package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
  121. package/lib-commonjs/components/GaugeChart/GaugeChart.js +3 -0
  122. package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
  123. package/lib-commonjs/components/GaugeChart/GaugeChart.types.js.map +1 -1
  124. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +9 -0
  125. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  126. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +599 -0
  127. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -0
  128. package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js +7 -0
  129. package/lib-commonjs/components/HeatMapChart/HeatMapChart.types.js.map +1 -0
  130. package/lib-commonjs/components/HeatMapChart/index.js +8 -0
  131. package/lib-commonjs/components/HeatMapChart/index.js.map +1 -0
  132. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js +68 -0
  133. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -0
  134. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +580 -0
  135. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -0
  136. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js +7 -0
  137. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.types.js.map +1 -0
  138. package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js +8 -0
  139. package/lib-commonjs/components/HorizontalBarChartWithAxis/index.js.map +1 -0
  140. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +116 -0
  141. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -0
  142. package/lib-commonjs/components/Legends/Legends.js +37 -37
  143. package/lib-commonjs/components/Legends/Legends.js.map +1 -1
  144. package/lib-commonjs/components/LineChart/LineChart.js +41 -33
  145. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  146. package/lib-commonjs/components/SankeyChart/SankeyChart.js +1038 -0
  147. package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -0
  148. package/lib-commonjs/components/SankeyChart/SankeyChart.types.js +6 -0
  149. package/lib-commonjs/components/SankeyChart/SankeyChart.types.js.map +1 -0
  150. package/lib-commonjs/components/SankeyChart/index.js +8 -0
  151. package/lib-commonjs/components/SankeyChart/index.js.map +1 -0
  152. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +179 -0
  153. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -0
  154. package/lib-commonjs/components/ScatterChart/ScatterChart.js +45 -58
  155. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  156. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +164 -87
  157. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  158. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.types.js.map +1 -1
  159. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +915 -0
  160. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -0
  161. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js +6 -0
  162. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -0
  163. package/lib-commonjs/components/VerticalStackedBarChart/index.js +8 -0
  164. package/lib-commonjs/components/VerticalStackedBarChart/index.js.map +1 -0
  165. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +120 -0
  166. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -0
  167. package/lib-commonjs/index.js +5 -0
  168. package/lib-commonjs/index.js.map +1 -1
  169. package/lib-commonjs/types/DataPoint.js +1 -3
  170. package/lib-commonjs/types/DataPoint.js.map +1 -1
  171. package/lib-commonjs/utilities/SVGTooltipText.js +49 -4
  172. package/lib-commonjs/utilities/SVGTooltipText.js.map +1 -1
  173. package/lib-commonjs/utilities/colors.js +23 -0
  174. package/lib-commonjs/utilities/colors.js.map +1 -1
  175. package/lib-commonjs/utilities/string.js +29 -0
  176. package/lib-commonjs/utilities/string.js.map +1 -0
  177. package/lib-commonjs/utilities/test-data.js +59 -0
  178. package/lib-commonjs/utilities/test-data.js.map +1 -1
  179. package/lib-commonjs/utilities/utilities.js +94 -17
  180. package/lib-commonjs/utilities/utilities.js.map +1 -1
  181. package/package.json +11 -8
  182. package/lib/components/DeclarativeChart/PlotlySchema.js +0 -7
  183. package/lib/components/DeclarativeChart/PlotlySchema.js.map +0 -1
  184. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js +0 -10
  185. package/lib-commonjs/components/DeclarativeChart/PlotlySchema.js.map +0 -1
@@ -0,0 +1,580 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "HorizontalBarChartWithAxis", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return HorizontalBarChartWithAxis;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ const _d3array = require("d3-array");
14
+ const _d3selection = require("d3-selection");
15
+ const _d3scale = require("d3-scale");
16
+ const _Legends = require("../../components/Legends/Legends");
17
+ const _reactutilities = require("@fluentui/react-utilities");
18
+ const _useHorizontalBarChartWithAxisStylesstyles = require("./useHorizontalBarChartWithAxisStyles.styles");
19
+ const _CartesianChart = require("../CommonComponents/CartesianChart");
20
+ const _ChartPopover = require("../CommonComponents/ChartPopover");
21
+ const _index = require("../../utilities/index");
22
+ const HorizontalBarChartWithAxis = /*#__PURE__*/ _react.forwardRef((props, forwardedRef)=>{
23
+ var _props_legendProps, _props_legendProps1, _props_legendProps2, _props_legendProps3;
24
+ const _refArray = [];
25
+ const _calloutId = (0, _reactutilities.useId)('callout');
26
+ const _isRtl = (0, _index.useRtl)();
27
+ const _tooltipId = (0, _reactutilities.useId)('HBCWATooltipID_');
28
+ const _xAxisType = props.data && props.data.length > 0 ? (0, _index.getTypeOfAxis)(props.data[0].x, true) : _index.XAxisTypes.NumericAxis;
29
+ const _yAxisType = props.data && props.data.length > 0 ? (0, _index.getTypeOfAxis)(props.data[0].y, false) : _index.YAxisType.StringAxis;
30
+ const _emptyChartId = (0, _reactutilities.useId)('_HBCWithAxis_empty');
31
+ let _points = [];
32
+ let _barHeight = 0;
33
+ let _colors = [];
34
+ let _margins;
35
+ let _bars;
36
+ let _yAxisLabels;
37
+ let _xMax;
38
+ let _calloutAnchorPoint;
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ let tooltipElement;
41
+ const cartesianChartRef = _react.useRef(null);
42
+ const [color, setColor] = _react.useState('');
43
+ const [dataForHoverCard, setDataForHoverCard] = _react.useState(0);
44
+ const [isLegendSelected, setIsLegendSelected] = _react.useState(((_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.selectedLegends) && props.legendProps.selectedLegends.length > 0 || ((_props_legendProps1 = props.legendProps) === null || _props_legendProps1 === void 0 ? void 0 : _props_legendProps1.selectedLegend) !== undefined);
45
+ const [isLegendHovered, setIsLegendHovered] = _react.useState(false);
46
+ var _props_legendProps_selectedLegend;
47
+ const [selectedLegendTitle, setSelectedLegendTitle] = _react.useState((_props_legendProps_selectedLegend = (_props_legendProps2 = props.legendProps) === null || _props_legendProps2 === void 0 ? void 0 : _props_legendProps2.selectedLegend) !== null && _props_legendProps_selectedLegend !== void 0 ? _props_legendProps_selectedLegend : '');
48
+ const [xCalloutValue, setXCalloutValue] = _react.useState('');
49
+ const [yCalloutValue, setYCalloutValue] = _react.useState('');
50
+ const [selectedLegends, setSelectedLegends] = _react.useState(((_props_legendProps3 = props.legendProps) === null || _props_legendProps3 === void 0 ? void 0 : _props_legendProps3.selectedLegends) || []);
51
+ const [dataPointCalloutProps, setDataPointCalloutProps] = _react.useState();
52
+ const [callOutAccessibilityData, setCallOutAccessibilityData] = _react.useState();
53
+ const [isPopoverOpen, setPopoverOpen] = _react.useState(false);
54
+ const [clickPosition, setClickPosition] = _react.useState({
55
+ x: 0,
56
+ y: 0
57
+ });
58
+ const prevPropsRef = _react.useRef(null);
59
+ _react.useEffect(()=>{
60
+ if (prevPropsRef.current) {
61
+ var _prevProps_legendProps, _props_legendProps;
62
+ const prevProps = prevPropsRef.current;
63
+ if (!(0, _index.areArraysEqual)((_prevProps_legendProps = prevProps.legendProps) === null || _prevProps_legendProps === void 0 ? void 0 : _prevProps_legendProps.selectedLegends, (_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.selectedLegends)) {
64
+ var _props_legendProps1;
65
+ setSelectedLegends(((_props_legendProps1 = props.legendProps) === null || _props_legendProps1 === void 0 ? void 0 : _props_legendProps1.selectedLegends) || []);
66
+ }
67
+ }
68
+ prevPropsRef.current = props;
69
+ }, [
70
+ props
71
+ ]);
72
+ _react.useImperativeHandle(props.componentRef, ()=>{
73
+ var _cartesianChartRef_current;
74
+ var _cartesianChartRef_current_chartContainer;
75
+ return {
76
+ chartContainer: (_cartesianChartRef_current_chartContainer = (_cartesianChartRef_current = cartesianChartRef.current) === null || _cartesianChartRef_current === void 0 ? void 0 : _cartesianChartRef_current.chartContainer) !== null && _cartesianChartRef_current_chartContainer !== void 0 ? _cartesianChartRef_current_chartContainer : null
77
+ };
78
+ }, []);
79
+ const classes = (0, _useHorizontalBarChartWithAxisStylesstyles.useHorizontalBarChartWithAxisStyles)(props);
80
+ function _adjustProps() {
81
+ _points = props.data || [];
82
+ _barHeight = props.barHeight || 32;
83
+ const defaultPalette = [
84
+ (0, _index.getColorFromToken)(_index.DataVizPalette.color6),
85
+ (0, _index.getColorFromToken)(_index.DataVizPalette.color1),
86
+ (0, _index.getColorFromToken)(_index.DataVizPalette.color5),
87
+ (0, _index.getColorFromToken)(_index.DataVizPalette.color7)
88
+ ];
89
+ _colors = props.colors || defaultPalette;
90
+ }
91
+ function _getMargins(margins) {
92
+ _margins = margins;
93
+ }
94
+ function _renderContentForOnlyBars(point) {
95
+ const { useSingleColor = false } = props;
96
+ let selectedPointIndex = 0;
97
+ props.data.forEach((yDataPoint, index)=>{
98
+ if (yDataPoint.y === point.y) {
99
+ selectedPointIndex = index;
100
+ }
101
+ });
102
+ // eslint-disable-next-line @typescript-eslint/no-shadow
103
+ let color;
104
+ if (useSingleColor) {
105
+ //if useSingle color , then check if user has given a palette or not
106
+ // and pick the first color from that or else from our paltette.
107
+ color = props.colors ? _createColors()(1) : (0, _index.getNextColor)(1, 0);
108
+ } else {
109
+ color = point.color ? point.color : props.colors ? _createColors()(point.x) : (0, _index.getNextColor)(selectedPointIndex, 0);
110
+ }
111
+ var _props_culture;
112
+ return /*#__PURE__*/ _react.createElement(_react.Fragment, null, /*#__PURE__*/ _react.createElement(_ChartPopover.ChartPopover, {
113
+ XValue: point.xAxisCalloutData || point.x.toString(),
114
+ legend: point.legend,
115
+ YValue: point.yAxisCalloutData || point.y,
116
+ color: color,
117
+ culture: (_props_culture = props.culture) !== null && _props_culture !== void 0 ? _props_culture : 'en-us',
118
+ clickPosition: clickPosition,
119
+ isPopoverOpen: isPopoverOpen
120
+ }));
121
+ }
122
+ // eslint-disable-next-line @typescript-eslint/no-shadow
123
+ function _renderCallout(props) {
124
+ return props ? _renderContentForOnlyBars(props) : null;
125
+ }
126
+ function _getCustomizedCallout() {
127
+ return props.onRenderCalloutPerDataPoint ? props.onRenderCalloutPerDataPoint(dataPointCalloutProps, _renderCallout) : null;
128
+ }
129
+ function _getGraphData(xScale, yScale, containerHeight, containerWidth, xElement, yElement) {
130
+ return _bars = _yAxisType === _index.YAxisType.NumericAxis ? _createNumericBars(containerHeight, containerWidth, xElement, yElement) : _createStringBars(containerHeight, containerWidth, xElement, yElement);
131
+ }
132
+ function _createColors() {
133
+ const increment = _colors.length <= 1 ? 1 : 1 / (_colors.length - 1);
134
+ const { useSingleColor = false } = props;
135
+ if (useSingleColor) {
136
+ return (_p)=>{
137
+ const { colors } = props;
138
+ return colors && colors.length > 0 ? colors[0] : (0, _index.getColorFromToken)(_index.DataVizPalette.color16);
139
+ };
140
+ }
141
+ const domainValues = [];
142
+ for(let i = 0; i < _colors.length; i++){
143
+ domainValues.push(increment * i * _xMax);
144
+ }
145
+ const colorScale = (0, _d3scale.scaleLinear)().domain(domainValues).range(_colors);
146
+ return colorScale;
147
+ }
148
+ function _refCallback(element, legendTitle) {
149
+ _refArray.push({
150
+ index: legendTitle,
151
+ refElement: element
152
+ });
153
+ }
154
+ function _onBarHover(point, color, mouseEvent) {
155
+ mouseEvent.persist();
156
+ // eslint-disable-next-line @typescript-eslint/no-shadow
157
+ if ((isLegendSelected === false || _isLegendHighlighted(point.legend)) && _calloutAnchorPoint !== point) {
158
+ _calloutAnchorPoint = point;
159
+ setPopoverOpen(true);
160
+ _updatePosition(mouseEvent.clientX, mouseEvent.clientY);
161
+ setDataForHoverCard(point.x);
162
+ setSelectedLegendTitle(point.legend);
163
+ setColor(props.useSingleColor || props.enableGradient ? color : point.color);
164
+ // To display callout value, if no callout value given, taking given point.x value as a string.
165
+ setXCalloutValue(point.yAxisCalloutData || point.y.toString());
166
+ setYCalloutValue(point.xAxisCalloutData || point.x.toString());
167
+ setDataPointCalloutProps(point);
168
+ setCallOutAccessibilityData(point.callOutAccessibilityData);
169
+ }
170
+ }
171
+ function _onBarLeave() {
172
+ setPopoverOpen(false);
173
+ }
174
+ function _handleChartMouseLeave() {
175
+ _calloutAnchorPoint = null;
176
+ setPopoverOpen(false);
177
+ }
178
+ // eslint-disable-next-line @typescript-eslint/no-shadow
179
+ function _onBarFocus(point, refArrayIndexNumber, color) {
180
+ if ((isLegendSelected === false || _isLegendHighlighted(point.legend)) && _calloutAnchorPoint !== point) {
181
+ // eslint-disable-next-line @typescript-eslint/no-shadow
182
+ _refArray.forEach((obj, index)=>{
183
+ if (refArrayIndexNumber === index) {
184
+ setPopoverOpen(true);
185
+ setSelectedLegendTitle(point.legend);
186
+ setDataForHoverCard(point.x);
187
+ setColor(props.useSingleColor ? color : point.color);
188
+ setXCalloutValue(point.yAxisCalloutData || point.y.toString());
189
+ setYCalloutValue(point.xAxisCalloutData || point.x.toString());
190
+ setDataPointCalloutProps(point);
191
+ setCallOutAccessibilityData(point.callOutAccessibilityData);
192
+ }
193
+ });
194
+ }
195
+ }
196
+ function _getScales(containerHeight, containerWidth, isNumericScale) {
197
+ if (isNumericScale) {
198
+ const xMax = (0, _d3array.max)(_points, (point)=>point.x);
199
+ const yMax = (0, _d3array.max)(_points, (point)=>point.y);
200
+ const xBarScale = (0, _d3scale.scaleLinear)().domain(_isRtl ? [
201
+ xMax,
202
+ 0
203
+ ] : [
204
+ 0,
205
+ xMax
206
+ ]).nice().range([
207
+ _margins.left,
208
+ containerWidth - _margins.right
209
+ ]);
210
+ const yBarScale = (0, _d3scale.scaleLinear)().domain([
211
+ 0,
212
+ yMax
213
+ ]).range([
214
+ containerHeight - _margins.bottom,
215
+ _margins.top
216
+ ]);
217
+ return {
218
+ xBarScale,
219
+ yBarScale
220
+ };
221
+ } else {
222
+ const xMax = (0, _d3array.max)(_points, (point)=>point.x);
223
+ // please note these padding default values must be consistent in here
224
+ // and CatrtesianChartBase w for more details refer example
225
+ // http://using-d3js.com/04_07_ordinal_scales.html
226
+ const yBarScale = (0, _d3scale.scaleBand)().domain(_yAxisLabels).range([
227
+ containerHeight - _margins.bottom - _barHeight / 2,
228
+ _margins.top + _barHeight / 2
229
+ ]).padding(props.yAxisPadding || 0);
230
+ const xBarScale = (0, _d3scale.scaleLinear)().domain(_isRtl ? [
231
+ xMax,
232
+ 0
233
+ ] : [
234
+ 0,
235
+ xMax
236
+ ]).nice().range([
237
+ _margins.left,
238
+ containerWidth - _margins.right
239
+ ]);
240
+ return {
241
+ xBarScale,
242
+ yBarScale
243
+ };
244
+ }
245
+ }
246
+ function _createNumericBars(containerHeight, containerWidth, xElement, yElement) {
247
+ const { useSingleColor = false } = props;
248
+ const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth, true);
249
+ const sortedBars = [
250
+ ..._points
251
+ ];
252
+ sortedBars.sort((a, b)=>{
253
+ const aValue = typeof a.y === 'number' ? a.y : parseFloat(a.y);
254
+ const bValue = typeof b.y === 'number' ? b.y : parseFloat(b.y);
255
+ return bValue - aValue;
256
+ });
257
+ const bars = sortedBars.map((point, index)=>{
258
+ let shouldHighlight = true;
259
+ if (isLegendHovered || isLegendSelected) {
260
+ shouldHighlight = _isLegendHighlighted(point.legend);
261
+ }
262
+ const barHeight = Math.max(yBarScale(point.y), 0);
263
+ if (barHeight < 1) {
264
+ return /*#__PURE__*/ _react.createElement(_react.Fragment, {
265
+ key: point.x
266
+ }, " ");
267
+ }
268
+ let startColor;
269
+ if (useSingleColor) {
270
+ //if useSingle color , then check if user has given a palette or not
271
+ // and pick the first color from that or else from our paltette.
272
+ startColor = props.colors ? _createColors()(1) : (0, _index.getNextColor)(1, 0);
273
+ } else {
274
+ startColor = props.colors ? _createColors()(point.x) : (0, _index.getNextColor)(index, 0);
275
+ }
276
+ startColor = point.color && !useSingleColor ? point.color : startColor;
277
+ return /*#__PURE__*/ _react.createElement(_react.Fragment, {
278
+ key: `${index}_${point.x}`
279
+ }, /*#__PURE__*/ _react.createElement("rect", {
280
+ key: point.y,
281
+ x: _isRtl ? xBarScale(point.x) : _margins.left,
282
+ y: yBarScale(point.y) - _barHeight / 2,
283
+ "data-is-focusable": shouldHighlight,
284
+ width: _isRtl ? containerWidth - _margins.right - Math.max(xBarScale(point.x), 0) : Math.max(xBarScale(point.x), 0) - _margins.left,
285
+ height: _barHeight,
286
+ ref: (e)=>{
287
+ _refCallback(e, point.legend);
288
+ },
289
+ rx: props.roundCorners ? 3 : 0,
290
+ onClick: point.onClick,
291
+ onMouseOver: (event)=>_onBarHover(point, startColor, event),
292
+ "aria-label": _getAriaLabel(point),
293
+ role: "img",
294
+ "aria-labelledby": `toolTip${_calloutId}`,
295
+ onMouseLeave: _onBarLeave,
296
+ onFocus: ()=>_onBarFocus(point, index, startColor),
297
+ onBlur: _onBarLeave,
298
+ fill: startColor,
299
+ opacity: shouldHighlight ? 1 : 0.1,
300
+ tabIndex: point.legend !== '' ? 0 : undefined
301
+ }));
302
+ });
303
+ return bars;
304
+ }
305
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
306
+ function _tooltipOfYAxislabels(ytooltipProps) {
307
+ const { tooltipCls, yAxis, id } = ytooltipProps;
308
+ if (yAxis === null) {
309
+ return null;
310
+ }
311
+ const div = (0, _d3selection.select)('body').append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
312
+ const aa = yAxis.selectAll('#BaseSpan')._groups[0];
313
+ const baseSpanLength = aa && Object.keys(aa).length;
314
+ const originalDataArray = [];
315
+ for(let i = 0; i < baseSpanLength; i++){
316
+ const originalData = aa[i].dataset && Object.values(aa[i].dataset)[0];
317
+ originalDataArray.push(originalData);
318
+ }
319
+ const tickObject = yAxis.selectAll('.tick')._groups[0];
320
+ const tickObjectLength = tickObject && Object.keys(tickObject).length;
321
+ for(let i = 0; i < tickObjectLength; i++){
322
+ const d1 = tickObject[i];
323
+ (0, _d3selection.select)(d1) // eslint-disable-next-line @typescript-eslint/no-explicit-any
324
+ .on('mouseover', (event, d)=>{
325
+ if (!tooltipElement) {
326
+ div.style('opacity', 0.9);
327
+ div.text(originalDataArray[i]).style('left', event.pageX + 'px').style('top', event.pageY - 28 + 'px');
328
+ }
329
+ }).on('mouseout', (d)=>{
330
+ div.style('opacity', 0);
331
+ });
332
+ }
333
+ }
334
+ function _createStringBars(containerHeight, containerWidth, xElement, yElement) {
335
+ const { xBarScale, yBarScale } = _getScales(containerHeight, containerWidth, false);
336
+ const { useSingleColor = false } = props;
337
+ const bars = _points.map((point, index)=>{
338
+ let shouldHighlight = true;
339
+ if (isLegendHovered || isLegendSelected) {
340
+ shouldHighlight = _isLegendHighlighted(point.legend);
341
+ }
342
+ const barHeight = Math.max(yBarScale(point.y), 0);
343
+ if (barHeight < 1) {
344
+ return /*#__PURE__*/ _react.createElement(_react.Fragment, {
345
+ key: point.x
346
+ }, " ");
347
+ }
348
+ let startColor;
349
+ if (useSingleColor) {
350
+ //if useSingle color , then check if user has given a palette or not
351
+ // and pick the first color from that or else from our paltette.
352
+ startColor = props.colors ? _createColors()(1) : (0, _index.getNextColor)(1, 0);
353
+ } else {
354
+ startColor = props.colors ? _createColors()(point.x) : (0, _index.getNextColor)(index, 0);
355
+ }
356
+ startColor = point.color && !useSingleColor ? point.color : startColor;
357
+ return /*#__PURE__*/ _react.createElement(_react.Fragment, {
358
+ key: `${index}_${point.x}`
359
+ }, /*#__PURE__*/ _react.createElement("rect", {
360
+ transform: `translate(0,${0.5 * (yBarScale.bandwidth() - _barHeight)})`,
361
+ key: point.x,
362
+ x: _isRtl ? xBarScale(point.x) : _margins.left,
363
+ y: yBarScale(point.y),
364
+ rx: props.roundCorners ? 3 : 0,
365
+ width: _isRtl ? containerWidth - _margins.right - Math.max(xBarScale(point.x), 0) : Math.max(xBarScale(point.x), 0) - _margins.left,
366
+ height: _barHeight,
367
+ "aria-labelledby": `toolTip${_calloutId}`,
368
+ "aria-label": _getAriaLabel(point),
369
+ role: "img",
370
+ ref: (e)=>{
371
+ _refCallback(e, point.legend);
372
+ },
373
+ onClick: point.onClick,
374
+ onMouseOver: (event)=>_onBarHover(point, startColor, event),
375
+ onMouseLeave: _onBarLeave,
376
+ onBlur: _onBarLeave,
377
+ "data-is-focusable": shouldHighlight,
378
+ opacity: shouldHighlight ? 1 : 0.1,
379
+ onFocus: ()=>_onBarFocus(point, index, startColor),
380
+ fill: startColor,
381
+ tabIndex: point.legend !== '' ? 0 : undefined
382
+ }));
383
+ });
384
+ // Removing un wanted tooltip div from DOM, when prop not provided, for proper cleanup
385
+ // of unwanted DOM elements, to prevent flacky behaviour in tooltips , that might occur
386
+ // in creating tooltips when tooltips are enabled( as we try to recreate a tspan with _tooltipId)
387
+ if (!props.showYAxisLablesTooltip) {
388
+ try {
389
+ // eslint-disable-next-line @nx/workspace-no-restricted-globals
390
+ document.getElementById(_tooltipId) && document.getElementById(_tooltipId).remove();
391
+ //eslint-disable-next-line no-empty
392
+ } catch (e) {}
393
+ }
394
+ // Used to display tooltip at y axis labels.
395
+ if (props.showYAxisLablesTooltip) {
396
+ const yAxisElement = (0, _d3selection.select)(yElement).call(yBarScale);
397
+ if (!tooltipElement) {
398
+ try {
399
+ // eslint-disable-next-line @nx/workspace-no-restricted-globals
400
+ document.getElementById(_tooltipId) && document.getElementById(_tooltipId).remove();
401
+ //eslint-disable-next-line no-empty
402
+ } catch (e) {}
403
+ }
404
+ const ytooltipProps = {
405
+ tooltipCls: classes.tooltip,
406
+ id: _tooltipId,
407
+ yAxis: yAxisElement
408
+ };
409
+ yAxisElement && _tooltipOfYAxislabels(ytooltipProps);
410
+ }
411
+ return bars;
412
+ }
413
+ function _onLegendHover(customMessage) {
414
+ if (!_isLegendSelected()) {
415
+ setIsLegendHovered(true);
416
+ setSelectedLegendTitle(customMessage);
417
+ }
418
+ }
419
+ function _onLegendLeave(isLegendFocused) {
420
+ if (!!isLegendFocused || !_isLegendSelected()) {
421
+ setIsLegendHovered(false);
422
+ setSelectedLegendTitle('');
423
+ setIsLegendSelected(isLegendFocused ? false : _isLegendSelected());
424
+ }
425
+ }
426
+ function _getLegendData(data) {
427
+ const { useSingleColor } = props;
428
+ const actions = [];
429
+ data.forEach((point, _index1)=>{
430
+ // eslint-disable-next-line @typescript-eslint/no-shadow
431
+ const color = useSingleColor ? props.colors ? _createColors()(1) : (0, _index.getNextColor)(1, 0) : point.color;
432
+ // mapping data to the format Legends component needs
433
+ const legend = {
434
+ title: point.legend,
435
+ color,
436
+ hoverAction: ()=>{
437
+ _handleChartMouseLeave();
438
+ _onLegendHover(point.legend);
439
+ },
440
+ // eslint-disable-next-line @typescript-eslint/no-shadow
441
+ onMouseOutAction: (isLegendSelected)=>{
442
+ _onLegendLeave(isLegendSelected);
443
+ }
444
+ };
445
+ actions.push(legend);
446
+ });
447
+ const legends = /*#__PURE__*/ _react.createElement(_Legends.Legends, {
448
+ legends: actions,
449
+ enabledWrapLines: props.enabledLegendsWrapLines,
450
+ overflowText: props.legendsOverflowText,
451
+ ...props.legendProps,
452
+ onChange: _onLegendSelectionChange
453
+ });
454
+ return legends;
455
+ }
456
+ function _isLegendSelected() {
457
+ return isLegendSelected;
458
+ }
459
+ /**
460
+ * This function checks if the given legend is highlighted or not.
461
+ * A legend can be highlighted in 2 ways:
462
+ * 1. selection: if the user clicks on it
463
+ * 2. hovering: if there is no selected legend and the user hovers over it
464
+ */ function _isLegendHighlighted(legend) {
465
+ return _getHighlightedLegend().includes(legend);
466
+ }
467
+ function _getHighlightedLegend() {
468
+ return selectedLegends.length > 0 ? selectedLegends : selectedLegendTitle ? [
469
+ selectedLegendTitle
470
+ ] : [];
471
+ }
472
+ function _onLegendSelectionChange(selectedLegends, event, currentLegend) {
473
+ var _props_legendProps, _props_legendProps1;
474
+ if ((_props_legendProps = props.legendProps) === null || _props_legendProps === void 0 ? void 0 : _props_legendProps.canSelectMultipleLegends) {
475
+ setSelectedLegends(selectedLegends);
476
+ setSelectedLegendTitle(currentLegend === null || currentLegend === void 0 ? void 0 : currentLegend.title);
477
+ } else {
478
+ setSelectedLegends(selectedLegends.slice(-1));
479
+ setSelectedLegendTitle(currentLegend === null || currentLegend === void 0 ? void 0 : currentLegend.title);
480
+ }
481
+ setIsLegendSelected(selectedLegends.length > 0);
482
+ if ((_props_legendProps1 = props.legendProps) === null || _props_legendProps1 === void 0 ? void 0 : _props_legendProps1.onChange) {
483
+ props.legendProps.onChange(selectedLegends, event, currentLegend);
484
+ }
485
+ }
486
+ function _getAxisData(yAxisData) {
487
+ if (yAxisData && yAxisData.yAxisDomainValues.length) {
488
+ // For HBCWA x and y Values are swapped
489
+ const { yAxisDomainValues: domainValue } = yAxisData;
490
+ _xMax = Math.max(domainValue[domainValue.length - 1], props.xMaxValue || 0);
491
+ }
492
+ }
493
+ function _getAriaLabel(point) {
494
+ var _point_callOutAccessibilityData;
495
+ const xValue = point.xAxisCalloutData || point.x;
496
+ const yValue = point.yAxisCalloutData || point.y;
497
+ return ((_point_callOutAccessibilityData = point.callOutAccessibilityData) === null || _point_callOutAccessibilityData === void 0 ? void 0 : _point_callOutAccessibilityData.ariaLabel) || `${xValue}. ` + `${yValue}.`;
498
+ }
499
+ function _getChartTitle() {
500
+ const { chartTitle, data } = props;
501
+ return (chartTitle ? `${chartTitle}. ` : '') + `Horizontal bar chart with ${(data === null || data === void 0 ? void 0 : data.length) || 0} bars. `;
502
+ }
503
+ function _isChartEmpty() {
504
+ return !(props.data && props.data.length > 0);
505
+ }
506
+ function _updatePosition(newX, newY) {
507
+ const threshold = 1; // Set a threshold for movement
508
+ const { x, y } = clickPosition;
509
+ // Calculate the distance moved
510
+ const distance = Math.sqrt(Math.pow(newX - x, 2) + Math.pow(newY - y, 2));
511
+ // Update the position only if the distance moved is greater than the threshold
512
+ if (distance > threshold) {
513
+ setClickPosition({
514
+ x: newX,
515
+ y: newY
516
+ });
517
+ setPopoverOpen(true);
518
+ }
519
+ }
520
+ if (!_isChartEmpty()) {
521
+ _adjustProps();
522
+ const calloutProps = {
523
+ color: color,
524
+ legend: selectedLegendTitle,
525
+ XValue: xCalloutValue,
526
+ YValue: yCalloutValue ? yCalloutValue : dataForHoverCard,
527
+ ...props.calloutProps,
528
+ ...(0, _index.getAccessibleDataObject)(callOutAccessibilityData),
529
+ customCallout: {
530
+ customizedCallout: _getCustomizedCallout() !== null ? _getCustomizedCallout() : undefined,
531
+ customCalloutProps: props.calloutPropsPerDataPoint ? props.calloutPropsPerDataPoint(dataPointCalloutProps) : undefined
532
+ },
533
+ isCartesian: true,
534
+ isPopoverOpen,
535
+ clickPosition
536
+ };
537
+ const tickParams = {
538
+ tickValues: props.tickValues,
539
+ tickFormat: props.tickFormat
540
+ };
541
+ const reversedBars = [
542
+ ..._points
543
+ ].reverse();
544
+ _yAxisLabels = reversedBars.map((point)=>point.y);
545
+ _xMax = Math.max((0, _d3array.max)(_points, (point)=>point.x), props.xMaxValue || 0);
546
+ const legendBars = _getLegendData(_points);
547
+ return /*#__PURE__*/ _react.createElement(_CartesianChart.CartesianChart, {
548
+ ...props,
549
+ chartTitle: _getChartTitle(),
550
+ points: _points,
551
+ chartType: _index.ChartTypes.HorizontalBarChartWithAxis,
552
+ xAxisType: _xAxisType,
553
+ yAxisType: _yAxisType,
554
+ stringDatasetForYAxisDomain: _yAxisLabels,
555
+ calloutProps: calloutProps,
556
+ tickParams: tickParams,
557
+ legendBars: legendBars,
558
+ barwidth: _barHeight,
559
+ getmargins: _getMargins,
560
+ getGraphData: _getGraphData,
561
+ getAxisData: _getAxisData,
562
+ onChartMouseLeave: _handleChartMouseLeave,
563
+ componentRef: cartesianChartRef,
564
+ /* eslint-disable react/jsx-no-bind */ // eslint-disable-next-line @typescript-eslint/no-shadow
565
+ children: (props)=>{
566
+ return /*#__PURE__*/ _react.createElement(_react.Fragment, null, /*#__PURE__*/ _react.createElement("g", null, _bars));
567
+ }
568
+ });
569
+ } else {
570
+ return /*#__PURE__*/ _react.createElement("div", {
571
+ id: _emptyChartId,
572
+ role: 'alert',
573
+ style: {
574
+ opacity: '0'
575
+ },
576
+ "aria-label": 'Graph has no data to display'
577
+ });
578
+ }
579
+ });
580
+ HorizontalBarChartWithAxis.displayName = 'HorizontalBarChartWithAxis';