@neo4j-ndl/react-charts 2.1.21 → 2.2.0

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 (209) hide show
  1. package/lib/LICENSES.txt +0 -295
  2. package/lib/NOTICE.txt +1383 -1392
  3. package/lib/{esm/charts/index.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/defineProperty.js} +13 -5
  4. package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.js +46 -0
  5. package/lib/{esm/charts/tests/ChartWrapperWithTooltipFormatter.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.js} +12 -13
  6. package/lib/{esm/index.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutPropertiesLoose.js} +13 -2
  7. package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPrimitive.js +35 -0
  8. package/lib/{esm/charts/utils/chart-types.js → cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPropertyKey.js} +10 -2
  9. package/lib/cjs/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/typeof.js +37 -0
  10. package/lib/cjs/_virtual/_rolldown/runtime.js +44 -0
  11. package/lib/cjs/charts/Chart.js +121 -111
  12. package/lib/cjs/charts/Chart.js.map +1 -1
  13. package/lib/cjs/charts/ChartContainer.js +67 -62
  14. package/lib/cjs/charts/ChartContainer.js.map +1 -1
  15. package/lib/cjs/charts/ChartEmpty.js +45 -30
  16. package/lib/cjs/charts/ChartEmpty.js.map +1 -1
  17. package/lib/cjs/charts/ChartRender.js +112 -87
  18. package/lib/cjs/charts/ChartRender.js.map +1 -1
  19. package/lib/cjs/charts/ChartTooltip.js +111 -65
  20. package/lib/cjs/charts/ChartTooltip.js.map +1 -1
  21. package/lib/cjs/charts/Legend.js +81 -69
  22. package/lib/cjs/charts/Legend.js.map +1 -1
  23. package/lib/cjs/charts/LegendItem.js +83 -62
  24. package/lib/cjs/charts/LegendItem.js.map +1 -1
  25. package/lib/cjs/charts/LegendLayout.js +330 -348
  26. package/lib/cjs/charts/LegendLayout.js.map +1 -1
  27. package/lib/cjs/charts/hooks/use-chart-instance.js +115 -122
  28. package/lib/cjs/charts/hooks/use-chart-instance.js.map +1 -1
  29. package/lib/cjs/charts/hooks/use-chart-option.js +79 -80
  30. package/lib/cjs/charts/hooks/use-chart-option.js.map +1 -1
  31. package/lib/cjs/charts/hooks/use-chart-refs.js +47 -44
  32. package/lib/cjs/charts/hooks/use-chart-refs.js.map +1 -1
  33. package/lib/cjs/charts/hooks/use-chart-zoom.js +102 -127
  34. package/lib/cjs/charts/hooks/use-chart-zoom.js.map +1 -1
  35. package/lib/cjs/charts/hooks/use-legend-interactions.js +127 -132
  36. package/lib/cjs/charts/hooks/use-legend-interactions.js.map +1 -1
  37. package/lib/cjs/charts/hooks/use-legend-series.js +143 -174
  38. package/lib/cjs/charts/hooks/use-legend-series.js.map +1 -1
  39. package/lib/cjs/charts/hooks/use-legend-visibility.js +66 -85
  40. package/lib/cjs/charts/hooks/use-legend-visibility.js.map +1 -1
  41. package/lib/cjs/charts/index.js +31 -40
  42. package/lib/cjs/charts/index.js.map +1 -1
  43. package/lib/cjs/charts/themes/ndl-echarts-theme.js +136 -168
  44. package/lib/cjs/charts/themes/ndl-echarts-theme.js.map +1 -1
  45. package/lib/cjs/charts/utils/aria-description.js +150 -214
  46. package/lib/cjs/charts/utils/aria-description.js.map +1 -1
  47. package/lib/cjs/charts/utils/build-chart-option.js +166 -174
  48. package/lib/cjs/charts/utils/build-chart-option.js.map +1 -1
  49. package/lib/cjs/charts/utils/chart-tooltip-formatter.js +156 -172
  50. package/lib/cjs/charts/utils/chart-tooltip-formatter.js.map +1 -1
  51. package/lib/cjs/charts/utils/chart-types.js +25 -20
  52. package/lib/cjs/charts/utils/chart-types.js.map +1 -1
  53. package/lib/cjs/charts/utils/defaults.js +69 -67
  54. package/lib/cjs/charts/utils/defaults.js.map +1 -1
  55. package/lib/cjs/charts/utils/format-utils.js +55 -66
  56. package/lib/cjs/charts/utils/format-utils.js.map +1 -1
  57. package/lib/cjs/charts/utils/legend-layout.js +54 -53
  58. package/lib/cjs/charts/utils/legend-layout.js.map +1 -1
  59. package/lib/cjs/charts/utils/legend-utils.js +82 -121
  60. package/lib/cjs/charts/utils/legend-utils.js.map +1 -1
  61. package/lib/cjs/charts/utils/scatter-tooltip-points.js +191 -266
  62. package/lib/cjs/charts/utils/scatter-tooltip-points.js.map +1 -1
  63. package/lib/cjs/charts/utils/threshold.js +89 -102
  64. package/lib/cjs/charts/utils/threshold.js.map +1 -1
  65. package/lib/cjs/charts/utils/user-option-utils.js +419 -347
  66. package/lib/cjs/charts/utils/user-option-utils.js.map +1 -1
  67. package/lib/cjs/index.js +31 -35
  68. package/lib/cjs/index.js.map +1 -1
  69. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/defineProperty.mjs +11 -0
  70. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.mjs +24 -0
  71. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.mjs +12 -0
  72. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutPropertiesLoose.mjs +11 -0
  73. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPrimitive.mjs +13 -0
  74. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/toPropertyKey.mjs +8 -0
  75. package/lib/esm/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/typeof.mjs +10 -0
  76. package/lib/esm/charts/Chart.mjs +123 -0
  77. package/lib/esm/charts/Chart.mjs.map +1 -0
  78. package/lib/esm/charts/ChartContainer.mjs +71 -0
  79. package/lib/esm/charts/ChartContainer.mjs.map +1 -0
  80. package/lib/esm/charts/ChartEmpty.mjs +46 -0
  81. package/lib/esm/charts/ChartEmpty.mjs.map +1 -0
  82. package/lib/esm/charts/ChartRender.mjs +113 -0
  83. package/lib/esm/charts/ChartRender.mjs.map +1 -0
  84. package/lib/esm/charts/ChartTooltip.mjs +109 -0
  85. package/lib/esm/charts/ChartTooltip.mjs.map +1 -0
  86. package/lib/esm/charts/Legend.mjs +82 -0
  87. package/lib/esm/charts/Legend.mjs.map +1 -0
  88. package/lib/esm/charts/LegendItem.mjs +82 -0
  89. package/lib/esm/charts/LegendItem.mjs.map +1 -0
  90. package/lib/esm/charts/LegendLayout.mjs +337 -0
  91. package/lib/esm/charts/LegendLayout.mjs.map +1 -0
  92. package/lib/esm/charts/hooks/use-chart-instance.mjs +119 -0
  93. package/lib/esm/charts/hooks/use-chart-instance.mjs.map +1 -0
  94. package/lib/esm/charts/hooks/use-chart-option.mjs +79 -0
  95. package/lib/esm/charts/hooks/use-chart-option.mjs.map +1 -0
  96. package/lib/esm/charts/hooks/use-chart-refs.mjs +49 -0
  97. package/lib/esm/charts/hooks/use-chart-refs.mjs.map +1 -0
  98. package/lib/esm/charts/hooks/use-chart-zoom.mjs +102 -0
  99. package/lib/esm/charts/hooks/use-chart-zoom.mjs.map +1 -0
  100. package/lib/esm/charts/hooks/use-legend-interactions.mjs +138 -0
  101. package/lib/esm/charts/hooks/use-legend-interactions.mjs.map +1 -0
  102. package/lib/esm/charts/hooks/use-legend-series.mjs +151 -0
  103. package/lib/esm/charts/hooks/use-legend-series.mjs.map +1 -0
  104. package/lib/esm/charts/hooks/use-legend-visibility.mjs +67 -0
  105. package/lib/esm/charts/hooks/use-legend-visibility.mjs.map +1 -0
  106. package/lib/esm/charts/index.mjs +27 -0
  107. package/lib/esm/charts/index.mjs.map +1 -0
  108. package/lib/esm/charts/themes/ndl-echarts-theme.mjs +139 -0
  109. package/lib/esm/charts/themes/ndl-echarts-theme.mjs.map +1 -0
  110. package/lib/esm/charts/utils/aria-description.mjs +162 -0
  111. package/lib/esm/charts/utils/aria-description.mjs.map +1 -0
  112. package/lib/esm/charts/utils/build-chart-option.mjs +184 -0
  113. package/lib/esm/charts/utils/build-chart-option.mjs.map +1 -0
  114. package/lib/esm/charts/utils/chart-tooltip-formatter.mjs +159 -0
  115. package/lib/esm/charts/utils/chart-tooltip-formatter.mjs.map +1 -0
  116. package/lib/esm/charts/utils/chart-types.mjs +24 -0
  117. package/lib/esm/charts/utils/chart-types.mjs.map +1 -0
  118. package/lib/esm/charts/utils/defaults.mjs +73 -0
  119. package/lib/esm/charts/utils/defaults.mjs.map +1 -0
  120. package/lib/esm/charts/utils/format-utils.mjs +61 -0
  121. package/lib/esm/charts/utils/format-utils.mjs.map +1 -0
  122. package/lib/esm/charts/utils/legend-layout.mjs +57 -0
  123. package/lib/esm/charts/utils/legend-layout.mjs.map +1 -0
  124. package/lib/esm/charts/utils/legend-utils.mjs +90 -0
  125. package/lib/esm/charts/utils/legend-utils.mjs.map +1 -0
  126. package/lib/esm/charts/utils/scatter-tooltip-points.mjs +215 -0
  127. package/lib/esm/charts/utils/scatter-tooltip-points.mjs.map +1 -0
  128. package/lib/esm/charts/utils/threshold.mjs +92 -0
  129. package/lib/esm/charts/utils/threshold.mjs.map +1 -0
  130. package/lib/esm/charts/utils/user-option-utils.mjs +445 -0
  131. package/lib/esm/charts/utils/user-option-utils.mjs.map +1 -0
  132. package/lib/esm/index.mjs +27 -0
  133. package/lib/esm/index.mjs.map +1 -0
  134. package/package.json +12 -16
  135. package/skills/ndl-react-charts/SKILL.md +2 -2
  136. package/lib/cjs/charts/tests/ChartWrapperWithTooltipFormatter.js +0 -38
  137. package/lib/cjs/charts/tests/ChartWrapperWithTooltipFormatter.js.map +0 -1
  138. package/lib/cjs/charts/tests/ChartZoomHarness.js +0 -113
  139. package/lib/cjs/charts/tests/ChartZoomHarness.js.map +0 -1
  140. package/lib/cjs/charts/tests/HorizontalBarWithVerticalSlider.js +0 -78
  141. package/lib/cjs/charts/tests/HorizontalBarWithVerticalSlider.js.map +0 -1
  142. package/lib/cjs/charts/tests/PieChartWithRerender.js +0 -46
  143. package/lib/cjs/charts/tests/PieChartWithRerender.js.map +0 -1
  144. package/lib/cjs/charts/tests/chart-test-utils.js +0 -527
  145. package/lib/cjs/charts/tests/chart-test-utils.js.map +0 -1
  146. package/lib/esm/charts/Chart.js +0 -114
  147. package/lib/esm/charts/Chart.js.map +0 -1
  148. package/lib/esm/charts/ChartContainer.js +0 -67
  149. package/lib/esm/charts/ChartContainer.js.map +0 -1
  150. package/lib/esm/charts/ChartEmpty.js +0 -33
  151. package/lib/esm/charts/ChartEmpty.js.map +0 -1
  152. package/lib/esm/charts/ChartRender.js +0 -89
  153. package/lib/esm/charts/ChartRender.js.map +0 -1
  154. package/lib/esm/charts/ChartTooltip.js +0 -64
  155. package/lib/esm/charts/ChartTooltip.js.map +0 -1
  156. package/lib/esm/charts/Legend.js +0 -71
  157. package/lib/esm/charts/Legend.js.map +0 -1
  158. package/lib/esm/charts/LegendItem.js +0 -61
  159. package/lib/esm/charts/LegendItem.js.map +0 -1
  160. package/lib/esm/charts/LegendLayout.js +0 -323
  161. package/lib/esm/charts/LegendLayout.js.map +0 -1
  162. package/lib/esm/charts/hooks/use-chart-instance.js +0 -128
  163. package/lib/esm/charts/hooks/use-chart-instance.js.map +0 -1
  164. package/lib/esm/charts/hooks/use-chart-option.js +0 -82
  165. package/lib/esm/charts/hooks/use-chart-option.js.map +0 -1
  166. package/lib/esm/charts/hooks/use-chart-refs.js +0 -48
  167. package/lib/esm/charts/hooks/use-chart-refs.js.map +0 -1
  168. package/lib/esm/charts/hooks/use-chart-zoom.js +0 -129
  169. package/lib/esm/charts/hooks/use-chart-zoom.js.map +0 -1
  170. package/lib/esm/charts/hooks/use-legend-interactions.js +0 -145
  171. package/lib/esm/charts/hooks/use-legend-interactions.js.map +0 -1
  172. package/lib/esm/charts/hooks/use-legend-series.js +0 -184
  173. package/lib/esm/charts/hooks/use-legend-series.js.map +0 -1
  174. package/lib/esm/charts/hooks/use-legend-visibility.js +0 -87
  175. package/lib/esm/charts/hooks/use-legend-visibility.js.map +0 -1
  176. package/lib/esm/charts/index.js.map +0 -1
  177. package/lib/esm/charts/tests/ChartWrapperWithTooltipFormatter.js.map +0 -1
  178. package/lib/esm/charts/tests/ChartZoomHarness.js +0 -109
  179. package/lib/esm/charts/tests/ChartZoomHarness.js.map +0 -1
  180. package/lib/esm/charts/tests/HorizontalBarWithVerticalSlider.js +0 -74
  181. package/lib/esm/charts/tests/HorizontalBarWithVerticalSlider.js.map +0 -1
  182. package/lib/esm/charts/tests/PieChartWithRerender.js +0 -43
  183. package/lib/esm/charts/tests/PieChartWithRerender.js.map +0 -1
  184. package/lib/esm/charts/tests/chart-test-utils.js +0 -500
  185. package/lib/esm/charts/tests/chart-test-utils.js.map +0 -1
  186. package/lib/esm/charts/themes/ndl-echarts-theme.js +0 -172
  187. package/lib/esm/charts/themes/ndl-echarts-theme.js.map +0 -1
  188. package/lib/esm/charts/utils/aria-description.js +0 -228
  189. package/lib/esm/charts/utils/aria-description.js.map +0 -1
  190. package/lib/esm/charts/utils/build-chart-option.js +0 -193
  191. package/lib/esm/charts/utils/build-chart-option.js.map +0 -1
  192. package/lib/esm/charts/utils/chart-tooltip-formatter.js +0 -177
  193. package/lib/esm/charts/utils/chart-tooltip-formatter.js.map +0 -1
  194. package/lib/esm/charts/utils/chart-types.js.map +0 -1
  195. package/lib/esm/charts/utils/defaults.js +0 -73
  196. package/lib/esm/charts/utils/defaults.js.map +0 -1
  197. package/lib/esm/charts/utils/format-utils.js +0 -74
  198. package/lib/esm/charts/utils/format-utils.js.map +0 -1
  199. package/lib/esm/charts/utils/legend-layout.js +0 -59
  200. package/lib/esm/charts/utils/legend-layout.js.map +0 -1
  201. package/lib/esm/charts/utils/legend-utils.js +0 -131
  202. package/lib/esm/charts/utils/legend-utils.js.map +0 -1
  203. package/lib/esm/charts/utils/scatter-tooltip-points.js +0 -291
  204. package/lib/esm/charts/utils/scatter-tooltip-points.js.map +0 -1
  205. package/lib/esm/charts/utils/threshold.js +0 -106
  206. package/lib/esm/charts/utils/threshold.js.map +0 -1
  207. package/lib/esm/charts/utils/user-option-utils.js +0 -374
  208. package/lib/esm/charts/utils/user-option-utils.js.map +0 -1
  209. package/lib/esm/index.js.map +0 -1
@@ -1,363 +1,345 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
17
5
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __rest = (this && this.__rest) || function (s, e) {
36
- var t = {};
37
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
- t[p] = s[p];
39
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
- t[p[i]] = s[p[i]];
43
- }
44
- return t;
45
- };
46
- var __importDefault = (this && this.__importDefault) || function (mod) {
47
- return (mod && mod.__esModule) ? mod : { "default": mod };
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.LegendLayout = void 0;
51
- const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
7
+ const require_charts_utils_legend_layout = require("./utils/legend-layout.js");
8
+ const require_objectSpread2 = require("../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectSpread2.js");
9
+ const require_objectWithoutProperties = require("../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/objectWithoutProperties.js");
10
+ let react = require("react");
11
+ react = require_runtime.__toESM(react);
12
+ let react_jsx_runtime = require("react/jsx-runtime");
13
+ let _neo4j_ndl_react = require("@neo4j-ndl/react");
14
+ let classnames = require("classnames");
15
+ classnames = require_runtime.__toESM(classnames);
16
+ // src/charts/LegendLayout.tsx
52
17
  /*!
53
- *
54
- * Copyright (c) "Neo4j"
55
- * Neo4j Sweden AB [http://neo4j.com]
56
- *
57
- * This file is part of Neo4j.
58
- *
59
- * Neo4j is free software: you can redistribute it and/or modify
60
- * it under the terms of the GNU General Public License as published by
61
- * the Free Software Foundation, either version 3 of the License, or
62
- * (at your option) any later version.
63
- *
64
- * This program is distributed in the hope that it will be useful,
65
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
66
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67
- * GNU General Public License for more details.
68
- *
69
- * You should have received a copy of the GNU General Public License
70
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
71
- */
72
- const react_1 = require("@neo4j-ndl/react");
73
- const classnames_1 = __importDefault(require("classnames"));
74
- const react_2 = __importStar(require("react"));
75
- const legend_layout_1 = require("./utils/legend-layout");
18
+ *
19
+ * Copyright (c) "Neo4j"
20
+ * Neo4j Sweden AB [http://neo4j.com]
21
+ *
22
+ * This file is part of Neo4j.
23
+ *
24
+ * Neo4j is free software: you can redistribute it and/or modify
25
+ * it under the terms of the GNU General Public License as published by
26
+ * the Free Software Foundation, either version 3 of the License, or
27
+ * (at your option) any later version.
28
+ *
29
+ * This program is distributed in the hope that it will be useful,
30
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32
+ * GNU General Public License for more details.
33
+ *
34
+ * You should have received a copy of the GNU General Public License
35
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
36
+ */
37
+ const _excluded = [
38
+ "children",
39
+ "className",
40
+ "isLayoutReady",
41
+ "itemCount",
42
+ "onLayoutReady",
43
+ "htmlAttributes"
44
+ ];
76
45
  const getLegendElementsContentHeight = (legendContent, elements) => {
77
- const legendContentStyle = getComputedStyle(legendContent);
78
- const paddingBottom = parseFloat(legendContentStyle.paddingBottom) || 0;
79
- const elementsBottom = Math.max(...elements.map((element) => element.offsetTop + element.offsetHeight));
80
- return elementsBottom + paddingBottom;
46
+ const legendContentStyle = getComputedStyle(legendContent);
47
+ const paddingBottom = parseFloat(legendContentStyle.paddingBottom) || 0;
48
+ return Math.max(...elements.map((element) => element.offsetTop + element.offsetHeight)) + paddingBottom;
81
49
  };
82
- const getCollapsedLegendContentHeight = ({ availableRowWidth, elements, legendContent, }) => {
83
- const legendContentStyle = getComputedStyle(legendContent);
84
- const paddingTop = parseFloat(legendContentStyle.paddingTop) || 0;
85
- const paddingBottom = parseFloat(legendContentStyle.paddingBottom) || 0;
86
- const rowGap = parseFloat(legendContentStyle.rowGap) || 0;
87
- let currentRowHeight = 0;
88
- let currentRowWidth = 0;
89
- const rowHeights = [];
90
- elements.forEach((element) => {
91
- const elementWidth = (0, legend_layout_1.getComputedElementWidth)(element);
92
- const elementHeight = element.getBoundingClientRect().height;
93
- const shouldWrap = currentRowWidth > 0 && currentRowWidth + elementWidth > availableRowWidth;
94
- if (shouldWrap) {
95
- rowHeights.push(currentRowHeight);
96
- currentRowHeight = 0;
97
- currentRowWidth = 0;
98
- }
99
- currentRowWidth += elementWidth;
100
- currentRowHeight = Math.max(currentRowHeight, elementHeight);
101
- });
102
- if (currentRowHeight > 0) {
103
- rowHeights.push(currentRowHeight);
104
- }
105
- const rowsHeight = rowHeights.reduce((height, rowHeight) => {
106
- return height + rowHeight;
107
- }, 0);
108
- return (paddingTop +
109
- rowsHeight +
110
- rowGap * Math.max(rowHeights.length - 1, 0) +
111
- paddingBottom);
50
+ const getCollapsedLegendContentHeight = ({ availableRowWidth, elements, legendContent }) => {
51
+ const legendContentStyle = getComputedStyle(legendContent);
52
+ const paddingTop = parseFloat(legendContentStyle.paddingTop) || 0;
53
+ const paddingBottom = parseFloat(legendContentStyle.paddingBottom) || 0;
54
+ const rowGap = parseFloat(legendContentStyle.rowGap) || 0;
55
+ let currentRowHeight = 0;
56
+ let currentRowWidth = 0;
57
+ const rowHeights = [];
58
+ elements.forEach((element) => {
59
+ const elementWidth = require_charts_utils_legend_layout.getComputedElementWidth(element);
60
+ const elementHeight = element.getBoundingClientRect().height;
61
+ if (currentRowWidth > 0 && currentRowWidth + elementWidth > availableRowWidth) {
62
+ rowHeights.push(currentRowHeight);
63
+ currentRowHeight = 0;
64
+ currentRowWidth = 0;
65
+ }
66
+ currentRowWidth += elementWidth;
67
+ currentRowHeight = Math.max(currentRowHeight, elementHeight);
68
+ });
69
+ if (currentRowHeight > 0) rowHeights.push(currentRowHeight);
70
+ return paddingTop + rowHeights.reduce((height, rowHeight) => {
71
+ return height + rowHeight;
72
+ }, 0) + rowGap * Math.max(rowHeights.length - 1, 0) + paddingBottom;
112
73
  };
113
74
  /**
114
- * Tracks legend container width for responsive collapsed-layout recalculation.
115
- *
116
- * The width is kept in state so `useCollapsibleLegendLayout` can re-measure item
117
- * wrapping whenever the available legend width changes.
118
- */
75
+ * Tracks legend container width for responsive collapsed-layout recalculation.
76
+ *
77
+ * The width is kept in state so `useCollapsibleLegendLayout` can re-measure item
78
+ * wrapping whenever the available legend width changes.
79
+ */
119
80
  const useLegendContainerWidth = (legendContainerRef) => {
120
- const [legendWidth, setLegendWidth] = (0, react_2.useState)(Infinity);
121
- const updateLegendWidth = (0, react_2.useCallback)(() => {
122
- var _a;
123
- const nextWidth = (_a = legendContainerRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth;
124
- if (nextWidth === undefined) {
125
- return;
126
- }
127
- setLegendWidth(nextWidth);
128
- }, [legendContainerRef]);
129
- (0, react_2.useEffect)(() => {
130
- updateLegendWidth();
131
- const legendContainer = legendContainerRef.current;
132
- if (!legendContainer) {
133
- return;
134
- }
135
- const resizeObserver = new ResizeObserver(updateLegendWidth);
136
- resizeObserver.observe(legendContainer);
137
- return () => {
138
- resizeObserver.disconnect();
139
- };
140
- }, [legendContainerRef, updateLegendWidth]);
141
- return legendWidth;
81
+ const [legendWidth, setLegendWidth] = (0, react.useState)(Infinity);
82
+ const updateLegendWidth = (0, react.useCallback)(() => {
83
+ var _legendContainerRef$c;
84
+ const nextWidth = (_legendContainerRef$c = legendContainerRef.current) === null || _legendContainerRef$c === void 0 ? void 0 : _legendContainerRef$c.clientWidth;
85
+ if (nextWidth === void 0) return;
86
+ setLegendWidth(nextWidth);
87
+ }, [legendContainerRef]);
88
+ (0, react.useEffect)(() => {
89
+ updateLegendWidth();
90
+ const legendContainer = legendContainerRef.current;
91
+ if (!legendContainer) return;
92
+ const resizeObserver = new ResizeObserver(updateLegendWidth);
93
+ resizeObserver.observe(legendContainer);
94
+ return () => {
95
+ resizeObserver.disconnect();
96
+ };
97
+ }, [legendContainerRef, updateLegendWidth]);
98
+ return legendWidth;
142
99
  };
143
100
  /**
144
- * Owns the collapsed, measuring, and expanded layout state for wrapping legends.
145
- *
146
- * Collapsed legends only render the visible subset of items. When the item count
147
- * or container width changes, the hook temporarily renders every item in an
148
- * invisible measuring pass so it can calculate wrapping, overflow, and the next
149
- * visible item count. The last collapsed height is preserved during that pass so
150
- * the chart area does not shrink while the hidden full legend is being measured.
151
- */
152
- const useCollapsibleLegendLayout = ({ itemCount, legendContainerRef, legendContentRef, legendMeasurementRef, viewMoreButtonMeasurementRef, }) => {
153
- const [isExpanded, setIsExpanded] = (0, react_2.useState)(false);
154
- const [isMeasuring, setIsMeasuring] = (0, react_2.useState)(false);
155
- const [layoutSnapshot, setLayoutSnapshot] = (0, react_2.useState)({
156
- contentHeight: 0,
157
- hasOverflow: false,
158
- visibleItemCount: itemCount,
159
- });
160
- const skipNextCollapseMeasurementRef = (0, react_2.useRef)(false);
161
- const legendWidth = useLegendContainerWidth(legendContainerRef);
162
- const updateVisibleItems = (0, react_2.useCallback)(() => {
163
- var _a;
164
- const legendContent = legendMeasurementRef.current;
165
- const viewMoreButton = viewMoreButtonMeasurementRef.current;
166
- if (!legendContent || !viewMoreButton) {
167
- setIsMeasuring(false);
168
- return;
169
- }
170
- const legendItems = Array.from(legendContent.querySelectorAll('.ndl-chart-legend-item')).filter((element) => element.offsetParent !== null);
171
- if (legendItems.length === 0) {
172
- setLayoutSnapshot((snapshot) => (Object.assign(Object.assign({}, snapshot), { contentHeight: 0, hasOverflow: false, visibleItemCount: itemCount })));
173
- setIsMeasuring(false);
174
- return;
175
- }
176
- const rowTops = Array.from(new Set(legendItems.map((element) => element.offsetTop))).sort((left, right) => left - right);
177
- const nextLegendContentHeight = legendContent.scrollHeight;
178
- const nextLegendItemsContentHeight = getLegendElementsContentHeight(legendContent, legendItems);
179
- if (rowTops.length <= legend_layout_1.COLLAPSED_LEGEND_ROWS) {
180
- setLayoutSnapshot((snapshot) => (Object.assign(Object.assign({}, snapshot), { contentHeight: nextLegendItemsContentHeight, hasOverflow: false, visibleItemCount: itemCount })));
181
- setIsMeasuring(false);
182
- return;
183
- }
184
- const legendContainer = legendContainerRef.current;
185
- const legendContentStyle = getComputedStyle(legendContent);
186
- const availableRowWidth = ((_a = legendContainer === null || legendContainer === void 0 ? void 0 : legendContainer.clientWidth) !== null && _a !== void 0 ? _a : legendContent.clientWidth) -
187
- (parseFloat(legendContentStyle.paddingLeft) || 0) -
188
- (parseFloat(legendContentStyle.paddingRight) || 0);
189
- const viewMoreButtonWidth = (0, legend_layout_1.getComputedElementWidth)(viewMoreButton);
190
- const legendItemWidths = legendItems.map(legend_layout_1.getComputedElementWidth);
191
- const nextVisibleItemCount = (0, legend_layout_1.getCollapsedVisibleItemCount)(legendItemWidths, availableRowWidth, viewMoreButtonWidth);
192
- const nextCollapsedContentHeight = getCollapsedLegendContentHeight({
193
- availableRowWidth,
194
- elements: [...legendItems.slice(0, nextVisibleItemCount), viewMoreButton],
195
- legendContent,
196
- });
197
- setLayoutSnapshot((snapshot) => (Object.assign(Object.assign({}, snapshot), { collapsedHeight: Math.min(nextCollapsedContentHeight, legend_layout_1.COLLAPSED_LEGEND_MAX_HEIGHT), contentHeight: nextLegendContentHeight, hasOverflow: nextVisibleItemCount < itemCount, visibleItemCount: nextVisibleItemCount })));
198
- setIsMeasuring(false);
199
- }, [
200
- itemCount,
201
- legendContainerRef,
202
- legendMeasurementRef,
203
- viewMoreButtonMeasurementRef,
204
- ]);
205
- (0, react_2.useEffect)(() => {
206
- setIsExpanded(false);
207
- }, [itemCount]);
208
- (0, react_2.useEffect)(() => {
209
- if (isExpanded) {
210
- setIsMeasuring(false);
211
- return;
212
- }
213
- if (skipNextCollapseMeasurementRef.current) {
214
- skipNextCollapseMeasurementRef.current = false;
215
- setIsMeasuring(false);
216
- return;
217
- }
218
- setIsMeasuring(true);
219
- }, [isExpanded, itemCount, legendWidth]);
220
- (0, react_2.useEffect)(() => {
221
- const isMeasuringCollapsed = !isExpanded && isMeasuring;
222
- const animationFrame = requestAnimationFrame(() => {
223
- if (isMeasuringCollapsed) {
224
- updateVisibleItems();
225
- }
226
- else {
227
- setLayoutSnapshot((snapshot) => {
228
- var _a, _b;
229
- return (Object.assign(Object.assign({}, snapshot), { contentHeight: (_b = (_a = legendContentRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight) !== null && _b !== void 0 ? _b : 0 }));
230
- });
231
- if (!isMeasuring && !isExpanded && layoutSnapshot.hasOverflow) {
232
- setLayoutSnapshot((snapshot) => {
233
- var _a;
234
- return (Object.assign(Object.assign({}, snapshot), { collapsedHeight: (_a = legendContentRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().height }));
235
- });
236
- }
237
- }
238
- });
239
- return () => {
240
- cancelAnimationFrame(animationFrame);
241
- };
242
- }, [
243
- isExpanded,
244
- isMeasuring,
245
- legendContentRef,
246
- layoutSnapshot.hasOverflow,
247
- updateVisibleItems,
248
- ]);
249
- const expandLegend = (0, react_2.useCallback)(() => {
250
- setIsMeasuring(false);
251
- setIsExpanded(true);
252
- }, []);
253
- const collapseLegend = (0, react_2.useCallback)(() => {
254
- skipNextCollapseMeasurementRef.current = true;
255
- setIsExpanded(false);
256
- }, []);
257
- return {
258
- collapseLegend,
259
- expandLegend,
260
- isExpanded,
261
- isMeasuring,
262
- layoutSnapshot,
263
- };
101
+ * Owns the collapsed, measuring, and expanded layout state for wrapping legends.
102
+ *
103
+ * Collapsed legends only render the visible subset of items. When the item count
104
+ * or container width changes, the hook temporarily renders every item in an
105
+ * invisible measuring pass so it can calculate wrapping, overflow, and the next
106
+ * visible item count. The last collapsed height is preserved during that pass so
107
+ * the chart area does not shrink while the hidden full legend is being measured.
108
+ */
109
+ const useCollapsibleLegendLayout = ({ itemCount, legendContainerRef, legendContentRef, legendMeasurementRef, viewMoreButtonMeasurementRef }) => {
110
+ const [isExpanded, setIsExpanded] = (0, react.useState)(false);
111
+ const [isMeasuring, setIsMeasuring] = (0, react.useState)(false);
112
+ const [layoutSnapshot, setLayoutSnapshot] = (0, react.useState)({
113
+ contentHeight: 0,
114
+ hasOverflow: false,
115
+ visibleItemCount: itemCount
116
+ });
117
+ const skipNextCollapseMeasurementRef = (0, react.useRef)(false);
118
+ const legendWidth = useLegendContainerWidth(legendContainerRef);
119
+ const updateVisibleItems = (0, react.useCallback)(() => {
120
+ var _legendContainer$clie;
121
+ const legendContent = legendMeasurementRef.current;
122
+ const viewMoreButton = viewMoreButtonMeasurementRef.current;
123
+ if (!legendContent || !viewMoreButton) {
124
+ setIsMeasuring(false);
125
+ return;
126
+ }
127
+ const legendItems = Array.from(legendContent.querySelectorAll(".ndl-chart-legend-item")).filter((element) => element.offsetParent !== null);
128
+ if (legendItems.length === 0) {
129
+ setLayoutSnapshot((snapshot) => require_objectSpread2.default(require_objectSpread2.default({}, snapshot), {}, {
130
+ contentHeight: 0,
131
+ hasOverflow: false,
132
+ visibleItemCount: itemCount
133
+ }));
134
+ setIsMeasuring(false);
135
+ return;
136
+ }
137
+ const rowTops = Array.from(new Set(legendItems.map((element) => element.offsetTop))).sort((left, right) => left - right);
138
+ const nextLegendContentHeight = legendContent.scrollHeight;
139
+ const nextLegendItemsContentHeight = getLegendElementsContentHeight(legendContent, legendItems);
140
+ if (rowTops.length <= 2) {
141
+ setLayoutSnapshot((snapshot) => require_objectSpread2.default(require_objectSpread2.default({}, snapshot), {}, {
142
+ contentHeight: nextLegendItemsContentHeight,
143
+ hasOverflow: false,
144
+ visibleItemCount: itemCount
145
+ }));
146
+ setIsMeasuring(false);
147
+ return;
148
+ }
149
+ const legendContainer = legendContainerRef.current;
150
+ const legendContentStyle = getComputedStyle(legendContent);
151
+ const availableRowWidth = ((_legendContainer$clie = legendContainer === null || legendContainer === void 0 ? void 0 : legendContainer.clientWidth) !== null && _legendContainer$clie !== void 0 ? _legendContainer$clie : legendContent.clientWidth) - (parseFloat(legendContentStyle.paddingLeft) || 0) - (parseFloat(legendContentStyle.paddingRight) || 0);
152
+ const viewMoreButtonWidth = require_charts_utils_legend_layout.getComputedElementWidth(viewMoreButton);
153
+ const legendItemWidths = legendItems.map(require_charts_utils_legend_layout.getComputedElementWidth);
154
+ const nextVisibleItemCount = require_charts_utils_legend_layout.getCollapsedVisibleItemCount(legendItemWidths, availableRowWidth, viewMoreButtonWidth);
155
+ const nextCollapsedContentHeight = getCollapsedLegendContentHeight({
156
+ availableRowWidth,
157
+ elements: [...legendItems.slice(0, nextVisibleItemCount), viewMoreButton],
158
+ legendContent
159
+ });
160
+ setLayoutSnapshot((snapshot) => require_objectSpread2.default(require_objectSpread2.default({}, snapshot), {}, {
161
+ collapsedHeight: Math.min(nextCollapsedContentHeight, 64),
162
+ contentHeight: nextLegendContentHeight,
163
+ hasOverflow: nextVisibleItemCount < itemCount,
164
+ visibleItemCount: nextVisibleItemCount
165
+ }));
166
+ setIsMeasuring(false);
167
+ }, [
168
+ itemCount,
169
+ legendContainerRef,
170
+ legendMeasurementRef,
171
+ viewMoreButtonMeasurementRef
172
+ ]);
173
+ (0, react.useEffect)(() => {
174
+ setIsExpanded(false);
175
+ }, [itemCount]);
176
+ (0, react.useEffect)(() => {
177
+ if (isExpanded) {
178
+ setIsMeasuring(false);
179
+ return;
180
+ }
181
+ if (skipNextCollapseMeasurementRef.current) {
182
+ skipNextCollapseMeasurementRef.current = false;
183
+ setIsMeasuring(false);
184
+ return;
185
+ }
186
+ setIsMeasuring(true);
187
+ }, [
188
+ isExpanded,
189
+ itemCount,
190
+ legendWidth
191
+ ]);
192
+ (0, react.useEffect)(() => {
193
+ const isMeasuringCollapsed = !isExpanded && isMeasuring;
194
+ const animationFrame = requestAnimationFrame(() => {
195
+ if (isMeasuringCollapsed) updateVisibleItems();
196
+ else {
197
+ setLayoutSnapshot((snapshot) => {
198
+ var _legendContentRef$cur, _legendContentRef$cur2;
199
+ return require_objectSpread2.default(require_objectSpread2.default({}, snapshot), {}, { contentHeight: (_legendContentRef$cur = (_legendContentRef$cur2 = legendContentRef.current) === null || _legendContentRef$cur2 === void 0 ? void 0 : _legendContentRef$cur2.scrollHeight) !== null && _legendContentRef$cur !== void 0 ? _legendContentRef$cur : 0 });
200
+ });
201
+ if (!isMeasuring && !isExpanded && layoutSnapshot.hasOverflow) setLayoutSnapshot((snapshot) => {
202
+ var _legendContentRef$cur3;
203
+ return require_objectSpread2.default(require_objectSpread2.default({}, snapshot), {}, { collapsedHeight: (_legendContentRef$cur3 = legendContentRef.current) === null || _legendContentRef$cur3 === void 0 ? void 0 : _legendContentRef$cur3.getBoundingClientRect().height });
204
+ });
205
+ }
206
+ });
207
+ return () => {
208
+ cancelAnimationFrame(animationFrame);
209
+ };
210
+ }, [
211
+ isExpanded,
212
+ isMeasuring,
213
+ legendContentRef,
214
+ layoutSnapshot.hasOverflow,
215
+ updateVisibleItems
216
+ ]);
217
+ const expandLegend = (0, react.useCallback)(() => {
218
+ setIsMeasuring(false);
219
+ setIsExpanded(true);
220
+ }, []);
221
+ return {
222
+ collapseLegend: (0, react.useCallback)(() => {
223
+ skipNextCollapseMeasurementRef.current = true;
224
+ setIsExpanded(false);
225
+ }, []),
226
+ expandLegend,
227
+ isExpanded,
228
+ isMeasuring,
229
+ layoutSnapshot
230
+ };
264
231
  };
265
232
  /**
266
- * Renders the responsive legend layout shell.
267
- *
268
- * The component switches between a two-row collapsed view, an invisible
269
- * measurement view, and an expanded scrollable view while keeping the
270
- * "View more"/"View less" action wired to the measured overflow state.
271
- */
272
- const LegendLayout = (_a) => {
273
- var { children, className, isLayoutReady = true, itemCount, onLayoutReady, htmlAttributes } = _a, restProps = __rest(_a, ["children", "className", "isLayoutReady", "itemCount", "onLayoutReady", "htmlAttributes"]);
274
- const legendContainerRef = (0, react_2.useRef)(null);
275
- const legendContentRef = (0, react_2.useRef)(null);
276
- const legendMeasurementRef = (0, react_2.useRef)(null);
277
- const pendingFocusLegendItemIndexRef = (0, react_2.useRef)(null);
278
- const viewMoreButtonMeasurementRef = (0, react_2.useRef)(null);
279
- const { collapseLegend, expandLegend, isExpanded, isMeasuring, layoutSnapshot, } = useCollapsibleLegendLayout({
280
- itemCount,
281
- legendContainerRef,
282
- legendContentRef,
283
- legendMeasurementRef,
284
- viewMoreButtonMeasurementRef,
285
- });
286
- const childList = react_2.default.Children.toArray(children);
287
- const childrenToRender = !isExpanded
288
- ? childList.slice(0, layoutSnapshot.visibleItemCount)
289
- : childList;
290
- const legendHeight = !isMeasuring && !isExpanded && layoutSnapshot.hasOverflow
291
- ? layoutSnapshot.collapsedHeight
292
- : !isMeasuring &&
293
- !layoutSnapshot.hasOverflow &&
294
- layoutSnapshot.contentHeight
295
- ? layoutSnapshot.contentHeight
296
- : undefined;
297
- (0, react_2.useEffect)(() => {
298
- if (!isMeasuring && layoutSnapshot.contentHeight > 0) {
299
- let secondFrame;
300
- const firstFrame = requestAnimationFrame(() => {
301
- secondFrame = requestAnimationFrame(() => {
302
- onLayoutReady === null || onLayoutReady === void 0 ? void 0 : onLayoutReady();
303
- });
304
- });
305
- return () => {
306
- cancelAnimationFrame(firstFrame);
307
- if (secondFrame !== undefined) {
308
- cancelAnimationFrame(secondFrame);
309
- }
310
- };
311
- }
312
- }, [isMeasuring, layoutSnapshot.contentHeight, onLayoutReady]);
313
- (0, react_2.useEffect)(() => {
314
- var _a, _b;
315
- const pendingFocusLegendItemIndex = pendingFocusLegendItemIndexRef.current;
316
- if (!isExpanded || pendingFocusLegendItemIndex === null) {
317
- return;
318
- }
319
- const legendItems = (_a = legendContentRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.ndl-chart-legend-item');
320
- (_b = legendItems === null || legendItems === void 0 ? void 0 : legendItems[pendingFocusLegendItemIndex]) === null || _b === void 0 ? void 0 : _b.focus();
321
- pendingFocusLegendItemIndexRef.current = null;
322
- }, [isExpanded]);
323
- const handleLegendActionClick = (0, react_2.useCallback)(() => {
324
- if (isExpanded) {
325
- collapseLegend();
326
- return;
327
- }
328
- pendingFocusLegendItemIndexRef.current = layoutSnapshot.visibleItemCount;
329
- expandLegend();
330
- }, [
331
- collapseLegend,
332
- expandLegend,
333
- isExpanded,
334
- layoutSnapshot.visibleItemCount,
335
- ]);
336
- const classes = (0, classnames_1.default)('ndl-chart-legend', {
337
- 'ndl-chart-legend-calculating': !isExpanded && isMeasuring,
338
- 'ndl-chart-legend-collapsed': layoutSnapshot.hasOverflow && !isExpanded,
339
- 'ndl-chart-legend-expanded': layoutSnapshot.hasOverflow && isExpanded,
340
- 'ndl-chart-legend-hidden': !isLayoutReady,
341
- 'ndl-chart-legend-scrollable': layoutSnapshot.hasOverflow &&
342
- isExpanded &&
343
- layoutSnapshot.contentHeight > legend_layout_1.COLLAPSED_LEGEND_MAX_HEIGHT,
344
- 'ndl-chart-legend-wrapping': true,
345
- }, className);
346
- return ((0, jsx_runtime_1.jsx)("div", Object.assign({ ref: legendContainerRef, className: "ndl-chart-legend-container" }, restProps, htmlAttributes, { children: (0, jsx_runtime_1.jsxs)("div", { className: classes, ref: legendContentRef, style: {
347
- height: legendHeight,
348
- maxHeight: layoutSnapshot.hasOverflow && isExpanded
349
- ? 'var(--ndl-chart-legend-expanded-max-height)'
350
- : layoutSnapshot.hasOverflow
351
- ? legend_layout_1.COLLAPSED_LEGEND_MAX_HEIGHT
352
- : undefined,
353
- }, children: [childrenToRender, layoutSnapshot.hasOverflow && ((0, jsx_runtime_1.jsx)(react_1.TextLink, { as: "button", className: "ndl-chart-legend-action", htmlAttributes: {
354
- 'aria-expanded': isExpanded,
355
- onClick: handleLegendActionClick,
356
- type: 'button',
357
- }, children: isExpanded ? 'View less' : 'View more' })), isMeasuring && ((0, jsx_runtime_1.jsxs)("div", { "aria-hidden": "true", className: "ndl-chart-legend-measurement", ref: legendMeasurementRef, children: [childList, (0, jsx_runtime_1.jsx)(react_1.TextLink, { as: "button", ref: viewMoreButtonMeasurementRef, className: "ndl-chart-legend-action", htmlAttributes: {
358
- tabIndex: -1,
359
- type: 'button',
360
- }, children: "View more" })] }))] }) })));
233
+ * Renders the responsive legend layout shell.
234
+ *
235
+ * The component switches between a two-row collapsed view, an invisible
236
+ * measurement view, and an expanded scrollable view while keeping the
237
+ * "View more"/"View less" action wired to the measured overflow state.
238
+ */
239
+ const LegendLayout = (_ref) => {
240
+ let { children, className, isLayoutReady = true, itemCount, onLayoutReady, htmlAttributes } = _ref, restProps = require_objectWithoutProperties.default(_ref, _excluded);
241
+ const legendContainerRef = (0, react.useRef)(null);
242
+ const legendContentRef = (0, react.useRef)(null);
243
+ const legendMeasurementRef = (0, react.useRef)(null);
244
+ const pendingFocusLegendItemIndexRef = (0, react.useRef)(null);
245
+ const viewMoreButtonMeasurementRef = (0, react.useRef)(null);
246
+ const { collapseLegend, expandLegend, isExpanded, isMeasuring, layoutSnapshot } = useCollapsibleLegendLayout({
247
+ itemCount,
248
+ legendContainerRef,
249
+ legendContentRef,
250
+ legendMeasurementRef,
251
+ viewMoreButtonMeasurementRef
252
+ });
253
+ const childList = react.default.Children.toArray(children);
254
+ const childrenToRender = !isExpanded ? childList.slice(0, layoutSnapshot.visibleItemCount) : childList;
255
+ const legendHeight = !isMeasuring && !isExpanded && layoutSnapshot.hasOverflow ? layoutSnapshot.collapsedHeight : !isMeasuring && !layoutSnapshot.hasOverflow && layoutSnapshot.contentHeight ? layoutSnapshot.contentHeight : void 0;
256
+ (0, react.useEffect)(() => {
257
+ if (!isMeasuring && layoutSnapshot.contentHeight > 0) {
258
+ let secondFrame;
259
+ const firstFrame = requestAnimationFrame(() => {
260
+ secondFrame = requestAnimationFrame(() => {
261
+ onLayoutReady === null || onLayoutReady === void 0 || onLayoutReady();
262
+ });
263
+ });
264
+ return () => {
265
+ cancelAnimationFrame(firstFrame);
266
+ if (secondFrame !== void 0) cancelAnimationFrame(secondFrame);
267
+ };
268
+ }
269
+ }, [
270
+ isMeasuring,
271
+ layoutSnapshot.contentHeight,
272
+ onLayoutReady
273
+ ]);
274
+ (0, react.useEffect)(() => {
275
+ var _legendContentRef$cur4, _legendItems$pendingF;
276
+ const pendingFocusLegendItemIndex = pendingFocusLegendItemIndexRef.current;
277
+ if (!isExpanded || pendingFocusLegendItemIndex === null) return;
278
+ const legendItems = (_legendContentRef$cur4 = legendContentRef.current) === null || _legendContentRef$cur4 === void 0 ? void 0 : _legendContentRef$cur4.querySelectorAll(".ndl-chart-legend-item");
279
+ legendItems === null || legendItems === void 0 || (_legendItems$pendingF = legendItems[pendingFocusLegendItemIndex]) === null || _legendItems$pendingF === void 0 || _legendItems$pendingF.focus();
280
+ pendingFocusLegendItemIndexRef.current = null;
281
+ }, [isExpanded]);
282
+ const handleLegendActionClick = (0, react.useCallback)(() => {
283
+ if (isExpanded) {
284
+ collapseLegend();
285
+ return;
286
+ }
287
+ pendingFocusLegendItemIndexRef.current = layoutSnapshot.visibleItemCount;
288
+ expandLegend();
289
+ }, [
290
+ collapseLegend,
291
+ expandLegend,
292
+ isExpanded,
293
+ layoutSnapshot.visibleItemCount
294
+ ]);
295
+ const classes = (0, classnames.default)("ndl-chart-legend", {
296
+ "ndl-chart-legend-calculating": !isExpanded && isMeasuring,
297
+ "ndl-chart-legend-collapsed": layoutSnapshot.hasOverflow && !isExpanded,
298
+ "ndl-chart-legend-expanded": layoutSnapshot.hasOverflow && isExpanded,
299
+ "ndl-chart-legend-hidden": !isLayoutReady,
300
+ "ndl-chart-legend-scrollable": layoutSnapshot.hasOverflow && isExpanded && layoutSnapshot.contentHeight > 64,
301
+ "ndl-chart-legend-wrapping": true
302
+ }, className);
303
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", require_objectSpread2.default(require_objectSpread2.default(require_objectSpread2.default({
304
+ ref: legendContainerRef,
305
+ className: "ndl-chart-legend-container"
306
+ }, restProps), htmlAttributes), {}, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
307
+ className: classes,
308
+ ref: legendContentRef,
309
+ style: {
310
+ height: legendHeight,
311
+ maxHeight: layoutSnapshot.hasOverflow && isExpanded ? "var(--ndl-chart-legend-expanded-max-height)" : layoutSnapshot.hasOverflow ? 64 : void 0
312
+ },
313
+ children: [
314
+ childrenToRender,
315
+ layoutSnapshot.hasOverflow && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_neo4j_ndl_react.TextLink, {
316
+ as: "button",
317
+ className: "ndl-chart-legend-action",
318
+ htmlAttributes: {
319
+ "aria-expanded": isExpanded,
320
+ onClick: handleLegendActionClick,
321
+ type: "button"
322
+ },
323
+ children: isExpanded ? "View less" : "View more"
324
+ }),
325
+ isMeasuring && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
326
+ "aria-hidden": "true",
327
+ className: "ndl-chart-legend-measurement",
328
+ ref: legendMeasurementRef,
329
+ children: [childList, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_neo4j_ndl_react.TextLink, {
330
+ as: "button",
331
+ ref: viewMoreButtonMeasurementRef,
332
+ className: "ndl-chart-legend-action",
333
+ htmlAttributes: {
334
+ tabIndex: -1,
335
+ type: "button"
336
+ },
337
+ children: "View more"
338
+ })]
339
+ })
340
+ ]
341
+ }) }));
361
342
  };
362
343
  exports.LegendLayout = LegendLayout;
344
+
363
345
  //# sourceMappingURL=LegendLayout.js.map