diff --git a/stpyvista/CHANGELOG.md b/stpyvista/CHANGELOG.md index 3e39cc4..2576386 100644 --- a/stpyvista/CHANGELOG.md +++ b/stpyvista/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog -## [v 0.0.17] - 2024-04-02 +## [v 0.0.17] - 2024-04-11 - Rewrite buffer using context manager +- Introduce and experimental viewer based on trame and vanilla vtk-js ## [v 0.0.16] - 2024-03-29 - Add controls help description diff --git a/stpyvista/src/stpyvista/__init__.py b/stpyvista/src/stpyvista/__init__.py index f878826..b6cd0be 100644 --- a/stpyvista/src/stpyvista/__init__.py +++ b/stpyvista/src/stpyvista/__init__.py @@ -12,12 +12,9 @@ from bokeh.resources import CDN, INLINE -BOKEH_RESOURCES = {"CDN": CDN, "INLINE": INLINE} - pn.extension("vtk", sizing_mode="stretch_both") +BOKEH_RESOURCES = {"CDN": CDN, "INLINE": INLINE} -# Tell streamlit that there is a component called stpyvista, -# and that the code to display that component is in the "frontend" folder class stpyvistaTypeError(TypeError): pass @@ -26,11 +23,30 @@ class stpyvistaTypeError(TypeError): class stpyvistaValueError(ValueError): pass + +# Tell streamlit that there is a component called `experimental_vtkjs`, +# and that the code to display that component is in the "vanilla_vtkjs" folder experimental_frontend_dir = (Path(__file__).parent / "vanilla_vtkjs").absolute() -_exp_component_func = components.declare_component("experimental_vtkjs", path=str(experimental_frontend_dir)) +_exp_component_func = components.declare_component( + "experimental_vtkjs", path=str(experimental_frontend_dir) +) -def experimental_vtkjs(vtksz_data: bytes, key: Optional[str] = None): +def experimental_vtkjs(vtksz_data: bytes, key: Optional[str] = None): + """ + Renders an interactive Pyvista Plotter in streamlit. + + Parameters + ---------- + vtksz_data: bytes + Data from a vtksz in zip format. + + Returns + ------- + dict + A stringified JSON with camera view properties. + """ + base64_str = base64.b64encode(vtksz_data).decode().replace("\n", "") component_value = _exp_component_func( @@ -42,9 +58,10 @@ def experimental_vtkjs(vtksz_data: bytes, key: Optional[str] = None): return component_value -frontend_dir = (Path(__file__).parent / "frontend").absolute() +frontend_dir = (Path(__file__).parent / "panel_based").absolute() _component_func = components.declare_component("stpyvista", path=str(frontend_dir)) + def stpyvista( plotter: Plotter, use_container_width: bool = True, diff --git a/stpyvista/src/stpyvista/frontend/fullscreen.js b/stpyvista/src/stpyvista/panel_based/fullscreen.js similarity index 100% rename from stpyvista/src/stpyvista/frontend/fullscreen.js rename to stpyvista/src/stpyvista/panel_based/fullscreen.js diff --git a/stpyvista/src/stpyvista/frontend/index.html b/stpyvista/src/stpyvista/panel_based/index.html similarity index 100% rename from stpyvista/src/stpyvista/frontend/index.html rename to stpyvista/src/stpyvista/panel_based/index.html diff --git a/stpyvista/src/stpyvista/frontend/main.js b/stpyvista/src/stpyvista/panel_based/main.js similarity index 100% rename from stpyvista/src/stpyvista/frontend/main.js rename to stpyvista/src/stpyvista/panel_based/main.js diff --git a/stpyvista/src/stpyvista/frontend/streamlit-component-lib.js b/stpyvista/src/stpyvista/panel_based/streamlit-component-lib.js similarity index 100% rename from stpyvista/src/stpyvista/frontend/streamlit-component-lib.js rename to stpyvista/src/stpyvista/panel_based/streamlit-component-lib.js diff --git a/stpyvista/src/stpyvista/frontend/style.css b/stpyvista/src/stpyvista/panel_based/style.css similarity index 100% rename from stpyvista/src/stpyvista/frontend/style.css rename to stpyvista/src/stpyvista/panel_based/style.css