From 2143ea1dbc377719be74594759d5902d6befb008 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Fri, 2 Oct 2026 13:48:44 -0700 Subject: [PATCH 1/3] fix(workflow-form): redraw a result's chart in place, and drop the key that was meant to rebuild it The visualization frame audited before it filtered. An update event carries only the operators whose result changed, so a window that closed on another operator's event was handed that event by the filter and dropped, taking this operator's pending redraw with it: the last update of a run could leave the previous picture showing for good. Filter first. The canvas result panel uses the same frame and gains the same reliability. The Form View keyed each chart frame by a per-operator version, bumped on every result update, meaning to rebuild the frame rather than reuse it. It could not do that. Every visualisation operator takes its whole input before it draws (`process_table`, single-snapshot output), so the update that carries a picture is the one that mounts the frame, and a second one never arrives; measured on a run, the chart's operator sees two updates, one picture and one frame, with the key and without it. A re-run replaces the snapshot inside the operator's result service, which lives until the page is left, so there is no new frame to key on there either. The machinery never fired, so it goes. No visible change: this fixes a latent ordering bug and removes code that cannot run. Closes #8759 Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01FVvP3ttj22f9LB4p9u2anY --- ...ualization-frame-content.component.spec.ts | 18 +++++++++ .../visualization-frame-content.component.ts | 9 +++-- .../workflow-form.component.html | 12 +++--- .../workflow-form.component.spec.ts | 22 +++++------ .../workflow-form/workflow-form.component.ts | 38 +++++++------------ 5 files changed, 53 insertions(+), 46 deletions(-) diff --git a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts index 9027bb36da8..a9fbe74c4be 100644 --- a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts +++ b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts @@ -151,6 +151,24 @@ describe("VisualizationFrameContentComponent", () => { expect(iframe.getAttribute("srcdoc")).toBe(initialSrcdoc); })); + // An update event carries only the operators whose result changed, so events for different + // operators interleave. With the audit before the filter, a window that closed on another + // operator's event was dropped by the filter and this operator's pending redraw was lost. + it("does not lose this operator's pending redraw to a later emission for another operator", fakeAsync(() => { + snapshotProvider = () => makeResultSnapshot("
v1
"); + buildComponent("op-1"); + const iframe = fixture.nativeElement.querySelector("iframe") as HTMLIFrameElement; + + snapshotProvider = () => makeResultSnapshot("
v2
"); + resultUpdateStream.next({ "op-1": { fake: true } }); + tick(UPDATE_INTERVAL_MS / 2); + resultUpdateStream.next({ "some-other-op": { fake: true } }); + tick(UPDATE_INTERVAL_MS / 2); + fixture.detectChanges(); + + expect(iframe.getAttribute("srcdoc")).toContain("v2"); + })); + it("ignores stream emissions when operatorId is undefined", fakeAsync(() => { buildComponent(undefined); const drawSpy = vi.spyOn(component, "drawChart"); diff --git a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts index eb329c1c7f1..e4ad05a1b8d 100644 --- a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts +++ b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts @@ -45,12 +45,15 @@ export class VisualizationFrameContentComponent implements AfterContentInit { // attempt to draw chart immediately this.drawChart(); - // setup an event lister that re-draws the chart content every (n) milliseconds - // auditTime makes sure the first re-draw happens after (n) milliseconds has elapsed + // Re-draw on this operator's result updates, at most once per UPDATE_INTERVAL_MS: auditTime + // holds the first re-draw until the interval has elapsed. Filter BEFORE auditing: an update + // event carries only the operators whose result changed, so with the audit first a window that + // closed on another operator's event handed the filter that event, and this operator's pending + // re-draw was lost -- the last update of a run showed the previous picture for good. this.workflowResultService .getResultUpdateStream() - .pipe(auditTime(VisualizationFrameContentComponent.UPDATE_INTERVAL_MS)) .pipe(filter(rec => this.operatorId !== undefined && rec[this.operatorId] !== undefined)) + .pipe(auditTime(VisualizationFrameContentComponent.UPDATE_INTERVAL_MS)) .pipe(untilDestroyed(this)) .subscribe(() => { this.drawChart(); diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html index a142107331f..c3ba4c44abc 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html @@ -607,11 +607,13 @@

Results shown here

*ngSwitchCase="isTabularResult(id)" [operatorId]="id"> - - + +

{ expect(component.resultLabel("gone")).toBe("gone"); }); - it("keeps a result's frame identity stable until its version moves", () => { - build(formViewWorkflow).ngOnInit(); - const before = component.resultKey("op-1"); - expect(component.resultKey("op-1")).toBe(before); - - (component as any).resultVersion.set("op-1", 1); - - expect(component.resultKey("op-1")).not.toBe(before); - expect(component.trackByKey(0, "k")).toBe("k"); - }); - it("resizes a result within bounds, per result, and re-fits after", () => { vi.useFakeTimers(); build(formViewWorkflow).ngOnInit(); @@ -2528,13 +2517,20 @@ describe("WorkflowFormComponent", () => { vi.useRealTimers(); }); - it("bumps the result version and re-fits on a result update", () => { + // An update to a result the form already shows reaches the frame in place (the frame redraws on + // its operator's updates); the form only re-limits the shown set and re-fits. It used to keep a + // per-operator version here as well, to key the frame on, which nothing needs. + it("re-limits the shown results and re-fits on a result update, and rebuilds nothing", () => { vi.useFakeTimers(); build(formViewWorkflow).ngOnInit(); + const refresh = vi.spyOn(component as any, "refreshShownResults"); const fit = vi.spyOn(component as any, "fitVisualisations").mockImplementation(() => {}); h.resultUpdateStream.next({ "op-1": {} }); - expect(component.resultKey("op-1")).toBe("op-1#1"); + h.resultUpdateStream.next({ "op-1": {} }); + + expect(refresh).toHaveBeenCalledTimes(2); + expect(fit).not.toHaveBeenCalled(); vi.advanceTimersByTime(300); expect(fit).toHaveBeenCalled(); vi.useRealTimers(); diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts index 4c493ec71df..5491c79d42f 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts @@ -240,10 +240,6 @@ export class WorkflowFormComponent implements OnInit, OnDestroy { /** Chart height per result (0 compact / 1 default / 2 tall). Per operator so one does not resize * the others, and in memory only -- a viewing preference, not part of the workflow. */ private zoomByResult = new Map(); - /** Bumped when a result changes, used as the chart's *ngFor identity so the frame is rebuilt, not - * reused: the chart reads its content once at creation, so a stale frame showed "undefined". */ - private resultVersion = new Map(); - /** The collapsible workflow preview: closed until the reader opens it. */ public workflowOpen = false; /** The embedded canvas is built the first time the strip opens, never while collapsed. */ @@ -371,15 +367,22 @@ export class WorkflowFormComponent implements OnInit, OnDestroy { // views switch, so a step chosen there is already selected here and no event will say so. this.syncSelectionFromHighlight(); - // A result changing bumps that operator's version (so its chart frame is rebuilt, not reused), - // re-limits what the form shows to the currently-viewed set, and re-fits the visualisations. + + // A result update re-limits what the form shows to the currently-viewed set and re-fits the + // visualisations. The chart frame itself is left alone: it redraws in place on its own + // operator's updates (see the visualization frame, at most once per two seconds), and an + // operator's result service lives until the page is left -- a re-run replaces the snapshot + // inside it, nothing clears it -- so there is never a new frame to build mid-session. + // This used to bump a per-operator version that keyed the frame, meaning to rebuild it rather + // than reuse it. It could not do that: every visualisation operator takes its whole input + // before it draws (`process_table`, single-snapshot output), so the one update that carries a + // picture is also the one that mounts the frame, and a second one never comes. Measured on a + // run: two updates for the chart's operator, one picture, one frame -- with the key and + // without it. Dead machinery, so it goes. this.workflowResultService .getResultUpdateStream() .pipe(untilDestroyed(this)) - .subscribe(update => { - for (const operatorID of Object.keys(update ?? {})) { - this.resultVersion.set(operatorID, (this.resultVersion.get(operatorID) ?? 0) + 1); - } + .subscribe(() => { this.refreshShownResults(); // markForCheck, not detectChanges: this fires often during a run, and a synchronous pass // can be thrown out of by an unrelated component's NG0100, killing the subscription. @@ -1418,21 +1421,6 @@ export class WorkflowFormComponent implements OnInit, OnDestroy { return operator ? this.formBindingService.operatorLabel(operator) : operatorID; } - public trackByKey(_: number, key: string): string { - return key; - } - - /** - * A per-result identity that changes on each result-update for that operator, used as the chart's - * *ngFor key so the frame is rebuilt (not reused) when the result changes: the chart reads its - * content once at creation, so a reused frame kept showing the old (or "undefined") picture. A - * visualisation's result arrives as a single snapshot, so in practice this bumps about once per - * result rather than per tuple. - */ - public resultKey(operatorID: string): string { - return operatorID + "#" + (this.resultVersion.get(operatorID) ?? 0); - } - public resultZoom(operatorID: string): number { return this.zoomByResult.get(operatorID) ?? 1; } From ff0fc31989d459a949a8306109c3137a45f534e9 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Mon, 2 Nov 2026 01:56:45 -0800 Subject: [PATCH 2/3] fix(workflow-form): assert the chart frame survives a result update, and tidy the subscription (review) Copilot on #9021: the unit test's "rebuilds nothing" was only a name, so the rendered spec now holds the frame's component instance and host element across two updates for its step and checks both are the same objects afterwards; the frame's three .pipe() calls are one pipe, so the filter-before-audit order is visible in one place; and the result-update comment is cut to the invariant, with the measurements left on #8759. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01FVvP3ttj22f9LB4p9u2anY --- .../visualization-frame-content.component.ts | 8 +++-- .../workflow-form.component.spec.ts | 6 ++-- .../workflow-form/workflow-form.component.ts | 16 +++------ .../workflow-form.rendered.spec.ts | 34 +++++++++++++++++++ 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts index e4ad05a1b8d..2bfad1e683c 100644 --- a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts +++ b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts @@ -52,9 +52,11 @@ export class VisualizationFrameContentComponent implements AfterContentInit { // re-draw was lost -- the last update of a run showed the previous picture for good. this.workflowResultService .getResultUpdateStream() - .pipe(filter(rec => this.operatorId !== undefined && rec[this.operatorId] !== undefined)) - .pipe(auditTime(VisualizationFrameContentComponent.UPDATE_INTERVAL_MS)) - .pipe(untilDestroyed(this)) + .pipe( + filter(rec => this.operatorId !== undefined && rec[this.operatorId] !== undefined), + auditTime(VisualizationFrameContentComponent.UPDATE_INTERVAL_MS), + untilDestroyed(this) + ) .subscribe(() => { this.drawChart(); }); diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts index f4e9ad9372e..df514ae2d2e 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.spec.ts @@ -2518,9 +2518,9 @@ describe("WorkflowFormComponent", () => { }); // An update to a result the form already shows reaches the frame in place (the frame redraws on - // its operator's updates); the form only re-limits the shown set and re-fits. It used to keep a - // per-operator version here as well, to key the frame on, which nothing needs. - it("re-limits the shown results and re-fits on a result update, and rebuilds nothing", () => { + // its operator's updates); the form only re-limits the shown set and re-fits. That the frame is + // still the same one afterwards is asserted on the rendered page (workflow-form.rendered.spec). + it("re-limits the shown results and re-fits on a result update", () => { vi.useFakeTimers(); build(formViewWorkflow).ngOnInit(); const refresh = vi.spyOn(component as any, "refreshShownResults"); diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts index 5491c79d42f..ff19529f09c 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.ts @@ -367,18 +367,10 @@ export class WorkflowFormComponent implements OnInit, OnDestroy { // views switch, so a step chosen there is already selected here and no event will say so. this.syncSelectionFromHighlight(); - - // A result update re-limits what the form shows to the currently-viewed set and re-fits the - // visualisations. The chart frame itself is left alone: it redraws in place on its own - // operator's updates (see the visualization frame, at most once per two seconds), and an - // operator's result service lives until the page is left -- a re-run replaces the snapshot - // inside it, nothing clears it -- so there is never a new frame to build mid-session. - // This used to bump a per-operator version that keyed the frame, meaning to rebuild it rather - // than reuse it. It could not do that: every visualisation operator takes its whole input - // before it draws (`process_table`, single-snapshot output), so the one update that carries a - // picture is also the one that mounts the frame, and a second one never comes. Measured on a - // run: two updates for the chart's operator, one picture, one frame -- with the key and - // without it. Dead machinery, so it goes. + // A result update re-limits what the form shows and re-fits the visualisations. The chart + // frame is left alone: it redraws in place on its own operator's updates. The per-operator + // version that used to key the frame here never produced a second frame -- a visualisation + // operator draws once, from its whole input -- so it is gone; the measurements are on #8759. this.workflowResultService .getResultUpdateStream() .pipe(untilDestroyed(this)) diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.rendered.spec.ts b/frontend/src/app/workspace/component/workflow-form/workflow-form.rendered.spec.ts index 7437037ce82..43f85cb1933 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.rendered.spec.ts +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.rendered.spec.ts @@ -890,6 +890,40 @@ describe("WorkflowFormComponent (rendered template)", () => { expect(names().map(e => e.getAttribute("aria-current"))).toEqual(["false", "true"]); }); + // What the result-update subscription claims: an update for a chart already on the page reaches + // the frame that is there, it does not get the frame rebuilt. A per-result key meant to do that + // used to sit on the frame; this is the assertion that would fail if one came back. + it("keeps the same chart frame across that step's result updates", () => { + const updates = new Subject>(); + const wrs: any = TestBed.inject(WorkflowResultService); + wrs.getResultUpdateStream = () => updates.asObservable(); + wrs.hasNonEmptyResult = () => true; + // A snapshot with a picture takes the visualisation branch. The frame's template is blanked + // above, so what is instantiated is the component instance alone, with no iframe to run. + wrs.getResultService = () => ({ getCurrentResultSnapshot: () => [{ "html-content": "

chart
" }] }); + // An update re-reads the shown set from the graph (refreshShownResults), so op-1 has to be a + // step that is on it: with no downstream link it is a final step, shown by default. + const actions: any = TestBed.inject(WorkflowActionService); + const graph = actions.getTexeraGraph(); + graph.getAllOperators = () => [{ operatorID: "op-1" }]; + actions.getTexeraGraph = () => graph; + fixture.detectChanges(); + finishLoad(); + vi.spyOn(fixture.componentInstance as any, "fitVisualisations").mockImplementation(() => {}); + + const frame = () => fixture.debugElement.query(By.directive(VisualizationFrameContentComponent)); + const first = frame(); + expect(first).not.toBeNull(); + + updates.next({ "op-1": {} }); + fixture.detectChanges(); + updates.next({ "op-1": {} }); + fixture.detectChanges(); + + expect(frame().componentInstance).toBe(first.componentInstance); + expect(frame().nativeElement).toBe(first.nativeElement); + }); + it("mounts the step panel from the start, hidden until a step is selected", () => { fixture.detectChanges(); finishLoad(); From 7e91fc7f3de5c70fceb2bcf53ba1760d67794f0e Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Fri, 27 Nov 2026 19:46:20 -0800 Subject: [PATCH 3/3] fix(workflow-form): redraw the chart on the first update, and say what the key did Review fixes on #9021 (mengw15). The frame redrew on its operator's updates through auditTime, which held the first redraw for the whole interval: with the frame no longer rebuilt, a re-run that finished inside the interval sent one update, already carrying the new picture, and the mounted frame showed the old one for 2 s. It throttles with a leading and a trailing edge now, so the first update redraws at once and the rest coalesce into one redraw per window. The comments on the form (and the PR description) claimed the removed key never fired; it fired on every update of a visualiser that outputs a row per input row, and each rebuild was the flicker of #8759 -- corrected. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01FVvP3ttj22f9LB4p9u2anY --- ...ualization-frame-content.component.spec.ts | 58 +++++++++++++++---- .../visualization-frame-content.component.ts | 21 ++++--- .../workflow-form.component.html | 7 ++- .../workflow-form/workflow-form.component.ts | 7 ++- 4 files changed, 69 insertions(+), 24 deletions(-) diff --git a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts index a9fbe74c4be..e1455fc6a6b 100644 --- a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts +++ b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.spec.ts @@ -114,26 +114,56 @@ describe("VisualizationFrameContentComponent", () => { }); describe("result-update stream subscription", () => { - it("redraws after UPDATE_INTERVAL_MS when a matching operatorId emits", fakeAsync(() => { + // The frame stays mounted across runs. A re-run that finishes inside the interval sends a + // single update, already carrying the new picture; held for the interval, the frame showed the + // old one for that long (mengw15 on #9021, measured against the real result service). + it("redraws at once on the first update after mounting", fakeAsync(() => { snapshotProvider = () => makeResultSnapshot("
v1
"); buildComponent("op-1"); // Initial drawChart() from ngAfterContentInit ran with v1. const iframe = fixture.nativeElement.querySelector("iframe") as HTMLIFrameElement; expect(iframe.getAttribute("srcdoc")).toContain("v1"); - // Stream emits, but auditTime(UPDATE_INTERVAL_MS) holds the redraw. snapshotProvider = () => makeResultSnapshot("
v2
"); resultUpdateStream.next({ "op-1": { fake: true } }); - - // Before the audit window elapses, the iframe still shows v1. - tick(UPDATE_INTERVAL_MS - 1); fixture.detectChanges(); - expect(iframe.getAttribute("srcdoc")).toContain("v1"); - // After the window, the redraw fires and the iframe flips to v2. - tick(1); + expect(iframe.getAttribute("srcdoc")).toContain("v2"); + })); + + // A visualiser that outputs a row per input row sends an update per batch over a slow source; + // the frame draws the first at once and the rest at most once per interval, the trailing + // redraw taking whatever is current when the window closes. + it("holds further updates inside the interval to one trailing redraw, of the latest picture", fakeAsync(() => { + snapshotProvider = () => makeResultSnapshot("
v1
"); + buildComponent("op-1"); + const iframe = fixture.nativeElement.querySelector("iframe") as HTMLIFrameElement; + const drawSpy = vi.spyOn(component, "drawChart"); + + snapshotProvider = () => makeResultSnapshot("
v2
"); + resultUpdateStream.next({ "op-1": { fake: true } }); + snapshotProvider = () => makeResultSnapshot("
v3
"); + tick(UPDATE_INTERVAL_MS / 4); + resultUpdateStream.next({ "op-1": { fake: true } }); + snapshotProvider = () => makeResultSnapshot("
v4
"); + tick(UPDATE_INTERVAL_MS / 4); + resultUpdateStream.next({ "op-1": { fake: true } }); + + // Inside the window: only the leading redraw has run. + tick(UPDATE_INTERVAL_MS / 4); fixture.detectChanges(); + expect(drawSpy).toHaveBeenCalledTimes(1); expect(iframe.getAttribute("srcdoc")).toContain("v2"); + + // The window closes: one more redraw, with the picture that is current now. + tick(UPDATE_INTERVAL_MS / 4); + fixture.detectChanges(); + expect(drawSpy).toHaveBeenCalledTimes(2); + expect(iframe.getAttribute("srcdoc")).toContain("v4"); + + // Nothing arrived in the window that followed, so nothing more is drawn. + tick(UPDATE_INTERVAL_MS); + expect(drawSpy).toHaveBeenCalledTimes(2); })); it("ignores stream emissions that don't include the current operatorId", fakeAsync(() => { @@ -152,21 +182,27 @@ describe("VisualizationFrameContentComponent", () => { })); // An update event carries only the operators whose result changed, so events for different - // operators interleave. With the audit before the filter, a window that closed on another + // operators interleave. With the throttle before the filter, a window that closed on another // operator's event was dropped by the filter and this operator's pending redraw was lost. it("does not lose this operator's pending redraw to a later emission for another operator", fakeAsync(() => { snapshotProvider = () => makeResultSnapshot("
v1
"); buildComponent("op-1"); const iframe = fixture.nativeElement.querySelector("iframe") as HTMLIFrameElement; + // The leading redraw opens the window ... snapshotProvider = () => makeResultSnapshot("
v2
"); resultUpdateStream.next({ "op-1": { fake: true } }); - tick(UPDATE_INTERVAL_MS / 2); + // ... a second update of this operator is pending inside it ... + snapshotProvider = () => makeResultSnapshot("
v3
"); + tick(UPDATE_INTERVAL_MS / 4); + resultUpdateStream.next({ "op-1": { fake: true } }); + // ... and another operator's event lands before the window closes. + tick(UPDATE_INTERVAL_MS / 4); resultUpdateStream.next({ "some-other-op": { fake: true } }); tick(UPDATE_INTERVAL_MS / 2); fixture.detectChanges(); - expect(iframe.getAttribute("srcdoc")).toContain("v2"); + expect(iframe.getAttribute("srcdoc")).toContain("v3"); })); it("ignores stream emissions when operatorId is undefined", fakeAsync(() => { diff --git a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts index 2bfad1e683c..482ad576082 100644 --- a/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts +++ b/frontend/src/app/workspace/component/visualization-panel-content/visualization-frame-content.component.ts @@ -20,7 +20,8 @@ import { AfterContentInit, Component, Input } from "@angular/core"; import { DomSanitizer } from "@angular/platform-browser"; import { WorkflowResultService } from "../../service/workflow-result/workflow-result.service"; -import { auditTime, filter } from "rxjs/operators"; +import { asyncScheduler } from "rxjs"; +import { filter, throttleTime } from "rxjs/operators"; import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; @UntilDestroy() @@ -45,16 +46,22 @@ export class VisualizationFrameContentComponent implements AfterContentInit { // attempt to draw chart immediately this.drawChart(); - // Re-draw on this operator's result updates, at most once per UPDATE_INTERVAL_MS: auditTime - // holds the first re-draw until the interval has elapsed. Filter BEFORE auditing: an update - // event carries only the operators whose result changed, so with the audit first a window that - // closed on another operator's event handed the filter that event, and this operator's pending - // re-draw was lost -- the last update of a run showed the previous picture for good. + // Re-draw on this operator's result updates: at once on the first (the frame stays mounted + // across runs, and a re-run that finishes inside the interval sends one update, already + // carrying the new picture -- held back, it showed the old one for the whole interval), then at + // most once per UPDATE_INTERVAL_MS, with a trailing re-draw for whatever arrived inside the + // window. Filter BEFORE throttling: an update event carries only the operators whose result + // changed, so with the throttle first a window that closed on another operator's event handed + // the filter that event, and this operator's pending re-draw was lost -- the last update of a + // run showed the previous picture for good. this.workflowResultService .getResultUpdateStream() .pipe( filter(rec => this.operatorId !== undefined && rec[this.operatorId] !== undefined), - auditTime(VisualizationFrameContentComponent.UPDATE_INTERVAL_MS), + throttleTime(VisualizationFrameContentComponent.UPDATE_INTERVAL_MS, asyncScheduler, { + leading: true, + trailing: true, + }), untilDestroyed(this) ) .subscribe(() => { diff --git a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html index c3ba4c44abc..d03474eadcb 100644 --- a/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html +++ b/frontend/src/app/workspace/component/workflow-form/workflow-form.component.html @@ -610,9 +610,10 @@

Results shown here

+ This was keyed on a per-result version that rebuilt the frame on every update: + a visualiser that outputs a row per input row sends several updates with a + picture over a slow source, and each rebuild was the flicker of #8759 (see the + result-update subscription). -->