1- use plotly:: Plot ;
1+ use plotly:: { Configuration , Plot } ;
22
33/// Write a plot to HTML files for documentation and display
44///
@@ -11,17 +11,47 @@ use plotly::Plot;
1111/// * `plot` - The plot to write to HTML
1212/// * `name` - The base name for the HTML files (without extension)
1313///
14- /// # Returns
15- ///
16- /// The path to the standalone HTML file
14+ /// # Returns the path to the standalone HTML file
1715pub fn write_example_to_html ( plot : & Plot , name : & str ) -> String {
16+ write_example_to_html_with_inline_config ( plot, name, None )
17+ }
18+
19+ /// Write a plot to HTML files for documentation and display
20+ ///
21+ /// This function creates both an inline HTML file (for mdbook inclusion) and
22+ /// a standalone HTML file (for direct viewing). The inline file is prefixed
23+ /// with "inline_" and both files are placed in the "./output" directory.
24+ /// The plot for inline HTML display can be configured with the provided
25+ /// `inline_config` when provided, otherwise the standalone inherited plot configuration is used.
26+ ///
27+ /// # Arguments
28+ ///
29+ /// * `plot` - The plot to write to HTML
30+ /// * `name` - The base name for the HTML files (without extension)
31+ /// * `inline_config` - The configuration to use for the inline HTML file
32+ ///
33+ /// # Returns the path to the standalone HTML file
34+ pub fn write_example_to_html_with_inline_config (
35+ plot : & Plot ,
36+ name : & str ,
37+ inline_config : Option < Configuration > ,
38+ ) -> String {
1839 std:: fs:: create_dir_all ( "./output" ) . unwrap ( ) ;
40+
41+ let standalone_config = plot. configuration ( ) . clone ( ) ;
42+ let inline_config = inline_config. unwrap_or ( standalone_config. clone ( ) ) ;
43+
1944 // Write inline HTML
20- let html = plot. to_inline_html ( Some ( name) ) ;
21- let path = format ! ( "./output/inline_{name}.html" ) ;
22- std:: fs:: write ( path, html) . unwrap ( ) ;
45+ let mut inline_plot = plot. clone ( ) ;
46+ inline_plot. set_configuration ( inline_config) ;
47+ let html = inline_plot. to_inline_html ( Some ( name) ) ;
48+ let inline_path = format ! ( "./output/inline_{name}.html" ) ;
49+ std:: fs:: write ( inline_path, html) . unwrap ( ) ;
50+
2351 // Write standalone HTML
52+ let mut standalone_plot = plot. clone ( ) ;
53+ standalone_plot. set_configuration ( standalone_config) ;
2454 let path = format ! ( "./output/{name}.html" ) ;
25- plot . write_html ( & path) ;
55+ standalone_plot . write_html ( & path) ;
2656 path
2757}
0 commit comments