@redvars/peacock 3.15.0 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/dist/assets/styles.css +1 -1
  2. package/dist/assets/styles.css.map +1 -1
  3. package/dist/assets/theme.js +19 -19
  4. package/dist/assets/tokens.css +1 -1
  5. package/dist/assets/tokens.css.map +1 -1
  6. package/dist/card-content.js +8 -7
  7. package/dist/card-content.js.map +1 -1
  8. package/dist/card.js +142 -98
  9. package/dist/card.js.map +1 -1
  10. package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
  11. package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
  12. package/dist/chart-area.js +78 -0
  13. package/dist/chart-area.js.map +1 -0
  14. package/dist/chart-bar.js +283 -213
  15. package/dist/chart-bar.js.map +1 -1
  16. package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
  17. package/dist/chart-base-C2qRMF48.js.map +1 -0
  18. package/dist/chart-doughnut.js +55 -287
  19. package/dist/chart-doughnut.js.map +1 -1
  20. package/dist/chart-line.js +626 -0
  21. package/dist/chart-line.js.map +1 -0
  22. package/dist/chart-pie.js +637 -195
  23. package/dist/chart-pie.js.map +1 -1
  24. package/dist/code-editor.js +704 -131
  25. package/dist/code-editor.js.map +1 -1
  26. package/dist/code-group.js +188 -0
  27. package/dist/code-group.js.map +1 -0
  28. package/dist/code-highlighter.js +895 -257
  29. package/dist/code-highlighter.js.map +1 -1
  30. package/dist/custom-elements-jsdocs.json +2278 -677
  31. package/dist/custom-elements.json +13962 -3690
  32. package/dist/image.js +5 -1
  33. package/dist/image.js.map +1 -1
  34. package/dist/index.js +8 -7
  35. package/dist/index.js.map +1 -1
  36. package/dist/loader-full.js +1 -1
  37. package/dist/loader.js +9 -3
  38. package/dist/loader.js.map +1 -1
  39. package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
  40. package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
  41. package/dist/pagination.js +408 -110
  42. package/dist/pagination.js.map +1 -1
  43. package/dist/path-CJ0Arqcy.js +166 -0
  44. package/dist/path-CJ0Arqcy.js.map +1 -0
  45. package/dist/snackbar.js +89 -34
  46. package/dist/snackbar.js.map +1 -1
  47. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  48. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  49. package/dist/src/__internal/chart/paths.d.ts +5 -0
  50. package/dist/src/__internal/chart/types.d.ts +42 -0
  51. package/dist/src/card/card-content.d.ts +2 -3
  52. package/dist/src/card/card.d.ts +31 -17
  53. package/dist/src/chart-area/chart-area.d.ts +54 -0
  54. package/dist/src/chart-area/index.d.ts +1 -0
  55. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  56. package/dist/src/chart-bar/index.d.ts +0 -1
  57. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  58. package/dist/src/chart-line/chart-line.d.ts +69 -0
  59. package/dist/src/chart-line/index.d.ts +1 -0
  60. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  61. package/dist/src/code-editor/code-editor.d.ts +52 -13
  62. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  63. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  64. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  65. package/dist/src/code-highlighter/index.d.ts +1 -0
  66. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  67. package/dist/src/code-highlighter/local.d.ts +4 -1
  68. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  69. package/dist/src/index.d.ts +4 -2
  70. package/dist/src/pagination/page-items.d.ts +14 -0
  71. package/dist/src/pagination/pagination.d.ts +46 -7
  72. package/dist/src/snackbar/snackbar.d.ts +13 -1
  73. package/dist/src/table/table.d.ts +125 -27
  74. package/dist/src/toolbar/toolbar.d.ts +56 -51
  75. package/dist/table.js +1007 -338
  76. package/dist/table.js.map +1 -1
  77. package/dist/test/chart.test.d.ts +1 -0
  78. package/dist/test/code-highlighter.test.d.ts +1 -0
  79. package/dist/test/pagination.test.d.ts +1 -0
  80. package/dist/test/table.test.d.ts +1 -0
  81. package/dist/token-colors-0TFHWbcq.js +81 -0
  82. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  83. package/dist/toolbar.js +195 -184
  84. package/dist/toolbar.js.map +1 -1
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +1 -2
  87. package/readme.md +7 -6
  88. package/scss/_code-block.scss +139 -0
  89. package/scss/tokens.css +24 -0
  90. package/src/__internal/chart/cartesian-chart.ts +404 -0
  91. package/src/__internal/chart/chart-base.scss +252 -0
  92. package/src/__internal/chart/chart-base.ts +474 -0
  93. package/src/__internal/chart/paths.ts +28 -0
  94. package/src/__internal/chart/types.ts +49 -0
  95. package/src/card/card-content.ts +12 -9
  96. package/src/card/card.scss +66 -54
  97. package/src/card/card.ts +109 -73
  98. package/src/chart-area/chart-area.ts +82 -0
  99. package/src/chart-area/index.ts +1 -0
  100. package/src/chart-bar/chart-bar.ts +336 -250
  101. package/src/chart-bar/index.ts +0 -1
  102. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  103. package/src/chart-doughnut/demo/index.html +14 -22
  104. package/src/chart-line/chart-line.scss +25 -0
  105. package/src/chart-line/chart-line.ts +346 -0
  106. package/src/chart-line/index.ts +1 -0
  107. package/src/chart-pie/chart-pie.scss +35 -16
  108. package/src/chart-pie/chart-pie.ts +282 -188
  109. package/src/chart-pie/demo/index.html +13 -21
  110. package/src/code-editor/code-editor.scss +132 -36
  111. package/src/code-editor/code-editor.ts +308 -88
  112. package/src/code-editor/demo/index.html +39 -12
  113. package/src/code-editor/editor-theme.ts +213 -0
  114. package/src/code-highlighter/code-group.scss +34 -0
  115. package/src/code-highlighter/code-group.ts +173 -0
  116. package/src/code-highlighter/code-highlighter.scss +226 -111
  117. package/src/code-highlighter/code-highlighter.ts +554 -199
  118. package/src/code-highlighter/demo/index.html +68 -4
  119. package/src/code-highlighter/index.ts +1 -0
  120. package/src/code-highlighter/line-ranges.ts +81 -0
  121. package/src/code-highlighter/local.ts +9 -3
  122. package/src/code-highlighter/token-colors.ts +42 -0
  123. package/src/index.ts +4 -2
  124. package/src/loader.ts +8 -2
  125. package/src/pagination/page-items.ts +50 -0
  126. package/src/pagination/pagination.scss +159 -44
  127. package/src/pagination/pagination.ts +275 -74
  128. package/src/snackbar/demo/index.html +39 -4
  129. package/src/snackbar/snackbar.scss +27 -10
  130. package/src/snackbar/snackbar.ts +80 -37
  131. package/src/table/table.scss +337 -109
  132. package/src/table/table.ts +812 -272
  133. package/src/toolbar/toolbar-colors.scss +6 -7
  134. package/src/toolbar/toolbar.scss +35 -106
  135. package/src/toolbar/toolbar.ts +180 -80
  136. package/dist/array-D5vjT2Xm.js +0 -14
  137. package/dist/array-D5vjT2Xm.js.map +0 -1
  138. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  139. package/dist/chart-stacked-bar.js +0 -403
  140. package/dist/chart-stacked-bar.js.map +0 -1
  141. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  142. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  143. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  144. package/dist/pie-Dz0IDiPt.js +0 -537
  145. package/dist/pie-Dz0IDiPt.js.map +0 -1
  146. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  147. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  148. package/dist/pierre-light-BEkAPImt.js +0 -4
  149. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  150. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  151. package/dist/src/code-highlighter/constants.d.ts +0 -1
  152. package/dist/transform-DSwFSqzD.js.map +0 -1
  153. package/src/chart-bar/chart-bar.scss +0 -58
  154. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  155. package/src/chart-doughnut/chart-donut.scss +0 -37
  156. package/src/code-highlighter/constants.ts +0 -117
  157. /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@redvars/peacock",
3
3
  "description": "The foundation for beautiful user interfaces",
4
4
  "license": "Apache-2.0",
5
- "version": "3.15.0",
5
+ "version": "3.17.0",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.js",
@@ -60,7 +60,6 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@floating-ui/dom": "^1.7.5",
63
- "@pierre/theme": "^0.0.29",
64
63
  "@tiptap/core": "^2.11.3",
65
64
  "@tiptap/extension-mention": "^2.11.3",
66
65
  "@tiptap/extension-placeholder": "^2.11.3",
package/readme.md CHANGED
@@ -44,9 +44,9 @@ Visit [https://peacock.redvars.com](https://peacock.redvars.com) to view the doc
44
44
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
45
45
  <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
46
46
 
47
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@redvars/peacock@3.15.0/dist/assets/styles.css"></link>
47
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@redvars/peacock@3.17.0/dist/assets/styles.css"></link>
48
48
  <script type='module'
49
- src='https://cdn.jsdelivr.net/npm/@redvars/peacock@3.15.0/dist/loader.js'></script>
49
+ src='https://cdn.jsdelivr.net/npm/@redvars/peacock@3.17.0/dist/loader.js'></script>
50
50
  </head>
51
51
 
52
52
  <wc-button>Button</wc-button>
@@ -185,10 +185,11 @@ These components are used to display data in a graphical format. They include
185
185
 
186
186
  | Name | Component | State |
187
187
  |---------------------------------------------------------------------------------|------------------------|-------|
188
- | [Bar Chart](https://peacock.redvars.com/components/chart-bar) | wc-chart-bar | 🟢 |
189
- | [Doughnut Chart](https://peacock.redvars.com/components/chart-doughnut) | wc-chart-doughnut | 🟢 |
190
- | [Pie Chart](https://peacock.redvars.com/components/chart-pie) | wc-chart-pie | 🟢 |
191
- | [Stacked Bar Chart](https://peacock.redvars.com/components/chart-bar) | wc-chart-stacked-bar | 🟢 |
188
+ | [Area Chart](https://peacock.redvars.com/charts/area/) | wc-chart-area | 🟢 |
189
+ | [Bar Chart](https://peacock.redvars.com/charts/bar/) | wc-chart-bar | 🟢 |
190
+ | [Doughnut Chart](https://peacock.redvars.com/charts/doughnut/) | wc-chart-doughnut | 🟢 |
191
+ | [Line Chart](https://peacock.redvars.com/charts/line/) | wc-chart-line | 🟢 |
192
+ | [Pie Chart](https://peacock.redvars.com/charts/pie/) | wc-chart-pie | 🟢 |
192
193
 
193
194
 
194
195
  ## 📄 License
@@ -0,0 +1,139 @@
1
+ @use './mixin';
2
+
3
+ /// The frame, header and actions shared by wc-code-highlighter and wc-code-editor, so both
4
+ /// read as the same block. `$name` prefixes the public custom properties:
5
+ /// `--#{$name}-background`, `--#{$name}-border-color`, `--#{$name}-shape` and
6
+ /// `--#{$name}-foreground`.
7
+ ///
8
+ /// Markup: `.code-block` holds an optional `.header` (a `slot[name=icon]`, a `.title` and
9
+ /// `.actions`), or `.actions.floating` when there is no header, plus a `.sr-only` live region.
10
+ @mixin chrome($name) {
11
+ .code-block {
12
+ --_pad-block: var(--spacing-200);
13
+ --_pad-inline: var(--spacing-200);
14
+ --_pad-near: var(--spacing-100);
15
+ --_background: var(
16
+ --#{$name}-background,
17
+ var(--color-surface-container-low)
18
+ );
19
+ --_border-color: var(--#{$name}-border-color, var(--color-outline-variant));
20
+ --_foreground: var(--#{$name}-foreground, var(--color-on-surface));
21
+
22
+ position: relative;
23
+ display: flex;
24
+ flex-direction: column;
25
+ height: 100%;
26
+ min-width: 0;
27
+ overflow: hidden;
28
+ background: var(--_background);
29
+ color: var(--_foreground);
30
+ border: 1px solid var(--_border-color);
31
+ border-radius: var(--#{$name}-shape, var(--shape-corner-medium));
32
+ }
33
+
34
+ // ── Header ───────────────────────────────────────────────────────────────
35
+
36
+ .header {
37
+ display: flex;
38
+ align-items: center;
39
+ gap: var(--spacing-100);
40
+ min-width: 0;
41
+ padding: var(--_pad-block) var(--_pad-inline) 0;
42
+ color: var(--color-on-surface-variant);
43
+ }
44
+
45
+ ::slotted([slot='icon']) {
46
+ --icon-size: 1.125rem;
47
+
48
+ flex: none;
49
+ color: var(--color-on-surface-variant);
50
+ }
51
+
52
+ .title {
53
+ flex: 1 1 auto;
54
+ min-width: 0;
55
+ overflow: hidden;
56
+ text-overflow: ellipsis;
57
+ white-space: nowrap;
58
+ color: var(--color-on-surface);
59
+
60
+ @include mixin.get-typography(title-small);
61
+ }
62
+
63
+ // ── Actions ──────────────────────────────────────────────────────────────
64
+
65
+ .actions {
66
+ display: flex;
67
+ flex: none;
68
+ align-items: center;
69
+ gap: var(--spacing-025);
70
+ margin-inline-start: auto;
71
+ }
72
+
73
+ .header .actions {
74
+ margin-block: calc(-1 * var(--spacing-100));
75
+ margin-inline-end: calc(-1 * var(--spacing-100));
76
+ }
77
+
78
+ // Without a header, the actions float at the top end as a small toolbar that
79
+ // appears on hover or keyboard focus, and stays visible on touch screens.
80
+ .actions.floating {
81
+ position: absolute;
82
+ z-index: 1;
83
+ inset-block-start: var(--spacing-100);
84
+ inset-inline-end: var(--spacing-100);
85
+ padding: var(--spacing-025);
86
+ background: var(--color-surface);
87
+ border: 1px solid var(--color-outline-variant);
88
+ border-radius: var(--shape-corner-full);
89
+ opacity: 0;
90
+ transition: opacity var(--duration-short4) var(--easing-standard);
91
+ }
92
+
93
+ .code-block:hover .actions.floating,
94
+ .code-block:focus-within .actions.floating {
95
+ opacity: 1;
96
+ }
97
+
98
+ @media (pointer: coarse) {
99
+ .actions.floating {
100
+ opacity: 1;
101
+ }
102
+ }
103
+
104
+ @media (prefers-reduced-motion: reduce) {
105
+ .actions.floating {
106
+ transition: none;
107
+ }
108
+ }
109
+
110
+ // ── Accessibility ────────────────────────────────────────────────────────
111
+
112
+ .sr-only {
113
+ position: absolute;
114
+ width: 1px;
115
+ height: 1px;
116
+ padding: 0;
117
+ margin: -1px;
118
+ overflow: hidden;
119
+ clip-path: inset(50%);
120
+ white-space: nowrap;
121
+ border: 0;
122
+ }
123
+
124
+ // ── Size ─────────────────────────────────────────────────────────────────
125
+
126
+ :host([size='sm']) {
127
+ .code-block {
128
+ --_pad-block: var(--spacing-150);
129
+ --_pad-inline: var(--spacing-150);
130
+ --_pad-near: var(--spacing-075);
131
+
132
+ border-radius: var(--#{$name}-shape, var(--shape-corner-small));
133
+ }
134
+
135
+ .title {
136
+ @include mixin.get-typography(label-medium);
137
+ }
138
+ }
139
+ }
package/scss/tokens.css CHANGED
@@ -24,6 +24,14 @@
24
24
  --color-blue-90: #dce1ff;
25
25
  --color-blue-100: #ffffff;
26
26
  --color-blue-container: var(--color-blue-90);
27
+ --color-chart-1: var(--color-primary-40);
28
+ --color-chart-2: var(--color-tertiary-50);
29
+ --color-chart-3: var(--color-blue-50);
30
+ --color-chart-4: var(--color-green-50);
31
+ --color-chart-5: var(--color-orange-50);
32
+ --color-chart-6: var(--color-purple-50);
33
+ --color-chart-7: var(--color-red-50);
34
+ --color-chart-8: var(--color-yellow-50);
27
35
  --color-error: var(--color-red-40);
28
36
  --color-error-container: var(--color-red-90);
29
37
  --color-green: var(--color-green-40);
@@ -515,6 +523,14 @@
515
523
  --color-background: var(--color-neutral-10);
516
524
  --color-blue: var(--color-blue-80);
517
525
  --color-blue-container: var(--color-blue-30);
526
+ --color-chart-1: var(--color-primary-80);
527
+ --color-chart-2: var(--color-tertiary-70);
528
+ --color-chart-3: var(--color-blue-70);
529
+ --color-chart-4: var(--color-green-70);
530
+ --color-chart-5: var(--color-orange-70);
531
+ --color-chart-6: var(--color-purple-70);
532
+ --color-chart-7: var(--color-red-70);
533
+ --color-chart-8: var(--color-yellow-70);
518
534
  --color-error: var(--color-red-80);
519
535
  --color-error-container: var(--color-red-30);
520
536
  --color-green: var(--color-green-80);
@@ -611,6 +627,14 @@
611
627
  --color-background: var(--color-neutral-10);
612
628
  --color-blue: var(--color-blue-80);
613
629
  --color-blue-container: var(--color-blue-30);
630
+ --color-chart-1: var(--color-primary-80);
631
+ --color-chart-2: var(--color-tertiary-70);
632
+ --color-chart-3: var(--color-blue-70);
633
+ --color-chart-4: var(--color-green-70);
634
+ --color-chart-5: var(--color-orange-70);
635
+ --color-chart-6: var(--color-purple-70);
636
+ --color-chart-7: var(--color-red-70);
637
+ --color-chart-8: var(--color-yellow-70);
614
638
  --color-error: var(--color-red-80);
615
639
  --color-error-container: var(--color-red-30);
616
640
  --color-green: var(--color-green-80);
@@ -0,0 +1,404 @@
1
+ import { html, svg } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+ import { ScaleBand, ScaleLinear, ScalePoint, select, Selection } from 'd3';
4
+ import { ChartBase, chartColor } from './chart-base.js';
5
+ import type {
6
+ ChartConfig,
7
+ ChartDatum,
8
+ ChartSelectDetail,
9
+ ChartSeries,
10
+ ChartTooltipModel,
11
+ } from './types.js';
12
+
13
+ export type ChartOrientation = 'vertical' | 'horizontal';
14
+
15
+ /** Plot margins and inner size, in SVG pixels. */
16
+ export type CartesianLayout = {
17
+ left: number;
18
+ top: number;
19
+ right: number;
20
+ bottom: number;
21
+ innerWidth: number;
22
+ innerHeight: number;
23
+ };
24
+
25
+ /** Rough width of a `label-medium` character, used to size axes before text is measured. */
26
+ const CHAR_WIDTH = 7;
27
+ const AXIS_GAP = 8;
28
+ const X_AXIS_HEIGHT = 24;
29
+ const MAX_CATEGORY_AXIS_WIDTH = 120;
30
+
31
+ type CategoryScale = ScaleBand<string> | ScalePoint<string>;
32
+
33
+ /**
34
+ * Base for charts with a category axis and a value axis (bar, line, area). Data is an array of
35
+ * rows; `index` names the category field and `config` names the series fields.
36
+ */
37
+ export abstract class CartesianChart extends ChartBase {
38
+ // ── Properties
39
+
40
+ /** Rows to plot. Each row holds the category field (`index`) and a number per series. */
41
+ @property({ type: Array }) data: ChartDatum[] = [];
42
+
43
+ /** Series to plot, keyed by data field, with optional label and color. Defaults to every numeric field. */
44
+ @property({ type: Object }) config: ChartConfig = {};
45
+
46
+ /** Data field that holds the category label, for example `month`. */
47
+ @property({ type: String }) index: string = '';
48
+
49
+ /** Hides the gridlines. */
50
+ @property({ type: Boolean, attribute: 'hide-grid' }) hideGrid: boolean =
51
+ false;
52
+
53
+ /** Hides the category axis labels. */
54
+ @property({ type: Boolean, attribute: 'hide-category-axis' })
55
+ hideCategoryAxis: boolean = false;
56
+
57
+ /** Hides the value axis labels. */
58
+ @property({ type: Boolean, attribute: 'hide-value-axis' })
59
+ hideValueAxis: boolean = false;
60
+
61
+ // ── Private fields
62
+
63
+ /** Current plot layout, set by `computeLayout()`. */
64
+ protected layout: CartesianLayout = {
65
+ left: 0,
66
+ top: 0,
67
+ right: 0,
68
+ bottom: 0,
69
+ innerWidth: 0,
70
+ innerHeight: 0,
71
+ };
72
+
73
+ /** Which axis carries the categories. */
74
+ protected orientation: ChartOrientation = 'vertical';
75
+
76
+ /** Category centers along the category axis, in inner plot coordinates. */
77
+ protected centers: number[] = [];
78
+
79
+ /** Width of one category slot along the category axis. */
80
+ protected step: number = 0;
81
+
82
+ /** Tooltip anchor per category, in plot element coordinates. */
83
+ protected anchors: { x: number; y: number }[] = [];
84
+
85
+ /** Whether the cursor is a band (bars) or a line (line, area). */
86
+ protected cursorKind: 'band' | 'line' = 'band';
87
+
88
+ // ── Overrides
89
+
90
+ protected drawProperties(): string[] {
91
+ return [
92
+ ...super.drawProperties(),
93
+ 'data',
94
+ 'config',
95
+ 'index',
96
+ 'hideGrid',
97
+ 'hideCategoryAxis',
98
+ 'hideValueAxis',
99
+ ];
100
+ }
101
+
102
+ protected hasData(): boolean {
103
+ return this.data.length > 0 && this.seriesKeys().length > 0;
104
+ }
105
+
106
+ protected getSeries(): ChartSeries[] {
107
+ return this.seriesKeys().map((key, i) => ({
108
+ key,
109
+ label: this.config[key]?.label ?? key,
110
+ color: this.config[key]?.color ?? chartColor(i),
111
+ }));
112
+ }
113
+
114
+ protected getItemCount(): number {
115
+ return this.data.length;
116
+ }
117
+
118
+ protected itemAtPoint(x: number, y: number): number {
119
+ const { left, top, innerWidth, innerHeight } = this.layout;
120
+ const px = x - left;
121
+ const py = y - top;
122
+ if (px < 0 || py < 0 || px > innerWidth || py > innerHeight) return -1;
123
+ const along = this.orientation === 'vertical' ? px : py;
124
+ let best = -1;
125
+ let bestDistance = Infinity;
126
+ this.centers.forEach((center, i) => {
127
+ const distance = Math.abs(center - along);
128
+ if (distance < bestDistance) {
129
+ bestDistance = distance;
130
+ best = i;
131
+ }
132
+ });
133
+ return best;
134
+ }
135
+
136
+ protected getTooltip(index: number): ChartTooltipModel | undefined {
137
+ const datum = this.data[index];
138
+ if (!datum) return undefined;
139
+ const anchor = this.anchors[index] ?? { x: 0, y: 0 };
140
+ return {
141
+ title: this.categoryLabel(index),
142
+ rows: this.visibleSeries().map(series => ({
143
+ key: series.key,
144
+ label: series.label,
145
+ color: series.color,
146
+ value: this.formatValue(this.seriesValue(datum, series.key)),
147
+ })),
148
+ x: anchor.x,
149
+ y: anchor.y,
150
+ };
151
+ }
152
+
153
+ protected getSelectDetail(index: number): ChartSelectDetail {
154
+ return { index, datum: this.data[index] };
155
+ }
156
+
157
+ protected drawHighlight(): void {
158
+ const root = this.plotArea();
159
+ if (!root) return;
160
+ const cursor = root.select<SVGRectElement>('.cursor');
161
+ const index = this.activeIndex;
162
+ if (index < 0 || this.centers[index] === undefined) {
163
+ cursor.classed('is-visible', false);
164
+ return;
165
+ }
166
+ const { innerWidth, innerHeight } = this.layout;
167
+ const center = this.centers[index];
168
+ const size = this.cursorKind === 'band' ? this.step : 1;
169
+ cursor
170
+ .classed('cursor-line', this.cursorKind === 'line')
171
+ .classed('is-visible', true);
172
+ if (this.orientation === 'vertical') {
173
+ cursor
174
+ .attr('x', center - size / 2)
175
+ .attr('y', 0)
176
+ .attr('width', size)
177
+ .attr('height', innerHeight);
178
+ } else {
179
+ cursor
180
+ .attr('x', 0)
181
+ .attr('y', center - size / 2)
182
+ .attr('width', innerWidth)
183
+ .attr('height', size);
184
+ }
185
+ }
186
+
187
+ protected renderSvgContent() {
188
+ return svg`<defs></defs>
189
+ <g class="plot-area">
190
+ <g class="grid"></g>
191
+ <rect class="cursor"></rect>
192
+ <g class="marks"></g>
193
+ <g class="value-labels"></g>
194
+ <g class="category-axis"></g>
195
+ <g class="value-axis"></g>
196
+ <g class="active-layer"></g>
197
+ </g>`;
198
+ }
199
+
200
+ protected renderTable() {
201
+ const series = this.getSeries();
202
+ return html`<thead>
203
+ <tr>
204
+ <th scope="col">${this.index || 'Category'}</th>
205
+ ${series.map(s => html`<th scope="col">${s.label}</th>`)}
206
+ </tr>
207
+ </thead>
208
+ <tbody>
209
+ ${this.data.map(
210
+ (datum, i) =>
211
+ html`<tr>
212
+ <th scope="row">${this.categoryLabel(i)}</th>
213
+ ${series.map(
214
+ s =>
215
+ html`<td>
216
+ ${this.formatValue(this.seriesValue(datum, s.key))}
217
+ </td>`,
218
+ )}
219
+ </tr>`,
220
+ )}
221
+ </tbody>`;
222
+ }
223
+
224
+ // ── Helpers for subclasses
225
+
226
+ /** Series keys from `config`, or every numeric field of the first row except `index`. */
227
+ protected seriesKeys(): string[] {
228
+ const configured = Object.keys(this.config ?? {});
229
+ if (configured.length) return configured;
230
+ const first = this.data[0];
231
+ if (!first) return [];
232
+ return Object.keys(first).filter(
233
+ key => key !== this.index && typeof first[key] === 'number',
234
+ );
235
+ }
236
+
237
+ /** Series not switched off in the legend. */
238
+ protected visibleSeries(): ChartSeries[] {
239
+ return this.getSeries().filter(series => !this.isHidden(series.key));
240
+ }
241
+
242
+ /** A row's value for a series, 0 when missing. */
243
+ protected seriesValue(datum: ChartDatum, key: string): number {
244
+ const value = Number(datum[key]);
245
+ return Number.isFinite(value) ? value : 0;
246
+ }
247
+
248
+ /** Category label of a row. */
249
+ protected categoryLabel(index: number): string {
250
+ const datum = this.data[index];
251
+ if (!datum) return '';
252
+ return this.index ? String(datum[this.index] ?? '') : String(index + 1);
253
+ }
254
+
255
+ /** Category domain: row positions, so repeated labels stay distinct. */
256
+ protected categoryDomain(): string[] {
257
+ return this.data.map((_, i) => String(i));
258
+ }
259
+
260
+ /** The `.plot-area` group, or undefined before the SVG renders. */
261
+ protected plotArea():
262
+ | Selection<SVGGElement, unknown, null, undefined>
263
+ | undefined {
264
+ if (!this.svgElement) return undefined;
265
+ return select(this.svgElement).select<SVGGElement>(
266
+ '.plot-area',
267
+ ) as unknown as Selection<SVGGElement, unknown, null, undefined>;
268
+ }
269
+
270
+ /**
271
+ * Sets `layout` from the value scale's ticks and the category labels. Call before setting the
272
+ * scales' ranges. `valueLabelSpace` reserves room for value labels at the end of the marks.
273
+ */
274
+ protected computeLayout(
275
+ valueScale: ScaleLinear<number, number>,
276
+ valueLabelSpace = 0,
277
+ ) {
278
+ const { width, height } = this.svgSize();
279
+ const tickWidth =
280
+ Math.max(...valueScale.ticks(5).map(t => this.formatTick(t).length), 1) *
281
+ CHAR_WIDTH +
282
+ AXIS_GAP;
283
+ const categoryWidth = Math.min(
284
+ Math.max(...this.data.map((_, i) => this.categoryLabel(i).length), 1) *
285
+ CHAR_WIDTH +
286
+ AXIS_GAP,
287
+ MAX_CATEGORY_AXIS_WIDTH,
288
+ );
289
+
290
+ let left: number;
291
+ let bottom: number;
292
+ let top = 8;
293
+ let right = 8;
294
+ if (this.orientation === 'vertical') {
295
+ left = this.hideValueAxis ? 4 : tickWidth;
296
+ bottom = this.hideCategoryAxis ? 4 : X_AXIS_HEIGHT;
297
+ top += valueLabelSpace ? 12 : 0;
298
+ // Room for half of the last category label.
299
+ right += this.hideCategoryAxis ? 0 : 4;
300
+ } else {
301
+ left = this.hideCategoryAxis ? 4 : categoryWidth;
302
+ bottom = this.hideValueAxis ? 4 : X_AXIS_HEIGHT;
303
+ right += valueLabelSpace;
304
+ }
305
+
306
+ this.layout = {
307
+ left,
308
+ top,
309
+ right,
310
+ bottom,
311
+ innerWidth: Math.max(width - left - right, 0),
312
+ innerHeight: Math.max(height - top - bottom, 0),
313
+ };
314
+ }
315
+
316
+ /**
317
+ * Draws gridlines, the zero baseline and both axes' labels, and records category centers.
318
+ * The scales must already have their ranges set from `layout`.
319
+ */
320
+ protected drawFrame(
321
+ categoryScale: CategoryScale,
322
+ valueScale: ScaleLinear<number, number>,
323
+ ) {
324
+ const root = this.plotArea();
325
+ if (!root) return;
326
+ const { left, top, innerWidth, innerHeight } = this.layout;
327
+ const vertical = this.orientation === 'vertical';
328
+ root.attr('transform', `translate(${left},${top})`);
329
+
330
+ const domain = categoryScale.domain();
331
+ const bandwidth = categoryScale.bandwidth();
332
+ this.step = categoryScale.step();
333
+ this.centers = domain.map(key => (categoryScale(key) ?? 0) + bandwidth / 2);
334
+
335
+ // Gridlines at each value tick; the zero line is solid.
336
+ const ticks = valueScale.ticks(5);
337
+ const gridTicks = this.hideGrid ? [] : ticks.filter(t => t !== 0);
338
+ root
339
+ .select('.grid')
340
+ .selectAll<SVGLineElement, number>('line.gridline')
341
+ .data(gridTicks, d => String(d))
342
+ .join('line')
343
+ .attr('class', 'gridline')
344
+ .attr('x1', d => (vertical ? 0 : valueScale(d)))
345
+ .attr('x2', d => (vertical ? innerWidth : valueScale(d)))
346
+ .attr('y1', d => (vertical ? valueScale(d) : 0))
347
+ .attr('y2', d => (vertical ? valueScale(d) : innerHeight));
348
+
349
+ const zero = valueScale(0);
350
+ root
351
+ .select('.grid')
352
+ .selectAll<SVGLineElement, number>('line.baseline')
353
+ .data([zero])
354
+ .join('line')
355
+ .attr('class', 'baseline')
356
+ .attr('x1', vertical ? 0 : zero)
357
+ .attr('x2', vertical ? innerWidth : zero)
358
+ .attr('y1', vertical ? zero : 0)
359
+ .attr('y2', vertical ? zero : innerHeight);
360
+
361
+ // Value axis labels.
362
+ const showValueAxis = !this.hideValueAxis;
363
+ root
364
+ .select('.value-axis')
365
+ .selectAll<SVGTextElement, number>('text')
366
+ .data(showValueAxis ? ticks : [], d => String(d))
367
+ .join('text')
368
+ .attr('class', 'axis-label')
369
+ .attr('text-anchor', vertical ? 'end' : 'middle')
370
+ .attr('dominant-baseline', vertical ? 'middle' : 'hanging')
371
+ .attr('x', d => (vertical ? -AXIS_GAP : valueScale(d)))
372
+ .attr('y', d => (vertical ? valueScale(d) : innerHeight + AXIS_GAP))
373
+ .text(d => this.formatTick(d));
374
+
375
+ // Category axis labels, thinned out when they would overlap.
376
+ const showCategoryAxis = !this.hideCategoryAxis;
377
+ const longest = Math.max(
378
+ ...domain.map((_, i) => this.categoryLabel(i).length),
379
+ 1,
380
+ );
381
+ const labelSize = vertical ? longest * CHAR_WIDTH + AXIS_GAP : 18;
382
+ const every = Math.max(1, Math.ceil(labelSize / Math.max(this.step, 1)));
383
+ const shown = showCategoryAxis
384
+ ? domain.filter((_, i) => i % every === 0)
385
+ : [];
386
+ root
387
+ .select('.category-axis')
388
+ .selectAll<SVGTextElement, string>('text')
389
+ .data(shown, d => d)
390
+ .join('text')
391
+ .attr('class', 'axis-label')
392
+ .attr('text-anchor', vertical ? 'middle' : 'end')
393
+ .attr('dominant-baseline', vertical ? 'hanging' : 'middle')
394
+ .attr('x', d =>
395
+ vertical ? (categoryScale(d) ?? 0) + bandwidth / 2 : -AXIS_GAP,
396
+ )
397
+ .attr('y', d =>
398
+ vertical
399
+ ? innerHeight + AXIS_GAP
400
+ : (categoryScale(d) ?? 0) + bandwidth / 2,
401
+ )
402
+ .text(d => this.categoryLabel(Number(d)));
403
+ }
404
+ }