Skip to content

Commit edf2482

Browse files
committed
doc: add file output for jsdom renderer documentation
1 parent 8f8460c commit edf2482

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## pyobsplot 0.3.9-dev
22

3+
- Plots generated by the `jsdom` renderer can now be saved to HTML or SVG files
34
- Update Observable Plot to 0.6.11
45

56

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ If you just want to try this package without installing it on your computer, you
6868
- Custom JavaScript code can be passed as strings with the `js` method
6969
- Python `date` and `datetime` objects are automatically converted to JavaScript `Date` objects
7070
- Works with Jupyter notebooks and Quarto HTML documents. Plots without legends are also supported in PDF and docx outputs with the `jsdom` renderer.
71+
- Plots generated by the `jsdom` renderer can be saved to SVG or HTML files
7172

7273
**Limitations:**
7374

doc/index.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ If you just want to try this package without installing it on your computer, you
9090
- Python `date` and `datetime` objects are automatically converted to JavaScript `Date` objects
9191
- Plots can be defined with a dictionary, a call to a `Plot` mark function, or with `kwargs`. See [alternative syntaxes](usage.qmd#alternative-syntaxes).
9292
- Works with Jupyter notebooks and Quarto HTML documents. Plots without legends are also supported in PDF and docx outputs with the `jsdom` renderer.
93+
- Plots generated by the `jsdom` renderer can be saved to SVG or HTML files
9394

9495
**Limitations:**
9596

doc/usage.qmd

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ The following table lists the differences between the two renderers.
142142
<td>Not supported. Only static plots are produced.</td>
143143
</tr>
144144
<tr>
145+
<td>**Save plot to disk**</td>
146+
<td>Plots can be saved as SVG or HTML files</td>
147+
<td>Not supported</td>
148+
</tr>
149+
<tr>
145150
<td>**Jupyter<br>interactivity**</td>
146151
<td>Basic</td>
147152
<td>None</td>
@@ -398,7 +403,7 @@ def generate_plot_spec(opacity):
398403
"marks": [
399404
Plot.rectY(penguins, Plot.binX({"y": "count"}, {"x": "body_mass_g", "fill": "steelblue", "fillOpacity": opacity})),
400405
Plot.ruleY([0])
401-
]
406+
]
402407
}
403408
404409
plot = op(generate_plot_spec(1))
@@ -417,3 +422,30 @@ display(plot)
417422

418423
You can see a live version of this example in the following Colab notebook: [![](img/colab-badge.svg)](https://colab.research.google.com/github/juba/pyobsplot/blob/main/examples/interactivity.ipynb)
419424

425+
426+
## Saving plots to file
427+
428+
When using the `jsdom` renderer, generated plots can be savec to a file. To do this, just add a `path` argument to your generator call:
429+
430+
```{python}
431+
#| eval: false
432+
433+
op = Obsplot(renderer="jsdom")
434+
op(Plot.lineY([1,2,3,2]), path="path_to/file.svg")
435+
```
436+
437+
By default Plot generates charts as SVG, but if a legend, title, subtitle or caption is present, the SVG is wrapped in a `<figure>` HTML tag. When using the `path` option, `pyobsplot` will warn you if you try to save an HTML output to a SVG file.
438+
439+
In any case, you can also use Plot's `figure` option to force the output to be wrapped in `<figure>`:
440+
441+
```{python}
442+
#| eval: false
443+
444+
op = Obsplot(renderer="jsdom")
445+
op({
446+
"marks": Plot.lineY([1, 2, 3, 2]),
447+
"figure": True
448+
},
449+
path="/tmp/out.html"
450+
)
451+
```

0 commit comments

Comments
 (0)