@fluentui/react-charts 9.3.6 → 9.3.8

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 (210) hide show
  1. package/CHANGELOG.md +46 -2
  2. package/dist/index.d.ts +70 -17
  3. package/lib/components/AnnotationOnlyChart/AnnotationOnlyChart.js +2 -16
  4. package/lib/components/AnnotationOnlyChart/AnnotationOnlyChart.js.map +1 -1
  5. package/lib/components/AnnotationOnlyChart/AnnotationOnlyChart.types.js.map +1 -1
  6. package/lib/components/AreaChart/AreaChart.js +3 -43
  7. package/lib/components/AreaChart/AreaChart.js.map +1 -1
  8. package/lib/components/AreaChart/useAreaChartStyles.styles.js +1 -2
  9. package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
  10. package/lib/components/ChartTable/ChartTable.js +8 -11
  11. package/lib/components/ChartTable/ChartTable.js.map +1 -1
  12. package/lib/components/ChartTable/ChartTable.types.js.map +1 -1
  13. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js +107 -67
  14. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -1
  15. package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js +7 -1
  16. package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js.map +1 -1
  17. package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js +7 -1
  18. package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js.map +1 -1
  19. package/lib/components/CommonComponents/CartesianChart.js +52 -32
  20. package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
  21. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  22. package/lib/components/CommonComponents/ChartPopover.js +1 -2
  23. package/lib/components/CommonComponents/ChartPopover.js.map +1 -1
  24. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +9 -7
  25. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  26. package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js +8 -5
  27. package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
  28. package/lib/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -1
  29. package/lib/components/CommonComponents/useChartPopoverStyles.styles.raw.js +0 -2
  30. package/lib/components/CommonComponents/useChartPopoverStyles.styles.raw.js.map +1 -1
  31. package/lib/components/DeclarativeChart/DeclarativeChart.js +48 -25
  32. package/lib/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  33. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +309 -209
  34. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  35. package/lib/components/DonutChart/DonutChart.js +9 -15
  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 +4 -2
  39. package/lib/components/DonutChart/Pie/Pie.js.map +1 -1
  40. package/lib/components/FunnelChart/FunnelChart.js +8 -13
  41. package/lib/components/FunnelChart/FunnelChart.js.map +1 -1
  42. package/lib/components/FunnelChart/FunnelChart.types.js.map +1 -1
  43. package/lib/components/GanttChart/GanttChart.js +4 -17
  44. package/lib/components/GanttChart/GanttChart.js.map +1 -1
  45. package/lib/components/GaugeChart/GaugeChart.js +8 -13
  46. package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
  47. package/lib/components/GaugeChart/GaugeChart.types.js.map +1 -1
  48. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +24 -36
  49. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  50. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +1 -2
  51. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  52. package/lib/components/HeatMapChart/HeatMapChart.js +3 -16
  53. package/lib/components/HeatMapChart/HeatMapChart.js.map +1 -1
  54. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +5 -25
  55. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  56. package/lib/components/Legends/Legends.js +3 -4
  57. package/lib/components/Legends/Legends.js.map +1 -1
  58. package/lib/components/Legends/Legends.types.js.map +1 -1
  59. package/lib/components/Legends/OverflowMenu.js.map +1 -1
  60. package/lib/components/Legends/useLegendsStyles.styles.raw.js.map +1 -1
  61. package/lib/components/LineChart/LineChart.js +68 -75
  62. package/lib/components/LineChart/LineChart.js.map +1 -1
  63. package/lib/components/LineChart/LineChart.types.js +1 -1
  64. package/lib/components/LineChart/LineChart.types.js.map +1 -1
  65. package/lib/components/LineChart/eventAnnotation/EventAnnotation.js +3 -4
  66. package/lib/components/LineChart/eventAnnotation/EventAnnotation.js.map +1 -1
  67. package/lib/components/LineChart/useLineChartStyles.styles.js +1 -2
  68. package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  69. package/lib/components/SankeyChart/SankeyChart.js +4 -10
  70. package/lib/components/SankeyChart/SankeyChart.js.map +1 -1
  71. package/lib/components/SankeyChart/SankeyChart.types.js.map +1 -1
  72. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +1 -2
  73. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
  74. package/lib/components/ScatterChart/ScatterChart.js +41 -49
  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 +1 -2
  78. package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  79. package/lib/components/Sparkline/Sparkline.js +11 -7
  80. package/lib/components/Sparkline/Sparkline.js.map +1 -1
  81. package/lib/components/VerticalBarChart/VerticalBarChart.js +15 -92
  82. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  83. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +1 -2
  84. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  85. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +28 -49
  86. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  87. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +1 -2
  88. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
  89. package/lib/types/ChartAnnotation.js.map +1 -1
  90. package/lib/types/DataPoint.js.map +1 -1
  91. package/lib/utilities/Common.styles.js +0 -1
  92. package/lib/utilities/Common.styles.js.map +1 -1
  93. package/lib/utilities/Common.styles.raw.js +0 -1
  94. package/lib/utilities/Common.styles.raw.js.map +1 -1
  95. package/lib/utilities/FocusableTooltipText.js +1 -1
  96. package/lib/utilities/FocusableTooltipText.js.map +1 -1
  97. package/lib/utilities/getWindow.js +0 -1
  98. package/lib/utilities/getWindow.js.map +1 -1
  99. package/lib/utilities/hooks.js +34 -0
  100. package/lib/utilities/hooks.js.map +1 -0
  101. package/lib/utilities/image-export-utils.js +118 -78
  102. package/lib/utilities/image-export-utils.js.map +1 -1
  103. package/lib/utilities/utilities.js +243 -102
  104. package/lib/utilities/utilities.js.map +1 -1
  105. package/lib-commonjs/components/AnnotationOnlyChart/AnnotationOnlyChart.js +2 -16
  106. package/lib-commonjs/components/AnnotationOnlyChart/AnnotationOnlyChart.js.map +1 -1
  107. package/lib-commonjs/components/AnnotationOnlyChart/AnnotationOnlyChart.types.js.map +1 -1
  108. package/lib-commonjs/components/AreaChart/AreaChart.js +2 -41
  109. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
  110. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +0 -2
  111. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
  112. package/lib-commonjs/components/ChartTable/ChartTable.js +9 -11
  113. package/lib-commonjs/components/ChartTable/ChartTable.js.map +1 -1
  114. package/lib-commonjs/components/ChartTable/ChartTable.types.js.map +1 -1
  115. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js +107 -67
  116. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -1
  117. package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js +7 -1
  118. package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js.map +1 -1
  119. package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js +7 -1
  120. package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js.map +1 -1
  121. package/lib-commonjs/components/CommonComponents/CartesianChart.js +51 -31
  122. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  123. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  124. package/lib-commonjs/components/CommonComponents/ChartPopover.js +1 -2
  125. package/lib-commonjs/components/CommonComponents/ChartPopover.js.map +1 -1
  126. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +7 -6
  127. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  128. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js +7 -4
  129. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
  130. package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.js.map +1 -1
  131. package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.raw.js +0 -2
  132. package/lib-commonjs/components/CommonComponents/useChartPopoverStyles.styles.raw.js.map +1 -1
  133. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js +48 -25
  134. package/lib-commonjs/components/DeclarativeChart/DeclarativeChart.js.map +1 -1
  135. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +309 -208
  136. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  137. package/lib-commonjs/components/DonutChart/DonutChart.js +7 -13
  138. package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
  139. package/lib-commonjs/components/DonutChart/DonutChart.types.js.map +1 -1
  140. package/lib-commonjs/components/DonutChart/Pie/Pie.js +4 -2
  141. package/lib-commonjs/components/DonutChart/Pie/Pie.js.map +1 -1
  142. package/lib-commonjs/components/FunnelChart/FunnelChart.js +7 -12
  143. package/lib-commonjs/components/FunnelChart/FunnelChart.js.map +1 -1
  144. package/lib-commonjs/components/FunnelChart/FunnelChart.types.js.map +1 -1
  145. package/lib-commonjs/components/GanttChart/GanttChart.js +3 -16
  146. package/lib-commonjs/components/GanttChart/GanttChart.js.map +1 -1
  147. package/lib-commonjs/components/GaugeChart/GaugeChart.js +7 -12
  148. package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
  149. package/lib-commonjs/components/GaugeChart/GaugeChart.types.js.map +1 -1
  150. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +22 -34
  151. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  152. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -2
  153. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  154. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js +2 -15
  155. package/lib-commonjs/components/HeatMapChart/HeatMapChart.js.map +1 -1
  156. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +4 -23
  157. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  158. package/lib-commonjs/components/Legends/Legends.js +3 -4
  159. package/lib-commonjs/components/Legends/Legends.js.map +1 -1
  160. package/lib-commonjs/components/Legends/Legends.types.js.map +1 -1
  161. package/lib-commonjs/components/Legends/OverflowMenu.js.map +1 -1
  162. package/lib-commonjs/components/Legends/useLegendsStyles.styles.raw.js.map +1 -1
  163. package/lib-commonjs/components/LineChart/LineChart.js +67 -74
  164. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  165. package/lib-commonjs/components/LineChart/LineChart.types.js +1 -1
  166. package/lib-commonjs/components/LineChart/LineChart.types.js.map +1 -1
  167. package/lib-commonjs/components/LineChart/eventAnnotation/EventAnnotation.js +2 -2
  168. package/lib-commonjs/components/LineChart/eventAnnotation/EventAnnotation.js.map +1 -1
  169. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +0 -2
  170. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  171. package/lib-commonjs/components/SankeyChart/SankeyChart.js +4 -10
  172. package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -1
  173. package/lib-commonjs/components/SankeyChart/SankeyChart.types.js.map +1 -1
  174. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +0 -2
  175. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
  176. package/lib-commonjs/components/ScatterChart/ScatterChart.js +38 -46
  177. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  178. package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -1
  179. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +0 -2
  180. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  181. package/lib-commonjs/components/Sparkline/Sparkline.js +11 -7
  182. package/lib-commonjs/components/Sparkline/Sparkline.js.map +1 -1
  183. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +14 -91
  184. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  185. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +0 -2
  186. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  187. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +26 -47
  188. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  189. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +0 -2
  190. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
  191. package/lib-commonjs/types/ChartAnnotation.js.map +1 -1
  192. package/lib-commonjs/types/DataPoint.js.map +1 -1
  193. package/lib-commonjs/utilities/Common.styles.js +0 -1
  194. package/lib-commonjs/utilities/Common.styles.js.map +1 -1
  195. package/lib-commonjs/utilities/Common.styles.raw.js +0 -1
  196. package/lib-commonjs/utilities/Common.styles.raw.js.map +1 -1
  197. package/lib-commonjs/utilities/FocusableTooltipText.js.map +1 -1
  198. package/lib-commonjs/utilities/getWindow.js +0 -1
  199. package/lib-commonjs/utilities/getWindow.js.map +1 -1
  200. package/lib-commonjs/utilities/hooks.js +45 -0
  201. package/lib-commonjs/utilities/hooks.js.map +1 -0
  202. package/lib-commonjs/utilities/image-export-utils.js +119 -79
  203. package/lib-commonjs/utilities/image-export-utils.js.map +1 -1
  204. package/lib-commonjs/utilities/utilities.js +253 -101
  205. package/lib-commonjs/utilities/utilities.js.map +1 -1
  206. package/package.json +9 -9
  207. package/lib/components/DeclarativeChart/imageExporter.js +0 -223
  208. package/lib/components/DeclarativeChart/imageExporter.js.map +0 -1
  209. package/lib-commonjs/components/DeclarativeChart/imageExporter.js +0 -233
  210. package/lib-commonjs/components/DeclarativeChart/imageExporter.js.map +0 -1
@@ -13,6 +13,8 @@ import { formatDateToLocaleString, formatToLocaleString, getMultiLevelDateTimeFo
13
13
  export const MIN_DOMAIN_MARGIN = 8;
14
14
  export const MIN_DONUT_RADIUS = 1;
15
15
  export const DEFAULT_DATE_STRING = '2000-01-01';
16
+ export const CARTESIAN_XAXIS_CLASSNAME = 'fui-cart__xAxis';
17
+ const CARTESIAN_XAXIS_TEXT_SELECTOR = `.${CARTESIAN_XAXIS_CLASSNAME} text`;
16
18
  export var ChartTypes = /*#__PURE__*/ function(ChartTypes) {
17
19
  ChartTypes[ChartTypes["AreaChart"] = 0] = "AreaChart";
18
20
  ChartTypes[ChartTypes["LineChart"] = 1] = "LineChart";
@@ -67,9 +69,13 @@ function yAxisTickFormatterInternal(value, limitWidth = false) {
67
69
  * @param {IXAxisParams} xAxisParams
68
70
  */ export function createNumericXAxis(xAxisParams, tickParams, chartType, culture, scaleType, _useRtl) {
69
71
  const { domainNRangeValues, showRoundOffXTickValues = false, xAxistickSize = 6, tickPadding = 10, xAxisCount, xAxisElement, hideTickOverlap, calcMaxLabelWidth, tickStep, tick0, tickText } = xAxisParams;
72
+ const dStartValue = domainNRangeValues.dStartValue;
73
+ const dEndValue = domainNRangeValues.dEndValue;
74
+ const finalXmin = xAxisParams.xMinValue !== undefined ? Math.min(dStartValue, xAxisParams.xMinValue) : dStartValue;
75
+ const finalXmax = xAxisParams.xMaxValue !== undefined ? Math.max(dEndValue, xAxisParams.xMaxValue) : dEndValue;
70
76
  const xAxisScale = createNumericScale(scaleType).domain([
71
- domainNRangeValues.dStartValue,
72
- domainNRangeValues.dEndValue
77
+ finalXmin,
78
+ finalXmax
73
79
  ]).range([
74
80
  domainNRangeValues.rStartValue,
75
81
  domainNRangeValues.rEndValue
@@ -86,7 +92,7 @@ function yAxisTickFormatterInternal(value, limitWidth = false) {
86
92
  const xAxisValue = typeof domainValue === 'number' ? domainValue : domainValue.valueOf();
87
93
  return (defaultFormat === null || defaultFormat === void 0 ? void 0 : defaultFormat(xAxisValue)) === '' ? '' : formatToLocaleString(xAxisValue, culture);
88
94
  };
89
- if (hideTickOverlap && typeof xAxisCount === 'undefined') {
95
+ if (hideTickOverlap) {
90
96
  const longestLabelWidth = calcMaxLabelWidth(xAxisScale.ticks().map((v, i)=>tickFormat(v, i))) + 20;
91
97
  const [start, end] = xAxisScale.range();
92
98
  tickCount = Math.min(Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth)), 10);
@@ -110,10 +116,12 @@ function yAxisTickFormatterInternal(value, limitWidth = false) {
110
116
  if (xAxisElement) {
111
117
  d3Select(xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true').style('direction', 'ltr').style('unicode-bidi', 'isolate');
112
118
  }
113
- const tickValues = (customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount)).map(xAxis.tickFormat());
119
+ const tickValues = customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount);
120
+ const tickLabels = tickValues.map(xAxis.tickFormat());
114
121
  return {
115
122
  xScale: xAxisScale,
116
- tickValues
123
+ tickValues,
124
+ tickLabels
117
125
  };
118
126
  }
119
127
  /**
@@ -306,7 +314,7 @@ export function getDateFormatLevel(date, useUTC) {
306
314
  * @param {IXAxisParams} xAxisParams
307
315
  * @param {ITickParams} tickParams
308
316
  */ export function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLocale, customDateTimeFormatter, useUTC, chartType) {
309
- const { domainNRangeValues, xAxisElement, tickPadding = 6, xAxistickSize = 6, xAxisCount, calcMaxLabelWidth, tickStep, tick0, tickText } = xAxisParams;
317
+ const { domainNRangeValues, xAxisElement, tickPadding = 6, xAxistickSize = 6, xAxisCount, hideTickOverlap, calcMaxLabelWidth, tickStep, tick0, tickText } = xAxisParams;
310
318
  const isUtcSet = useUTC === true || useUTC === 'utc';
311
319
  const xAxisScale = isUtcSet ? d3ScaleUtc() : d3ScaleTime();
312
320
  xAxisScale.domain([
@@ -350,10 +358,11 @@ export function getDateFormatLevel(date, useUTC) {
350
358
  }
351
359
  return formatDateToLocaleString(domainValue, culture, useUTC ? true : false, false, formatOptions);
352
360
  };
353
- const longestLabelWidth = calcMaxLabelWidth(xAxisScale.ticks().map(tickFormat)) + 40;
354
- const [start, end] = xAxisScale.range();
355
- const maxPossibleTickCount = Math.min(Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth)), 10);
356
- tickCount = Math.min(maxPossibleTickCount, xAxisCount !== null && xAxisCount !== void 0 ? xAxisCount : tickCount);
361
+ if (hideTickOverlap) {
362
+ const longestLabelWidth = calcMaxLabelWidth(xAxisScale.ticks().map(tickFormat)) + 40;
363
+ const [start, end] = xAxisScale.range();
364
+ tickCount = Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth));
365
+ }
357
366
  const xAxis = d3AxisBottom(xAxisScale).tickSize(xAxistickSize).tickPadding(tickPadding).ticks(tickCount).tickFormat(tickFormat);
358
367
  if ([
359
368
  8
@@ -372,10 +381,12 @@ export function getDateFormatLevel(date, useUTC) {
372
381
  if (xAxisElement) {
373
382
  d3Select(xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true');
374
383
  }
375
- const tickValues = (customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount)).map(xAxis.tickFormat());
384
+ const tickValues = customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount);
385
+ const tickLabels = tickValues.map(xAxis.tickFormat());
376
386
  return {
377
387
  xScale: xAxisScale,
378
- tickValues
388
+ tickValues,
389
+ tickLabels
379
390
  };
380
391
  }
381
392
  /**
@@ -432,7 +443,8 @@ export function getDateFormatLevel(date, useUTC) {
432
443
  }
433
444
  return {
434
445
  xScale: xAxisScale,
435
- tickValues: tickValues.map(xAxis.tickFormat())
446
+ tickValues,
447
+ tickLabels: tickValues.map(xAxis.tickFormat())
436
448
  };
437
449
  }
438
450
  export function useRtl() {
@@ -708,27 +720,24 @@ export function calloutData(values) {
708
720
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
709
721
  combinedResult.forEach((ele)=>{
710
722
  const xValue = ele.x instanceof Date ? ele.x.getTime() : ele.x;
723
+ const newPoint = {
724
+ legend: ele.legend,
725
+ y: ele.y,
726
+ color: ele.color,
727
+ xAxisCalloutData: ele.xAxisCalloutData,
728
+ yAxisCalloutData: ele.yAxisCalloutData,
729
+ callOutAccessibilityData: ele.callOutAccessibilityData,
730
+ index: ele.index
731
+ };
711
732
  if (xValue in xValToDataPoints) {
712
- xValToDataPoints[xValue].push({
713
- legend: ele.legend,
714
- y: ele.y,
715
- color: ele.color,
716
- xAxisCalloutData: ele.xAxisCalloutData,
717
- yAxisCalloutData: ele.yAxisCalloutData,
718
- callOutAccessibilityData: ele.callOutAccessibilityData,
719
- index: ele.index
720
- });
733
+ // Check if a point with the same legend and y-value already exists
734
+ const existingPoint = xValToDataPoints[xValue].find((p)=>p.legend === newPoint.legend && p.y === newPoint.y);
735
+ if (!existingPoint) {
736
+ xValToDataPoints[xValue].push(newPoint);
737
+ }
721
738
  } else {
722
739
  xValToDataPoints[xValue] = [
723
- {
724
- legend: ele.legend,
725
- y: ele.y,
726
- color: ele.color,
727
- xAxisCalloutData: ele.xAxisCalloutData,
728
- yAxisCalloutData: ele.yAxisCalloutData,
729
- callOutAccessibilityData: ele.callOutAccessibilityData,
730
- index: ele.index
731
- }
740
+ newPoint
732
741
  ];
733
742
  }
734
743
  });
@@ -773,14 +782,14 @@ export const DEFAULT_WRAP_WIDTH = 10;
773
782
  * @param {IWrapLabelProps} wrapLabelProps
774
783
  * @returns
775
784
  */ export function createWrapOfXLabels(wrapLabelProps) {
776
- const { node, xAxis, noOfCharsToTruncate, showXAxisLablesTooltip, width = DEFAULT_WRAP_WIDTH } = wrapLabelProps;
785
+ const { node, xAxis, noOfCharsToTruncate, showXAxisLablesTooltip, width = DEFAULT_WRAP_WIDTH, container } = wrapLabelProps;
777
786
  if (node === null) {
778
787
  return;
779
788
  }
780
789
  const axisNode = d3Select(node).call(xAxis);
781
790
  let removeVal = 0;
782
791
  let maxLines = 1;
783
- axisNode.selectAll('.tick text').each(function() {
792
+ axisNode.selectAll('.tick text').each(function(_, tickIndex) {
784
793
  const text = d3Select(this);
785
794
  const totalWord = text.text();
786
795
  const truncatedWord = `${text.text().slice(0, noOfCharsToTruncate)}...`;
@@ -792,33 +801,33 @@ export const DEFAULT_WRAP_WIDTH = 10;
792
801
  const lineHeight = 1.1; // ems
793
802
  const y = text.attr('y');
794
803
  const dy = parseFloat(text.attr('dy'));
795
- let tspan = text.text(null).append('tspan').attr('x', 0).attr('y', y).attr('id', 'BaseSpan').attr('dy', dy + 'em').attr('data-', totalWord);
796
- if (showXAxisLablesTooltip && totalWordLength > noOfCharsToTruncate) {
797
- tspan = text.append('tspan').attr('id', 'showDots').attr('x', 0).attr('y', y).attr('dy', dy + 'em').text(truncatedWord);
798
- } else if (showXAxisLablesTooltip && totalWordLength <= noOfCharsToTruncate) {
799
- tspan = text.append('tspan').attr('id', 'LessLength').attr('x', 0).attr('y', y).attr('dy', dy + 'em').text(totalWord);
804
+ let tspan = text.text(null).attr('data-full', totalWord).append('tspan').attr('x', 0).attr('y', y).attr('dy', dy + 'em');
805
+ if (showXAxisLablesTooltip) {
806
+ tspan.text(totalWordLength > noOfCharsToTruncate ? truncatedWord : totalWord);
800
807
  } else {
808
+ const maxWidth = Array.isArray(width) ? width[tickIndex] : width;
801
809
  while(word = words.pop()){
802
810
  line.push(word);
803
- tspan.text(line.join(' '));
804
- if (tspan.node().getComputedTextLength() > width && line.length > 1) {
811
+ const label = line.join(' ');
812
+ tspan.text(label);
813
+ const labelWidth = getTextSize(label, CARTESIAN_XAXIS_TEXT_SELECTOR, container).width;
814
+ if (labelWidth > maxWidth && line.length > 1) {
805
815
  line.pop();
806
816
  tspan.text(line.join(' '));
807
817
  line = [
808
818
  word
809
819
  ];
810
- tspan = text.append('tspan').attr('id', 'WordBreakId').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(word);
820
+ tspan = text.append('tspan').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(word);
811
821
  }
812
822
  }
813
823
  }
814
824
  maxLines = Math.max(maxLines, lineNumber + 1);
815
825
  });
816
826
  if (!showXAxisLablesTooltip) {
827
+ var _querySelector;
817
828
  let maxHeight = 12; // intial value to render corretly first time
818
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
819
- const outerHTMLElement = document.getElementById('WordBreakId');
820
- const BoxCordinates = outerHTMLElement && outerHTMLElement.getBoundingClientRect();
821
- const boxHeight = BoxCordinates && BoxCordinates.height;
829
+ var _querySelector_getBoundingClientRect_height;
830
+ const boxHeight = (_querySelector_getBoundingClientRect_height = (_querySelector = (container !== null && container !== void 0 ? container : document).querySelector(`.${CARTESIAN_XAXIS_CLASSNAME} tspan`)) === null || _querySelector === void 0 ? void 0 : _querySelector.getBoundingClientRect().height) !== null && _querySelector_getBoundingClientRect_height !== void 0 ? _querySelector_getBoundingClientRect_height : 0;
822
831
  if (boxHeight > maxHeight) {
823
832
  maxHeight = boxHeight;
824
833
  }
@@ -834,24 +843,18 @@ yAxis, noOfCharsToTruncate, truncateLabel, isRtl) {
834
843
  if (node === null) {
835
844
  return;
836
845
  }
837
- let tickIndex = 0;
838
846
  const axisNode = d3Select(node).call(yAxis);
839
847
  axisNode.selectAll('.tick text').each(function() {
840
848
  const text = d3Select(this);
841
849
  const totalWord = text.text();
842
850
  const truncatedWord = isRtl ? `...${text.text().slice(0, noOfCharsToTruncate)}` : `${text.text().slice(0, noOfCharsToTruncate)}...`;
843
851
  const totalWordLength = text.text().length;
844
- const padding = 0; // ems
845
852
  const y = text.attr('y');
846
853
  const x = text.attr('x');
847
854
  const dy = parseFloat(text.attr('dy'));
848
- const dx = 0;
849
- const uid = tickIndex++;
850
- text.text(null).append('tspan').attr('x', x).attr('y', y).attr('id', `BaseSpan-${uid}`).attr('dy', dy + 'em').attr('data-', totalWord);
851
- if (truncateLabel && totalWordLength > noOfCharsToTruncate) {
852
- text.append('tspan').attr('id', `showDots-${uid}`).attr('x', x).attr('y', y).attr('dy', dy + 'em').attr('dx', padding + dx + 'em').text(truncatedWord);
853
- } else {
854
- text.append('tspan').attr('id', `LessLength-${uid}`).attr('x', x).attr('y', y).attr('dx', padding + dx + 'em').text(totalWord);
855
+ const tspan = text.text(null).attr('data-full', totalWord).append('tspan').attr('x', x).attr('y', y).attr('dy', dy + 'em');
856
+ if (truncateLabel) {
857
+ tspan.text(totalWordLength > noOfCharsToTruncate ? truncatedWord : totalWord);
855
858
  }
856
859
  });
857
860
  }
@@ -900,30 +903,30 @@ export const wrapContent = (content, id, maxWidth)=>{
900
903
  * On hover of the truncated word(at x axis labels tick), a tooltip will be appeared.
901
904
  */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
902
905
  export function tooltipOfAxislabels(axistooltipProps) {
903
- const { tooltipCls, axis, id } = axistooltipProps;
906
+ const { tooltipCls, axis, id, container } = axistooltipProps;
904
907
  if (axis === null) {
905
908
  return null;
906
909
  }
907
- const div = d3Select('body').append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
908
- const aa = axis.selectAll('[id^="BaseSpan-"]')._groups[0];
909
- const baseSpanLength = aa && Object.keys(aa).length;
910
- const originalDataArray = [];
911
- for(let i = 0; i < baseSpanLength; i++){
912
- const originalData = aa[i].dataset && Object.values(aa[i].dataset)[0];
913
- originalDataArray.push(originalData);
914
- }
915
- const tickObject = axis.selectAll('.tick')._groups[0];
916
- const tickObjectLength = tickObject && Object.keys(tickObject).length;
917
- for(let i = 0; i < tickObjectLength; i++){
918
- const d1 = tickObject[i];
919
- d3Select(d1)// eslint-disable-next-line @typescript-eslint/no-explicit-any
910
+ const div = (container ? d3Select(container) : d3Select('body')).append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
911
+ axis.selectAll('.tick text').each(function() {
912
+ const tickSelection = d3Select(this);
913
+ const fullLabel = tickSelection.attr('data-full');
914
+ if (tickSelection.text() === fullLabel) {
915
+ return;
916
+ }
917
+ const tickEl = this;
918
+ tickSelection// eslint-disable-next-line @typescript-eslint/no-explicit-any
920
919
  .on('mouseover', (event, d)=>{
921
- div.style('opacity', 0.9);
922
- div.html(originalDataArray[i]).style('left', event.pageX + 'px').style('top', event.pageY - 28 + 'px');
920
+ const containerBounds = container === null || container === void 0 ? void 0 : container.getBoundingClientRect();
921
+ const tickBounds = tickEl.getBoundingClientRect();
922
+ const tooltipBottom = containerBounds ? containerBounds.bottom - (tickBounds.top - 4) : tickBounds.top - 4;
923
+ var _containerBounds_left;
924
+ const tooltipLeft = (tickBounds.left + tickBounds.right) / 2 - ((_containerBounds_left = containerBounds === null || containerBounds === void 0 ? void 0 : containerBounds.left) !== null && _containerBounds_left !== void 0 ? _containerBounds_left : 0);
925
+ div.text(fullLabel).style('bottom', `${tooltipBottom}px`).style('left', `${tooltipLeft}px`).style('transform', 'translateX(-50%)').style('opacity', 0.9);
923
926
  }).on('mouseout', (d)=>{
924
927
  div.style('opacity', 0);
925
928
  });
926
- }
929
+ });
927
930
  }
928
931
  /**
929
932
  * Find the axis type of line chart and area chart from given data
@@ -949,11 +952,11 @@ export function tooltipOfAxislabels(axistooltipProps) {
949
952
  * @param {number} width
950
953
  * @param {boolean} isRTL
951
954
  * @returns {IDomainNRange}
952
- */ export function domainRangeOfNumericForAreaLineScatterCharts(points, margins, width, isRTL, scaleType, hasMarkersMode) {
955
+ */ export function domainRangeOfNumericForAreaLineScatterCharts(points, margins, width, isRTL, scaleType, hasMarkersMode, xMinVal, xMaxVal) {
953
956
  const isScatterPolar = isScatterPolarSeries(points);
954
957
  let [xMin, xMax] = getScatterXDomainExtent(points, scaleType);
955
958
  if (hasMarkersMode) {
956
- const xPadding = getDomainPaddingForMarkers(xMin, xMax, scaleType);
959
+ const xPadding = getDomainPaddingForMarkers(xMin, xMax, scaleType, xMinVal, xMaxVal);
957
960
  xMin = xMin - xPadding.start;
958
961
  xMax = xMax + xPadding.end;
959
962
  }
@@ -1444,10 +1447,8 @@ export const isScalePaddingDefined = (prop, shorthandProp)=>{
1444
1447
  return array[index];
1445
1448
  }
1446
1449
  export const HighContrastSelector = '@media screen and (-ms-high-contrast: active), screen and (forced-colors: active)';
1447
- export const HighContrastSelectorWhite = // eslint-disable-next-line @fluentui/max-len
1448
- '@media screen and (-ms-high-contrast: black-on-white), screen and (forced-colors: active) and (prefers-color-scheme: light)';
1449
- export const HighContrastSelectorBlack = // eslint-disable-next-line @fluentui/max-len
1450
- '@media screen and (-ms-high-contrast: white-on-black), screen and (forced-colors: active) and (prefers-color-scheme: dark)';
1450
+ export const HighContrastSelectorWhite = '@media screen and (-ms-high-contrast: black-on-white), screen and (forced-colors: active) and (prefers-color-scheme: light)';
1451
+ export const HighContrastSelectorBlack = '@media screen and (-ms-high-contrast: white-on-black), screen and (forced-colors: active) and (prefers-color-scheme: dark)';
1451
1452
  export const formatDate = (date, useUTC)=>{
1452
1453
  const timeFormat = useUTC ? d3UtcFormat : d3TimeFormat;
1453
1454
  return timeFormat('%-e %b %Y, %H:%M')(date) + (useUTC ? ' GMT' : '');
@@ -1467,8 +1468,8 @@ export function areArraysEqual(arr1, arr2) {
1467
1468
  return true;
1468
1469
  }
1469
1470
  const cssVarRegExp = /var\((--[a-zA-Z0-9\-]+)\)/g;
1470
- export function resolveCSSVariables(chartContainer, styleRules) {
1471
- const containerStyles = getComputedStyle(chartContainer);
1471
+ export function resolveCSSVariables(container, styleRules) {
1472
+ const containerStyles = getComputedStyle(container);
1472
1473
  return styleRules.replace(cssVarRegExp, (match, group1)=>{
1473
1474
  return containerStyles.getPropertyValue(group1);
1474
1475
  });
@@ -1571,11 +1572,6 @@ export function copyStyle(properties, fromEl, toEl) {
1571
1572
  });
1572
1573
  }
1573
1574
  }
1574
- let measurementSpanCounter = 0;
1575
- function getUniqueMeasurementSpanId() {
1576
- measurementSpanCounter++;
1577
- return `measurement_span_${measurementSpanCounter}`;
1578
- }
1579
1575
  const MEASUREMENT_SPAN_STYLE = {
1580
1576
  position: 'absolute',
1581
1577
  visibility: 'hidden',
@@ -1586,23 +1582,60 @@ const MEASUREMENT_SPAN_STYLE = {
1586
1582
  border: 'none',
1587
1583
  whiteSpace: 'pre'
1588
1584
  };
1589
- export const createMeasurementSpan = (text, className, parentElement)=>{
1590
- const MEASUREMENT_SPAN_ID = getUniqueMeasurementSpanId();
1585
+ const MEASUREMENT_SPAN_ID = 'fui_measurement_span';
1586
+ const TEXT_STYLE_PROPERTIES = [
1587
+ 'font-size',
1588
+ 'font-family',
1589
+ 'font-weight',
1590
+ 'font-style',
1591
+ 'letter-spacing',
1592
+ 'text-transform'
1593
+ ];
1594
+ export const measureTextWithDOM = (text, cssSelector, container)=>{
1591
1595
  let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
1592
1596
  if (!measurementSpan) {
1593
1597
  measurementSpan = document.createElement('span');
1594
1598
  measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
1595
1599
  measurementSpan.setAttribute('aria-hidden', 'true');
1596
- if (parentElement) {
1597
- parentElement.appendChild(measurementSpan);
1598
- } else {
1599
- document.body.appendChild(measurementSpan);
1600
- }
1600
+ (container !== null && container !== void 0 ? container : document.body).appendChild(measurementSpan);
1601
1601
  }
1602
- measurementSpan.setAttribute('class', className);
1603
1602
  Object.assign(measurementSpan.style, MEASUREMENT_SPAN_STYLE);
1603
+ const refEl = (container !== null && container !== void 0 ? container : document).querySelector(cssSelector);
1604
+ if (refEl) {
1605
+ copyStyle(TEXT_STYLE_PROPERTIES, refEl, measurementSpan);
1606
+ }
1604
1607
  measurementSpan.textContent = `${text}`;
1605
- return measurementSpan;
1608
+ const rect = measurementSpan.getBoundingClientRect();
1609
+ return {
1610
+ node: measurementSpan,
1611
+ width: rect.width,
1612
+ height: rect.height
1613
+ };
1614
+ };
1615
+ const CACHE_SIZE = 2000;
1616
+ const textSizeCache = new Map();
1617
+ export const getTextSize = (text, cssSelector, container)=>{
1618
+ const cacheKey = `${text}|${cssSelector}`;
1619
+ const cachedResult = textSizeCache.get(cacheKey);
1620
+ if (cachedResult) {
1621
+ return cachedResult;
1622
+ }
1623
+ const { width, height } = measureTextWithDOM(text, cssSelector, container);
1624
+ // TODO: Improve cache eviction strategy if needed (e.g., LRU)
1625
+ if (textSizeCache.size >= CACHE_SIZE) {
1626
+ const firstKey = textSizeCache.keys().next().value;
1627
+ if (!isInvalidValue(firstKey)) {
1628
+ textSizeCache.delete(firstKey);
1629
+ }
1630
+ }
1631
+ textSizeCache.set(cacheKey, {
1632
+ width,
1633
+ height
1634
+ });
1635
+ return {
1636
+ width,
1637
+ height
1638
+ };
1606
1639
  };
1607
1640
  /**
1608
1641
  * Utility function to check if an array of points is scatterpolar
@@ -1634,17 +1667,26 @@ const createNumericScale = (scaleType)=>{
1634
1667
  return d3ScaleLinear();
1635
1668
  }
1636
1669
  };
1637
- export const getDomainPaddingForMarkers = (minVal, maxVal, scaleType)=>{
1670
+ export const getDomainPaddingForMarkers = (minVal, maxVal, scaleType, userMinVal, userMaxVal)=>{
1638
1671
  if (scaleType === 'log') {
1639
1672
  return {
1640
1673
  start: minVal * 0.5,
1641
1674
  end: maxVal
1642
1675
  };
1643
1676
  }
1644
- const defaultPadding = (maxVal - minVal) * 0.1;
1677
+ /* if user explicitly sets userMinVal or userMaxVal, we will check that to avoid excessive padding on either side.
1678
+ If the difference between minVal and userMinVal is more than 10% of the data range, we set padding to 0 on that side.
1679
+ this is to avoid cases where userMinVal is significantly smaller than minVal or userMaxVal is significantly larger than
1680
+ maxVal, which would lead to excessive padding. In other cases, we apply the default 10% padding on both sides.
1681
+ */ const rangePadding = (maxVal - minVal) * 0.1;
1682
+ // If explicit bounds are set and they're far from the data range, don't add extra padding
1683
+ const paddingAlreadySatisfiedAtMin = userMinVal !== undefined && rangePadding > Math.abs(minVal - Math.min(minVal, userMinVal));
1684
+ const paddingAlreadySatisfiedAtMax = userMaxVal !== undefined && rangePadding > Math.abs(maxVal - Math.max(maxVal, userMaxVal));
1685
+ const startPadding = paddingAlreadySatisfiedAtMin ? 0 : rangePadding;
1686
+ const endPadding = paddingAlreadySatisfiedAtMax ? 0 : rangePadding;
1645
1687
  return {
1646
- start: defaultPadding,
1647
- end: defaultPadding
1688
+ start: startPadding,
1689
+ end: endPadding
1648
1690
  };
1649
1691
  };
1650
1692
  /**
@@ -1673,7 +1715,7 @@ export const getScatterXDomainExtent = (points, scaleType)=>{
1673
1715
  xMax
1674
1716
  ];
1675
1717
  };
1676
- export const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, yScaleSecondary, useSecondaryYScale, xScaleType, yScaleType: primaryYScaleType, secondaryYScaleType })=>{
1718
+ export const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, yScaleSecondary, useSecondaryYScale, xScaleType, yScaleType: primaryYScaleType, secondaryYScaleType, xMinValue, xMaxValue, yMinValue, yMaxValue })=>{
1677
1719
  // Note: This function is executed after the scale is created, so the actual padding can be
1678
1720
  // obtained by calculating the difference between the respective minimums or maximums of the
1679
1721
  // scale domain and the data. However, doing so often causes the marker size to scale up
@@ -1684,13 +1726,13 @@ export const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, ySca
1684
1726
  // it the other way around (i.e., adjusting the scale domain first with padding and then scaling
1685
1727
  // the markers to fit inside the plot area).
1686
1728
  const [xMin, xMax] = getScatterXDomainExtent(data, xScaleType);
1687
- const xPadding = getDomainPaddingForMarkers(+xMin, +xMax, xScaleType);
1729
+ const xPadding = getDomainPaddingForMarkers(+xMin, +xMax, xScaleType, xMinValue, xMaxValue);
1688
1730
  const scaleXMin = xMin instanceof Date ? new Date(+xMin - xPadding.start) : xMin - xPadding.start;
1689
1731
  const scaleXMax = xMax instanceof Date ? new Date(+xMax + xPadding.end) : xMax + xPadding.end;
1690
1732
  const extraXPixels = Math.min(Math.abs(xScale(xMin) - xScale(scaleXMin)), Math.abs(xScale(scaleXMax) - xScale(xMax)));
1691
1733
  const yScaleType = useSecondaryYScale ? secondaryYScaleType : primaryYScaleType;
1692
1734
  const { startValue: yMin, endValue: yMax } = findNumericMinMaxOfY(data, undefined, useSecondaryYScale, yScaleType);
1693
- const yPadding = getDomainPaddingForMarkers(yMin, yMax, yScaleType);
1735
+ const yPadding = getDomainPaddingForMarkers(yMin, yMax, yScaleType, yMinValue, yMaxValue);
1694
1736
  const scaleYMin = yMin - yPadding.start;
1695
1737
  const scaleYMax = yMax + yPadding.end;
1696
1738
  const yScale = useSecondaryYScale ? yScaleSecondary : yScalePrimary;
@@ -1742,7 +1784,7 @@ const generateNumericTicks = (scaleType, tickStep, tick0, scaleDomain)=>{
1742
1784
  const refTick = typeof tick0 === 'number' ? tick0 : 0;
1743
1785
  if (scaleType === 'log') {
1744
1786
  if (typeof tickStep === 'number' && tickStep > 0) {
1745
- return generateLinearTicks(refTick, tickStep, scaleDomain.map((d)=>Math.log10(d))).map((t)=>Math.pow(10, t));
1787
+ return generateLinearTicks(refTick, tickStep, scaleDomain.map((d)=>Math.log10(d))).map((t)=>10 ** t);
1746
1788
  }
1747
1789
  if (typeof tickStep === 'string') {
1748
1790
  const prefix = tickStep[0];
@@ -1799,7 +1841,7 @@ const generateDateTicks = (tickStep, tick0, scaleDomain, useUTC)=>{
1799
1841
  * @param value - The value that is being rounded.
1800
1842
  * @param precision - The number of decimal places to round the number to
1801
1843
  */ export function precisionRound(value, precision, base = 10) {
1802
- const exp = Math.pow(base, precision);
1844
+ const exp = base ** precision;
1803
1845
  return Math.round(value * exp) / exp;
1804
1846
  }
1805
1847
  export const findCalloutPoints = (calloutPointsByX, x)=>{
@@ -1815,3 +1857,102 @@ export const findCalloutPoints = (calloutPointsByX, x)=>{
1815
1857
  values: calloutPointsByX[key]
1816
1858
  };
1817
1859
  };
1860
+ export const autoLayoutXAxisLabels = (tickValues, tickLabels, scale, axisNode, containerWidth, container)=>{
1861
+ let requiresWrap = false;
1862
+ let requiresTruncate = false;
1863
+ const maxWidths = [];
1864
+ const [rangeStart, rangeEnd] = scale.range();
1865
+ const isRTL = rangeEnd - rangeStart < 0;
1866
+ const start = isRTL ? containerWidth : 0;
1867
+ const end = isRTL ? 0 : containerWidth;
1868
+ const getTickPosition = (index)=>{
1869
+ var _scale;
1870
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1871
+ return ((_scale = scale(tickValues[index])) !== null && _scale !== void 0 ? _scale : 0) + ('bandwidth' in scale ? scale.bandwidth() / 2 : 0);
1872
+ };
1873
+ const getLabelWidth = (text)=>{
1874
+ return getTextSize(text, CARTESIAN_XAXIS_TEXT_SELECTOR, container).width;
1875
+ };
1876
+ for(let i = 0; i < tickValues.length; i++){
1877
+ const position = getTickPosition(i);
1878
+ const leftSpace = Math.abs(i > 0 ? (position - getTickPosition(i - 1)) / 2 : position - start);
1879
+ const rightSpace = Math.abs(i + 1 < tickValues.length ? (getTickPosition(i + 1) - position) / 2 : end - position);
1880
+ const maxAvailableWidth = Math.min(leftSpace, rightSpace) * 2 - 8; // 4px padding on both sides
1881
+ const label = tickLabels[i];
1882
+ const labelWidth = getLabelWidth(label);
1883
+ maxWidths.push(maxAvailableWidth);
1884
+ if (labelWidth > maxAvailableWidth) {
1885
+ const longestWordWidth = Math.max(...label.split(/\s+/).map((word)=>getLabelWidth(word)));
1886
+ if (longestWordWidth <= maxAvailableWidth) {
1887
+ requiresWrap = true;
1888
+ } else {
1889
+ requiresTruncate = true;
1890
+ }
1891
+ }
1892
+ }
1893
+ if (requiresTruncate) {
1894
+ return truncateAndStaggerXAxisLabels(tickValues, tickLabels, scale, axisNode, containerWidth, container);
1895
+ }
1896
+ if (requiresWrap) {
1897
+ var _createWrapOfXLabels;
1898
+ return (_createWrapOfXLabels = createWrapOfXLabels({
1899
+ node: axisNode,
1900
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1901
+ xAxis: scale,
1902
+ noOfCharsToTruncate: 100,
1903
+ showXAxisLablesTooltip: false,
1904
+ width: maxWidths,
1905
+ container
1906
+ })) !== null && _createWrapOfXLabels !== void 0 ? _createWrapOfXLabels : 0;
1907
+ }
1908
+ return 0;
1909
+ };
1910
+ const truncateAndStaggerXAxisLabels = (tickValues, tickLabels, scale, axisNode, containerWidth, container)=>{
1911
+ if (!axisNode) {
1912
+ return 0;
1913
+ }
1914
+ let maxHeight = 12;
1915
+ const [rangeStart, rangeEnd] = scale.range();
1916
+ const isRTL = rangeEnd - rangeStart < 0;
1917
+ const start = isRTL ? containerWidth : 0;
1918
+ const end = isRTL ? 0 : containerWidth;
1919
+ const getTickPosition = (index)=>{
1920
+ var _scale;
1921
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1922
+ return ((_scale = scale(tickValues[index])) !== null && _scale !== void 0 ? _scale : 0) + ('bandwidth' in scale ? scale.bandwidth() / 2 : 0);
1923
+ };
1924
+ const getLabelSize = (text)=>{
1925
+ return getTextSize(text, CARTESIAN_XAXIS_TEXT_SELECTOR, container);
1926
+ };
1927
+ d3Select(axisNode).selectAll('.tick text').each(function(_, i) {
1928
+ const position = getTickPosition(i);
1929
+ const leftSpace = Math.abs(i > 0 ? position - getTickPosition(i - 1) : position - start);
1930
+ const rightSpace = Math.abs(i + 1 < tickValues.length ? getTickPosition(i + 1) - position : end - position);
1931
+ const maxAvailableWidth = Math.min(leftSpace, rightSpace) * 2 - 8; // 4px padding on both sides
1932
+ const label = tickLabels[i];
1933
+ const textNode = d3Select(this).text(null).attr('data-full', label);
1934
+ const lineHeight = 1.1; // ems
1935
+ const y = textNode.attr('y');
1936
+ const dy = parseFloat(textNode.attr('dy'));
1937
+ textNode.append('tspan').attr('x', 0).attr('y', y).attr('dy', (i % 2 === 1 ? lineHeight : 0) + dy + 'em').text(truncateTextToFitWidth(label, maxAvailableWidth, (s)=>getLabelSize(s).width));
1938
+ maxHeight = Math.max(maxHeight, getLabelSize(label).height);
1939
+ });
1940
+ return tickValues.length > 1 ? maxHeight : 0;
1941
+ };
1942
+ const truncateTextToFitWidth = (text, maxWidth, measure)=>{
1943
+ if (measure(text) <= maxWidth) {
1944
+ return text;
1945
+ }
1946
+ let lo = 1;
1947
+ let hi = text.length;
1948
+ while(lo < hi){
1949
+ const mid = Math.floor((lo + hi + 1) / 2);
1950
+ const candidate = text.slice(0, mid) + '...';
1951
+ if (measure(candidate) <= maxWidth) {
1952
+ lo = mid;
1953
+ } else {
1954
+ hi = mid - 1;
1955
+ }
1956
+ }
1957
+ return text.slice(0, lo) + '...';
1958
+ };