@fluentui/react-charts 9.2.1 → 9.2.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 (201) hide show
  1. package/CHANGELOG.md +57 -2
  2. package/dist/index.d.ts +168 -15
  3. package/lib/ChartTable.js +1 -0
  4. package/lib/ChartTable.js.map +1 -0
  5. package/lib/components/AreaChart/AreaChart.js +4 -1
  6. package/lib/components/AreaChart/AreaChart.js.map +1 -1
  7. package/lib/components/AreaChart/useAreaChartStyles.styles.js +2 -1
  8. package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
  9. package/lib/components/AreaChart/useAreaChartStyles.styles.raw.js +2 -1
  10. package/lib/components/AreaChart/useAreaChartStyles.styles.raw.js.map +1 -1
  11. package/lib/components/ChartTable/ChartTable.js +58 -0
  12. package/lib/components/ChartTable/ChartTable.js.map +1 -0
  13. package/lib/components/ChartTable/ChartTable.types.js +1 -0
  14. package/lib/components/ChartTable/ChartTable.types.js.map +1 -0
  15. package/lib/components/ChartTable/index.js +3 -0
  16. package/lib/components/ChartTable/index.js.map +1 -0
  17. package/lib/components/ChartTable/useChartTableStyles.styles.js +93 -0
  18. package/lib/components/ChartTable/useChartTableStyles.styles.js.map +1 -0
  19. package/lib/components/ChartTable/useChartTableStyles.styles.raw.js +55 -0
  20. package/lib/components/ChartTable/useChartTableStyles.styles.raw.js.map +1 -0
  21. package/lib/components/CommonComponents/CartesianChart.js +170 -100
  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/CommonComponents/ChartPopover.types.js.map +1 -1
  25. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +13 -0
  26. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  27. package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js +12 -0
  28. package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
  29. package/lib/components/DeclarativeChart/DeclarativeChart.js +180 -102
  30. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  31. package/lib/components/DeclarativeChart/PlotlyColorAdapter.js +100 -0
  32. package/lib/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -0
  33. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +890 -211
  34. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  35. package/lib/components/DonutChart/DonutChart.js +2 -2
  36. package/lib/components/DonutChart/DonutChart.js.map +1 -1
  37. package/lib/components/DonutChart/DonutChart.types.js.map +1 -1
  38. package/lib/components/DonutChart/Pie/Pie.js.map +1 -1
  39. package/lib/components/FunnelChart/FunnelChart.js.map +1 -1
  40. package/lib/components/GanttChart/GanttChart.js.map +1 -1
  41. package/lib/components/GanttChart/useGanttChartStyles.styles.js +2 -1
  42. package/lib/components/GanttChart/useGanttChartStyles.styles.js.map +1 -1
  43. package/lib/components/GanttChart/useGanttChartStyles.styles.raw.js +2 -1
  44. package/lib/components/GanttChart/useGanttChartStyles.styles.raw.js.map +1 -1
  45. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +185 -144
  46. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  47. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +2 -1
  48. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  49. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.raw.js +2 -1
  50. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.raw.js.map +1 -1
  51. package/lib/components/HeatMapChart/HeatMapChart.js +175 -114
  52. package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -1
  53. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js +2 -1
  54. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -1
  55. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.raw.js +2 -1
  56. package/lib/components/HeatMapChart/useHeatMapChartStyles.styles.raw.js.map +1 -1
  57. package/lib/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -1
  58. package/lib/components/HorizontalBarChart/HorizontalBarChart.types.js.map +1 -1
  59. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +26 -6
  60. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  61. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +2 -1
  62. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -1
  63. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.raw.js +2 -1
  64. package/lib/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.raw.js.map +1 -1
  65. package/lib/components/Legends/Legends.js.map +1 -1
  66. package/lib/components/Legends/OverflowMenu.js.map +1 -1
  67. package/lib/components/LineChart/LineChart.js +251 -78
  68. package/lib/components/LineChart/LineChart.js.map +1 -1
  69. package/lib/components/LineChart/LineChart.types.js.map +1 -1
  70. package/lib/components/LineChart/useLineChartStyles.styles.js +10 -3
  71. package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  72. package/lib/components/LineChart/useLineChartStyles.styles.raw.js +14 -2
  73. package/lib/components/LineChart/useLineChartStyles.styles.raw.js.map +1 -1
  74. package/lib/components/ScatterChart/ScatterChart.js +56 -37
  75. package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
  76. package/lib/components/ScatterChart/ScatterChart.types.js.map +1 -1
  77. package/lib/components/ScatterChart/useScatterChartStyles.styles.js +21 -4
  78. package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  79. package/lib/components/ScatterChart/useScatterChartStyles.styles.raw.js +16 -3
  80. package/lib/components/ScatterChart/useScatterChartStyles.styles.raw.js.map +1 -1
  81. package/lib/components/VerticalBarChart/VerticalBarChart.js +38 -14
  82. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  83. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +2 -1
  84. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  85. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.raw.js +2 -1
  86. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.raw.js.map +1 -1
  87. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +214 -96
  88. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  89. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -1
  90. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +2 -1
  91. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
  92. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.raw.js +2 -1
  93. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.raw.js.map +1 -1
  94. package/lib/index.js +1 -0
  95. package/lib/index.js.map +1 -1
  96. package/lib/types/DataPoint.js.map +1 -1
  97. package/lib/utilities/FocusableTooltipText.js.map +1 -1
  98. package/lib/utilities/utilities.js +41 -42
  99. package/lib/utilities/utilities.js.map +1 -1
  100. package/lib/utilities/vbc-utils.js +24 -0
  101. package/lib/utilities/vbc-utils.js.map +1 -1
  102. package/lib-commonjs/ChartTable.js +6 -0
  103. package/lib-commonjs/ChartTable.js.map +1 -0
  104. package/lib-commonjs/components/AreaChart/AreaChart.js +4 -1
  105. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
  106. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +2 -1
  107. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
  108. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.raw.js +2 -1
  109. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.raw.js.map +1 -1
  110. package/lib-commonjs/components/ChartTable/ChartTable.js +69 -0
  111. package/lib-commonjs/components/ChartTable/ChartTable.js.map +1 -0
  112. package/lib-commonjs/components/ChartTable/ChartTable.types.js +6 -0
  113. package/lib-commonjs/components/ChartTable/ChartTable.types.js.map +1 -0
  114. package/lib-commonjs/components/ChartTable/index.js +8 -0
  115. package/lib-commonjs/components/ChartTable/index.js.map +1 -0
  116. package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.js +196 -0
  117. package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.js.map +1 -0
  118. package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.raw.js +69 -0
  119. package/lib-commonjs/components/ChartTable/useChartTableStyles.styles.raw.js.map +1 -0
  120. package/lib-commonjs/components/CommonComponents/CartesianChart.js +169 -98
  121. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  122. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  123. package/lib-commonjs/components/CommonComponents/ChartPopover.types.js.map +1 -1
  124. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +13 -0
  125. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  126. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js +12 -0
  127. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
  128. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +176 -100
  129. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  130. package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js +128 -0
  131. package/lib-commonjs/components/DeclarativeChart/PlotlyColorAdapter.js.map +1 -0
  132. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +909 -209
  133. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  134. package/lib-commonjs/components/DonutChart/DonutChart.js +1 -1
  135. package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
  136. package/lib-commonjs/components/DonutChart/DonutChart.types.js.map +1 -1
  137. package/lib-commonjs/components/DonutChart/Pie/Pie.js.map +1 -1
  138. package/lib-commonjs/components/FunnelChart/FunnelChart.js.map +1 -1
  139. package/lib-commonjs/components/GanttChart/GanttChart.js.map +1 -1
  140. package/lib-commonjs/components/GanttChart/useGanttChartStyles.styles.js +2 -1
  141. package/lib-commonjs/components/GanttChart/useGanttChartStyles.styles.js.map +1 -1
  142. package/lib-commonjs/components/GanttChart/useGanttChartStyles.styles.raw.js +2 -1
  143. package/lib-commonjs/components/GanttChart/useGanttChartStyles.styles.raw.js.map +1 -1
  144. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +183 -142
  145. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  146. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +2 -1
  147. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  148. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.raw.js +2 -1
  149. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.raw.js.map +1 -1
  150. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +174 -113
  151. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -1
  152. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js +2 -1
  153. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.js.map +1 -1
  154. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.raw.js +2 -1
  155. package/lib-commonjs/components/HeatMapChart/useHeatMapChartStyles.styles.raw.js.map +1 -1
  156. package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.js.map +1 -1
  157. package/lib-commonjs/components/HorizontalBarChart/HorizontalBarChart.types.js.map +1 -1
  158. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +25 -5
  159. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  160. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js +2 -1
  161. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.js.map +1 -1
  162. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.raw.js +2 -1
  163. package/lib-commonjs/components/HorizontalBarChartWithAxis/useHorizontalBarChartWithAxisStyles.styles.raw.js.map +1 -1
  164. package/lib-commonjs/components/Legends/Legends.js.map +1 -1
  165. package/lib-commonjs/components/Legends/OverflowMenu.js.map +1 -1
  166. package/lib-commonjs/components/LineChart/LineChart.js +250 -78
  167. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  168. package/lib-commonjs/components/LineChart/LineChart.types.js.map +1 -1
  169. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +12 -3
  170. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  171. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.raw.js +14 -2
  172. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.raw.js.map +1 -1
  173. package/lib-commonjs/components/ScatterChart/ScatterChart.js +56 -37
  174. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  175. package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -1
  176. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +30 -3
  177. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  178. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.raw.js +15 -2
  179. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.raw.js.map +1 -1
  180. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +37 -13
  181. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  182. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +2 -1
  183. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  184. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.raw.js +2 -1
  185. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.raw.js.map +1 -1
  186. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +213 -95
  187. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  188. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.types.js.map +1 -1
  189. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +2 -1
  190. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
  191. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.raw.js +2 -1
  192. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.raw.js.map +1 -1
  193. package/lib-commonjs/index.js +1 -0
  194. package/lib-commonjs/index.js.map +1 -1
  195. package/lib-commonjs/types/DataPoint.js.map +1 -1
  196. package/lib-commonjs/utilities/FocusableTooltipText.js.map +1 -1
  197. package/lib-commonjs/utilities/utilities.js +44 -41
  198. package/lib-commonjs/utilities/utilities.js.map +1 -1
  199. package/lib-commonjs/utilities/vbc-utils.js +27 -0
  200. package/lib-commonjs/utilities/vbc-utils.js.map +1 -1
  201. package/package.json +10 -10
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { ChartTypes, getAccessibleDataObject, getColorContrast, getTypeOfAxis, resolveCSSVariables, XAxisTypes, YAxisType, createNumericYAxis, domainRangeOfXStringAxis, createStringYAxis, useRtl } from '../../utilities/index';
2
+ import { ChartTypes, getAccessibleDataObject, getColorContrast, getTypeOfAxis, resolveCSSVariables, XAxisTypes, YAxisType, createNumericYAxis, domainRangeOfXStringAxis, createStringYAxis, useRtl, sortAxisCategories } from '../../utilities/index';
3
3
  import { formatToLocaleString } from '@fluentui/chart-utilities';
4
4
  import { CartesianChart } from '../CommonComponents/index';
5
5
  import { useId } from '@fluentui/react-utilities';
@@ -10,7 +10,13 @@ import { scaleLinear as d3ScaleLinear } from 'd3-scale';
10
10
  import { format as d3Format } from 'd3-format';
11
11
  import { timeFormat as d3TimeFormat } from 'd3-time-format';
12
12
  import { toImage } from '../../utilities/image-export-utils';
13
- export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
13
+ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props = {
14
+ xAxisCategoryOrder: 'default',
15
+ yAxisCategoryOrder: 'default',
16
+ data: [],
17
+ domainValuesForColorScale: [],
18
+ rangeValuesForColorScale: []
19
+ }, forwardedRef)=>{
14
20
  const classes = useHeatMapChartStyles(props);
15
21
  const _stringXAxisDataPoints = React.useRef([]);
16
22
  const _stringYAxisDataPoints = React.useRef([]);
@@ -135,16 +141,16 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
135
141
  return color === tokens.colorNeutralForeground1 ? tokens.colorNeutralBackground1 : tokens.colorNeutralForeground1;
136
142
  };
137
143
  /**
138
- * This is the function which is responsible for
139
- * drawing the rectangle in the graph and also
140
- * attaching dom events to that rectangles
141
- */ const _createRectangles = ()=>{
144
+ * This is the function which is responsible for
145
+ * drawing the rectangle in the graph and also
146
+ * attaching dom events to that rectangles
147
+ */ const _createRectangles = ()=>{
142
148
  const rectangles = [];
143
149
  const yAxisDataPoints = _stringYAxisDataPoints.current.slice().reverse();
144
150
  /**
145
- * yAxisDataPoint is noting but the DataPoint
146
- * which will be rendered on the y-axis
147
- */ yAxisDataPoints.forEach((yAxisDataPoint)=>{
151
+ * yAxisDataPoint is noting but the DataPoint
152
+ * which will be rendered on the y-axis
153
+ */ yAxisDataPoints.forEach((yAxisDataPoint)=>{
148
154
  let index = 0;
149
155
  _stringXAxisDataPoints.current.forEach((xAxisDataPoint)=>{
150
156
  var _dataSet_current_yAxisDataPoint_index, _dataSet_current_yAxisDataPoint_index1;
@@ -153,9 +159,9 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
153
159
  if (((_dataSet_current_yAxisDataPoint_index = _dataSet.current[yAxisDataPoint][index]) === null || _dataSet_current_yAxisDataPoint_index === void 0 ? void 0 : _dataSet_current_yAxisDataPoint_index.x) === xAxisDataPoint && typeof ((_dataSet_current_yAxisDataPoint_index1 = _dataSet.current[yAxisDataPoint][index]) === null || _dataSet_current_yAxisDataPoint_index1 === void 0 ? void 0 : _dataSet_current_yAxisDataPoint_index1.value) === 'number') {
154
160
  var _cartesianChartRef_current;
155
161
  /**
156
- * dataPointObject is an object where it contains information on single
157
- * data point such as x, y , value, rectText property of the rectangle
158
- */ const dataPointObject = _dataSet.current[yAxisDataPoint][index];
162
+ * dataPointObject is an object where it contains information on single
163
+ * data point such as x, y , value, rectText property of the rectangle
164
+ */ const dataPointObject = _dataSet.current[yAxisDataPoint][index];
159
165
  let styleRules = '';
160
166
  let foregroundColor = tokens.colorNeutralForeground1;
161
167
  if ((_cartesianChartRef_current = cartesianChartRef.current) === null || _cartesianChartRef_current === void 0 ? void 0 : _cartesianChartRef_current.chartContainer) {
@@ -219,30 +225,30 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
219
225
  return rectangles;
220
226
  };
221
227
  /**
222
- * when the legend is hovered we need to highlight
223
- * all the rectangles which fall under that category
224
- * and un-highlight the rest of them
225
- * @param legendTitle
226
- */ const _onLegendHover = (legendTitle)=>{
228
+ * when the legend is hovered we need to highlight
229
+ * all the rectangles which fall under that category
230
+ * and un-highlight the rest of them
231
+ * @param legendTitle
232
+ */ const _onLegendHover = (legendTitle)=>{
227
233
  setActiveLegend(legendTitle);
228
234
  };
229
235
  /**
230
- * when the mouse is out from the legend , we need
231
- * to show the graph in initial mode.
232
- */ const _onLegendLeave = ()=>{
236
+ * when the mouse is out from the legend , we need
237
+ * to show the graph in initial mode.
238
+ */ const _onLegendLeave = ()=>{
233
239
  setActiveLegend('');
234
240
  };
235
241
  /**
236
- * @param legendTitle
237
- * when the legend is clicked we need to highlight
238
- * all the rectangles which fall under that category
239
- * and un highlight the rest of them
240
- */ const _onLegendClick = (legendTitle)=>{
242
+ * @param legendTitle
243
+ * when the legend is clicked we need to highlight
244
+ * all the rectangles which fall under that category
245
+ * and un highlight the rest of them
246
+ */ const _onLegendClick = (legendTitle)=>{
241
247
  /**
242
- * check if the legend is already selceted,
243
- * if yes, un-select the legend, else
244
- * set the selected legend state to legendTitle
245
- */ if (selectedLegend === legendTitle) {
248
+ * check if the legend is already selceted,
249
+ * if yes, un-select the legend, else
250
+ * set the selected legend state to legendTitle
251
+ */ if (selectedLegend === legendTitle) {
246
252
  setSelectedLegend('');
247
253
  } else {
248
254
  setSelectedLegend(legendTitle);
@@ -313,19 +319,13 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
313
319
  yAxisStringFormatter
314
320
  ]);
315
321
  /**
316
- * This function will return the final sorted and formatted x-axis points
317
- * which will be rendered on the x-axis
318
- * @param points
319
- * @returns x-axis points
320
- */ const _getXAxisDataPoints = React.useCallback((points)=>{
322
+ * This function will return the final sorted and formatted x-axis points
323
+ * which will be rendered on the x-axis
324
+ * @param points
325
+ * @returns x-axis points
326
+ */ const _getXAxisDataPoints = React.useCallback((points)=>{
321
327
  let xAxisPoints = [];
322
- const unFormattedXAxisDataPoints = Object.keys(points).sort((a, b)=>{
323
- if (_xAxisType.current === XAxisTypes.DateAxis || _xAxisType.current === XAxisTypes.NumericAxis) {
324
- return +a - +b;
325
- } else {
326
- return props.sortOrder === 'none' ? 0 : a.toLowerCase() > b.toLowerCase() ? 1 : -1;
327
- }
328
- });
328
+ const unFormattedXAxisDataPoints = _getOrderedXAxisLabels(points);
329
329
  xAxisPoints = unFormattedXAxisDataPoints.map((xPoint)=>{
330
330
  if (_xAxisType.current === XAxisTypes.DateAxis) {
331
331
  return _getStringFormattedDate(xPoint, props.xAxisDateFormatString);
@@ -343,19 +343,13 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
343
343
  props.xAxisNumberFormatString
344
344
  ]);
345
345
  /**
346
- * This function will return the final sorted and formatted y-axis points
347
- * which will be rendered on the y-axis
348
- * @param points
349
- * @returns yaxis points
350
- */ const _getYAxisDataPoints = React.useCallback((points)=>{
346
+ * This function will return the final sorted and formatted y-axis points
347
+ * which will be rendered on the y-axis
348
+ * @param points
349
+ * @returns yaxis points
350
+ */ const _getYAxisDataPoints = React.useCallback((points)=>{
351
351
  let yAxisPoints = [];
352
- const unFormattedYAxisDataPoints = Object.keys(points).sort((a, b)=>{
353
- if (_yAxisType.current === YAxisType.DateAxis || _yAxisType.current === YAxisType.NumericAxis) {
354
- return +a - +b;
355
- } else {
356
- return props.sortOrder === 'none' ? 0 : a.toLowerCase() > b.toLowerCase() ? 1 : -1;
357
- }
358
- });
352
+ const unFormattedYAxisDataPoints = _getOrderedYAxisLabels(points);
359
353
  yAxisPoints = unFormattedYAxisDataPoints.map((yPoint)=>{
360
354
  if (_yAxisType.current === YAxisType.DateAxis) {
361
355
  return _getStringFormattedDate(yPoint, props.yAxisDateFormatString);
@@ -373,24 +367,24 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
373
367
  props.yAxisNumberFormatString
374
368
  ]);
375
369
  /**
376
- * This will create a new data set based on the prop
377
- * @data
378
- * We will be using This data set to contsruct our rectangles
379
- * in the chart, we use this data set becuase, when we loop in this
380
- * data and build the heat map, it will support accessibility as
381
- * specified in the figma
382
- */ const _createNewDataSet = React.useCallback((data, xAxisDateFormatString, xAxisNumberFormatString, yAxisDateFormatString, yAxisNumberFormatString)=>{
370
+ * This will create a new data set based on the prop
371
+ * @data
372
+ * We will be using This data set to contsruct our rectangles
373
+ * in the chart, we use this data set becuase, when we loop in this
374
+ * data and build the heat map, it will support accessibility as
375
+ * specified in the figma
376
+ */ const _createNewDataSet = React.useCallback((data, xAxisDateFormatString, xAxisNumberFormatString, yAxisDateFormatString, yAxisNumberFormatString)=>{
383
377
  /**
384
- * please do not destructure any of the props here,
385
- * instead send them as parameter to this functions so that
386
- * this functions get called whenever the prop changes
387
- */ const flattenData = [];
378
+ * please do not destructure any of the props here,
379
+ * instead send them as parameter to this functions so that
380
+ * this functions get called whenever the prop changes
381
+ */ const flattenData = [];
388
382
  /**
389
- * below for each loop will store all the datapoints in the one array.
390
- * basically it will flatten the nestesd array (data prop) into single array
391
- * of object. where each object contains x, y, rectText , value and legend propety of single
392
- * data point.
393
- */ data.forEach((item)=>{
383
+ * below for each loop will store all the datapoints in the one array.
384
+ * basically it will flatten the nestesd array (data prop) into single array
385
+ * of object. where each object contains x, y, rectText , value and legend propety of single
386
+ * data point.
387
+ */ data.forEach((item)=>{
394
388
  item.data.forEach((point)=>{
395
389
  flattenData.push({
396
390
  ...point,
@@ -407,13 +401,13 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
407
401
  uniqueXPoints[posX] = '1';
408
402
  uniqueYPoints[posY] = '1';
409
403
  /** we will check if the property(posY) is already there in object, if Yes,
410
- * then we will append the item in the Array related to the pos, if not
411
- * then we will simply append the item in the new Array and
412
- * assign that array to the property (posY) in the Object
413
- * and finally we will get the array of Objects associated to each
414
- * property (which is nothing but y data point) and object in the
415
- * array are noting but x data points associated to the property y
416
- */ if (yPoints[posY]) {
404
+ * then we will append the item in the Array related to the pos, if not
405
+ * then we will simply append the item in the new Array and
406
+ * assign that array to the property (posY) in the Object
407
+ * and finally we will get the array of Objects associated to each
408
+ * property (which is nothing but y data point) and object in the
409
+ * array are noting but x data points associated to the property y
410
+ */ if (yPoints[posY]) {
417
411
  yPoints[posY] = [
418
412
  ...yPoints[posY],
419
413
  item
@@ -425,21 +419,12 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
425
419
  }
426
420
  });
427
421
  /**
428
- * we will now sort(ascending) the array's of y data point based on the x value
429
- * sorting is important to achive the accessibility order of the
430
- * rectangles and then format the x and y datapoints respectively
431
- */ Object.keys(yPoints).forEach((item)=>{
432
- yPoints[item].sort((a, b)=>{
433
- if (_xAxisType.current === XAxisTypes.StringAxis) {
434
- return props.sortOrder === 'none' ? 0 : a.x.toLowerCase() > b.x.toLowerCase() ? 1 : -1;
435
- } else if (_xAxisType.current === XAxisTypes.DateAxis) {
436
- return a.x.getTime() - b.x.getTime();
437
- } else if (_xAxisType.current === XAxisTypes.NumericAxis) {
438
- return +a.x > +b.x ? 1 : -1;
439
- } else {
440
- return a.x > b.x ? 1 : -1;
441
- }
442
- }).forEach((datapoint)=>{
422
+ * we will now sort(ascending) the array's of y data point based on the x value
423
+ * sorting is important to achive the accessibility order of the
424
+ * rectangles and then format the x and y datapoints respectively
425
+ */ Object.keys(yPoints).forEach((item)=>{
426
+ yPoints[item] = _getOrderedXPoints(yPoints[item]);
427
+ yPoints[item].forEach((datapoint)=>{
443
428
  if (_xAxisType.current === XAxisTypes.DateAxis) {
444
429
  datapoint.x = _getStringFormattedDate(datapoint.x, xAxisDateFormatString);
445
430
  }
@@ -461,14 +446,14 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
461
446
  });
462
447
  });
463
448
  /**
464
- * if y-axis data points are of type date or number or if we have string formatter,
465
- * then we need to change data points to their respective string
466
- * format, becuase in the private variable this._stringYAxisDatapoints, points will be stored in
467
- * string format. and in here `yPoint` are not so we need to change, so that
468
- * function `this._createRectangles` should work perfetcly while looping, and if we don't change
469
- * then `this._createRectangles` will fail while looping, causing the error
470
- * Cannot read property 'forEach' of undefined
471
- */ Object.keys(yPoints).forEach((yPoint)=>{
449
+ * if y-axis data points are of type date or number or if we have string formatter,
450
+ * then we need to change data points to their respective string
451
+ * format, becuase in the private variable _stringYAxisDatapoints, points will be stored in
452
+ * string format. and in here `yPoint` are not so we need to change, so that
453
+ * function `_createRectangles` should work perfetcly while looping, and if we don't change
454
+ * then `_createRectangles` will fail while looping, causing the error
455
+ * Cannot read property 'forEach' of undefined
456
+ */ Object.keys(yPoints).forEach((yPoint)=>{
472
457
  if (_yAxisType.current === YAxisType.DateAxis) {
473
458
  yPoints[_getStringFormattedDate(yPoint, yAxisDateFormatString)] = yPoints[yPoint];
474
459
  } else if (_yAxisType.current === YAxisType.NumericAxis) {
@@ -478,16 +463,16 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
478
463
  }
479
464
  });
480
465
  /**
481
- * assigning new data set
482
- */ const dataSet = yPoints;
466
+ * assigning new data set
467
+ */ const dataSet = yPoints;
483
468
  /**
484
- * These are the Y axis data points which will get rendered in the
485
- * Y axis in graph
486
- */ const yAxisPoints = _getYAxisDataPoints(uniqueYPoints);
469
+ * These are the Y axis data points which will get rendered in the
470
+ * Y axis in graph
471
+ */ const yAxisPoints = _getYAxisDataPoints(uniqueYPoints);
487
472
  /**
488
- * These are the x axis data points which will get rendered in the
489
- * x axis in the graph
490
- */ const xAxisPoints = _getXAxisDataPoints(uniqueXPoints);
473
+ * These are the x axis data points which will get rendered in the
474
+ * x axis in the graph
475
+ */ const xAxisPoints = _getXAxisDataPoints(uniqueXPoints);
491
476
  return {
492
477
  dataSet,
493
478
  yAxisPoints,
@@ -509,16 +494,16 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
509
494
  return d3Format(formatString || '.2~s')(+point);
510
495
  };
511
496
  /**
512
- * This function checks if the given legend is highlighted or not.
513
- * A legend can be highlighted in 2 ways:
514
- * 1. selection: if the user clicks on it
515
- * 2. hovering: if there is no selected legend and the user hovers over it
516
- */ const _legendHighlighted = (legendTitle)=>{
497
+ * This function checks if the given legend is highlighted or not.
498
+ * A legend can be highlighted in 2 ways:
499
+ * 1. selection: if the user clicks on it
500
+ * 2. hovering: if there is no selected legend and the user hovers over it
501
+ */ const _legendHighlighted = (legendTitle)=>{
517
502
  return selectedLegend === legendTitle || selectedLegend === '' && activeLegend === legendTitle;
518
503
  };
519
504
  /**
520
- * This function checks if none of the legends is selected or hovered.
521
- */ const _noLegendHighlighted = ()=>{
505
+ * This function checks if none of the legends is selected or hovered.
506
+ */ const _noLegendHighlighted = ()=>{
522
507
  return selectedLegend === '' && activeLegend === '';
523
508
  };
524
509
  const _getAriaLabel = (point)=>{
@@ -538,6 +523,82 @@ export const HeatMapChart = /*#__PURE__*/ React.forwardRef((props, forwardedRef)
538
523
  const numDataPoints = props.data.reduce((acc, curr)=>acc + curr.data.length, 0);
539
524
  return (chartTitle ? `${chartTitle}. ` : '') + `Heat map chart with ${numDataPoints} data points. `;
540
525
  };
526
+ const _getOrderedXAxisLabels = (points)=>{
527
+ if (!_shouldOrderXAxisLabelsByCategoryOrder()) {
528
+ // Keep the original ordering logic as the default behavior to ensure backward compatibility
529
+ return Object.keys(points).sort((a, b)=>{
530
+ if (_xAxisType.current === XAxisTypes.DateAxis || _xAxisType.current === XAxisTypes.NumericAxis) {
531
+ return +a - +b;
532
+ } else {
533
+ return props.sortOrder === 'none' ? 0 : a.toLowerCase() > b.toLowerCase() ? 1 : -1;
534
+ }
535
+ });
536
+ }
537
+ return sortAxisCategories(_mapCategoryToValues(), props.xAxisCategoryOrder);
538
+ };
539
+ const _getOrderedYAxisLabels = (points)=>{
540
+ if (!_shouldOrderYAxisLabelsByCategoryOrder()) {
541
+ // Keep the original ordering logic as the default behavior to ensure backward compatibility
542
+ return Object.keys(points).sort((a, b)=>{
543
+ if (_yAxisType.current === YAxisType.DateAxis || _yAxisType.current === YAxisType.NumericAxis) {
544
+ return +a - +b;
545
+ } else {
546
+ return props.sortOrder === 'none' ? 0 : a.toLowerCase() > b.toLowerCase() ? 1 : -1;
547
+ }
548
+ });
549
+ }
550
+ return sortAxisCategories(_mapCategoryToValues(true), props.yAxisCategoryOrder);
551
+ };
552
+ const _getOrderedXPoints = (xPoints)=>{
553
+ if (!_shouldOrderXAxisLabelsByCategoryOrder()) {
554
+ return xPoints.sort((a, b)=>{
555
+ if (_xAxisType.current === XAxisTypes.StringAxis) {
556
+ return props.sortOrder === 'none' ? 0 : a.x.toLowerCase() > b.x.toLowerCase() ? 1 : -1;
557
+ } else if (_xAxisType.current === XAxisTypes.DateAxis) {
558
+ return a.x.getTime() - b.x.getTime();
559
+ } else if (_xAxisType.current === XAxisTypes.NumericAxis) {
560
+ return +a.x > +b.x ? 1 : -1;
561
+ } else {
562
+ return a.x > b.x ? 1 : -1;
563
+ }
564
+ });
565
+ }
566
+ const result = [];
567
+ const xValueToPoints = {};
568
+ xPoints.forEach((point)=>{
569
+ const xValue = point.x;
570
+ if (!xValueToPoints[xValue]) {
571
+ xValueToPoints[xValue] = [];
572
+ }
573
+ xValueToPoints[xValue].push(point);
574
+ });
575
+ const xAxisLabels = _getOrderedXAxisLabels({});
576
+ xAxisLabels.forEach((xValue)=>{
577
+ if (xValueToPoints[xValue]) {
578
+ result.push(...xValueToPoints[xValue]);
579
+ }
580
+ });
581
+ return result;
582
+ };
583
+ const _shouldOrderXAxisLabelsByCategoryOrder = ()=>{
584
+ return _xAxisType.current === XAxisTypes.StringAxis && props.xAxisCategoryOrder !== 'default';
585
+ };
586
+ const _shouldOrderYAxisLabelsByCategoryOrder = ()=>{
587
+ return _yAxisType.current === YAxisType.StringAxis && props.yAxisCategoryOrder !== 'default';
588
+ };
589
+ const _mapCategoryToValues = (isYAxis = false)=>{
590
+ const categoryToValues = {};
591
+ props.data.forEach((item)=>{
592
+ item.data.forEach((point)=>{
593
+ const category = isYAxis ? point.y : point.x;
594
+ if (!categoryToValues[category]) {
595
+ categoryToValues[category] = [];
596
+ }
597
+ categoryToValues[category].push(point.value);
598
+ });
599
+ });
600
+ return categoryToValues;
601
+ };
541
602
  const updatePosition = (newX, newY)=>{
542
603
  const threshold = 1; // Set a threshold for movement
543
604
  const { x, y } = clickPosition;