@crysound/crychart 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -2
- package/README.zh-CN.md +24 -2
- package/dist/crychart.cjs +390 -19
- package/dist/crychart.global.js +390 -19
- package/dist/crychart.js +390 -19
- package/dist/types/adapters/opentest.d.ts +3 -1
- package/dist/types/chart.d.ts +9 -0
- package/dist/types/index.d.ts +13 -2
- package/dist/types/render-heatmap.d.ts +2 -0
- package/dist/types/render.d.ts +4 -0
- package/dist/types/shared-webgl-context.d.ts +83 -0
- package/docs/npm-usage.md +1 -1
- package/package.json +1 -1
package/dist/crychart.js
CHANGED
|
@@ -16209,6 +16209,294 @@ var LineStripRenderer = class {
|
|
|
16209
16209
|
}
|
|
16210
16210
|
};
|
|
16211
16211
|
|
|
16212
|
+
// src/shared-webgl-context.ts
|
|
16213
|
+
var cores = /* @__PURE__ */ new WeakMap();
|
|
16214
|
+
var claimedCanvases = /* @__PURE__ */ new WeakMap();
|
|
16215
|
+
function sharedContextCore(context) {
|
|
16216
|
+
const core = cores.get(context);
|
|
16217
|
+
if (!core) throw new TypeError("Expected a valid SharedWebGLContext");
|
|
16218
|
+
return core;
|
|
16219
|
+
}
|
|
16220
|
+
function resetSharedBaseline(gl, width, height, maxVertexAttribs) {
|
|
16221
|
+
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
|
|
16222
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
|
|
16223
|
+
gl.drawBuffers([gl.BACK]);
|
|
16224
|
+
gl.readBuffer(gl.BACK);
|
|
16225
|
+
gl.bindVertexArray(null);
|
|
16226
|
+
for (let i = 0; i < maxVertexAttribs; i++) {
|
|
16227
|
+
gl.disableVertexAttribArray(i);
|
|
16228
|
+
gl.vertexAttribDivisor(i, 0);
|
|
16229
|
+
}
|
|
16230
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
16231
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
16232
|
+
gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, null);
|
|
16233
|
+
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
|
|
16234
|
+
gl.bindBuffer(gl.COPY_READ_BUFFER, null);
|
|
16235
|
+
gl.bindBuffer(gl.COPY_WRITE_BUFFER, null);
|
|
16236
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
16237
|
+
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
|
|
16238
|
+
for (let unit = 2; unit >= 0; unit--) {
|
|
16239
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
16240
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
16241
|
+
gl.bindSampler(unit, null);
|
|
16242
|
+
}
|
|
16243
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
|
|
16244
|
+
gl.pixelStorei(gl.PACK_ALIGNMENT, 4);
|
|
16245
|
+
gl.pixelStorei(gl.UNPACK_ROW_LENGTH, 0);
|
|
16246
|
+
gl.pixelStorei(gl.UNPACK_SKIP_ROWS, 0);
|
|
16247
|
+
gl.pixelStorei(gl.UNPACK_SKIP_PIXELS, 0);
|
|
16248
|
+
gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, 0);
|
|
16249
|
+
gl.pixelStorei(gl.UNPACK_SKIP_IMAGES, 0);
|
|
16250
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
16251
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
16252
|
+
gl.useProgram(null);
|
|
16253
|
+
gl.colorMask(true, true, true, true);
|
|
16254
|
+
gl.depthMask(true);
|
|
16255
|
+
gl.stencilMask(255);
|
|
16256
|
+
for (const capability of [
|
|
16257
|
+
gl.DEPTH_TEST,
|
|
16258
|
+
gl.STENCIL_TEST,
|
|
16259
|
+
gl.CULL_FACE,
|
|
16260
|
+
gl.RASTERIZER_DISCARD,
|
|
16261
|
+
gl.SAMPLE_ALPHA_TO_COVERAGE,
|
|
16262
|
+
gl.SAMPLE_COVERAGE,
|
|
16263
|
+
gl.SCISSOR_TEST,
|
|
16264
|
+
gl.POLYGON_OFFSET_FILL
|
|
16265
|
+
]) {
|
|
16266
|
+
gl.disable(capability);
|
|
16267
|
+
}
|
|
16268
|
+
gl.enable(gl.BLEND);
|
|
16269
|
+
gl.enable(gl.DITHER);
|
|
16270
|
+
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
|
|
16271
|
+
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
16272
|
+
gl.viewport(0, 0, width, height);
|
|
16273
|
+
gl.scissor(0, 0, width, height);
|
|
16274
|
+
}
|
|
16275
|
+
var SharedContextCore = class {
|
|
16276
|
+
canvas;
|
|
16277
|
+
cullOffscreen;
|
|
16278
|
+
antialias;
|
|
16279
|
+
ownsCanvas;
|
|
16280
|
+
clients = /* @__PURE__ */ new Set();
|
|
16281
|
+
observer;
|
|
16282
|
+
observedRoots = /* @__PURE__ */ new Map();
|
|
16283
|
+
offscreenClients = /* @__PURE__ */ new Set();
|
|
16284
|
+
gl = null;
|
|
16285
|
+
attempted = false;
|
|
16286
|
+
disposed = false;
|
|
16287
|
+
maxVertexAttribs = 0;
|
|
16288
|
+
pendingPresent;
|
|
16289
|
+
chartDraws = 0;
|
|
16290
|
+
blits = 0;
|
|
16291
|
+
backingResizes = 0;
|
|
16292
|
+
contextLosses = 0;
|
|
16293
|
+
contextRestores = 0;
|
|
16294
|
+
onLost = (event) => {
|
|
16295
|
+
event.preventDefault();
|
|
16296
|
+
this.contextLosses++;
|
|
16297
|
+
};
|
|
16298
|
+
onRestore = () => {
|
|
16299
|
+
this.contextRestores++;
|
|
16300
|
+
};
|
|
16301
|
+
constructor(options) {
|
|
16302
|
+
if (options !== void 0 && (typeof options !== "object" || options === null)) {
|
|
16303
|
+
throw new TypeError("SharedWebGLContext options must be an object");
|
|
16304
|
+
}
|
|
16305
|
+
if (options?.canvas !== void 0) {
|
|
16306
|
+
if (typeof options.canvas !== "object" || options.canvas === null || typeof options.canvas.getContext !== "function") {
|
|
16307
|
+
throw new TypeError("SharedWebGLContext canvas must provide getContext");
|
|
16308
|
+
}
|
|
16309
|
+
if (claimedCanvases.has(options.canvas)) {
|
|
16310
|
+
throw new Error("Canvas is already bound to an active SharedWebGLContext");
|
|
16311
|
+
}
|
|
16312
|
+
this.canvas = options.canvas;
|
|
16313
|
+
this.ownsCanvas = false;
|
|
16314
|
+
claimedCanvases.set(options.canvas, this);
|
|
16315
|
+
} else if (typeof document !== "undefined") {
|
|
16316
|
+
this.canvas = document.createElement("canvas");
|
|
16317
|
+
this.ownsCanvas = true;
|
|
16318
|
+
} else {
|
|
16319
|
+
this.canvas = void 0;
|
|
16320
|
+
this.ownsCanvas = false;
|
|
16321
|
+
}
|
|
16322
|
+
this.antialias = options?.antialias === true;
|
|
16323
|
+
this.cullOffscreen = options?.cullOffscreen !== false;
|
|
16324
|
+
}
|
|
16325
|
+
acquire() {
|
|
16326
|
+
if (this.disposed) return null;
|
|
16327
|
+
if (this.attempted) return this.gl;
|
|
16328
|
+
this.attempted = true;
|
|
16329
|
+
if (!this.canvas) return null;
|
|
16330
|
+
let gl = null;
|
|
16331
|
+
try {
|
|
16332
|
+
gl = this.canvas.getContext("webgl2", {
|
|
16333
|
+
alpha: true,
|
|
16334
|
+
antialias: this.antialias,
|
|
16335
|
+
depth: false,
|
|
16336
|
+
stencil: false,
|
|
16337
|
+
premultipliedAlpha: true,
|
|
16338
|
+
preserveDrawingBuffer: false
|
|
16339
|
+
});
|
|
16340
|
+
} catch {
|
|
16341
|
+
gl = null;
|
|
16342
|
+
}
|
|
16343
|
+
if (gl) {
|
|
16344
|
+
this.gl = gl;
|
|
16345
|
+
const maxAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
16346
|
+
this.maxVertexAttribs = typeof maxAttribs === "number" && maxAttribs > 0 ? maxAttribs : 0;
|
|
16347
|
+
this.canvas.addEventListener("webglcontextlost", this.onLost);
|
|
16348
|
+
this.canvas.addEventListener("webglcontextrestored", this.onRestore);
|
|
16349
|
+
}
|
|
16350
|
+
return this.gl;
|
|
16351
|
+
}
|
|
16352
|
+
isAvailable() {
|
|
16353
|
+
const gl = this.acquire();
|
|
16354
|
+
return gl !== null && !this.disposed && !gl.isContextLost();
|
|
16355
|
+
}
|
|
16356
|
+
isDisposed() {
|
|
16357
|
+
return this.disposed;
|
|
16358
|
+
}
|
|
16359
|
+
getChartCount() {
|
|
16360
|
+
return this.clients.size;
|
|
16361
|
+
}
|
|
16362
|
+
getStats() {
|
|
16363
|
+
const active2 = this.gl !== null && !this.disposed;
|
|
16364
|
+
return {
|
|
16365
|
+
available: active2 && !this.gl.isContextLost(),
|
|
16366
|
+
disposed: this.disposed,
|
|
16367
|
+
registeredCharts: this.clients.size,
|
|
16368
|
+
offscreenCharts: this.offscreenClients.size,
|
|
16369
|
+
backingWidth: active2 && this.canvas ? this.canvas.width : 0,
|
|
16370
|
+
backingHeight: active2 && this.canvas ? this.canvas.height : 0,
|
|
16371
|
+
chartDraws: this.chartDraws,
|
|
16372
|
+
blits: this.blits,
|
|
16373
|
+
backingResizes: this.backingResizes,
|
|
16374
|
+
contextLosses: this.contextLosses,
|
|
16375
|
+
contextRestores: this.contextRestores
|
|
16376
|
+
};
|
|
16377
|
+
}
|
|
16378
|
+
register(client) {
|
|
16379
|
+
if (this.disposed) throw new Error("SharedWebGLContext has been disposed");
|
|
16380
|
+
if (this.clients.has(client)) return;
|
|
16381
|
+
this.clients.add(client);
|
|
16382
|
+
if (this.cullOffscreen && typeof IntersectionObserver === "function") {
|
|
16383
|
+
if (!this.observer) {
|
|
16384
|
+
this.observer = new IntersectionObserver(
|
|
16385
|
+
(entries) => {
|
|
16386
|
+
for (const entry of entries) {
|
|
16387
|
+
const targetClient = this.observedRoots.get(entry.target);
|
|
16388
|
+
if (!targetClient) continue;
|
|
16389
|
+
const offscreen = !entry.isIntersecting;
|
|
16390
|
+
if (offscreen) this.offscreenClients.add(targetClient);
|
|
16391
|
+
else this.offscreenClients.delete(targetClient);
|
|
16392
|
+
targetClient.setOffscreen?.(offscreen);
|
|
16393
|
+
}
|
|
16394
|
+
},
|
|
16395
|
+
{ threshold: 0 }
|
|
16396
|
+
);
|
|
16397
|
+
}
|
|
16398
|
+
this.observedRoots.set(client.root, client);
|
|
16399
|
+
this.observer.observe(client.root);
|
|
16400
|
+
}
|
|
16401
|
+
}
|
|
16402
|
+
unregister(client) {
|
|
16403
|
+
this.clients.delete(client);
|
|
16404
|
+
this.offscreenClients.delete(client);
|
|
16405
|
+
if (this.observedRoots.delete(client.root)) {
|
|
16406
|
+
this.observer?.unobserve(client.root);
|
|
16407
|
+
}
|
|
16408
|
+
}
|
|
16409
|
+
beginChartDraw(pixelWidth, pixelHeight) {
|
|
16410
|
+
this.pendingPresent = void 0;
|
|
16411
|
+
const gl = this.acquire();
|
|
16412
|
+
if (!gl || this.disposed || gl.isContextLost()) return false;
|
|
16413
|
+
const canvas = this.canvas;
|
|
16414
|
+
const width = Math.max(1, Math.round(pixelWidth));
|
|
16415
|
+
const height = Math.max(1, Math.round(pixelHeight));
|
|
16416
|
+
let resized = false;
|
|
16417
|
+
if (canvas.width !== width) {
|
|
16418
|
+
canvas.width = width;
|
|
16419
|
+
resized = true;
|
|
16420
|
+
}
|
|
16421
|
+
if (canvas.height !== height) {
|
|
16422
|
+
canvas.height = height;
|
|
16423
|
+
resized = true;
|
|
16424
|
+
}
|
|
16425
|
+
if (resized) this.backingResizes++;
|
|
16426
|
+
resetSharedBaseline(gl, width, height, this.maxVertexAttribs);
|
|
16427
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
16428
|
+
gl.clearColor(0, 0, 0, 0);
|
|
16429
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
16430
|
+
this.pendingPresent = { width, height };
|
|
16431
|
+
this.chartDraws++;
|
|
16432
|
+
return true;
|
|
16433
|
+
}
|
|
16434
|
+
present(target, pixelWidth, pixelHeight) {
|
|
16435
|
+
const pending = this.pendingPresent;
|
|
16436
|
+
this.pendingPresent = void 0;
|
|
16437
|
+
const width = Math.max(1, Math.round(pixelWidth));
|
|
16438
|
+
const height = Math.max(1, Math.round(pixelHeight));
|
|
16439
|
+
if (!pending || !target || !this.canvas || pending.width !== width || pending.height !== height) {
|
|
16440
|
+
return;
|
|
16441
|
+
}
|
|
16442
|
+
target.save();
|
|
16443
|
+
target.setTransform(1, 0, 0, 1, 0, 0);
|
|
16444
|
+
target.globalAlpha = 1;
|
|
16445
|
+
target.globalCompositeOperation = "copy";
|
|
16446
|
+
target.imageSmoothingEnabled = false;
|
|
16447
|
+
target.drawImage(this.canvas, 0, 0);
|
|
16448
|
+
target.restore();
|
|
16449
|
+
this.blits++;
|
|
16450
|
+
}
|
|
16451
|
+
dispose() {
|
|
16452
|
+
if (this.disposed) return;
|
|
16453
|
+
this.disposed = true;
|
|
16454
|
+
this.pendingPresent = void 0;
|
|
16455
|
+
this.observer?.disconnect();
|
|
16456
|
+
this.observer = void 0;
|
|
16457
|
+
this.observedRoots.clear();
|
|
16458
|
+
this.offscreenClients.clear();
|
|
16459
|
+
this.clients.clear();
|
|
16460
|
+
if (this.canvas) {
|
|
16461
|
+
if (this.gl) {
|
|
16462
|
+
this.canvas.removeEventListener("webglcontextlost", this.onLost);
|
|
16463
|
+
this.canvas.removeEventListener("webglcontextrestored", this.onRestore);
|
|
16464
|
+
}
|
|
16465
|
+
if (this.ownsCanvas) {
|
|
16466
|
+
this.gl?.getExtension("WEBGL_lose_context")?.loseContext();
|
|
16467
|
+
this.canvas.width = 1;
|
|
16468
|
+
this.canvas.height = 1;
|
|
16469
|
+
} else {
|
|
16470
|
+
claimedCanvases.delete(this.canvas);
|
|
16471
|
+
}
|
|
16472
|
+
}
|
|
16473
|
+
this.gl = null;
|
|
16474
|
+
}
|
|
16475
|
+
};
|
|
16476
|
+
var SharedWebGLContext = class {
|
|
16477
|
+
constructor(options) {
|
|
16478
|
+
cores.set(this, new SharedContextCore(options));
|
|
16479
|
+
}
|
|
16480
|
+
/** Lazily acquires the shared WebGL2 context on first call and caches the result without retrying. */
|
|
16481
|
+
isAvailable() {
|
|
16482
|
+
return sharedContextCore(this).isAvailable();
|
|
16483
|
+
}
|
|
16484
|
+
isDisposed() {
|
|
16485
|
+
return sharedContextCore(this).isDisposed();
|
|
16486
|
+
}
|
|
16487
|
+
/** Number of charts currently registered with this shared context. */
|
|
16488
|
+
getChartCount() {
|
|
16489
|
+
return sharedContextCore(this).getChartCount();
|
|
16490
|
+
}
|
|
16491
|
+
getStats() {
|
|
16492
|
+
return sharedContextCore(this).getStats();
|
|
16493
|
+
}
|
|
16494
|
+
/** Idempotently disposes the shared context. Dispose all registered charts first. */
|
|
16495
|
+
dispose() {
|
|
16496
|
+
sharedContextCore(this).dispose();
|
|
16497
|
+
}
|
|
16498
|
+
};
|
|
16499
|
+
|
|
16212
16500
|
// src/render.ts
|
|
16213
16501
|
var iconVertex = `#version 300 es
|
|
16214
16502
|
precision highp float;
|
|
@@ -16354,7 +16642,15 @@ var DataRenderer = class {
|
|
|
16354
16642
|
this.ownedCoverageFrame = options.ownedCoverageFrame === true;
|
|
16355
16643
|
this.gpuClipPolicy = options.gpuClipPolicy ?? "legacy";
|
|
16356
16644
|
let gl = null;
|
|
16357
|
-
|
|
16645
|
+
let contextEvents = canvas;
|
|
16646
|
+
if (options.renderer !== "canvas2d" && options.sharedContext) {
|
|
16647
|
+
const core = sharedContextCore(options.sharedContext);
|
|
16648
|
+
gl = core.acquire();
|
|
16649
|
+
if (gl && core.canvas) {
|
|
16650
|
+
this.sharedContext = options.sharedContext;
|
|
16651
|
+
contextEvents = core.canvas;
|
|
16652
|
+
}
|
|
16653
|
+
} else try {
|
|
16358
16654
|
if (options.renderer !== "canvas2d") gl = canvas.getContext("webgl2", {
|
|
16359
16655
|
alpha: true,
|
|
16360
16656
|
antialias: options.antialias ?? false,
|
|
@@ -16365,11 +16661,12 @@ var DataRenderer = class {
|
|
|
16365
16661
|
}
|
|
16366
16662
|
if (options.renderer === "webgl2" && !gl) throw new Error("CRYChart WebGL2 renderer is unavailable");
|
|
16367
16663
|
this.gl = gl;
|
|
16664
|
+
this.contextEvents = contextEvents;
|
|
16368
16665
|
this.backend = gl ? "webgl2" : "canvas2d";
|
|
16369
16666
|
if (gl) {
|
|
16370
16667
|
this.init(gl);
|
|
16371
|
-
|
|
16372
|
-
|
|
16668
|
+
this.contextEvents.addEventListener("webglcontextlost", this.onLost);
|
|
16669
|
+
this.contextEvents.addEventListener("webglcontextrestored", this.onRestore);
|
|
16373
16670
|
} else
|
|
16374
16671
|
try {
|
|
16375
16672
|
this.ctx = canvas.getContext("2d");
|
|
@@ -16401,6 +16698,8 @@ var DataRenderer = class {
|
|
|
16401
16698
|
lost = false;
|
|
16402
16699
|
iconPipeline;
|
|
16403
16700
|
iconTextures = /* @__PURE__ */ new Map();
|
|
16701
|
+
sharedContext;
|
|
16702
|
+
contextEvents;
|
|
16404
16703
|
stats = {
|
|
16405
16704
|
frames: 0,
|
|
16406
16705
|
uploads: 0,
|
|
@@ -17125,8 +17424,8 @@ var DataRenderer = class {
|
|
|
17125
17424
|
this.attributeBuffers.clear();
|
|
17126
17425
|
if (this.program) this.gl.deleteProgram(this.program);
|
|
17127
17426
|
}
|
|
17128
|
-
this.
|
|
17129
|
-
this.
|
|
17427
|
+
this.contextEvents.removeEventListener("webglcontextlost", this.onLost);
|
|
17428
|
+
this.contextEvents.removeEventListener("webglcontextrestored", this.onRestore);
|
|
17130
17429
|
}
|
|
17131
17430
|
};
|
|
17132
17431
|
function appendPointPath(ctx, x, y, size, shape, rotation) {
|
|
@@ -18004,8 +18303,9 @@ var DataRendererHeatmap = class {
|
|
|
18004
18303
|
this.canvas = canvas;
|
|
18005
18304
|
this.options = options;
|
|
18006
18305
|
this.initialize();
|
|
18007
|
-
|
|
18008
|
-
|
|
18306
|
+
const events = this.options.contextEvents ?? this.canvas;
|
|
18307
|
+
events.addEventListener("webglcontextlost", this.contextLost);
|
|
18308
|
+
events.addEventListener("webglcontextrestored", this.contextRestored);
|
|
18009
18309
|
}
|
|
18010
18310
|
stats = { frames: 0, uploads: 0, textureUploads: 0, paletteUploads: 0, uploadedBytes: 0, drawCalls: 0, cells: 0, renderTimeMs: 0, cachedTextures: 0, cacheBytes: 0, contextRestores: 0 };
|
|
18011
18311
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -18296,8 +18596,9 @@ var DataRendererHeatmap = class {
|
|
|
18296
18596
|
this.program = void 0;
|
|
18297
18597
|
this.stats.cachedTextures = 0;
|
|
18298
18598
|
this.stats.cacheBytes = 0;
|
|
18299
|
-
this.
|
|
18300
|
-
|
|
18599
|
+
const events = this.options.contextEvents ?? this.canvas;
|
|
18600
|
+
events.removeEventListener("webglcontextlost", this.contextLost);
|
|
18601
|
+
events.removeEventListener("webglcontextrestored", this.contextRestored);
|
|
18301
18602
|
}
|
|
18302
18603
|
};
|
|
18303
18604
|
|
|
@@ -20607,6 +20908,11 @@ var ChartXY = class {
|
|
|
20607
20908
|
observer;
|
|
20608
20909
|
overlayContext;
|
|
20609
20910
|
underlayContext;
|
|
20911
|
+
sharedCore;
|
|
20912
|
+
sharedPresent = null;
|
|
20913
|
+
sharedClient;
|
|
20914
|
+
sharedOffscreen = false;
|
|
20915
|
+
sharedDeferred = false;
|
|
20610
20916
|
heatmapRenderer;
|
|
20611
20917
|
heatmapPalettes = /* @__PURE__ */ new Map();
|
|
20612
20918
|
heatCache = /* @__PURE__ */ new Map();
|
|
@@ -20693,7 +20999,7 @@ var ChartXY = class {
|
|
|
20693
20999
|
this.underlay = underlay;
|
|
20694
21000
|
this.overlay = overlay;
|
|
20695
21001
|
try {
|
|
20696
|
-
this.renderer = new DataRenderer(data, { antialias: options.antialias, renderer: options.renderer, lineCoverageUnion: options.experimentalLineCoverage === true, ownedCoverageFrame: options.experimentalOwnedCoverageFrame === true, gpuClipPolicy: this.gpuClipPolicy });
|
|
21002
|
+
this.renderer = new DataRenderer(data, { antialias: options.antialias, renderer: options.renderer, lineCoverageUnion: options.experimentalLineCoverage === true, ownedCoverageFrame: options.experimentalOwnedCoverageFrame === true, gpuClipPolicy: this.gpuClipPolicy, sharedContext: options.sharedContext ?? void 0 });
|
|
20697
21003
|
} catch (error) {
|
|
20698
21004
|
this.cssTextFonts?.dispose();
|
|
20699
21005
|
root.remove();
|
|
@@ -20713,6 +21019,18 @@ var ChartXY = class {
|
|
|
20713
21019
|
});
|
|
20714
21020
|
this.observer.observe(container);
|
|
20715
21021
|
}
|
|
21022
|
+
if (this.renderer?.sharedContext) {
|
|
21023
|
+
const sharedCore = sharedContextCore(this.renderer.sharedContext);
|
|
21024
|
+
this.sharedCore = sharedCore;
|
|
21025
|
+
this.sharedPresent = data.getContext("2d");
|
|
21026
|
+
const client = {
|
|
21027
|
+
root,
|
|
21028
|
+
setOffscreen: (offscreen) => this.setSharedOffscreen(offscreen)
|
|
21029
|
+
};
|
|
21030
|
+
this.sharedClient = client;
|
|
21031
|
+
sharedCore.register(client);
|
|
21032
|
+
this.cleanups.push(() => sharedCore.unregister(client));
|
|
21033
|
+
}
|
|
20716
21034
|
}
|
|
20717
21035
|
this.engine = {
|
|
20718
21036
|
container: this.root ?? this.container,
|
|
@@ -21458,8 +21776,26 @@ var ChartXY = class {
|
|
|
21458
21776
|
this.cancelAxisScrollAnimations();
|
|
21459
21777
|
for (const series of this.series) series.cancelHighlightAnimation?.();
|
|
21460
21778
|
}
|
|
21779
|
+
setSharedOffscreen(offscreen) {
|
|
21780
|
+
if (offscreen === this.sharedOffscreen || this.disposed) return;
|
|
21781
|
+
this.sharedOffscreen = offscreen;
|
|
21782
|
+
if (offscreen) {
|
|
21783
|
+
if (this.frame && typeof cancelAnimationFrame === "function") {
|
|
21784
|
+
cancelAnimationFrame(this.frame);
|
|
21785
|
+
this.frame = 0;
|
|
21786
|
+
this.sharedDeferred = true;
|
|
21787
|
+
}
|
|
21788
|
+
} else if (this.sharedDeferred) {
|
|
21789
|
+
this.sharedDeferred = false;
|
|
21790
|
+
this.invalidate();
|
|
21791
|
+
}
|
|
21792
|
+
}
|
|
21461
21793
|
invalidate() {
|
|
21462
21794
|
if (this.disposed || this.frame || this.rendering || !this.root) return;
|
|
21795
|
+
if (this.sharedOffscreen) {
|
|
21796
|
+
this.sharedDeferred = true;
|
|
21797
|
+
return;
|
|
21798
|
+
}
|
|
21463
21799
|
if (typeof requestAnimationFrame === "function")
|
|
21464
21800
|
this.frame = requestAnimationFrame((timestamp) => {
|
|
21465
21801
|
this.frame = 0;
|
|
@@ -21913,6 +22249,8 @@ var ChartXY = class {
|
|
|
21913
22249
|
ctx.drawImage(cache.canvas, r.left, r.top, r.width, r.height);
|
|
21914
22250
|
}
|
|
21915
22251
|
renderData(packets) {
|
|
22252
|
+
const shared = this.sharedCore;
|
|
22253
|
+
if (shared && !shared.beginChartDraw(this.canvas.width, this.canvas.height)) return;
|
|
21916
22254
|
const grids = [];
|
|
21917
22255
|
for (const s of this.series) {
|
|
21918
22256
|
if (!(s instanceof HeatmapSeries) || !s.visible || s.disposed || !this.gpuHeatmap(s))
|
|
@@ -21983,7 +22321,7 @@ var ChartXY = class {
|
|
|
21983
22321
|
this.heatmapRenderer = new DataRendererHeatmap(
|
|
21984
22322
|
this.renderer.gl,
|
|
21985
22323
|
this.canvas,
|
|
21986
|
-
{ clipPolicy: this.gpuClipPolicy }
|
|
22324
|
+
{ clipPolicy: this.gpuClipPolicy, contextEvents: this.renderer.contextEvents }
|
|
21987
22325
|
);
|
|
21988
22326
|
const gl = this.renderer?.gl;
|
|
21989
22327
|
const rasterTarget = this.gpuClipPolicy === "contained" && gl ? rasterTargetForRect(null, gl.drawingBufferWidth, gl.drawingBufferHeight, this.plot, this.dpr) : void 0;
|
|
@@ -22000,6 +22338,7 @@ var ChartXY = class {
|
|
|
22000
22338
|
clear: grids.length === 0,
|
|
22001
22339
|
rasterTarget
|
|
22002
22340
|
});
|
|
22341
|
+
if (shared) shared.present(this.sharedPresent, this.canvas.width, this.canvas.height);
|
|
22003
22342
|
}
|
|
22004
22343
|
gpuHeatmap(s) {
|
|
22005
22344
|
return !!this.renderer?.gl && s.axisX.type !== "logarithmic" && s.axisY.type !== "logarithmic";
|
|
@@ -23259,7 +23598,8 @@ var Chart3D = class extends ChartXY {
|
|
|
23259
23598
|
gpuPackets = /* @__PURE__ */ new Map();
|
|
23260
23599
|
gpuRevision = 0;
|
|
23261
23600
|
constructor(options = {}) {
|
|
23262
|
-
|
|
23601
|
+
if (options.sharedContext) throw new UnsupportedFeatureError("shared WebGL contexts for Chart3D");
|
|
23602
|
+
super({ ...options, sharedContext: null, antialias: options.antialias ?? true });
|
|
23263
23603
|
this.cameraModel = options.experimental3DCameraModel === "legacy" ? "legacy" : "world";
|
|
23264
23604
|
this.axesZ.push(new Axis(this, "z", options.defaultAxisZ));
|
|
23265
23605
|
this.coordsAxis.z = this.axesZ[0];
|
|
@@ -24834,7 +25174,8 @@ function createCRYChartAdapter(container, options = {}) {
|
|
|
24834
25174
|
const chart = new ChartXY({
|
|
24835
25175
|
container,
|
|
24836
25176
|
legend: { visible: false },
|
|
24837
|
-
...options.xScale === "logarithmic" ? { defaultAxisX: { type: "logarithmic", base: 10 } } : {}
|
|
25177
|
+
...options.xScale === "logarithmic" ? { defaultAxisX: { type: "logarithmic", base: 10 } } : {},
|
|
25178
|
+
...options.sharedContext ? { sharedContext: options.sharedContext } : {}
|
|
24838
25179
|
});
|
|
24839
25180
|
const entries = /* @__PURE__ */ new Map();
|
|
24840
25181
|
let disposed = false;
|
|
@@ -25010,12 +25351,27 @@ function createCRYChartAdapter(container, options = {}) {
|
|
|
25010
25351
|
}
|
|
25011
25352
|
|
|
25012
25353
|
// src/index.ts
|
|
25013
|
-
function cryChart(
|
|
25354
|
+
function cryChart(options = {}) {
|
|
25355
|
+
if (options.sharedContext !== void 0 && options.sharedContextOptions !== void 0) {
|
|
25356
|
+
throw new TypeError(
|
|
25357
|
+
"Pass either sharedContext or sharedContextOptions, not both"
|
|
25358
|
+
);
|
|
25359
|
+
}
|
|
25360
|
+
if (options.sharedContext !== void 0 && !(options.sharedContext instanceof SharedWebGLContext)) {
|
|
25361
|
+
throw new TypeError("sharedContext must be a SharedWebGLContext");
|
|
25362
|
+
}
|
|
25363
|
+
if (options.sharedContext?.isDisposed()) {
|
|
25364
|
+
throw new Error("sharedContext has been disposed");
|
|
25365
|
+
}
|
|
25366
|
+
const shared = options.sharedContext ?? (options.sharedContextOptions ? new SharedWebGLContext(options.sharedContextOptions) : void 0);
|
|
25367
|
+
const ownsShared = !options.sharedContext && shared !== void 0;
|
|
25014
25368
|
const owned2 = /* @__PURE__ */ new Set();
|
|
25015
25369
|
let disposed = false;
|
|
25016
|
-
const create = (ctor,
|
|
25370
|
+
const create = (ctor, opts = {}) => {
|
|
25017
25371
|
if (disposed) throw new Error("Chart context has been disposed");
|
|
25018
|
-
const
|
|
25372
|
+
const injects = shared !== void 0 && (ctor === ChartXY || ctor === Polar || ctor === Dashboard) && !("sharedContext" in opts);
|
|
25373
|
+
const finalOptions = injects ? { ...opts, sharedContext: shared } : opts;
|
|
25374
|
+
const chart = new ctor(finalOptions);
|
|
25019
25375
|
owned2.add(chart);
|
|
25020
25376
|
chart.onDispose(() => owned2.delete(chart));
|
|
25021
25377
|
return chart;
|
|
@@ -25046,17 +25402,25 @@ function cryChart(_options = {}) {
|
|
|
25046
25402
|
} catch (error) {
|
|
25047
25403
|
errors.push(error);
|
|
25048
25404
|
}
|
|
25405
|
+
if (ownsShared) try {
|
|
25406
|
+
shared.dispose();
|
|
25407
|
+
} catch (error) {
|
|
25408
|
+
errors.push(error);
|
|
25409
|
+
}
|
|
25049
25410
|
if (errors.length) throw new AggregateError(errors, "Some chart disposal callbacks failed");
|
|
25050
25411
|
}
|
|
25051
25412
|
},
|
|
25052
25413
|
isDisposed: () => disposed,
|
|
25053
25414
|
/** Live charts owned by this context; disposed charts are released immediately. */
|
|
25054
|
-
getChartCount: () => owned2.size
|
|
25415
|
+
getChartCount: () => owned2.size,
|
|
25416
|
+
/** Shared WebGL2 context used by this context; undefined when not enabled. */
|
|
25417
|
+
getSharedContext: () => shared
|
|
25055
25418
|
};
|
|
25056
25419
|
}
|
|
25057
|
-
var version = "1.0.
|
|
25420
|
+
var version = "1.0.7";
|
|
25058
25421
|
var Dashboard = class {
|
|
25059
25422
|
root;
|
|
25423
|
+
sharedContext;
|
|
25060
25424
|
cells = /* @__PURE__ */ new Map();
|
|
25061
25425
|
children = /* @__PURE__ */ new Set();
|
|
25062
25426
|
events = new EventHub();
|
|
@@ -25068,6 +25432,7 @@ var Dashboard = class {
|
|
|
25068
25432
|
throw new Error("Dashboard requires a DOM");
|
|
25069
25433
|
const container = typeof options.container === "string" ? document.getElementById(options.container) : options.container ?? document.body;
|
|
25070
25434
|
if (!container) throw new Error("Dashboard container was not found");
|
|
25435
|
+
this.sharedContext = options.sharedContext;
|
|
25071
25436
|
this.root = document.createElement("div");
|
|
25072
25437
|
this.columns = options.numberOfColumns ?? 2;
|
|
25073
25438
|
this.rows = options.numberOfRows ?? 2;
|
|
@@ -25080,8 +25445,13 @@ var Dashboard = class {
|
|
|
25080
25445
|
cell.style.cssText = `min-height:0;min-width:0;grid-column:${(options.columnIndex ?? 0) + 1}/span ${options.columnSpan ?? 1};grid-row:${(options.rowIndex ?? 0) + 1}/span ${options.rowSpan ?? 1}`;
|
|
25081
25446
|
this.root.append(cell);
|
|
25082
25447
|
let chart;
|
|
25448
|
+
const inject = this.sharedContext && (Ctor === ChartXY || Ctor === Polar) && !("sharedContext" in options);
|
|
25083
25449
|
try {
|
|
25084
|
-
chart = new Ctor({
|
|
25450
|
+
chart = new Ctor({
|
|
25451
|
+
...options,
|
|
25452
|
+
...inject ? { sharedContext: this.sharedContext } : {},
|
|
25453
|
+
container: cell
|
|
25454
|
+
});
|
|
25085
25455
|
} catch (error) {
|
|
25086
25456
|
cell.remove();
|
|
25087
25457
|
throw error;
|
|
@@ -25232,6 +25602,7 @@ export {
|
|
|
25232
25602
|
SegmentFigure,
|
|
25233
25603
|
SegmentSeries,
|
|
25234
25604
|
Series3DBase,
|
|
25605
|
+
SharedWebGLContext,
|
|
25235
25606
|
SimpleShadingStyle,
|
|
25236
25607
|
SlicedHierarchyChart,
|
|
25237
25608
|
SolidFill,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ChartXY } from '../chart.js';
|
|
2
|
+
import type { SharedWebGLContext } from '../shared-webgl-context.js';
|
|
2
3
|
/** OpenTest's public data envelope, represented independently of its Vue host. */
|
|
3
4
|
export type NumericValues = readonly number[] | Float32Array | Float64Array | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array;
|
|
4
5
|
export interface DataEnvelope {
|
|
@@ -33,8 +34,9 @@ export interface FrameworkChartOptions {
|
|
|
33
34
|
fontSize?: number;
|
|
34
35
|
viewport?: ChartViewport;
|
|
35
36
|
showYCursor?: boolean;
|
|
37
|
+
sharedContext?: SharedWebGLContext;
|
|
36
38
|
}
|
|
37
|
-
export type FrameworkChartDisplayOptions = Partial<Omit<FrameworkChartOptions, 'xScale' | 'showYCursor'>>;
|
|
39
|
+
export type FrameworkChartDisplayOptions = Partial<Omit<FrameworkChartOptions, 'xScale' | 'showYCursor' | 'sharedContext'>>;
|
|
38
40
|
export interface FrameworkChartApi {
|
|
39
41
|
setData(data: DataEnvelope, options?: FrameworkSeriesOptions & {
|
|
40
42
|
append?: boolean;
|
package/dist/types/chart.d.ts
CHANGED
|
@@ -14,12 +14,15 @@ import { SurfaceGrid3D, SurfaceMesh3D, MeshModel3D, BoxSeries3D } from './mesh3d
|
|
|
14
14
|
import { type PolarLayout, type PolarInsets } from './polar-layout.js';
|
|
15
15
|
import { type AxisPosition, type PublicEventListener, type ChartEventListenerOptions } from './chart-events.js';
|
|
16
16
|
import { type Projection3D, type Vec3 } from './world-camera.js';
|
|
17
|
+
import { type SharedWebGLContext } from './shared-webgl-context.js';
|
|
17
18
|
export interface ChartOptions {
|
|
18
19
|
/** Artifact research switch; this candidate defaults to the world camera. */
|
|
19
20
|
experimental3DCameraModel?: 'world' | 'legacy';
|
|
20
21
|
container?: HTMLElement | string;
|
|
21
22
|
antialias?: boolean;
|
|
22
23
|
renderer?: 'auto' | 'webgl2' | 'canvas2d';
|
|
24
|
+
/** Share one WebGL2 context across charts (ChartXY/Polar only). null opts out when a cryChart() context injects one. */
|
|
25
|
+
sharedContext?: SharedWebGLContext | null;
|
|
23
26
|
/** Explicit diagnostic opt-in. Pixel and paired-performance validation is ongoing. */
|
|
24
27
|
experimentalLineBlocks?: boolean;
|
|
25
28
|
/** Display-only extrema candidate; disabled unless an explicit pixel span is supplied. */
|
|
@@ -129,6 +132,11 @@ export declare class ChartXY {
|
|
|
129
132
|
private observer?;
|
|
130
133
|
private overlayContext?;
|
|
131
134
|
private underlayContext?;
|
|
135
|
+
private sharedCore?;
|
|
136
|
+
private sharedPresent;
|
|
137
|
+
private sharedClient?;
|
|
138
|
+
private sharedOffscreen;
|
|
139
|
+
private sharedDeferred;
|
|
132
140
|
private heatmapRenderer?;
|
|
133
141
|
private heatmapPalettes;
|
|
134
142
|
private heatCache;
|
|
@@ -319,6 +327,7 @@ export declare class ChartXY {
|
|
|
319
327
|
protected cancelAxisScrollAnimations(): void;
|
|
320
328
|
protected hasPendingAnimationFrame(): boolean;
|
|
321
329
|
protected cancelScheduledAnimation(): void;
|
|
330
|
+
private setSharedOffscreen;
|
|
322
331
|
invalidate(): void;
|
|
323
332
|
renderNow(): void;
|
|
324
333
|
/** Internal post-render publication hook; consumer callbacks may request a new frame. */
|
package/dist/types/index.d.ts
CHANGED
|
@@ -24,13 +24,21 @@ export * from './polar-heatmap.js';
|
|
|
24
24
|
export * from './polar-series.js';
|
|
25
25
|
export * from './mesh3d.js';
|
|
26
26
|
export * from "./adapters/opentest.js";
|
|
27
|
+
export { SharedWebGLContext, type SharedContextOptions, type SharedWebGLContextStats, } from "./shared-webgl-context.js";
|
|
27
28
|
import { ChartXY, Chart3D, Polar, type ChartOptions } from "./chart.js";
|
|
28
29
|
import { Pie, Gauge, Spider, BarChart, TreeMapChart, ParallelCoordinateChart, DataGrid } from "./specialty.js";
|
|
29
30
|
import { SunBurstChart, Funnel, Pyramid } from "./hierarchy.js";
|
|
30
31
|
import { MapChart, type MapOptions } from "./map.js";
|
|
31
32
|
import { type EventListener } from './core/events.js';
|
|
33
|
+
import { SharedWebGLContext, type SharedContextOptions } from "./shared-webgl-context.js";
|
|
34
|
+
export interface CryChartOptions {
|
|
35
|
+
sharedContext?: SharedWebGLContext;
|
|
36
|
+
sharedContextOptions?: SharedContextOptions;
|
|
37
|
+
/** Compatible with LightningChart-style options (such as license); ignored. */
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
32
40
|
/** Create a CRYChart context that owns its chart instances. */
|
|
33
|
-
export declare function cryChart(
|
|
41
|
+
export declare function cryChart(options?: CryChartOptions): {
|
|
34
42
|
ChartXY: (o?: ChartOptions) => ChartXY;
|
|
35
43
|
Chart3D: (o?: ChartOptions) => Chart3D;
|
|
36
44
|
Polar: (o?: ChartOptions) => Polar;
|
|
@@ -50,10 +58,13 @@ export declare function cryChart(_options?: Record<string, unknown>): {
|
|
|
50
58
|
isDisposed: () => boolean;
|
|
51
59
|
/** Live charts owned by this context; disposed charts are released immediately. */
|
|
52
60
|
getChartCount: () => number;
|
|
61
|
+
/** Shared WebGL2 context used by this context; undefined when not enabled. */
|
|
62
|
+
getSharedContext: () => SharedWebGLContext | undefined;
|
|
53
63
|
};
|
|
54
|
-
export declare const version = "1.0.
|
|
64
|
+
export declare const version = "1.0.7";
|
|
55
65
|
export declare class Dashboard {
|
|
56
66
|
readonly root: HTMLDivElement;
|
|
67
|
+
private readonly sharedContext?;
|
|
57
68
|
private cells;
|
|
58
69
|
private children;
|
|
59
70
|
private events;
|
|
@@ -79,6 +79,7 @@ export declare class DataRendererHeatmap {
|
|
|
79
79
|
readonly canvas: HTMLCanvasElement;
|
|
80
80
|
readonly options: {
|
|
81
81
|
clipPolicy?: GpuClipPolicy;
|
|
82
|
+
contextEvents?: EventTarget;
|
|
82
83
|
};
|
|
83
84
|
readonly stats: {
|
|
84
85
|
frames: number;
|
|
@@ -102,6 +103,7 @@ export declare class DataRendererHeatmap {
|
|
|
102
103
|
private disposed;
|
|
103
104
|
constructor(gl: WebGL2RenderingContext, canvas: HTMLCanvasElement, options?: {
|
|
104
105
|
clipPolicy?: GpuClipPolicy;
|
|
106
|
+
contextEvents?: EventTarget;
|
|
105
107
|
});
|
|
106
108
|
/** Undefined until data has reached the current, live WebGL context. */
|
|
107
109
|
getUploadedRevision(id: number): number | undefined;
|