Skip to content

Commit 2519998

Browse files
committed
bump
1 parent 6ef04eb commit 2519998

2 files changed

Lines changed: 115 additions & 1 deletion

File tree

‎plans/VersoPresentation.md‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Verso notebook presentation and output lifecycle
2+
3+
Status: deferred until after the v1 release, per the user's decision on 2026-11-12. The current implementation in `VersoExtension.md` defines the v1 scope; this proposal is not a release requirement and implementation has not started.
4+
Baseline: local commit `6ef04eb8`; reviewed maintainer fork `bd568aba75134a08ba02a8320251e86258384592`.
5+
6+
## Objective
7+
8+
Add the maintainer's useful notebook presentation behaviors to our tested Verso adapter: host-aware colors/fonts, container-width sizing, and convenient image-download defaults. Add explicit disposal of rendered outputs before introducing more browser observers and event handlers.
9+
10+
Retain the inline `text/html` renderer, shared asynchronous Plotly loader, originating-assembly bridge, and existing public HTML helpers. Widget/iframe output is a separate architectural decision, not a prerequisite for these features.
11+
12+
## Proposed public behavior
13+
14+
Add a small per-chart API in `Plotly.NET.Verso`, provisionally `PresentationOptions` and `Presentation.withOptions options chart`:
15+
16+
| Option | Default | Opt-in behavior |
17+
|---|---|---|
18+
| Theme | `Preserve` | `FollowHost`: apply host presentation colors/fonts under the precedence rules below and follow live theme changes |
19+
| Sizing | `Preserve` | `FitContainerWidth`: deliberately replace rendered width with the output container's width; keep chart height |
20+
| Snapshot | `Preserve` | `NotebookDefaults`: fill missing image-download filename/format/scale settings |
21+
22+
The names are proposed API names, not existing functions. A chart with no presentation metadata must render as it does today. Lifecycle cleanup applies to all charts independently of these choices.
23+
24+
Store options as a versioned JSON string under a reserved DisplayOptions property, such as `Plotly.NET.Verso.Presentation`. The helper copies the DisplayOptions container and attaches the new metadata without changing the source chart or its nested HTML nodes. Read the metadata through the originating assembly's public DynamicObj API; pass strings and simple values through the bridge, not foreign option types. Do not introduce mutable global settings that can diverge between kernel and extension assembly contexts.
25+
26+
Read policy once per formatted output. Later changes to another chart must not change existing output policies. Live host-theme changes are the deliberate exception for outputs using `FollowHost`. Recommend applying the helper after `Chart.combine`; do not invent trace-level option merging in this change.
27+
28+
## Goal 1: deterministic output disposal
29+
30+
- Track each rendered output by its actual DOM element and unique ID.
31+
- When a rendered output is removed or replaced, call `Plotly.purge` and remove adapter-owned listeners, observers, timers, and queued animation-frame work.
32+
- Removal during loading must prevent subsequent `newPlot`, error insertion, or ready-state updates for that output. Keep a shared load alive when another output still needs it.
33+
- Removal during asynchronous drawing must prevent later callbacks from reviving the output. Perform final cleanup after drawing settles if it can create resources after the initial disposal.
34+
- Keep lifecycle tracking bounded: unregister disposed elements and stop shared observation when no outputs need it. Do not attach one permanent document-wide observer per cell.
35+
- Keep shared Plotly availability and failed-load retry behavior intact. Do not remove another cell's library or output.
36+
37+
Acceptance tests use real rendering plus spies on purge and adapter-owned registrations. Ready-output removal purges once; in-flight drawing may require final cleanup again. Repeated reruns leave one live chart and its expected active subscriptions. Test one of two waiting cells being removed, removal while drawing, and removal before a queued callback fires. Assert observable cleanup rather than unreliable heap-size thresholds.
38+
39+
## Goal 2: optional host-theme adaptation
40+
41+
- Apply theme values before the first `Plotly.newPlot` call so the first rendered frame uses the selected palette.
42+
- Use the existing Verso theme context as fallback and the host's resolved CSS tokens when present. Listen for `verso:themechanged` only for opted-in, eligible outputs.
43+
- Scope every update to that chart's element. Do not wrap global `Plotly.newPlot`/`react` or restyle all charts on the page.
44+
- First-version coverage is paper/plot backgrounds, font family/size/color, and Cartesian axis grid/line/zero-line/tick colors, including Cartesian subplots. Trace colors, colorways, colorscales, and family-specific 3D/polar/geo/ternary styling are outside this change.
45+
- Missing or invalid theme tokens leave the corresponding original presentation value in place. Do not fetch fonts or inject external font resources.
46+
- Theme changes must preserve data, chart IDs, zoom/ranges, and explicit user settings; they must not recreate the chart with `newPlot`.
47+
48+
Precedence is explicit:
49+
50+
1. Direct layout and trace properties win, including properties whose values happen to equal library defaults.
51+
2. A non-stock custom template remains authoritative; skip automatic theme adaptation for that chart in this first version.
52+
3. An absent template or a structurally stock Plotly.NET template is eligible only when `FollowHost` was selected. Apply a render-only presentation overlay while retaining the other template settings.
53+
4. Obtain the stock template baseline from the chart's originating assembly (`ChartTemplates.plotly`), not the extension's assembly or the mutable current `Defaults.DefaultTemplate`. Do not retain foreign assembly/type objects in static caches.
54+
55+
There is no historical provenance for an explicitly supplied template identical to the stock template. Under this contract, opting into `FollowHost` makes that template eligible too; `Preserve` keeps it unchanged. Do not claim that value comparison can reconstruct how a chart was created.
56+
57+
Acceptance tests cover light/dark first draw, live theme switching, fallback with absent CSS tokens, explicit layout overrides, custom templates, stock-equivalent templates, Cartesian subplots, independent opted-in/opted-out outputs, and unchanged zoom after a theme change. Verify source-chart immutability and settings round-trip for both normal and foreign-assembly charts. No updates may run after disposal.
58+
59+
## Goal 3: optional container-width sizing
60+
61+
- `Preserve` retains current dimensions and behavior, including an explicitly supplied width equal to the library default.
62+
- `FitContainerWidth` explicitly authorizes overriding width for this rendered output, including a previously supplied width. Keep its height, data, and other layout settings unchanged.
63+
- Observe a stable output wrapper's available content width, not the document root or the graph's own width. Respond when a sidebar or notebook column changes without a window resize.
64+
- Ignore zero-width measurements until the output becomes visible. Coalesce rapid changes and do nothing when the effective width has not changed.
65+
- Resize the existing graph; do not create a new chart or introduce height/width feedback loops. Do not globally force `config.responsive=false` as the iframe-specific fork implementation does.
66+
- Preserve zoom/ranges during resize and disconnect the observer and queued work on disposal.
67+
68+
Acceptance tests change parent width without dispatching `window.resize`, check actual Plotly dimensions, preserve height, test hidden-to-visible output, rapid resizing, two independently sized cells, preserved zoom, and removed outputs. Explicit-width preservation is tested in `Preserve`; deliberate width replacement is tested in `FitContainerWidth`.
69+
70+
## Goal 4: optional image-download defaults
71+
72+
- In `NotebookDefaults`, fill only missing `toImageButtonOptions` properties: PNG format, scale 2, and a filename derived from the chart title.
73+
- Preserve every supplied export property, including filename, format, scale, width, and height. Preserve all other config values and custom modebar settings.
74+
- Produce a bounded, filesystem-safe title slug, removing title markup, separators, control characters, and invalid trailing characters. Handle reserved filenames and empty/unusable titles with a stable `plotly-chart` fallback; limit generated filenames to 80 characters before the extension.
75+
- Resolve values per output without modifying the original chart. Do not alter trace data, titles, or normal chart display dimensions to improve exports.
76+
77+
Acceptance tests cover plain/markup/Unicode/empty/long/reserved titles and independently supplied option overrides. Verify the modebar receives the expected filename/options and generate an actual PNG, checking its dimensions at scale 2. A self-contained line-chart fixture must render and export with external HTTP requests blocked.
78+
79+
## Goal 5: preserve compatibility and prove host behavior
80+
81+
- Keep `GenericChartFormatter`, `Formatters.toVersoHTML`, and `Formatters.toVersoHTMLOffline` signatures and output contracts.
82+
- Preserve custom CDN, missing-reference CDN, `Full`, `NoReference`, and actionable `Require` behavior, as well as MIME filtering, cancellation, metadata, descriptions, and additional HTML tags.
83+
- Keep render-only changes separate from source chart JSON. Do not reintroduce date-string conversion while processing captured JSON.
84+
- Extend packaged CLI/web-host fixtures to exercise the new policies, reruns, theme updates, resizing, save, and reopen. Reopened opted-in output follows the current host theme and container width; opted-out output keeps its chart styling.
85+
- Existing helpers remain usable outside Verso. If no host theme context or CSS tokens are available, keep the original chart palette; do not manufacture a new default theme or fetch resources.
86+
- Run deterministic unit/browser tests on Windows and Linux, packaged integration, documentation generation, and the required full clean suite before committing. Record actual environments and outcomes.
87+
- Perform and record a manual VS Code check of dark/light switching, notebook-width changes, configured versus preserved export options, repeated reruns, offline output, and save/reopen. Do not substitute automated web-host tests for this check.
88+
89+
## Planned commits
90+
91+
- [ ] **1. Per-chart presentation policy.** Add typed options, immutable metadata helper, bridge capture, and unit/foreign-assembly round-trip tests. Document default/override semantics in API comments.
92+
- [ ] **2. Output disposal.** Add lifecycle tracking and purge/observer cleanup with browser regressions for removal, reruns, and pending work.
93+
- [ ] **3. Host themes.** Add initial and live theme application, explicit precedence rules, and unit/browser tests, including multi-cell and subplot cases.
94+
- [ ] **4. Container sizing.** Add opt-in width observation, hidden-output handling, and browser resize/disposal/zoom tests.
95+
- [ ] **5. Snapshot defaults.** Add safe filename generation and missing-property defaults with unit tests and actual browser export checks.
96+
- [ ] **6. Packaged host coverage and documentation.** Extend host fixtures and manuals, attribute adapted maintainer code, run final validation, and record results.
97+
98+
## Explicit exclusions
99+
100+
- Switching the default formatter to `text/x-verso-widget` or changing existing helper return formats.
101+
- Global monkey-patching of Plotly or page-wide selectors that affect unrelated charts.
102+
- Global mutable theme/offline flags, silently overriding explicit config, or treating default-value equality as author-intent provenance.
103+
- Full styling support for every Plotly trace family, new core chart APIs, unrelated dependency/runtime upgrades, or publishing packages.
104+
- Claiming a demonstrated memory leak: removal cleanup is a source-supported lifecycle concern that the new tests must establish precisely.
105+
106+
## Sources and attribution
107+
108+
Adapt selected concepts/code from Torrey Betts' fork with attribution in the implementation commits. Its iframe-specific scripts require adaptation for the existing inline renderer.
109+
110+
- [Fork theme/sizing/export implementation](https://github.com/TorreyBetts/Plotly.NET/blob/bd568aba75134a08ba02a8320251e86258384592/src/Plotly.NET.Verso/Theming.fs)
111+
- [Fork formatter and widget contract](https://github.com/TorreyBetts/Plotly.NET/blob/bd568aba75134a08ba02a8320251e86258384592/src/Plotly.NET.Verso/Formatters.fs)
112+
- [Verso 1.2.3 output handling](https://github.com/DataficationSDK/Verso/blob/6f2e3dd9103be27931340bcb0bba2e326590f992/src/Verso.Blazor.Shared/Components/Notebook/OutputView.razor)
113+
- [Verso theme context](https://github.com/DataficationSDK/Verso/blob/6f2e3dd9103be27931340bcb0bba2e326590f992/src/Verso.Abstractions/Contexts/IThemeContext.cs)
114+
- [Inline theme-change event](https://github.com/DataficationSDK/Verso/blob/6f2e3dd9103be27931340bcb0bba2e326590f992/src/Verso.Blazor.Shared/wwwroot/js/verso-inline-layout-bridge.js)

‎src/Plotly.NET.Verso/RELEASE_NOTES.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 1.0.0 - TBD
1+
## 1.0.0 - November 12 2026
22

33
- Initial release of Plotly.NET.Verso
44
- Renders GenericChart objects as interactive Plotly charts in Verso notebooks

0 commit comments

Comments
 (0)