Skip to content

Commit 44c7eb6

Browse files
committed
include new static export in plotly crate
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent f42fa87 commit 44c7eb6

File tree

7 files changed

+92
-76
lines changed

7 files changed

+92
-76
lines changed

plotly/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "plotly"
33
version = "0.12.1"
44
description = "A plotting library powered by Plotly.js"
5-
authors = ["Ioannis Giagkiozis <[email protected]>"]
5+
authors = ["Ioannis Giagkiozis <[email protected]>", "Andrei Gherghescu <[email protected]>"]
66
license = "MIT"
77
readme = "../README.md"
88
homepage = "https://github.com/plotly/plotly.rs"
@@ -17,6 +17,11 @@ exclude = ["target/*"]
1717
kaleido = ["plotly_kaleido"]
1818
kaleido_download = ["plotly_kaleido/download"]
1919

20+
plotly_static = []
21+
plotly_static_download = ["plotly_static/download"]
22+
plotly_static_chromedriver = ["plotly_static/chromedriver"]
23+
plotly_static_geckodriver = ["plotly_static/geckodriver"]
24+
2025
plotly_ndarray = ["ndarray"]
2126
plotly_image = ["image"]
2227
plotly_embed_js = []
@@ -27,6 +32,7 @@ dyn-clone = "1"
2732
erased-serde = "0.4"
2833
image = { version = "0.25", optional = true }
2934
plotly_derive = { version = "0.12", path = "../plotly_derive" }
35+
plotly_static = { version = "0.0.1", path = "../plotly_static", optional = true }
3036
plotly_kaleido = { version = "0.12", path = "../plotly_kaleido", optional = true }
3137
ndarray = { version = "0.16", optional = true }
3238
once_cell = "1"
@@ -53,6 +59,6 @@ image = "0.25"
5359
itertools = ">=0.10, <0.15"
5460
itertools-num = "0.1"
5561
ndarray = "0.16"
56-
plotly_kaleido = { path = "../plotly_kaleido", features = ["download"] }
62+
plotly_static = { path = "../plotly_static", features = ["download", "chromedriver"], default-features = false }
5763
rand_distr = "0.5"
5864
base64 = "0.22"

plotly/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ pub use common::color;
3333
pub use configuration::Configuration;
3434
pub use layout::Layout;
3535
pub use plot::{Plot, Trace};
36+
3637
#[cfg(feature = "kaleido")]
3738
pub use static_format::ImageFormat;
3839
#[cfg(not(feature = "kaleido"))]
3940
pub use static_format::ImageFormat;
41+
42+
#[cfg(feature = "plotly_static")]
43+
pub use plotly_static::{StaticExporterBuilder, ImageFormat};
44+
4045
// Also provide easy access to modules which contain additional trace-specific types
4146
pub use traces::{
4247
box_plot, contour, heat_map, histogram, image, mesh3d, sankey, scatter, scatter3d,

plotly_static/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ keywords = ["plot", "static", "image", "export", "chart", "plotly", "ndarray"]
1313
exclude = ["target/*"]
1414

1515
[features]
16-
default = ["download"]
16+
# default = ["download", "chromedriver"]
1717
download = []
1818
geckodriver = []
1919
chromedriver = []

plotly_static/build.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ use anyhow::{anyhow, Context, Result};
88
use tokio::time::sleep;
99
use webdriver_downloader::prelude::*;
1010

11-
#[cfg(target_os = "windows")]
12-
const DRIVER_EXT: &str = ".exe";
13-
#[cfg(not(target_os = "windows"))]
14-
const DRIVER_EXT: &str = "";
11+
// Enforce that only one driver feature is enabled
12+
#[cfg(all(feature = "geckodriver", feature = "chromedriver"))]
13+
compile_error!("Only one of 'geckodriver' or 'chromedriver' features can be enabled at a time.");
1514

15+
// Define the WEBDRIVER_BIN constant based on the enabled feature
1616
#[cfg(feature = "geckodriver")]
1717
const WEBDRIVER_BIN: &str = "geckodriver";
1818

1919
#[cfg(feature = "chromedriver")]
2020
const WEBDRIVER_BIN: &str = "chromedriver";
2121

22+
#[cfg(target_os = "windows")]
23+
const DRIVER_EXT: &str = ".exe";
24+
#[cfg(not(target_os = "windows"))]
25+
const DRIVER_EXT: &str = "";
26+
2227
const CHROME_PATH_ENV: &str = "CHROME_PATH";
2328
const CHROMEDRIVER_PATH_ENV: &str = "CHROMEDRIVER_PATH";
2429
const FIREFOX_PATH_ENV: &str = "FIREFOX_PATH";

plotly_static/examples/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::{Parser, ValueEnum};
2-
use plotly_static::{ImageFormat, StaticlyBuilder};
2+
use plotly_static::{ImageFormat, StaticExporterBuilder};
33
use serde_json::Value;
44
use std::fs;
55
use std::io::{self, Read};
@@ -109,8 +109,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
109109
return Err("Invalid JSON: expected an object".into());
110110
}
111111

112-
// Build Staticly instance
113-
let mut staticly = StaticlyBuilder::default()
112+
// Build StaticExporter instance
113+
let mut exporter = StaticExporterBuilder::default()
114114
.offline_mode(cli.offline)
115115
.build()?;
116116

@@ -123,7 +123,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
123123
);
124124

125125
// Export the plot
126-
staticly.write_fig(
126+
exporter.write_fig(
127127
&cli.output,
128128
&plot_json,
129129
cli.format.into(),

0 commit comments

Comments
 (0)