Skip to content

Commit a732160

Browse files
committed
expand ci with Firefox+Ubuntu testing & refactor
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent c00b5be commit a732160

File tree

14 files changed

+230
-82
lines changed

14 files changed

+230
-82
lines changed

.github/workflows/ci.yml

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
with:
4343
components: clippy
4444
targets: wasm32-unknown-unknown
45+
# lint plotly_static for all features
46+
- run: cargo clippy -p plotly_static --features geckodriver,webdriver_download -- -D warnings -A deprecated
47+
- run: cargo clippy -p plotly_static --features chromedriver,webdriver_download -- -D warnings -A deprecated
4548
# lint the main library workspace for non-wasm target
4649
- run: cargo clippy --features all -- -D warnings -A deprecated
4750
# lint the non-wasm examples
@@ -70,17 +73,37 @@ jobs:
7073
strategy:
7174
fail-fast: false
7275
matrix:
73-
os: [ubuntu-latest, windows-latest, macos-latest]
76+
include:
77+
- os: ubuntu-latest
78+
browser: chrome
79+
features: plotly_ndarray,plotly_image,static_export_default,ci
80+
- os: ubuntu-latest
81+
browser: firefox
82+
features: plotly_ndarray,plotly_image,static_export_geckodriver,static_export_wd_download,ci
83+
- os: windows-latest
84+
browser: chrome
85+
features: plotly_ndarray,plotly_image,static_export_chromedriver,ci
86+
- os: macos-latest
87+
browser: chrome
88+
features: plotly_ndarray,plotly_image,static_export_default,ci
7489
runs-on: ${{ matrix.os }}
7590
timeout-minutes: ${{ matrix.os == 'windows-latest' && 30 || 10 }}
7691
steps:
7792
- name: Setup Chrome
93+
if: matrix.browser == 'chrome'
7894
uses: browser-actions/setup-chrome@v1
7995
with:
8096
chrome-version: 'latest'
8197
install-chromedriver: true
8298
id: setup-chrome
8399

100+
- name: Setup Firefox
101+
if: matrix.browser == 'firefox'
102+
uses: browser-actions/setup-firefox@v1
103+
with:
104+
firefox-version: 'latest'
105+
id: setup-firefox
106+
84107
- uses: actions/checkout@v4
85108

86109
- uses: dtolnay/rust-toolchain@stable
@@ -106,14 +129,41 @@ jobs:
106129
-ChromePath "${{ steps.setup-chrome.outputs.chrome-path }}" `
107130
-ChromeDriverPath "${{ steps.setup-chrome.outputs.chromedriver-path }}"
108131
109-
# Run tests on non-Windows platforms
110-
- name: Run tests (${{ matrix.os }})
111-
if: matrix.os != 'windows-latest'
112-
run: cargo test --verbose --workspace --features plotly_ndarray,plotly_image,static_export_default --exclude plotly_kaleido
132+
# Run tests on Ubuntu with Chrome
133+
- name: Run tests (${{ matrix.os }} - Chrome)
134+
if: matrix.os == 'ubuntu-latest' && matrix.browser == 'chrome'
135+
run: cargo test --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
136+
137+
# Install xvfb for Firefox WebGL support
138+
- name: Install xvfb
139+
if: matrix.os == 'ubuntu-latest' && matrix.browser == 'firefox'
140+
run: |
141+
sudo apt-get update
142+
sudo apt-get install -y xvfb
143+
144+
# Run tests on Ubuntu with Firefox
145+
- name: Run tests (${{ matrix.os }} - Firefox)
146+
if: matrix.os == 'ubuntu-latest' && matrix.browser == 'firefox'
147+
run: |
148+
# Set environment variables for Firefox WebDriver
149+
export BROWSER_PATH="${{ steps.setup-firefox.outputs.firefox-path }}"
150+
export RUST_LOG="debug"
151+
export RUST_BACKTRACE="1"
152+
153+
echo "Environment variables set:"
154+
echo "BROWSER_PATH: $BROWSER_PATH"
155+
echo "RUST_LOG: $RUST_LOG"
156+
157+
xvfb-run -s "-screen 0 1920x1080x24" cargo test --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
158+
159+
# Run tests on macOS with Chrome
160+
- name: Run tests (${{ matrix.os }} - Chrome)
161+
if: matrix.os == 'macos-latest' && matrix.browser == 'chrome'
162+
run: cargo test --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
113163

114164
# Run tests on Windows with Chrome WebDriver
115-
- name: Run tests (${{ matrix.os }})
116-
if: matrix.os == 'windows-latest'
165+
- name: Run tests (${{ matrix.os }} - Chrome)
166+
if: matrix.os == 'windows-latest' && matrix.browser == 'chrome'
117167
shell: pwsh
118168
run: |
119169
# Set environment variables for WebDriver
@@ -127,13 +177,13 @@ jobs:
127177
Write-Host "WEBDRIVER_PATH: $env:WEBDRIVER_PATH"
128178
Write-Host "BROWSER_PATH: $env:BROWSER_PATH"
129179
130-
cargo test --verbose --workspace --features plotly_ndarray,plotly_image,static_export_chromedriver --exclude plotly_kaleido
180+
cargo test --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
131181
132182
- name: Upload example.pdf artifact
133183
uses: actions/upload-artifact@v4
134184
with:
135-
name: example-pdf-${{ matrix.os }}
136-
path: ${{ github.workspace }}/plotly_static/example.pdf
185+
name: example-pdf-${{ matrix.os }}-${{ matrix.browser }}
186+
path: ${{ github.workspace }}/plotly_static/example.*
137187
retention-days: 30
138188

139189
code-coverage:

docs/book/src/fundamentals/static_image_export.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The static export functionality is controlled by feature flags in the main `plot
1515
- `static_export_geckodriver`: Uses Firefox for rendering (requires geckodriver)
1616

1717
### Optional Features:
18-
- `static_export_downloader`: Automatically downloads WebDriver binaries at build time
18+
- `static_export_wd_download`: Automatically downloads WebDriver binaries at build time
1919
- `static_export_default`: Convenience feature that includes chromedriver + downloader
2020

2121
### Cargo.toml Configuration Examples:
@@ -27,7 +27,7 @@ plotly = { version = "0.13", features = ["static_export_chromedriver"] }
2727

2828
# With automatic WebDriver download
2929
[dependencies]
30-
plotly = { version = "0.13", features = ["static_export_chromedriver", "static_export_downloader"] }
30+
plotly = { version = "0.13", features = ["static_export_chromedriver", "static_export_wd_download"] }
3131

3232
# Recommended: Default configuration with Firefox + auto-download
3333
[dependencies]
@@ -39,7 +39,7 @@ plotly = { version = "0.13", features = ["static_export_default"] }
3939
1. **WebDriver Installation**: You need either chromedriver or geckodriver installed
4040
- Chrome: Download from https://chromedriver.chromium.org/
4141
- Firefox: Download from https://github.com/mozilla/geckodriver/releases
42-
- Or use the `static_export_downloader` feature for automatic download
42+
- Or use the `static_export_wd_download` feature for automatic download
4343

4444
2. **Browser Installation**: You need Chrome/Chromium or Firefox installed
4545

examples/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ members = [
1515
"scientific_charts",
1616
"shapes",
1717
"statistical_charts",
18+
"static_export",
1819
"subplots",
1920
"themes"
2021
]

examples/customization/consistent_static_format_export/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ authors = ["Yuriy D. Sibirmovsky"]
66
description = "This example demonstrates exporting a plot to SVG, PNG, and PDF and keeping the font size consistent across all formats."
77

88
[dependencies]
9-
plotly = { path = "../../../plotly", features = ["kaleido", "kaleido_download"] }
9+
plotly = { path = "../../../plotly", features = ["static_export_default"] }
10+
env_logger = "0.10"
11+
log = "0.4"

examples/customization/consistent_static_format_export/src/main.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
use log::info;
12
use plotly::color::{NamedColor, Rgb};
23
use plotly::common::{Anchor, Font, Line, Marker, MarkerSymbol, Mode, Title};
34
use plotly::layout::{Axis, ItemSizing, Legend, Margin, Shape, ShapeLine, ShapeType};
4-
use plotly::{ImageFormat, Layout, Plot, Scatter};
5+
use plotly::plotly_static::{ImageFormat, StaticExporterBuilder};
6+
use plotly::{Layout, Plot, Scatter};
57

68
fn line_and_scatter_plot(
79
x1: Vec<f64>,
810
y1: Vec<f64>,
911
x2: Vec<f64>,
1012
y2: Vec<f64>,
11-
flnm: &str,
13+
file_name: &str,
1214
title: &str,
1315
) {
1416
let bgcol = Rgb::new(255, 255, 255);
@@ -140,18 +142,26 @@ fn line_and_scatter_plot(
140142
plot.add_trace(trace2);
141143
plot.set_layout(layout);
142144

143-
// Export to multiple formats to demonstrate the SVG export issue
144-
println!("Exporting plot to multiple formats...");
145-
println!("Note: SVG export may have font sizing issues compared to PNG/PDF");
146-
147-
plot.write_image(flnm, ImageFormat::PDF, 1280, 960, 1.0);
148-
plot.write_image(flnm, ImageFormat::SVG, 1280, 960, 1.0);
149-
plot.write_image(flnm, ImageFormat::PNG, 1280, 960, 1.0);
150-
151-
println!("Export complete. Check the output files:");
152-
println!(" - {flnm}.pdf");
153-
println!(" - {flnm}.svg");
154-
println!(" - {flnm}.png");
145+
let mut exporter = StaticExporterBuilder::default()
146+
.spawn_webdriver(true)
147+
.webdriver_port(4444)
148+
.build()
149+
.unwrap();
150+
151+
info!("Exporting to PNG format...");
152+
plot.write_image_with_exporter(&mut exporter, file_name, ImageFormat::PNG, 1280, 960, 1.0)
153+
.unwrap();
154+
info!("Exporting to SVG format...");
155+
plot.write_image_with_exporter(&mut exporter, file_name, ImageFormat::SVG, 1280, 960, 1.0)
156+
.unwrap();
157+
info!("Exporting to PDF format...");
158+
plot.write_image_with_exporter(&mut exporter, file_name, ImageFormat::PDF, 1280, 960, 1.0)
159+
.unwrap();
160+
161+
info!("Export complete. Check the output files:");
162+
info!(" - {file_name}.pdf");
163+
info!(" - {file_name}.svg");
164+
info!(" - {file_name}.png");
155165
}
156166

157167
fn read_from_file(file_path: &str) -> Vec<Vec<f64>> {
@@ -204,6 +214,8 @@ fn read_from_file(file_path: &str) -> Vec<Vec<f64>> {
204214
}
205215

206216
fn main() {
217+
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
218+
207219
let data = read_from_file("assets/data_file.dat");
208220
let x1 = data[0].clone();
209221
let y1 = data[1].clone();

examples/kaleido/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn main() {
1616

1717
// The image will be saved to format!("output/image.{image_format}") relative to
1818
// the current working directory.
19+
#[allow(deprecated)]
1920
plot.write_image(&filename, ImageFormat::EPS, width, height, scale);
2021
plot.write_image(&filename, ImageFormat::JPEG, width, height, scale);
2122
plot.write_image(&filename, ImageFormat::PDF, width, height, scale);

examples/static_export/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The example uses `static_export_default` which includes:
3131

3232
```toml
3333
# Use Chrome/Chromium instead of Firefox
34-
plotly = { version = "0.13", features = ["static_export_chromedriver", "static_export_downloader"] }
34+
plotly = { version = "0.13", features = ["static_export_chromedriver", "static_export_wd_download"] }
3535

3636
# Manual WebDriver installation (no automatic download)
3737
plotly = { version = "0.13", features = ["static_export_geckodriver"] }

plotly/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ kaleido = ["plotly_kaleido"]
1919
# DEPRECATED: kaleido_download feature will be removed in version 0.14.0. Use plotly_static_download instead.
2020
kaleido_download = ["plotly_kaleido/download"]
2121

22-
static_export_downloader = ["plotly_static/webdriver_download"]
2322
static_export_chromedriver = ["plotly_static", "plotly_static/chromedriver"]
2423
static_export_geckodriver = ["plotly_static", "plotly_static/geckodriver"]
24+
static_export_wd_download = ["plotly_static/webdriver_download"]
2525
static_export_default = ["plotly_static", "plotly_static/chromedriver", "plotly_static/webdriver_download"]
2626

2727
# All non-conflicting features
@@ -38,7 +38,7 @@ erased-serde = "0.4"
3838
image = { version = "0.25", optional = true }
3939
plotly_derive = { version = "0.13", path = "../plotly_derive" }
4040
plotly_static = { version = "0.0.1", path = "../plotly_static", optional = true }
41-
plotly_kaleido = { version = "0.12", path = "../plotly_kaleido", optional = true }
41+
plotly_kaleido = { version = "0.13", path = "../plotly_kaleido", optional = true }
4242
ndarray = { version = "0.16", optional = true }
4343
once_cell = "1"
4444
serde = { version = "1.0", features = ["derive"] }

plotly/src/plot.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ mod tests {
10771077
let dst = PathBuf::from("example.pdf");
10781078
let mut exporter = plotly_static::StaticExporterBuilder::default()
10791079
.webdriver_port(get_unique_port())
1080+
.pdf_export_timeout(750)
10801081
.build()
10811082
.unwrap();
10821083
plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::PDF, 1024, 680, 1.0)
@@ -1085,8 +1086,8 @@ mod tests {
10851086
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
10861087
let file_size = metadata.len();
10871088
assert!(file_size > 0,);
1088-
// assert!(std::fs::remove_file(&dst).is_ok());
1089-
// assert!(!dst.exists());
1089+
assert!(std::fs::remove_file(&dst).is_ok());
1090+
assert!(!dst.exists());
10901091
}
10911092

10921093
#[test]
@@ -1177,6 +1178,12 @@ mod tests {
11771178
.webdriver_port(get_unique_port())
11781179
.build()
11791180
.unwrap();
1181+
1182+
assert!(!plot
1183+
.to_base64_with_exporter(&mut exporter, ImageFormat::PNG, 1024, 680, 1.0)
1184+
.unwrap()
1185+
.is_empty());
1186+
11801187
plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::PNG, 800, 600, 1.0)
11811188
.unwrap();
11821189
assert!(dst.exists());
@@ -1186,10 +1193,5 @@ mod tests {
11861193
assert!(file_size > 0,);
11871194
assert!(std::fs::remove_file(&dst).is_ok());
11881195
assert!(!dst.exists());
1189-
1190-
assert!(!plot
1191-
.to_base64_with_exporter(&mut exporter, ImageFormat::PNG, 1024, 680, 1.0)
1192-
.unwrap()
1193-
.is_empty());
11941196
}
11951197
}

plotly_kaleido/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "plotly_kaleido"
3-
version = "0.12.2"
3+
version = "0.13.0"
44
description = "Additional output format support for plotly using Kaleido"
55
authors = [
66
"Ioannis Giagkiozis <[email protected]>",

0 commit comments

Comments
 (0)