@fluentui/react-charts 9.3.7 → 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 (143) hide show
  1. package/CHANGELOG.md +27 -2
  2. package/dist/index.d.ts +55 -7
  3. package/lib/components/AreaChart/AreaChart.js +1 -28
  4. package/lib/components/AreaChart/AreaChart.js.map +1 -1
  5. package/lib/components/AreaChart/useAreaChartStyles.styles.js +1 -2
  6. package/lib/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
  7. package/lib/components/ChartTable/ChartTable.js +6 -1
  8. package/lib/components/ChartTable/ChartTable.js.map +1 -1
  9. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js +107 -67
  10. package/lib/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -1
  11. package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js +7 -1
  12. package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js.map +1 -1
  13. package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js +7 -1
  14. package/lib/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js.map +1 -1
  15. package/lib/components/CommonComponents/CartesianChart.js +50 -32
  16. package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
  17. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  18. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +5 -5
  19. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  20. package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js +4 -3
  21. package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
  22. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +261 -187
  23. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  24. package/lib/components/DonutChart/DonutChart.js +6 -3
  25. package/lib/components/DonutChart/DonutChart.js.map +1 -1
  26. package/lib/components/FunnelChart/FunnelChart.js +6 -3
  27. package/lib/components/FunnelChart/FunnelChart.js.map +1 -1
  28. package/lib/components/GanttChart/GanttChart.js +1 -1
  29. package/lib/components/GanttChart/GanttChart.js.map +1 -1
  30. package/lib/components/GaugeChart/GaugeChart.js +6 -3
  31. package/lib/components/GaugeChart/GaugeChart.js.map +1 -1
  32. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +17 -17
  33. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  34. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +1 -2
  35. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  36. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +2 -4
  37. package/lib/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  38. package/lib/components/Legends/Legends.js +3 -4
  39. package/lib/components/Legends/Legends.js.map +1 -1
  40. package/lib/components/LineChart/LineChart.js +66 -64
  41. package/lib/components/LineChart/LineChart.js.map +1 -1
  42. package/lib/components/LineChart/useLineChartStyles.styles.js +1 -2
  43. package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  44. package/lib/components/SankeyChart/SankeyChart.js +1 -1
  45. package/lib/components/SankeyChart/SankeyChart.js.map +1 -1
  46. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +1 -2
  47. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
  48. package/lib/components/ScatterChart/ScatterChart.js +18 -26
  49. package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
  50. package/lib/components/ScatterChart/ScatterChart.types.js.map +1 -1
  51. package/lib/components/ScatterChart/useScatterChartStyles.styles.js +1 -2
  52. package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  53. package/lib/components/VerticalBarChart/VerticalBarChart.js +13 -78
  54. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  55. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +1 -2
  56. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  57. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +21 -32
  58. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  59. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +1 -2
  60. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
  61. package/lib/types/ChartAnnotation.js.map +1 -1
  62. package/lib/types/DataPoint.js.map +1 -1
  63. package/lib/utilities/Common.styles.js +0 -1
  64. package/lib/utilities/Common.styles.js.map +1 -1
  65. package/lib/utilities/Common.styles.raw.js +0 -1
  66. package/lib/utilities/Common.styles.raw.js.map +1 -1
  67. package/lib/utilities/image-export-utils.js +4 -4
  68. package/lib/utilities/image-export-utils.js.map +1 -1
  69. package/lib/utilities/utilities.js +220 -78
  70. package/lib/utilities/utilities.js.map +1 -1
  71. package/lib-commonjs/components/AreaChart/AreaChart.js +0 -26
  72. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
  73. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +0 -2
  74. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
  75. package/lib-commonjs/components/ChartTable/ChartTable.js +6 -1
  76. package/lib-commonjs/components/ChartTable/ChartTable.js.map +1 -1
  77. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js +107 -67
  78. package/lib-commonjs/components/CommonComponents/Annotations/ChartAnnotationLayer.js.map +1 -1
  79. package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js +7 -1
  80. package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.js.map +1 -1
  81. package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js +7 -1
  82. package/lib-commonjs/components/CommonComponents/Annotations/useChartAnnotationLayer.styles.raw.js.map +1 -1
  83. package/lib-commonjs/components/CommonComponents/CartesianChart.js +49 -31
  84. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  85. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  86. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +3 -4
  87. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  88. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js +3 -2
  89. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
  90. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +261 -186
  91. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  92. package/lib-commonjs/components/DonutChart/DonutChart.js +5 -2
  93. package/lib-commonjs/components/DonutChart/DonutChart.js.map +1 -1
  94. package/lib-commonjs/components/FunnelChart/FunnelChart.js +5 -2
  95. package/lib-commonjs/components/FunnelChart/FunnelChart.js.map +1 -1
  96. package/lib-commonjs/components/GanttChart/GanttChart.js +1 -1
  97. package/lib-commonjs/components/GanttChart/GanttChart.js.map +1 -1
  98. package/lib-commonjs/components/GaugeChart/GaugeChart.js +5 -2
  99. package/lib-commonjs/components/GaugeChart/GaugeChart.js.map +1 -1
  100. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +15 -15
  101. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  102. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -2
  103. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  104. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js +2 -4
  105. package/lib-commonjs/components/HorizontalBarChartWithAxis/HorizontalBarChartWithAxis.js.map +1 -1
  106. package/lib-commonjs/components/Legends/Legends.js +3 -4
  107. package/lib-commonjs/components/Legends/Legends.js.map +1 -1
  108. package/lib-commonjs/components/LineChart/LineChart.js +65 -63
  109. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  110. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +0 -2
  111. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  112. package/lib-commonjs/components/SankeyChart/SankeyChart.js +1 -1
  113. package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -1
  114. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +0 -2
  115. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
  116. package/lib-commonjs/components/ScatterChart/ScatterChart.js +17 -25
  117. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  118. package/lib-commonjs/components/ScatterChart/ScatterChart.types.js.map +1 -1
  119. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +0 -2
  120. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  121. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +12 -77
  122. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  123. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +0 -2
  124. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  125. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +20 -31
  126. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  127. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +0 -2
  128. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
  129. package/lib-commonjs/types/ChartAnnotation.js.map +1 -1
  130. package/lib-commonjs/types/DataPoint.js.map +1 -1
  131. package/lib-commonjs/utilities/Common.styles.js +0 -1
  132. package/lib-commonjs/utilities/Common.styles.js.map +1 -1
  133. package/lib-commonjs/utilities/Common.styles.raw.js +0 -1
  134. package/lib-commonjs/utilities/Common.styles.raw.js.map +1 -1
  135. package/lib-commonjs/utilities/image-export-utils.js +3 -3
  136. package/lib-commonjs/utilities/image-export-utils.js.map +1 -1
  137. package/lib-commonjs/utilities/utilities.js +232 -81
  138. package/lib-commonjs/utilities/utilities.js.map +1 -1
  139. package/package.json +9 -9
  140. package/lib/components/DeclarativeChart/imageExporter.js +0 -223
  141. package/lib/components/DeclarativeChart/imageExporter.js.map +0 -1
  142. package/lib-commonjs/components/DeclarativeChart/imageExporter.js +0 -233
  143. package/lib-commonjs/components/DeclarativeChart/imageExporter.js.map +0 -1
@@ -10,6 +10,9 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
+ CARTESIAN_XAXIS_CLASSNAME: function() {
14
+ return CARTESIAN_XAXIS_CLASSNAME;
15
+ },
13
16
  ChartTypes: function() {
14
17
  return ChartTypes;
15
18
  },
@@ -49,6 +52,9 @@ _export(exports, {
49
52
  areArraysEqual: function() {
50
53
  return areArraysEqual;
51
54
  },
55
+ autoLayoutXAxisLabels: function() {
56
+ return autoLayoutXAxisLabels;
57
+ },
52
58
  calculateLongestLabelWidth: function() {
53
59
  return calculateLongestLabelWidth;
54
60
  },
@@ -67,9 +73,6 @@ _export(exports, {
67
73
  createDateXAxis: function() {
68
74
  return createDateXAxis;
69
75
  },
70
- createMeasurementSpan: function() {
71
- return createMeasurementSpan;
72
- },
73
76
  createNumericXAxis: function() {
74
77
  return createNumericXAxis;
75
78
  },
@@ -175,6 +178,9 @@ _export(exports, {
175
178
  getSecureProps: function() {
176
179
  return getSecureProps;
177
180
  },
181
+ getTextSize: function() {
182
+ return getTextSize;
183
+ },
178
184
  getTypeOfAxis: function() {
179
185
  return getTypeOfAxis;
180
186
  },
@@ -202,6 +208,9 @@ _export(exports, {
202
208
  isValidDomainValue: function() {
203
209
  return isValidDomainValue;
204
210
  },
211
+ measureTextWithDOM: function() {
212
+ return measureTextWithDOM;
213
+ },
205
214
  pointTypes: function() {
206
215
  return pointTypes;
207
216
  },
@@ -252,6 +261,8 @@ const _chartutilities = require("@fluentui/chart-utilities");
252
261
  const MIN_DOMAIN_MARGIN = 8;
253
262
  const MIN_DONUT_RADIUS = 1;
254
263
  const DEFAULT_DATE_STRING = '2000-01-01';
264
+ const CARTESIAN_XAXIS_CLASSNAME = 'fui-cart__xAxis';
265
+ const CARTESIAN_XAXIS_TEXT_SELECTOR = `.${CARTESIAN_XAXIS_CLASSNAME} text`;
255
266
  var ChartTypes = /*#__PURE__*/ function(ChartTypes) {
256
267
  ChartTypes[ChartTypes["AreaChart"] = 0] = "AreaChart";
257
268
  ChartTypes[ChartTypes["LineChart"] = 1] = "LineChart";
@@ -321,7 +332,7 @@ function createNumericXAxis(xAxisParams, tickParams, chartType, culture, scaleTy
321
332
  const xAxisValue = typeof domainValue === 'number' ? domainValue : domainValue.valueOf();
322
333
  return (defaultFormat === null || defaultFormat === void 0 ? void 0 : defaultFormat(xAxisValue)) === '' ? '' : (0, _chartutilities.formatToLocaleString)(xAxisValue, culture);
323
334
  };
324
- if (hideTickOverlap && typeof xAxisCount === 'undefined') {
335
+ if (hideTickOverlap) {
325
336
  const longestLabelWidth = calcMaxLabelWidth(xAxisScale.ticks().map((v, i)=>tickFormat(v, i))) + 20;
326
337
  const [start, end] = xAxisScale.range();
327
338
  tickCount = Math.min(Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth)), 10);
@@ -345,10 +356,12 @@ function createNumericXAxis(xAxisParams, tickParams, chartType, culture, scaleTy
345
356
  if (xAxisElement) {
346
357
  (0, _d3selection.select)(xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true').style('direction', 'ltr').style('unicode-bidi', 'isolate');
347
358
  }
348
- const tickValues = (customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount)).map(xAxis.tickFormat());
359
+ const tickValues = customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount);
360
+ const tickLabels = tickValues.map(xAxis.tickFormat());
349
361
  return {
350
362
  xScale: xAxisScale,
351
- tickValues
363
+ tickValues,
364
+ tickLabels
352
365
  };
353
366
  }
354
367
  /**
@@ -536,7 +549,7 @@ function getDateFormatLevel(date, useUTC) {
536
549
  return (_matchedFormat_formatLevel = matchedFormat === null || matchedFormat === void 0 ? void 0 : matchedFormat.formatLevel) !== null && _matchedFormat_formatLevel !== void 0 ? _matchedFormat_formatLevel : 7;
537
550
  }
538
551
  function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLocale, customDateTimeFormatter, useUTC, chartType) {
539
- const { domainNRangeValues, xAxisElement, tickPadding = 6, xAxistickSize = 6, xAxisCount, calcMaxLabelWidth, tickStep, tick0, tickText } = xAxisParams;
552
+ const { domainNRangeValues, xAxisElement, tickPadding = 6, xAxistickSize = 6, xAxisCount, hideTickOverlap, calcMaxLabelWidth, tickStep, tick0, tickText } = xAxisParams;
540
553
  const isUtcSet = useUTC === true || useUTC === 'utc';
541
554
  const xAxisScale = isUtcSet ? (0, _d3scale.scaleUtc)() : (0, _d3scale.scaleTime)();
542
555
  xAxisScale.domain([
@@ -580,10 +593,11 @@ function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLo
580
593
  }
581
594
  return (0, _chartutilities.formatDateToLocaleString)(domainValue, culture, useUTC ? true : false, false, formatOptions);
582
595
  };
583
- const longestLabelWidth = calcMaxLabelWidth(xAxisScale.ticks().map(tickFormat)) + 40;
584
- const [start, end] = xAxisScale.range();
585
- const maxPossibleTickCount = Math.min(Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth)), 10);
586
- tickCount = Math.min(maxPossibleTickCount, xAxisCount !== null && xAxisCount !== void 0 ? xAxisCount : tickCount);
596
+ if (hideTickOverlap) {
597
+ const longestLabelWidth = calcMaxLabelWidth(xAxisScale.ticks().map(tickFormat)) + 40;
598
+ const [start, end] = xAxisScale.range();
599
+ tickCount = Math.max(1, Math.floor(Math.abs(end - start) / longestLabelWidth));
600
+ }
587
601
  const xAxis = (0, _d3axis.axisBottom)(xAxisScale).tickSize(xAxistickSize).tickPadding(tickPadding).ticks(tickCount).tickFormat(tickFormat);
588
602
  if ([
589
603
  8
@@ -602,10 +616,12 @@ function createDateXAxis(xAxisParams, tickParams, culture, options, timeFormatLo
602
616
  if (xAxisElement) {
603
617
  (0, _d3selection.select)(xAxisElement).call(xAxis).selectAll('text').attr('aria-hidden', 'true');
604
618
  }
605
- const tickValues = (customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount)).map(xAxis.tickFormat());
619
+ const tickValues = customTickValues !== null && customTickValues !== void 0 ? customTickValues : xAxisScale.ticks(tickCount);
620
+ const tickLabels = tickValues.map(xAxis.tickFormat());
606
621
  return {
607
622
  xScale: xAxisScale,
608
- tickValues
623
+ tickValues,
624
+ tickLabels
609
625
  };
610
626
  }
611
627
  function createStringXAxis(xAxisParams, tickParams, dataset, culture, _useRtl) {
@@ -654,7 +670,8 @@ function createStringXAxis(xAxisParams, tickParams, dataset, culture, _useRtl) {
654
670
  }
655
671
  return {
656
672
  xScale: xAxisScale,
657
- tickValues: tickValues.map(xAxis.tickFormat())
673
+ tickValues,
674
+ tickLabels: tickValues.map(xAxis.tickFormat())
658
675
  };
659
676
  }
660
677
  function useRtl() {
@@ -949,14 +966,14 @@ function silceOrAppendToArray(array, value) {
949
966
  }
950
967
  const DEFAULT_WRAP_WIDTH = 10;
951
968
  function createWrapOfXLabels(wrapLabelProps) {
952
- const { node, xAxis, noOfCharsToTruncate, showXAxisLablesTooltip, width = DEFAULT_WRAP_WIDTH } = wrapLabelProps;
969
+ const { node, xAxis, noOfCharsToTruncate, showXAxisLablesTooltip, width = DEFAULT_WRAP_WIDTH, container } = wrapLabelProps;
953
970
  if (node === null) {
954
971
  return;
955
972
  }
956
973
  const axisNode = (0, _d3selection.select)(node).call(xAxis);
957
974
  let removeVal = 0;
958
975
  let maxLines = 1;
959
- axisNode.selectAll('.tick text').each(function() {
976
+ axisNode.selectAll('.tick text').each(function(_, tickIndex) {
960
977
  const text = (0, _d3selection.select)(this);
961
978
  const totalWord = text.text();
962
979
  const truncatedWord = `${text.text().slice(0, noOfCharsToTruncate)}...`;
@@ -968,33 +985,33 @@ function createWrapOfXLabels(wrapLabelProps) {
968
985
  const lineHeight = 1.1; // ems
969
986
  const y = text.attr('y');
970
987
  const dy = parseFloat(text.attr('dy'));
971
- let tspan = text.text(null).append('tspan').attr('x', 0).attr('y', y).attr('id', 'BaseSpan').attr('dy', dy + 'em').attr('data-', totalWord);
972
- if (showXAxisLablesTooltip && totalWordLength > noOfCharsToTruncate) {
973
- tspan = text.append('tspan').attr('id', 'showDots').attr('x', 0).attr('y', y).attr('dy', dy + 'em').text(truncatedWord);
974
- } else if (showXAxisLablesTooltip && totalWordLength <= noOfCharsToTruncate) {
975
- tspan = text.append('tspan').attr('id', 'LessLength').attr('x', 0).attr('y', y).attr('dy', dy + 'em').text(totalWord);
988
+ let tspan = text.text(null).attr('data-full', totalWord).append('tspan').attr('x', 0).attr('y', y).attr('dy', dy + 'em');
989
+ if (showXAxisLablesTooltip) {
990
+ tspan.text(totalWordLength > noOfCharsToTruncate ? truncatedWord : totalWord);
976
991
  } else {
992
+ const maxWidth = Array.isArray(width) ? width[tickIndex] : width;
977
993
  while(word = words.pop()){
978
994
  line.push(word);
979
- tspan.text(line.join(' '));
980
- if (tspan.node().getComputedTextLength() > width && line.length > 1) {
995
+ const label = line.join(' ');
996
+ tspan.text(label);
997
+ const labelWidth = getTextSize(label, CARTESIAN_XAXIS_TEXT_SELECTOR, container).width;
998
+ if (labelWidth > maxWidth && line.length > 1) {
981
999
  line.pop();
982
1000
  tspan.text(line.join(' '));
983
1001
  line = [
984
1002
  word
985
1003
  ];
986
- tspan = text.append('tspan').attr('id', 'WordBreakId').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(word);
1004
+ tspan = text.append('tspan').attr('x', 0).attr('y', y).attr('dy', ++lineNumber * lineHeight + dy + 'em').text(word);
987
1005
  }
988
1006
  }
989
1007
  }
990
1008
  maxLines = Math.max(maxLines, lineNumber + 1);
991
1009
  });
992
1010
  if (!showXAxisLablesTooltip) {
1011
+ var _querySelector;
993
1012
  let maxHeight = 12; // intial value to render corretly first time
994
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
995
- const outerHTMLElement = document.getElementById('WordBreakId');
996
- const BoxCordinates = outerHTMLElement && outerHTMLElement.getBoundingClientRect();
997
- const boxHeight = BoxCordinates && BoxCordinates.height;
1013
+ var _querySelector_getBoundingClientRect_height;
1014
+ 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;
998
1015
  if (boxHeight > maxHeight) {
999
1016
  maxHeight = boxHeight;
1000
1017
  }
@@ -1006,24 +1023,18 @@ function createYAxisLabels(node, yAxis, noOfCharsToTruncate, truncateLabel, isRt
1006
1023
  if (node === null) {
1007
1024
  return;
1008
1025
  }
1009
- let tickIndex = 0;
1010
1026
  const axisNode = (0, _d3selection.select)(node).call(yAxis);
1011
1027
  axisNode.selectAll('.tick text').each(function() {
1012
1028
  const text = (0, _d3selection.select)(this);
1013
1029
  const totalWord = text.text();
1014
1030
  const truncatedWord = isRtl ? `...${text.text().slice(0, noOfCharsToTruncate)}` : `${text.text().slice(0, noOfCharsToTruncate)}...`;
1015
1031
  const totalWordLength = text.text().length;
1016
- const padding = 0; // ems
1017
1032
  const y = text.attr('y');
1018
1033
  const x = text.attr('x');
1019
1034
  const dy = parseFloat(text.attr('dy'));
1020
- const dx = 0;
1021
- const uid = tickIndex++;
1022
- text.text(null).append('tspan').attr('x', x).attr('y', y).attr('id', `BaseSpan-${uid}`).attr('dy', dy + 'em').attr('data-', totalWord);
1023
- if (truncateLabel && totalWordLength > noOfCharsToTruncate) {
1024
- text.append('tspan').attr('id', `showDots-${uid}`).attr('x', x).attr('y', y).attr('dy', dy + 'em').attr('dx', padding + dx + 'em').text(truncatedWord);
1025
- } else {
1026
- text.append('tspan').attr('id', `LessLength-${uid}`).attr('x', x).attr('y', y).attr('dx', padding + dx + 'em').text(totalWord);
1035
+ const tspan = text.text(null).attr('data-full', totalWord).append('tspan').attr('x', x).attr('y', y).attr('dy', dy + 'em');
1036
+ if (truncateLabel) {
1037
+ tspan.text(totalWordLength > noOfCharsToTruncate ? truncatedWord : totalWord);
1027
1038
  }
1028
1039
  });
1029
1040
  }
@@ -1065,30 +1076,30 @@ const calculateLongestLabelWidth = (labels, query = 'none')=>{
1065
1076
  return maxLabelWidth;
1066
1077
  };
1067
1078
  function tooltipOfAxislabels(axistooltipProps) {
1068
- const { tooltipCls, axis, id } = axistooltipProps;
1079
+ const { tooltipCls, axis, id, container } = axistooltipProps;
1069
1080
  if (axis === null) {
1070
1081
  return null;
1071
1082
  }
1072
- const div = (0, _d3selection.select)('body').append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
1073
- const aa = axis.selectAll('[id^="BaseSpan-"]')._groups[0];
1074
- const baseSpanLength = aa && Object.keys(aa).length;
1075
- const originalDataArray = [];
1076
- for(let i = 0; i < baseSpanLength; i++){
1077
- const originalData = aa[i].dataset && Object.values(aa[i].dataset)[0];
1078
- originalDataArray.push(originalData);
1079
- }
1080
- const tickObject = axis.selectAll('.tick')._groups[0];
1081
- const tickObjectLength = tickObject && Object.keys(tickObject).length;
1082
- for(let i = 0; i < tickObjectLength; i++){
1083
- const d1 = tickObject[i];
1084
- (0, _d3selection.select)(d1) // eslint-disable-next-line @typescript-eslint/no-explicit-any
1083
+ const div = (container ? (0, _d3selection.select)(container) : (0, _d3selection.select)('body')).append('div').attr('id', id).attr('class', tooltipCls).style('opacity', 0);
1084
+ axis.selectAll('.tick text').each(function() {
1085
+ const tickSelection = (0, _d3selection.select)(this);
1086
+ const fullLabel = tickSelection.attr('data-full');
1087
+ if (tickSelection.text() === fullLabel) {
1088
+ return;
1089
+ }
1090
+ const tickEl = this;
1091
+ tickSelection // eslint-disable-next-line @typescript-eslint/no-explicit-any
1085
1092
  .on('mouseover', (event, d)=>{
1086
- div.style('opacity', 0.9);
1087
- div.html(originalDataArray[i]).style('left', event.pageX + 'px').style('top', event.pageY - 28 + 'px');
1093
+ const containerBounds = container === null || container === void 0 ? void 0 : container.getBoundingClientRect();
1094
+ const tickBounds = tickEl.getBoundingClientRect();
1095
+ const tooltipBottom = containerBounds ? containerBounds.bottom - (tickBounds.top - 4) : tickBounds.top - 4;
1096
+ var _containerBounds_left;
1097
+ 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);
1098
+ div.text(fullLabel).style('bottom', `${tooltipBottom}px`).style('left', `${tooltipLeft}px`).style('transform', 'translateX(-50%)').style('opacity', 0.9);
1088
1099
  }).on('mouseout', (d)=>{
1089
1100
  div.style('opacity', 0);
1090
1101
  });
1091
- }
1102
+ });
1092
1103
  }
1093
1104
  function getXAxisType(points) {
1094
1105
  let isXAxisDateType = false;
@@ -1102,11 +1113,11 @@ function getXAxisType(points) {
1102
1113
  }
1103
1114
  return isXAxisDateType;
1104
1115
  }
1105
- function domainRangeOfNumericForAreaLineScatterCharts(points, margins, width, isRTL, scaleType, hasMarkersMode) {
1116
+ function domainRangeOfNumericForAreaLineScatterCharts(points, margins, width, isRTL, scaleType, hasMarkersMode, xMinVal, xMaxVal) {
1106
1117
  const isScatterPolar = isScatterPolarSeries(points);
1107
1118
  let [xMin, xMax] = getScatterXDomainExtent(points, scaleType);
1108
1119
  if (hasMarkersMode) {
1109
- const xPadding = getDomainPaddingForMarkers(xMin, xMax, scaleType);
1120
+ const xPadding = getDomainPaddingForMarkers(xMin, xMax, scaleType, xMinVal, xMaxVal);
1110
1121
  xMin = xMin - xPadding.start;
1111
1122
  xMax = xMax + xPadding.end;
1112
1123
  }
@@ -1513,8 +1524,8 @@ function areArraysEqual(arr1, arr2) {
1513
1524
  return true;
1514
1525
  }
1515
1526
  const cssVarRegExp = /var\((--[a-zA-Z0-9\-]+)\)/g;
1516
- function resolveCSSVariables(chartContainer, styleRules) {
1517
- const containerStyles = getComputedStyle(chartContainer);
1527
+ function resolveCSSVariables(container, styleRules) {
1528
+ const containerStyles = getComputedStyle(container);
1518
1529
  return styleRules.replace(cssVarRegExp, (match, group1)=>{
1519
1530
  return containerStyles.getPropertyValue(group1);
1520
1531
  });
@@ -1614,11 +1625,6 @@ function copyStyle(properties, fromEl, toEl) {
1614
1625
  });
1615
1626
  }
1616
1627
  }
1617
- let measurementSpanCounter = 0;
1618
- function getUniqueMeasurementSpanId() {
1619
- measurementSpanCounter++;
1620
- return `measurement_span_${measurementSpanCounter}`;
1621
- }
1622
1628
  const MEASUREMENT_SPAN_STYLE = {
1623
1629
  position: 'absolute',
1624
1630
  visibility: 'hidden',
@@ -1629,23 +1635,60 @@ const MEASUREMENT_SPAN_STYLE = {
1629
1635
  border: 'none',
1630
1636
  whiteSpace: 'pre'
1631
1637
  };
1632
- const createMeasurementSpan = (text, className, parentElement)=>{
1633
- const MEASUREMENT_SPAN_ID = getUniqueMeasurementSpanId();
1638
+ const MEASUREMENT_SPAN_ID = 'fui_measurement_span';
1639
+ const TEXT_STYLE_PROPERTIES = [
1640
+ 'font-size',
1641
+ 'font-family',
1642
+ 'font-weight',
1643
+ 'font-style',
1644
+ 'letter-spacing',
1645
+ 'text-transform'
1646
+ ];
1647
+ const measureTextWithDOM = (text, cssSelector, container)=>{
1634
1648
  let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
1635
1649
  if (!measurementSpan) {
1636
1650
  measurementSpan = document.createElement('span');
1637
1651
  measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
1638
1652
  measurementSpan.setAttribute('aria-hidden', 'true');
1639
- if (parentElement) {
1640
- parentElement.appendChild(measurementSpan);
1641
- } else {
1642
- document.body.appendChild(measurementSpan);
1643
- }
1653
+ (container !== null && container !== void 0 ? container : document.body).appendChild(measurementSpan);
1644
1654
  }
1645
- measurementSpan.setAttribute('class', className);
1646
1655
  Object.assign(measurementSpan.style, MEASUREMENT_SPAN_STYLE);
1656
+ const refEl = (container !== null && container !== void 0 ? container : document).querySelector(cssSelector);
1657
+ if (refEl) {
1658
+ copyStyle(TEXT_STYLE_PROPERTIES, refEl, measurementSpan);
1659
+ }
1647
1660
  measurementSpan.textContent = `${text}`;
1648
- return measurementSpan;
1661
+ const rect = measurementSpan.getBoundingClientRect();
1662
+ return {
1663
+ node: measurementSpan,
1664
+ width: rect.width,
1665
+ height: rect.height
1666
+ };
1667
+ };
1668
+ const CACHE_SIZE = 2000;
1669
+ const textSizeCache = new Map();
1670
+ const getTextSize = (text, cssSelector, container)=>{
1671
+ const cacheKey = `${text}|${cssSelector}`;
1672
+ const cachedResult = textSizeCache.get(cacheKey);
1673
+ if (cachedResult) {
1674
+ return cachedResult;
1675
+ }
1676
+ const { width, height } = measureTextWithDOM(text, cssSelector, container);
1677
+ // TODO: Improve cache eviction strategy if needed (e.g., LRU)
1678
+ if (textSizeCache.size >= CACHE_SIZE) {
1679
+ const firstKey = textSizeCache.keys().next().value;
1680
+ if (!(0, _chartutilities.isInvalidValue)(firstKey)) {
1681
+ textSizeCache.delete(firstKey);
1682
+ }
1683
+ }
1684
+ textSizeCache.set(cacheKey, {
1685
+ width,
1686
+ height
1687
+ });
1688
+ return {
1689
+ width,
1690
+ height
1691
+ };
1649
1692
  };
1650
1693
  function isScatterPolarSeries(points) {
1651
1694
  return points.some((item)=>{
@@ -1667,17 +1710,26 @@ const createNumericScale = (scaleType)=>{
1667
1710
  return (0, _d3scale.scaleLinear)();
1668
1711
  }
1669
1712
  };
1670
- const getDomainPaddingForMarkers = (minVal, maxVal, scaleType)=>{
1713
+ const getDomainPaddingForMarkers = (minVal, maxVal, scaleType, userMinVal, userMaxVal)=>{
1671
1714
  if (scaleType === 'log') {
1672
1715
  return {
1673
1716
  start: minVal * 0.5,
1674
1717
  end: maxVal
1675
1718
  };
1676
1719
  }
1677
- const defaultPadding = (maxVal - minVal) * 0.1;
1720
+ /* if user explicitly sets userMinVal or userMaxVal, we will check that to avoid excessive padding on either side.
1721
+ If the difference between minVal and userMinVal is more than 10% of the data range, we set padding to 0 on that side.
1722
+ this is to avoid cases where userMinVal is significantly smaller than minVal or userMaxVal is significantly larger than
1723
+ maxVal, which would lead to excessive padding. In other cases, we apply the default 10% padding on both sides.
1724
+ */ const rangePadding = (maxVal - minVal) * 0.1;
1725
+ // If explicit bounds are set and they're far from the data range, don't add extra padding
1726
+ const paddingAlreadySatisfiedAtMin = userMinVal !== undefined && rangePadding > Math.abs(minVal - Math.min(minVal, userMinVal));
1727
+ const paddingAlreadySatisfiedAtMax = userMaxVal !== undefined && rangePadding > Math.abs(maxVal - Math.max(maxVal, userMaxVal));
1728
+ const startPadding = paddingAlreadySatisfiedAtMin ? 0 : rangePadding;
1729
+ const endPadding = paddingAlreadySatisfiedAtMax ? 0 : rangePadding;
1678
1730
  return {
1679
- start: defaultPadding,
1680
- end: defaultPadding
1731
+ start: startPadding,
1732
+ end: endPadding
1681
1733
  };
1682
1734
  };
1683
1735
  const isValidDomainValue = (value, scaleType)=>{
@@ -1701,7 +1753,7 @@ const getScatterXDomainExtent = (points, scaleType)=>{
1701
1753
  xMax
1702
1754
  ];
1703
1755
  };
1704
- const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, yScaleSecondary, useSecondaryYScale, xScaleType, yScaleType: primaryYScaleType, secondaryYScaleType })=>{
1756
+ const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, yScaleSecondary, useSecondaryYScale, xScaleType, yScaleType: primaryYScaleType, secondaryYScaleType, xMinValue, xMaxValue, yMinValue, yMaxValue })=>{
1705
1757
  // Note: This function is executed after the scale is created, so the actual padding can be
1706
1758
  // obtained by calculating the difference between the respective minimums or maximums of the
1707
1759
  // scale domain and the data. However, doing so often causes the marker size to scale up
@@ -1712,13 +1764,13 @@ const getRangeForScatterMarkerSize = ({ data, xScale, yScalePrimary, yScaleSecon
1712
1764
  // it the other way around (i.e., adjusting the scale domain first with padding and then scaling
1713
1765
  // the markers to fit inside the plot area).
1714
1766
  const [xMin, xMax] = getScatterXDomainExtent(data, xScaleType);
1715
- const xPadding = getDomainPaddingForMarkers(+xMin, +xMax, xScaleType);
1767
+ const xPadding = getDomainPaddingForMarkers(+xMin, +xMax, xScaleType, xMinValue, xMaxValue);
1716
1768
  const scaleXMin = xMin instanceof Date ? new Date(+xMin - xPadding.start) : xMin - xPadding.start;
1717
1769
  const scaleXMax = xMax instanceof Date ? new Date(+xMax + xPadding.end) : xMax + xPadding.end;
1718
1770
  const extraXPixels = Math.min(Math.abs(xScale(xMin) - xScale(scaleXMin)), Math.abs(xScale(scaleXMax) - xScale(xMax)));
1719
1771
  const yScaleType = useSecondaryYScale ? secondaryYScaleType : primaryYScaleType;
1720
1772
  const { startValue: yMin, endValue: yMax } = findNumericMinMaxOfY(data, undefined, useSecondaryYScale, yScaleType);
1721
- const yPadding = getDomainPaddingForMarkers(yMin, yMax, yScaleType);
1773
+ const yPadding = getDomainPaddingForMarkers(yMin, yMax, yScaleType, yMinValue, yMaxValue);
1722
1774
  const scaleYMin = yMin - yPadding.start;
1723
1775
  const scaleYMax = yMax + yPadding.end;
1724
1776
  const yScale = useSecondaryYScale ? yScaleSecondary : yScalePrimary;
@@ -1770,7 +1822,7 @@ const generateNumericTicks = (scaleType, tickStep, tick0, scaleDomain)=>{
1770
1822
  const refTick = typeof tick0 === 'number' ? tick0 : 0;
1771
1823
  if (scaleType === 'log') {
1772
1824
  if (typeof tickStep === 'number' && tickStep > 0) {
1773
- return generateLinearTicks(refTick, tickStep, scaleDomain.map((d)=>Math.log10(d))).map((t)=>Math.pow(10, t));
1825
+ return generateLinearTicks(refTick, tickStep, scaleDomain.map((d)=>Math.log10(d))).map((t)=>10 ** t);
1774
1826
  }
1775
1827
  if (typeof tickStep === 'string') {
1776
1828
  const prefix = tickStep[0];
@@ -1817,7 +1869,7 @@ function calculatePrecision(value) {
1817
1869
  return 0;
1818
1870
  }
1819
1871
  function precisionRound(value, precision, base = 10) {
1820
- const exp = Math.pow(base, precision);
1872
+ const exp = base ** precision;
1821
1873
  return Math.round(value * exp) / exp;
1822
1874
  }
1823
1875
  const findCalloutPoints = (calloutPointsByX, x)=>{
@@ -1833,3 +1885,102 @@ const findCalloutPoints = (calloutPointsByX, x)=>{
1833
1885
  values: calloutPointsByX[key]
1834
1886
  };
1835
1887
  };
1888
+ const autoLayoutXAxisLabels = (tickValues, tickLabels, scale, axisNode, containerWidth, container)=>{
1889
+ let requiresWrap = false;
1890
+ let requiresTruncate = false;
1891
+ const maxWidths = [];
1892
+ const [rangeStart, rangeEnd] = scale.range();
1893
+ const isRTL = rangeEnd - rangeStart < 0;
1894
+ const start = isRTL ? containerWidth : 0;
1895
+ const end = isRTL ? 0 : containerWidth;
1896
+ const getTickPosition = (index)=>{
1897
+ var _scale;
1898
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1899
+ return ((_scale = scale(tickValues[index])) !== null && _scale !== void 0 ? _scale : 0) + ('bandwidth' in scale ? scale.bandwidth() / 2 : 0);
1900
+ };
1901
+ const getLabelWidth = (text)=>{
1902
+ return getTextSize(text, CARTESIAN_XAXIS_TEXT_SELECTOR, container).width;
1903
+ };
1904
+ for(let i = 0; i < tickValues.length; i++){
1905
+ const position = getTickPosition(i);
1906
+ const leftSpace = Math.abs(i > 0 ? (position - getTickPosition(i - 1)) / 2 : position - start);
1907
+ const rightSpace = Math.abs(i + 1 < tickValues.length ? (getTickPosition(i + 1) - position) / 2 : end - position);
1908
+ const maxAvailableWidth = Math.min(leftSpace, rightSpace) * 2 - 8; // 4px padding on both sides
1909
+ const label = tickLabels[i];
1910
+ const labelWidth = getLabelWidth(label);
1911
+ maxWidths.push(maxAvailableWidth);
1912
+ if (labelWidth > maxAvailableWidth) {
1913
+ const longestWordWidth = Math.max(...label.split(/\s+/).map((word)=>getLabelWidth(word)));
1914
+ if (longestWordWidth <= maxAvailableWidth) {
1915
+ requiresWrap = true;
1916
+ } else {
1917
+ requiresTruncate = true;
1918
+ }
1919
+ }
1920
+ }
1921
+ if (requiresTruncate) {
1922
+ return truncateAndStaggerXAxisLabels(tickValues, tickLabels, scale, axisNode, containerWidth, container);
1923
+ }
1924
+ if (requiresWrap) {
1925
+ var _createWrapOfXLabels;
1926
+ return (_createWrapOfXLabels = createWrapOfXLabels({
1927
+ node: axisNode,
1928
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1929
+ xAxis: scale,
1930
+ noOfCharsToTruncate: 100,
1931
+ showXAxisLablesTooltip: false,
1932
+ width: maxWidths,
1933
+ container
1934
+ })) !== null && _createWrapOfXLabels !== void 0 ? _createWrapOfXLabels : 0;
1935
+ }
1936
+ return 0;
1937
+ };
1938
+ const truncateAndStaggerXAxisLabels = (tickValues, tickLabels, scale, axisNode, containerWidth, container)=>{
1939
+ if (!axisNode) {
1940
+ return 0;
1941
+ }
1942
+ let maxHeight = 12;
1943
+ const [rangeStart, rangeEnd] = scale.range();
1944
+ const isRTL = rangeEnd - rangeStart < 0;
1945
+ const start = isRTL ? containerWidth : 0;
1946
+ const end = isRTL ? 0 : containerWidth;
1947
+ const getTickPosition = (index)=>{
1948
+ var _scale;
1949
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1950
+ return ((_scale = scale(tickValues[index])) !== null && _scale !== void 0 ? _scale : 0) + ('bandwidth' in scale ? scale.bandwidth() / 2 : 0);
1951
+ };
1952
+ const getLabelSize = (text)=>{
1953
+ return getTextSize(text, CARTESIAN_XAXIS_TEXT_SELECTOR, container);
1954
+ };
1955
+ (0, _d3selection.select)(axisNode).selectAll('.tick text').each(function(_, i) {
1956
+ const position = getTickPosition(i);
1957
+ const leftSpace = Math.abs(i > 0 ? position - getTickPosition(i - 1) : position - start);
1958
+ const rightSpace = Math.abs(i + 1 < tickValues.length ? getTickPosition(i + 1) - position : end - position);
1959
+ const maxAvailableWidth = Math.min(leftSpace, rightSpace) * 2 - 8; // 4px padding on both sides
1960
+ const label = tickLabels[i];
1961
+ const textNode = (0, _d3selection.select)(this).text(null).attr('data-full', label);
1962
+ const lineHeight = 1.1; // ems
1963
+ const y = textNode.attr('y');
1964
+ const dy = parseFloat(textNode.attr('dy'));
1965
+ 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));
1966
+ maxHeight = Math.max(maxHeight, getLabelSize(label).height);
1967
+ });
1968
+ return tickValues.length > 1 ? maxHeight : 0;
1969
+ };
1970
+ const truncateTextToFitWidth = (text, maxWidth, measure)=>{
1971
+ if (measure(text) <= maxWidth) {
1972
+ return text;
1973
+ }
1974
+ let lo = 1;
1975
+ let hi = text.length;
1976
+ while(lo < hi){
1977
+ const mid = Math.floor((lo + hi + 1) / 2);
1978
+ const candidate = text.slice(0, mid) + '...';
1979
+ if (measure(candidate) <= maxWidth) {
1980
+ lo = mid;
1981
+ } else {
1982
+ hi = mid - 1;
1983
+ }
1984
+ }
1985
+ return text.slice(0, lo) + '...';
1986
+ };