A local server for viewing plotly plots
Goal: support images the way foundry-nvim's plot server does (an image plus a mime type), alongside plotly figures.
- The
plottable needs amimecolumn that defaults to the plotly type, so existing rows keep working. - Existing databases need an
ALTER TABLE, becauseCREATE TABLE IF NOT EXISTSwon't add the column. - Store image bytes as a BLOB. Decode base64 on ingest, since base64 costs about 33% more space.
POST /plotviewer/plotalready takes a raw body. The least disruptive change is to branch onContent-Type.application/jsonor no type keeps today's behavior.image/*is stored as an image.
- Plotly rows embed the whole figure JSON in
data-plot-jsonand render client-side. Embedding base64 images the same way would be much heavier, especially in SSE payloads. - Serve image bytes from a URL like
/plot/<id>/imageand use a plain<img src>. The browser caches them. plot.htmlandplot_list_item.htmlboth need a branch on mime.renderPlotandrenderThumbnailsinplot.jsalready skip elements with nodata-plot-json, so they need little or no change.- The sidebar thumbnail for an image is just the
<img>. Plotly thumbnails are rendered to PNG client-side.
- The
htmx:afterSwaphandler on#recent-plotsreadsdata-plot-jsonfrom the new first sidebar item. It then hand-builds the#plot-containerHTML around that JSON and callsrenderPlot(). - An image item has no
data-plot-json, so the handler hitsif (!preview) return;. The image would appear in the sidebar but never in the main pane. - Fix: add an image branch there, or have it trigger the sidebar item's existing
hx-getso the server renders the right partial for each type. The second option avoids duplicating markup in JS. - The click, resize and SSE connection-indicator handlers don't need to change.
- No theme, so no
paper_bgcoloror font colors to read. The sidebar item and plot area need a neutral default. - No
layout.title, so#title-textis empty unless a title is sent. - Transparent matplotlib PNGs will look odd on the dark background.