Skip to content

Commit 6cff411

Browse files
committed
fix examples ci for static export
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent 47f3379 commit 6cff411

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
lines changed

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);

plotly/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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_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]>",

plotly_kaleido/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use serde_json::Value;
2626
/// This enum defines all the image formats that can be exported from Plotly
2727
/// plots using the Kaleido engine. Kaleido supports all these formats natively.
2828
#[derive(Debug, Clone)]
29+
#[allow(deprecated)]
2930
pub enum ImageFormat {
3031
/// Portable Network Graphics format
3132
PNG,
@@ -37,7 +38,15 @@ pub enum ImageFormat {
3738
SVG,
3839
/// Portable Document Format
3940
PDF,
40-
/// Encapsulated PostScript format
41+
/// Encapsulated PostScript format (deprecated)
42+
///
43+
/// This format is deprecated since version 0.13.0 and will be removed in
44+
/// version 0.14.0. Use SVG or PDF instead for vector graphics. EPS is
45+
/// not supported in the open source version.
46+
#[deprecated(
47+
since = "0.13.0",
48+
note = "Use SVG or PDF instead. EPS variant will be removed in version 0.14.0"
49+
)]
4150
EPS,
4251
}
4352

@@ -64,6 +73,7 @@ impl std::fmt::Display for ImageFormat {
6473
Self::WEBP => "webp",
6574
Self::SVG => "svg",
6675
Self::PDF => "pdf",
76+
#[allow(deprecated)]
6777
Self::EPS => "eps",
6878
}
6979
)
@@ -208,6 +218,7 @@ impl Kaleido {
208218
dst.set_extension(format.to_string());
209219

210220
let image_data = self.convert(plotly_data, format.clone(), width, height, scale)?;
221+
#[allow(deprecated)]
211222
let data = match format {
212223
ImageFormat::SVG | ImageFormat::EPS => image_data.as_bytes(),
213224
_ => &general_purpose::STANDARD.decode(image_data).unwrap(),
@@ -460,6 +471,7 @@ mod tests {
460471
let test_plot = create_test_plot();
461472
let k = Kaleido::new();
462473
let dst = PathBuf::from("example.eps");
474+
#[allow(deprecated)]
463475
let r = k.save(dst.as_path(), &test_plot, ImageFormat::EPS, 1200, 900, 4.5);
464476
assert!(r.is_ok());
465477
assert!(std::fs::remove_file(dst.as_path()).is_ok());

plotly_static/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@
198198
//! sessions
199199
//!
200200
//! ### WebDriver Configuration
201+
202+
#![allow(deprecated)]
201203
//!
202204
//! Set the `WEBDRIVER_PATH` environment variable to specify a custom WebDriver
203205
//! binary location (should point to the full executable path):

0 commit comments

Comments
 (0)