pub struct StaticExporterBuilder { /* private fields */ }
Expand description
Builder for configuring and creating a StaticExporter
instance.
This builder provides an interface for configuring WebDriver settings,
browser capabilities, and other options before creating a StaticExporter
instance. The builder automatically handles WebDriver process management,
including detection of existing sessions and automatic spawning when needed.
§Examples
// This example requires a running WebDriver (chromedriver/geckodriver) and a browser.
// It cannot be run as a doc test.
use plotly_static::StaticExporterBuilder;
let exporter = StaticExporterBuilder::default()
.webdriver_port(4444)
.spawn_webdriver(true)
.offline_mode(false)
.pdf_export_timeout(500)
.build()
.expect("Failed to build StaticExporter");
§Default Configuration
- WebDriver port: 4444
- WebDriver URL: “http://localhost”
- Spawn webdriver: true (automatically manages WebDriver lifecycle)
- Offline mode: false
- PDF export timeout: 250ms
- Browser capabilities: Default Chrome/Firefox headless options
- Automatic WebDriver detection and connection reuse
Implementations§
Source§impl StaticExporterBuilder
impl StaticExporterBuilder
Sourcepub fn webdriver_port(self, port: u32) -> Self
pub fn webdriver_port(self, port: u32) -> Self
Sets the WebDriver port number.
§Examples
use plotly_static::StaticExporterBuilder;
let builder = StaticExporterBuilder::default()
.webdriver_port(4444);
Sourcepub fn webdriver_url(self, url: &str) -> Self
pub fn webdriver_url(self, url: &str) -> Self
Sets the WebDriver URL.
§Examples
use plotly_static::StaticExporterBuilder;
let builder = StaticExporterBuilder::default()
.webdriver_url("http://localhost");
Sourcepub fn spawn_webdriver(self, yes: bool) -> Self
pub fn spawn_webdriver(self, yes: bool) -> Self
Controls whether to automatically spawn a WebDriver process.
If true
, automatically spawns a WebDriver process. If false
,
expects an existing WebDriver server to be running.
§Examples
use plotly_static::StaticExporterBuilder;
// Auto-spawn WebDriver
let builder = StaticExporterBuilder::default()
.spawn_webdriver(true);
// Use existing WebDriver server
let builder = StaticExporterBuilder::default()
.spawn_webdriver(false);
Sourcepub fn offline_mode(self, yes: bool) -> Self
pub fn offline_mode(self, yes: bool) -> Self
Controls whether to use offline mode with bundled JavaScript libraries.
If true
, uses bundled JavaScript libraries instead of CDN. If false
,
downloads libraries from CDN.
§Examples
use plotly_static::StaticExporterBuilder;
// Use bundled libraries (no internet required)
let builder = StaticExporterBuilder::default()
.offline_mode(true);
// Use CDN libraries
let builder = StaticExporterBuilder::default()
.offline_mode(false);
Sourcepub fn pdf_export_timeout(self, timeout_ms: u32) -> Self
pub fn pdf_export_timeout(self, timeout_ms: u32) -> Self
Sets the PDF export timeout in milliseconds.
This timeout controls how long to wait for the SVG image to load before proceeding with PDF generation. A longer timeout may be needed for complex plots or slower systems.
§Examples
use plotly_static::StaticExporterBuilder;
// Set a longer timeout for complex plots
let builder = StaticExporterBuilder::default()
.pdf_export_timeout(500);
// Use default timeout (150ms)
let builder = StaticExporterBuilder::default()
.pdf_export_timeout(150);
Sourcepub fn webdriver_browser_caps(self, caps: Vec<String>) -> Self
pub fn webdriver_browser_caps(self, caps: Vec<String>) -> Self
Sets custom browser capabilities for the WebDriver.
§Examples
use plotly_static::StaticExporterBuilder;
let custom_caps = vec![
"--headless".to_string(),
"--no-sandbox".to_string(),
"--disable-gpu".to_string(),
];
let builder = StaticExporterBuilder::default()
.webdriver_browser_caps(custom_caps);
Sourcepub fn build(&self) -> Result<StaticExporter>
pub fn build(&self) -> Result<StaticExporter>
Builds a StaticExporter
instance with the current configuration.
This method creates a new StaticExporter
instance with all the
configured settings. The method manages WebDriver:
- If
spawn_webdriver
is enabled, it first tries to connect to an existing WebDriver session on the specified port, and only spawns a new process if none is found - If
spawn_webdriver
is disabled, it creates a connection to an existing WebDriver without spawning
Returns a Result<StaticExporter>
where:
Ok(exporter)
- Successfully created the StaticExporter instanceErr(e)
- Failed to create the instance (e.g., WebDriver not available, port conflicts, etc.)
§Examples
use plotly_static::StaticExporterBuilder;
let exporter = StaticExporterBuilder::default()
.webdriver_port(4444)
.build()
.expect("Failed to build StaticExporter");
Trait Implementations§
Source§impl Default for StaticExporterBuilder
impl Default for StaticExporterBuilder
Source§fn default() -> Self
fn default() -> Self
Creates a new StaticExporterBuilder
with default configuration.
The default configuration includes:
- WebDriver port: 4444
- WebDriver URL: “http://localhost”
- Spawn webdriver: true
- Offline mode: false
- PDF export timeout: 250ms
- Default browser capabilities for headless operation