@crysound/crychart 1.0.7 → 1.0.8

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.
@@ -1029,6 +1029,262 @@ var CRYChart = (() => {
1029
1029
  return page[absoluteIndex - pageIndex * view.pageSize];
1030
1030
  }
1031
1031
 
1032
+ // src/data-order.ts
1033
+ var caches = /* @__PURE__ */ new WeakMap();
1034
+ function resetContent(state) {
1035
+ state.epoch = -1;
1036
+ state.first = 0;
1037
+ state.next = 0;
1038
+ state.lastIndex = -1;
1039
+ state.lastValue = NaN;
1040
+ state.invalid = -1;
1041
+ state.decrease = -1;
1042
+ state.nonIncrease = -1;
1043
+ state.lastScanned = 0;
1044
+ state.lastFast = 0;
1045
+ state.lastEndpoints = 0;
1046
+ }
1047
+ function createState() {
1048
+ return {
1049
+ epoch: -1,
1050
+ first: 0,
1051
+ next: 0,
1052
+ lastIndex: -1,
1053
+ lastValue: NaN,
1054
+ invalid: -1,
1055
+ decrease: -1,
1056
+ nonIncrease: -1,
1057
+ scanned: 0,
1058
+ lastScanned: 0,
1059
+ fast: 0,
1060
+ lastFast: 0,
1061
+ endpoints: 0,
1062
+ lastEndpoints: 0,
1063
+ cacheHits: 0,
1064
+ rebuilds: 0
1065
+ };
1066
+ }
1067
+ function cacheFor(dataSet) {
1068
+ let cache = caches.get(dataSet);
1069
+ if (!cache) {
1070
+ cache = { epoch: dataSet.getContentEpoch(), columns: /* @__PURE__ */ new Map() };
1071
+ caches.set(dataSet, cache);
1072
+ const owned2 = cache;
1073
+ dataSet.onChange((current) => {
1074
+ if (current.isDisposed()) {
1075
+ owned2.columns.clear();
1076
+ caches.delete(current);
1077
+ return;
1078
+ }
1079
+ const epoch = current.getContentEpoch();
1080
+ if (owned2.epoch !== epoch) {
1081
+ for (const state of owned2.columns.values()) resetContent(state);
1082
+ owned2.epoch = epoch;
1083
+ }
1084
+ });
1085
+ }
1086
+ return cache;
1087
+ }
1088
+ function accept(state, index, value, first) {
1089
+ if (!Number.isFinite(value)) state.invalid = index;
1090
+ if (index > first && state.lastIndex === index - 1) {
1091
+ if (value < state.lastValue) state.decrease = index;
1092
+ if (value <= state.lastValue) state.nonIncrease = index;
1093
+ }
1094
+ state.lastValue = value;
1095
+ state.lastIndex = index;
1096
+ }
1097
+ function certifiedIncreasing(run, firstOffset, lastOffset, a, b) {
1098
+ if (!(run.step > 0) || !Number.isFinite(run.step) || !Number.isFinite(run.start) || !Number.isFinite(a) || !Number.isFinite(b) || !(b > a)) return false;
1099
+ const magnitude = Math.max(Math.abs(run.start), Math.abs(firstOffset * run.step), Math.abs(lastOffset * run.step), Math.abs(a), Math.abs(b));
1100
+ const separation = magnitude * Number.EPSILON * 8 + Number.MIN_VALUE * 8;
1101
+ return run.step > separation;
1102
+ }
1103
+ function scanAffine(state, view, from, next) {
1104
+ let low = view.runStart, high = view.runs.length;
1105
+ while (low < high) {
1106
+ const middle = low + Math.floor((high - low) / 2), run = view.runs[middle];
1107
+ if (run.firstIndex + run.count <= from) low = middle + 1;
1108
+ else high = middle;
1109
+ }
1110
+ for (let r = low; r < view.runs.length; r++) {
1111
+ const run = view.runs[r], first = Math.max(from, run.firstIndex), end = Math.min(next, run.firstIndex + run.count);
1112
+ if (first >= end) continue;
1113
+ if (end - first > 1) {
1114
+ const firstOffset = first - run.firstIndex, lastOffset = end - 1 - run.firstIndex;
1115
+ const a = run.start + firstOffset * run.step, b = run.start + lastOffset * run.step;
1116
+ state.endpoints += 2;
1117
+ state.lastEndpoints += 2;
1118
+ if (certifiedIncreasing(run, firstOffset, lastOffset, a, b)) {
1119
+ accept(state, first, a, view.firstIndex);
1120
+ state.lastIndex = end - 1;
1121
+ state.lastValue = b;
1122
+ state.fast += end - first;
1123
+ state.lastFast += end - first;
1124
+ continue;
1125
+ }
1126
+ }
1127
+ for (let index = first; index < end; index++) accept(state, index, run.start + (index - run.firstIndex) * run.step, view.firstIndex);
1128
+ state.scanned += end - first;
1129
+ state.lastScanned += end - first;
1130
+ }
1131
+ }
1132
+ function result(state, first, next, epoch) {
1133
+ const finite2 = state.invalid < first;
1134
+ return {
1135
+ finite: finite2,
1136
+ monotonic: finite2 && state.decrease <= first,
1137
+ strict: finite2 && state.nonIncrease <= first,
1138
+ sampleCount: next - first,
1139
+ firstIndex: first,
1140
+ nextIndex: next,
1141
+ contentEpoch: epoch,
1142
+ lastInvalidPointIndex: state.invalid,
1143
+ lastDecreaseEdgeIndex: state.decrease,
1144
+ lastNonIncreaseEdgeIndex: state.nonIncrease,
1145
+ scannedSamples: state.scanned,
1146
+ lastScannedSamples: state.lastScanned,
1147
+ affineFastSamples: state.fast,
1148
+ lastAffineFastSamples: state.lastFast,
1149
+ affineEndpointEvaluations: state.endpoints,
1150
+ lastAffineEndpointEvaluations: state.lastEndpoints,
1151
+ cacheHits: state.cacheHits,
1152
+ rebuilds: state.rebuilds
1153
+ };
1154
+ }
1155
+ function getColumnOrder(dataSet, name) {
1156
+ if (!(dataSet.hasColumn?.(name) ?? Object.prototype.hasOwnProperty.call(dataSet.schema, name))) throw new RangeError(`Unknown data column: ${name}`);
1157
+ const epoch = dataSet.getContentEpoch(), next = dataSet.getNextSampleIndex(), first = next - dataSet.getSampleCount();
1158
+ if (dataSet.isDisposed()) return result(createState(), first, next, epoch);
1159
+ const cache = cacheFor(dataSet);
1160
+ let state = cache.columns.get(name);
1161
+ if (!state) {
1162
+ state = createState();
1163
+ cache.columns.set(name, state);
1164
+ }
1165
+ state.lastScanned = 0;
1166
+ state.lastFast = 0;
1167
+ state.lastEndpoints = 0;
1168
+ if (state.epoch === epoch && state.first === first && state.next === next) {
1169
+ state.cacheHits++;
1170
+ return result(state, first, next, epoch);
1171
+ }
1172
+ if (state.epoch !== epoch || next < state.next || first < state.first) {
1173
+ resetContent(state);
1174
+ state.rebuilds++;
1175
+ }
1176
+ const from = Math.max(first, state.next);
1177
+ if (from < next) {
1178
+ const view = dataSet.getColumnRuns(name);
1179
+ if (view.kind === "affine") scanAffine(state, view, from, next);
1180
+ else if (view.kind === "paged") {
1181
+ const cursor = new PagedColumnCursor(view, from);
1182
+ while (cursor.values) {
1183
+ const values = cursor.values, base = cursor.absoluteIndex - cursor.offset;
1184
+ for (let i = cursor.offset, end = i + cursor.length; i < end; i++) accept(state, base + i, values[i], first);
1185
+ cursor.next();
1186
+ }
1187
+ state.scanned += next - from;
1188
+ state.lastScanned += next - from;
1189
+ } else {
1190
+ let absolute = view.firstIndex;
1191
+ for (const values of view.slices) {
1192
+ const start = Math.max(0, from - absolute);
1193
+ for (let i = start; i < values.length; i++) accept(state, absolute + i, values[i], first);
1194
+ absolute += values.length;
1195
+ }
1196
+ state.scanned += next - from;
1197
+ state.lastScanned += next - from;
1198
+ }
1199
+ }
1200
+ state.epoch = epoch;
1201
+ state.first = first;
1202
+ state.next = next;
1203
+ return result(state, first, next, epoch);
1204
+ }
1205
+ var finiteCaches = /* @__PURE__ */ new WeakMap();
1206
+ function getColumnFinite(dataSet, name) {
1207
+ if (!(dataSet.hasColumn?.(name) ?? Object.prototype.hasOwnProperty.call(dataSet.schema, name))) throw new RangeError(`Unknown data column: ${name}`);
1208
+ const epoch = dataSet.getContentEpoch(), next = dataSet.getNextSampleIndex(), first = next - dataSet.getSampleCount();
1209
+ const expected2 = { revision: dataSet.revision, epoch, first, next };
1210
+ let columns = finiteCaches.get(dataSet);
1211
+ if (!columns && !dataSet.isDisposed()) {
1212
+ columns = /* @__PURE__ */ new Map();
1213
+ finiteCaches.set(dataSet, columns);
1214
+ const owned2 = columns;
1215
+ dataSet.onChange((current) => {
1216
+ if (current.isDisposed()) {
1217
+ owned2.clear();
1218
+ finiteCaches.delete(current);
1219
+ }
1220
+ });
1221
+ }
1222
+ let state = columns?.get(name);
1223
+ if (!state) {
1224
+ state = { invalid: -1, scanned: 0, fullScans: 0, incrementalScans: 0, cacheHits: 0 };
1225
+ columns?.set(name, state);
1226
+ }
1227
+ const before = readSourceCertificate(dataSet, expected2);
1228
+ const delta = !before?.tainted && state.certificate ? certifySourceDelta(dataSet, state.certificate, expected2).delta : void 0;
1229
+ state.certificate = void 0;
1230
+ let from = first, scanned = 0;
1231
+ if (delta) {
1232
+ from = Math.max(first, delta.previous.next);
1233
+ if (delta.kind === "unchanged") state.cacheHits++;
1234
+ else state.incrementalScans++;
1235
+ } else {
1236
+ state.invalid = -1;
1237
+ state.fullScans++;
1238
+ }
1239
+ if (from < next && !dataSet.isDisposed()) {
1240
+ const view = dataSet.getColumnRuns(name);
1241
+ if (view.firstIndex !== first || view.count !== next - first) throw new RangeError("Finite source does not cover the retained window");
1242
+ if (view.kind === "dense") {
1243
+ let absolute = first;
1244
+ for (const values of view.slices) {
1245
+ const start = Math.max(0, from - absolute), end = Math.min(values.length, next - absolute);
1246
+ for (let i = start; i < end; i++) if (!Number.isFinite(values[i])) state.invalid = absolute + i;
1247
+ scanned += Math.max(0, end - start);
1248
+ absolute += values.length;
1249
+ }
1250
+ } else if (view.kind === "paged") {
1251
+ for (let index = from; index < next; ) {
1252
+ const pageIndex = Math.floor(index / view.pageSize), base = pageIndex * view.pageSize;
1253
+ const values = view.getPage(pageIndex), end = Math.min(next, base + view.pageSize);
1254
+ for (; index < end; index++) {
1255
+ if (!Number.isFinite(values?.[index - base])) state.invalid = index;
1256
+ scanned++;
1257
+ }
1258
+ }
1259
+ } else {
1260
+ for (let r = view.runStart; r < view.runs.length; r++) {
1261
+ const run = view.runs[r], begin = Math.max(from, run.firstIndex), end = Math.min(next, run.firstIndex + run.count);
1262
+ for (let index = begin; index < end; index++) if (!Number.isFinite(run.start + (index - run.firstIndex) * run.step)) state.invalid = index;
1263
+ scanned += Math.max(0, end - begin);
1264
+ }
1265
+ }
1266
+ if (scanned !== next - from) throw new RangeError("Finite source omitted retained values");
1267
+ }
1268
+ state.scanned += scanned;
1269
+ const after = readSourceCertificate(dataSet, expected2);
1270
+ const verifiedCurrent = dataSet.revision === expected2.revision && dataSet.getContentEpoch() === epoch && dataSet.getNextSampleIndex() === next && dataSet.getSampleCount() === next - first && before === after;
1271
+ state.certificate = verifiedCurrent && after && !after.tainted ? after : void 0;
1272
+ return {
1273
+ finite: verifiedCurrent && state.invalid < first,
1274
+ verifiedCurrent,
1275
+ sampleCount: next - first,
1276
+ firstIndex: first,
1277
+ nextIndex: next,
1278
+ contentEpoch: epoch,
1279
+ lastInvalidPointIndex: state.invalid,
1280
+ scannedSamples: state.scanned,
1281
+ lastScannedSamples: scanned,
1282
+ fullScans: state.fullScans,
1283
+ incrementalScans: state.incrementalScans,
1284
+ cacheHits: state.cacheHits
1285
+ };
1286
+ }
1287
+
1032
1288
  // src/core/data.ts
1033
1289
  function positiveInteger(value, name) {
1034
1290
  if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`${name} must be a positive safe integer`);
@@ -1517,7 +1773,7 @@ var CRYChart = (() => {
1517
1773
  const name = range.key === void 0 ? [...this.columns].find(([, c]) => c.schema.pattern === "progressive" || c.schema.pattern === "regressive")?.[0] ?? (this.columns.has("xValues") ? "xValues" : "x") : String(range.key);
1518
1774
  const column = this.columns.get(name);
1519
1775
  if (!column) throw new RangeError(`Unknown data column: ${name}`);
1520
- [from, to] = this.findRange(column, Math.min(range.start, range.end), Math.max(range.start, range.end));
1776
+ [from, to] = this.findRange(name, column, Math.min(range.start, range.end), Math.max(range.start, range.end));
1521
1777
  }
1522
1778
  const data = {};
1523
1779
  const allocated = this.pagedOptions ? /* @__PURE__ */ new Set() : void 0;
@@ -1762,11 +2018,34 @@ var CRYChart = (() => {
1762
2018
  column.runStart = 0;
1763
2019
  invalidateSourceCertificate(this, this.deltaSourceHeader(), "column-materialized");
1764
2020
  }
1765
- findRange(column, min, max) {
2021
+ findRange(name, column, min, max) {
1766
2022
  let from = this.count, to = this.count;
1767
- if (Number.isNaN(min) || Number.isNaN(max)) return [from, to];
2023
+ if (this.count === 0 || Number.isNaN(min) || Number.isNaN(max)) return [from, to];
2024
+ const monotonic = getColumnOrder(this, name).monotonic;
1768
2025
  if (column.paged !== void 0) {
1769
2026
  const view = this.paged.getColumnView(column.paged), firstIndex = view.firstIndex, endIndex = firstIndex + view.count;
2027
+ if (monotonic) {
2028
+ const pageSize = view.pageSize;
2029
+ const valueAt = (index) => {
2030
+ const pageIndex = Math.floor(index / pageSize), page = view.getPage(pageIndex);
2031
+ if (!page) throw new Error("Missing retained page");
2032
+ return page[index - pageIndex * pageSize];
2033
+ };
2034
+ let low = firstIndex, high = endIndex;
2035
+ while (low < high) {
2036
+ const middle = low + Math.floor((high - low) / 2);
2037
+ if (valueAt(middle) < min) low = middle + 1;
2038
+ else high = middle;
2039
+ }
2040
+ const matchStart = low;
2041
+ high = endIndex;
2042
+ while (low < high) {
2043
+ const middle = low + Math.floor((high - low) / 2);
2044
+ if (valueAt(middle) <= max) low = middle + 1;
2045
+ else high = middle;
2046
+ }
2047
+ return matchStart < low ? [matchStart - firstIndex, low - firstIndex] : [this.count, this.count];
2048
+ }
1770
2049
  for (let index = firstIndex; index < endIndex; ) {
1771
2050
  const pageIndex = Math.floor(index / view.pageSize), page = view.getPage(pageIndex);
1772
2051
  if (!page) throw new Error("Missing retained page");
@@ -1781,6 +2060,47 @@ var CRYChart = (() => {
1781
2060
  }
1782
2061
  } else if (column.runs) {
1783
2062
  const firstIndex = this.nextIndex - this.count;
2063
+ if (monotonic) {
2064
+ let rFirst = this.findRun(column, firstIndex);
2065
+ const rEnd = column.runs.length;
2066
+ const runBounds = (r) => {
2067
+ const run = column.runs[r];
2068
+ const start = Math.max(firstIndex, run.firstIndex), end = Math.min(this.nextIndex, run.firstIndex + run.count);
2069
+ return { run, start, end, firstVal: run.start + (start - run.firstIndex) * run.step, lastVal: run.start + (end - 1 - run.firstIndex) * run.step };
2070
+ };
2071
+ let low = rFirst, high = rEnd;
2072
+ while (low < high) {
2073
+ const mid = low + Math.floor((high - low) / 2);
2074
+ if (runBounds(mid).lastVal < min) low = mid + 1;
2075
+ else high = mid;
2076
+ }
2077
+ const startRunIndex = low;
2078
+ if (startRunIndex >= rEnd) return [this.count, this.count];
2079
+ low = startRunIndex;
2080
+ high = rEnd;
2081
+ while (low < high) {
2082
+ const mid = low + Math.floor((high - low) / 2);
2083
+ if (runBounds(mid).firstVal <= max) low = mid + 1;
2084
+ else high = mid;
2085
+ }
2086
+ const endRunIndex = low - 1;
2087
+ if (endRunIndex < startRunIndex) return [this.count, this.count];
2088
+ const firstB = runBounds(startRunIndex);
2089
+ let sLow = firstB.start, sHigh = firstB.end;
2090
+ while (sLow < sHigh) {
2091
+ const mid = sLow + Math.floor((sHigh - sLow) / 2);
2092
+ if (firstB.run.start + (mid - firstB.run.firstIndex) * firstB.run.step < min) sLow = mid + 1;
2093
+ else sHigh = mid;
2094
+ }
2095
+ const lastB = runBounds(endRunIndex);
2096
+ let eLow = startRunIndex === endRunIndex ? sLow : lastB.start, eHigh = lastB.end;
2097
+ while (eLow < eHigh) {
2098
+ const mid = eLow + Math.floor((eHigh - eLow) / 2);
2099
+ if (lastB.run.start + (mid - lastB.run.firstIndex) * lastB.run.step <= max) eLow = mid + 1;
2100
+ else eHigh = mid;
2101
+ }
2102
+ return sLow < eLow ? [sLow - firstIndex, eLow - firstIndex] : [this.count, this.count];
2103
+ }
1784
2104
  for (let r = column.runStart; r < column.runs.length; r++) {
1785
2105
  const run = column.runs[r];
1786
2106
  const start = Math.max(firstIndex, run.firstIndex), end = Math.min(this.nextIndex, run.firstIndex + run.count);
@@ -1815,6 +2135,23 @@ var CRYChart = (() => {
1815
2135
  }
1816
2136
  } else {
1817
2137
  const first = Math.min(this.count, this.allocation - this.head);
2138
+ if (monotonic) {
2139
+ const denseAt = (i) => column.values[i < first ? this.head + i : i - first];
2140
+ let low = 0, high = this.count;
2141
+ while (low < high) {
2142
+ const middle = low + Math.floor((high - low) / 2);
2143
+ if (denseAt(middle) < min) low = middle + 1;
2144
+ else high = middle;
2145
+ }
2146
+ const matchStart = low;
2147
+ high = this.count;
2148
+ while (low < high) {
2149
+ const middle = low + Math.floor((high - low) / 2);
2150
+ if (denseAt(middle) <= max) low = middle + 1;
2151
+ else high = middle;
2152
+ }
2153
+ return matchStart < low ? [matchStart, low] : [this.count, this.count];
2154
+ }
1818
2155
  for (let i = 0; i < first; i++) {
1819
2156
  const value = column.values[this.head + i];
1820
2157
  if (value >= min && value <= max) {
@@ -4562,329 +4899,73 @@ var CRYChart = (() => {
4562
4899
  const minorCandidates = steppedTickPositions(low, high, base).filter((value) => !majorSet.has(value));
4563
4900
  const width = (values, level) => Math.max(0, ...values.map((value) => {
4564
4901
  const text = format(value, level);
4565
- return measure?.(text, level) ?? text.length * this.tickStrategy[level].getLabelFont().getSize() * 0.6;
4566
- }));
4567
- const minorFill = this.tickStrategy.minor.getLabelFillStyle(), minorTextVisible = minorFill?.kind !== "empty" && (minorFill?.getColor?.()?.a ?? 1) > 0;
4568
- automatic.minor = minorTextVisible ? timeTickPositions(start, end, axisSizePixels, intervalCount, { majorLabelWidth: width(automatic.major, "major"), minorLabelWidth: width(minorCandidates, "minor") }).minor : minorCandidates;
4569
- }
4570
- const collect = (level) => {
4571
- const placement = level === "major" ? this.tickStrategy.customMajor : this.tickStrategy.customMinor;
4572
- const customPixels = placement ? this.chart.getAxisCustomTickPlacementPixelLength?.(this) : void 0;
4573
- const values = placement ? placement({ interval: { start, end }, axisSizePixels: customPixels ?? axisSizePixels }) : automatic[level];
4574
- if (!Array.isArray(values)) return [];
4575
- return values.slice(0, 1e3).flatMap((tick) => {
4576
- const value = typeof tick === "number" ? tick : tick?.position;
4577
- return Number.isFinite(value) && value >= low && value <= high ? [{ value, label: tick?.label ?? format(value, level) }] : [];
4578
- });
4579
- };
4580
- return { major: collect("major"), minor: collect("minor") };
4581
- }
4582
- ticks(count = 7) {
4583
- return this.tickLayout(this.getPixelLength(), count).major;
4584
- }
4585
- };
4586
- var PolarAxisRadial = class extends Axis {
4587
- constructor(polarChart, options = {}) {
4588
- super(polarChart, "x", options);
4589
- this.polarChart = polarChart;
4590
- }
4591
- tickFormattingFunction = (radians) => `${Math.round(radians * 180 / Math.PI)}\xB0`;
4592
- defaultCursorValueFormat(value) {
4593
- const strategy = this.tickStrategy;
4594
- if (strategy.cursorFormatting || strategy.kind !== "numeric") return super.defaultCursorValueFormat(value);
4595
- const offset = strategy.getFormattingOffset(), degrees = offset === void 0 ? value : value + offset;
4596
- return Number.isFinite(degrees) ? degrees.toFixed(0) : String(degrees);
4597
- }
4598
- setNorth(degrees) {
4599
- if (!Number.isFinite(degrees)) throw new RangeError("North angle must be finite");
4600
- this.polarChart.setAngleOrigin(90 - (this.polarChart.getClockwise() ? -degrees : degrees));
4601
- return this;
4602
- }
4603
- getNorth(_unused) {
4604
- const angle = (90 - this.polarChart.getAngleOrigin()) * (this.polarChart.getClockwise() ? -1 : 1);
4605
- return angle === 0 ? 0 : angle;
4606
- }
4607
- setClockwise(value) {
4608
- const north = this.getNorth();
4609
- this.polarChart.setClockwise(value);
4610
- return this.setNorth(north);
4611
- }
4612
- getClockwise() {
4613
- return this.polarChart.getClockwise();
4614
- }
4615
- setTickStyle(value) {
4616
- this.tickStrategy.setMajorTickStyle(value);
4617
- return this;
4618
- }
4619
- getTickStyle() {
4620
- return this.tickStrategy.getMajorTickStyle();
4621
- }
4622
- setTickFormattingFunction(value) {
4623
- if (typeof value !== "function") throw new TypeError("Polar tick formatter must be a function");
4624
- this.tickFormattingFunction = value;
4625
- this.chart.invalidate();
4626
- return this;
4627
- }
4628
- getTickFormattingFunction() {
4629
- return this.tickFormattingFunction;
4630
- }
4631
- };
4632
-
4633
- // src/data-order.ts
4634
- var caches = /* @__PURE__ */ new WeakMap();
4635
- function resetContent(state) {
4636
- state.epoch = -1;
4637
- state.first = 0;
4638
- state.next = 0;
4639
- state.lastIndex = -1;
4640
- state.lastValue = NaN;
4641
- state.invalid = -1;
4642
- state.decrease = -1;
4643
- state.nonIncrease = -1;
4644
- state.lastScanned = 0;
4645
- state.lastFast = 0;
4646
- state.lastEndpoints = 0;
4647
- }
4648
- function createState() {
4649
- return {
4650
- epoch: -1,
4651
- first: 0,
4652
- next: 0,
4653
- lastIndex: -1,
4654
- lastValue: NaN,
4655
- invalid: -1,
4656
- decrease: -1,
4657
- nonIncrease: -1,
4658
- scanned: 0,
4659
- lastScanned: 0,
4660
- fast: 0,
4661
- lastFast: 0,
4662
- endpoints: 0,
4663
- lastEndpoints: 0,
4664
- cacheHits: 0,
4665
- rebuilds: 0
4666
- };
4667
- }
4668
- function cacheFor(dataSet) {
4669
- let cache = caches.get(dataSet);
4670
- if (!cache) {
4671
- cache = { epoch: dataSet.getContentEpoch(), columns: /* @__PURE__ */ new Map() };
4672
- caches.set(dataSet, cache);
4673
- const owned2 = cache;
4674
- dataSet.onChange((current) => {
4675
- if (current.isDisposed()) {
4676
- owned2.columns.clear();
4677
- caches.delete(current);
4678
- return;
4679
- }
4680
- const epoch = current.getContentEpoch();
4681
- if (owned2.epoch !== epoch) {
4682
- for (const state of owned2.columns.values()) resetContent(state);
4683
- owned2.epoch = epoch;
4684
- }
4685
- });
4686
- }
4687
- return cache;
4688
- }
4689
- function accept(state, index, value, first) {
4690
- if (!Number.isFinite(value)) state.invalid = index;
4691
- if (index > first && state.lastIndex === index - 1) {
4692
- if (value < state.lastValue) state.decrease = index;
4693
- if (value <= state.lastValue) state.nonIncrease = index;
4694
- }
4695
- state.lastValue = value;
4696
- state.lastIndex = index;
4697
- }
4698
- function certifiedIncreasing(run, firstOffset, lastOffset, a, b) {
4699
- if (!(run.step > 0) || !Number.isFinite(run.step) || !Number.isFinite(run.start) || !Number.isFinite(a) || !Number.isFinite(b) || !(b > a)) return false;
4700
- const magnitude = Math.max(Math.abs(run.start), Math.abs(firstOffset * run.step), Math.abs(lastOffset * run.step), Math.abs(a), Math.abs(b));
4701
- const separation = magnitude * Number.EPSILON * 8 + Number.MIN_VALUE * 8;
4702
- return run.step > separation;
4703
- }
4704
- function scanAffine(state, view, from, next) {
4705
- let low = view.runStart, high = view.runs.length;
4706
- while (low < high) {
4707
- const middle = low + Math.floor((high - low) / 2), run = view.runs[middle];
4708
- if (run.firstIndex + run.count <= from) low = middle + 1;
4709
- else high = middle;
4710
- }
4711
- for (let r = low; r < view.runs.length; r++) {
4712
- const run = view.runs[r], first = Math.max(from, run.firstIndex), end = Math.min(next, run.firstIndex + run.count);
4713
- if (first >= end) continue;
4714
- if (end - first > 1) {
4715
- const firstOffset = first - run.firstIndex, lastOffset = end - 1 - run.firstIndex;
4716
- const a = run.start + firstOffset * run.step, b = run.start + lastOffset * run.step;
4717
- state.endpoints += 2;
4718
- state.lastEndpoints += 2;
4719
- if (certifiedIncreasing(run, firstOffset, lastOffset, a, b)) {
4720
- accept(state, first, a, view.firstIndex);
4721
- state.lastIndex = end - 1;
4722
- state.lastValue = b;
4723
- state.fast += end - first;
4724
- state.lastFast += end - first;
4725
- continue;
4726
- }
4902
+ return measure?.(text, level) ?? text.length * this.tickStrategy[level].getLabelFont().getSize() * 0.6;
4903
+ }));
4904
+ const minorFill = this.tickStrategy.minor.getLabelFillStyle(), minorTextVisible = minorFill?.kind !== "empty" && (minorFill?.getColor?.()?.a ?? 1) > 0;
4905
+ automatic.minor = minorTextVisible ? timeTickPositions(start, end, axisSizePixels, intervalCount, { majorLabelWidth: width(automatic.major, "major"), minorLabelWidth: width(minorCandidates, "minor") }).minor : minorCandidates;
4727
4906
  }
4728
- for (let index = first; index < end; index++) accept(state, index, run.start + (index - run.firstIndex) * run.step, view.firstIndex);
4729
- state.scanned += end - first;
4730
- state.lastScanned += end - first;
4907
+ const collect = (level) => {
4908
+ const placement = level === "major" ? this.tickStrategy.customMajor : this.tickStrategy.customMinor;
4909
+ const customPixels = placement ? this.chart.getAxisCustomTickPlacementPixelLength?.(this) : void 0;
4910
+ const values = placement ? placement({ interval: { start, end }, axisSizePixels: customPixels ?? axisSizePixels }) : automatic[level];
4911
+ if (!Array.isArray(values)) return [];
4912
+ return values.slice(0, 1e3).flatMap((tick) => {
4913
+ const value = typeof tick === "number" ? tick : tick?.position;
4914
+ return Number.isFinite(value) && value >= low && value <= high ? [{ value, label: tick?.label ?? format(value, level) }] : [];
4915
+ });
4916
+ };
4917
+ return { major: collect("major"), minor: collect("minor") };
4731
4918
  }
4732
- }
4733
- function result(state, first, next, epoch) {
4734
- const finite2 = state.invalid < first;
4735
- return {
4736
- finite: finite2,
4737
- monotonic: finite2 && state.decrease <= first,
4738
- strict: finite2 && state.nonIncrease <= first,
4739
- sampleCount: next - first,
4740
- firstIndex: first,
4741
- nextIndex: next,
4742
- contentEpoch: epoch,
4743
- lastInvalidPointIndex: state.invalid,
4744
- lastDecreaseEdgeIndex: state.decrease,
4745
- lastNonIncreaseEdgeIndex: state.nonIncrease,
4746
- scannedSamples: state.scanned,
4747
- lastScannedSamples: state.lastScanned,
4748
- affineFastSamples: state.fast,
4749
- lastAffineFastSamples: state.lastFast,
4750
- affineEndpointEvaluations: state.endpoints,
4751
- lastAffineEndpointEvaluations: state.lastEndpoints,
4752
- cacheHits: state.cacheHits,
4753
- rebuilds: state.rebuilds
4754
- };
4755
- }
4756
- function getColumnOrder(dataSet, name) {
4757
- if (!(dataSet.hasColumn?.(name) ?? Object.prototype.hasOwnProperty.call(dataSet.schema, name))) throw new RangeError(`Unknown data column: ${name}`);
4758
- const epoch = dataSet.getContentEpoch(), next = dataSet.getNextSampleIndex(), first = next - dataSet.getSampleCount();
4759
- if (dataSet.isDisposed()) return result(createState(), first, next, epoch);
4760
- const cache = cacheFor(dataSet);
4761
- let state = cache.columns.get(name);
4762
- if (!state) {
4763
- state = createState();
4764
- cache.columns.set(name, state);
4919
+ ticks(count = 7) {
4920
+ return this.tickLayout(this.getPixelLength(), count).major;
4765
4921
  }
4766
- state.lastScanned = 0;
4767
- state.lastFast = 0;
4768
- state.lastEndpoints = 0;
4769
- if (state.epoch === epoch && state.first === first && state.next === next) {
4770
- state.cacheHits++;
4771
- return result(state, first, next, epoch);
4922
+ };
4923
+ var PolarAxisRadial = class extends Axis {
4924
+ constructor(polarChart, options = {}) {
4925
+ super(polarChart, "x", options);
4926
+ this.polarChart = polarChart;
4772
4927
  }
4773
- if (state.epoch !== epoch || next < state.next || first < state.first) {
4774
- resetContent(state);
4775
- state.rebuilds++;
4928
+ tickFormattingFunction = (radians) => `${Math.round(radians * 180 / Math.PI)}\xB0`;
4929
+ defaultCursorValueFormat(value) {
4930
+ const strategy = this.tickStrategy;
4931
+ if (strategy.cursorFormatting || strategy.kind !== "numeric") return super.defaultCursorValueFormat(value);
4932
+ const offset = strategy.getFormattingOffset(), degrees = offset === void 0 ? value : value + offset;
4933
+ return Number.isFinite(degrees) ? degrees.toFixed(0) : String(degrees);
4776
4934
  }
4777
- const from = Math.max(first, state.next);
4778
- if (from < next) {
4779
- const view = dataSet.getColumnRuns(name);
4780
- if (view.kind === "affine") scanAffine(state, view, from, next);
4781
- else if (view.kind === "paged") {
4782
- const cursor = new PagedColumnCursor(view, from);
4783
- while (cursor.values) {
4784
- const values = cursor.values, base = cursor.absoluteIndex - cursor.offset;
4785
- for (let i = cursor.offset, end = i + cursor.length; i < end; i++) accept(state, base + i, values[i], first);
4786
- cursor.next();
4787
- }
4788
- state.scanned += next - from;
4789
- state.lastScanned += next - from;
4790
- } else {
4791
- let absolute = view.firstIndex;
4792
- for (const values of view.slices) {
4793
- const start = Math.max(0, from - absolute);
4794
- for (let i = start; i < values.length; i++) accept(state, absolute + i, values[i], first);
4795
- absolute += values.length;
4796
- }
4797
- state.scanned += next - from;
4798
- state.lastScanned += next - from;
4799
- }
4935
+ setNorth(degrees) {
4936
+ if (!Number.isFinite(degrees)) throw new RangeError("North angle must be finite");
4937
+ this.polarChart.setAngleOrigin(90 - (this.polarChart.getClockwise() ? -degrees : degrees));
4938
+ return this;
4800
4939
  }
4801
- state.epoch = epoch;
4802
- state.first = first;
4803
- state.next = next;
4804
- return result(state, first, next, epoch);
4805
- }
4806
- var finiteCaches = /* @__PURE__ */ new WeakMap();
4807
- function getColumnFinite(dataSet, name) {
4808
- if (!(dataSet.hasColumn?.(name) ?? Object.prototype.hasOwnProperty.call(dataSet.schema, name))) throw new RangeError(`Unknown data column: ${name}`);
4809
- const epoch = dataSet.getContentEpoch(), next = dataSet.getNextSampleIndex(), first = next - dataSet.getSampleCount();
4810
- const expected2 = { revision: dataSet.revision, epoch, first, next };
4811
- let columns = finiteCaches.get(dataSet);
4812
- if (!columns && !dataSet.isDisposed()) {
4813
- columns = /* @__PURE__ */ new Map();
4814
- finiteCaches.set(dataSet, columns);
4815
- const owned2 = columns;
4816
- dataSet.onChange((current) => {
4817
- if (current.isDisposed()) {
4818
- owned2.clear();
4819
- finiteCaches.delete(current);
4820
- }
4821
- });
4940
+ getNorth(_unused) {
4941
+ const angle = (90 - this.polarChart.getAngleOrigin()) * (this.polarChart.getClockwise() ? -1 : 1);
4942
+ return angle === 0 ? 0 : angle;
4822
4943
  }
4823
- let state = columns?.get(name);
4824
- if (!state) {
4825
- state = { invalid: -1, scanned: 0, fullScans: 0, incrementalScans: 0, cacheHits: 0 };
4826
- columns?.set(name, state);
4944
+ setClockwise(value) {
4945
+ const north = this.getNorth();
4946
+ this.polarChart.setClockwise(value);
4947
+ return this.setNorth(north);
4827
4948
  }
4828
- const before = readSourceCertificate(dataSet, expected2);
4829
- const delta = !before?.tainted && state.certificate ? certifySourceDelta(dataSet, state.certificate, expected2).delta : void 0;
4830
- state.certificate = void 0;
4831
- let from = first, scanned = 0;
4832
- if (delta) {
4833
- from = Math.max(first, delta.previous.next);
4834
- if (delta.kind === "unchanged") state.cacheHits++;
4835
- else state.incrementalScans++;
4836
- } else {
4837
- state.invalid = -1;
4838
- state.fullScans++;
4949
+ getClockwise() {
4950
+ return this.polarChart.getClockwise();
4839
4951
  }
4840
- if (from < next && !dataSet.isDisposed()) {
4841
- const view = dataSet.getColumnRuns(name);
4842
- if (view.firstIndex !== first || view.count !== next - first) throw new RangeError("Finite source does not cover the retained window");
4843
- if (view.kind === "dense") {
4844
- let absolute = first;
4845
- for (const values of view.slices) {
4846
- const start = Math.max(0, from - absolute), end = Math.min(values.length, next - absolute);
4847
- for (let i = start; i < end; i++) if (!Number.isFinite(values[i])) state.invalid = absolute + i;
4848
- scanned += Math.max(0, end - start);
4849
- absolute += values.length;
4850
- }
4851
- } else if (view.kind === "paged") {
4852
- for (let index = from; index < next; ) {
4853
- const pageIndex = Math.floor(index / view.pageSize), base = pageIndex * view.pageSize;
4854
- const values = view.getPage(pageIndex), end = Math.min(next, base + view.pageSize);
4855
- for (; index < end; index++) {
4856
- if (!Number.isFinite(values?.[index - base])) state.invalid = index;
4857
- scanned++;
4858
- }
4859
- }
4860
- } else {
4861
- for (let r = view.runStart; r < view.runs.length; r++) {
4862
- const run = view.runs[r], begin = Math.max(from, run.firstIndex), end = Math.min(next, run.firstIndex + run.count);
4863
- for (let index = begin; index < end; index++) if (!Number.isFinite(run.start + (index - run.firstIndex) * run.step)) state.invalid = index;
4864
- scanned += Math.max(0, end - begin);
4865
- }
4866
- }
4867
- if (scanned !== next - from) throw new RangeError("Finite source omitted retained values");
4952
+ setTickStyle(value) {
4953
+ this.tickStrategy.setMajorTickStyle(value);
4954
+ return this;
4868
4955
  }
4869
- state.scanned += scanned;
4870
- const after = readSourceCertificate(dataSet, expected2);
4871
- const verifiedCurrent = dataSet.revision === expected2.revision && dataSet.getContentEpoch() === epoch && dataSet.getNextSampleIndex() === next && dataSet.getSampleCount() === next - first && before === after;
4872
- state.certificate = verifiedCurrent && after && !after.tainted ? after : void 0;
4873
- return {
4874
- finite: verifiedCurrent && state.invalid < first,
4875
- verifiedCurrent,
4876
- sampleCount: next - first,
4877
- firstIndex: first,
4878
- nextIndex: next,
4879
- contentEpoch: epoch,
4880
- lastInvalidPointIndex: state.invalid,
4881
- scannedSamples: state.scanned,
4882
- lastScannedSamples: scanned,
4883
- fullScans: state.fullScans,
4884
- incrementalScans: state.incrementalScans,
4885
- cacheHits: state.cacheHits
4886
- };
4887
- }
4956
+ getTickStyle() {
4957
+ return this.tickStrategy.getMajorTickStyle();
4958
+ }
4959
+ setTickFormattingFunction(value) {
4960
+ if (typeof value !== "function") throw new TypeError("Polar tick formatter must be a function");
4961
+ this.tickFormattingFunction = value;
4962
+ this.chart.invalidate();
4963
+ return this;
4964
+ }
4965
+ getTickFormattingFunction() {
4966
+ return this.tickFormattingFunction;
4967
+ }
4968
+ };
4888
4969
 
4889
4970
  // src/line-extrema-pair-proof.ts
4890
4971
  var issued2 = /* @__PURE__ */ new WeakSet();
@@ -7872,7 +7953,8 @@ var CRYChart = (() => {
7872
7953
  yValues: { storage: Float64Array },
7873
7954
  ...this.axisZ ? { zValues: { storage: Float64Array } } : {}
7874
7955
  },
7875
- includesNaN: options.includesNaN
7956
+ includesNaN: options.includesNaN,
7957
+ columnStorage: options.columnStorage
7876
7958
  });
7877
7959
  const keys = Object.keys(this.dataSet.schema);
7878
7960
  const implicitX = keys.length === 1 && !this.axisZ && keys[0] !== "x" && keys[0] !== "xValues";
@@ -15681,6 +15763,38 @@ void main(){
15681
15763
  this.frameState = this.saveState();
15682
15764
  this.capturedFrameActive = true;
15683
15765
  }
15766
+ /** Shared-context all-coverage batch after SharedWebGLContext established its
15767
+ * exact clean default-target baseline: avoids 28 synchronous GL state queries
15768
+ * while preserving identical restoreState semantics for both draw and frame scopes. */
15769
+ beginKnownCapturedFrame(program, viewport) {
15770
+ if (this.disposed || this.frameState) throw new Error("Captured coverage frame requires a fresh frame");
15771
+ const gl = this.gl;
15772
+ this.frameState = {
15773
+ drawFramebuffer: null,
15774
+ readFramebuffer: null,
15775
+ viewport: Int32Array.from(viewport),
15776
+ scissor: Int32Array.from(viewport),
15777
+ clearColor: new Float32Array(4),
15778
+ colorMask: [true, true, true, true],
15779
+ program,
15780
+ vao: null,
15781
+ arrayBuffer: null,
15782
+ activeTexture: gl.TEXTURE0,
15783
+ texture0: null,
15784
+ sampler0: null,
15785
+ enabled: [[gl.SCISSOR_TEST, true], [gl.BLEND, true], [gl.DEPTH_TEST, false], [gl.STENCIL_TEST, false], [gl.CULL_FACE, false], [gl.RASTERIZER_DISCARD, false], [gl.SAMPLE_ALPHA_TO_COVERAGE, false], [gl.SAMPLE_COVERAGE, false], [gl.DITHER, true]],
15786
+ blendSourceRGB: gl.SRC_ALPHA,
15787
+ blendSourceAlpha: gl.ONE,
15788
+ blendDestinationRGB: gl.ONE_MINUS_SRC_ALPHA,
15789
+ blendDestinationAlpha: gl.ONE_MINUS_SRC_ALPHA,
15790
+ blendEquationRGB: gl.FUNC_ADD,
15791
+ blendEquationAlpha: gl.FUNC_ADD
15792
+ };
15793
+ this.capturedFrameActive = true;
15794
+ this.ownedMaskStateReady = false;
15795
+ this.knownFrameActive = true;
15796
+ this.stats.knownFrameBaselines++;
15797
+ }
15684
15798
  /** Internal capability, only after DataRenderer established this exact private
15685
15799
  * default-target baseline. Standalone draw()/frame users keep full capture.
15686
15800
  * This record is ephemeral and cleared by every flush/end/context/dispose. */
@@ -16188,6 +16302,10 @@ void main(){
16188
16302
  if (!this.coverage) throw new Error("Captured frame requires coverage rendering");
16189
16303
  this.coverage.beginCapturedFrame();
16190
16304
  }
16305
+ beginKnownCapturedCoverageFrame(program, viewport) {
16306
+ if (!this.coverage) throw new Error("Captured frame requires coverage rendering");
16307
+ this.coverage.beginKnownCapturedFrame(program, viewport);
16308
+ }
16191
16309
  canDraw(packet) {
16192
16310
  if (this.coverage) return this.coverage.canDraw(packet);
16193
16311
  return !this.disposed && packet.strictlyMonotonicX === true && packet.mode === "line" && packet.dimensions === 2 && packet.count >= 2 && packet.thickness > 0 && !packet.colors && !packet.dashPattern?.length && packet.positions.length >= packet.count * 2;
@@ -16471,6 +16589,7 @@ void main(){
16471
16589
  disposed = false;
16472
16590
  maxVertexAttribs = 0;
16473
16591
  pendingPresent;
16592
+ baselineClean = false;
16474
16593
  chartDraws = 0;
16475
16594
  blits = 0;
16476
16595
  backingResizes = 0;
@@ -16478,9 +16597,11 @@ void main(){
16478
16597
  contextRestores = 0;
16479
16598
  onLost = (event) => {
16480
16599
  event.preventDefault();
16600
+ this.baselineClean = false;
16481
16601
  this.contextLosses++;
16482
16602
  };
16483
16603
  onRestore = () => {
16604
+ this.baselineClean = false;
16484
16605
  this.contextRestores++;
16485
16606
  };
16486
16607
  constructor(options) {
@@ -16508,6 +16629,7 @@ void main(){
16508
16629
  this.cullOffscreen = options?.cullOffscreen !== false;
16509
16630
  }
16510
16631
  acquire() {
16632
+ this.baselineClean = false;
16511
16633
  if (this.disposed) return null;
16512
16634
  if (this.attempted) return this.gl;
16513
16635
  this.attempted = true;
@@ -16613,12 +16735,20 @@ void main(){
16613
16735
  gl.clearColor(0, 0, 0, 0);
16614
16736
  gl.clear(gl.COLOR_BUFFER_BIT);
16615
16737
  this.pendingPresent = { width, height };
16738
+ this.baselineClean = true;
16616
16739
  this.chartDraws++;
16617
16740
  return true;
16618
16741
  }
16742
+ /** Consume the clean baseline established by beginChartDraw() for the first drawGPU() in this chart frame. */
16743
+ consumeCleanBaseline() {
16744
+ if (!this.baselineClean || this.disposed || !this.pendingPresent) return false;
16745
+ this.baselineClean = false;
16746
+ return true;
16747
+ }
16619
16748
  present(target, pixelWidth, pixelHeight) {
16620
16749
  const pending = this.pendingPresent;
16621
16750
  this.pendingPresent = void 0;
16751
+ this.baselineClean = false;
16622
16752
  const width = Math.max(1, Math.round(pixelWidth));
16623
16753
  const height = Math.max(1, Math.round(pixelHeight));
16624
16754
  if (!pending || !target || !this.canvas || pending.width !== width || pending.height !== height) {
@@ -16637,6 +16767,7 @@ void main(){
16637
16767
  if (this.disposed) return;
16638
16768
  this.disposed = true;
16639
16769
  this.pendingPresent = void 0;
16770
+ this.baselineClean = false;
16640
16771
  this.observer?.disconnect();
16641
16772
  this.observer = void 0;
16642
16773
  this.observedRoots.clear();
@@ -17169,8 +17300,12 @@ void main(){
17169
17300
  const gl = this.gl;
17170
17301
  const owned2 = this.canUseKnownOwnedFrame(packets, clear, this.gpuClipPolicy === "contained" && rasterTarget?.framebuffer !== null);
17171
17302
  if (owned2 && !this.lineStrip) this.lineStrip = new LineStripRenderer(gl, { coverageUnion: true, coverageStateScope: "frame", clipPolicy: this.gpuClipPolicy });
17172
- const coverageBatch = !owned2 && !rasterTarget && packets.length > 0 && packets.every((p) => p.strictlyMonotonicX === true && p.mode === "line" && p.dimensions === 2 && Number.isSafeInteger(p.count) && p.count >= 2 && p.positions.length >= p.count * 2 && Number.isFinite(p.thickness) && p.thickness > 0 && !p.colors && !p.dashPattern?.length && !p.pointSizes && !p.pointRotations) && gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING) === null;
17173
- if (coverageBatch && !this.lineStrip) this.lineStrip = new LineStripRenderer(gl, { coverageUnion: this.lineCoverageUnion, coverageStateScope: this.lineCoverageStateScope, clipPolicy: this.gpuClipPolicy });
17303
+ const sharedBaselineWasClean = this.sharedContext !== void 0 ? sharedContextCore(this.sharedContext).consumeCleanBaseline() : false;
17304
+ const sharedCleanBaseline = !owned2 && !rasterTarget && clear && sharedBaselineWasClean;
17305
+ const compatibleCoveragePackets = !owned2 && !rasterTarget && packets.length > 0 && packets.every((p) => p.strictlyMonotonicX === true && p.mode === "line" && p.dimensions === 2 && Number.isSafeInteger(p.count) && p.count >= 2 && p.positions.length >= p.count * 2 && Number.isFinite(p.thickness) && p.thickness > 0 && !p.colors && !p.dashPattern?.length && !p.pointSizes && !p.pointRotations);
17306
+ const sharedKnownCoverageBatch = sharedCleanBaseline && compatibleCoveragePackets;
17307
+ const coverageBatch = !sharedKnownCoverageBatch && compatibleCoveragePackets && gl.getParameter(gl.DRAW_FRAMEBUFFER_BINDING) === null;
17308
+ if ((sharedKnownCoverageBatch || coverageBatch) && !this.lineStrip) this.lineStrip = new LineStripRenderer(gl, { coverageUnion: this.lineCoverageUnion, coverageStateScope: this.lineCoverageStateScope, clipPolicy: this.gpuClipPolicy });
17174
17309
  const stripBefore = { uploads: this.lineStrip?.stats.uploads ?? 0, bytes: this.lineStrip?.stats.uploadedBytes ?? 0 };
17175
17310
  this.lineStrip?.beginFrame();
17176
17311
  let frameEnded = false;
@@ -17198,6 +17333,10 @@ void main(){
17198
17333
  gl.uniform2f(this.uniforms.plotOrigin, x, y);
17199
17334
  gl.uniform1f(this.uniforms.dpr, dpr);
17200
17335
  if (owned2) this.lineStrip.beginKnownOwnedFrame(this.program, [x, y, w, h]);
17336
+ else if (sharedKnownCoverageBatch) {
17337
+ this.lineStrip.beginKnownCapturedCoverageFrame(this.program, [x, y, w, h]);
17338
+ capturedCoverageBatch = true;
17339
+ }
17201
17340
  let clipX = x, clipY = y, clipW = w, clipH = h;
17202
17341
  const live = /* @__PURE__ */ new Set();
17203
17342
  const liveAttributes = /* @__PURE__ */ new Set();
@@ -20306,30 +20445,73 @@ void main() {
20306
20445
  // src/axis-canvas.ts
20307
20446
  var color = (fill, fallback) => fill?.kind === "empty" ? ColorRGBA(0, 0, 0, 0) : fill?.getColor?.() ?? fallback;
20308
20447
  var validFont = (font2) => font2.toCSS?.() ?? `${font2.getSize()}px sans-serif`;
20448
+ var TEXT_METRICS_CACHE_MAX = 1024;
20449
+ var fontCacheEpoch = 0;
20450
+ var fontCacheListening = false;
20451
+ var persistentTextCaches = /* @__PURE__ */ new WeakMap();
20452
+ function ensureFontCacheListener() {
20453
+ if (fontCacheListening) return;
20454
+ try {
20455
+ const fonts = globalThis.document?.fonts;
20456
+ if (typeof fonts?.addEventListener === "function") {
20457
+ fonts.addEventListener("loadingdone", () => {
20458
+ fontCacheEpoch++;
20459
+ });
20460
+ fontCacheListening = true;
20461
+ }
20462
+ } catch {
20463
+ }
20464
+ }
20465
+ function getAxisTextMetricsCache(ctx) {
20466
+ if (!ctx) return void 0;
20467
+ ensureFontCacheListener();
20468
+ let entry = persistentTextCaches.get(ctx);
20469
+ if (!entry || entry.epoch !== fontCacheEpoch) {
20470
+ entry = { epoch: fontCacheEpoch, map: /* @__PURE__ */ new Map() };
20471
+ persistentTextCaches.set(ctx, entry);
20472
+ } else if (entry.map.size >= TEXT_METRICS_CACHE_MAX) {
20473
+ entry.map.clear();
20474
+ }
20475
+ return entry.map;
20476
+ }
20309
20477
  var lineBoxHeight = (font2) => font2.getSize() * 0.8;
20310
20478
  function lineBoxBaseline(metrics2, font2) {
20311
20479
  const size = font2.getSize();
20312
20480
  return ((metrics2?.fontBoundingBoxAscent ?? size * 0.8) - (metrics2?.fontBoundingBoxDescent ?? size * 0.2)) / 2;
20313
20481
  }
20314
- function textMetrics(ctx, text, font2, cache) {
20315
- const key = validFont(font2) + "\0" + text, cached = cache?.get(key);
20482
+ function textMetrics(ctx, text, font2, cache, align) {
20483
+ const fontCss = validFont(font2);
20484
+ const key = fontCss + "\0" + (align ?? "") + "\0" + text, cached = cache?.get(key);
20316
20485
  if (cached) return cached;
20317
- const previous = ctx?.font, previousBaseline = ctx?.textBaseline;
20318
- if (ctx) {
20319
- ctx.font = validFont(font2);
20320
- ctx.textBaseline = "alphabetic";
20321
- }
20486
+ const previous = ctx?.font, previousBaseline = ctx?.textBaseline, previousAlign = ctx?.textAlign;
20322
20487
  let measured;
20323
20488
  try {
20489
+ if (ctx) {
20490
+ ctx.font = fontCss;
20491
+ ctx.textBaseline = "alphabetic";
20492
+ if (align !== void 0) ctx.textAlign = align;
20493
+ }
20324
20494
  measured = ctx?.measureText?.(text);
20325
20495
  } finally {
20326
20496
  if (ctx) {
20327
20497
  if (previous !== void 0) ctx.font = previous;
20328
20498
  if (previousBaseline !== void 0) ctx.textBaseline = previousBaseline;
20499
+ if (align !== void 0 && previousAlign !== void 0) ctx.textAlign = previousAlign;
20329
20500
  }
20330
20501
  }
20331
- const result2 = { width: measured?.width ?? text.length * font2.getSize() * 0.6, ascent: measured?.actualBoundingBoxAscent ?? font2.getSize() * 0.75, descent: measured?.actualBoundingBoxDescent ?? font2.getSize() * 0.25, baseline: lineBoxBaseline(measured, font2) };
20332
- cache?.set(key, result2);
20502
+ const result2 = {
20503
+ width: measured?.width ?? text.length * font2.getSize() * 0.6,
20504
+ ascent: measured?.actualBoundingBoxAscent ?? font2.getSize() * 0.75,
20505
+ descent: measured?.actualBoundingBoxDescent ?? font2.getSize() * 0.25,
20506
+ baseline: lineBoxBaseline(measured, font2),
20507
+ actualBoundingBoxAscent: measured?.actualBoundingBoxAscent,
20508
+ actualBoundingBoxDescent: measured?.actualBoundingBoxDescent,
20509
+ ...align !== void 0 ? { actualBoundingBoxLeft: measured?.actualBoundingBoxLeft, actualBoundingBoxRight: measured?.actualBoundingBoxRight } : {}
20510
+ };
20511
+ if (cache) {
20512
+ if (cache.size >= TEXT_METRICS_CACHE_MAX) cache.clear();
20513
+ cache.set(key, result2);
20514
+ }
20333
20515
  return result2;
20334
20516
  }
20335
20517
  function measureChartTitleContent(ctx, text, font2, dpr = 1) {
@@ -20413,9 +20595,9 @@ void main() {
20413
20595
  const laneSize = extent > 0 ? Math.ceil(extent + (horizontal ? 2 : 4)) : 0;
20414
20596
  return { measured: true, labelFont, titleFont, lane: 0, laneOffset: 0, laneSize, labelOffset, titleOffset, tickLength, labelWidth, labelAscent, labelDescent, titleWidth: title.width, titleAscent: title.ascent, titleDescent: title.descent, rotation };
20415
20597
  }
20416
- function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont) {
20598
+ function measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, persistentCache) {
20417
20599
  const result2 = { contentMargins: { left: 0, right: 0, top: 0, bottom: 0 }, extraMargins: { left: 0, right: 0, top: 0, bottom: 0 }, axes: /* @__PURE__ */ new Map() };
20418
- const textCache = /* @__PURE__ */ new Map();
20600
+ const textCache = persistentCache ?? /* @__PURE__ */ new Map();
20419
20601
  for (const [horizontal, list] of [[true, axesX], [false, axesY]]) for (const opposite of [false, true]) {
20420
20602
  const groups = /* @__PURE__ */ new Map();
20421
20603
  for (const axis of list) if (axis.visible && !axis.disposed && axis.opposite === opposite) {
@@ -20490,14 +20672,15 @@ void main() {
20490
20672
  }
20491
20673
  }
20492
20674
  function drawAxisCanvas(ctx, options) {
20493
- const { plot: r, axesX, axesY, light = false, theme, resolveFont } = options, layout = options.layout ?? measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont);
20675
+ const textCache = getAxisTextMetricsCache(ctx);
20676
+ const { plot: r, axesX, axesY, light = false, theme, resolveFont } = options, layout = options.layout ?? measureAxisCanvasLayout(ctx, axesX, axesY, theme, resolveFont, textCache);
20494
20677
  const baselines = [];
20495
20678
  ctx.save();
20496
20679
  try {
20497
20680
  ctx.textBaseline = "alphabetic";
20498
20681
  for (const axis of [...axesX, ...axesY]) {
20499
20682
  if (!axis.visible || axis.disposed) continue;
20500
- const m = layout.axes.get(axis) ?? metrics(axis, ctx, void 0, theme, resolveFont), horizontal = axis.direction === "x", outward = axis.opposite ? horizontal ? -1 : 1 : horizontal ? 1 : -1;
20683
+ const m = layout.axes.get(axis) ?? metrics(axis, ctx, textCache, theme, resolveFont), horizontal = axis.direction === "x", outward = axis.opposite ? horizontal ? -1 : 1 : horizontal ? 1 : -1;
20501
20684
  const linePosition = horizontal ? axis.opposite ? r.top - m.laneOffset : r.top + r.height + m.laneOffset : axis.opposite ? r.left + r.width + m.laneOffset : r.left - m.laneOffset;
20502
20685
  const range = axis.getScreenRange(), axisLength = Math.abs(range.end - range.start) * (horizontal ? r.width : r.height), strategy = axis.tickStrategy;
20503
20686
  const lineFrom = horizontal ? { x: r.left + range.start * r.width, y: linePosition } : { x: linePosition, y: r.top + (1 - range.start) * r.height };
@@ -20512,7 +20695,7 @@ void main() {
20512
20695
  if (options.paintFrame) {
20513
20696
  if (axis.stroke?.getThickness?.() > 0) baselines.push({ stroke: axis.stroke, from: lineFrom, to: lineTo });
20514
20697
  } else paintStroke(ctx, axis.stroke, lineFrom, lineTo);
20515
- const ticks = measuredTickLayout(axis, ctx, axisLength, strategy.kind === "datetime" || strategy.kind === "time" ? /* @__PURE__ */ new Map() : void 0, theme, resolveFont), labels = [], interval = axis.getInterval();
20698
+ const ticks = measuredTickLayout(axis, ctx, axisLength, textCache, theme, resolveFont), labels = [], interval = axis.getInterval();
20516
20699
  for (const level of ["minor", "major", "great"]) {
20517
20700
  const style = tickStyle(strategy, level);
20518
20701
  if (!style) continue;
@@ -20527,17 +20710,18 @@ void main() {
20527
20710
  const labelFill = resolvedTickFill(axis, level, style, theme, true);
20528
20711
  const labelColor = labelFill !== void 0 ? color(labelFill, ColorRGBA(0, 0, 0, 0)) : light ? ColorRGBA(82, 97, 118) : color(style.getLabelFillStyle(), ColorRGBA(150, 164, 185));
20529
20712
  if (labelColor.a > 0 && tick.label.length) {
20713
+ const align = horizontal ? level === "great" ? "left" : "center" : axis.opposite ? "left" : "right";
20530
20714
  ctx.font = validFont(labelFont);
20531
20715
  ctx.fillStyle = labelColor.toCSS();
20532
- ctx.textAlign = horizontal ? level === "great" ? "left" : "center" : axis.opposite ? "left" : "right";
20533
- const measured = ctx.measureText(tick.label), width = Number.isFinite(measured.width) ? measured.width : 0;
20716
+ ctx.textAlign = align;
20717
+ const measured = textMetrics(ctx, tick.label, labelFont, textCache, align), width = Number.isFinite(measured.width) ? measured.width : 0;
20534
20718
  const anchor = level === "great" && "anchor" in tick ? axis.valueToScreenFraction(tick.anchor) : fraction2;
20535
20719
  const anchorX = horizontal ? r.left + anchor * r.width + (level === "great" ? 2 : 0) : x;
20536
20720
  const anchorY = horizontal ? y : r.top + r.height - anchor * r.height;
20537
20721
  const labelX = horizontal ? boundAxisLabelX(ctx, tick.label, anchorX, lineFrom.x, lineTo.x, measured) : x + outward * m.labelOffset;
20538
20722
  let labelY = anchorY + (horizontal ? outward * m.labelOffset : 4);
20539
20723
  if (m.lineBoxTitleBaseline !== void 0) {
20540
- const baseline = lineBoxBaseline(measured, labelFont), halfLine = lineBoxHeight(labelFont) / 2;
20724
+ const baseline = measured.baseline, halfLine = lineBoxHeight(labelFont) / 2;
20541
20725
  labelY = anchorY + baseline + (horizontal ? outward * (m.labelOffset + halfLine) : 0);
20542
20726
  if (!horizontal) {
20543
20727
  const first = Math.min(lineFrom.y, lineTo.y) + Math.max(halfLine + baseline, measured.actualBoundingBoxAscent ?? labelFont.getSize() * 0.75);
@@ -21815,7 +21999,7 @@ void main() {
21815
21999
  this.prepareCustomTickPlacementLengths(axesX, axesY);
21816
22000
  const layoutAxesX = axesX.filter((axis) => this.hasAxisLaneContent(axis));
21817
22001
  const layoutAxesY = axesY.filter((axis) => this.hasAxisLaneContent(axis));
21818
- this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont) : void 0;
22002
+ this.axisCanvasLayout = this.kind === "xy" ? measureAxisCanvasLayout(this.overlayContext ?? void 0, layoutAxesX, layoutAxesY, this.theme, this.resolveTextFont, getAxisTextMetricsCache(this.overlayContext ?? void 0)) : void 0;
21819
22003
  const axisExtra = this.axisCanvasLayout?.extraMargins ?? { left: 0, right: 0, top: 0, bottom: 0 };
21820
22004
  const legendMargin = this.overlayContext ? this.legend.getLayout(this.overlayContext, this.legendArea()).margin : { left: 0, right: 0, top: 0, bottom: 0 };
21821
22005
  if (this.kind === "polar") {
@@ -25602,7 +25786,7 @@ ${sample.position[0].toFixed(4)}, ${sample.position[1].toFixed(4)}`, contains: (
25602
25786
  getSharedContext: () => shared
25603
25787
  };
25604
25788
  }
25605
- var version = "1.0.7";
25789
+ var version = "1.0.8";
25606
25790
  var Dashboard = class {
25607
25791
  root;
25608
25792
  sharedContext;