Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": 2,
"identity": {
"name": "CRYChart",
"packageVersion": "1.0.1-opentest.29",
"packageVersion": "1.0.1-opentest.30",
"entry": "examples/official/index.html"
},
"count": 167,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crychart",
"version": "1.0.1-opentest.29",
"version": "1.0.1-opentest.30",
"description": "CRYChart chart engine with streaming data, interactive axes and WebGL rendering",
"type": "module",
"main": "./dist/crychart.cjs",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function cryChart(_options: Record<string, unknown> = {}) {
getChartCount: () => owned.size,
};
}
export const version = "1.0.1-opentest.29";
export const version = "1.0.1-opentest.30";
export class Dashboard {
readonly root: HTMLDivElement;
private cells = new Map<any, HTMLDivElement>();
Expand Down
32 changes: 29 additions & 3 deletions src/line-display-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface LineDisplayStats {
reusedTerminalGroups: number;
reusedProjectionSamplesThisUpdate: number;
projectedSamplesThisUpdate: number;
projectionRebasesThisUpdate: number;
selectionDelta?: LedgerWork;
}
export type LineDisplayResult =
Expand Down Expand Up @@ -213,6 +214,10 @@ export class LineDisplayCache {
}

update(request: LineDisplayRequest): LineDisplayResult {
return this.updateProjection(request, true);
}

private updateProjection(request: LineDisplayRequest, allowRebase: boolean): LineDisplayResult {
if (this.disposed) throw new Error('Line display cache is disposed');
const source = request.source, retained = source.nextSampleIndex - source.firstSampleIndex;
const extremaPair = acceptsExtremaPair(request.extremaPairProof,source);
Expand All @@ -223,7 +228,7 @@ export class LineDisplayCache {
const stats: LineDisplayStats = {retainedSourceSamples: retained, requestedSourceSamples: 0, selectedDisplaySamples: 0, submittedDisplaySamples: 0, omittedDisplaySamples: 0,
summaryPages: 0, summaryBytes: 0, selectionBytes: 0, projectionBytes: 0, cachedSelectionBytes: 0, cachedProjectionBytes: 0, cachedTopologyBytes: 0, reusedSelectionPages: 0, sourceSamplesScannedThisUpdate: 0, boundarySamplesScannedThisUpdate: 0,
visitedSummaryNodes: 0, reusedPages: 0, evictedPages: 0, largestSimplifiedPixelSpan: 0, maximumProjectionXError: 0, maximumProjectionYError: 0, sourceReduction: false, displayReduction: false, extremaNeighborsRetained: request.preserveExtremaNeighbors !== false,
reusedTerminalGroups: 0, reusedProjectionSamplesThisUpdate: 0, projectedSamplesThisUpdate: 0};
reusedTerminalGroups: 0, reusedProjectionSamplesThisUpdate: 0, projectedSamplesThisUpdate: 0, projectionRebasesThisUpdate: 0};
const fallback = (reason: Extract<LineDisplayResult, {kind: 'fallback'}>['reason']): LineDisplayResult => {stats.evictedPages += this.pages.size; this.clear(); return {kind: 'fallback', reason, stats};};
if (request.coordinateMode !== 'linear') return fallback('unsupported-transform');
if (retained > 1 && request.monotonicX !== 'verified-strict') return fallback('unverified-x-order');
Expand Down Expand Up @@ -604,8 +609,29 @@ export class LineDisplayCache {
else {for (const page of this.pages.values()) {stats.cachedSelectionBytes += page.selected?.indices.byteLength ?? 0; stats.cachedProjectionBytes += page.selected?.positions.byteLength ?? 0; stats.cachedTopologyBytes += (page.selected?.groups.byteLength ?? 0) + (page.selected?.groupLookup?.byteLength ?? 0);}}
this.state = {identity: source.identity, epoch: source.contentEpoch, binding: request.bindingRevision, projection: selectionPolicyKey, next: source.nextSampleIndex};
if (pageMode) {
// Coverage requires strict projected X. If Float32 relative coordinates
// collapse distinct source X values, atomically use the usual fallback.
// A rolling window can outlive its original projection origin. Recover
// Float32 spacing around the current window before falling back to raw
// geometry. Keep min/max summaries: only display selections/coordinates
// and their GPU/ledger certificates depend on this origin. Re-reading all
// retained source samples here causes periodic stalls at high rates.
if (!strict && allowRebase) {
const center = x(first) / 2 + x(last) / 2;
if (Number.isFinite(center) && center !== origin.x) {
this.origin = {...origin, x: center};
for (const page of this.pages.values()) page.selected = undefined;
this.pagePackets?.clear(); this.arena?.clear(); this.deltaLedger?.clear();
const retry = this.updateProjection(request, false);
retry.stats.projectionRebasesThisUpdate++;
// Preserve actual work counters from both attempts, but publish only
// the accepted projection's errors, allocations and geometry counts.
for (const key of ['sourceSamplesScannedThisUpdate', 'boundarySamplesScannedThisUpdate',
'visitedSummaryNodes', 'projectedSamplesThisUpdate', 'reusedProjectionSamplesThisUpdate',
'reusedTerminalGroups', 'evictedPages'] as const) retry.stats[key] += stats[key];
return retry;
}
}
// Even a centered origin cannot represent every possible source spacing.
// Keep the strict-order safety gate and bound recovery to one attempt.
if (!strict) return fallback('unverified-x-order');
if (arenaMode) {
const template = {strokeGroup: request.strokeGroup ?? this.id, origin: this.origin!, domain: request.domain, clipRect: request.clipRect, thickness: request.style.thickness, color: [...request.style.color] as typeof request.style.color};
Expand Down
52 changes: 52 additions & 0 deletions tests/line-display-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,55 @@ test('independent centerline oracle bounds both directions inside each accepted
}
}
});

for (const mode of ['pages', 'arena'] as const) test(`${mode} projection recovery retains summaries, peaks and gaps and resumes incremental updates`, () => {
const capacity = 192000 * 60, batch = 192000 * 6, step = 1000 / 192000;
const values = (n: number, first: number) => Float64Array.from({length: n}, (_, i) => (first + i) % 8191 === 0 ? NaN : (first + i) % 997 === 0 ? 1 : 0);
const data = new DataSetXY({schema: {x: {storage: Float64Array, auto: true, pattern: 'progressive'}, y: {storage: Float64Array}}});
data.setMaxSampleCount(capacity);
data.appendSamples({y: values(capacity, 0)}, {start: 1811059, step});
const cache = new LineDisplayCache();
const draw = () => display(cache.update({...request(data, {width: 910, audit: false}), strokeGroup: 42,
packetMode: mode, reuseCertifiedPages: true, reuseUnchangedGroups: true, collectSourceIndices: false}));
try {
draw();
data.appendSamples({y: values(batch, capacity)});
const recovered = draw();
assert.equal(recovered.stats.projectionRebasesThisUpdate, 1);
assert.ok(recovered.stats.sourceSamplesScannedThisUpdate <= batch + 32);
assert.ok(recovered.stats.reusedPages > 2500);
assert.ok(recovered.stats.submittedDisplaySamples < 100000);
let sawPeak = false, sawGap = false;
for (const packet of recovered.packets!) for (let i = 0; i < packet.count; i++) {
const rawX = packet.positions[i * 2]! + packet.origin.x;
const absolute = Math.round((rawX - 1811059) / step);
const rawY = data.getValue('y', absolute - batch)!;
const displayedY = packet.positions[i * 2 + 1]! + packet.origin.y;
if (Number.isNaN(rawY)) {assert.ok(Number.isNaN(displayedY)); sawGap = true;}
else {assert.equal(displayedY, rawY); if (rawY === 1) sawPeak = true;}
if (i) assert.ok(packet.positions[i * 2]! > packet.positions[(i - 1) * 2]!);
}
assert.ok(sawPeak && sawGap);
data.appendSamples({y: values(9600, capacity + batch)});
const next = draw();
assert.equal(next.stats.projectionRebasesThisUpdate, 0);
assert.ok(next.stats.sourceSamplesScannedThisUpdate <= 9616);
assert.ok(next.stats.projectedSamplesThisUpdate < 1000);
if (mode === 'arena') {
assert.equal(next.stats.arena!.fullRebuild, false);
assert.ok(next.stats.selectionDelta!.reusedCompletePages > 2500);
}
} finally {cache.dispose(); data.dispose();}
});

test('irreducible Float32 spacing still falls back after one bounded projection recovery', () => {
const data = make(1, {start: 0});
data.appendSamples({y: Float64Array.from({length: 4999}, (_, i) => i % 2)}, {start: 1e12, step: .001});
const cache = new LineDisplayCache();
const result = cache.update({...request(data), strokeGroup: 1, packetMode: 'arena'});
assert.equal(result.kind, 'fallback');
if (result.kind === 'fallback') assert.equal(result.reason, 'unverified-x-order');
assert.equal(result.stats.projectionRebasesThisUpdate, 1);
assert.equal(data.getSampleCount(), 5000);
cache.dispose(); data.dispose();
});
38 changes: 38 additions & 0 deletions tests/line-display-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,41 @@ test('explicit display view preserves ordinary translucent raster and complete s
assert.deepEqual(data.readBack(),before);
}finally{chart.dispose();data.dispose();}
});

// Real Monitor retention and sample spacing. The first projection origin stays
// behind the rolling window until the tail crosses Float32's 2^16-ms boundary.
test('192kHz 60-second rolling waveform keeps display reduction across Float32 origin drift', () => {
const count = 192000 * 60, batch = 192000 * 6, step = 1000 / 192000;
const chart = new ChartXY({experimentalLineDisplayPixels: 1, experimentalLineDisplayPackets: true, experimentalLineCoverage: true});
const data = new DataSetXY({schema: {x: {storage: Float64Array, auto: true, pattern: 'progressive'}, y: {storage: Float64Array}}});
data.setMaxSampleCount(count);
// Isolated peaks retain adjacent samples, including those that collide in
// Float32. Constant data would omit the close neighbors and miss this bug.
const values = (length: number, first = 0) => Float64Array.from({length}, (_, i) => (i + first) % 997 === 0 ? 1 : 0);
data.appendSamples({y: values(count)}, {start: 1811059, step});
const series = chart.addLineSeries({schema: data.schema}).setDataSet(data).setDataMapping({x: 'x', y: 'y'});
series.setStrokeStyle(new SolidLine({thickness: 1, fillStyle: new SolidFill({color: ColorRGBA(30, 200, 170, 255)})}));
chart.getDefaultAxisY().setInterval({start: -0.2, end: 1.2});
try {
let previousOrigin: number | undefined, originChanges = 0;
for (let pass = 0; pass <= 7; pass++) {
if (pass) data.appendSamples({y: values(batch, data.getNextSampleIndex())});
chart.getDefaultAxisX().setInterval({start: data.getValue('x', 0)!, end: data.getValue('x', count - 1)!});
const packets = series.drawLineDisplayPackets(rect, rect, 1.5, 1, true);
const stats = series.getLineDisplayStats();
assert.ok(stats, `pass ${pass}: display cache must not fall back to all ${count} raw samples`);
assert.equal(series.getLineBlockStats(), undefined);
assert.equal(data.getSampleCount(), count);
assert.ok(stats.submittedDisplaySamples < 100000);
if (pass) assert.ok(stats.sourceSamplesScannedThisUpdate <= batch + 32, 'old summary pages must survive a projection rebase');
const origin = packets[0]!.origin.x;
if (previousOrigin !== undefined && previousOrigin !== origin) originChanges++;
previousOrigin = origin;
for (const packet of packets) {
assert.ok(packet.strictlyMonotonicX);
for (let i = 1; i < packet.count; i++) assert.ok(packet.positions[i * 2]! > packet.positions[(i - 1) * 2]!);
}
}
assert.ok(originChanges >= 2, 'exercise repeated origin recovery, not just initial projection');
} finally {chart.dispose(); data.dispose();}
});
Loading