@fluentui/react-charts 0.0.0-nightly-20251215-0407.1 → 0.0.0-nightly-20251217-0407.1

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 (103) hide show
  1. package/CHANGELOG.md +13 -13
  2. package/dist/index.d.ts +25 -1
  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/CommonComponents/CartesianChart.js +41 -31
  8. package/lib/components/CommonComponents/CartesianChart.js.map +1 -1
  9. package/lib/components/CommonComponents/CartesianChart.types.js.map +1 -1
  10. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js +5 -5
  11. package/lib/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  12. package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js +4 -3
  13. package/lib/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
  14. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js +177 -29
  15. package/lib/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  16. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +17 -17
  17. package/lib/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  18. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +1 -2
  19. package/lib/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  20. package/lib/components/Legends/Legends.js +3 -4
  21. package/lib/components/Legends/Legends.js.map +1 -1
  22. package/lib/components/LineChart/LineChart.js +1 -23
  23. package/lib/components/LineChart/LineChart.js.map +1 -1
  24. package/lib/components/LineChart/useLineChartStyles.styles.js +1 -2
  25. package/lib/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  26. package/lib/components/SankeyChart/SankeyChart.js +1 -1
  27. package/lib/components/SankeyChart/SankeyChart.js.map +1 -1
  28. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js +1 -2
  29. package/lib/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
  30. package/lib/components/ScatterChart/ScatterChart.js +1 -23
  31. package/lib/components/ScatterChart/ScatterChart.js.map +1 -1
  32. package/lib/components/ScatterChart/useScatterChartStyles.styles.js +1 -2
  33. package/lib/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  34. package/lib/components/VerticalBarChart/VerticalBarChart.js +8 -78
  35. package/lib/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  36. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +1 -2
  37. package/lib/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  38. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js +14 -26
  39. package/lib/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  40. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +1 -2
  41. package/lib/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
  42. package/lib/types/DataPoint.js.map +1 -1
  43. package/lib/utilities/Common.styles.js +0 -1
  44. package/lib/utilities/Common.styles.js.map +1 -1
  45. package/lib/utilities/Common.styles.raw.js +0 -1
  46. package/lib/utilities/Common.styles.raw.js.map +1 -1
  47. package/lib/utilities/image-export-utils.js +4 -4
  48. package/lib/utilities/image-export-utils.js.map +1 -1
  49. package/lib/utilities/utilities.js +200 -67
  50. package/lib/utilities/utilities.js.map +1 -1
  51. package/lib-commonjs/components/AreaChart/AreaChart.js +0 -26
  52. package/lib-commonjs/components/AreaChart/AreaChart.js.map +1 -1
  53. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js +0 -2
  54. package/lib-commonjs/components/AreaChart/useAreaChartStyles.styles.js.map +1 -1
  55. package/lib-commonjs/components/CommonComponents/CartesianChart.js +40 -30
  56. package/lib-commonjs/components/CommonComponents/CartesianChart.js.map +1 -1
  57. package/lib-commonjs/components/CommonComponents/CartesianChart.types.js.map +1 -1
  58. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js +3 -4
  59. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.js.map +1 -1
  60. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js +3 -2
  61. package/lib-commonjs/components/CommonComponents/useCartesianChartStyles.styles.raw.js.map +1 -1
  62. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js +177 -28
  63. package/lib-commonjs/components/DeclarativeChart/PlotlySchemaAdapter.js.map +1 -1
  64. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js +15 -15
  65. package/lib-commonjs/components/GroupedVerticalBarChart/GroupedVerticalBarChart.js.map +1 -1
  66. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js +0 -2
  67. package/lib-commonjs/components/GroupedVerticalBarChart/useGroupedVerticalBarChartStyles.styles.js.map +1 -1
  68. package/lib-commonjs/components/Legends/Legends.js +3 -4
  69. package/lib-commonjs/components/Legends/Legends.js.map +1 -1
  70. package/lib-commonjs/components/LineChart/LineChart.js +0 -22
  71. package/lib-commonjs/components/LineChart/LineChart.js.map +1 -1
  72. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js +0 -2
  73. package/lib-commonjs/components/LineChart/useLineChartStyles.styles.js.map +1 -1
  74. package/lib-commonjs/components/SankeyChart/SankeyChart.js +1 -1
  75. package/lib-commonjs/components/SankeyChart/SankeyChart.js.map +1 -1
  76. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js +0 -2
  77. package/lib-commonjs/components/SankeyChart/useSankeyChartStyles.styles.js.map +1 -1
  78. package/lib-commonjs/components/ScatterChart/ScatterChart.js +0 -22
  79. package/lib-commonjs/components/ScatterChart/ScatterChart.js.map +1 -1
  80. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js +0 -2
  81. package/lib-commonjs/components/ScatterChart/useScatterChartStyles.styles.js.map +1 -1
  82. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js +7 -77
  83. package/lib-commonjs/components/VerticalBarChart/VerticalBarChart.js.map +1 -1
  84. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js +0 -2
  85. package/lib-commonjs/components/VerticalBarChart/useVerticalBarChartStyles.styles.js.map +1 -1
  86. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js +13 -25
  87. package/lib-commonjs/components/VerticalStackedBarChart/VerticalStackedBarChart.js.map +1 -1
  88. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js +0 -2
  89. package/lib-commonjs/components/VerticalStackedBarChart/useVerticalStackedBarChartStyles.styles.js.map +1 -1
  90. package/lib-commonjs/types/DataPoint.js.map +1 -1
  91. package/lib-commonjs/utilities/Common.styles.js +0 -1
  92. package/lib-commonjs/utilities/Common.styles.js.map +1 -1
  93. package/lib-commonjs/utilities/Common.styles.raw.js +0 -1
  94. package/lib-commonjs/utilities/Common.styles.raw.js.map +1 -1
  95. package/lib-commonjs/utilities/image-export-utils.js +3 -3
  96. package/lib-commonjs/utilities/image-export-utils.js.map +1 -1
  97. package/lib-commonjs/utilities/utilities.js +212 -70
  98. package/lib-commonjs/utilities/utilities.js.map +1 -1
  99. package/package.json +12 -12
  100. package/lib/components/DeclarativeChart/imageExporter.js +0 -223
  101. package/lib/components/DeclarativeChart/imageExporter.js.map +0 -1
  102. package/lib-commonjs/components/DeclarativeChart/imageExporter.js +0 -233
  103. 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;
@@ -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)=>{
@@ -1842,3 +1885,102 @@ const findCalloutPoints = (calloutPointsByX, x)=>{
1842
1885
  values: calloutPointsByX[key]
1843
1886
  };
1844
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
+ };