chartgpu-angular 21.0.0 → 22.0.1

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.
@@ -1,260 +1,324 @@
1
- import { NgStyle } from '@angular/common';
2
- import * as i0 from '@angular/core';
3
- import { input, output, viewChild, signal, afterNextRender, effect, untracked, ChangeDetectionStrategy, Component, Directive, computed, Injectable, makeEnvironmentProviders } from '@angular/core';
4
- import { ChartGPU, connectCharts, createPipelineCache } from 'chartgpu';
5
-
6
- class ChartGpuAngularComponent {
7
- destroyRef;
8
- options = input.required(...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
9
- gpuContext = input(null, ...(ngDevMode ? [{ debugName: "gpuContext" }] : /* istanbul ignore next */ []));
10
- theme = input(undefined, ...(ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []));
11
- className = input(...(ngDevMode ? [undefined, { debugName: "className" }] : /* istanbul ignore next */ []));
12
- style = input(...(ngDevMode ? [undefined, { debugName: "style" }] : /* istanbul ignore next */ []));
13
- ready = output();
14
- chartReady = output();
15
- chartDispose = output();
16
- resize = output();
17
- click = output();
18
- chartClick = output();
19
- mouseOver = output();
20
- mouseOut = output();
21
- crosshairMove = output();
22
- dataAppend = output();
23
- zoomChange = output();
24
- zoomRangeChange = output();
25
- deviceLost = output();
26
- chartError = output();
27
- host = viewChild('host', ...(ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []));
28
- canvasHost = viewChild('canvasHost', ...(ngDevMode ? [{ debugName: "canvasHost" }] : /* istanbul ignore next */ []));
29
- chartInstance = signal(null, ...(ngDevMode ? [{ debugName: "chartInstance" }] : /* istanbul ignore next */ []));
30
- initializationError = signal(null, ...(ngDevMode ? [{ debugName: "initializationError" }] : /* istanbul ignore next */ []));
31
- chartContainer;
32
- createdWithOptions;
33
- resizeTimeout;
34
- resizeObserver;
35
- removeChartListeners;
36
- destroying = false;
37
- constructor(destroyRef) {
38
- this.destroyRef = destroyRef;
39
- this.destroyRef.onDestroy(() => {
40
- this.resizeObserver?.disconnect();
41
- if (this.resizeTimeout !== undefined) {
42
- clearTimeout(this.resizeTimeout);
43
- }
44
- this.disposeChart();
45
- });
46
- afterNextRender(() => {
47
- const container = this.host()?.nativeElement;
48
- if (container) {
49
- this.observeResize(container);
50
- }
51
- });
52
- effect(onCleanup => {
53
- const container = this.canvasHost()?.nativeElement;
54
- const options = this.options();
55
- const gpuContext = this.gpuContext();
56
- const theme = this.theme();
57
- this.initializationError.set(null);
58
- if (!container) {
59
- this.disposeChart();
60
- return;
61
- }
62
- if (typeof navigator === 'undefined' || !('gpu' in navigator)) {
63
- this.reportError(new Error('WebGPU not supported in this browser'));
64
- return;
65
- }
66
- if (untracked(() => this.chartInstance()) && this.chartContainer === container) {
67
- return;
68
- }
69
- let cancelled = false;
70
- let createdInstance;
71
- const initialOptions = this.getEffectiveOptions(options, theme);
72
- void (gpuContext
73
- ? ChartGPU.create(container, initialOptions, gpuContext)
74
- : ChartGPU.create(container, initialOptions)).then(instance => {
75
- createdInstance = instance;
76
- if (cancelled) {
77
- instance.dispose();
78
- return;
79
- }
80
- try {
81
- const latest = untracked(() => ({
82
- options: this.options(),
83
- theme: this.theme(),
84
- }));
85
- if (latest.options !== options || latest.theme !== theme) {
86
- instance.setOption(this.getEffectiveOptions(latest.options, latest.theme));
87
- }
88
- this.createdWithOptions = latest;
89
- this.chartContainer = container;
90
- this.chartInstance.set(instance);
91
- this.removeChartListeners = this.listenToChart(instance);
92
- this.ready.emit({ container });
93
- this.chartReady.emit(instance);
94
- const range = instance.getZoomRange();
95
- if (range) {
96
- this.emitZoomRange(range);
97
- }
98
- }
99
- catch (cause) {
100
- instance.dispose();
101
- throw cause;
102
- }
103
- }).catch((cause) => {
104
- if (cancelled) {
105
- return;
106
- }
107
- if (createdInstance && this.chartInstance() !== createdInstance && !createdInstance.disposed) {
108
- createdInstance.dispose();
109
- }
110
- this.reportError(cause);
111
- });
112
- onCleanup(() => {
113
- cancelled = true;
114
- if (this.chartContainer === container) {
115
- this.disposeChart();
116
- }
117
- });
118
- }, { allowSignalWrites: true });
119
- effect(() => {
120
- const options = this.options();
121
- const theme = this.theme();
122
- const instance = this.chartInstance();
123
- if (!instance || instance.disposed) {
124
- return;
125
- }
126
- if (this.createdWithOptions?.options === options && this.createdWithOptions.theme === theme) {
127
- this.createdWithOptions = undefined;
128
- return;
129
- }
130
- try {
131
- instance.setOption(this.getEffectiveOptions(options, theme));
132
- }
133
- catch (cause) {
134
- this.reportError(cause);
135
- }
136
- }, { allowSignalWrites: true });
137
- }
138
- emitClick(event) {
139
- this.click.emit({ x: event.offsetX, y: event.offsetY });
140
- }
141
- ngOnDestroy() {
142
- this.destroying = true;
143
- }
144
- getChart() {
145
- const instance = this.chartInstance();
146
- return instance && !instance.disposed ? instance : null;
147
- }
148
- getContainer() {
149
- return this.canvasHost()?.nativeElement ?? null;
150
- }
151
- appendData(seriesIndex, newPoints, options) {
152
- this.getChart()?.appendData(seriesIndex, newPoints, options);
153
- }
154
- renderFrame() {
155
- return this.getChart()?.renderFrame() ?? false;
156
- }
157
- needsRender() {
158
- return this.getChart()?.needsRender() ?? false;
159
- }
160
- getRenderMode() {
161
- return this.getChart()?.getRenderMode() ?? 'auto';
162
- }
163
- setRenderMode(mode) {
164
- this.getChart()?.setRenderMode(mode);
165
- }
166
- setOption(options) {
167
- this.getChart()?.setOption(options);
168
- }
169
- setZoomRange(start, end, source) {
170
- this.getChart()?.setZoomRange(start, end, source);
171
- }
172
- setInteractionX(x, source) {
173
- this.getChart()?.setInteractionX(x, source);
174
- }
175
- getInteractionX() {
176
- return this.getChart()?.getInteractionX() ?? null;
177
- }
178
- hitTest(event) {
179
- return this.getChart()?.hitTest(event) ?? null;
180
- }
181
- getEffectiveOptions(options, theme) {
182
- return theme !== undefined ? { ...options, theme } : options;
183
- }
184
- listenToChart(instance) {
185
- const click = (payload) => this.chartClick.emit(payload);
186
- const mouseOver = (payload) => this.mouseOver.emit(payload);
187
- const mouseOut = (payload) => this.mouseOut.emit(payload);
188
- const crosshairMove = (payload) => this.crosshairMove.emit(payload);
189
- const dataAppend = (payload) => this.dataAppend.emit(payload);
190
- const zoomChange = (payload) => this.emitZoomRange(payload);
191
- const deviceLost = (payload) => this.deviceLost.emit(payload);
192
- instance.on('click', click);
193
- instance.on('mouseover', mouseOver);
194
- instance.on('mouseout', mouseOut);
195
- instance.on('crosshairMove', crosshairMove);
196
- instance.on('dataAppend', dataAppend);
197
- instance.on('zoomRangeChange', zoomChange);
198
- instance.on('deviceLost', deviceLost);
199
- return () => {
200
- if (instance.disposed) {
201
- return;
202
- }
203
- instance.off('click', click);
204
- instance.off('mouseover', mouseOver);
205
- instance.off('mouseout', mouseOut);
206
- instance.off('crosshairMove', crosshairMove);
207
- instance.off('dataAppend', dataAppend);
208
- instance.off('zoomRangeChange', zoomChange);
209
- instance.off('deviceLost', deviceLost);
210
- };
211
- }
212
- emitZoomRange(range) {
213
- this.zoomChange.emit({ range: { start: range.start, end: range.end } });
214
- this.zoomRangeChange.emit({ start: range.start, end: range.end });
215
- }
216
- observeResize(container) {
217
- if (typeof ResizeObserver === 'undefined') {
218
- return;
219
- }
220
- this.resizeObserver = new ResizeObserver(entries => {
221
- const entry = entries[0];
222
- if (!entry) {
223
- return;
224
- }
225
- const { width, height } = entry.contentRect;
226
- this.resize.emit({ width, height, container });
227
- if (this.resizeTimeout !== undefined) {
228
- clearTimeout(this.resizeTimeout);
229
- }
230
- this.resizeTimeout = setTimeout(() => {
231
- this.chartInstance()?.resize();
232
- this.resizeTimeout = undefined;
233
- }, 100);
234
- });
235
- this.resizeObserver.observe(container);
236
- }
237
- reportError(cause) {
238
- const error = cause instanceof Error ? cause : new Error(String(cause));
239
- this.initializationError.set(error);
240
- this.chartError.emit(error);
241
- }
242
- disposeChart() {
243
- const instance = this.chartInstance();
244
- this.removeChartListeners?.();
245
- this.removeChartListeners = undefined;
246
- if (instance && !instance.disposed) {
247
- instance.dispose();
248
- if (!this.destroying) {
249
- this.chartDispose.emit();
250
- }
251
- }
252
- this.chartInstance.set(null);
253
- this.chartContainer = undefined;
254
- this.createdWithOptions = undefined;
255
- }
256
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ChartGpuAngularComponent, deps: [{ token: i0.DestroyRef }], target: i0.ɵɵFactoryTarget.Component });
257
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.25", type: ChartGpuAngularComponent, isStandalone: true, selector: "lib-chartgpu-angular", inputs: { options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: true, transformFunction: null }, gpuContext: { classPropertyName: "gpuContext", publicName: "gpuContext", isSignal: true, isRequired: false, transformFunction: null }, theme: { classPropertyName: "theme", publicName: "theme", isSignal: true, isRequired: false, transformFunction: null }, className: { classPropertyName: "className", publicName: "className", isSignal: true, isRequired: false, transformFunction: null }, style: { classPropertyName: "style", publicName: "style", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { ready: "ready", chartReady: "chartReady", chartDispose: "chartDispose", resize: "resize", click: "click", chartClick: "chartClick", mouseOver: "mouseOver", mouseOut: "mouseOut", crosshairMove: "crosshairMove", dataAppend: "dataAppend", zoomChange: "zoomChange", zoomRangeChange: "zoomRangeChange", deviceLost: "deviceLost", chartError: "chartError" }, host: { classAttribute: "chartgpu-angular" }, viewQueries: [{ propertyName: "host", first: true, predicate: ["host"], descendants: true, isSignal: true }, { propertyName: "canvasHost", first: true, predicate: ["canvasHost"], descendants: true, isSignal: true }], ngImport: i0, template: `
1
+ import { NgStyle } from "@angular/common";
2
+ import * as i0 from "@angular/core";
3
+ import { ChangeDetectionStrategy, Component, Directive, Injectable, afterNextRender, computed, effect, input, makeEnvironmentProviders, output, signal, untracked, viewChild } from "@angular/core";
4
+ import { ChartGPU, connectCharts, createPipelineCache } from "chartgpu";
5
+ var ChartGpuAngularComponent = class ChartGpuAngularComponent {
6
+ destroyRef;
7
+ options = input.required(...ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []);
8
+ gpuContext = input(null, ...ngDevMode ? [{ debugName: "gpuContext" }] : /* istanbul ignore next */ []);
9
+ theme = input(void 0, ...ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []);
10
+ className = input(...ngDevMode ? [void 0, { debugName: "className" }] : /* istanbul ignore next */ []);
11
+ style = input(...ngDevMode ? [void 0, { debugName: "style" }] : /* istanbul ignore next */ []);
12
+ ready = output();
13
+ chartReady = output();
14
+ chartDispose = output();
15
+ resize = output();
16
+ click = output();
17
+ chartClick = output();
18
+ mouseOver = output();
19
+ mouseOut = output();
20
+ crosshairMove = output();
21
+ dataAppend = output();
22
+ zoomChange = output();
23
+ zoomRangeChange = output();
24
+ deviceLost = output();
25
+ chartError = output();
26
+ host = viewChild("host", ...ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []);
27
+ canvasHost = viewChild("canvasHost", ...ngDevMode ? [{ debugName: "canvasHost" }] : /* istanbul ignore next */ []);
28
+ chartInstance = signal(null, ...ngDevMode ? [{ debugName: "chartInstance" }] : /* istanbul ignore next */ []);
29
+ initializationError = signal(null, ...ngDevMode ? [{ debugName: "initializationError" }] : /* istanbul ignore next */ []);
30
+ chartContainer;
31
+ createdWithOptions;
32
+ resizeTimeout;
33
+ resizeObserver;
34
+ removeChartListeners;
35
+ destroying = false;
36
+ constructor(destroyRef) {
37
+ this.destroyRef = destroyRef;
38
+ this.destroyRef.onDestroy(() => {
39
+ this.resizeObserver?.disconnect();
40
+ if (this.resizeTimeout !== void 0) clearTimeout(this.resizeTimeout);
41
+ this.disposeChart();
42
+ });
43
+ afterNextRender(() => {
44
+ const container = this.host()?.nativeElement;
45
+ if (container) this.observeResize(container);
46
+ });
47
+ effect((onCleanup) => {
48
+ const container = this.canvasHost()?.nativeElement;
49
+ const options = this.options();
50
+ const gpuContext = this.gpuContext();
51
+ const theme = this.theme();
52
+ this.initializationError.set(null);
53
+ if (!container) {
54
+ this.disposeChart();
55
+ return;
56
+ }
57
+ if (typeof navigator === "undefined" || !("gpu" in navigator)) {
58
+ this.reportError(/* @__PURE__ */ new Error("WebGPU not supported in this browser"));
59
+ return;
60
+ }
61
+ if (untracked(() => this.chartInstance()) && this.chartContainer === container) return;
62
+ let cancelled = false;
63
+ let createdInstance;
64
+ const initialOptions = this.getEffectiveOptions(options, theme);
65
+ (gpuContext ? ChartGPU.create(container, initialOptions, gpuContext) : ChartGPU.create(container, initialOptions)).then((instance) => {
66
+ createdInstance = instance;
67
+ if (cancelled) {
68
+ instance.dispose();
69
+ return;
70
+ }
71
+ try {
72
+ const latest = untracked(() => ({
73
+ options: this.options(),
74
+ theme: this.theme()
75
+ }));
76
+ if (latest.options !== options || latest.theme !== theme) instance.setOption(this.getEffectiveOptions(latest.options, latest.theme));
77
+ this.createdWithOptions = latest;
78
+ this.chartContainer = container;
79
+ this.chartInstance.set(instance);
80
+ this.removeChartListeners = this.listenToChart(instance);
81
+ this.ready.emit({ container });
82
+ this.chartReady.emit(instance);
83
+ const range = instance.getZoomRange();
84
+ if (range) this.emitZoomRange(range);
85
+ } catch (cause) {
86
+ instance.dispose();
87
+ throw cause;
88
+ }
89
+ }).catch((cause) => {
90
+ if (cancelled) return;
91
+ if (createdInstance && this.chartInstance() !== createdInstance && !createdInstance.disposed) createdInstance.dispose();
92
+ this.reportError(cause);
93
+ });
94
+ onCleanup(() => {
95
+ cancelled = true;
96
+ if (this.chartContainer === container) this.disposeChart();
97
+ });
98
+ }, { allowSignalWrites: true });
99
+ effect(() => {
100
+ const options = this.options();
101
+ const theme = this.theme();
102
+ const instance = this.chartInstance();
103
+ if (!instance || instance.disposed) return;
104
+ if (this.createdWithOptions?.options === options && this.createdWithOptions.theme === theme) {
105
+ this.createdWithOptions = void 0;
106
+ return;
107
+ }
108
+ try {
109
+ instance.setOption(this.getEffectiveOptions(options, theme));
110
+ } catch (cause) {
111
+ this.reportError(cause);
112
+ }
113
+ }, { allowSignalWrites: true });
114
+ }
115
+ emitClick(event) {
116
+ this.click.emit({
117
+ x: event.offsetX,
118
+ y: event.offsetY
119
+ });
120
+ }
121
+ ngOnDestroy() {
122
+ this.destroying = true;
123
+ }
124
+ getChart() {
125
+ const instance = this.chartInstance();
126
+ return instance && !instance.disposed ? instance : null;
127
+ }
128
+ getContainer() {
129
+ return this.canvasHost()?.nativeElement ?? null;
130
+ }
131
+ appendData(seriesIndex, newPoints, options) {
132
+ this.getChart()?.appendData(seriesIndex, newPoints, options);
133
+ }
134
+ renderFrame() {
135
+ return this.getChart()?.renderFrame() ?? false;
136
+ }
137
+ needsRender() {
138
+ return this.getChart()?.needsRender() ?? false;
139
+ }
140
+ getRenderMode() {
141
+ return this.getChart()?.getRenderMode() ?? "auto";
142
+ }
143
+ setRenderMode(mode) {
144
+ this.getChart()?.setRenderMode(mode);
145
+ }
146
+ setOption(options) {
147
+ this.getChart()?.setOption(options);
148
+ }
149
+ setZoomRange(start, end, source) {
150
+ this.getChart()?.setZoomRange(start, end, source);
151
+ }
152
+ setInteractionX(x, source) {
153
+ this.getChart()?.setInteractionX(x, source);
154
+ }
155
+ getInteractionX() {
156
+ return this.getChart()?.getInteractionX() ?? null;
157
+ }
158
+ hitTest(event) {
159
+ return this.getChart()?.hitTest(event) ?? null;
160
+ }
161
+ getEffectiveOptions(options, theme) {
162
+ return theme !== void 0 ? {
163
+ ...options,
164
+ theme
165
+ } : options;
166
+ }
167
+ listenToChart(instance) {
168
+ const click = (payload) => this.chartClick.emit(payload);
169
+ const mouseOver = (payload) => this.mouseOver.emit(payload);
170
+ const mouseOut = (payload) => this.mouseOut.emit(payload);
171
+ const crosshairMove = (payload) => this.crosshairMove.emit(payload);
172
+ const dataAppend = (payload) => this.dataAppend.emit(payload);
173
+ const zoomChange = (payload) => this.emitZoomRange(payload);
174
+ const deviceLost = (payload) => this.deviceLost.emit(payload);
175
+ instance.on("click", click);
176
+ instance.on("mouseover", mouseOver);
177
+ instance.on("mouseout", mouseOut);
178
+ instance.on("crosshairMove", crosshairMove);
179
+ instance.on("dataAppend", dataAppend);
180
+ instance.on("zoomRangeChange", zoomChange);
181
+ instance.on("deviceLost", deviceLost);
182
+ return () => {
183
+ if (instance.disposed) return;
184
+ instance.off("click", click);
185
+ instance.off("mouseover", mouseOver);
186
+ instance.off("mouseout", mouseOut);
187
+ instance.off("crosshairMove", crosshairMove);
188
+ instance.off("dataAppend", dataAppend);
189
+ instance.off("zoomRangeChange", zoomChange);
190
+ instance.off("deviceLost", deviceLost);
191
+ };
192
+ }
193
+ emitZoomRange(range) {
194
+ this.zoomChange.emit({ range: {
195
+ start: range.start,
196
+ end: range.end
197
+ } });
198
+ this.zoomRangeChange.emit({
199
+ start: range.start,
200
+ end: range.end
201
+ });
202
+ }
203
+ observeResize(container) {
204
+ if (typeof ResizeObserver === "undefined") return;
205
+ this.resizeObserver = new ResizeObserver((entries) => {
206
+ const entry = entries[0];
207
+ if (!entry) return;
208
+ const { width, height } = entry.contentRect;
209
+ this.resize.emit({
210
+ width,
211
+ height,
212
+ container
213
+ });
214
+ if (this.resizeTimeout !== void 0) clearTimeout(this.resizeTimeout);
215
+ this.resizeTimeout = setTimeout(() => {
216
+ this.chartInstance()?.resize();
217
+ this.resizeTimeout = void 0;
218
+ }, 100);
219
+ });
220
+ this.resizeObserver.observe(container);
221
+ }
222
+ reportError(cause) {
223
+ const error = cause instanceof Error ? cause : new Error(String(cause));
224
+ this.initializationError.set(error);
225
+ this.chartError.emit(error);
226
+ }
227
+ disposeChart() {
228
+ const instance = this.chartInstance();
229
+ this.removeChartListeners?.();
230
+ this.removeChartListeners = void 0;
231
+ if (instance && !instance.disposed) {
232
+ instance.dispose();
233
+ if (!this.destroying) this.chartDispose.emit();
234
+ }
235
+ this.chartInstance.set(null);
236
+ this.chartContainer = void 0;
237
+ this.createdWithOptions = void 0;
238
+ }
239
+ static ɵfac = i0.ɵɵngDeclareFactory({
240
+ minVersion: "12.0.0",
241
+ version: "22.2.3",
242
+ ngImport: i0,
243
+ type: ChartGpuAngularComponent,
244
+ deps: [{ token: i0.DestroyRef }],
245
+ target: i0.ɵɵFactoryTarget.Component
246
+ });
247
+ static ɵcmp = i0.ɵɵngDeclareComponent({
248
+ minVersion: "17.0.0",
249
+ version: "22.2.3",
250
+ type: ChartGpuAngularComponent,
251
+ isStandalone: true,
252
+ selector: "lib-chartgpu-angular",
253
+ inputs: {
254
+ options: {
255
+ classPropertyName: "options",
256
+ publicName: "options",
257
+ isSignal: true,
258
+ isRequired: true,
259
+ transformFunction: null
260
+ },
261
+ gpuContext: {
262
+ classPropertyName: "gpuContext",
263
+ publicName: "gpuContext",
264
+ isSignal: true,
265
+ isRequired: false,
266
+ transformFunction: null
267
+ },
268
+ theme: {
269
+ classPropertyName: "theme",
270
+ publicName: "theme",
271
+ isSignal: true,
272
+ isRequired: false,
273
+ transformFunction: null
274
+ },
275
+ className: {
276
+ classPropertyName: "className",
277
+ publicName: "className",
278
+ isSignal: true,
279
+ isRequired: false,
280
+ transformFunction: null
281
+ },
282
+ style: {
283
+ classPropertyName: "style",
284
+ publicName: "style",
285
+ isSignal: true,
286
+ isRequired: false,
287
+ transformFunction: null
288
+ }
289
+ },
290
+ outputs: {
291
+ ready: "ready",
292
+ chartReady: "chartReady",
293
+ chartDispose: "chartDispose",
294
+ resize: "resize",
295
+ click: "click",
296
+ chartClick: "chartClick",
297
+ mouseOver: "mouseOver",
298
+ mouseOut: "mouseOut",
299
+ crosshairMove: "crosshairMove",
300
+ dataAppend: "dataAppend",
301
+ zoomChange: "zoomChange",
302
+ zoomRangeChange: "zoomRangeChange",
303
+ deviceLost: "deviceLost",
304
+ chartError: "chartError"
305
+ },
306
+ host: { classAttribute: "chartgpu-angular" },
307
+ viewQueries: [{
308
+ propertyName: "host",
309
+ first: true,
310
+ predicate: ["host"],
311
+ descendants: true,
312
+ isSignal: true
313
+ }, {
314
+ propertyName: "canvasHost",
315
+ first: true,
316
+ predicate: ["canvasHost"],
317
+ descendants: true,
318
+ isSignal: true
319
+ }],
320
+ ngImport: i0,
321
+ template: `
258
322
  <div
259
323
  #host
260
324
  class="chartgpu-host"
@@ -267,11 +331,32 @@ class ChartGpuAngularComponent {
267
331
  <div class="chartgpu-error" role="alert">{{ error.message }}</div>
268
332
  }
269
333
  </div>
270
- `, isInline: true, styles: [":host{display:block;width:100%;height:100%}.chartgpu-host{position:relative;width:100%;height:100%}.chartgpu-canvas-host{position:absolute;inset:0}.chartgpu-error{position:absolute;inset:0;display:grid;place-items:center;padding:1rem;text-align:center}\n"], dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
271
- }
272
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ChartGpuAngularComponent, decorators: [{
273
- type: Component,
274
- args: [{ selector: 'lib-chartgpu-angular', standalone: true, imports: [NgStyle], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'chartgpu-angular' }, template: `
334
+ `,
335
+ isInline: true,
336
+ styles: [":host{display:block;width:100%;height:100%}.chartgpu-host{position:relative;width:100%;height:100%}.chartgpu-canvas-host{position:absolute;inset:0}.chartgpu-error{position:absolute;inset:0;display:grid;place-items:center;padding:1rem;text-align:center}\n"],
337
+ dependencies: [{
338
+ kind: "directive",
339
+ type: NgStyle,
340
+ selector: "[ngStyle]",
341
+ inputs: ["ngStyle"]
342
+ }],
343
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
344
+ });
345
+ };
346
+ i0.ɵɵngDeclareClassMetadata({
347
+ minVersion: "12.0.0",
348
+ version: "22.2.3",
349
+ ngImport: i0,
350
+ type: ChartGpuAngularComponent,
351
+ decorators: [{
352
+ type: Component,
353
+ args: [{
354
+ selector: "lib-chartgpu-angular",
355
+ standalone: true,
356
+ imports: [NgStyle],
357
+ changeDetection: ChangeDetectionStrategy.OnPush,
358
+ host: { class: "chartgpu-angular" },
359
+ template: `
275
360
  <div
276
361
  #host
277
362
  class="chartgpu-host"
@@ -284,150 +369,314 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImpo
284
369
  <div class="chartgpu-error" role="alert">{{ error.message }}</div>
285
370
  }
286
371
  </div>
287
- `, styles: [":host{display:block;width:100%;height:100%}.chartgpu-host{position:relative;width:100%;height:100%}.chartgpu-canvas-host{position:absolute;inset:0}.chartgpu-error{position:absolute;inset:0;display:grid;place-items:center;padding:1rem;text-align:center}\n"] }]
288
- }], ctorParameters: () => [{ type: i0.DestroyRef }], propDecorators: { options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: true }] }], gpuContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "gpuContext", required: false }] }], theme: [{ type: i0.Input, args: [{ isSignal: true, alias: "theme", required: false }] }], className: [{ type: i0.Input, args: [{ isSignal: true, alias: "className", required: false }] }], style: [{ type: i0.Input, args: [{ isSignal: true, alias: "style", required: false }] }], ready: [{ type: i0.Output, args: ["ready"] }], chartReady: [{ type: i0.Output, args: ["chartReady"] }], chartDispose: [{ type: i0.Output, args: ["chartDispose"] }], resize: [{ type: i0.Output, args: ["resize"] }], click: [{ type: i0.Output, args: ["click"] }], chartClick: [{ type: i0.Output, args: ["chartClick"] }], mouseOver: [{ type: i0.Output, args: ["mouseOver"] }], mouseOut: [{ type: i0.Output, args: ["mouseOut"] }], crosshairMove: [{ type: i0.Output, args: ["crosshairMove"] }], dataAppend: [{ type: i0.Output, args: ["dataAppend"] }], zoomChange: [{ type: i0.Output, args: ["zoomChange"] }], zoomRangeChange: [{ type: i0.Output, args: ["zoomRangeChange"] }], deviceLost: [{ type: i0.Output, args: ["deviceLost"] }], chartError: [{ type: i0.Output, args: ["chartError"] }], host: [{ type: i0.ViewChild, args: ['host', { isSignal: true }] }], canvasHost: [{ type: i0.ViewChild, args: ['canvasHost', { isSignal: true }] }] } });
289
-
290
- class ChartgpuConnectChartsDirective {
291
- charts = input([], { ...(ngDevMode ? { debugName: "charts" } : /* istanbul ignore next */ {}), alias: 'libChartgpuConnectCharts' });
292
- syncOptions = input(...(ngDevMode ? [undefined, { debugName: "syncOptions" }] : /* istanbul ignore next */ []));
293
- connectionError = output();
294
- ids = new WeakMap();
295
- nextId = 1;
296
- signature;
297
- constructor() {
298
- effect(onCleanup => {
299
- const charts = this.charts();
300
- const options = this.syncOptions();
301
- const optionsSignature = options
302
- ? `crosshair=${options.syncCrosshair ?? ''},zoom=${options.syncZoom ?? ''}`
303
- : '';
304
- const signature = `${charts.map(chart => {
305
- if (!chart) {
306
- return 'null';
307
- }
308
- let id = this.ids.get(chart);
309
- if (id === undefined) {
310
- id = this.nextId++;
311
- this.ids.set(chart, id);
312
- }
313
- return `${id}:${chart.disposed ? 1 : 0}`;
314
- }).join('|')}|${optionsSignature}`;
315
- if (signature === this.signature) {
316
- return;
317
- }
318
- this.signature = signature;
319
- if (charts.length === 0 || charts.some(chart => !chart || chart.disposed)) {
320
- return;
321
- }
322
- const resolved = [];
323
- for (const chart of charts) {
324
- if (!chart || chart.disposed) {
325
- return;
326
- }
327
- resolved.push(chart);
328
- }
329
- try {
330
- const disconnect = connectCharts(resolved, options);
331
- onCleanup(disconnect);
332
- }
333
- catch (cause) {
334
- this.connectionError.emit(cause instanceof Error ? cause : new Error(String(cause)));
335
- }
336
- });
337
- }
338
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ChartgpuConnectChartsDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
339
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.25", type: ChartgpuConnectChartsDirective, isStandalone: true, selector: "[libChartgpuConnectCharts]", inputs: { charts: { classPropertyName: "charts", publicName: "libChartgpuConnectCharts", isSignal: true, isRequired: false, transformFunction: null }, syncOptions: { classPropertyName: "syncOptions", publicName: "syncOptions", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { connectionError: "connectionError" }, ngImport: i0 });
340
- }
341
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ChartgpuConnectChartsDirective, decorators: [{
342
- type: Directive,
343
- args: [{
344
- selector: '[libChartgpuConnectCharts]',
345
- standalone: true,
346
- }]
347
- }], ctorParameters: () => [], propDecorators: { charts: [{ type: i0.Input, args: [{ isSignal: true, alias: "libChartgpuConnectCharts", required: false }] }], syncOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "syncOptions", required: false }] }], connectionError: [{ type: i0.Output, args: ["connectionError"] }] } });
348
-
372
+ `,
373
+ styles: [":host{display:block;width:100%;height:100%}.chartgpu-host{position:relative;width:100%;height:100%}.chartgpu-canvas-host{position:absolute;inset:0}.chartgpu-error{position:absolute;inset:0;display:grid;place-items:center;padding:1rem;text-align:center}\n"]
374
+ }]
375
+ }],
376
+ ctorParameters: () => [{ type: i0.DestroyRef }],
377
+ propDecorators: {
378
+ options: [{
379
+ type: i0.Input,
380
+ args: [{
381
+ isSignal: true,
382
+ alias: "options",
383
+ required: true
384
+ }]
385
+ }],
386
+ gpuContext: [{
387
+ type: i0.Input,
388
+ args: [{
389
+ isSignal: true,
390
+ alias: "gpuContext",
391
+ required: false
392
+ }]
393
+ }],
394
+ theme: [{
395
+ type: i0.Input,
396
+ args: [{
397
+ isSignal: true,
398
+ alias: "theme",
399
+ required: false
400
+ }]
401
+ }],
402
+ className: [{
403
+ type: i0.Input,
404
+ args: [{
405
+ isSignal: true,
406
+ alias: "className",
407
+ required: false
408
+ }]
409
+ }],
410
+ style: [{
411
+ type: i0.Input,
412
+ args: [{
413
+ isSignal: true,
414
+ alias: "style",
415
+ required: false
416
+ }]
417
+ }],
418
+ ready: [{
419
+ type: i0.Output,
420
+ args: ["ready"]
421
+ }],
422
+ chartReady: [{
423
+ type: i0.Output,
424
+ args: ["chartReady"]
425
+ }],
426
+ chartDispose: [{
427
+ type: i0.Output,
428
+ args: ["chartDispose"]
429
+ }],
430
+ resize: [{
431
+ type: i0.Output,
432
+ args: ["resize"]
433
+ }],
434
+ click: [{
435
+ type: i0.Output,
436
+ args: ["click"]
437
+ }],
438
+ chartClick: [{
439
+ type: i0.Output,
440
+ args: ["chartClick"]
441
+ }],
442
+ mouseOver: [{
443
+ type: i0.Output,
444
+ args: ["mouseOver"]
445
+ }],
446
+ mouseOut: [{
447
+ type: i0.Output,
448
+ args: ["mouseOut"]
449
+ }],
450
+ crosshairMove: [{
451
+ type: i0.Output,
452
+ args: ["crosshairMove"]
453
+ }],
454
+ dataAppend: [{
455
+ type: i0.Output,
456
+ args: ["dataAppend"]
457
+ }],
458
+ zoomChange: [{
459
+ type: i0.Output,
460
+ args: ["zoomChange"]
461
+ }],
462
+ zoomRangeChange: [{
463
+ type: i0.Output,
464
+ args: ["zoomRangeChange"]
465
+ }],
466
+ deviceLost: [{
467
+ type: i0.Output,
468
+ args: ["deviceLost"]
469
+ }],
470
+ chartError: [{
471
+ type: i0.Output,
472
+ args: ["chartError"]
473
+ }],
474
+ host: [{
475
+ type: i0.ViewChild,
476
+ args: ["host", { isSignal: true }]
477
+ }],
478
+ canvasHost: [{
479
+ type: i0.ViewChild,
480
+ args: ["canvasHost", { isSignal: true }]
481
+ }]
482
+ }
483
+ });
484
+ var ChartgpuConnectChartsDirective = class ChartgpuConnectChartsDirective {
485
+ charts = input([], {
486
+ ...ngDevMode ? { debugName: "charts" } : /* istanbul ignore next */ {},
487
+ alias: "libChartgpuConnectCharts"
488
+ });
489
+ syncOptions = input(...ngDevMode ? [void 0, { debugName: "syncOptions" }] : /* istanbul ignore next */ []);
490
+ connectionError = output();
491
+ ids = /* @__PURE__ */ new WeakMap();
492
+ nextId = 1;
493
+ signature;
494
+ constructor() {
495
+ effect((onCleanup) => {
496
+ const charts = this.charts();
497
+ const options = this.syncOptions();
498
+ const optionsSignature = options ? `crosshair=${options.syncCrosshair ?? ""},zoom=${options.syncZoom ?? ""}` : "";
499
+ const signature = `${charts.map((chart) => {
500
+ if (!chart) return "null";
501
+ let id = this.ids.get(chart);
502
+ if (id === void 0) {
503
+ id = this.nextId++;
504
+ this.ids.set(chart, id);
505
+ }
506
+ return `${id}:${chart.disposed ? 1 : 0}`;
507
+ }).join("|")}|${optionsSignature}`;
508
+ if (signature === this.signature) return;
509
+ this.signature = signature;
510
+ if (charts.length === 0 || charts.some((chart) => !chart || chart.disposed)) return;
511
+ const resolved = [];
512
+ for (const chart of charts) {
513
+ if (!chart || chart.disposed) return;
514
+ resolved.push(chart);
515
+ }
516
+ try {
517
+ onCleanup(connectCharts(resolved, options));
518
+ } catch (cause) {
519
+ this.connectionError.emit(cause instanceof Error ? cause : new Error(String(cause)));
520
+ }
521
+ });
522
+ }
523
+ static ɵfac = i0.ɵɵngDeclareFactory({
524
+ minVersion: "12.0.0",
525
+ version: "22.2.3",
526
+ ngImport: i0,
527
+ type: ChartgpuConnectChartsDirective,
528
+ deps: [],
529
+ target: i0.ɵɵFactoryTarget.Directive
530
+ });
531
+ static ɵdir = i0.ɵɵngDeclareDirective({
532
+ minVersion: "17.1.0",
533
+ version: "22.2.3",
534
+ type: ChartgpuConnectChartsDirective,
535
+ isStandalone: true,
536
+ selector: "[libChartgpuConnectCharts]",
537
+ inputs: {
538
+ charts: {
539
+ classPropertyName: "charts",
540
+ publicName: "libChartgpuConnectCharts",
541
+ isSignal: true,
542
+ isRequired: false,
543
+ transformFunction: null
544
+ },
545
+ syncOptions: {
546
+ classPropertyName: "syncOptions",
547
+ publicName: "syncOptions",
548
+ isSignal: true,
549
+ isRequired: false,
550
+ transformFunction: null
551
+ }
552
+ },
553
+ outputs: { connectionError: "connectionError" },
554
+ ngImport: i0
555
+ });
556
+ };
557
+ i0.ɵɵngDeclareClassMetadata({
558
+ minVersion: "12.0.0",
559
+ version: "22.2.3",
560
+ ngImport: i0,
561
+ type: ChartgpuConnectChartsDirective,
562
+ decorators: [{
563
+ type: Directive,
564
+ args: [{
565
+ selector: "[libChartgpuConnectCharts]",
566
+ standalone: true
567
+ }]
568
+ }],
569
+ ctorParameters: () => [],
570
+ propDecorators: {
571
+ charts: [{
572
+ type: i0.Input,
573
+ args: [{
574
+ isSignal: true,
575
+ alias: "libChartgpuConnectCharts",
576
+ required: false
577
+ }]
578
+ }],
579
+ syncOptions: [{
580
+ type: i0.Input,
581
+ args: [{
582
+ isSignal: true,
583
+ alias: "syncOptions",
584
+ required: false
585
+ }]
586
+ }],
587
+ connectionError: [{
588
+ type: i0.Output,
589
+ args: ["connectionError"]
590
+ }]
591
+ }
592
+ });
349
593
  const INITIAL_STATE = {
350
- adapter: null,
351
- device: null,
352
- pipelineCache: null,
353
- error: null,
354
- isReady: false,
594
+ adapter: null,
595
+ device: null,
596
+ pipelineCache: null,
597
+ error: null,
598
+ isReady: false
355
599
  };
356
- /**
357
- * Creates one shared WebGPU context and pipeline cache for charts in a dashboard.
358
- * The device is intentionally not destroyed with the service so charts can share it
359
- * for the lifetime of the application.
360
- */
361
- class ChartgpuGPUContextService {
362
- state = signal(INITIAL_STATE, ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
363
- context = computed(() => {
364
- const state = this.state();
365
- if (!state.adapter || !state.device || !state.pipelineCache) {
366
- return null;
367
- }
368
- return {
369
- adapter: state.adapter,
370
- device: state.device,
371
- pipelineCache: state.pipelineCache,
372
- };
373
- }, ...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
374
- initialization;
375
- initialize() {
376
- if (!this.initialization) {
377
- this.initialization = this.createContext();
378
- }
379
- return this.initialization;
380
- }
381
- async createContext() {
382
- try {
383
- if (typeof navigator === 'undefined' || !('gpu' in navigator)) {
384
- throw new Error('WebGPU not supported in this browser');
385
- }
386
- const gpu = navigator.gpu;
387
- if (!gpu) {
388
- throw new Error('WebGPU not supported in this browser');
389
- }
390
- const adapter = await gpu.requestAdapter({ powerPreference: 'high-performance' });
391
- if (!adapter) {
392
- const error = new Error('WebGPU is not available. No compatible GPUAdapter was found.');
393
- const state = { ...INITIAL_STATE, error };
394
- this.state.set(state);
395
- return state;
396
- }
397
- const device = await adapter.requestDevice();
398
- const pipelineCache = createPipelineCache(device);
399
- const state = {
400
- adapter,
401
- device,
402
- pipelineCache,
403
- error: null,
404
- isReady: true,
405
- };
406
- this.state.set(state);
407
- return state;
408
- }
409
- catch (cause) {
410
- const error = cause instanceof Error ? cause : new Error(String(cause));
411
- const state = { ...INITIAL_STATE, error };
412
- this.state.set(state);
413
- return state;
414
- }
415
- }
416
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ChartgpuGPUContextService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
417
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ChartgpuGPUContextService, providedIn: 'root' });
418
- }
419
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ChartgpuGPUContextService, decorators: [{
420
- type: Injectable,
421
- args: [{ providedIn: 'root' }]
422
- }] });
423
-
600
+ var ChartgpuGPUContextService = class ChartgpuGPUContextService {
601
+ state = signal(INITIAL_STATE, ...ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []);
602
+ context = computed(() => {
603
+ const state = this.state();
604
+ if (!state.adapter || !state.device || !state.pipelineCache) return null;
605
+ return {
606
+ adapter: state.adapter,
607
+ device: state.device,
608
+ pipelineCache: state.pipelineCache
609
+ };
610
+ }, ...ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []);
611
+ initialization;
612
+ initialize() {
613
+ if (!this.initialization) this.initialization = this.createContext();
614
+ return this.initialization;
615
+ }
616
+ async createContext() {
617
+ try {
618
+ if (typeof navigator === "undefined" || !("gpu" in navigator)) throw new Error("WebGPU not supported in this browser");
619
+ const gpu = navigator.gpu;
620
+ if (!gpu) throw new Error("WebGPU not supported in this browser");
621
+ const adapter = await gpu.requestAdapter({ powerPreference: "high-performance" });
622
+ if (!adapter) {
623
+ const error = /* @__PURE__ */ new Error("WebGPU is not available. No compatible GPUAdapter was found.");
624
+ const state = {
625
+ ...INITIAL_STATE,
626
+ error
627
+ };
628
+ this.state.set(state);
629
+ return state;
630
+ }
631
+ const device = await adapter.requestDevice();
632
+ const state = {
633
+ adapter,
634
+ device,
635
+ pipelineCache: createPipelineCache(device),
636
+ error: null,
637
+ isReady: true
638
+ };
639
+ this.state.set(state);
640
+ return state;
641
+ } catch (cause) {
642
+ const error = cause instanceof Error ? cause : new Error(String(cause));
643
+ const state = {
644
+ ...INITIAL_STATE,
645
+ error
646
+ };
647
+ this.state.set(state);
648
+ return state;
649
+ }
650
+ }
651
+ static ɵfac = i0.ɵɵngDeclareFactory({
652
+ minVersion: "12.0.0",
653
+ version: "22.2.3",
654
+ ngImport: i0,
655
+ type: ChartgpuGPUContextService,
656
+ deps: [],
657
+ target: i0.ɵɵFactoryTarget.Injectable
658
+ });
659
+ static ɵprov = i0.ɵɵngDeclareInjectable({
660
+ minVersion: "12.0.0",
661
+ version: "22.2.3",
662
+ ngImport: i0,
663
+ type: ChartgpuGPUContextService,
664
+ providedIn: "root"
665
+ });
666
+ };
667
+ i0.ɵɵngDeclareClassMetadata({
668
+ minVersion: "12.0.0",
669
+ version: "22.2.3",
670
+ ngImport: i0,
671
+ type: ChartgpuGPUContextService,
672
+ decorators: [{
673
+ type: Injectable,
674
+ args: [{ providedIn: "root" }]
675
+ }]
676
+ });
424
677
  function provideChartGpuContext() {
425
- return makeEnvironmentProviders([ChartgpuGPUContextService]);
678
+ return makeEnvironmentProviders([ChartgpuGPUContextService]);
426
679
  }
427
-
428
- /**
429
- * Generated bundle index. Do not edit.
430
- */
431
-
432
680
  export { ChartGpuAngularComponent, ChartgpuConnectChartsDirective, ChartgpuGPUContextService, provideChartGpuContext };
433
- //# sourceMappingURL=chartgpu-angular.mjs.map
681
+
682
+ //# sourceMappingURL=chartgpu-angular.mjs.map