yukit-web 0.10.6 → 0.10.7

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 (190) hide show
  1. package/fesm2022/yukit-web-chart.mjs +807 -552
  2. package/fesm2022/yukit-web-chart.mjs.map +1 -1
  3. package/fesm2022/yukit-web-helm-accordion.mjs +271 -100
  4. package/fesm2022/yukit-web-helm-accordion.mjs.map +1 -1
  5. package/fesm2022/yukit-web-helm-alert-dialog.mjs +675 -243
  6. package/fesm2022/yukit-web-helm-alert-dialog.mjs.map +1 -1
  7. package/fesm2022/yukit-web-helm-alert.mjs +199 -91
  8. package/fesm2022/yukit-web-helm-alert.mjs.map +1 -1
  9. package/fesm2022/yukit-web-helm-aspect-ratio.mjs +77 -43
  10. package/fesm2022/yukit-web-helm-aspect-ratio.mjs.map +1 -1
  11. package/fesm2022/yukit-web-helm-attachment.mjs +552 -205
  12. package/fesm2022/yukit-web-helm-attachment.mjs.map +1 -1
  13. package/fesm2022/yukit-web-helm-autocomplete.mjs +913 -288
  14. package/fesm2022/yukit-web-helm-autocomplete.mjs.map +1 -1
  15. package/fesm2022/yukit-web-helm-avatar.mjs +298 -137
  16. package/fesm2022/yukit-web-helm-avatar.mjs.map +1 -1
  17. package/fesm2022/yukit-web-helm-badge.mjs +78 -44
  18. package/fesm2022/yukit-web-helm-badge.mjs.map +1 -1
  19. package/fesm2022/yukit-web-helm-breadcrumb.mjs +466 -183
  20. package/fesm2022/yukit-web-helm-breadcrumb.mjs.map +1 -1
  21. package/fesm2022/yukit-web-helm-bubble.mjs +297 -118
  22. package/fesm2022/yukit-web-helm-bubble.mjs.map +1 -1
  23. package/fesm2022/yukit-web-helm-button-group.mjs +179 -83
  24. package/fesm2022/yukit-web-helm-button-group.mjs.map +1 -1
  25. package/fesm2022/yukit-web-helm-button.mjs +137 -67
  26. package/fesm2022/yukit-web-helm-button.mjs.map +1 -1
  27. package/fesm2022/yukit-web-helm-calendar.mjs +957 -230
  28. package/fesm2022/yukit-web-helm-calendar.mjs.map +1 -1
  29. package/fesm2022/yukit-web-helm-card.mjs +318 -136
  30. package/fesm2022/yukit-web-helm-card.mjs.map +1 -1
  31. package/fesm2022/yukit-web-helm-carousel.mjs +563 -233
  32. package/fesm2022/yukit-web-helm-carousel.mjs.map +1 -1
  33. package/fesm2022/yukit-web-helm-checkbox.mjs +367 -101
  34. package/fesm2022/yukit-web-helm-checkbox.mjs.map +1 -1
  35. package/fesm2022/yukit-web-helm-collapsible.mjs +155 -61
  36. package/fesm2022/yukit-web-helm-collapsible.mjs.map +1 -1
  37. package/fesm2022/yukit-web-helm-combobox.mjs +1572 -481
  38. package/fesm2022/yukit-web-helm-combobox.mjs.map +1 -1
  39. package/fesm2022/yukit-web-helm-command.mjs +752 -260
  40. package/fesm2022/yukit-web-helm-command.mjs.map +1 -1
  41. package/fesm2022/yukit-web-helm-context-menu.mjs +161 -63
  42. package/fesm2022/yukit-web-helm-context-menu.mjs.map +1 -1
  43. package/fesm2022/yukit-web-helm-date-picker.mjs +2322 -932
  44. package/fesm2022/yukit-web-helm-date-picker.mjs.map +1 -1
  45. package/fesm2022/yukit-web-helm-dialog.mjs +625 -240
  46. package/fesm2022/yukit-web-helm-dialog.mjs.map +1 -1
  47. package/fesm2022/yukit-web-helm-drawer.mjs +539 -222
  48. package/fesm2022/yukit-web-helm-drawer.mjs.map +1 -1
  49. package/fesm2022/yukit-web-helm-dropdown-menu.mjs +1295 -493
  50. package/fesm2022/yukit-web-helm-dropdown-menu.mjs.map +1 -1
  51. package/fesm2022/yukit-web-helm-empty.mjs +280 -121
  52. package/fesm2022/yukit-web-helm-empty.mjs.map +1 -1
  53. package/fesm2022/yukit-web-helm-field.mjs +670 -301
  54. package/fesm2022/yukit-web-helm-field.mjs.map +1 -1
  55. package/fesm2022/yukit-web-helm-hover-card.mjs +198 -99
  56. package/fesm2022/yukit-web-helm-hover-card.mjs.map +1 -1
  57. package/fesm2022/yukit-web-helm-input-group.mjs +357 -165
  58. package/fesm2022/yukit-web-helm-input-group.mjs.map +1 -1
  59. package/fesm2022/yukit-web-helm-input-otp.mjs +306 -114
  60. package/fesm2022/yukit-web-helm-input-otp.mjs.map +1 -1
  61. package/fesm2022/yukit-web-helm-input.mjs +62 -30
  62. package/fesm2022/yukit-web-helm-input.mjs.map +1 -1
  63. package/fesm2022/yukit-web-helm-item.mjs +545 -227
  64. package/fesm2022/yukit-web-helm-item.mjs.map +1 -1
  65. package/fesm2022/yukit-web-helm-kbd.mjs +85 -44
  66. package/fesm2022/yukit-web-helm-kbd.mjs.map +1 -1
  67. package/fesm2022/yukit-web-helm-label.mjs +60 -28
  68. package/fesm2022/yukit-web-helm-label.mjs.map +1 -1
  69. package/fesm2022/yukit-web-helm-marker.mjs +165 -74
  70. package/fesm2022/yukit-web-helm-marker.mjs.map +1 -1
  71. package/fesm2022/yukit-web-helm-menubar.mjs +207 -82
  72. package/fesm2022/yukit-web-helm-menubar.mjs.map +1 -1
  73. package/fesm2022/yukit-web-helm-message.mjs +277 -112
  74. package/fesm2022/yukit-web-helm-message.mjs.map +1 -1
  75. package/fesm2022/yukit-web-helm-native-select.mjs +363 -129
  76. package/fesm2022/yukit-web-helm-native-select.mjs.map +1 -1
  77. package/fesm2022/yukit-web-helm-navigation-menu.mjs +398 -166
  78. package/fesm2022/yukit-web-helm-navigation-menu.mjs.map +1 -1
  79. package/fesm2022/yukit-web-helm-pagination.mjs +1444 -460
  80. package/fesm2022/yukit-web-helm-pagination.mjs.map +1 -1
  81. package/fesm2022/yukit-web-helm-popover.mjs +358 -133
  82. package/fesm2022/yukit-web-helm-popover.mjs.map +1 -1
  83. package/fesm2022/yukit-web-helm-progress.mjs +126 -58
  84. package/fesm2022/yukit-web-helm-progress.mjs.map +1 -1
  85. package/fesm2022/yukit-web-helm-radio-group.mjs +420 -144
  86. package/fesm2022/yukit-web-helm-radio-group.mjs.map +1 -1
  87. package/fesm2022/yukit-web-helm-resizable.mjs +210 -91
  88. package/fesm2022/yukit-web-helm-resizable.mjs.map +1 -1
  89. package/fesm2022/yukit-web-helm-scroll-area.mjs +64 -34
  90. package/fesm2022/yukit-web-helm-scroll-area.mjs.map +1 -1
  91. package/fesm2022/yukit-web-helm-select.mjs +1059 -351
  92. package/fesm2022/yukit-web-helm-select.mjs.map +1 -1
  93. package/fesm2022/yukit-web-helm-separator.mjs +61 -31
  94. package/fesm2022/yukit-web-helm-separator.mjs.map +1 -1
  95. package/fesm2022/yukit-web-helm-sheet.mjs +590 -231
  96. package/fesm2022/yukit-web-helm-sheet.mjs.map +1 -1
  97. package/fesm2022/yukit-web-helm-sidebar.mjs +1781 -757
  98. package/fesm2022/yukit-web-helm-sidebar.mjs.map +1 -1
  99. package/fesm2022/yukit-web-helm-skeleton.mjs +45 -27
  100. package/fesm2022/yukit-web-helm-skeleton.mjs.map +1 -1
  101. package/fesm2022/yukit-web-helm-slider.mjs +139 -59
  102. package/fesm2022/yukit-web-helm-slider.mjs.map +1 -1
  103. package/fesm2022/yukit-web-helm-sonner.mjs +350 -62
  104. package/fesm2022/yukit-web-helm-sonner.mjs.map +1 -1
  105. package/fesm2022/yukit-web-helm-spinner.mjs +118 -44
  106. package/fesm2022/yukit-web-helm-spinner.mjs.map +1 -1
  107. package/fesm2022/yukit-web-helm-switch.mjs +326 -94
  108. package/fesm2022/yukit-web-helm-switch.mjs.map +1 -1
  109. package/fesm2022/yukit-web-helm-table.mjs +374 -177
  110. package/fesm2022/yukit-web-helm-table.mjs.map +1 -1
  111. package/fesm2022/yukit-web-helm-tabs.mjs +549 -173
  112. package/fesm2022/yukit-web-helm-tabs.mjs.map +1 -1
  113. package/fesm2022/yukit-web-helm-textarea.mjs +62 -30
  114. package/fesm2022/yukit-web-helm-textarea.mjs.map +1 -1
  115. package/fesm2022/yukit-web-helm-toggle-group.mjs +291 -89
  116. package/fesm2022/yukit-web-helm-toggle-group.mjs.map +1 -1
  117. package/fesm2022/yukit-web-helm-toggle.mjs +132 -57
  118. package/fesm2022/yukit-web-helm-toggle.mjs.map +1 -1
  119. package/fesm2022/yukit-web-helm-tooltip.mjs +84 -54
  120. package/fesm2022/yukit-web-helm-tooltip.mjs.map +1 -1
  121. package/fesm2022/yukit-web-helm-typography.mjs +461 -202
  122. package/fesm2022/yukit-web-helm-typography.mjs.map +1 -1
  123. package/fesm2022/yukit-web-helm-utils.mjs +131 -253
  124. package/fesm2022/yukit-web-helm-utils.mjs.map +1 -1
  125. package/fesm2022/yukit-web.mjs +24457 -9670
  126. package/fesm2022/yukit-web.mjs.map +1 -1
  127. package/package.json +9 -9
  128. package/types/yukit-web-chart.d.ts +184 -125
  129. package/types/yukit-web-helm-accordion.d.ts +49 -28
  130. package/types/yukit-web-helm-alert-dialog.d.ts +127 -73
  131. package/types/yukit-web-helm-alert.d.ts +30 -32
  132. package/types/yukit-web-helm-aspect-ratio.d.ts +17 -15
  133. package/types/yukit-web-helm-attachment.d.ts +97 -69
  134. package/types/yukit-web-helm-autocomplete.d.ts +205 -79
  135. package/types/yukit-web-helm-avatar.d.ts +44 -39
  136. package/types/yukit-web-helm-badge.d.ts +18 -17
  137. package/types/yukit-web-helm-breadcrumb.d.ts +69 -45
  138. package/types/yukit-web-helm-bubble.d.ts +54 -40
  139. package/types/yukit-web-helm-button-group.d.ts +29 -22
  140. package/types/yukit-web-helm-button.d.ts +41 -31
  141. package/types/yukit-web-helm-calendar.d.ts +157 -85
  142. package/types/yukit-web-helm-card.d.ts +38 -42
  143. package/types/yukit-web-helm-carousel.d.ts +105 -73
  144. package/types/yukit-web-helm-checkbox.d.ts +117 -58
  145. package/types/yukit-web-helm-collapsible.d.ts +34 -19
  146. package/types/yukit-web-helm-combobox.d.ts +355 -150
  147. package/types/yukit-web-helm-command.d.ts +140 -73
  148. package/types/yukit-web-helm-context-menu.d.ts +48 -27
  149. package/types/yukit-web-helm-date-picker.d.ts +852 -556
  150. package/types/yukit-web-helm-dialog.d.ts +106 -78
  151. package/types/yukit-web-helm-drawer.d.ts +90 -61
  152. package/types/yukit-web-helm-dropdown-menu.d.ts +278 -158
  153. package/types/yukit-web-helm-empty.d.ts +38 -42
  154. package/types/yukit-web-helm-field.d.ts +122 -91
  155. package/types/yukit-web-helm-hover-card.d.ts +39 -27
  156. package/types/yukit-web-helm-input-group.d.ts +63 -41
  157. package/types/yukit-web-helm-input-otp.d.ts +38 -35
  158. package/types/yukit-web-helm-input.d.ts +19 -12
  159. package/types/yukit-web-helm-item.d.ts +90 -82
  160. package/types/yukit-web-helm-kbd.d.ts +10 -15
  161. package/types/yukit-web-helm-label.d.ts +14 -11
  162. package/types/yukit-web-helm-marker.d.ts +26 -27
  163. package/types/yukit-web-helm-menubar.d.ts +61 -32
  164. package/types/yukit-web-helm-message.d.ts +34 -38
  165. package/types/yukit-web-helm-native-select.d.ts +102 -61
  166. package/types/yukit-web-helm-navigation-menu.d.ts +76 -42
  167. package/types/yukit-web-helm-pagination.d.ts +344 -166
  168. package/types/yukit-web-helm-popover.d.ts +62 -42
  169. package/types/yukit-web-helm-progress.d.ts +27 -20
  170. package/types/yukit-web-helm-radio-group.d.ts +121 -63
  171. package/types/yukit-web-helm-resizable.d.ts +46 -24
  172. package/types/yukit-web-helm-scroll-area.d.ts +6 -10
  173. package/types/yukit-web-helm-select.d.ts +231 -114
  174. package/types/yukit-web-helm-separator.d.ts +15 -12
  175. package/types/yukit-web-helm-sheet.d.ts +94 -65
  176. package/types/yukit-web-helm-sidebar.d.ts +322 -232
  177. package/types/yukit-web-helm-skeleton.d.ts +6 -10
  178. package/types/yukit-web-helm-slider.d.ts +33 -13
  179. package/types/yukit-web-helm-sonner.d.ts +112 -51
  180. package/types/yukit-web-helm-spinner.d.ts +24 -17
  181. package/types/yukit-web-helm-switch.d.ts +89 -51
  182. package/types/yukit-web-helm-table.d.ts +38 -42
  183. package/types/yukit-web-helm-tabs.d.ts +116 -60
  184. package/types/yukit-web-helm-textarea.d.ts +19 -12
  185. package/types/yukit-web-helm-toggle-group.d.ts +81 -32
  186. package/types/yukit-web-helm-toggle.d.ts +39 -21
  187. package/types/yukit-web-helm-tooltip.d.ts +21 -16
  188. package/types/yukit-web-helm-typography.d.ts +62 -77
  189. package/types/yukit-web-helm-utils.d.ts +8 -11
  190. package/types/yukit-web.d.ts +5092 -2351
@@ -1,650 +1,905 @@
1
- import { _IdGenerator } from '@angular/cdk/a11y';
2
- import * as i0 from '@angular/core';
3
- import { signal, inject, DestroyRef, afterNextRender, viewChild, input, booleanAttribute, computed, linkedSignal, ChangeDetectionStrategy, Component } from '@angular/core';
4
- import { HlmSkeleton } from 'yukit-web/helm/skeleton';
5
- import { hlm } from 'yukit-web/helm/utils';
6
- import { area, curveMonotoneX, curveMonotoneY, stack, stackOffsetNone, stackOffsetDiverging, line, pie, arc } from 'd3-shape';
7
- import { scaleBand, scalePoint, scaleLinear } from 'd3-scale';
8
-
9
- /** Every chart token, in palette order. */
1
+ import { _IdGenerator } from "@angular/cdk/a11y";
2
+ import * as i0 from "@angular/core";
3
+ import { ChangeDetectionStrategy, Component, DestroyRef, afterNextRender, booleanAttribute, computed, inject, input, linkedSignal, signal, viewChild } from "@angular/core";
4
+ import { HlmSkeleton } from "yukit-web/helm/skeleton";
5
+ import { hlm } from "yukit-web/helm/utils";
6
+ import { arc, area, curveMonotoneX, curveMonotoneY, line, pie, stack, stackOffsetDiverging, stackOffsetNone } from "d3-shape";
7
+ import { scaleBand, scaleLinear, scalePoint } from "d3-scale";
10
8
  const YUW_CHART_COLORS = [
11
- 'chart-1',
12
- 'chart-2',
13
- 'chart-3',
14
- 'chart-4',
15
- 'chart-5',
16
- 'chart-6',
17
- 'chart-7',
18
- 'chart-8',
9
+ "chart-1",
10
+ "chart-2",
11
+ "chart-3",
12
+ "chart-4",
13
+ "chart-5",
14
+ "chart-6",
15
+ "chart-7",
16
+ "chart-8"
19
17
  ];
20
- /** Color token of the series at `index`, cycling through the palette: builds a config for a dynamic set of series. */
21
18
  function yuwChartColorAt(index) {
22
- const count = YUW_CHART_COLORS.length;
23
- return YUW_CHART_COLORS[((index % count) + count) % count];
19
+ const count = YUW_CHART_COLORS.length;
20
+ return YUW_CHART_COLORS[(index % count + count) % count];
24
21
  }
25
-
26
- /** Average advance of a glyph at the `text-xs` size axis labels use, to reserve room without measuring text. */
27
- const CHART_CHAR_WIDTH = 7;
28
22
  function cssColor(color) {
29
- return `var(--${color})`;
23
+ return `var(--${color})`;
30
24
  }
31
25
  function seriesOf(config) {
32
- return Object.entries(config).map(([key, series]) => ({ key, label: series.label, color: cssColor(series.color) }));
26
+ return Object.entries(config).map(([key, series]) => ({
27
+ key,
28
+ label: series.label,
29
+ color: cssColor(series.color)
30
+ }));
33
31
  }
34
- /** A finite number, or `null` for anything else: a missing value is a gap, never a zero. */
35
32
  function valueOf(row, key) {
36
- const value = row[key];
37
- return typeof value === 'number' && Number.isFinite(value) ? value : null;
33
+ const value = row[key];
34
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
38
35
  }
39
36
  function textWidth(labels) {
40
- return labels.reduce((widest, label) => Math.max(widest, label.length), 0) * CHART_CHAR_WIDTH;
37
+ return labels.reduce((widest, label) => Math.max(widest, label.length), 0) * 7;
41
38
  }
42
39
  function rectPath(x, y, width, height, radius = 0) {
43
- const r = Math.max(0, Math.min(radius, width / 2, height / 2));
44
- return (`M${x + r},${y}h${width - 2 * r}a${r},${r} 0 0 1 ${r},${r}v${height - 2 * r}` +
45
- `a${r},${r} 0 0 1 ${-r},${r}h${2 * r - width}a${r},${r} 0 0 1 ${-r},${-r}` +
46
- `v${2 * r - height}a${r},${r} 0 0 1 ${r},${-r}Z`);
40
+ const r = Math.max(0, Math.min(radius, width / 2, height / 2));
41
+ return `M${x + r},${y}h${width - 2 * r}a${r},${r} 0 0 1 ${r},${r}v${height - 2 * r}a${r},${r} 0 0 1 ${-r},${r}h${2 * r - width}a${r},${r} 0 0 1 ${-r},${-r}v${2 * r - height}a${r},${r} 0 0 1 ${r},${-r}Z`;
47
42
  }
48
43
  function emptyScene(table) {
49
- return { cursorPaint: 'band', empty: true, grid: [], hits: [], marks: [], origin: { x: 0, y: 0 }, table, ticks: [] };
44
+ return {
45
+ cursorPaint: "band",
46
+ empty: true,
47
+ grid: [],
48
+ hits: [],
49
+ marks: [],
50
+ origin: {
51
+ x: 0,
52
+ y: 0
53
+ },
54
+ table,
55
+ ticks: []
56
+ };
50
57
  }
51
-
52
58
  const LABEL_GAP = 8;
53
59
  const AXIS_ROOM = 24;
54
60
  const LINE_HEIGHT = 16;
55
61
  const MAX_VALUE_TICKS = 5;
56
62
  function tickCount(length, room) {
57
- return Math.max(2, Math.min(MAX_VALUE_TICKS, Math.floor(length / room)));
63
+ return Math.max(2, Math.min(MAX_VALUE_TICKS, Math.floor(length / room)));
58
64
  }
59
65
  const VERTICAL = {
60
- curve: curveMonotoneX,
61
- anchor: (plot, category) => ({ x: category, y: (plot.top + plot.bottom) / 2 }),
62
- area: (spans) => area()
63
- .x((span) => span.category)
64
- .y0((span) => span.base)
65
- .y1((span) => span.top)
66
- .curve(curveMonotoneX)(spans) ?? '',
67
- band: (plot, start, end) => rectPath(start, plot.top, end - start, plot.bottom - plot.top),
68
- bar: (category, size, base, top, radius) => rectPath(category, Math.min(base, top), size, Math.abs(base - top), radius),
69
- categoryLabelChars: () => Number.POSITIVE_INFINITY,
70
- categoryLabelRoom: (categoryLabelWidth) => categoryLabelWidth + LABEL_GAP,
71
- categoryRange: (plot) => [plot.left, plot.right],
72
- categoryTick: (plot, category, label) => ({ anchor: 'middle', label, x: category, y: plot.bottom + AXIS_ROOM - 6 }),
73
- cursor: (plot, category) => `M${category},${plot.top}V${plot.bottom}`,
74
- grid: (plot, value) => `M${plot.left},${value}H${plot.right}`,
75
- margins: (_width, valueLabelWidth) => ({
76
- top: LABEL_GAP,
77
- right: LABEL_GAP,
78
- bottom: AXIS_ROOM,
79
- left: valueLabelWidth + LABEL_GAP,
80
- }),
81
- point: (category, value) => [category, value],
82
- valueRange: (plot) => [plot.bottom, plot.top],
83
- valueTick: (plot, value, label) => ({ anchor: 'end', label, x: plot.left - LABEL_GAP, y: value }),
84
- valueTickCount: (plot) => tickCount(plot.bottom - plot.top, 2 * LINE_HEIGHT),
66
+ curve: curveMonotoneX,
67
+ anchor: (plot, category) => ({
68
+ x: category,
69
+ y: (plot.top + plot.bottom) / 2
70
+ }),
71
+ area: (spans) => area().x((span) => span.category).y0((span) => span.base).y1((span) => span.top).curve(curveMonotoneX)(spans) ?? "",
72
+ band: (plot, start, end) => rectPath(start, plot.top, end - start, plot.bottom - plot.top),
73
+ bar: (category, size, base, top, radius) => rectPath(category, Math.min(base, top), size, Math.abs(base - top), radius),
74
+ categoryLabelChars: () => Number.POSITIVE_INFINITY,
75
+ categoryLabelRoom: (categoryLabelWidth) => categoryLabelWidth + LABEL_GAP,
76
+ categoryRange: (plot) => [plot.left, plot.right],
77
+ categoryTick: (plot, category, label) => ({
78
+ anchor: "middle",
79
+ label,
80
+ x: category,
81
+ y: plot.bottom + AXIS_ROOM - 6
82
+ }),
83
+ cursor: (plot, category) => `M${category},${plot.top}V${plot.bottom}`,
84
+ grid: (plot, value) => `M${plot.left},${value}H${plot.right}`,
85
+ margins: (_width, valueLabelWidth) => ({
86
+ top: LABEL_GAP,
87
+ right: LABEL_GAP,
88
+ bottom: AXIS_ROOM,
89
+ left: valueLabelWidth + LABEL_GAP
90
+ }),
91
+ point: (category, value) => [category, value],
92
+ valueRange: (plot) => [plot.bottom, plot.top],
93
+ valueTick: (plot, value, label) => ({
94
+ anchor: "end",
95
+ label,
96
+ x: plot.left - LABEL_GAP,
97
+ y: value
98
+ }),
99
+ valueTickCount: (plot) => tickCount(plot.bottom - plot.top, 32)
85
100
  };
86
101
  const HORIZONTAL = {
87
- curve: curveMonotoneY,
88
- anchor: (plot, category) => ({ x: plot.right, y: category }),
89
- area: (spans) => area()
90
- .y((span) => span.category)
91
- .x0((span) => span.base)
92
- .x1((span) => span.top)
93
- .curve(curveMonotoneY)(spans) ?? '',
94
- band: (plot, start, end) => rectPath(plot.left, start, plot.right - plot.left, end - start),
95
- bar: (category, size, base, top, radius) => rectPath(Math.min(base, top), category, Math.abs(base - top), size, radius),
96
- categoryLabelChars: (margins) => Math.max(1, Math.floor((margins.left - LABEL_GAP) / CHART_CHAR_WIDTH)),
97
- categoryLabelRoom: () => LINE_HEIGHT,
98
- categoryRange: (plot) => [plot.top, plot.bottom],
99
- categoryTick: (plot, category, label) => ({ anchor: 'end', label, x: plot.left - LABEL_GAP, y: category }),
100
- cursor: (plot, category) => `M${plot.left},${category}H${plot.right}`,
101
- grid: (plot, value) => `M${value},${plot.top}V${plot.bottom}`,
102
- margins: (width, valueLabelWidth, categoryLabelWidth) => ({
103
- top: LABEL_GAP,
104
- right: Math.max(LABEL_GAP, valueLabelWidth / 2),
105
- bottom: AXIS_ROOM,
106
- left: Math.min(categoryLabelWidth, width * 0.4) + LABEL_GAP,
107
- }),
108
- point: (category, value) => [value, category],
109
- valueRange: (plot) => [plot.left, plot.right],
110
- valueTick: (plot, value, label) => ({ anchor: 'middle', label, x: value, y: plot.bottom + AXIS_ROOM - 6 }),
111
- valueTickCount: (plot, valueLabelWidth) => tickCount(plot.right - plot.left, valueLabelWidth + 2 * LABEL_GAP),
102
+ curve: curveMonotoneY,
103
+ anchor: (plot, category) => ({
104
+ x: plot.right,
105
+ y: category
106
+ }),
107
+ area: (spans) => area().y((span) => span.category).x0((span) => span.base).x1((span) => span.top).curve(curveMonotoneY)(spans) ?? "",
108
+ band: (plot, start, end) => rectPath(plot.left, start, plot.right - plot.left, end - start),
109
+ bar: (category, size, base, top, radius) => rectPath(Math.min(base, top), category, Math.abs(base - top), size, radius),
110
+ categoryLabelChars: (margins) => Math.max(1, Math.floor((margins.left - LABEL_GAP) / 7)),
111
+ categoryLabelRoom: () => LINE_HEIGHT,
112
+ categoryRange: (plot) => [plot.top, plot.bottom],
113
+ categoryTick: (plot, category, label) => ({
114
+ anchor: "end",
115
+ label,
116
+ x: plot.left - LABEL_GAP,
117
+ y: category
118
+ }),
119
+ cursor: (plot, category) => `M${plot.left},${category}H${plot.right}`,
120
+ grid: (plot, value) => `M${value},${plot.top}V${plot.bottom}`,
121
+ margins: (width, valueLabelWidth, categoryLabelWidth) => ({
122
+ top: LABEL_GAP,
123
+ right: Math.max(LABEL_GAP, valueLabelWidth / 2),
124
+ bottom: AXIS_ROOM,
125
+ left: Math.min(categoryLabelWidth, width * .4) + LABEL_GAP
126
+ }),
127
+ point: (category, value) => [value, category],
128
+ valueRange: (plot) => [plot.left, plot.right],
129
+ valueTick: (plot, value, label) => ({
130
+ anchor: "middle",
131
+ label,
132
+ x: value,
133
+ y: plot.bottom + AXIS_ROOM - 6
134
+ }),
135
+ valueTickCount: (plot, valueLabelWidth) => tickCount(plot.right - plot.left, valueLabelWidth + 16)
112
136
  };
113
-
114
137
  function extentWithZero(values) {
115
- const ends = values.flat().flatMap((value) => (value ? [value.base, value.top] : []));
116
- const min = Math.min(0, ...ends);
117
- const max = Math.max(0, ...ends);
118
- return [min, max === min ? min + 1 : max];
138
+ const ends = values.flat().flatMap((value) => value ? [value.base, value.top] : []);
139
+ const min = Math.min(0, ...ends);
140
+ const max = Math.max(0, ...ends);
141
+ return [min, max === min ? min + 1 : max];
119
142
  }
120
- /** Every series starts from zero. */
121
143
  const sideBySide = (rows, keys) => {
122
- const columns = keys.map((key) => rows.map((row) => {
123
- const value = valueOf(row, key);
124
- return value === null ? null : { base: 0, top: value, value };
125
- }));
126
- return { domain: extentWithZero(columns), byKey: new Map(keys.map((key, index) => [key, columns[index]])) };
144
+ const columns = keys.map((key) => rows.map((row) => {
145
+ const value = valueOf(row, key);
146
+ return value === null ? null : {
147
+ base: 0,
148
+ top: value,
149
+ value
150
+ };
151
+ }));
152
+ return {
153
+ domain: extentWithZero(columns),
154
+ byKey: new Map(keys.map((key, index) => [key, columns[index]]))
155
+ };
127
156
  };
128
- /** Each series starts where the previous one ended, following `offset`. */
129
157
  function stackedBy(offset) {
130
- return (rows, keys) => {
131
- const layers = stack()
132
- .keys(keys)
133
- .value((row, key) => valueOf(row, key) ?? 0)
134
- .offset(offset)(rows);
135
- const columns = layers.map((layer) => layer.map(([base, top], index) => ({ base, top, value: valueOf(rows[index], layer.key) })));
136
- return { domain: extentWithZero(columns), byKey: new Map(keys.map((key, index) => [key, columns[index]])) };
137
- };
158
+ return (rows, keys) => {
159
+ const columns = stack().keys(keys).value((row, key) => valueOf(row, key) ?? 0).offset(offset)(rows).map((layer) => layer.map(([base, top], index) => ({
160
+ base,
161
+ top,
162
+ value: valueOf(rows[index], layer.key)
163
+ })));
164
+ return {
165
+ domain: extentWithZero(columns),
166
+ byKey: new Map(keys.map((key, index) => [key, columns[index]]))
167
+ };
168
+ };
138
169
  }
139
- /** A continuous stack, so an area keeps its height where a series holds nothing. */
140
170
  const stacked = stackedBy(stackOffsetNone);
141
- /** Positive values stack upwards and negative ones downwards from zero, as bars need. */
142
171
  const stackedDiverging = stackedBy(stackOffsetDiverging);
143
-
144
172
  const VALUE_TICKS = 5;
145
173
  const BAR_RADIUS = 4;
146
- /** What highlights the active category: its whole band behind bars, a rule across lines and areas. */
147
174
  const CURSORS = {
148
- band: (orientation, plot, start, end) => orientation.band(plot, start, end),
149
- line: (orientation, plot, _start, _end, center) => orientation.cursor(plot, center),
175
+ band: (orientation, plot, start, end) => orientation.band(plot, start, end),
176
+ line: (orientation, plot, _start, _end, center) => orientation.cursor(plot, center)
150
177
  };
151
- /** Categories as bands, so bars have a width. */
152
178
  const bands = (count, range) => {
153
- const scale = scaleBand().domain(indices(count)).range(range).paddingInner(0.2).paddingOuter(0.1);
154
- const starts = indices(count).map((index) => scale(index) ?? 0);
155
- return { starts, size: scale.bandwidth(), centers: starts.map((start) => start + scale.bandwidth() / 2) };
179
+ const scale = scaleBand().domain(indices(count)).range(range).paddingInner(.2).paddingOuter(.1);
180
+ const starts = indices(count).map((index) => scale(index) ?? 0);
181
+ return {
182
+ starts,
183
+ size: scale.bandwidth(),
184
+ centers: starts.map((start) => start + scale.bandwidth() / 2)
185
+ };
156
186
  };
157
- /** Categories as points spanning the whole axis, so lines reach both edges. */
158
187
  const points = (count, range) => {
159
- const scale = scalePoint().domain(indices(count)).range(range);
160
- const centers = indices(count).map((index) => scale(index) ?? 0);
161
- return { starts: centers, size: 0, centers };
188
+ const scale = scalePoint().domain(indices(count)).range(range);
189
+ const centers = indices(count).map((index) => scale(index) ?? 0);
190
+ return {
191
+ starts: centers,
192
+ size: 0,
193
+ centers
194
+ };
162
195
  };
163
- /** Bars of every series side by side inside the category band. */
164
196
  const groupedBars = {
165
- cursor: 'band',
166
- points: false,
167
- marks: ({ categories, orientation, scale, series, values }) => {
168
- const inner = scaleBand()
169
- .domain(series.map((item) => item.key))
170
- .range([0, categories.size])
171
- .padding(0.1);
172
- return series.flatMap((item) => barsOf(values, item).map(({ index, value }) => ({
173
- color: item.color,
174
- d: orientation.bar(categories.starts[index] + (inner(item.key) ?? 0), inner.bandwidth(), scale(value.base), scale(value.top), BAR_RADIUS),
175
- hit: index,
176
- key: item.key,
177
- paint: 'fill',
178
- })));
179
- },
197
+ cursor: "band",
198
+ points: false,
199
+ marks: ({ categories, orientation, scale, series, values }) => {
200
+ const inner = scaleBand().domain(series.map((item) => item.key)).range([0, categories.size]).padding(.1);
201
+ return series.flatMap((item) => barsOf(values, item).map(({ index, value }) => ({
202
+ color: item.color,
203
+ d: orientation.bar(categories.starts[index] + (inner(item.key) ?? 0), inner.bandwidth(), scale(value.base), scale(value.top), BAR_RADIUS),
204
+ hit: index,
205
+ key: item.key,
206
+ paint: "fill"
207
+ })));
208
+ }
180
209
  };
181
- /** One bar per category, each series a segment of it. */
182
210
  const stackedBars = {
183
- cursor: 'band',
184
- points: false,
185
- marks: ({ categories, orientation, scale, series, values }) => series.flatMap((item) => barsOf(values, item).map(({ index, value }) => ({
186
- color: item.color,
187
- d: orientation.bar(categories.starts[index], categories.size, scale(value.base), scale(value.top), 0),
188
- hit: index,
189
- key: item.key,
190
- paint: 'fill',
191
- }))),
211
+ cursor: "band",
212
+ points: false,
213
+ marks: ({ categories, orientation, scale, series, values }) => series.flatMap((item) => barsOf(values, item).map(({ index, value }) => ({
214
+ color: item.color,
215
+ d: orientation.bar(categories.starts[index], categories.size, scale(value.base), scale(value.top), 0),
216
+ hit: index,
217
+ key: item.key,
218
+ paint: "fill"
219
+ })))
192
220
  };
193
221
  const lines = {
194
- cursor: 'line',
195
- points: true,
196
- marks: (frame) => frame.series.map((item) => strokeOf(frame, item)),
222
+ cursor: "line",
223
+ points: true,
224
+ marks: (frame) => frame.series.map((item) => strokeOf(frame, item))
197
225
  };
198
- /** A translucent band under each series, outlined by its line. */
199
226
  const areas = {
200
- cursor: 'line',
201
- points: true,
202
- marks: (frame) => frame.series.flatMap((item) => [
203
- {
204
- color: item.color,
205
- d: frame.orientation.area(spansOf(frame, item)),
206
- hit: null,
207
- key: item.key,
208
- paint: 'area',
209
- },
210
- strokeOf(frame, item),
211
- ]),
227
+ cursor: "line",
228
+ points: true,
229
+ marks: (frame) => frame.series.flatMap((item) => [{
230
+ color: item.color,
231
+ d: frame.orientation.area(spansOf(frame, item)),
232
+ hit: null,
233
+ key: item.key,
234
+ paint: "area"
235
+ }, strokeOf(frame, item)])
212
236
  };
213
- /** A bar, line or area chart: the categories along one axis, the values along the other. */
214
237
  function cartesianLayout(options) {
215
- return (input) => {
216
- const series = seriesOf(input.config);
217
- const table = tableOf$1(input, series);
218
- if (input.data.length === 0 || series.length === 0) {
219
- return emptyScene(table);
220
- }
221
- return sceneOf(options, input, series, table);
222
- };
238
+ return (input) => {
239
+ const series = seriesOf(input.config);
240
+ const table = tableOf$1(input, series);
241
+ if (input.data.length === 0 || series.length === 0) return emptyScene(table);
242
+ return sceneOf(options, input, series, table);
243
+ };
223
244
  }
224
245
  function sceneOf(options, input, series, table) {
225
- const { orientation } = options;
226
- const values = options.values(input.data, series.map((item) => item.key));
227
- const value = scaleLinear().domain(values.domain).nice();
228
- const labelWidth = textWidth(value.ticks(VALUE_TICKS).map((tick) => input.valueFormat(tick)));
229
- const titles = input.data.map((row) => titleOf(input, row));
230
- const margins = orientation.margins(input.width, labelWidth, textWidth(titles));
231
- const plot = {
232
- top: margins.top,
233
- left: margins.left,
234
- right: Math.max(margins.left + 1, input.width - margins.right),
235
- bottom: Math.max(margins.top + 1, input.height - margins.bottom),
236
- };
237
- const tickCount = orientation.valueTickCount(plot, labelWidth);
238
- const candidates = value.ticks(tickCount);
239
- const tickValues = candidates.filter((_tick, index) => index % Math.ceil(candidates.length / tickCount) === 0);
240
- const valueLabels = tickValues.map((tick) => input.valueFormat(tick));
241
- const scale = value.range(orientation.valueRange(plot));
242
- const range = orientation.categoryRange(plot);
243
- const categories = options.categories(input.data.length, range);
244
- const frame = { categories, orientation, scale, series, values };
245
- const boundaries = boundariesOf(categories.centers, range);
246
- return {
247
- cursorPaint: options.marks.cursor,
248
- empty: false,
249
- grid: tickValues.map((tick) => orientation.grid(plot, scale(tick))),
250
- hits: categories.centers.map((center, index) => ({
251
- anchor: orientation.anchor(plot, center),
252
- cursor: CURSORS[options.marks.cursor](orientation, plot, boundaries[index], boundaries[index + 1], center),
253
- d: orientation.band(plot, boundaries[index], boundaries[index + 1]),
254
- points: options.marks.points ? pointsOf(frame, index) : [],
255
- tooltip: tooltipOf(input, series, values, index, titles[index]),
256
- })),
257
- marks: options.marks.marks(frame),
258
- origin: { x: 0, y: 0 },
259
- table,
260
- ticks: [
261
- ...tickValues.map((tick, index) => orientation.valueTick(plot, scale(tick), valueLabels[index])),
262
- ...categoryTicksOf(orientation, plot, margins, categories.centers, range, titles),
263
- ],
264
- };
246
+ const { orientation } = options;
247
+ const values = options.values(input.data, series.map((item) => item.key));
248
+ const value = scaleLinear().domain(values.domain).nice();
249
+ const labelWidth = textWidth(value.ticks(VALUE_TICKS).map((tick) => input.valueFormat(tick)));
250
+ const titles = input.data.map((row) => titleOf(input, row));
251
+ const margins = orientation.margins(input.width, labelWidth, textWidth(titles));
252
+ const plot = {
253
+ top: margins.top,
254
+ left: margins.left,
255
+ right: Math.max(margins.left + 1, input.width - margins.right),
256
+ bottom: Math.max(margins.top + 1, input.height - margins.bottom)
257
+ };
258
+ const tickCount = orientation.valueTickCount(plot, labelWidth);
259
+ const candidates = value.ticks(tickCount);
260
+ const tickValues = candidates.filter((_tick, index) => index % Math.ceil(candidates.length / tickCount) === 0);
261
+ const valueLabels = tickValues.map((tick) => input.valueFormat(tick));
262
+ const scale = value.range(orientation.valueRange(plot));
263
+ const range = orientation.categoryRange(plot);
264
+ const categories = options.categories(input.data.length, range);
265
+ const frame = {
266
+ categories,
267
+ orientation,
268
+ scale,
269
+ series,
270
+ values
271
+ };
272
+ const boundaries = boundariesOf(categories.centers, range);
273
+ return {
274
+ cursorPaint: options.marks.cursor,
275
+ empty: false,
276
+ grid: tickValues.map((tick) => orientation.grid(plot, scale(tick))),
277
+ hits: categories.centers.map((center, index) => ({
278
+ anchor: orientation.anchor(plot, center),
279
+ cursor: CURSORS[options.marks.cursor](orientation, plot, boundaries[index], boundaries[index + 1], center),
280
+ d: orientation.band(plot, boundaries[index], boundaries[index + 1]),
281
+ points: options.marks.points ? pointsOf(frame, index) : [],
282
+ tooltip: tooltipOf(input, series, values, index, titles[index])
283
+ })),
284
+ marks: options.marks.marks(frame),
285
+ origin: {
286
+ x: 0,
287
+ y: 0
288
+ },
289
+ table,
290
+ ticks: [...tickValues.map((tick, index) => orientation.valueTick(plot, scale(tick), valueLabels[index])), ...categoryTicksOf(orientation, plot, margins, categories.centers, range, titles)]
291
+ };
265
292
  }
266
293
  function categoryTicksOf(orientation, plot, margins, centers, range, titles) {
267
- const step = Math.abs(range[1] - range[0]) / Math.max(1, centers.length);
268
- const every = Math.max(1, Math.ceil(orientation.categoryLabelRoom(textWidth(titles)) / Math.max(step, 1)));
269
- const chars = orientation.categoryLabelChars(margins);
270
- return centers
271
- .map((center, index) => orientation.categoryTick(plot, center, truncate(titles[index], chars)))
272
- .filter((_tick, index) => index % every === 0);
294
+ const step = Math.abs(range[1] - range[0]) / Math.max(1, centers.length);
295
+ const every = Math.max(1, Math.ceil(orientation.categoryLabelRoom(textWidth(titles)) / Math.max(step, 1)));
296
+ const chars = orientation.categoryLabelChars(margins);
297
+ return centers.map((center, index) => orientation.categoryTick(plot, center, truncate(titles[index], chars))).filter((_tick, index) => index % every === 0);
273
298
  }
274
299
  function pointsOf({ categories, orientation, scale, series, values }, index) {
275
- return series.flatMap((item) => {
276
- const value = values.byKey.get(item.key)?.[index];
277
- if (!value || value.value === null) {
278
- return [];
279
- }
280
- const [cx, cy] = orientation.point(categories.centers[index], scale(value.top));
281
- return [{ color: item.color, cx, cy, key: item.key }];
282
- });
300
+ return series.flatMap((item) => {
301
+ const value = values.byKey.get(item.key)?.[index];
302
+ if (!value || value.value === null) return [];
303
+ const [cx, cy] = orientation.point(categories.centers[index], scale(value.top));
304
+ return [{
305
+ color: item.color,
306
+ cx,
307
+ cy,
308
+ key: item.key
309
+ }];
310
+ });
283
311
  }
284
312
  function strokeOf({ categories, orientation, scale, values }, item) {
285
- const coordinates = (values.byKey.get(item.key) ?? []).map((value, index) => value ? orientation.point(categories.centers[index], scale(value.top)) : null);
286
- const path = line()
287
- .defined((point) => point !== null)
288
- .x((point) => point?.[0] ?? 0)
289
- .y((point) => point?.[1] ?? 0)
290
- .curve(orientation.curve);
291
- return { color: item.color, d: path(coordinates) ?? '', hit: null, key: item.key, paint: 'stroke' };
313
+ const coordinates = (values.byKey.get(item.key) ?? []).map((value, index) => value ? orientation.point(categories.centers[index], scale(value.top)) : null);
314
+ const path = line().defined((point) => point !== null).x((point) => point?.[0] ?? 0).y((point) => point?.[1] ?? 0).curve(orientation.curve);
315
+ return {
316
+ color: item.color,
317
+ d: path(coordinates) ?? "",
318
+ hit: null,
319
+ key: item.key,
320
+ paint: "stroke"
321
+ };
292
322
  }
293
323
  function spansOf({ categories, scale, values }, item) {
294
- return (values.byKey.get(item.key) ?? []).flatMap((value, index) => value ? [{ base: scale(value.base), category: categories.centers[index], top: scale(value.top) }] : []);
324
+ return (values.byKey.get(item.key) ?? []).flatMap((value, index) => value ? [{
325
+ base: scale(value.base),
326
+ category: categories.centers[index],
327
+ top: scale(value.top)
328
+ }] : []);
295
329
  }
296
330
  function barsOf(values, item) {
297
- return (values.byKey.get(item.key) ?? []).flatMap((value, index) => value && value.value !== null && value.base !== value.top ? [{ index, value }] : []);
331
+ return (values.byKey.get(item.key) ?? []).flatMap((value, index) => value && value.value !== null && value.base !== value.top ? [{
332
+ index,
333
+ value
334
+ }] : []);
298
335
  }
299
336
  function tooltipOf(input, series, values, index, title) {
300
- return {
301
- title: input.categoryKey === undefined ? null : title,
302
- items: series.flatMap((item) => {
303
- const value = values.byKey.get(item.key)?.[index]?.value ?? null;
304
- return value === null
305
- ? []
306
- : [{ color: item.color, key: item.key, label: item.label, value: input.valueFormat(value) }];
307
- }),
308
- };
337
+ return {
338
+ title: input.categoryKey === void 0 ? null : title,
339
+ items: series.flatMap((item) => {
340
+ const value = values.byKey.get(item.key)?.[index]?.value ?? null;
341
+ return value === null ? [] : [{
342
+ color: item.color,
343
+ key: item.key,
344
+ label: item.label,
345
+ value: input.valueFormat(value)
346
+ }];
347
+ })
348
+ };
309
349
  }
310
350
  function tableOf$1(input, series) {
311
- return {
312
- corner: input.categoryLabel ?? '',
313
- head: series.map((item) => item.label),
314
- rows: input.data.map((row) => ({
315
- header: titleOf(input, row),
316
- cells: series.map((item) => {
317
- const value = valueOf(row, item.key);
318
- return value === null ? '' : input.valueFormat(value);
319
- }),
320
- })),
321
- };
351
+ return {
352
+ corner: input.categoryLabel ?? "",
353
+ head: series.map((item) => item.label),
354
+ rows: input.data.map((row) => ({
355
+ header: titleOf(input, row),
356
+ cells: series.map((item) => {
357
+ const value = valueOf(row, item.key);
358
+ return value === null ? "" : input.valueFormat(value);
359
+ })
360
+ }))
361
+ };
322
362
  }
323
363
  function titleOf(input, row) {
324
- return input.categoryKey === undefined ? '' : input.categoryFormat(row[input.categoryKey]);
364
+ return input.categoryKey === void 0 ? "" : input.categoryFormat(row[input.categoryKey]);
325
365
  }
326
- /** Edges between consecutive categories, so every pixel of the axis activates the nearest one. */
327
366
  function boundariesOf(centers, range) {
328
- const middles = centers.slice(1).map((center, index) => (centers[index] + center) / 2);
329
- return [range[0], ...middles, range[1]];
367
+ const middles = centers.slice(1).map((center, index) => (centers[index] + center) / 2);
368
+ return [
369
+ range[0],
370
+ ...middles,
371
+ range[1]
372
+ ];
330
373
  }
331
374
  function truncate(label, chars) {
332
- return label.length > chars ? `${label.slice(0, Math.max(1, chars - 1))}…` : label;
375
+ return label.length > chars ? `${label.slice(0, Math.max(1, chars - 1))}…` : label;
333
376
  }
334
377
  function indices(count) {
335
- return Array.from({ length: count }, (_, index) => index);
378
+ return Array.from({ length: count }, (_, index) => index);
336
379
  }
337
-
338
380
  const EDGE = 4;
339
- /** One slice per series, sized by its value summed across every row. */
340
381
  function pieLayout(options) {
341
- return (input) => {
342
- const slices = slicesOf(input);
343
- const table = tableOf(input, slices);
344
- const shown = slices.filter((slice) => slice.total > 0);
345
- if (shown.length === 0) {
346
- return emptyScene(table);
347
- }
348
- const radius = Math.max(1, Math.min(input.width, input.height) / 2 - EDGE);
349
- const centerX = input.width / 2;
350
- const centerY = input.height / 2;
351
- const arcs = pie()
352
- .sort(null)
353
- .value((slice) => slice.total)(shown);
354
- const shape = arc()
355
- .innerRadius(radius * options.hole)
356
- .outerRadius(radius)
357
- .padAngle(options.hole > 0 ? 0.01 : 0)
358
- .cornerRadius(options.hole > 0 ? 3 : 0);
359
- const paths = arcs.map((datum) => shape(datum) ?? '');
360
- return {
361
- cursorPaint: 'band',
362
- empty: false,
363
- grid: [],
364
- origin: { x: centerX, y: centerY },
365
- hits: arcs.map((datum, index) => {
366
- const [x, y] = shape.centroid(datum);
367
- return {
368
- anchor: { x: centerX + x, y: centerY + y },
369
- cursor: null,
370
- d: paths[index],
371
- points: [],
372
- tooltip: {
373
- title: null,
374
- items: [
375
- {
376
- color: datum.data.color,
377
- key: datum.data.key,
378
- label: datum.data.label,
379
- value: input.valueFormat(datum.data.total),
380
- },
381
- ],
382
- },
383
- };
384
- }),
385
- marks: arcs.map((datum, index) => ({
386
- color: datum.data.color,
387
- d: paths[index],
388
- hit: index,
389
- key: datum.data.key,
390
- paint: 'fill',
391
- })),
392
- table,
393
- ticks: [],
394
- };
395
- };
382
+ return (input) => {
383
+ const slices = slicesOf(input);
384
+ const table = tableOf(input, slices);
385
+ const shown = slices.filter((slice) => slice.total > 0);
386
+ if (shown.length === 0) return emptyScene(table);
387
+ const radius = Math.max(1, Math.min(input.width, input.height) / 2 - EDGE);
388
+ const centerX = input.width / 2;
389
+ const centerY = input.height / 2;
390
+ const arcs = pie().sort(null).value((slice) => slice.total)(shown);
391
+ const shape = arc().innerRadius(radius * options.hole).outerRadius(radius).padAngle(options.hole > 0 ? .01 : 0).cornerRadius(options.hole > 0 ? 3 : 0);
392
+ const paths = arcs.map((datum) => shape(datum) ?? "");
393
+ return {
394
+ cursorPaint: "band",
395
+ empty: false,
396
+ grid: [],
397
+ origin: {
398
+ x: centerX,
399
+ y: centerY
400
+ },
401
+ hits: arcs.map((datum, index) => {
402
+ const [x, y] = shape.centroid(datum);
403
+ return {
404
+ anchor: {
405
+ x: centerX + x,
406
+ y: centerY + y
407
+ },
408
+ cursor: null,
409
+ d: paths[index],
410
+ points: [],
411
+ tooltip: {
412
+ title: null,
413
+ items: [{
414
+ color: datum.data.color,
415
+ key: datum.data.key,
416
+ label: datum.data.label,
417
+ value: input.valueFormat(datum.data.total)
418
+ }]
419
+ }
420
+ };
421
+ }),
422
+ marks: arcs.map((datum, index) => ({
423
+ color: datum.data.color,
424
+ d: paths[index],
425
+ hit: index,
426
+ key: datum.data.key,
427
+ paint: "fill"
428
+ })),
429
+ table,
430
+ ticks: []
431
+ };
432
+ };
396
433
  }
397
434
  function slicesOf(input) {
398
- return seriesOf(input.config).map((series) => ({
399
- ...series,
400
- total: input.data.reduce((sum, row) => sum + Math.max(0, valueOf(row, series.key) ?? 0), 0),
401
- }));
435
+ return seriesOf(input.config).map((series) => ({
436
+ ...series,
437
+ total: input.data.reduce((sum, row) => sum + Math.max(0, valueOf(row, series.key) ?? 0), 0)
438
+ }));
402
439
  }
403
440
  function tableOf(input, slices) {
404
- return {
405
- corner: null,
406
- head: slices.map((slice) => slice.label),
407
- rows: input.data.length === 0 ? [] : [{ header: null, cells: slices.map((slice) => input.valueFormat(slice.total)) }],
408
- };
441
+ return {
442
+ corner: null,
443
+ head: slices.map((slice) => slice.label),
444
+ rows: input.data.length === 0 ? [] : [{
445
+ header: null,
446
+ cells: slices.map((slice) => input.valueFormat(slice.total))
447
+ }]
448
+ };
409
449
  }
410
-
411
- /** The layout drawing each chart kind. A new kind is one entry here, built from the same parts. */
412
450
  const YUW_CHART_LAYOUTS = {
413
- area: cartesianLayout({ categories: points, marks: areas, orientation: VERTICAL, values: sideBySide }),
414
- 'area-stacked': cartesianLayout({ categories: points, marks: areas, orientation: VERTICAL, values: stacked }),
415
- bar: cartesianLayout({ categories: bands, marks: groupedBars, orientation: VERTICAL, values: sideBySide }),
416
- 'bar-horizontal': cartesianLayout({
417
- categories: bands,
418
- marks: groupedBars,
419
- orientation: HORIZONTAL,
420
- values: sideBySide,
421
- }),
422
- 'bar-horizontal-stacked': cartesianLayout({
423
- categories: bands,
424
- marks: stackedBars,
425
- orientation: HORIZONTAL,
426
- values: stackedDiverging,
427
- }),
428
- 'bar-stacked': cartesianLayout({
429
- categories: bands,
430
- marks: stackedBars,
431
- orientation: VERTICAL,
432
- values: stackedDiverging,
433
- }),
434
- donut: pieLayout({ hole: 0.6 }),
435
- line: cartesianLayout({ categories: points, marks: lines, orientation: VERTICAL, values: sideBySide }),
436
- pie: pieLayout({ hole: 0 }),
451
+ area: cartesianLayout({
452
+ categories: points,
453
+ marks: areas,
454
+ orientation: VERTICAL,
455
+ values: sideBySide
456
+ }),
457
+ "area-stacked": cartesianLayout({
458
+ categories: points,
459
+ marks: areas,
460
+ orientation: VERTICAL,
461
+ values: stacked
462
+ }),
463
+ bar: cartesianLayout({
464
+ categories: bands,
465
+ marks: groupedBars,
466
+ orientation: VERTICAL,
467
+ values: sideBySide
468
+ }),
469
+ "bar-horizontal": cartesianLayout({
470
+ categories: bands,
471
+ marks: groupedBars,
472
+ orientation: HORIZONTAL,
473
+ values: sideBySide
474
+ }),
475
+ "bar-horizontal-stacked": cartesianLayout({
476
+ categories: bands,
477
+ marks: stackedBars,
478
+ orientation: HORIZONTAL,
479
+ values: stackedDiverging
480
+ }),
481
+ "bar-stacked": cartesianLayout({
482
+ categories: bands,
483
+ marks: stackedBars,
484
+ orientation: VERTICAL,
485
+ values: stackedDiverging
486
+ }),
487
+ donut: pieLayout({ hole: .6 }),
488
+ line: cartesianLayout({
489
+ categories: points,
490
+ marks: lines,
491
+ orientation: VERTICAL,
492
+ values: sideBySide
493
+ }),
494
+ pie: pieLayout({ hole: 0 })
495
+ };
496
+ const UNMEASURED = {
497
+ height: 0,
498
+ width: 0
437
499
  };
438
-
439
- const UNMEASURED = { height: 0, width: 0 };
440
- /**
441
- * Tracks the content box of `element` as a signal. Stays at zero on the server and wherever `ResizeObserver` is
442
- * missing, so nothing is drawn until there is a real box to draw into. Must be called in an injection context.
443
- */
444
500
  function injectChartSize(element) {
445
- const size = signal(UNMEASURED, { ...(ngDevMode ? { debugName: "size" } : /* istanbul ignore next */ {}), equal: (a, b) => a.width === b.width && a.height === b.height });
446
- const destroyRef = inject(DestroyRef);
447
- afterNextRender(() => {
448
- const target = element()?.nativeElement;
449
- if (!target || typeof ResizeObserver === 'undefined') {
450
- return;
451
- }
452
- const observer = new ResizeObserver(([entry]) => size.set({ width: Math.floor(entry.contentRect.width), height: Math.floor(entry.contentRect.height) }));
453
- observer.observe(target);
454
- destroyRef.onDestroy(() => observer.disconnect());
455
- });
456
- return size.asReadonly();
501
+ const size = signal(UNMEASURED, {
502
+ ...ngDevMode ? { debugName: "size" } : /* istanbul ignore next */ {},
503
+ equal: (a, b) => a.width === b.width && a.height === b.height
504
+ });
505
+ const destroyRef = inject(DestroyRef);
506
+ afterNextRender(() => {
507
+ const target = element()?.nativeElement;
508
+ if (!target || typeof ResizeObserver === "undefined") return;
509
+ const observer = new ResizeObserver(([entry]) => size.set({
510
+ width: Math.floor(entry.contentRect.width),
511
+ height: Math.floor(entry.contentRect.height)
512
+ }));
513
+ observer.observe(target);
514
+ destroyRef.onDestroy(() => observer.disconnect());
515
+ });
516
+ return size.asReadonly();
457
517
  }
458
-
459
- /** Classes of each kind of mark; the color arrives separately, as a `var(--chart-n)` style. */
460
518
  const MARK_CLASS = {
461
- area: 'opacity-30',
462
- fill: 'stroke-background stroke-1 motion-safe:transition-opacity motion-safe:duration-150',
463
- stroke: 'fill-none stroke-2',
519
+ area: "opacity-30",
520
+ fill: "stroke-background stroke-1 motion-safe:transition-opacity motion-safe:duration-150",
521
+ stroke: "fill-none stroke-2"
464
522
  };
465
- /** Which style property carries the color of each kind of mark. */
466
523
  const MARK_COLOR_PROPERTY = {
467
- area: 'fill',
468
- fill: 'fill',
469
- stroke: 'stroke',
524
+ area: "fill",
525
+ fill: "fill",
526
+ stroke: "stroke"
470
527
  };
471
- const MARK_DIMMED_CLASS = 'opacity-40';
472
528
  const CURSOR_CLASS = {
473
- band: 'fill-muted',
474
- line: 'fill-none stroke-border stroke-1',
529
+ band: "fill-muted",
530
+ line: "fill-none stroke-border stroke-1"
475
531
  };
476
- /** Which side of its anchor the tooltip opens to, so it stays inside the plot. */
477
532
  const TOOLTIP_SIDE_CLASS = {
478
- left: '-translate-x-[calc(100%+0.75rem)]',
479
- right: 'translate-x-3',
533
+ left: "-translate-x-[calc(100%+0.75rem)]",
534
+ right: "translate-x-3"
480
535
  };
481
- /** What each key does to the active position, given it and how many there are; `null` hides the tooltip. */
482
536
  const KEY_MOVES = {
483
- ArrowDown: (active, count) => Math.min(active + 1, count - 1),
484
- ArrowLeft: (active) => Math.max(active - 1, 0),
485
- ArrowRight: (active, count) => Math.min(active + 1, count - 1),
486
- ArrowUp: (active) => Math.max(active - 1, 0),
487
- End: (_active, count) => count - 1,
488
- Escape: () => null,
489
- Home: () => 0,
537
+ ArrowDown: (active, count) => Math.min(active + 1, count - 1),
538
+ ArrowLeft: (active) => Math.max(active - 1, 0),
539
+ ArrowRight: (active, count) => Math.min(active + 1, count - 1),
540
+ ArrowUp: (active) => Math.max(active - 1, 0),
541
+ End: (_active, count) => count - 1,
542
+ Escape: () => null,
543
+ Home: () => 0
490
544
  };
491
-
492
- /**
493
- * Chart drawn as SVG from a series `config` and `data` rows, with a tooltip and a legend that read the same config.
494
- *
495
- * Every series is a key of `config` naming the row field that holds its values, plus its label (already translated)
496
- * and a `chart-n` color token, so light and dark mode recolor through the theme with no redraw. `kind` picks the
497
- * drawing: bars (grouped, stacked, horizontal), lines, areas, or a pie / donut with one slice per series summed across
498
- * the rows. The chart fills its root element and redraws when it resizes; size it with `class` (default `h-72`).
499
- *
500
- * The pointer and the keyboard (focus the plot, then the arrow keys, Home, End and Escape) move a tooltip across the
501
- * categories or slices, announced politely to screen readers. The same numbers are always available to assistive
502
- * technology as a visually hidden table, which also renders on the server, where the plot is not drawn.
503
- *
504
- * The library hardcodes no locale: `valueFormat` and `categoryFormat` turn values and categories into text.
505
- *
506
- * Inputs:
507
- * - `ariaLabel`: Required accessible name of the chart, e.g. its title. The app supplies and translates it.
508
- * - `categoryFormat`: Turns the value under `categoryKey` into its label. Cartesian kinds only. Default is `String`.
509
- * - `categoryKey`: Row field holding each category, e.g. the period. Cartesian kinds only. Default is `undefined`.
510
- * - `categoryLabel`: Header of the category column in the accessible table, e.g. "Month". Cartesian kinds only.
511
- * Default is `undefined`.
512
- * - `config`: Required series, keyed by the row field holding their values (`YuwChartConfigDto`). Its order is the
513
- * drawing, stacking, legend and tooltip order.
514
- * - `data`: Required rows (`YuwChartRowDto[]`). A non-numeric value is a gap, never a zero.
515
- * - `description`: Accessible description, e.g. the period the chart covers. Default is `undefined`.
516
- * - `emptyText`: Required message shown when there is nothing to draw. The app supplies and translates it.
517
- * - `kind`: The drawing (`YuwChartKindDto`). Default is `'bar'`.
518
- * - `legend`: Shows the legend under the plot. Default is `true`.
519
- * - `loading`: Shows a skeleton instead of the plot and marks the chart busy. Default is `false`.
520
- * - `valueFormat`: Turns a value into the text of axes, tooltips and the accessible table, e.g. a localized currency.
521
- * Default is `String`.
522
- * - `class`: Extra classes merged last onto the root element; set its height here.
523
- *
524
- * Usage:
525
- * ```html
526
- * <yuw-chart
527
- * kind="bar-stacked"
528
- * ariaLabel="Purchases per month"
529
- * emptyText="No purchases in this period"
530
- * categoryKey="month"
531
- * categoryLabel="Month"
532
- * [config]="config"
533
- * [data]="rows"
534
- * [valueFormat]="formatEuros"
535
- * class="h-80"
536
- * />
537
- * ```
538
- */
539
- class YuwChartComponent {
540
- constructor() {
541
- this._id = inject(_IdGenerator).getId('yuw-chart-');
542
- this._plot = viewChild('plot', ...(ngDevMode ? [{ debugName: "_plot" }] : /* istanbul ignore next */ []));
543
- this.ariaLabel = input.required(...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
544
- this.categoryFormat = input(String, ...(ngDevMode ? [{ debugName: "categoryFormat" }] : /* istanbul ignore next */ []));
545
- this.categoryKey = input(...(ngDevMode ? [undefined, { debugName: "categoryKey" }] : /* istanbul ignore next */ []));
546
- this.categoryLabel = input(...(ngDevMode ? [undefined, { debugName: "categoryLabel" }] : /* istanbul ignore next */ []));
547
- this.config = input.required(...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
548
- this.data = input.required(...(ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []));
549
- this.description = input(...(ngDevMode ? [undefined, { debugName: "description" }] : /* istanbul ignore next */ []));
550
- this.emptyText = input.required(...(ngDevMode ? [{ debugName: "emptyText" }] : /* istanbul ignore next */ []));
551
- this.kind = input('bar', ...(ngDevMode ? [{ debugName: "kind" }] : /* istanbul ignore next */ []));
552
- this.legend = input(true, { ...(ngDevMode ? { debugName: "legend" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
553
- this.loading = input(false, { ...(ngDevMode ? { debugName: "loading" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
554
- this.userClass = input('', { ...(ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {}), alias: 'class' });
555
- this.valueFormat = input(String, ...(ngDevMode ? [{ debugName: "valueFormat" }] : /* istanbul ignore next */ []));
556
- this.descriptionId = `${this._id}-description`;
557
- this.size = injectChartSize(this._plot);
558
- this.scene = computed(() => YUW_CHART_LAYOUTS[this.kind()]({
559
- categoryFormat: this.categoryFormat(),
560
- categoryKey: this.categoryKey(),
561
- categoryLabel: this.categoryLabel(),
562
- config: this.config(),
563
- data: this.data(),
564
- height: this.size().height,
565
- valueFormat: this.valueFormat(),
566
- width: this.size().width,
567
- }), ...(ngDevMode ? [{ debugName: "scene" }] : /* istanbul ignore next */ []));
568
- this.active = linkedSignal({ ...(ngDevMode ? { debugName: "active" } : /* istanbul ignore next */ {}), source: this.scene, computation: () => null });
569
- this.activeHit = computed(() => {
570
- const active = this.active();
571
- return active === null ? null : (this.scene().hits[active] ?? null);
572
- }, ...(ngDevMode ? [{ debugName: "activeHit" }] : /* istanbul ignore next */ []));
573
- this.activePoints = computed(() => this.activeHit()?.points ?? [], ...(ngDevMode ? [{ debugName: "activePoints" }] : /* istanbul ignore next */ []));
574
- this.announcement = computed(() => {
575
- const tooltip = this.activeHit()?.tooltip;
576
- if (!tooltip) {
577
- return '';
578
- }
579
- return [tooltip.title, ...tooltip.items.map((item) => `${item.label}: ${item.value}`)]
580
- .filter((part) => !!part)
581
- .join(', ');
582
- }, ...(ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []));
583
- this.cursorClass = computed(() => CURSOR_CLASS[this.scene().cursorPaint], ...(ngDevMode ? [{ debugName: "cursorClass" }] : /* istanbul ignore next */ []));
584
- this.describedBy = computed(() => (this.description() ? this.descriptionId : null), ...(ngDevMode ? [{ debugName: "describedBy" }] : /* istanbul ignore next */ []));
585
- this.drawable = computed(() => this.size().width > 0 && this.size().height > 0, ...(ngDevMode ? [{ debugName: "drawable" }] : /* istanbul ignore next */ []));
586
- this.interactive = computed(() => !this.loading() && this.scene().hits.length > 0, ...(ngDevMode ? [{ debugName: "interactive" }] : /* istanbul ignore next */ []));
587
- this.legendItems = computed(() => Object.entries(this.config()).map(([key, series]) => ({ key, label: series.label, color: cssColor(series.color) })), ...(ngDevMode ? [{ debugName: "legendItems" }] : /* istanbul ignore next */ []));
588
- this.marks = computed(() => {
589
- const active = this.active();
590
- return this.scene().marks.map((mark) => ({
591
- d: mark.d,
592
- key: mark.key,
593
- class: hlm(MARK_CLASS[mark.paint], active !== null && mark.hit !== null && mark.hit !== active && MARK_DIMMED_CLASS),
594
- style: { [MARK_COLOR_PROPERTY[mark.paint]]: mark.color },
595
- }));
596
- }, ...(ngDevMode ? [{ debugName: "marks" }] : /* istanbul ignore next */ []));
597
- this.origin = computed(() => `translate(${this.scene().origin.x},${this.scene().origin.y})`, ...(ngDevMode ? [{ debugName: "origin" }] : /* istanbul ignore next */ []));
598
- this.rootClass = computed(() => hlm('flex h-72 w-full flex-col gap-3', this.userClass()), ...(ngDevMode ? [{ debugName: "rootClass" }] : /* istanbul ignore next */ []));
599
- this.showLegend = computed(() => this.legend() && !this.loading() && !this.scene().empty, ...(ngDevMode ? [{ debugName: "showLegend" }] : /* istanbul ignore next */ []));
600
- this.tooltip = computed(() => {
601
- const hit = this.activeHit();
602
- if (!hit || hit.tooltip.items.length === 0) {
603
- return null;
604
- }
605
- return {
606
- ...hit.tooltip,
607
- left: hit.anchor.x,
608
- top: hit.anchor.y,
609
- class: TOOLTIP_SIDE_CLASS[hit.anchor.x > this.size().width / 2 ? 'left' : 'right'],
610
- };
611
- }, ...(ngDevMode ? [{ debugName: "tooltip" }] : /* istanbul ignore next */ []));
612
- this.viewBox = computed(() => `0 0 ${this.size().width} ${this.size().height}`, ...(ngDevMode ? [{ debugName: "viewBox" }] : /* istanbul ignore next */ []));
613
- }
614
- activate(index) {
615
- this.active.set(index);
616
- }
617
- clear() {
618
- this.active.set(null);
619
- }
620
- onFocus(event) {
621
- const target = event.target;
622
- if (this.active() === null && target.matches(':focus-visible')) {
623
- this.active.set(0);
624
- }
625
- }
626
- onKeydown(event) {
627
- const move = KEY_MOVES[event.key];
628
- const count = this.scene().hits.length;
629
- if (!move || count === 0) {
630
- return;
631
- }
632
- event.preventDefault();
633
- this.active.set(move(this.active() ?? -1, count));
634
- }
635
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.22", ngImport: i0, type: YuwChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
636
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.22", type: YuwChartComponent, isStandalone: true, selector: "yuw-chart", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: true, transformFunction: null }, categoryFormat: { classPropertyName: "categoryFormat", publicName: "categoryFormat", isSignal: true, isRequired: false, transformFunction: null }, categoryKey: { classPropertyName: "categoryKey", publicName: "categoryKey", isSignal: true, isRequired: false, transformFunction: null }, categoryLabel: { classPropertyName: "categoryLabel", publicName: "categoryLabel", isSignal: true, isRequired: false, transformFunction: null }, config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null }, description: { classPropertyName: "description", publicName: "description", isSignal: true, isRequired: false, transformFunction: null }, emptyText: { classPropertyName: "emptyText", publicName: "emptyText", isSignal: true, isRequired: true, transformFunction: null }, kind: { classPropertyName: "kind", publicName: "kind", isSignal: true, isRequired: false, transformFunction: null }, legend: { classPropertyName: "legend", publicName: "legend", isSignal: true, isRequired: false, transformFunction: null }, loading: { classPropertyName: "loading", publicName: "loading", isSignal: true, isRequired: false, transformFunction: null }, userClass: { classPropertyName: "userClass", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, valueFormat: { classPropertyName: "valueFormat", publicName: "valueFormat", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "contents" }, viewQueries: [{ propertyName: "_plot", first: true, predicate: ["plot"], descendants: true, isSignal: true }], ngImport: i0, template: "<div role=\"figure\" [class]=\"rootClass()\" [attr.aria-label]=\"ariaLabel()\" [attr.aria-busy]=\"loading() || null\">\n @if (description(); as text) {\n <p class=\"sr-only\" [id]=\"descriptionId\">{{ text }}</p>\n }\n\n <!-- Plot -->\n <div\n #plot\n role=\"group\"\n class=\"relative min-h-0 flex-1 rounded-md outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-describedby]=\"describedBy()\"\n [attr.tabindex]=\"interactive() ? 0 : null\"\n (focus)=\"onFocus($event)\"\n (blur)=\"clear()\"\n (keydown)=\"onKeydown($event)\"\n (pointerleave)=\"clear()\"\n >\n @if (loading()) {\n <div hlmSkeleton class=\"size-full\" aria-hidden=\"true\"></div>\n } @else if (scene().empty) {\n <div class=\"flex size-full items-center justify-center text-center text-sm text-muted-foreground\">\n {{ emptyText() }}\n </div>\n } @else if (drawable()) {\n <svg\n aria-hidden=\"true\"\n class=\"absolute inset-0 overflow-visible\"\n [attr.width]=\"size().width\"\n [attr.height]=\"size().height\"\n [attr.viewBox]=\"viewBox()\"\n >\n @for (line of scene().grid; track $index) {\n <path class=\"fill-none stroke-border [stroke-dasharray:3_3]\" [attr.d]=\"line\" />\n }\n\n @if (activeHit()?.cursor; as cursor) {\n <path [class]=\"cursorClass()\" [attr.d]=\"cursor\" />\n }\n\n <g [attr.transform]=\"origin()\">\n @for (mark of marks(); track $index) {\n <path [class]=\"mark.class\" [style]=\"mark.style\" [attr.d]=\"mark.d\" />\n }\n </g>\n\n @for (point of activePoints(); track point.key) {\n <circle\n r=\"4\"\n class=\"stroke-background stroke-2\"\n [style.fill]=\"point.color\"\n [attr.cx]=\"point.cx\"\n [attr.cy]=\"point.cy\"\n />\n }\n\n @for (tick of scene().ticks; track $index) {\n <text\n dominant-baseline=\"middle\"\n class=\"fill-muted-foreground text-xs\"\n [attr.x]=\"tick.x\"\n [attr.y]=\"tick.y\"\n [attr.text-anchor]=\"tick.anchor\"\n >\n {{ tick.label }}\n </text>\n }\n\n <g [attr.transform]=\"origin()\">\n @for (hit of scene().hits; track $index) {\n <path class=\"fill-transparent\" [attr.d]=\"hit.d\" (pointerenter)=\"activate($index)\" />\n }\n </g>\n </svg>\n\n @if (tooltip(); as tip) {\n <div\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute z-10 grid min-w-32 -translate-y-1/2 gap-1.5 rounded-md border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-md motion-safe:transition-[left,top] motion-safe:duration-150\"\n [class]=\"tip.class\"\n [style.left.px]=\"tip.left\"\n [style.top.px]=\"tip.top\"\n >\n @if (tip.title) {\n <span class=\"font-medium\">{{ tip.title }}</span>\n }\n @for (item of tip.items; track item.key) {\n <span class=\"flex items-center gap-2\">\n <span class=\"size-2.5 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>\n <span class=\"text-muted-foreground\">{{ item.label }}</span>\n <span class=\"ml-auto font-mono font-medium tabular-nums\">{{ item.value }}</span>\n </span>\n }\n </div>\n }\n }\n\n <div role=\"status\" class=\"sr-only\">{{ announcement() }}</div>\n </div>\n\n <!-- Legend -->\n @if (showLegend()) {\n <ul class=\"flex flex-wrap items-center justify-center gap-x-4 gap-y-1 text-xs text-muted-foreground\">\n @for (item of legendItems(); track item.key) {\n <li class=\"flex items-center gap-1.5\">\n <span aria-hidden=\"true\" class=\"size-2.5 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>\n {{ item.label }}\n </li>\n }\n </ul>\n }\n\n <!-- Accessible data -->\n <table class=\"sr-only\">\n <caption>\n {{ ariaLabel() }}\n </caption>\n <thead>\n <tr>\n @if (scene().table.corner !== null) {\n <th scope=\"col\">{{ scene().table.corner }}</th>\n }\n @for (head of scene().table.head; track $index) {\n <th scope=\"col\">{{ head }}</th>\n }\n </tr>\n </thead>\n <tbody>\n @for (row of scene().table.rows; track $index) {\n <tr>\n @if (row.header !== null) {\n <th scope=\"row\">{{ row.header }}</th>\n }\n @for (cell of row.cells; track $index) {\n <td>{{ cell }}</td>\n }\n </tr>\n }\n </tbody>\n </table>\n</div>\n", dependencies: [{ kind: "directive", type: HlmSkeleton, selector: "[hlmSkeleton],hlm-skeleton" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
637
- }
638
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.22", ngImport: i0, type: YuwChartComponent, decorators: [{
639
- type: Component,
640
- args: [{ selector: 'yuw-chart', imports: [HlmSkeleton], host: {
641
- class: 'contents',
642
- }, changeDetection: ChangeDetectionStrategy.OnPush, template: "<div role=\"figure\" [class]=\"rootClass()\" [attr.aria-label]=\"ariaLabel()\" [attr.aria-busy]=\"loading() || null\">\n @if (description(); as text) {\n <p class=\"sr-only\" [id]=\"descriptionId\">{{ text }}</p>\n }\n\n <!-- Plot -->\n <div\n #plot\n role=\"group\"\n class=\"relative min-h-0 flex-1 rounded-md outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-describedby]=\"describedBy()\"\n [attr.tabindex]=\"interactive() ? 0 : null\"\n (focus)=\"onFocus($event)\"\n (blur)=\"clear()\"\n (keydown)=\"onKeydown($event)\"\n (pointerleave)=\"clear()\"\n >\n @if (loading()) {\n <div hlmSkeleton class=\"size-full\" aria-hidden=\"true\"></div>\n } @else if (scene().empty) {\n <div class=\"flex size-full items-center justify-center text-center text-sm text-muted-foreground\">\n {{ emptyText() }}\n </div>\n } @else if (drawable()) {\n <svg\n aria-hidden=\"true\"\n class=\"absolute inset-0 overflow-visible\"\n [attr.width]=\"size().width\"\n [attr.height]=\"size().height\"\n [attr.viewBox]=\"viewBox()\"\n >\n @for (line of scene().grid; track $index) {\n <path class=\"fill-none stroke-border [stroke-dasharray:3_3]\" [attr.d]=\"line\" />\n }\n\n @if (activeHit()?.cursor; as cursor) {\n <path [class]=\"cursorClass()\" [attr.d]=\"cursor\" />\n }\n\n <g [attr.transform]=\"origin()\">\n @for (mark of marks(); track $index) {\n <path [class]=\"mark.class\" [style]=\"mark.style\" [attr.d]=\"mark.d\" />\n }\n </g>\n\n @for (point of activePoints(); track point.key) {\n <circle\n r=\"4\"\n class=\"stroke-background stroke-2\"\n [style.fill]=\"point.color\"\n [attr.cx]=\"point.cx\"\n [attr.cy]=\"point.cy\"\n />\n }\n\n @for (tick of scene().ticks; track $index) {\n <text\n dominant-baseline=\"middle\"\n class=\"fill-muted-foreground text-xs\"\n [attr.x]=\"tick.x\"\n [attr.y]=\"tick.y\"\n [attr.text-anchor]=\"tick.anchor\"\n >\n {{ tick.label }}\n </text>\n }\n\n <g [attr.transform]=\"origin()\">\n @for (hit of scene().hits; track $index) {\n <path class=\"fill-transparent\" [attr.d]=\"hit.d\" (pointerenter)=\"activate($index)\" />\n }\n </g>\n </svg>\n\n @if (tooltip(); as tip) {\n <div\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute z-10 grid min-w-32 -translate-y-1/2 gap-1.5 rounded-md border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-md motion-safe:transition-[left,top] motion-safe:duration-150\"\n [class]=\"tip.class\"\n [style.left.px]=\"tip.left\"\n [style.top.px]=\"tip.top\"\n >\n @if (tip.title) {\n <span class=\"font-medium\">{{ tip.title }}</span>\n }\n @for (item of tip.items; track item.key) {\n <span class=\"flex items-center gap-2\">\n <span class=\"size-2.5 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>\n <span class=\"text-muted-foreground\">{{ item.label }}</span>\n <span class=\"ml-auto font-mono font-medium tabular-nums\">{{ item.value }}</span>\n </span>\n }\n </div>\n }\n }\n\n <div role=\"status\" class=\"sr-only\">{{ announcement() }}</div>\n </div>\n\n <!-- Legend -->\n @if (showLegend()) {\n <ul class=\"flex flex-wrap items-center justify-center gap-x-4 gap-y-1 text-xs text-muted-foreground\">\n @for (item of legendItems(); track item.key) {\n <li class=\"flex items-center gap-1.5\">\n <span aria-hidden=\"true\" class=\"size-2.5 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>\n {{ item.label }}\n </li>\n }\n </ul>\n }\n\n <!-- Accessible data -->\n <table class=\"sr-only\">\n <caption>\n {{ ariaLabel() }}\n </caption>\n <thead>\n <tr>\n @if (scene().table.corner !== null) {\n <th scope=\"col\">{{ scene().table.corner }}</th>\n }\n @for (head of scene().table.head; track $index) {\n <th scope=\"col\">{{ head }}</th>\n }\n </tr>\n </thead>\n <tbody>\n @for (row of scene().table.rows; track $index) {\n <tr>\n @if (row.header !== null) {\n <th scope=\"row\">{{ row.header }}</th>\n }\n @for (cell of row.cells; track $index) {\n <td>{{ cell }}</td>\n }\n </tr>\n }\n </tbody>\n </table>\n</div>\n" }]
643
- }], propDecorators: { _plot: [{ type: i0.ViewChild, args: ['plot', { isSignal: true }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: true }] }], categoryFormat: [{ type: i0.Input, args: [{ isSignal: true, alias: "categoryFormat", required: false }] }], categoryKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "categoryKey", required: false }] }], categoryLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "categoryLabel", required: false }] }], config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: true }] }], description: [{ type: i0.Input, args: [{ isSignal: true, alias: "description", required: false }] }], emptyText: [{ type: i0.Input, args: [{ isSignal: true, alias: "emptyText", required: true }] }], kind: [{ type: i0.Input, args: [{ isSignal: true, alias: "kind", required: false }] }], legend: [{ type: i0.Input, args: [{ isSignal: true, alias: "legend", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], userClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "class", required: false }] }], valueFormat: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueFormat", required: false }] }] } });
644
-
645
- /**
646
- * Generated bundle index. Do not edit.
647
- */
648
-
545
+ var YuwChartComponent = class YuwChartComponent {
546
+ constructor() {
547
+ this._id = inject(_IdGenerator).getId("yuw-chart-");
548
+ this._plot = viewChild("plot", ...ngDevMode ? [{ debugName: "_plot" }] : /* istanbul ignore next */ []);
549
+ this.ariaLabel = input.required(...ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []);
550
+ this.categoryFormat = input(String, ...ngDevMode ? [{ debugName: "categoryFormat" }] : /* istanbul ignore next */ []);
551
+ this.categoryKey = input(...ngDevMode ? [void 0, { debugName: "categoryKey" }] : /* istanbul ignore next */ []);
552
+ this.categoryLabel = input(...ngDevMode ? [void 0, { debugName: "categoryLabel" }] : /* istanbul ignore next */ []);
553
+ this.config = input.required(...ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []);
554
+ this.data = input.required(...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
555
+ this.description = input(...ngDevMode ? [void 0, { debugName: "description" }] : /* istanbul ignore next */ []);
556
+ this.emptyText = input.required(...ngDevMode ? [{ debugName: "emptyText" }] : /* istanbul ignore next */ []);
557
+ this.kind = input("bar", ...ngDevMode ? [{ debugName: "kind" }] : /* istanbul ignore next */ []);
558
+ this.legend = input(true, {
559
+ ...ngDevMode ? { debugName: "legend" } : /* istanbul ignore next */ {},
560
+ transform: booleanAttribute
561
+ });
562
+ this.loading = input(false, {
563
+ ...ngDevMode ? { debugName: "loading" } : /* istanbul ignore next */ {},
564
+ transform: booleanAttribute
565
+ });
566
+ this.userClass = input("", {
567
+ ...ngDevMode ? { debugName: "userClass" } : /* istanbul ignore next */ {},
568
+ alias: "class"
569
+ });
570
+ this.valueFormat = input(String, ...ngDevMode ? [{ debugName: "valueFormat" }] : /* istanbul ignore next */ []);
571
+ this.descriptionId = `${this._id}-description`;
572
+ this.size = injectChartSize(this._plot);
573
+ this.scene = computed(() => YUW_CHART_LAYOUTS[this.kind()]({
574
+ categoryFormat: this.categoryFormat(),
575
+ categoryKey: this.categoryKey(),
576
+ categoryLabel: this.categoryLabel(),
577
+ config: this.config(),
578
+ data: this.data(),
579
+ height: this.size().height,
580
+ valueFormat: this.valueFormat(),
581
+ width: this.size().width
582
+ }), ...ngDevMode ? [{ debugName: "scene" }] : /* istanbul ignore next */ []);
583
+ this.active = linkedSignal({
584
+ ...ngDevMode ? { debugName: "active" } : /* istanbul ignore next */ {},
585
+ source: this.scene,
586
+ computation: () => null
587
+ });
588
+ this.activeHit = computed(() => {
589
+ const active = this.active();
590
+ return active === null ? null : this.scene().hits[active] ?? null;
591
+ }, ...ngDevMode ? [{ debugName: "activeHit" }] : /* istanbul ignore next */ []);
592
+ this.activePoints = computed(() => this.activeHit()?.points ?? [], ...ngDevMode ? [{ debugName: "activePoints" }] : /* istanbul ignore next */ []);
593
+ this.announcement = computed(() => {
594
+ const tooltip = this.activeHit()?.tooltip;
595
+ if (!tooltip) return "";
596
+ return [tooltip.title, ...tooltip.items.map((item) => `${item.label}: ${item.value}`)].filter((part) => !!part).join(", ");
597
+ }, ...ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []);
598
+ this.cursorClass = computed(() => CURSOR_CLASS[this.scene().cursorPaint], ...ngDevMode ? [{ debugName: "cursorClass" }] : /* istanbul ignore next */ []);
599
+ this.describedBy = computed(() => this.description() ? this.descriptionId : null, ...ngDevMode ? [{ debugName: "describedBy" }] : /* istanbul ignore next */ []);
600
+ this.drawable = computed(() => this.size().width > 0 && this.size().height > 0, ...ngDevMode ? [{ debugName: "drawable" }] : /* istanbul ignore next */ []);
601
+ this.interactive = computed(() => !this.loading() && this.scene().hits.length > 0, ...ngDevMode ? [{ debugName: "interactive" }] : /* istanbul ignore next */ []);
602
+ this.legendItems = computed(() => Object.entries(this.config()).map(([key, series]) => ({
603
+ key,
604
+ label: series.label,
605
+ color: cssColor(series.color)
606
+ })), ...ngDevMode ? [{ debugName: "legendItems" }] : /* istanbul ignore next */ []);
607
+ this.marks = computed(() => {
608
+ const active = this.active();
609
+ return this.scene().marks.map((mark) => ({
610
+ d: mark.d,
611
+ key: mark.key,
612
+ class: hlm(MARK_CLASS[mark.paint], active !== null && mark.hit !== null && mark.hit !== active && "opacity-40"),
613
+ style: { [MARK_COLOR_PROPERTY[mark.paint]]: mark.color }
614
+ }));
615
+ }, ...ngDevMode ? [{ debugName: "marks" }] : /* istanbul ignore next */ []);
616
+ this.origin = computed(() => `translate(${this.scene().origin.x},${this.scene().origin.y})`, ...ngDevMode ? [{ debugName: "origin" }] : /* istanbul ignore next */ []);
617
+ this.rootClass = computed(() => hlm("flex h-72 w-full flex-col gap-3", this.userClass()), ...ngDevMode ? [{ debugName: "rootClass" }] : /* istanbul ignore next */ []);
618
+ this.showLegend = computed(() => this.legend() && !this.loading() && !this.scene().empty, ...ngDevMode ? [{ debugName: "showLegend" }] : /* istanbul ignore next */ []);
619
+ this.tooltip = computed(() => {
620
+ const hit = this.activeHit();
621
+ if (!hit || hit.tooltip.items.length === 0) return null;
622
+ return {
623
+ ...hit.tooltip,
624
+ left: hit.anchor.x,
625
+ top: hit.anchor.y,
626
+ class: TOOLTIP_SIDE_CLASS[hit.anchor.x > this.size().width / 2 ? "left" : "right"]
627
+ };
628
+ }, ...ngDevMode ? [{ debugName: "tooltip" }] : /* istanbul ignore next */ []);
629
+ this.viewBox = computed(() => `0 0 ${this.size().width} ${this.size().height}`, ...ngDevMode ? [{ debugName: "viewBox" }] : /* istanbul ignore next */ []);
630
+ }
631
+ activate(index) {
632
+ this.active.set(index);
633
+ }
634
+ clear() {
635
+ this.active.set(null);
636
+ }
637
+ onFocus(event) {
638
+ const target = event.target;
639
+ if (this.active() === null && target.matches(":focus-visible")) this.active.set(0);
640
+ }
641
+ onKeydown(event) {
642
+ const move = KEY_MOVES[event.key];
643
+ const count = this.scene().hits.length;
644
+ if (!move || count === 0) return;
645
+ event.preventDefault();
646
+ this.active.set(move(this.active() ?? -1, count));
647
+ }
648
+ static {
649
+ this.ɵfac = i0.ɵɵngDeclareFactory({
650
+ minVersion: "12.0.0",
651
+ version: "22.2.4",
652
+ ngImport: i0,
653
+ type: YuwChartComponent,
654
+ deps: [],
655
+ target: i0.ɵɵFactoryTarget.Component
656
+ });
657
+ }
658
+ static {
659
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
660
+ minVersion: "17.0.0",
661
+ version: "22.2.4",
662
+ type: YuwChartComponent,
663
+ isStandalone: true,
664
+ selector: "yuw-chart",
665
+ inputs: {
666
+ ariaLabel: {
667
+ classPropertyName: "ariaLabel",
668
+ publicName: "ariaLabel",
669
+ isSignal: true,
670
+ isRequired: true,
671
+ transformFunction: null
672
+ },
673
+ categoryFormat: {
674
+ classPropertyName: "categoryFormat",
675
+ publicName: "categoryFormat",
676
+ isSignal: true,
677
+ isRequired: false,
678
+ transformFunction: null
679
+ },
680
+ categoryKey: {
681
+ classPropertyName: "categoryKey",
682
+ publicName: "categoryKey",
683
+ isSignal: true,
684
+ isRequired: false,
685
+ transformFunction: null
686
+ },
687
+ categoryLabel: {
688
+ classPropertyName: "categoryLabel",
689
+ publicName: "categoryLabel",
690
+ isSignal: true,
691
+ isRequired: false,
692
+ transformFunction: null
693
+ },
694
+ config: {
695
+ classPropertyName: "config",
696
+ publicName: "config",
697
+ isSignal: true,
698
+ isRequired: true,
699
+ transformFunction: null
700
+ },
701
+ data: {
702
+ classPropertyName: "data",
703
+ publicName: "data",
704
+ isSignal: true,
705
+ isRequired: true,
706
+ transformFunction: null
707
+ },
708
+ description: {
709
+ classPropertyName: "description",
710
+ publicName: "description",
711
+ isSignal: true,
712
+ isRequired: false,
713
+ transformFunction: null
714
+ },
715
+ emptyText: {
716
+ classPropertyName: "emptyText",
717
+ publicName: "emptyText",
718
+ isSignal: true,
719
+ isRequired: true,
720
+ transformFunction: null
721
+ },
722
+ kind: {
723
+ classPropertyName: "kind",
724
+ publicName: "kind",
725
+ isSignal: true,
726
+ isRequired: false,
727
+ transformFunction: null
728
+ },
729
+ legend: {
730
+ classPropertyName: "legend",
731
+ publicName: "legend",
732
+ isSignal: true,
733
+ isRequired: false,
734
+ transformFunction: null
735
+ },
736
+ loading: {
737
+ classPropertyName: "loading",
738
+ publicName: "loading",
739
+ isSignal: true,
740
+ isRequired: false,
741
+ transformFunction: null
742
+ },
743
+ userClass: {
744
+ classPropertyName: "userClass",
745
+ publicName: "class",
746
+ isSignal: true,
747
+ isRequired: false,
748
+ transformFunction: null
749
+ },
750
+ valueFormat: {
751
+ classPropertyName: "valueFormat",
752
+ publicName: "valueFormat",
753
+ isSignal: true,
754
+ isRequired: false,
755
+ transformFunction: null
756
+ }
757
+ },
758
+ host: { classAttribute: "contents" },
759
+ viewQueries: [{
760
+ propertyName: "_plot",
761
+ first: true,
762
+ predicate: ["plot"],
763
+ descendants: true,
764
+ isSignal: true
765
+ }],
766
+ ngImport: i0,
767
+ template: "<div role=\"figure\" [class]=\"rootClass()\" [attr.aria-label]=\"ariaLabel()\" [attr.aria-busy]=\"loading() || null\">\n @if (description(); as text) {\n <p class=\"sr-only\" [id]=\"descriptionId\">{{ text }}</p>\n }\n\n <!-- Plot -->\n <div\n #plot\n role=\"group\"\n class=\"relative min-h-0 flex-1 rounded-md outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-describedby]=\"describedBy()\"\n [attr.tabindex]=\"interactive() ? 0 : null\"\n (focus)=\"onFocus($event)\"\n (blur)=\"clear()\"\n (keydown)=\"onKeydown($event)\"\n (pointerleave)=\"clear()\"\n >\n @if (loading()) {\n <div hlmSkeleton class=\"size-full\" aria-hidden=\"true\"></div>\n } @else if (scene().empty) {\n <div class=\"flex size-full items-center justify-center text-center text-sm text-muted-foreground\">\n {{ emptyText() }}\n </div>\n } @else if (drawable()) {\n <svg\n aria-hidden=\"true\"\n class=\"absolute inset-0 overflow-visible\"\n [attr.width]=\"size().width\"\n [attr.height]=\"size().height\"\n [attr.viewBox]=\"viewBox()\"\n >\n @for (line of scene().grid; track $index) {\n <path class=\"fill-none stroke-border [stroke-dasharray:3_3]\" [attr.d]=\"line\" />\n }\n\n @if (activeHit()?.cursor; as cursor) {\n <path [class]=\"cursorClass()\" [attr.d]=\"cursor\" />\n }\n\n <g [attr.transform]=\"origin()\">\n @for (mark of marks(); track $index) {\n <path [class]=\"mark.class\" [style]=\"mark.style\" [attr.d]=\"mark.d\" />\n }\n </g>\n\n @for (point of activePoints(); track point.key) {\n <circle\n r=\"4\"\n class=\"stroke-background stroke-2\"\n [style.fill]=\"point.color\"\n [attr.cx]=\"point.cx\"\n [attr.cy]=\"point.cy\"\n />\n }\n\n @for (tick of scene().ticks; track $index) {\n <text\n dominant-baseline=\"middle\"\n class=\"fill-muted-foreground text-xs\"\n [attr.x]=\"tick.x\"\n [attr.y]=\"tick.y\"\n [attr.text-anchor]=\"tick.anchor\"\n >\n {{ tick.label }}\n </text>\n }\n\n <g [attr.transform]=\"origin()\">\n @for (hit of scene().hits; track $index) {\n <path class=\"fill-transparent\" [attr.d]=\"hit.d\" (pointerenter)=\"activate($index)\" />\n }\n </g>\n </svg>\n\n @if (tooltip(); as tip) {\n <div\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute z-10 grid min-w-32 -translate-y-1/2 gap-1.5 rounded-md border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-md motion-safe:transition-[left,top] motion-safe:duration-150\"\n [class]=\"tip.class\"\n [style.left.px]=\"tip.left\"\n [style.top.px]=\"tip.top\"\n >\n @if (tip.title) {\n <span class=\"font-medium\">{{ tip.title }}</span>\n }\n @for (item of tip.items; track item.key) {\n <span class=\"flex items-center gap-2\">\n <span class=\"size-2.5 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>\n <span class=\"text-muted-foreground\">{{ item.label }}</span>\n <span class=\"ml-auto font-mono font-medium tabular-nums\">{{ item.value }}</span>\n </span>\n }\n </div>\n }\n }\n\n <div role=\"status\" class=\"sr-only\">{{ announcement() }}</div>\n </div>\n\n <!-- Legend -->\n @if (showLegend()) {\n <ul class=\"flex flex-wrap items-center justify-center gap-x-4 gap-y-1 text-xs text-muted-foreground\">\n @for (item of legendItems(); track item.key) {\n <li class=\"flex items-center gap-1.5\">\n <span aria-hidden=\"true\" class=\"size-2.5 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>\n {{ item.label }}\n </li>\n }\n </ul>\n }\n\n <!-- Accessible data -->\n <table class=\"sr-only\">\n <caption>\n {{ ariaLabel() }}\n </caption>\n <thead>\n <tr>\n @if (scene().table.corner !== null) {\n <th scope=\"col\">{{ scene().table.corner }}</th>\n }\n @for (head of scene().table.head; track $index) {\n <th scope=\"col\">{{ head }}</th>\n }\n </tr>\n </thead>\n <tbody>\n @for (row of scene().table.rows; track $index) {\n <tr>\n @if (row.header !== null) {\n <th scope=\"row\">{{ row.header }}</th>\n }\n @for (cell of row.cells; track $index) {\n <td>{{ cell }}</td>\n }\n </tr>\n }\n </tbody>\n </table>\n</div>\n",
768
+ dependencies: [{
769
+ kind: "directive",
770
+ type: HlmSkeleton,
771
+ selector: "[hlmSkeleton],hlm-skeleton"
772
+ }],
773
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
774
+ });
775
+ }
776
+ };
777
+ i0.ɵɵngDeclareClassMetadata({
778
+ minVersion: "12.0.0",
779
+ version: "22.2.4",
780
+ ngImport: i0,
781
+ type: YuwChartComponent,
782
+ decorators: [{
783
+ type: Component,
784
+ args: [{
785
+ selector: "yuw-chart",
786
+ imports: [HlmSkeleton],
787
+ host: { class: "contents" },
788
+ changeDetection: ChangeDetectionStrategy.OnPush,
789
+ template: "<div role=\"figure\" [class]=\"rootClass()\" [attr.aria-label]=\"ariaLabel()\" [attr.aria-busy]=\"loading() || null\">\n @if (description(); as text) {\n <p class=\"sr-only\" [id]=\"descriptionId\">{{ text }}</p>\n }\n\n <!-- Plot -->\n <div\n #plot\n role=\"group\"\n class=\"relative min-h-0 flex-1 rounded-md outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50\"\n [attr.aria-label]=\"ariaLabel()\"\n [attr.aria-describedby]=\"describedBy()\"\n [attr.tabindex]=\"interactive() ? 0 : null\"\n (focus)=\"onFocus($event)\"\n (blur)=\"clear()\"\n (keydown)=\"onKeydown($event)\"\n (pointerleave)=\"clear()\"\n >\n @if (loading()) {\n <div hlmSkeleton class=\"size-full\" aria-hidden=\"true\"></div>\n } @else if (scene().empty) {\n <div class=\"flex size-full items-center justify-center text-center text-sm text-muted-foreground\">\n {{ emptyText() }}\n </div>\n } @else if (drawable()) {\n <svg\n aria-hidden=\"true\"\n class=\"absolute inset-0 overflow-visible\"\n [attr.width]=\"size().width\"\n [attr.height]=\"size().height\"\n [attr.viewBox]=\"viewBox()\"\n >\n @for (line of scene().grid; track $index) {\n <path class=\"fill-none stroke-border [stroke-dasharray:3_3]\" [attr.d]=\"line\" />\n }\n\n @if (activeHit()?.cursor; as cursor) {\n <path [class]=\"cursorClass()\" [attr.d]=\"cursor\" />\n }\n\n <g [attr.transform]=\"origin()\">\n @for (mark of marks(); track $index) {\n <path [class]=\"mark.class\" [style]=\"mark.style\" [attr.d]=\"mark.d\" />\n }\n </g>\n\n @for (point of activePoints(); track point.key) {\n <circle\n r=\"4\"\n class=\"stroke-background stroke-2\"\n [style.fill]=\"point.color\"\n [attr.cx]=\"point.cx\"\n [attr.cy]=\"point.cy\"\n />\n }\n\n @for (tick of scene().ticks; track $index) {\n <text\n dominant-baseline=\"middle\"\n class=\"fill-muted-foreground text-xs\"\n [attr.x]=\"tick.x\"\n [attr.y]=\"tick.y\"\n [attr.text-anchor]=\"tick.anchor\"\n >\n {{ tick.label }}\n </text>\n }\n\n <g [attr.transform]=\"origin()\">\n @for (hit of scene().hits; track $index) {\n <path class=\"fill-transparent\" [attr.d]=\"hit.d\" (pointerenter)=\"activate($index)\" />\n }\n </g>\n </svg>\n\n @if (tooltip(); as tip) {\n <div\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute z-10 grid min-w-32 -translate-y-1/2 gap-1.5 rounded-md border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-md motion-safe:transition-[left,top] motion-safe:duration-150\"\n [class]=\"tip.class\"\n [style.left.px]=\"tip.left\"\n [style.top.px]=\"tip.top\"\n >\n @if (tip.title) {\n <span class=\"font-medium\">{{ tip.title }}</span>\n }\n @for (item of tip.items; track item.key) {\n <span class=\"flex items-center gap-2\">\n <span class=\"size-2.5 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>\n <span class=\"text-muted-foreground\">{{ item.label }}</span>\n <span class=\"ml-auto font-mono font-medium tabular-nums\">{{ item.value }}</span>\n </span>\n }\n </div>\n }\n }\n\n <div role=\"status\" class=\"sr-only\">{{ announcement() }}</div>\n </div>\n\n <!-- Legend -->\n @if (showLegend()) {\n <ul class=\"flex flex-wrap items-center justify-center gap-x-4 gap-y-1 text-xs text-muted-foreground\">\n @for (item of legendItems(); track item.key) {\n <li class=\"flex items-center gap-1.5\">\n <span aria-hidden=\"true\" class=\"size-2.5 shrink-0 rounded-[2px]\" [style.background]=\"item.color\"></span>\n {{ item.label }}\n </li>\n }\n </ul>\n }\n\n <!-- Accessible data -->\n <table class=\"sr-only\">\n <caption>\n {{ ariaLabel() }}\n </caption>\n <thead>\n <tr>\n @if (scene().table.corner !== null) {\n <th scope=\"col\">{{ scene().table.corner }}</th>\n }\n @for (head of scene().table.head; track $index) {\n <th scope=\"col\">{{ head }}</th>\n }\n </tr>\n </thead>\n <tbody>\n @for (row of scene().table.rows; track $index) {\n <tr>\n @if (row.header !== null) {\n <th scope=\"row\">{{ row.header }}</th>\n }\n @for (cell of row.cells; track $index) {\n <td>{{ cell }}</td>\n }\n </tr>\n }\n </tbody>\n </table>\n</div>\n"
790
+ }]
791
+ }],
792
+ propDecorators: {
793
+ _plot: [{
794
+ type: i0.ViewChild,
795
+ args: ["plot", { isSignal: true }]
796
+ }],
797
+ ariaLabel: [{
798
+ type: i0.Input,
799
+ args: [{
800
+ isSignal: true,
801
+ alias: "ariaLabel",
802
+ required: true
803
+ }]
804
+ }],
805
+ categoryFormat: [{
806
+ type: i0.Input,
807
+ args: [{
808
+ isSignal: true,
809
+ alias: "categoryFormat",
810
+ required: false
811
+ }]
812
+ }],
813
+ categoryKey: [{
814
+ type: i0.Input,
815
+ args: [{
816
+ isSignal: true,
817
+ alias: "categoryKey",
818
+ required: false
819
+ }]
820
+ }],
821
+ categoryLabel: [{
822
+ type: i0.Input,
823
+ args: [{
824
+ isSignal: true,
825
+ alias: "categoryLabel",
826
+ required: false
827
+ }]
828
+ }],
829
+ config: [{
830
+ type: i0.Input,
831
+ args: [{
832
+ isSignal: true,
833
+ alias: "config",
834
+ required: true
835
+ }]
836
+ }],
837
+ data: [{
838
+ type: i0.Input,
839
+ args: [{
840
+ isSignal: true,
841
+ alias: "data",
842
+ required: true
843
+ }]
844
+ }],
845
+ description: [{
846
+ type: i0.Input,
847
+ args: [{
848
+ isSignal: true,
849
+ alias: "description",
850
+ required: false
851
+ }]
852
+ }],
853
+ emptyText: [{
854
+ type: i0.Input,
855
+ args: [{
856
+ isSignal: true,
857
+ alias: "emptyText",
858
+ required: true
859
+ }]
860
+ }],
861
+ kind: [{
862
+ type: i0.Input,
863
+ args: [{
864
+ isSignal: true,
865
+ alias: "kind",
866
+ required: false
867
+ }]
868
+ }],
869
+ legend: [{
870
+ type: i0.Input,
871
+ args: [{
872
+ isSignal: true,
873
+ alias: "legend",
874
+ required: false
875
+ }]
876
+ }],
877
+ loading: [{
878
+ type: i0.Input,
879
+ args: [{
880
+ isSignal: true,
881
+ alias: "loading",
882
+ required: false
883
+ }]
884
+ }],
885
+ userClass: [{
886
+ type: i0.Input,
887
+ args: [{
888
+ isSignal: true,
889
+ alias: "class",
890
+ required: false
891
+ }]
892
+ }],
893
+ valueFormat: [{
894
+ type: i0.Input,
895
+ args: [{
896
+ isSignal: true,
897
+ alias: "valueFormat",
898
+ required: false
899
+ }]
900
+ }]
901
+ }
902
+ });
649
903
  export { YUW_CHART_COLORS, YuwChartComponent, yuwChartColorAt };
650
- //# sourceMappingURL=yukit-web-chart.mjs.map
904
+
905
+ //# sourceMappingURL=yukit-web-chart.mjs.map