@dataengineeringformachinelearning/viking-ui 3.0.0-alpha.2 → 4.0.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 (198) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +55 -12
  3. package/dist/LICENSE +201 -0
  4. package/dist/README.md +251 -0
  5. package/dist/fesm2022/dataengineeringformachinelearning-viking-ui.mjs +13751 -0
  6. package/dist/fesm2022/dataengineeringformachinelearning-viking-ui.mjs.map +1 -0
  7. package/dist/index.js +1 -4051
  8. package/dist/package.json +87 -0
  9. package/dist/scripts/build-web-components.mjs +37 -0
  10. package/dist/src/tokens/series-presets.ts +15 -0
  11. package/dist/src/tokens/tailwind.preset.js +209 -0
  12. package/dist/src/tokens/viking-tokens.json +318 -0
  13. package/dist/src/web/badge/viking-badge-wc.ts +116 -0
  14. package/dist/src/web/button/viking-button-wc.ts +165 -0
  15. package/dist/src/web/callout/viking-callout-wc.ts +105 -0
  16. package/dist/src/web/card/viking-card-wc.ts +66 -0
  17. package/dist/src/web/core/base.ts +56 -0
  18. package/dist/src/web/core/dom.ts +53 -0
  19. package/dist/src/web/core/icons-inline.ts +44 -0
  20. package/dist/src/web/core/styles.ts +1138 -0
  21. package/dist/src/web/core/types.ts +19 -0
  22. package/dist/src/web/field/viking-field-wc.ts +154 -0
  23. package/dist/src/web/index.ts +73 -0
  24. package/dist/src/web/input/viking-input-wc.ts +211 -0
  25. package/dist/src/web/modal/viking-modal-wc.ts +187 -0
  26. package/dist/src/web/search-palette/viking-search-palette-wc.ts +494 -0
  27. package/dist/src/web/select/viking-select-wc.ts +218 -0
  28. package/dist/src/web/suite-header/viking-suite-header-wc.ts +714 -0
  29. package/dist/src/web/suite-search-palette/viking-suite-search-palette-wc.ts +234 -0
  30. package/dist/src/web/theme-toggle/viking-theme-toggle-wc.ts +139 -0
  31. package/dist/src/web/types.ts +37 -0
  32. package/dist/src/web/web-components.spec.ts +297 -0
  33. package/dist/types/dataengineeringformachinelearning-viking-ui.d.ts +2658 -0
  34. package/dist/viking.manifest.json +271 -0
  35. package/dist/web-components.js +2427 -126
  36. package/package.json +25 -11
  37. package/src/assets/drakkar-favicon.svg +17 -0
  38. package/src/core/brand/deml-lockup.svg +5 -0
  39. package/src/core/brand/deml-mark-compact.svg +4 -0
  40. package/src/core/brand/deml-mark-filled.svg +3 -0
  41. package/src/core/brand/deml-mark-outline.svg +4 -0
  42. package/src/core/brand-icons.ts +62 -0
  43. package/src/core/icons.spec.ts +52 -0
  44. package/src/core/icons.ts +206 -0
  45. package/src/core/integration-brand-icons.ts +77 -0
  46. package/src/core/lucide-paths.generated.ts +130 -0
  47. package/src/core/types.ts +85 -0
  48. package/src/core/uid.ts +7 -0
  49. package/src/lib/accordion/accordion.ts +126 -0
  50. package/src/lib/app-header/app-header.scss +274 -0
  51. package/src/lib/app-header/app-header.ts +43 -0
  52. package/src/lib/app-sidebar/app-sidebar.scss +415 -0
  53. package/src/lib/app-sidebar/app-sidebar.ts +29 -0
  54. package/src/lib/auth-panel/auth-panel.spec.ts +132 -0
  55. package/src/lib/auth-panel/auth-panel.ts +228 -0
  56. package/src/lib/autocomplete/autocomplete.ts +223 -0
  57. package/src/lib/avatar/avatar.ts +126 -0
  58. package/src/lib/badge/badge.ts +182 -0
  59. package/src/lib/bar/bar.ts +31 -0
  60. package/src/lib/brand/brand.ts +60 -0
  61. package/src/lib/breadcrumbs/breadcrumbs.ts +81 -0
  62. package/src/lib/button/button-group.ts +40 -0
  63. package/src/lib/button/button.scss +96 -0
  64. package/src/lib/button/button.ts +98 -0
  65. package/src/lib/calendar/calendar.ts +253 -0
  66. package/src/lib/callout/callout.ts +211 -0
  67. package/src/lib/card/card-title.spec.ts +27 -0
  68. package/src/lib/card/card-title.ts +50 -0
  69. package/src/lib/card/card.ts +170 -0
  70. package/src/lib/carousel/carousel.ts +206 -0
  71. package/src/lib/chart/chart-zoom.spec.ts +65 -0
  72. package/src/lib/chart/chart-zoom.ts +71 -0
  73. package/src/lib/chart/chart.ts +1257 -0
  74. package/src/lib/chart-card-header/chart-card-header.ts +80 -0
  75. package/src/lib/chart-empty-state/chart-empty-state.ts +146 -0
  76. package/src/lib/chart-panel/chart-panel.ts +133 -0
  77. package/src/lib/checkbox/checkbox.ts +139 -0
  78. package/src/lib/color-picker/color-picker.ts +148 -0
  79. package/src/lib/command/command.ts +260 -0
  80. package/src/lib/composer/composer.ts +180 -0
  81. package/src/lib/confirm-dialog/confirm-dialog.ts +163 -0
  82. package/src/lib/confirm-dialog/dialog.service.ts +79 -0
  83. package/src/lib/context/context.ts +75 -0
  84. package/src/lib/core/cva.ts +33 -0
  85. package/src/lib/date-picker/date-picker.ts +139 -0
  86. package/src/lib/dropdown/dropdown.ts +188 -0
  87. package/src/lib/editor/editor.ts +170 -0
  88. package/src/lib/empty-state/empty-state.ts +100 -0
  89. package/src/lib/fab/fab.ts +76 -0
  90. package/src/lib/field/field.ts +111 -0
  91. package/src/lib/file-upload/file-upload.ts +208 -0
  92. package/src/lib/footer/footer.scss +155 -0
  93. package/src/lib/footer/footer.ts +28 -0
  94. package/src/lib/form-section/form-section.ts +200 -0
  95. package/src/lib/forms.spec.ts +92 -0
  96. package/src/lib/gauge-arc/gauge-arc.ts +85 -0
  97. package/src/lib/hud-panel/hud-panel.ts +27 -0
  98. package/src/lib/icon/icon.ts +284 -0
  99. package/src/lib/icon-badge/icon-badge.ts +87 -0
  100. package/src/lib/icon-heading/icon-heading.spec.ts +32 -0
  101. package/src/lib/icon-heading/icon-heading.ts +38 -0
  102. package/src/lib/icon-text/icon-text.ts +120 -0
  103. package/src/lib/input/input.ts +119 -0
  104. package/src/lib/kanban/kanban.ts +211 -0
  105. package/src/lib/kbd/kbd.ts +32 -0
  106. package/src/lib/label/label.ts +39 -0
  107. package/src/lib/loading-overlay/loading-overlay.ts +80 -0
  108. package/src/lib/menubar/menubar.ts +77 -0
  109. package/src/lib/metric-card/metric-card.ts +33 -0
  110. package/src/lib/modal/modal.ts +207 -0
  111. package/src/lib/native-select/native-select.ts +124 -0
  112. package/src/lib/navbar/navbar.ts +124 -0
  113. package/src/lib/navigation-menu/navigation-menu.ts +116 -0
  114. package/src/lib/otp-input/otp-input.ts +164 -0
  115. package/src/lib/page-back-link/page-back-link.ts +74 -0
  116. package/src/lib/page-header/page-header.ts +70 -0
  117. package/src/lib/pagination/pagination.ts +157 -0
  118. package/src/lib/pillbox/pillbox.ts +157 -0
  119. package/src/lib/popover/popover.ts +92 -0
  120. package/src/lib/profile/profile.ts +73 -0
  121. package/src/lib/progress/progress.ts +123 -0
  122. package/src/lib/radio/radio.ts +132 -0
  123. package/src/lib/ring-gauge/ring-gauge.ts +75 -0
  124. package/src/lib/scroll-area/scroll-area.ts +57 -0
  125. package/src/lib/search-palette/search-palette.scss +288 -0
  126. package/src/lib/search-palette/search-palette.ts +114 -0
  127. package/src/lib/select/select.ts +292 -0
  128. package/src/lib/separator/separator.ts +59 -0
  129. package/src/lib/sheet/sheet.ts +192 -0
  130. package/src/lib/sidebar-nav/sidebar-nav.scss +218 -0
  131. package/src/lib/sidebar-nav/sidebar-nav.ts +158 -0
  132. package/src/lib/site-drakkar/site-footer.ts +129 -0
  133. package/src/lib/site-drakkar/site-navbar.scss +2 -0
  134. package/src/lib/site-drakkar/site-navbar.ts +267 -0
  135. package/src/lib/site-drakkar/suite-search-items.spec.ts +61 -0
  136. package/src/lib/skeleton/skeleton.ts +51 -0
  137. package/src/lib/slider/slider.ts +133 -0
  138. package/src/lib/spinner/spinner.ts +75 -0
  139. package/src/lib/status-metric-row/status-metric-row.ts +74 -0
  140. package/src/lib/suite-search-palette/suite-search-palette.ts +95 -0
  141. package/src/lib/switch/switch.ts +131 -0
  142. package/src/lib/table/table.ts +137 -0
  143. package/src/lib/tabs/tab-panel.ts +61 -0
  144. package/src/lib/tabs/tab.ts +107 -0
  145. package/src/lib/tabs/tabs.ts +109 -0
  146. package/src/lib/textarea/textarea.ts +103 -0
  147. package/src/lib/theme-toggle/theme-toggle.spec.ts +40 -0
  148. package/src/lib/theme-toggle/theme-toggle.ts +39 -0
  149. package/src/lib/time-picker/time-picker.ts +197 -0
  150. package/src/lib/timeline/timeline.ts +152 -0
  151. package/src/lib/toast/toast.ts +196 -0
  152. package/src/lib/toggle/toggle-group.ts +60 -0
  153. package/src/lib/toggle/toggle.ts +101 -0
  154. package/src/lib/tooltip/tooltip.ts +119 -0
  155. package/src/lib/typography/heading.ts +52 -0
  156. package/src/lib/typography/text.ts +51 -0
  157. package/src/lib/uptime-bar/uptime-bar.ts +55 -0
  158. package/src/lib/verification-code-field/verification-code-field.ts +149 -0
  159. package/src/lib/whitepaper-cta/whitepaper-cta.scss +130 -0
  160. package/src/lib/whitepaper-cta/whitepaper-cta.ts +78 -0
  161. package/src/lib/wizard/wizard.ts +80 -0
  162. package/src/public-api.ts +172 -0
  163. package/src/tokens/series-presets.ts +15 -0
  164. package/src/tokens/tailwind.preset.js +209 -0
  165. package/src/viking-ui.spec.ts +416 -0
  166. package/src/web/web-components.spec.ts +297 -0
  167. package/dist/elements/button/viking-button.d.ts +0 -14
  168. package/dist/elements/card/viking-card.d.ts +0 -8
  169. package/dist/elements/core/dom.d.ts +0 -4
  170. package/dist/elements/core/styles.d.ts +0 -2
  171. package/dist/elements/modal/viking-modal.d.ts +0 -15
  172. package/dist/index.d.ts +0 -1
  173. package/dist/lib/core/brand-icons.d.ts +0 -29
  174. package/dist/lib/core/icons.d.ts +0 -132
  175. package/dist/lib/core/integration-brand-icons.d.ts +0 -18
  176. package/dist/lib/core/lucide-paths.generated.d.ts +0 -90
  177. package/dist/lib/site-drakkar/site-drakkar.config.d.ts +0 -50
  178. package/dist/lib/site-drakkar/suite-search-items.d.ts +0 -17
  179. package/dist/web/badge/viking-badge-wc.d.ts +0 -28
  180. package/dist/web/button/viking-button-wc.d.ts +0 -28
  181. package/dist/web/callout/viking-callout-wc.d.ts +0 -27
  182. package/dist/web/card/viking-card-wc.d.ts +0 -29
  183. package/dist/web/core/base.d.ts +0 -12
  184. package/dist/web/core/dom.d.ts +0 -11
  185. package/dist/web/core/icons-inline.d.ts +0 -7
  186. package/dist/web/core/styles.d.ts +0 -12
  187. package/dist/web/core/types.d.ts +0 -10
  188. package/dist/web/field/viking-field-wc.d.ts +0 -32
  189. package/dist/web/index.d.ts +0 -15
  190. package/dist/web/input/viking-input-wc.d.ts +0 -32
  191. package/dist/web/modal/viking-modal-wc.d.ts +0 -50
  192. package/dist/web/search-palette/viking-search-palette-wc.d.ts +0 -64
  193. package/dist/web/select/viking-select-wc.d.ts +0 -48
  194. package/dist/web/suite-header/viking-suite-header-wc.d.ts +0 -36
  195. package/dist/web/suite-search-palette/viking-suite-search-palette-wc.d.ts +0 -39
  196. package/dist/web/theme-toggle/viking-theme-toggle-wc.d.ts +0 -19
  197. package/dist/web/types.d.ts +0 -40
  198. package/dist/web-components/index.d.ts +0 -1
@@ -0,0 +1,206 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ Component,
4
+ ElementRef,
5
+ contentChildren,
6
+ signal,
7
+ viewChild,
8
+ } from "@angular/core";
9
+ import { VikingIcon } from "../icon/icon";
10
+
11
+ /** A single slide inside viking-carousel. */
12
+ @Component({
13
+ selector: "viking-carousel-slide",
14
+ changeDetection: ChangeDetectionStrategy.OnPush,
15
+ host: { role: "group", "aria-roledescription": "slide" },
16
+ template: `<ng-content />`,
17
+ styles: [
18
+ `
19
+ :host {
20
+ flex: 0 0 100%;
21
+ scroll-snap-align: start;
22
+ display: block;
23
+ box-sizing: border-box;
24
+ }
25
+ `,
26
+ ],
27
+ })
28
+ export class VikingCarouselSlide {}
29
+
30
+ /**
31
+ * viking-carousel — scroll-snap slideshow.
32
+ */
33
+ @Component({
34
+ selector: "viking-carousel",
35
+ imports: [VikingIcon],
36
+ changeDetection: ChangeDetectionStrategy.OnPush,
37
+ host: { "aria-roledescription": "carousel" },
38
+ template: `
39
+ <div
40
+ class="viking-carousel-viewport"
41
+ #viewport
42
+ tabindex="0"
43
+ role="group"
44
+ aria-label="Carousel slides"
45
+ (scroll)="onScroll()"
46
+ >
47
+ <ng-content />
48
+ </div>
49
+ <div class="viking-carousel-controls">
50
+ <button
51
+ type="button"
52
+ class="viking-carousel-nav"
53
+ aria-label="Previous slide"
54
+ [disabled]="index() <= 0"
55
+ (click)="goTo(index() - 1)"
56
+ >
57
+ <viking-icon name="chevron-left" [size]="18" />
58
+ </button>
59
+ <div class="viking-carousel-dots">
60
+ @for (slide of slides(); track $index) {
61
+ <button
62
+ type="button"
63
+ class="viking-carousel-dot"
64
+ [class.viking-active]="$index === index()"
65
+ [attr.aria-label]="'Go to slide ' + ($index + 1)"
66
+ [attr.aria-current]="$index === index()"
67
+ (click)="goTo($index)"
68
+ ></button>
69
+ }
70
+ </div>
71
+ <button
72
+ type="button"
73
+ class="viking-carousel-nav"
74
+ aria-label="Next slide"
75
+ [disabled]="index() >= slides().length - 1"
76
+ (click)="goTo(index() + 1)"
77
+ >
78
+ <viking-icon name="chevron-right" [size]="18" />
79
+ </button>
80
+ </div>
81
+ `,
82
+ styles: [
83
+ `
84
+ :host {
85
+ display: block;
86
+ }
87
+ .viking-carousel-viewport {
88
+ display: flex;
89
+ overflow-x: auto;
90
+ scroll-snap-type: x mandatory;
91
+ scroll-behavior: smooth;
92
+ border-radius: var(--viking-radius);
93
+ border: 1px solid var(--viking-border);
94
+ background: var(--viking-surface);
95
+ scrollbar-width: none;
96
+ }
97
+ .viking-carousel-viewport::-webkit-scrollbar {
98
+ display: none;
99
+ }
100
+ .viking-carousel-viewport:focus-visible {
101
+ outline: var(--viking-ring-width) solid var(--viking-ring);
102
+ outline-offset: var(--viking-ring-offset);
103
+ }
104
+ .viking-carousel-controls {
105
+ display: flex;
106
+ align-items: center;
107
+ justify-content: center;
108
+ gap: var(--viking-space-2);
109
+ margin-top: var(--viking-space-1);
110
+ }
111
+ .viking-carousel-nav {
112
+ display: inline-flex;
113
+ align-items: center;
114
+ justify-content: center;
115
+ min-width: var(--viking-touch-target-comfort);
116
+ min-height: var(--viking-touch-target-comfort);
117
+ border: 1px solid var(--viking-border-strong);
118
+ background: var(--viking-surface);
119
+ color: var(--viking-text);
120
+ border-radius: var(--viking-radius-pill);
121
+ padding: var(--viking-space-1);
122
+ cursor: pointer;
123
+ transition: var(--viking-transition-interactive);
124
+ -webkit-tap-highlight-color: transparent;
125
+ }
126
+ .viking-carousel-nav:hover:not(:disabled) {
127
+ border-color: var(--viking-accent-strong);
128
+ background: var(--viking-accent-soft);
129
+ box-shadow: var(--viking-shadow-sm);
130
+ transform: translateY(var(--viking-state-hover-lift));
131
+ }
132
+ .viking-carousel-nav:active:not(:disabled) {
133
+ transform: translateY(0) scale(var(--viking-state-active-scale));
134
+ }
135
+ .viking-carousel-nav:focus-visible {
136
+ outline: var(--viking-ring-width) solid var(--viking-ring);
137
+ outline-offset: var(--viking-ring-offset);
138
+ }
139
+ .viking-carousel-nav:disabled {
140
+ opacity: 0.45;
141
+ cursor: not-allowed;
142
+ }
143
+ .viking-carousel-dots {
144
+ display: flex;
145
+ gap: var(--viking-space-1);
146
+ }
147
+ .viking-carousel-dot {
148
+ position: relative;
149
+ width: var(--viking-space-1);
150
+ height: var(--viking-space-1);
151
+ border-radius: var(--viking-radius-pill);
152
+ border: 1px solid var(--viking-border-strong);
153
+ background: var(--viking-surface-alt);
154
+ cursor: pointer;
155
+ padding: 0;
156
+ transition: var(--viking-transition-interactive);
157
+ -webkit-tap-highlight-color: transparent;
158
+ }
159
+ .viking-carousel-dot::before {
160
+ content: "";
161
+ position: absolute;
162
+ inset: 50%;
163
+ width: var(--viking-touch-target-min);
164
+ height: var(--viking-touch-target-min);
165
+ transform: translate(-50%, -50%);
166
+ }
167
+ .viking-carousel-dot:hover:not(.viking-active) {
168
+ border-color: var(--viking-accent-strong);
169
+ background: var(--viking-accent-soft);
170
+ }
171
+ .viking-carousel-dot.viking-active {
172
+ background: var(--viking-accent);
173
+ border-color: var(--viking-accent);
174
+ box-shadow: 0 0 0 2px var(--viking-accent-soft);
175
+ }
176
+ .viking-carousel-dot:focus-visible {
177
+ outline: var(--viking-ring-width) solid var(--viking-ring);
178
+ outline-offset: var(--viking-ring-offset);
179
+ }
180
+ `,
181
+ ],
182
+ })
183
+ export class VikingCarousel {
184
+ private readonly viewport =
185
+ viewChild.required<ElementRef<HTMLElement>>("viewport");
186
+
187
+ protected readonly slides = contentChildren(VikingCarouselSlide);
188
+ protected readonly index = signal(0);
189
+
190
+ protected goTo = (target: number): void => {
191
+ const clamped = Math.min(this.slides().length - 1, Math.max(0, target));
192
+ const element = this.viewport().nativeElement;
193
+ element.scrollTo({
194
+ left: clamped * element.clientWidth,
195
+ behavior: "smooth",
196
+ });
197
+ this.index.set(clamped);
198
+ };
199
+
200
+ protected onScroll = (): void => {
201
+ const element = this.viewport().nativeElement;
202
+ if (element.clientWidth > 0) {
203
+ this.index.set(Math.round(element.scrollLeft / element.clientWidth));
204
+ }
205
+ };
206
+ }
@@ -0,0 +1,65 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ clampChartWindow,
4
+ fullChartWindow,
5
+ panChartWindow,
6
+ sliceChartData,
7
+ zoomChartWindow,
8
+ } from "./chart-zoom";
9
+
10
+ describe("chart-zoom", () => {
11
+ it("returns full window for positive counts", () => {
12
+ expect(fullChartWindow(10)).toEqual({ start: 0, end: 10 });
13
+ expect(fullChartWindow(0)).toEqual({ start: 0, end: 1 });
14
+ });
15
+
16
+ it("clamps window to valid bounds with minimum span", () => {
17
+ expect(clampChartWindow({ start: -5, end: 20 }, 10, 3)).toEqual({
18
+ start: 0,
19
+ end: 10,
20
+ });
21
+ expect(clampChartWindow({ start: 0, end: 1 }, 10, 3)).toEqual({
22
+ start: 0,
23
+ end: 3,
24
+ });
25
+ expect(clampChartWindow({ start: 0, end: 0 }, 0, 3)).toEqual({
26
+ start: 0,
27
+ end: 0,
28
+ });
29
+ });
30
+
31
+ it("zooms in on wheel up and out on wheel down", () => {
32
+ const current = { start: 0, end: 20 };
33
+ const zoomedIn = zoomChartWindow(current, 20, 0.5, -100, 3);
34
+ const zoomedOut = zoomChartWindow(current, 20, 0.5, 100, 3);
35
+ expect(zoomedIn.end - zoomedIn.start).toBeLessThan(20);
36
+ expect(zoomedOut.end - zoomedOut.start).toBeGreaterThanOrEqual(20);
37
+ });
38
+
39
+ it("returns full window when count is at or below min span", () => {
40
+ expect(zoomChartWindow({ start: 0, end: 3 }, 3, 0.5, -100, 3)).toEqual({
41
+ start: 0,
42
+ end: 3,
43
+ });
44
+ });
45
+
46
+ it("pans window by delta points", () => {
47
+ expect(panChartWindow({ start: 5, end: 15 }, 20, 3, 3)).toEqual({
48
+ start: 2,
49
+ end: 12,
50
+ });
51
+ expect(panChartWindow({ start: 0, end: 10 }, 20, -5, 3)).toEqual({
52
+ start: 5,
53
+ end: 15,
54
+ });
55
+ });
56
+
57
+ it("slices data for the active window", () => {
58
+ const values = ["a", "b", "c", "d", "e"];
59
+ expect(sliceChartData(values, { start: 1, end: 4 })).toEqual([
60
+ "b",
61
+ "c",
62
+ "d",
63
+ ]);
64
+ });
65
+ });
@@ -0,0 +1,71 @@
1
+ /** Visible index window for chart zoom/pan (inclusive start, exclusive end). */
2
+ export interface ChartZoomWindow {
3
+ start: number;
4
+ end: number;
5
+ }
6
+
7
+ export const fullChartWindow = (count: number): ChartZoomWindow => ({
8
+ start: 0,
9
+ end: Math.max(count, 1),
10
+ });
11
+
12
+ /** Clamp zoom window to valid bounds with a minimum visible span. */
13
+ export const clampChartWindow = (
14
+ window: ChartZoomWindow,
15
+ count: number,
16
+ minSpan = 3,
17
+ ): ChartZoomWindow => {
18
+ if (count <= 0) {
19
+ return { start: 0, end: 0 };
20
+ }
21
+ const span = Math.max(minSpan, Math.min(count, window.end - window.start));
22
+ let start = Math.max(0, Math.min(window.start, count - span));
23
+ let end = start + span;
24
+ if (end > count) {
25
+ end = count;
26
+ start = Math.max(0, end - span);
27
+ }
28
+ return { start, end };
29
+ };
30
+
31
+ /** Wheel delta → narrower/wider window centered on cursor fraction (0–1). */
32
+ export const zoomChartWindow = (
33
+ current: ChartZoomWindow,
34
+ count: number,
35
+ cursorFraction: number,
36
+ deltaY: number,
37
+ minSpan = 3,
38
+ ): ChartZoomWindow => {
39
+ if (count <= minSpan) {
40
+ return fullChartWindow(count);
41
+ }
42
+ const span = current.end - current.start;
43
+ const factor = deltaY < 0 ? 0.85 : 1.15;
44
+ const nextSpan = Math.max(
45
+ minSpan,
46
+ Math.min(count, Math.round(span * factor)),
47
+ );
48
+ const anchor = current.start + span * cursorFraction;
49
+ const raw: ChartZoomWindow = {
50
+ start: Math.round(anchor - nextSpan * cursorFraction),
51
+ end: Math.round(anchor - nextSpan * cursorFraction) + nextSpan,
52
+ };
53
+ return clampChartWindow(raw, count, minSpan);
54
+ };
55
+
56
+ /** Drag delta in data points → pan window. */
57
+ export const panChartWindow = (
58
+ current: ChartZoomWindow,
59
+ count: number,
60
+ deltaPoints: number,
61
+ minSpan = 3,
62
+ ): ChartZoomWindow =>
63
+ clampChartWindow(
64
+ { start: current.start - deltaPoints, end: current.end - deltaPoints },
65
+ count,
66
+ minSpan,
67
+ );
68
+
69
+ /** Slice series rows and category labels for the active window. */
70
+ export const sliceChartData = <T>(values: T[], window: ChartZoomWindow): T[] =>
71
+ values.slice(window.start, window.end);