blazeplot 0.1.10 → 0.1.12

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/dist/index.js CHANGED
@@ -500,7 +500,7 @@ var i = class {
500
500
  vert: h,
501
501
  frag: g
502
502
  }
503
- }, v = 3, y = 2, b = 4, x = 4, S = .8, C = 0, w = class {
503
+ }, v = 3, y = 2, b = 4, x = 4, S = .8, C = 0, ee = class {
504
504
  backend;
505
505
  lineProgram;
506
506
  segmentProgram;
@@ -793,13 +793,13 @@ var i = class {
793
793
  dispose() {
794
794
  this.backend.destroy();
795
795
  }
796
- }, T = [
796
+ }, w = [
797
797
  1024,
798
798
  4096,
799
799
  16384,
800
800
  32768,
801
801
  131072
802
- ], E = class {
802
+ ], te = class {
803
803
  regl;
804
804
  pool = [];
805
805
  preAllocated = !1;
@@ -812,7 +812,7 @@ var i = class {
812
812
  preAllocate() {
813
813
  if (!this.preAllocated) {
814
814
  this.preAllocated = !0;
815
- for (let e of T) this.pool.push(this.createEntry(e, "stream"));
815
+ for (let e of w) this.pool.push(this.createEntry(e, "stream"));
816
816
  }
817
817
  }
818
818
  acquire(e, t = "stream") {
@@ -852,17 +852,17 @@ var i = class {
852
852
  return this.pool.find((t) => !t.inUse && t.floatCapacity >= e);
853
853
  }
854
854
  roundUp(e) {
855
- for (let t of T) if (t >= e) return t;
856
- let t = T[T.length - 1], n = 1 << 32 - Math.clz32(e - 1);
855
+ for (let t of w) if (t >= e) return t;
856
+ let t = w[w.length - 1], n = 1 << 32 - Math.clz32(e - 1);
857
857
  return Math.max(t * 2, n);
858
858
  }
859
859
  };
860
860
  //#endregion
861
861
  //#region src/render/ReglBackend.ts
862
- function D(e) {
862
+ function ne(e) {
863
863
  return e;
864
864
  }
865
- var O = class {
865
+ var T = class {
866
866
  gl;
867
867
  regl;
868
868
  resources;
@@ -882,10 +882,10 @@ var O = class {
882
882
  });
883
883
  if (!n) throw Error("BlazePlot requires WebGL2, but this browser/context does not support it.");
884
884
  this.gl = n, this.regl = e({
885
- gl: D(this.gl),
885
+ gl: ne(this.gl),
886
886
  extensions: [],
887
887
  optionalExtensions: ["angle_instanced_arrays", "ext_disjoint_timer_query_webgl2"]
888
- }), this.capabilities = { instancing: this.regl.hasExtension("angle_instanced_arrays") }, this.resources = new E(this.regl), this.resources.preAllocate();
888
+ }), this.capabilities = { instancing: this.regl.hasExtension("angle_instanced_arrays") }, this.resources = new te(this.regl), this.resources.preAllocate();
889
889
  }
890
890
  createBuffer(e) {
891
891
  let { buffer: t } = this.resources.acquire(e.length, e.usage);
@@ -944,7 +944,7 @@ var O = class {
944
944
  ] });
945
945
  }
946
946
  viewport(e, t, n, r) {
947
- this.scissorBox = {
947
+ this.regl.poll(), this.scissorBox = {
948
948
  x: e,
949
949
  y: t,
950
950
  w: n,
@@ -1004,61 +1004,7 @@ var O = class {
1004
1004
  default: return e;
1005
1005
  }
1006
1006
  }
1007
- }, k = class {
1008
- canvas;
1009
- camera;
1010
- policy;
1011
- _enabled = !0;
1012
- activePointerId = null;
1013
- lastX = 0;
1014
- lastY = 0;
1015
- constructor(e, t, n) {
1016
- this.canvas = e, this.camera = t, this.policy = n, this.bindEvents();
1017
- }
1018
- get enabled() {
1019
- return this._enabled;
1020
- }
1021
- set enabled(e) {
1022
- this._enabled = e;
1023
- }
1024
- bindEvents() {
1025
- this.canvas.addEventListener("pointerdown", this.onPointerDown), this.canvas.addEventListener("pointermove", this.onPointerMove), this.canvas.addEventListener("pointerup", this.onPointerUp), this.canvas.addEventListener("pointercancel", this.onPointerUp), this.canvas.addEventListener("wheel", this.onWheel, { passive: !1 });
1026
- }
1027
- onPointerDown = (e) => {
1028
- !this._enabled || this.activePointerId !== null || (this.activePointerId = e.pointerId, this.lastX = e.clientX, this.lastY = e.clientY, this.canvas.setPointerCapture(e.pointerId));
1029
- };
1030
- onPointerMove = (e) => {
1031
- if (!this._enabled || e.pointerId !== this.activePointerId) return;
1032
- let t = this.canvas.getBoundingClientRect(), n = t.width > 0 ? (this.lastX - e.clientX) / t.width : 0, r = t.height > 0 ? (e.clientY - this.lastY) / t.height : 0, i = this.applyPanPolicy({
1033
- dx: n,
1034
- dy: r
1035
- });
1036
- i && this.camera.pan(i), this.lastX = e.clientX, this.lastY = e.clientY;
1037
- };
1038
- onPointerUp = (e) => {
1039
- e.pointerId === this.activePointerId && (this.activePointerId = null, this.canvas.hasPointerCapture(e.pointerId) && this.canvas.releasePointerCapture(e.pointerId));
1040
- };
1041
- onWheel = (e) => {
1042
- if (!this._enabled) return;
1043
- e.preventDefault();
1044
- let t = e.deltaY < 0 ? 1.1 : .9, n = this.canvas.getBoundingClientRect(), r = n.width > 0 ? (e.clientX - n.left) / n.width : .5, i = n.height > 0 ? 1 - (e.clientY - n.top) / n.height : .5, a = this.applyZoomPolicy({
1045
- factor: t,
1046
- cx: r,
1047
- cy: i,
1048
- axis: "xy"
1049
- });
1050
- a && this.camera.zoom(a);
1051
- };
1052
- applyPanPolicy(e) {
1053
- return this.policy?.beforePan ? this.policy.beforePan(this.camera, e) : e;
1054
- }
1055
- applyZoomPolicy(e) {
1056
- return this.policy?.beforeZoom ? this.policy.beforeZoom(this.camera, e) : e;
1057
- }
1058
- dispose() {
1059
- this.canvas.removeEventListener("pointerdown", this.onPointerDown), this.canvas.removeEventListener("pointermove", this.onPointerMove), this.canvas.removeEventListener("pointerup", this.onPointerUp), this.canvas.removeEventListener("pointercancel", this.onPointerUp), this.canvas.removeEventListener("wheel", this.onWheel);
1060
- }
1061
- }, A = class e {
1007
+ }, E = class e {
1062
1008
  _xMin = 0;
1063
1009
  _xMax = 1;
1064
1010
  _yMin = 0;
@@ -1143,7 +1089,7 @@ var O = class {
1143
1089
  static assertFinite(e, t) {
1144
1090
  if (!Number.isFinite(t)) throw RangeError(`Camera2D ${e} must be finite.`);
1145
1091
  }
1146
- }, j = class {
1092
+ }, D = class {
1147
1093
  camera;
1148
1094
  constructor(e) {
1149
1095
  this.camera = e;
@@ -1175,7 +1121,7 @@ var O = class {
1175
1121
  let n = Math.max(0, -Math.floor(Math.log10(t)) + 2), r = Number(e.toFixed(n));
1176
1122
  return Object.is(r, -0) ? 0 : r;
1177
1123
  }
1178
- }, M = class {
1124
+ }, O = class {
1179
1125
  layout;
1180
1126
  config;
1181
1127
  options;
@@ -1186,6 +1132,11 @@ var O = class {
1186
1132
  constructor(e, t, n = {}) {
1187
1133
  this.layout = e, this.config = t, this.options = n;
1188
1134
  }
1135
+ setOptions(e) {
1136
+ this.options = e;
1137
+ for (let e of this.xPool) e.style.font = this.options.font ?? "11px ui-monospace, monospace, sans-serif", e.style.color = this.options.color ?? "#bfd6ff";
1138
+ for (let e of this.yPool) e.style.font = this.options.font ?? "11px ui-monospace, monospace, sans-serif", e.style.color = this.options.color ?? "#bfd6ff";
1139
+ }
1189
1140
  update(e, t) {
1190
1141
  let n = Math.max(1, this.layout.plot.clientWidth), r = Math.max(1, this.layout.plot.clientHeight);
1191
1142
  this.config.x.visible ? t.getXTickValues(n, 12, this.xTicks) : this.xTicks.length = 0, this.config.y.visible ? t.getYTickValues(r, 8, this.yTicks) : this.yTicks.length = 0, this.updateAxis(this.xPool, this.xTicks, "x", e, n, r, t), this.updateAxis(this.yPool, this.yTicks, "y", e, n, r, t);
@@ -1217,7 +1168,7 @@ var O = class {
1217
1168
  }
1218
1169
  }
1219
1170
  }
1220
- }, N = class {
1171
+ }, k = class {
1221
1172
  root;
1222
1173
  plot;
1223
1174
  canvas;
@@ -1244,8 +1195,181 @@ var O = class {
1244
1195
  applyBaseStyles() {
1245
1196
  this.root.style.position = "relative", this.root.style.display = "grid", this.root.style.width = "100%", this.root.style.height = "100%", this.root.style.minWidth = "0", this.root.style.minHeight = "0", this.root.style.overflow = "hidden", this.plot.style.position = "relative", this.plot.style.gridColumn = "2", this.plot.style.gridRow = "1", this.plot.style.minWidth = "0", this.plot.style.minHeight = "0", this.plot.style.overflow = "hidden", this.canvas.style.position = "absolute", this.canvas.style.inset = "0", this.canvas.style.display = "block", this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.touchAction = "none", this.yAxis.style.position = "relative", this.yAxis.style.gridColumn = "1", this.yAxis.style.gridRow = "1", this.yAxis.style.minWidth = "0", this.yAxis.style.minHeight = "0", this.yAxis.style.overflow = "hidden", this.yAxis.style.pointerEvents = "none", this.xAxis.style.position = "relative", this.xAxis.style.gridColumn = "2", this.xAxis.style.gridRow = "2", this.xAxis.style.minWidth = "0", this.xAxis.style.minHeight = "0", this.xAxis.style.overflow = "hidden", this.xAxis.style.pointerEvents = "none", this.corner.style.gridColumn = "1", this.corner.style.gridRow = "2", this.corner.style.minWidth = "0", this.corner.style.minHeight = "0", this.corner.style.pointerEvents = "none";
1246
1197
  }
1247
- }, P = 16384, F = P >> 1, I = P >> 1, L = 3, R = 4096, z = 12, B = 64;
1198
+ }, A = {
1199
+ backgroundColor: [
1200
+ .08,
1201
+ .1,
1202
+ .16,
1203
+ 1
1204
+ ],
1205
+ backgroundCssColor: "rgba(20, 26, 41, 1)",
1206
+ gridColor: [
1207
+ .22,
1208
+ .3,
1209
+ .44,
1210
+ .45
1211
+ ],
1212
+ axisColor: "#bfd6ff",
1213
+ axisFont: "11px ui-monospace, monospace, sans-serif",
1214
+ seriesColors: [
1215
+ [
1216
+ .3,
1217
+ .6,
1218
+ 1,
1219
+ 1
1220
+ ],
1221
+ [
1222
+ .95,
1223
+ .35,
1224
+ .35,
1225
+ 1
1226
+ ],
1227
+ [
1228
+ .2,
1229
+ .8,
1230
+ .4,
1231
+ .9
1232
+ ],
1233
+ [
1234
+ .95,
1235
+ .72,
1236
+ .25,
1237
+ 1
1238
+ ],
1239
+ [
1240
+ .72,
1241
+ .45,
1242
+ .95,
1243
+ 1
1244
+ ],
1245
+ [
1246
+ .25,
1247
+ .85,
1248
+ .95,
1249
+ 1
1250
+ ]
1251
+ ],
1252
+ tooltipBackgroundColor: "rgba(4, 8, 16, 0.85)",
1253
+ tooltipTextColor: "#bfd6ff",
1254
+ tooltipFont: "11px/1.35 ui-monospace, monospace",
1255
+ legendBackgroundColor: "rgba(4, 8, 16, 0.85)",
1256
+ legendBorderColor: "transparent",
1257
+ legendTextColor: "#bfd6ff",
1258
+ legendMutedTextColor: "#789",
1259
+ legendFont: "11px/1.35 ui-monospace, monospace"
1260
+ };
1261
+ function j(e, t) {
1262
+ if (!e) return A;
1263
+ let n = M(e.backgroundColor, A.backgroundColor, t), r = e.seriesColors?.length ? e.seriesColors.map((e, n) => M(e, A.seriesColors[n % A.seriesColors.length], t)) : A.seriesColors;
1264
+ return {
1265
+ backgroundColor: n,
1266
+ backgroundCssColor: N(e.backgroundColor, A.backgroundCssColor),
1267
+ gridColor: M(e.gridColor, A.gridColor, t),
1268
+ axisColor: e.axisColor ?? A.axisColor,
1269
+ axisFont: e.axisFont ?? A.axisFont,
1270
+ seriesColors: r,
1271
+ tooltipBackgroundColor: e.tooltipBackgroundColor ?? A.tooltipBackgroundColor,
1272
+ tooltipTextColor: e.tooltipTextColor ?? A.tooltipTextColor,
1273
+ tooltipFont: e.tooltipFont ?? A.tooltipFont,
1274
+ legendBackgroundColor: e.legendBackgroundColor ?? A.legendBackgroundColor,
1275
+ legendBorderColor: e.legendBorderColor ?? A.legendBorderColor,
1276
+ legendTextColor: e.legendTextColor ?? A.legendTextColor,
1277
+ legendMutedTextColor: e.legendMutedTextColor ?? A.legendMutedTextColor,
1278
+ legendFont: e.legendFont ?? A.legendFont
1279
+ };
1280
+ }
1281
+ function M(e, t, n) {
1282
+ if (!e) return t;
1283
+ if (typeof e != "string") return e;
1284
+ let r = F(e, n), i = L(r ?? e, n);
1285
+ return I(r ?? e) ?? I(i ?? "") ?? t;
1286
+ }
1287
+ function N(e, t) {
1288
+ return e ? typeof e == "string" ? e : P(e) : t;
1289
+ }
1290
+ function P(e) {
1291
+ return `rgba(${Math.round(e[0] * 255)}, ${Math.round(e[1] * 255)}, ${Math.round(e[2] * 255)}, ${e[3]})`;
1292
+ }
1293
+ function F(e, t) {
1294
+ let n = t?.ownerDocument ?? globalThis.document;
1295
+ if (!n?.documentElement || typeof getComputedStyle > "u") return null;
1296
+ let r = t instanceof HTMLElement ? t : n.documentElement, i = n.createElement("span");
1297
+ i.style.position = "absolute", i.style.visibility = "hidden", i.style.pointerEvents = "none", i.style.color = e, r.appendChild(i);
1298
+ let a = getComputedStyle(i).color;
1299
+ return i.remove(), a || null;
1300
+ }
1301
+ function I(e) {
1302
+ let t = e.trim();
1303
+ return R(t) ?? z(t) ?? B(t);
1304
+ }
1305
+ function L(e, t) {
1306
+ let n = t?.ownerDocument ?? globalThis.document;
1307
+ if (!n?.createElement) return null;
1308
+ let r = n.createElement("canvas").getContext("2d");
1309
+ if (!r) return null;
1310
+ let i = "#010203";
1311
+ r.fillStyle = i, r.fillStyle = e;
1312
+ let a = String(r.fillStyle);
1313
+ return a === i ? null : a;
1314
+ }
1315
+ function R(e) {
1316
+ let t = e.match(/^rgba?\((.*)\)$/i);
1317
+ if (!t) return null;
1318
+ let n = t[1].trim().split("/").map((e) => e.trim()), r = n[0], i = n[1], a = r.includes(",") ? r.split(",").map((e) => e.trim()).filter(Boolean) : r.split(/\s+/).filter(Boolean);
1319
+ if (a.length < 3) return null;
1320
+ let o = V(a[0]), s = V(a[1]), c = V(a[2]), l = U(i ?? (a.length > 3 ? a[3] : void 0));
1321
+ return o === null || s === null || c === null || l === null ? null : [
1322
+ o,
1323
+ s,
1324
+ c,
1325
+ l
1326
+ ];
1327
+ }
1328
+ function z(e) {
1329
+ let t = e.match(/^color\(\s*srgb\s+(.+)\)$/i);
1330
+ if (!t) return null;
1331
+ let n = t[1].split("/").map((e) => e.trim()), r = n[0].split(/\s+/).filter(Boolean);
1332
+ if (r.length < 3) return null;
1333
+ let i = H(r[0]), a = H(r[1]), o = H(r[2]), s = U(n[1]);
1334
+ return i === null || a === null || o === null || s === null ? null : [
1335
+ i,
1336
+ a,
1337
+ o,
1338
+ s
1339
+ ];
1340
+ }
1341
+ function B(e) {
1342
+ let t = e.startsWith("#") ? e.slice(1) : "";
1343
+ if (![
1344
+ 3,
1345
+ 4,
1346
+ 6,
1347
+ 8
1348
+ ].includes(t.length) || !/^[\da-f]+$/i.test(t)) return null;
1349
+ let n = t.length <= 4 ? [...t].map((e) => e + e).join("") : t, r = Number.parseInt(n, 16);
1350
+ return Number.isFinite(r) ? [
1351
+ (r >> (n.length === 8 ? 24 : 16) & 255) / 255,
1352
+ (r >> (n.length === 8 ? 16 : 8) & 255) / 255,
1353
+ (r >> (n.length === 8 ? 8 : 0) & 255) / 255,
1354
+ n.length === 8 ? (r & 255) / 255 : 1
1355
+ ] : null;
1356
+ }
1248
1357
  function V(e) {
1358
+ return e.endsWith("%") ? W(Number.parseFloat(e) / 100) : W(Number.parseFloat(e) / 255);
1359
+ }
1360
+ function H(e) {
1361
+ return e.endsWith("%") ? W(Number.parseFloat(e) / 100) : W(Number.parseFloat(e));
1362
+ }
1363
+ function U(e) {
1364
+ return e ? e.endsWith("%") ? W(Number.parseFloat(e) / 100) : W(Number.parseFloat(e)) : 1;
1365
+ }
1366
+ function W(e) {
1367
+ return Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : null;
1368
+ }
1369
+ //#endregion
1370
+ //#region src/ui/Chart.ts
1371
+ var G = 16384, K = G >> 1, q = G >> 1, J = 3, Y = 4096, X = 12, Z = 64;
1372
+ function Q(e) {
1249
1373
  return e === !1 ? {
1250
1374
  visible: !1,
1251
1375
  position: "inside"
@@ -1257,13 +1381,36 @@ function V(e) {
1257
1381
  position: e.position ?? "inside"
1258
1382
  };
1259
1383
  }
1260
- var H = class {
1384
+ function $(e) {
1385
+ return e === !1 ? {
1386
+ x: {
1387
+ visible: !1,
1388
+ position: "inside"
1389
+ },
1390
+ y: {
1391
+ visible: !1,
1392
+ position: "inside"
1393
+ }
1394
+ } : e === !0 || e === void 0 ? {
1395
+ x: {
1396
+ visible: !0,
1397
+ position: "inside"
1398
+ },
1399
+ y: {
1400
+ visible: !0,
1401
+ position: "inside"
1402
+ }
1403
+ } : {
1404
+ x: Q(e.x),
1405
+ y: Q(e.y)
1406
+ };
1407
+ }
1408
+ var re = class {
1261
1409
  options;
1262
1410
  series = [];
1263
1411
  camera;
1264
1412
  axis;
1265
1413
  renderer;
1266
- input;
1267
1414
  rawLineBuffer;
1268
1415
  rawLineData;
1269
1416
  minMaxInstanceBuffer;
@@ -1277,6 +1424,8 @@ var H = class {
1277
1424
  yTicks = [];
1278
1425
  axisOverlay = null;
1279
1426
  normalizedAxes;
1427
+ resolvedTheme;
1428
+ _gridVisible;
1280
1429
  layout;
1281
1430
  stats = {
1282
1431
  fps: 0,
@@ -1290,6 +1439,7 @@ var H = class {
1290
1439
  pluginDisposers = [];
1291
1440
  hoverSubscribers = /* @__PURE__ */ new Set();
1292
1441
  seriesSubscribers = /* @__PURE__ */ new Set();
1442
+ themeSubscribers = /* @__PURE__ */ new Set();
1293
1443
  currentHover = null;
1294
1444
  lastPointerClientX = 0;
1295
1445
  lastPointerClientY = 0;
@@ -1303,38 +1453,13 @@ var H = class {
1303
1453
  this.pointerInPlot = !1, this.emitHover(null);
1304
1454
  };
1305
1455
  constructor(e, t = {}) {
1306
- this.options = t;
1307
- let n = t.axes;
1308
- n === !1 ? this.normalizedAxes = {
1309
- x: {
1310
- visible: !1,
1311
- position: "inside"
1312
- },
1313
- y: {
1314
- visible: !1,
1315
- position: "inside"
1316
- }
1317
- } : n === !0 || n === void 0 ? this.normalizedAxes = {
1318
- x: {
1319
- visible: !0,
1320
- position: "inside"
1321
- },
1322
- y: {
1323
- visible: !0,
1324
- position: "inside"
1325
- }
1326
- } : this.normalizedAxes = {
1327
- x: V(n.x),
1328
- y: V(n.y)
1329
- }, this.layout = new N(e, this.normalizedAxes), this.applyCanvasSize(), this.camera = new A(), this.axis = new j(this.camera), this.renderer = new w(new O(this.layout.canvas)), this.input = new k(this.layout.canvas, this.camera, t.viewportPolicy), this.rawLineData = new Float32Array(P * 2), this.rawLineBuffer = this.renderer.createFloatBuffer(this.rawLineData.length), this.minMaxInstanceData = new Float32Array(I * L), this.minMaxInstanceBuffer = this.renderer.createFloatBuffer(this.minMaxInstanceData.length), this.barTriangleData = new Float32Array(R * z), this.barTriangleBuffer = this.renderer.createFloatBuffer(this.barTriangleData.length), this.gridData = new Float32Array(B * 2), this.gridBuffer = this.renderer.createFloatBuffer(this.gridData.length), this.gridStyle = {
1330
- color: t.gridStyle?.color ?? [
1331
- .22,
1332
- .3,
1333
- .44,
1334
- .45
1335
- ],
1456
+ this.options = t, this.resolvedTheme = j(t.theme, e), this.normalizedAxes = $(t.axes), this._gridVisible = t.grid !== !1, this.layout = new k(e, this.normalizedAxes), this.layout.root.style.background = this.resolvedTheme.backgroundCssColor, this.applyCanvasSize(), this.camera = new E(), this.axis = new D(this.camera), this.renderer = new ee(new T(this.layout.canvas)), this.rawLineData = new Float32Array(G * 2), this.rawLineBuffer = this.renderer.createFloatBuffer(this.rawLineData.length), this.minMaxInstanceData = new Float32Array(q * J), this.minMaxInstanceBuffer = this.renderer.createFloatBuffer(this.minMaxInstanceData.length), this.barTriangleData = new Float32Array(Y * X), this.barTriangleBuffer = this.renderer.createFloatBuffer(this.barTriangleData.length), this.gridData = new Float32Array(Z * 2), this.gridBuffer = this.renderer.createFloatBuffer(this.gridData.length), this.gridStyle = {
1457
+ color: t.gridStyle?.color ?? this.resolvedTheme.gridColor,
1336
1458
  lineWidth: t.gridStyle?.lineWidth ?? 1
1337
- }, (this.normalizedAxes.x.visible || this.normalizedAxes.y.visible) && (this.axisOverlay = new M(this.layout, this.normalizedAxes)), this.canvas.addEventListener("pointermove", this.handlePointerMove), this.canvas.addEventListener("pointerleave", this.handlePointerLeave), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(this.layout.plot));
1459
+ }, (this.normalizedAxes.x.visible || this.normalizedAxes.y.visible) && (this.axisOverlay = new O(this.layout, this.normalizedAxes, {
1460
+ color: this.resolvedTheme.axisColor,
1461
+ font: this.resolvedTheme.axisFont
1462
+ })), this.canvas.addEventListener("pointermove", this.handlePointerMove), this.canvas.addEventListener("pointerleave", this.handlePointerLeave), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(this.layout.plot));
1338
1463
  for (let e of t.plugins ?? []) {
1339
1464
  let t = e.install(this);
1340
1465
  typeof t == "function" ? this.pluginDisposers.push(t) : t && this.pluginDisposers.push(() => t.dispose());
@@ -1349,30 +1474,54 @@ var H = class {
1349
1474
  get plotElement() {
1350
1475
  return this.layout.plot;
1351
1476
  }
1477
+ get xAxisElement() {
1478
+ return this.layout.xAxis;
1479
+ }
1480
+ get yAxisElement() {
1481
+ return this.layout.yAxis;
1482
+ }
1483
+ get theme() {
1484
+ return this.resolvedTheme;
1485
+ }
1486
+ getCamera() {
1487
+ return this.camera;
1488
+ }
1352
1489
  dataToPlot(e, t) {
1353
1490
  let [n, r] = this.camera.toClip(e, t);
1354
1491
  return this.camera.toScreen(n, r, this.canvas.clientWidth, this.canvas.clientHeight);
1355
1492
  }
1493
+ clientToData(e, t) {
1494
+ let n = this.canvas.getBoundingClientRect();
1495
+ if (n.width <= 0 || n.height <= 0) return null;
1496
+ let r = e - n.left, i = t - n.top;
1497
+ if (r < 0 || i < 0 || r > n.width || i > n.height) return null;
1498
+ let a = this.camera.viewport;
1499
+ return [a.xMin + r / n.width * (a.xMax - a.xMin), a.yMax - i / n.height * (a.yMax - a.yMin)];
1500
+ }
1501
+ getViewport() {
1502
+ return this.camera.viewport;
1503
+ }
1504
+ pan(e) {
1505
+ this.camera.pan(e), this.refreshHover();
1506
+ }
1507
+ zoom(e) {
1508
+ this.camera.zoom(e), this.refreshHover();
1509
+ }
1356
1510
  addSeries(e, t) {
1357
- let n = e.dataset ?? new a(e.capacity), r = t?.color ?? [
1358
- .3,
1359
- .6,
1360
- 1,
1361
- 1
1362
- ], o = new i(n, e, {
1363
- color: r,
1511
+ let n = e.dataset ?? new a(e.capacity), r = this.resolvedTheme.seriesColors, o = r[this.series.length % r.length] ?? this.resolvedTheme.seriesColors[0], s = t?.color ?? o, c = new i(n, e, {
1512
+ color: s,
1364
1513
  lineWidth: t?.lineWidth ?? 1,
1365
1514
  pointSize: t?.pointSize ?? 4,
1366
1515
  barWidth: t?.barWidth ?? .8,
1367
1516
  baseline: t?.baseline ?? 0,
1368
1517
  fillColor: t?.fillColor ?? [
1369
- r[0],
1370
- r[1],
1371
- r[2],
1372
- r[3] * .25
1518
+ s[0],
1519
+ s[1],
1520
+ s[2],
1521
+ s[3] * .25
1373
1522
  ]
1374
1523
  });
1375
- return this.series.push(o), this.emitSeriesChange(), o;
1524
+ return this.series.push(c), this.emitSeriesChange(), c;
1376
1525
  }
1377
1526
  addLine(e, t) {
1378
1527
  return this.addSeries({
@@ -1417,10 +1566,11 @@ var H = class {
1417
1566
  }));
1418
1567
  }
1419
1568
  setViewport(e) {
1420
- this.camera.setViewport(e);
1569
+ this.camera.setViewport(e), this.refreshHover();
1421
1570
  }
1422
1571
  resize(e = globalThis.devicePixelRatio) {
1423
- return this.applyCanvasSize(e);
1572
+ let t = this.applyCanvasSize(e);
1573
+ return t && this.refreshHover(), t;
1424
1574
  }
1425
1575
  getFrameStats(e = {
1426
1576
  fps: 0,
@@ -1440,9 +1590,28 @@ var H = class {
1440
1590
  let e = t;
1441
1591
  return this.hoverSubscribers.add(e), () => this.hoverSubscribers.delete(e);
1442
1592
  }
1593
+ if (e === "themechange") {
1594
+ let e = t;
1595
+ return this.themeSubscribers.add(e), () => this.themeSubscribers.delete(e);
1596
+ }
1443
1597
  let n = t;
1444
1598
  return this.seriesSubscribers.add(n), () => this.seriesSubscribers.delete(n);
1445
1599
  }
1600
+ setTheme(e) {
1601
+ this.resolvedTheme = j(e, this.layout.root), this.applyTheme(), this.emitThemeChange(), this.refreshHover();
1602
+ }
1603
+ setGridVisible(e) {
1604
+ this._gridVisible = e;
1605
+ }
1606
+ getGridVisible() {
1607
+ return this._gridVisible;
1608
+ }
1609
+ setAxes(e) {
1610
+ this.normalizedAxes = $(e), this.layout.update(this.normalizedAxes), this.axisOverlay?.dispose(), this.axisOverlay = null, (this.normalizedAxes.x.visible || this.normalizedAxes.y.visible) && (this.axisOverlay = new O(this.layout, this.normalizedAxes, {
1611
+ color: this.resolvedTheme.axisColor,
1612
+ font: this.resolvedTheme.axisFont
1613
+ })), this.resize(), this.refreshHover();
1614
+ }
1446
1615
  pick(e, t, n = {}) {
1447
1616
  let r = this.canvas.getBoundingClientRect();
1448
1617
  if (r.width <= 0 || r.height <= 0) return null;
@@ -1467,7 +1636,7 @@ var H = class {
1467
1636
  o.width = i, o.height = a;
1468
1637
  let s = o.getContext("2d");
1469
1638
  if (!s) throw Error("Unable to create a 2D canvas context for screenshot export.");
1470
- return e.background ? (s.fillStyle = e.background, s.fillRect(0, 0, i, a)) : s.clearRect(0, 0, i, a), s.drawImage(this.canvas, (n.left - t.left) * r, (n.top - t.top) * r, n.width * r, n.height * r), this.drawDomTextForScreenshot(s, t, r), new Promise((t, n) => {
1639
+ return s.fillStyle = e.background ?? P(this.resolvedTheme.backgroundColor), s.fillRect(0, 0, i, a), s.drawImage(this.canvas, (n.left - t.left) * r, (n.top - t.top) * r, n.width * r, n.height * r), this.drawDomTextForScreenshot(s, t, r), new Promise((t, n) => {
1471
1640
  o.toBlob((e) => e ? t(e) : n(/* @__PURE__ */ Error("Unable to encode chart screenshot.")), e.type ?? "image/png", e.quality);
1472
1641
  });
1473
1642
  }
@@ -1482,56 +1651,67 @@ var H = class {
1482
1651
  }
1483
1652
  render() {
1484
1653
  let e = performance.now();
1485
- this.lastFrameAt > 0 && (this.stats.fps = 1e3 / (e - this.lastFrameAt)), this.lastFrameAt = e, this.stats.pointsRendered = 0, this.stats.drawCalls = 0, this.stats.uploadBytes = 0, this.stats.renderMode = "none", this.options.viewportPolicy?.beforeRender?.(this.camera), this.renderer.viewport(0, 0, this.canvas.width, this.canvas.height), this.renderer.clear(.08, .1, .16, 1);
1486
- let t = this.camera.viewport;
1487
- if (this.options.grid !== !1) {
1488
- let e = this.writeGridVertices(t);
1654
+ this.lastFrameAt > 0 && (this.stats.fps = 1e3 / (e - this.lastFrameAt)), this.lastFrameAt = e, this.stats.pointsRendered = 0, this.stats.drawCalls = 0, this.stats.uploadBytes = 0, this.stats.renderMode = "none", this.options.viewportPolicy?.beforeRender?.(this.camera);
1655
+ let [t, n, r, i] = this.resolvedTheme.backgroundColor;
1656
+ this.renderer.viewport(0, 0, this.canvas.width, this.canvas.height), this.renderer.clear(t, n, r, i);
1657
+ let a = this.camera.viewport;
1658
+ if (this._gridVisible) {
1659
+ let e = this.writeGridVertices(a);
1489
1660
  e > 0 && (this.renderer.updateFloatBuffer(this.gridBuffer, this.gridData), this.renderer.drawLines(this.gridBuffer, e, this.gridStyle, this.camera), this.stats.drawCalls++, this.stats.uploadBytes += this.gridData.byteLength);
1490
1661
  }
1491
1662
  for (let e of this.series) {
1492
1663
  if (!e.visible) continue;
1493
1664
  if (e.rebuildPyramid(), e.config.mode === "scatter") {
1494
- this.drawScatterSeries(e, t);
1665
+ this.drawScatterSeries(e, a);
1495
1666
  continue;
1496
1667
  }
1497
1668
  if (e.config.mode === "bar") {
1498
- this.drawBarSeries(e, t);
1669
+ this.drawBarSeries(e, a);
1499
1670
  continue;
1500
1671
  }
1501
1672
  if (e.config.mode === "area") {
1502
- this.drawAreaSeries(e, t);
1673
+ this.drawAreaSeries(e, a);
1503
1674
  continue;
1504
1675
  }
1505
- let n = e.visibleSampleCount(t), r = e.hasLOD && n > P;
1506
- if (r && this.renderer.supportsInstancedSegments) {
1507
- let n = e.copyMinMaxInstanced(t, this.minMaxInstanceData, this.maxMinMaxSegments());
1508
- if (n <= 0) continue;
1509
- this.renderer.updateFloatBuffer(this.minMaxInstanceBuffer, this.minMaxInstanceData), this.renderer.drawMinMaxSegmentsInstanced(this.minMaxInstanceBuffer, n, e.style, this.camera), this.recordRenderMode("minmax"), this.stats.pointsRendered += n * 2, this.stats.drawCalls++, this.stats.uploadBytes += this.minMaxInstanceData.byteLength;
1676
+ let t = e.visibleSampleCount(a), n = e.hasLOD && t > G;
1677
+ if (n && this.renderer.supportsInstancedSegments) {
1678
+ let t = e.copyMinMaxInstanced(a, this.minMaxInstanceData, this.maxMinMaxSegments());
1679
+ if (t <= 0) continue;
1680
+ this.renderer.updateFloatBuffer(this.minMaxInstanceBuffer, this.minMaxInstanceData), this.renderer.drawMinMaxSegmentsInstanced(this.minMaxInstanceBuffer, t, e.style, this.camera), this.recordRenderMode("minmax"), this.stats.pointsRendered += t * 2, this.stats.drawCalls++, this.stats.uploadBytes += this.minMaxInstanceData.byteLength;
1510
1681
  continue;
1511
1682
  }
1512
- let i = r ? e.copyMinMaxVisible(t, this.rawLineData, this.maxMinMaxSegments()) : e.copyRawVisible(t, this.rawLineData, P);
1513
- i < 2 || (this.renderer.updateFloatBuffer(this.rawLineBuffer, this.rawLineData), r ? (this.renderer.drawMinMaxSegments(this.rawLineBuffer, i, e.style, this.camera), this.recordRenderMode("minmax")) : (this.renderer.drawLineStrip(this.rawLineBuffer, i, e.style, this.camera), this.recordRenderMode("raw")), this.stats.pointsRendered += i, this.stats.drawCalls++, this.stats.uploadBytes += this.rawLineData.byteLength);
1683
+ let r = n ? e.copyMinMaxVisible(a, this.rawLineData, this.maxMinMaxSegments()) : e.copyRawVisible(a, this.rawLineData, G);
1684
+ r < 2 || (this.renderer.updateFloatBuffer(this.rawLineBuffer, this.rawLineData), n ? (this.renderer.drawMinMaxSegments(this.rawLineBuffer, r, e.style, this.camera), this.recordRenderMode("minmax")) : (this.renderer.drawLineStrip(this.rawLineBuffer, r, e.style, this.camera), this.recordRenderMode("raw")), this.stats.pointsRendered += r, this.stats.drawCalls++, this.stats.uploadBytes += this.rawLineData.byteLength);
1514
1685
  }
1515
1686
  this.axisOverlay?.update(this.camera, this.axis), this.stats.frameMs = performance.now() - e, this.refreshHover();
1516
1687
  }
1517
1688
  dispose() {
1518
1689
  this.stop(), this.resizeObserver?.disconnect(), this.canvas.removeEventListener("pointermove", this.handlePointerMove), this.canvas.removeEventListener("pointerleave", this.handlePointerLeave);
1519
1690
  for (let e of this.pluginDisposers.splice(0)) e();
1520
- this.input.dispose(), this.axisOverlay?.dispose(), this.renderer.dispose(), this.layout.dispose();
1691
+ this.axisOverlay?.dispose(), this.renderer.dispose(), this.layout.dispose();
1692
+ }
1693
+ applyTheme() {
1694
+ this.layout.root.style.background = this.resolvedTheme.backgroundCssColor, this.options.gridStyle?.color === void 0 && (this.gridStyle = {
1695
+ ...this.gridStyle,
1696
+ color: this.resolvedTheme.gridColor
1697
+ }), this.axisOverlay?.setOptions({
1698
+ color: this.resolvedTheme.axisColor,
1699
+ font: this.resolvedTheme.axisFont
1700
+ });
1521
1701
  }
1522
1702
  applyCanvasSize(e = globalThis.devicePixelRatio) {
1523
1703
  let t = Number.isFinite(e) ? Math.max(1, e) : 1, n = Math.max(1, Math.floor(this.canvas.clientWidth * t)), r = Math.max(1, Math.floor(this.canvas.clientHeight * t));
1524
1704
  return this.canvas.width === n && this.canvas.height === r ? !1 : (this.canvas.width = n, this.canvas.height = r, !0);
1525
1705
  }
1526
1706
  drawAreaSeries(e, t) {
1527
- let n = e.style.baseline ?? 0, r = e.copyAreaVisible(t, this.rawLineData, F, n);
1707
+ let n = e.style.baseline ?? 0, r = e.copyAreaVisible(t, this.rawLineData, K, n);
1528
1708
  if (r < 4) return;
1529
1709
  this.renderer.updateFloatBuffer(this.rawLineBuffer, this.rawLineData), this.renderer.drawAreaStrip(this.rawLineBuffer, r, e.style, this.camera), this.stats.pointsRendered += r, this.stats.drawCalls++, this.stats.uploadBytes += this.rawLineData.byteLength;
1530
- let i = this.uploadRawInstances(e, t, F);
1710
+ let i = this.uploadRawInstances(e, t, K);
1531
1711
  i >= 2 && (this.renderer.drawLineStrip(this.rawLineBuffer, i, e.style, this.camera), this.stats.pointsRendered += i, this.stats.drawCalls++), this.recordRenderMode("area");
1532
1712
  }
1533
1713
  drawScatterSeries(e, t) {
1534
- let n = this.uploadRawInstances(e, t, P);
1714
+ let n = this.uploadRawInstances(e, t, G);
1535
1715
  n <= 0 || (this.renderer.supportsInstancedPoints ? this.renderer.drawPointsInstanced(this.rawLineBuffer, n, e.style, this.camera, this.canvas.width, this.canvas.height) : this.renderer.drawPointSprites(this.rawLineBuffer, n, e.style, this.camera), this.recordInstancedDraw("points", n));
1536
1716
  }
1537
1717
  drawBarSeries(e, t) {
@@ -1559,7 +1739,7 @@ var H = class {
1559
1739
  }
1560
1740
  includeBaselineInBarRanges(e, t) {
1561
1741
  for (let n = 0; n < e; n++) {
1562
- let e = n * L, r = this.minMaxInstanceData[e + 1], i = this.minMaxInstanceData[e + 2];
1742
+ let e = n * J, r = this.minMaxInstanceData[e + 1], i = this.minMaxInstanceData[e + 2];
1563
1743
  this.minMaxInstanceData[e + 1] = Math.min(t, r), this.minMaxInstanceData[e + 2] = Math.max(t, i);
1564
1744
  }
1565
1745
  }
@@ -1593,7 +1773,7 @@ var H = class {
1593
1773
  return [Math.max(n.xMin, s), Math.min(n.xMax, c)];
1594
1774
  }
1595
1775
  writeBarTriangle(e, t, n, r, i) {
1596
- let a = e * z;
1776
+ let a = e * X;
1597
1777
  this.barTriangleData[a] = t, this.barTriangleData[a + 1] = r, this.barTriangleData[a + 2] = n, this.barTriangleData[a + 3] = r, this.barTriangleData[a + 4] = t, this.barTriangleData[a + 5] = i, this.barTriangleData[a + 6] = t, this.barTriangleData[a + 7] = i, this.barTriangleData[a + 8] = n, this.barTriangleData[a + 9] = r, this.barTriangleData[a + 10] = n, this.barTriangleData[a + 11] = i;
1598
1778
  }
1599
1779
  drawBarTriangleFallback(e, t) {
@@ -1657,6 +1837,9 @@ var H = class {
1657
1837
  for (let e of this.seriesSubscribers) e();
1658
1838
  this.refreshHover();
1659
1839
  }
1840
+ emitThemeChange() {
1841
+ for (let e of this.themeSubscribers) e();
1842
+ }
1660
1843
  drawDomTextForScreenshot(e, t, n) {
1661
1844
  let r = this.layout.root.querySelectorAll("div");
1662
1845
  for (let i of r) {
@@ -1669,24 +1852,24 @@ var H = class {
1669
1852
  }
1670
1853
  }
1671
1854
  maxMinMaxSegments() {
1672
- return Math.min(this.canvas.width, I);
1855
+ return Math.min(this.canvas.width, q);
1673
1856
  }
1674
1857
  maxBarFallbackBars() {
1675
- return Math.min(R, P);
1858
+ return Math.min(Y, G);
1676
1859
  }
1677
1860
  maxRawBarInstances() {
1678
- return this.renderer.supportsInstancedBars ? P : this.maxBarFallbackBars();
1861
+ return this.renderer.supportsInstancedBars ? G : this.maxBarFallbackBars();
1679
1862
  }
1680
1863
  writeGridVertices(e) {
1681
1864
  let t = Math.max(1, this.canvas.clientWidth), n = Math.max(1, this.canvas.clientHeight);
1682
1865
  this.axis.getXTickValues(t, 12, this.xTicks), this.axis.getYTickValues(n, 8, this.yTicks);
1683
1866
  let r = 0;
1684
1867
  for (let t of this.xTicks) {
1685
- if (r + 2 > B) return r;
1868
+ if (r + 2 > Z) return r;
1686
1869
  this.gridData[r * 2] = t, this.gridData[r * 2 + 1] = e.yMin, r++, this.gridData[r * 2] = t, this.gridData[r * 2 + 1] = e.yMax, r++;
1687
1870
  }
1688
1871
  for (let t of this.yTicks) {
1689
- if (r + 2 > B) return r;
1872
+ if (r + 2 > Z) return r;
1690
1873
  this.gridData[r * 2] = e.xMin, this.gridData[r * 2 + 1] = t, r++, this.gridData[r * 2] = e.xMax, this.gridData[r * 2 + 1] = t, r++;
1691
1874
  }
1692
1875
  return r;
@@ -1694,7 +1877,7 @@ var H = class {
1694
1877
  recordRenderMode(e) {
1695
1878
  this.stats.renderMode === "none" ? this.stats.renderMode = e : this.stats.renderMode !== e && (this.stats.renderMode = "mixed");
1696
1879
  }
1697
- }, U = class {
1880
+ }, ie = class {
1698
1881
  xData;
1699
1882
  yData;
1700
1883
  constructor(e, t) {
@@ -1736,6 +1919,6 @@ var H = class {
1736
1919
  }
1737
1920
  };
1738
1921
  //#endregion
1739
- export { j as AxisController, A as Camera2D, H as Chart, n as MinMaxPyramid, a as RingBuffer, i as SeriesStore, U as StaticDataset };
1922
+ export { D as AxisController, E as Camera2D, re as Chart, A as DEFAULT_CHART_THEME, n as MinMaxPyramid, a as RingBuffer, i as SeriesStore, ie as StaticDataset };
1740
1923
 
1741
1924
  //# sourceMappingURL=index.js.map