Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ jobs:
3d_charts,
basic_charts,
custom_controls,
customization,
customization/consistent_static_format_export,
customization/density_mapbox_example,
customization/multiple_plots_example,
financial_charts,
images,
kaleido,
maps,
ndarray,
scientific_charts,
shapes,
statistical_charts,
subplots,
themes,
]
Expand Down
21 changes: 19 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
[workspace]
members = ["*", "plotly_utils"]
members = [
"3d_charts",
"basic_charts",
"custom_controls",
"customization/consistent_static_format_export",
"customization/density_mapbox_example",
"customization/multiple_plots_example",
"financial_charts",
"images",
"kaleido",
"maps",
"ndarray",
"plotly_utils",
"scientific_charts",
"shapes",
"statistical_charts",
"subplots",
"themes"
]
resolver = "2"
exclude = ["jupyter", "target", "wasm-yew"]
12 changes: 0 additions & 12 deletions examples/customization/Cargo.toml

This file was deleted.

29 changes: 28 additions & 1 deletion examples/customization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,34 @@

We often get issues/questions regarding customization of the HTML output. In most situations, these are not related to Plotly functionality but rather custom behavior related to HTML rendering.

This example pacakge contains examples of the most frequent raised questions by users of `plotly-rs`, such as
This directory contains examples of the most frequent raised questions by users of `plotly-rs`, such as:
- making the resulting HTML plot responsive on browser window size change
- making the resulting HTML fill the entire browser page
- placing multiple plots in the same HTML page, e.g., by using the [`build_html`](https://crates.io/crates/build_html) crate
- exporting plots to different formats with consistent font rendering

## Examples

### Density Mapbox Example
Demonstrates creating a responsive density mapbox plot with OpenStreetMap styling and zoom controls.

```bash
cd density_mapbox_example
cargo run
```

### Multiple Plots Example
Shows how to embed multiple plotly plots on a single HTML page using inline HTML generation.

```bash
cd multiple_plots_example
cargo run
```

### Consistent Format Export Example
Demonstrates exporting plots to SVG, PNG, and PDF formats with consistent font rendering across browsers.

```bash
cd consistent_static_format_export
cargo run
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "consistent_static_format_export"
version = "0.1.0"
edition = "2021"
authors = ["Yuriy D. Sibirmovsky"]
description = "This example demonstrates exporting a plot to SVG, PNG, and PDF and keeping the font size consistent across all formats."

[dependencies]
plotly = { path = "../../../plotly", features = ["kaleido", "kaleido_download"] }
34 changes: 34 additions & 0 deletions examples/customization/consistent_static_format_export/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SVG Export Example

This example demonstrates exporting a plot to SVG, PNG, and PDF using plotly.rs and keeping font size and style consistent accross SVG and other formats.

This example is based on [GitHub Issue #171](https://github.com/plotly/plotly.rs/issues/171).


**Summary:**

For consistent font rendering across browsers and export formats, always set the `font.family` property explicitly in your plot configuration. Relying on default or generic font settings can lead to differences in appearance, especially for font size and legend layout, depending on the browser or export backend.

**Recommendation:**

Always set the `font.family` property (e.g., to `"Times New Roman, serif"`) for all text elements (titles, axes, legends) to ensure consistent results in all output formats.

## Overview

This example creates a line and scatter plot with custom styling, including:
- Large font sizes for titles, legends, and axes
- Custom legend positioning and styling
- Border shapes around the plot
- Export to multiple formats (PDF, SVG, PNG)

## Running the Example

```bash
cd examples/customization/svg_export_example
cargo run
```

This will generate three output files:
- `Data_plot.pdf` - PDF format (typically renders correctly)
- `Data_plot.svg` - SVG format (may have font/legend issues)
- `Data_plot.png` - PNG format (typically renders correctly)
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
-6 0.34813262986687 0.157822391633258 -6 0
-5.9 0.46875653919673 0.328028117967049 -5.8 5
-5.8 0.628027231301822 0.52369472427333 -5.6 0
-5.7 0.837217193670763 0.75930808002296 -5.4 0
-5.6 1.11051986051416 1.05151591736406 -5.2 0
-5.5 1.46569311773448 1.41993951938828 -5 0
-5.4 1.92481189963786 1.88806100382544 -4.8 5
-5.3 2.51513944788948 2.48420179043188 -4.6 20
-5.2 3.2701251243082 3.24260528612921 -4.4 5
-5.1 4.23053409419851 4.20463343680189 -4.2 25
-5 5.44571057588177 5.42008243904707 -4 50
-4.9 6.97497154752718 6.94861744626477 -3.8 75
-4.8 8.88912170219436 8.861319429385 -3.6 105
-4.7 11.2720729739824 11.2423293883596 -3.4 135
-4.6 14.2225431063134 14.1905658358818 -3.2 195
-4.5 17.855797555045 17.8214809418407 -3 250
-4.4 22.3053876622905 22.2688090784502 -2.8 380
-4.3 27.7248257559954 27.6862489913022 -2.6 560
-4.2 34.2891249995171 34.2490078103487 -2.4 710
-4.1 42.1961189368502 42.1551221052607 -2.2 765
-4 51.6674633852301 51.6264588107484 -2 1080
-3.9 62.9492123746017 62.909287852889 -1.8 1230
-3.8 76.3118510886195 76.2743095595762 -1.6 1650
-3.7 92.0496631724023 92.0160143808758 -1.4 1765
-3.6 110.479308330028 110.451251065321 -1.2 1895
-3.5 131.937489825376 131.916883215734 -1 2225
-3.4 156.777601242171 156.766423994451 -0.8 2360
-3.3 185.36525843517 185.365555436519 -0.6 2635
-3.2 218.072646584863 218.086462920878 -0.4 2875
-3.1 255.271643934383 255.300947114738 -0.2 2710
-3 297.325723059073 297.372315053109 0 2715
-2.9 344.580676889233 344.646098425783 0.2 2870
-2.8 397.354269193195 397.439699625933 0.4 2765
-2.7 455.924966347558 456.031123176121 0.6 2750
-2.6 520.519966990174 520.647009799593 0.8 2250
-2.5 591.302806118227 591.450250194341 1 2255
-2.4 668.360867508848 668.527512647483 1.2 2075
-2.3 751.693189860458 751.877069862752 1.4 1605
-2.2 841.19899448311 841.397352480169 1.6 1440
-2.1 936.667392426119 936.876686481779 1.8 1165
-2 1037.76874355149 1037.98468595164 2 1000
-1.9 1144.04813658796 1144.2657688615 2.2 850
-1.8 1254.92143560091 1255.13523967822 2.4 695
-1.7 1369.67429337025 1369.87833744239 2.6 530
-1.6 1487.46446564367 1487.65258133184 2.8 420
-1.5 1607.32767298802 1607.49365847972 3 295
-1.4 1728.18715102635 1728.32499300291 3.2 205
-1.3 1848.86690841628 1848.97101401134 3.4 185
-1.2 1968.10857928572 1968.17400809455 3.6 70
-1.1 2084.59161822864 2084.61430363873 3.8 55
-1 2196.95644733861 2196.93339625419 4 25
-0.9 2303.83003253055 2303.75949296752 4.2 25
-0.8 2403.85324709827 2403.7348341459 4.4 10
-0.7 2495.70928036152 2495.5440526166 4.6 0
-0.6 2578.15227404741 2577.94275475925 4.8 5
-0.5 2650.03532344029 2649.78546315613 5 15
-0.4 2710.33696776216 2710.05204809582 5.2 10
-0.3 2758.18531662706 2757.87179772837 5.4 0
-0.2 2792.87901697234 2792.5443341764 5.6 0
-0.1 2813.90435606505 2813.5566738726 5.8 0
0 2820.94791773878 2820.59585155634 6 5
0.1 2813.90435606505 2813.5566738726
0.2 2792.87901697234 2792.5443341764
0.3 2758.18531662706 2757.87179772837
0.4 2710.33696776216 2710.05204809582
0.5 2650.03532344029 2649.78546315613
0.6 2578.15227404741 2577.94275475925
0.7 2495.70928036152 2495.5440526166
0.8 2403.85324709827 2403.7348341459
0.9 2303.83003253055 2303.75949296752
1 2196.95644733861 2196.93339625419
1.1 2084.59161822864 2084.61430363873
1.2 1968.10857928572 1968.17400809455
1.3 1848.86690841628 1848.97101401134
1.4 1728.18715102635 1728.32499300291
1.5 1607.32767298802 1607.49365847972
1.6 1487.46446564367 1487.65258133184
1.7 1369.67429337025 1369.87833744239
1.8 1254.92143560091 1255.13523967822
1.9 1144.04813658796 1144.2657688615
2 1037.76874355149 1037.98468595164
2.1 936.667392426119 936.876686481779
2.2 841.19899448311 841.397352480169
2.3 751.693189860458 751.877069862752
2.4 668.360867508848 668.527512647482
2.5 591.302806118227 591.45025019434
2.6 520.519966990174 520.647009799593
2.7 455.924966347558 456.03112317612
2.8 397.354269193195 397.439699625933
2.9 344.580676889233 344.646098425782
3 297.325723059073 297.372315053109
3.1 255.271643934383 255.300947114738
3.2 218.072646584863 218.086462920877
3.3 185.36525843517 185.365555436519
3.4 156.777601242171 156.766423994451
3.5 131.937489825376 131.916883215733
3.6 110.479308330028 110.451251065321
3.7 92.0496631724023 92.0160143808757
3.8 76.3118510886195 76.2743095595761
3.9 62.9492123746017 62.9092878528889
4 51.6674633852301 51.6264588107483
4.1 42.1961189368502 42.1551221052606
4.2 34.2891249995171 34.2490078103487
4.3 27.7248257559954 27.6862489913022
4.4 22.3053876622905 22.2688090784502
4.5 17.855797555045 17.8214809418407
4.6 14.2225431063134 14.1905658358818
4.7 11.2720729739824 11.2423293883595
4.8 8.88912170219436 8.86131942938499
4.9 6.97497154752718 6.94861744626476
5 5.44571057588177 5.42008243904706
5.1 4.23053409419851 4.20463343680188
5.2 3.2701251243082 3.2426052861292
5.3 2.51513944788948 2.48420179043187
5.4 1.92481189963786 1.88806100382543
5.5 1.46569311773448 1.41993951938828
5.6 1.11051986051416 1.05151591736406
5.7 0.837217193670763 0.759308080022959
5.8 0.628027231301822 0.523694724273329
5.9 0.46875653919673 0.328028117967048
6 0.34813262986687 0.157822391633258

Loading
Loading