@gravity-ui/charts 1.42.3 → 1.43.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 (127) hide show
  1. package/dist/cjs/components/AxisX/AxisX.js +31 -4
  2. package/dist/cjs/components/AxisX/prepare-axis-data.js +58 -13
  3. package/dist/cjs/components/AxisX/types.d.ts +18 -1
  4. package/dist/cjs/components/AxisY/AxisY.js +31 -4
  5. package/dist/cjs/components/AxisY/prepare-axis-data.js +68 -21
  6. package/dist/cjs/components/AxisY/prepare-axis-title.js +8 -3
  7. package/dist/cjs/components/AxisY/styles.css +1 -1
  8. package/dist/cjs/components/AxisY/types.d.ts +18 -1
  9. package/dist/cjs/components/ChartInner/index.js +21 -15
  10. package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +6 -5
  11. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +3 -2
  12. package/dist/cjs/components/ChartInner/useChartInnerProps.js +22 -11
  13. package/dist/cjs/components/ChartInner/useDefaultState.js +4 -3
  14. package/dist/cjs/components/ChartInner/utils/chart.js +1 -1
  15. package/dist/cjs/components/ChartInner/utils/normalized-original-data.d.ts +1 -0
  16. package/dist/cjs/components/ChartInner/utils/title.d.ts +3 -2
  17. package/dist/cjs/components/ChartInner/utils/title.js +69 -11
  18. package/dist/cjs/components/Legend/index.js +8 -11
  19. package/dist/cjs/components/Legend/styles.css +1 -1
  20. package/dist/cjs/components/Title/index.js +3 -5
  21. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +2 -1
  22. package/dist/cjs/components/Tooltip/ChartTooltipContent.js +3 -2
  23. package/dist/cjs/components/Tooltip/index.js +2 -2
  24. package/dist/cjs/components/utils/axis-title.js +1 -1
  25. package/dist/cjs/core/axes/types.d.ts +26 -9
  26. package/dist/cjs/core/axes/x-axis.js +16 -3
  27. package/dist/cjs/core/axes/y-axis.js +21 -8
  28. package/dist/cjs/core/constants/defaults/axis.d.ts +1 -0
  29. package/dist/cjs/core/constants/defaults/axis.js +1 -0
  30. package/dist/cjs/core/layout/split.d.ts +2 -2
  31. package/dist/cjs/core/layout/split.js +22 -19
  32. package/dist/cjs/core/scales/y-scale.js +37 -13
  33. package/dist/cjs/core/series/prepare-legend.js +7 -7
  34. package/dist/cjs/core/series/types.d.ts +2 -0
  35. package/dist/cjs/core/types/chart/axis.d.ts +43 -1
  36. package/dist/cjs/core/types/chart/title.d.ts +10 -0
  37. package/dist/cjs/core/types/chart/tooltip.d.ts +3 -1
  38. package/dist/cjs/core/utils/axis-generators/bottom.js +6 -16
  39. package/dist/cjs/core/utils/common.d.ts +0 -4
  40. package/dist/cjs/core/utils/common.js +1 -14
  41. package/dist/cjs/core/utils/get-hovered-plots.d.ts +3 -2
  42. package/dist/cjs/core/utils/get-hovered-plots.js +28 -4
  43. package/dist/cjs/core/utils/labels.d.ts +1 -0
  44. package/dist/cjs/core/utils/labels.js +5 -5
  45. package/dist/cjs/core/utils/text.d.ts +1 -0
  46. package/dist/cjs/core/utils/text.js +16 -2
  47. package/dist/cjs/hooks/types.d.ts +5 -2
  48. package/dist/cjs/hooks/useShapes/area/prepare-data.js +12 -7
  49. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +12 -4
  50. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +3 -2
  51. package/dist/cjs/hooks/useShapes/funnel/prepare-data.js +4 -1
  52. package/dist/cjs/hooks/useShapes/heatmap/prepare-data.js +1 -1
  53. package/dist/cjs/hooks/useShapes/line/prepare-data.js +4 -1
  54. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +9 -2
  55. package/dist/cjs/hooks/useShapes/radar/prepare-data.js +17 -7
  56. package/dist/cjs/hooks/useShapes/sankey/prepare-data.js +1 -1
  57. package/dist/cjs/hooks/useShapes/sankey/sankey-layout.d.ts +49 -0
  58. package/dist/cjs/hooks/useShapes/sankey/sankey-layout.js +362 -0
  59. package/dist/cjs/hooks/useShapes/styles.css +4 -4
  60. package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +3 -1
  61. package/dist/cjs/hooks/useTooltip/index.d.ts +3 -2
  62. package/dist/cjs/hooks/useTooltip/index.js +5 -3
  63. package/dist/cjs/types/chart-ui.d.ts +1 -0
  64. package/dist/esm/components/AxisX/AxisX.js +31 -4
  65. package/dist/esm/components/AxisX/prepare-axis-data.js +58 -13
  66. package/dist/esm/components/AxisX/types.d.ts +18 -1
  67. package/dist/esm/components/AxisY/AxisY.js +31 -4
  68. package/dist/esm/components/AxisY/prepare-axis-data.js +68 -21
  69. package/dist/esm/components/AxisY/prepare-axis-title.js +8 -3
  70. package/dist/esm/components/AxisY/styles.css +1 -1
  71. package/dist/esm/components/AxisY/types.d.ts +18 -1
  72. package/dist/esm/components/ChartInner/index.js +21 -15
  73. package/dist/esm/components/ChartInner/useChartInnerHandlers.js +6 -5
  74. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +3 -2
  75. package/dist/esm/components/ChartInner/useChartInnerProps.js +22 -11
  76. package/dist/esm/components/ChartInner/useDefaultState.js +4 -3
  77. package/dist/esm/components/ChartInner/utils/chart.js +1 -1
  78. package/dist/esm/components/ChartInner/utils/normalized-original-data.d.ts +1 -0
  79. package/dist/esm/components/ChartInner/utils/title.d.ts +3 -2
  80. package/dist/esm/components/ChartInner/utils/title.js +69 -11
  81. package/dist/esm/components/Legend/index.js +8 -11
  82. package/dist/esm/components/Legend/styles.css +1 -1
  83. package/dist/esm/components/Title/index.js +3 -5
  84. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +2 -1
  85. package/dist/esm/components/Tooltip/ChartTooltipContent.js +3 -2
  86. package/dist/esm/components/Tooltip/index.js +2 -2
  87. package/dist/esm/components/utils/axis-title.js +1 -1
  88. package/dist/esm/core/axes/types.d.ts +26 -9
  89. package/dist/esm/core/axes/x-axis.js +16 -3
  90. package/dist/esm/core/axes/y-axis.js +21 -8
  91. package/dist/esm/core/constants/defaults/axis.d.ts +1 -0
  92. package/dist/esm/core/constants/defaults/axis.js +1 -0
  93. package/dist/esm/core/layout/split.d.ts +2 -2
  94. package/dist/esm/core/layout/split.js +22 -19
  95. package/dist/esm/core/scales/y-scale.js +37 -13
  96. package/dist/esm/core/series/prepare-legend.js +7 -7
  97. package/dist/esm/core/series/types.d.ts +2 -0
  98. package/dist/esm/core/types/chart/axis.d.ts +43 -1
  99. package/dist/esm/core/types/chart/title.d.ts +10 -0
  100. package/dist/esm/core/types/chart/tooltip.d.ts +3 -1
  101. package/dist/esm/core/utils/axis-generators/bottom.js +6 -16
  102. package/dist/esm/core/utils/common.d.ts +0 -4
  103. package/dist/esm/core/utils/common.js +1 -14
  104. package/dist/esm/core/utils/get-hovered-plots.d.ts +3 -2
  105. package/dist/esm/core/utils/get-hovered-plots.js +28 -4
  106. package/dist/esm/core/utils/labels.d.ts +1 -0
  107. package/dist/esm/core/utils/labels.js +5 -5
  108. package/dist/esm/core/utils/text.d.ts +1 -0
  109. package/dist/esm/core/utils/text.js +16 -2
  110. package/dist/esm/hooks/types.d.ts +5 -2
  111. package/dist/esm/hooks/useShapes/area/prepare-data.js +12 -7
  112. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +12 -4
  113. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +3 -2
  114. package/dist/esm/hooks/useShapes/funnel/prepare-data.js +4 -1
  115. package/dist/esm/hooks/useShapes/heatmap/prepare-data.js +1 -1
  116. package/dist/esm/hooks/useShapes/line/prepare-data.js +4 -1
  117. package/dist/esm/hooks/useShapes/pie/prepare-data.js +9 -2
  118. package/dist/esm/hooks/useShapes/radar/prepare-data.js +17 -7
  119. package/dist/esm/hooks/useShapes/sankey/prepare-data.js +1 -1
  120. package/dist/esm/hooks/useShapes/sankey/sankey-layout.d.ts +49 -0
  121. package/dist/esm/hooks/useShapes/sankey/sankey-layout.js +362 -0
  122. package/dist/esm/hooks/useShapes/styles.css +4 -4
  123. package/dist/esm/hooks/useShapes/treemap/prepare-data.js +3 -1
  124. package/dist/esm/hooks/useTooltip/index.d.ts +3 -2
  125. package/dist/esm/hooks/useTooltip/index.js +5 -3
  126. package/dist/esm/types/chart-ui.d.ts +1 -0
  127. package/package.json +1 -3
@@ -0,0 +1,362 @@
1
+ // Derived from d3-sankey v0.12.3 (https://github.com/d3/d3-sankey)
2
+ // Copyright 2015-2021 Mike Bostock — ISC License
3
+ //
4
+ // Changes:
5
+ // - Ported to TypeScript with explicit generic types (SankeyComputedNode, SankeyComputedLink)
6
+ // - sankeyLinkHorizontal() implemented via linkHorizontal() from d3-shape
7
+ // - Removed unused alignment helpers (left, right, center); only justify is kept
8
+ // - No d3-sankey dependency; uses d3-array and d3-shape (already project dependencies)
9
+ import { max, min, sum } from 'd3-array';
10
+ import { linkHorizontal } from 'd3-shape';
11
+ function justify(node, n) {
12
+ return node.sourceLinks.length ? node.depth : n - 1;
13
+ }
14
+ function ascendingBreadth(a, b) {
15
+ return a.y0 - b.y0;
16
+ }
17
+ function ascendingSourceBreadth(a, b) {
18
+ return ascendingBreadth(a.source, b.source) || a.index - b.index;
19
+ }
20
+ function ascendingTargetBreadth(a, b) {
21
+ return ascendingBreadth(a.target, b.target) || a.index - b.index;
22
+ }
23
+ function nodeValue(d) {
24
+ return d.value;
25
+ }
26
+ function linkValue(d) {
27
+ return d.value;
28
+ }
29
+ export function sankey() {
30
+ let x0 = 0, y0 = 0, x1 = 1, y1 = 1;
31
+ let dx = 24; // nodeWidth
32
+ let dy = 8, py; // nodePadding
33
+ let getId = (_d, i) => i;
34
+ let align = justify;
35
+ let sort;
36
+ let linkSort;
37
+ let iterations = 6;
38
+ function generator(input) {
39
+ // Mutate input in-place (same as original d3-sankey): layout props are added
40
+ // directly to node/link objects so that source/target references stay consistent.
41
+ const graph = {
42
+ nodes: input.nodes,
43
+ links: input.links,
44
+ };
45
+ computeNodeLinks(graph);
46
+ computeNodeValues(graph);
47
+ computeNodeDepths(graph);
48
+ computeNodeHeights(graph);
49
+ computeNodeBreadths(graph);
50
+ computeLinkBreadths(graph);
51
+ return graph;
52
+ }
53
+ generator.nodeId = function (fn) {
54
+ getId = fn;
55
+ return generator;
56
+ };
57
+ generator.nodeAlign = function (fn) {
58
+ align = fn;
59
+ return generator;
60
+ };
61
+ generator.nodeSort = function (fn) {
62
+ sort = fn;
63
+ return generator;
64
+ };
65
+ generator.nodeWidth = function (value) {
66
+ dx = value;
67
+ return generator;
68
+ };
69
+ generator.nodePadding = function (value) {
70
+ dy = py = value;
71
+ return generator;
72
+ };
73
+ generator.linkSort = function (fn) {
74
+ linkSort = fn;
75
+ return generator;
76
+ };
77
+ generator.extent = function ([[left, top], [right, bottom]]) {
78
+ x0 = left;
79
+ y0 = top;
80
+ x1 = right;
81
+ y1 = bottom;
82
+ return generator;
83
+ };
84
+ generator.iterations = function (value) {
85
+ iterations = value;
86
+ return generator;
87
+ };
88
+ function computeNodeLinks(graph) {
89
+ for (const [i, node] of graph.nodes.entries()) {
90
+ node.index = i;
91
+ node.sourceLinks = [];
92
+ node.targetLinks = [];
93
+ }
94
+ const nodeById = new Map(graph.nodes.map((d, i) => [getId(d, i), d]));
95
+ for (const [i, link] of graph.links.entries()) {
96
+ link.index = i;
97
+ const unresolved = link;
98
+ if (typeof unresolved.source !== 'object') {
99
+ unresolved.source = findNode(nodeById, unresolved.source);
100
+ }
101
+ if (typeof unresolved.target !== 'object') {
102
+ unresolved.target = findNode(nodeById, unresolved.target);
103
+ }
104
+ link.source.sourceLinks.push(link);
105
+ link.target.targetLinks.push(link);
106
+ }
107
+ if (linkSort !== null && linkSort !== undefined) {
108
+ for (const { sourceLinks, targetLinks } of graph.nodes) {
109
+ sourceLinks.sort(linkSort);
110
+ targetLinks.sort(linkSort);
111
+ }
112
+ }
113
+ }
114
+ function computeNodeValues(graph) {
115
+ for (const node of graph.nodes) {
116
+ node.value =
117
+ node.fixedValue === undefined
118
+ ? Math.max(sum(node.sourceLinks, linkValue), sum(node.targetLinks, linkValue))
119
+ : node.fixedValue;
120
+ }
121
+ }
122
+ function computeNodeDepths(graph) {
123
+ const n = graph.nodes.length;
124
+ let current = new Set(graph.nodes);
125
+ let next = new Set();
126
+ let x = 0;
127
+ while (current.size) {
128
+ for (const node of current) {
129
+ node.depth = x;
130
+ for (const { target } of node.sourceLinks) {
131
+ next.add(target);
132
+ }
133
+ }
134
+ if (++x > n)
135
+ throw new Error('circular link');
136
+ current = next;
137
+ next = new Set();
138
+ }
139
+ }
140
+ function computeNodeHeights(graph) {
141
+ const n = graph.nodes.length;
142
+ let current = new Set(graph.nodes);
143
+ let next = new Set();
144
+ let x = 0;
145
+ while (current.size) {
146
+ for (const node of current) {
147
+ node.height = x;
148
+ for (const { source } of node.targetLinks) {
149
+ next.add(source);
150
+ }
151
+ }
152
+ if (++x > n)
153
+ throw new Error('circular link');
154
+ current = next;
155
+ next = new Set();
156
+ }
157
+ }
158
+ function computeNodeLayers(graph) {
159
+ var _a;
160
+ const x = ((_a = max(graph.nodes, (d) => d.depth)) !== null && _a !== void 0 ? _a : 0) + 1;
161
+ const kx = (x1 - x0 - dx) / (x - 1);
162
+ const columns = new Array(x);
163
+ for (const node of graph.nodes) {
164
+ const i = Math.max(0, Math.min(x - 1, Math.floor(align(node, x))));
165
+ node.layer = i;
166
+ node.x0 = x0 + i * kx;
167
+ node.x1 = node.x0 + dx;
168
+ if (columns[i])
169
+ columns[i].push(node);
170
+ else
171
+ columns[i] = [node];
172
+ }
173
+ if (sort) {
174
+ for (const column of columns) {
175
+ column.sort(sort);
176
+ }
177
+ }
178
+ return columns;
179
+ }
180
+ function initializeNodeBreadths(columns) {
181
+ var _a;
182
+ const ky = (_a = min(columns, (c) => (y1 - y0 - (c.length - 1) * py) / sum(c, nodeValue))) !== null && _a !== void 0 ? _a : 0;
183
+ for (const nodes of columns) {
184
+ let y = y0;
185
+ for (const node of nodes) {
186
+ node.y0 = y;
187
+ node.y1 = y + node.value * ky;
188
+ y = node.y1 + py;
189
+ for (const link of node.sourceLinks) {
190
+ link.width = link.value * ky;
191
+ }
192
+ }
193
+ y = (y1 - y + py) / (nodes.length + 1);
194
+ for (let i = 0; i < nodes.length; ++i) {
195
+ const node = nodes[i];
196
+ node.y0 += y * (i + 1);
197
+ node.y1 += y * (i + 1);
198
+ }
199
+ reorderLinks(nodes);
200
+ }
201
+ }
202
+ function computeNodeBreadths(graph) {
203
+ var _a;
204
+ const columns = computeNodeLayers(graph);
205
+ py = Math.min(dy, (y1 - y0) / (((_a = max(columns, (c) => c.length)) !== null && _a !== void 0 ? _a : 1) - 1));
206
+ initializeNodeBreadths(columns);
207
+ for (let i = 0; i < iterations; ++i) {
208
+ const alpha = Math.pow(0.99, i);
209
+ const beta = Math.max(1 - alpha, (i + 1) / iterations);
210
+ relaxRightToLeft(columns, alpha, beta);
211
+ relaxLeftToRight(columns, alpha, beta);
212
+ }
213
+ }
214
+ function computeLinkBreadths(graph) {
215
+ for (const node of graph.nodes) {
216
+ let ly0 = node.y0;
217
+ let ly1 = ly0;
218
+ for (const link of node.sourceLinks) {
219
+ link.y0 = ly0 + link.width / 2;
220
+ ly0 += link.width;
221
+ }
222
+ for (const link of node.targetLinks) {
223
+ link.y1 = ly1 + link.width / 2;
224
+ ly1 += link.width;
225
+ }
226
+ }
227
+ }
228
+ function relaxLeftToRight(columns, alpha, beta) {
229
+ for (let i = 1, n = columns.length; i < n; ++i) {
230
+ const column = columns[i];
231
+ for (const target of column) {
232
+ let y = 0;
233
+ let w = 0;
234
+ for (const { source, value } of target.targetLinks) {
235
+ const v = value * (target.layer - source.layer);
236
+ y += targetTop(source, target) * v;
237
+ w += v;
238
+ }
239
+ if (!(w > 0))
240
+ continue;
241
+ const d = (y / w - target.y0) * alpha;
242
+ target.y0 += d;
243
+ target.y1 += d;
244
+ reorderNodeLinks(target);
245
+ }
246
+ if (sort === undefined)
247
+ column.sort(ascendingBreadth);
248
+ resolveCollisions(column, beta);
249
+ }
250
+ }
251
+ function relaxRightToLeft(columns, alpha, beta) {
252
+ for (let n = columns.length, i = n - 2; i >= 0; --i) {
253
+ const column = columns[i];
254
+ for (const source of column) {
255
+ let y = 0;
256
+ let w = 0;
257
+ for (const { target, value } of source.sourceLinks) {
258
+ const v = value * (target.layer - source.layer);
259
+ y += sourceTop(source, target) * v;
260
+ w += v;
261
+ }
262
+ if (!(w > 0))
263
+ continue;
264
+ const d = (y / w - source.y0) * alpha;
265
+ source.y0 += d;
266
+ source.y1 += d;
267
+ reorderNodeLinks(source);
268
+ }
269
+ if (sort === undefined)
270
+ column.sort(ascendingBreadth);
271
+ resolveCollisions(column, beta);
272
+ }
273
+ }
274
+ function resolveCollisions(nodes, alpha) {
275
+ const i = Math.floor(nodes.length / 2);
276
+ const subject = nodes[i];
277
+ resolveCollisionsBottomToTop(nodes, subject.y0 - py, i - 1, alpha);
278
+ resolveCollisionsTopToBottom(nodes, subject.y1 + py, i + 1, alpha);
279
+ resolveCollisionsBottomToTop(nodes, y1, nodes.length - 1, alpha);
280
+ resolveCollisionsTopToBottom(nodes, y0, 0, alpha);
281
+ }
282
+ function resolveCollisionsTopToBottom(nodes, y, i, alpha) {
283
+ for (; i < nodes.length; ++i) {
284
+ const node = nodes[i];
285
+ const d = (y - node.y0) * alpha;
286
+ if (d > 1e-6) {
287
+ node.y0 += d;
288
+ node.y1 += d;
289
+ }
290
+ y = node.y1 + py;
291
+ }
292
+ }
293
+ function resolveCollisionsBottomToTop(nodes, y, i, alpha) {
294
+ for (; i >= 0; --i) {
295
+ const node = nodes[i];
296
+ const d = (node.y1 - y) * alpha;
297
+ if (d > 1e-6) {
298
+ node.y0 -= d;
299
+ node.y1 -= d;
300
+ }
301
+ y = node.y0 - py;
302
+ }
303
+ }
304
+ function reorderNodeLinks(node) {
305
+ if (linkSort === undefined) {
306
+ for (const { source: { sourceLinks }, } of node.targetLinks) {
307
+ sourceLinks.sort(ascendingTargetBreadth);
308
+ }
309
+ for (const { target: { targetLinks }, } of node.sourceLinks) {
310
+ targetLinks.sort(ascendingSourceBreadth);
311
+ }
312
+ }
313
+ }
314
+ function reorderLinks(nodes) {
315
+ if (linkSort === undefined) {
316
+ for (const { sourceLinks, targetLinks } of nodes) {
317
+ sourceLinks.sort(ascendingTargetBreadth);
318
+ targetLinks.sort(ascendingSourceBreadth);
319
+ }
320
+ }
321
+ }
322
+ function targetTop(source, target) {
323
+ let y = source.y0 - ((source.sourceLinks.length - 1) * py) / 2;
324
+ for (const { target: node, width } of source.sourceLinks) {
325
+ if (node === target)
326
+ break;
327
+ y += width + py;
328
+ }
329
+ for (const { source: node, width } of target.targetLinks) {
330
+ if (node === source)
331
+ break;
332
+ y -= width;
333
+ }
334
+ return y;
335
+ }
336
+ function sourceTop(source, target) {
337
+ let y = target.y0 - ((target.targetLinks.length - 1) * py) / 2;
338
+ for (const { source: node, width } of target.targetLinks) {
339
+ if (node === source)
340
+ break;
341
+ y += width + py;
342
+ }
343
+ for (const { target: node, width } of source.sourceLinks) {
344
+ if (node === target)
345
+ break;
346
+ y -= width;
347
+ }
348
+ return y;
349
+ }
350
+ return generator;
351
+ }
352
+ export function sankeyLinkHorizontal() {
353
+ return linkHorizontal()
354
+ .source((d) => [d.source.x1, d.y0])
355
+ .target((d) => [d.target.x0, d.y1]);
356
+ }
357
+ function findNode(nodeById, id) {
358
+ const node = nodeById.get(id);
359
+ if (!node)
360
+ throw new Error('missing: ' + id);
361
+ return node;
362
+ }
@@ -3,7 +3,7 @@
3
3
  .gcharts-radar__label,
4
4
  .gcharts-heatmap__label,
5
5
  .gcharts-funnel__label {
6
- dominant-baseline: text-before-edge;
6
+ dominant-baseline: hanging;
7
7
  }
8
8
 
9
9
  .gcharts-scatter__point {
@@ -17,7 +17,7 @@
17
17
  font-size: 11px;
18
18
  font-weight: bold;
19
19
  fill: var(--g-color-text-complementary);
20
- dominant-baseline: text-before-edge;
20
+ dominant-baseline: hanging;
21
21
  }
22
22
 
23
23
  .gcharts-bar-x__label {
@@ -28,14 +28,14 @@
28
28
  .gcharts-bar-y__label {
29
29
  user-select: none;
30
30
  fill: var(--g-color-text-complementary);
31
- dominant-baseline: text-after-edge;
31
+ dominant-baseline: hanging;
32
32
  }
33
33
 
34
34
  .gcharts-treemap__label {
35
35
  user-select: none;
36
36
  pointer-events: none;
37
37
  fill: var(--g-color-text-complementary);
38
- dominant-baseline: text-before-edge;
38
+ dominant-baseline: hanging;
39
39
  }
40
40
 
41
41
  .gcharts-waterfall__connector {
@@ -22,6 +22,7 @@ async function getLabels(args) {
22
22
  const label = getFormattedValue(Object.assign({ value: text }, args.options));
23
23
  let labelMaxHeight = 0;
24
24
  let labelMaxWidth = 0;
25
+ let hangingOffset = 0;
25
26
  if (html) {
26
27
  const size = (_a = (await getLabelsSize({
27
28
  labels: [label],
@@ -35,9 +36,10 @@ async function getLabels(args) {
35
36
  const size = await getTextSize(label);
36
37
  labelMaxHeight = size.height;
37
38
  labelMaxWidth = size.width;
39
+ hangingOffset = size.hangingOffset;
38
40
  }
39
41
  let x = left;
40
- const y = prevLabelsHeight + d.y0 + padding;
42
+ const y = prevLabelsHeight + d.y0 + padding + hangingOffset;
41
43
  const labelWidth = Math.min(labelMaxWidth, spaceWidth);
42
44
  const labelHeight = Math.min(labelMaxHeight, availableSpaceHeight);
43
45
  if (!labelWidth || y > d.y1) {
@@ -1,5 +1,5 @@
1
1
  import type { Dispatch } from 'd3-dispatch';
2
- import type { AxisPlotBand, AxisPlotLine, PointPosition, TooltipDataChunk } from '../../types';
2
+ import type { AxisPlotBand, AxisPlotLine, AxisPlotShape, PointPosition, TooltipDataChunk } from '../../types';
3
3
  import type { PreparedTooltip } from '../types';
4
4
  import type { PreparedXAxis, PreparedYAxis } from '../useAxis/types';
5
5
  type Args = {
@@ -10,8 +10,9 @@ type Args = {
10
10
  };
11
11
  export declare const useTooltip: ({ dispatcher, tooltip, xAxis, yAxis }: Args) => {
12
12
  hovered: TooltipDataChunk[] | undefined;
13
- hoveredPlotLines: AxisPlotLine[] | undefined;
14
13
  hoveredPlotBands: AxisPlotBand[] | undefined;
14
+ hoveredPlotLines: AxisPlotLine[] | undefined;
15
+ hoveredPlotShapes: AxisPlotShape[] | undefined;
15
16
  pointerPosition: PointPosition | undefined;
16
17
  };
17
18
  export {};
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import isEqual from 'lodash/isEqual';
3
3
  import { getSortedHovered } from '../../components/Tooltip/DefaultTooltipContent/utils';
4
4
  export const useTooltip = ({ dispatcher, tooltip, xAxis, yAxis }) => {
5
- const [{ hovered, hoveredPlotLines, hoveredPlotBands, pointerPosition }, setTooltipState] = React.useState({});
5
+ const [{ hovered, hoveredPlotBands, hoveredPlotLines, hoveredPlotShapes, pointerPosition }, setTooltipState,] = React.useState({});
6
6
  const prevHovered = React.useRef(hovered);
7
7
  React.useEffect(() => {
8
8
  if (tooltip === null || tooltip === void 0 ? void 0 : tooltip.enabled) {
@@ -17,8 +17,9 @@ export const useTooltip = ({ dispatcher, tooltip, xAxis, yAxis }) => {
17
17
  const isHoveredChanged = !isEqual(prevHovered.current, sortedHovered);
18
18
  const newTooltipState = {
19
19
  hovered: isHoveredChanged ? sortedHovered : prevHovered.current,
20
- hoveredPlotLines: nextHoveredPlots === null || nextHoveredPlots === void 0 ? void 0 : nextHoveredPlots.lines,
21
20
  hoveredPlotBands: nextHoveredPlots === null || nextHoveredPlots === void 0 ? void 0 : nextHoveredPlots.bands,
21
+ hoveredPlotLines: nextHoveredPlots === null || nextHoveredPlots === void 0 ? void 0 : nextHoveredPlots.lines,
22
+ hoveredPlotShapes: nextHoveredPlots === null || nextHoveredPlots === void 0 ? void 0 : nextHoveredPlots.shapes,
22
23
  pointerPosition: nextPointerPosition,
23
24
  };
24
25
  if (isHoveredChanged) {
@@ -35,8 +36,9 @@ export const useTooltip = ({ dispatcher, tooltip, xAxis, yAxis }) => {
35
36
  }, [dispatcher, tooltip, xAxis, yAxis]);
36
37
  return {
37
38
  hovered,
38
- hoveredPlotLines,
39
39
  hoveredPlotBands,
40
+ hoveredPlotLines,
41
+ hoveredPlotShapes,
40
42
  pointerPosition,
41
43
  };
42
44
  };
@@ -7,6 +7,7 @@ export interface LabelData {
7
7
  size: {
8
8
  width: number;
9
9
  height: number;
10
+ hangingOffset?: number;
10
11
  };
11
12
  textAnchor: 'start' | 'end' | 'middle';
12
13
  series: {
@@ -23,6 +23,7 @@ export const AxisX = (props) => {
23
23
  const plotDataAttr = 'data-plot-x';
24
24
  const plotBandDataAttr = `data-plot-x-band-${preparedAxisData.id}`;
25
25
  const plotLineDataAttr = `data-plot-x-line-${preparedAxisData.id}`;
26
+ const plotShapeDataAttr = `data-plot-x-shape-${preparedAxisData.id}`;
26
27
  if (plotBeforeRef === null || plotBeforeRef === void 0 ? void 0 : plotBeforeRef.current) {
27
28
  plotBeforeContainer = select(plotBeforeRef.current);
28
29
  }
@@ -45,7 +46,7 @@ export const AxisX = (props) => {
45
46
  .html((d) => d.text)
46
47
  .attr('x', (d) => d.x)
47
48
  .attr('y', (d) => d.y)
48
- .attr('dominant-baseline', 'text-before-edge')
49
+ .attr('dominant-baseline', 'hanging')
49
50
  .attr('text-anchor', 'start');
50
51
  }
51
52
  if (preparedAxisData.domain) {
@@ -98,7 +99,7 @@ export const AxisX = (props) => {
98
99
  .attr('y', (d) => d.y)
99
100
  .attr('text-anchor', 'start')
100
101
  .attr('class', labelClassName)
101
- .style('dominant-baseline', 'text-before-edge')
102
+ .style('dominant-baseline', 'hanging')
102
103
  .style('font-size', label.style.fontSize)
103
104
  .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '');
104
105
  }
@@ -134,7 +135,7 @@ export const AxisX = (props) => {
134
135
  .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '')
135
136
  .style('font-size', label.style.fontSize)
136
137
  .style('font-weight', (_b = label.style.fontWeight) !== null && _b !== void 0 ? _b : '')
137
- .style('dominant-baseline', 'text-before-edge')
138
+ .style('dominant-baseline', 'hanging')
138
139
  .style('text-anchor', 'start')
139
140
  .attr('transform', `translate(${label.x}, ${label.y}) rotate(${label.rotate})`)
140
141
  .attr('data-qa', (_c = label.qa) !== null && _c !== void 0 ? _c : null);
@@ -176,7 +177,7 @@ export const AxisX = (props) => {
176
177
  .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '')
177
178
  .style('font-size', label.style.fontSize)
178
179
  .style('font-weight', (_b = label.style.fontWeight) !== null && _b !== void 0 ? _b : '')
179
- .style('dominant-baseline', 'text-before-edge')
180
+ .style('dominant-baseline', 'hanging')
180
181
  .style('text-anchor', 'start')
181
182
  .attr('transform', `translate(${label.x}, ${label.y}) rotate(${label.rotate})`)
182
183
  .attr('data-qa', (_c = label.qa) !== null && _c !== void 0 ? _c : null);
@@ -186,14 +187,40 @@ export const AxisX = (props) => {
186
187
  setPlotLines(plotBeforeContainer, preparedAxisData.plotLines.filter((item) => item.layerPlacement === 'before'));
187
188
  setPlotLines(plotAfterContainer, preparedAxisData.plotLines.filter((item) => item.layerPlacement === 'after'));
188
189
  }
190
+ if (preparedAxisData.plotShapes.length > 0) {
191
+ const setPlotShapes = (plotContainer, plotShapes) => {
192
+ if (!plotContainer || !plotShapes.length) {
193
+ return;
194
+ }
195
+ plotContainer
196
+ .selectAll(`[${plotShapeDataAttr}]`)
197
+ .remove()
198
+ .data(plotShapes)
199
+ .join('g')
200
+ .attr(plotDataAttr, 1)
201
+ .attr(plotShapeDataAttr, 1)
202
+ .attr('transform', (d) => `translate(${d.x}, ${d.y})`)
203
+ .attr('opacity', (d) => d.opacity)
204
+ .html((d) => d.renderer({
205
+ x: d.x,
206
+ y: 0,
207
+ plotHeight: d.plotHeight,
208
+ plotWidth: d.plotWidth,
209
+ }));
210
+ };
211
+ setPlotShapes(plotBeforeContainer, preparedAxisData.plotShapes.filter((item) => item.layerPlacement === 'before'));
212
+ setPlotShapes(plotAfterContainer, preparedAxisData.plotShapes.filter((item) => item.layerPlacement === 'after'));
213
+ }
189
214
  return () => {
190
215
  if (plotBeforeContainer) {
191
216
  plotBeforeContainer.selectAll(`[${plotBandDataAttr}]`).remove();
192
217
  plotBeforeContainer.selectAll(`[${plotLineDataAttr}]`).remove();
218
+ plotBeforeContainer.selectAll(`[${plotShapeDataAttr}]`).remove();
193
219
  }
194
220
  if (plotAfterContainer) {
195
221
  plotAfterContainer.selectAll(`[${plotBandDataAttr}]`).remove();
196
222
  plotAfterContainer.selectAll(`[${plotLineDataAttr}]`).remove();
223
+ plotAfterContainer.selectAll(`[${plotShapeDataAttr}]`).remove();
197
224
  }
198
225
  };
199
226
  }, [lineGenerator, plotAfterRef, plotBeforeRef, preparedAxisData]);