Commit a3cab5e
authored
Add generic plot widgets and demos (#341)
* Add generic plot widgets and demos
- add ScatterPlotWidget, BarPlotWidget, and HistogramWidget with shared series normalization
- wire new widgets into exports and anywidget frontend mapping, plus notebook/marimo/vscode demos
- harden trajectory dict validation for empty species lists and extend widget tests
* Fix marimo widget rendering and improve demo notebooks
Marimo serializes cell outputs independently with a ~10 MB limit,
causing widgets embedding ~10 MB of inline JS to fail. anywidget
also only treats _esm values starting with http(s):// as URLs.
- Serve ESM via marimo's virtual-file system with absolute URL
resolution so anywidget imports it as a URL (not inline source)
- Keep CSS inline (~166 KB) to avoid stylesheet loading edge cases
- Add _in_marimo_runtime, _marimo_esm_url, _init_marimo_assets with
27 tests including mutation-verified coverage
- Fix marimo demo cell dependency wiring (_struct, _phonon_doc,
_band_data, _dos_data), broken markdown cells, and ruff noqa
- Add marimo check --strict pre-commit hook
- Fix RUF005 in bar_plot.py, TRY300 in matterviz.py
* Update widget demos with realistic fixture data and clearer narratives
Replace synthetic band/DOS demo payloads with phonon test fixtures and add concise explanatory headings across notebook, marimo, and VSCode interactive demos.
* Guard against marimo VS Code extension kernel crash
- Skip js() virtual file call when virtual_files_supported=False to
prevent ~14 MB base64 data URL allocations that crash the kernel
- Fall back to relative ./@file/ URL when request context is unavailable
- Set resolved ESM URL on class (not per-instance) to avoid N copies
- Use display() from IPython for plot widgets that shadow the method
- Document VS Code extension limitation in MatterVizWidget docstring
* Simplify marimo ESM caching in MatterVizWidget
Use dedicated class-level marimo URL cache fields instead of overloading the generic asset tuple cache, and keep test cache cleanup aligned with the new cache state.
* Auto-discover to_dict fields from synced traitlets and reorganize tests
Replace manual state_fields tuples with automatic discovery via
self.traits(sync=True) in MatterVizWidget.to_dict(). This fixes
serialization for ScatterPlotWidget and HistogramWidget which were
missing their state_fields definitions, and eliminates the need for
every subclass to maintain a redundant field list.
Also simplify production code (DRY numpy conversion in normalize_plot_json,
loop-ify lattice params, remove narrating comments in trajectory.py) and
split test_new_widgets.py into test_normalize.py, test_widget_construction.py,
and test_mime.py organized by domain rather than chronology.
* Rename display() to show(), add configure_assets(), fix marimo cell deps
- Rename MatterVizWidget.display() to show() to avoid shadowing the
'display' traitlet on ScatterPlot/BarPlot/HistogramWidget which made
widget.display() raise TypeError: 'dict' object is not callable
- Add configure_assets(version=, esm_src=, css_src=) for global asset
override via version tags, HTTP URLs, or local file paths
- Fix marimo demo: cells now properly return and declare dependencies
for _struct, _band_data, _phonon_doc, _dos_data
- Simplify matterviz.py: flatten _marimo_esm_url resolution, trim docstrings,
merge isinstance checks in normalize_plot_json
* Add CI job to execute widget demos
Runs all three widget demos (vscode, marimo, jupyter) in a single
consolidated step to catch runtime errors in demo scripts.1 parent 485ed72 commit a3cab5e
File tree
20 files changed
+2866
-879
lines changed- .github/workflows
- examples/widgets
- pymatviz
- widgets
- web
- tests/widgets
20 files changed
+2866
-879
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
45 | 69 | | |
46 | 70 | | |
47 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
29 | 38 | | |
30 | 39 | | |
31 | 40 | | |
| |||
0 commit comments