Skip to content

Commit a31eff6

Browse files
committed
cleanup
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent e55f829 commit a31eff6

File tree

4 files changed

+32
-81
lines changed

4 files changed

+32
-81
lines changed

plotly/src/plot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ impl Plot {
755755
pub fn offline_js_sources() -> String {
756756
// Note that since 'tex-mml-chtml' conflicts with 'tex-svg' when generating
757757
// Latex Titles we no longer include it.
758-
let local_tex_svg_js = include_str!("../templates/tex-svg-3.2.2.js");
759-
let local_plotly_js = include_str!("../templates/plotly.min.js");
758+
let local_tex_svg_js = include_str!("../resource/tex-svg-3.2.2.js");
759+
let local_plotly_js = include_str!("../resource/plotly.min.js");
760760

761761
format!(
762762
"<script type=\"text/javascript\">{local_plotly_js}</script>\n

plotly_static/src/lib.rs

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,6 @@ impl Default for StaticExporterBuilder {
522522
impl StaticExporterBuilder {
523523
/// Sets the WebDriver port number.
524524
///
525-
/// # Arguments
526-
///
527-
/// * `port` - The port number for the WebDriver server
528-
///
529525
/// # Examples
530526
///
531527
/// ```rust
@@ -541,10 +537,6 @@ impl StaticExporterBuilder {
541537

542538
/// Sets the WebDriver URL.
543539
///
544-
/// # Arguments
545-
///
546-
/// * `url` - The base URL for the WebDriver server (e.g., "http://localhost")
547-
///
548540
/// # Examples
549541
///
550542
/// ```rust
@@ -560,10 +552,8 @@ impl StaticExporterBuilder {
560552

561553
/// Controls whether to automatically spawn a WebDriver process.
562554
///
563-
/// # Arguments
564-
///
565-
/// * `yes` - If `true`, automatically spawns a WebDriver process. If
566-
/// `false`, expects an existing WebDriver server to be running.
555+
/// If `true`, automatically spawns a WebDriver process. If `false`,
556+
/// expects an existing WebDriver server to be running.
567557
///
568558
/// # Examples
569559
///
@@ -585,10 +575,8 @@ impl StaticExporterBuilder {
585575

586576
/// Controls whether to use offline mode with bundled JavaScript libraries.
587577
///
588-
/// # Arguments
589-
///
590-
/// * `yes` - If `true`, uses bundled JavaScript libraries instead of CDN.
591-
/// If `false`, downloads libraries from CDN.
578+
/// If `true`, uses bundled JavaScript libraries instead of CDN. If `false`,
579+
/// downloads libraries from CDN.
592580
///
593581
/// # Examples
594582
///
@@ -610,11 +598,6 @@ impl StaticExporterBuilder {
610598

611599
/// Sets custom browser capabilities for the WebDriver.
612600
///
613-
/// # Arguments
614-
///
615-
/// * `caps` - Vector of browser capability strings (e.g., ["--headless",
616-
/// "--no-sandbox"])
617-
///
618601
/// # Examples
619602
///
620603
/// ```rust
@@ -645,8 +628,6 @@ impl StaticExporterBuilder {
645628
/// - If `spawn_webdriver` is disabled, it creates a connection to an
646629
/// existing WebDriver without spawning
647630
///
648-
/// # Returns
649-
///
650631
/// Returns a `Result<StaticExporter>` where:
651632
/// - `Ok(exporter)` - Successfully created the StaticExporter instance
652633
/// - `Err(e)` - Failed to create the instance (e.g., WebDriver not
@@ -800,18 +781,6 @@ impl StaticExporter {
800781
/// browser and saves the result as an image file in the specified
801782
/// format.
802783
///
803-
/// # Arguments
804-
///
805-
/// * `dst` - The destination path for the output file (extension will be
806-
/// added automatically)
807-
/// * `plot` - The Plotly plot data as a JSON value
808-
/// * `format` - The desired output image format
809-
/// * `width` - The width of the output image in pixels
810-
/// * `height` - The height of the output image in pixels
811-
/// * `scale` - The scale factor for the image (1.0 = normal size)
812-
///
813-
/// # Returns
814-
///
815784
/// Returns `Ok(())` on success, or an error if the export fails.
816785
///
817786
/// # Examples
@@ -885,16 +854,6 @@ impl StaticExporter {
885854
/// - SVG: Returns plain SVG text
886855
/// - PNG/JPEG/WEBP/PDF: Returns base64-encoded data
887856
///
888-
/// # Arguments
889-
///
890-
/// * `plot` - The Plotly plot data as a JSON value
891-
/// * `format` - The desired output image format
892-
/// * `width` - The width of the output image in pixels
893-
/// * `height` - The height of the output image in pixels
894-
/// * `scale` - The scale factor for the image (1.0 = normal size)
895-
///
896-
/// # Returns
897-
///
898857
/// Returns the image data as a string on success, or an error if the export
899858
/// fails.
900859
///
@@ -1120,15 +1079,24 @@ impl StaticExporter {
11201079
Ok(caps)
11211080
}
11221081

1123-
/// Get diagnostic information about the underlying WebDriver process
1082+
/// Get diagnostic information about the underlying WebDriver process.
11241083
///
11251084
/// This method provides detailed information about the WebDriver process
11261085
/// for debugging purposes, including process status, port information,
11271086
/// and connection details.
11281087
///
1129-
/// # Returns
1088+
/// Returns a string with diagnostic information.
1089+
///
1090+
/// # Examples
11301091
///
1131-
/// Returns a string with diagnostic information
1092+
/// ```rust
1093+
/// use plotly_static::StaticExporterBuilder;
1094+
///
1095+
/// let exporter = StaticExporterBuilder::default().build()?;
1096+
/// let diagnostics = exporter.get_webdriver_diagnostics();
1097+
/// println!("{}", diagnostics);
1098+
/// # Ok::<(), Box<dyn std::error::Error>>(())
1099+
/// ```
11321100
pub fn get_webdriver_diagnostics(&self) -> String {
11331101
self.webdriver.get_diagnostics()
11341102
}
@@ -1348,8 +1316,12 @@ mod tests {
13481316
}
13491317

13501318
#[test]
1319+
#[cfg(feature = "chromedriver")]
1320+
// Skip this test for geckodriver as it doesn't support multiple concurrent
1321+
// sessions on the same process as gracefully as chromedriver
13511322
fn test_webdriver_process_reuse() {
13521323
init();
1324+
13531325
let test_plot = create_test_plot();
13541326

13551327
// Use a unique port to test actual WebDriver process reuse

plotly_static/src/template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub(crate) const PDF_EXPORT_JS_SCRIPT: &str = r##"
9191
return new Promise(function(resolve) {
9292
img.onload = function() {
9393
// Brief delay to ensure image is fully rendered
94-
setTimeout(resolve, 150);
94+
setTimeout(resolve, 250);
9595
};
9696
img.onerror = function() {
9797
cleanup();

plotly_static/src/webdriver.rs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct WebDriver {
5959
}
6060

6161
impl WebDriver {
62-
/// Creates a new WebDriver instance for spawning
62+
/// Creates a new WebDriver instance for spawning.
6363
///
6464
/// This method creates a WebDriver instance that will later spawn a new
6565
/// process. It looks for the WebDriver binary in the following order:
@@ -68,12 +68,6 @@ impl WebDriver {
6868
/// 2. Build-time downloaded path (if `webdriver_download` feature is
6969
/// enabled)
7070
///
71-
/// # Arguments
72-
///
73-
/// * `port` - The port number for the WebDriver server
74-
///
75-
/// # Returns
76-
///
7771
/// Returns a `Result<WebDriver>` where:
7872
/// - `Ok(webdriver)` - Successfully created the WebDriver instance
7973
/// - `Err(e)` - Failed to create the instance (e.g., binary not found)
@@ -90,7 +84,7 @@ impl WebDriver {
9084
})
9185
}
9286

93-
/// Spawn a new WebDriver instance, connecting to existing if available
87+
/// Spawn a new WebDriver instance, connecting to existing if available.
9488
///
9589
/// This method provides WebDriver management:
9690
/// 1. First checks if a WebDriver is already running on the specified port
@@ -100,18 +94,12 @@ impl WebDriver {
10094
/// This approach allows for efficient resource usage and supports both
10195
/// scenarios where WebDriver is managed externally or needs to be spawned.
10296
///
103-
/// # Arguments
104-
///
105-
/// * `port` - The port number to check/use for WebDriver
106-
///
107-
/// # Returns
108-
///
10997
/// Returns a `Result<WebDriver>` where:
11098
/// - `Ok(webdriver)` - Successfully created or connected to WebDriver
11199
/// - `Err(e)` - Failed to create or connect to WebDriver
112100
pub(crate) fn connect_or_spawn(port: u32) -> Result<Self> {
113101
match Self::try_connect(port) {
114-
Some(external_instance) => Ok(external_instance),
102+
Some(active_instance) => Ok(active_instance),
115103
None => Self::spawn(port)
116104
.map_err(|e| anyhow!("Failed to spawn new WebDriver on port {}: {}", port, e)),
117105
}
@@ -153,6 +141,7 @@ impl WebDriver {
153141

154142
let mut wd = Self::new(port)?;
155143
wd.spawn_webdriver()?;
144+
156145
if Self::is_webdriver_running(port) {
157146
info!("Successfully created and started WebDriver on port {port}");
158147
Ok(wd)
@@ -382,15 +371,13 @@ impl WebDriver {
382371
))
383372
}
384373

385-
/// Stops the WebDriver process
374+
/// Stops the WebDriver process.
386375
///
387376
/// This method manages WebDriver process termination:
388377
/// - Only terminates processes that were spawned by this instance
389378
/// - Leaves externally managed WebDriver sessions running
390379
/// - Logs warnings when attempting to stop external sessions
391380
///
392-
/// # Returns
393-
///
394381
/// Returns `Ok(())` on success, or an error if the process termination
395382
/// fails.
396383
pub fn stop(&mut self) -> Result<()> {
@@ -415,15 +402,13 @@ impl WebDriver {
415402
Ok(())
416403
}
417404

418-
/// Get diagnostic information about the WebDriver process
405+
/// Get diagnostic information about the WebDriver process.
419406
///
420407
/// This method provides detailed information about the WebDriver process
421408
/// for debugging purposes.
422409
///
423-
/// # Returns
424-
///
425-
/// Returns a string with diagnostic information
426-
pub fn get_diagnostics(&self) -> String {
410+
/// Returns a string with diagnostic information.
411+
pub(crate) fn get_diagnostics(&self) -> String {
427412
let mut inner = self.inner.lock().unwrap();
428413
let mut diagnostics = String::new();
429414

@@ -528,20 +513,14 @@ impl WebDriver {
528513
diagnostics
529514
}
530515

531-
/// Check if a WebDriver is already running on the specified port
516+
/// Check if a WebDriver is already running on the specified port.
532517
///
533518
/// This method performs a WebDriver standard-compliant check by:
534519
/// 1. Making an HTTP GET request to `/status` endpoint
535520
/// 2. Checking for HTTP 200 response
536521
/// 3. Verifying the response contains "ready" indicating the service is
537522
/// ready
538523
///
539-
/// # Arguments
540-
///
541-
/// * `port` - The port number to check
542-
///
543-
/// # Returns
544-
///
545524
/// Returns `true` if WebDriver is running and ready, `false` otherwise.
546525
pub(crate) fn is_webdriver_running(port: u32) -> bool {
547526
let url = format!("{WEBDRIVER_URL}:{port}/status");

0 commit comments

Comments
 (0)