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,48 @@ 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
26+ /// configuration is used.
27+ ///
28+ /// # Arguments
29+ ///
30+ /// * `plot` - The plot to write to HTML
31+ /// * `name` - The base name for the HTML files (without extension)
32+ /// * `inline_config` - The configuration to use for the inline HTML file
33+ ///
34+ /// # Returns the path to the standalone HTML file
35+ pub fn write_example_to_html_with_inline_config (
36+ plot : & Plot ,
37+ name : & str ,
38+ inline_config : Option < Configuration > ,
39+ ) -> String {
1840 std:: fs:: create_dir_all ( "./output" ) . unwrap ( ) ;
41+
42+ let standalone_config = plot. configuration ( ) . clone ( ) ;
43+ let inline_config = inline_config. unwrap_or ( standalone_config. clone ( ) ) ;
44+
1945 // 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 ( ) ;
46+ let mut inline_plot = plot. clone ( ) ;
47+ inline_plot. set_configuration ( inline_config) ;
48+ let html = inline_plot. to_inline_html ( Some ( name) ) ;
49+ let inline_path = format ! ( "./output/inline_{name}.html" ) ;
50+ std:: fs:: write ( inline_path, html) . unwrap ( ) ;
51+
2352 // Write standalone HTML
53+ let mut standalone_plot = plot. clone ( ) ;
54+ standalone_plot. set_configuration ( standalone_config) ;
2455 let path = format ! ( "./output/{name}.html" ) ;
25- plot . write_html ( & path) ;
56+ standalone_plot . write_html ( & path) ;
2657 path
2758}
0 commit comments