diff --git a/examples/test_bckg_color.rs b/examples/test_bckg_color.rs new file mode 100644 index 0000000..3814e92 --- /dev/null +++ b/examples/test_bckg_color.rs @@ -0,0 +1,70 @@ +// Display a reconciled tree form recPhyloXML format + +use light_phylogeny::{ArenaTree,Options,Config,read_recphyloxml_multi,recphyloxml_processing,phyloxml_processing}; +// use std::env; + +fn main() { + + + // ============================================================================================ + let transfers = vec![]; + let mut options: Options = Options::new(); + let config: Config = Config::new(); + let mut sp_tree: ArenaTree = ArenaTree::default(); + let mut gene_trees:std::vec::Vec> = Vec::new(); + let mut global_roots: std::vec::Vec = Vec::new(); + + + options.node_colors.push("03_duplication".to_string()); + options.node_colors.push("b4_duplication".to_string()); + + read_recphyloxml_multi("examples/example_dupli.recphylo".to_string(), + &mut sp_tree, &mut gene_trees, &mut global_roots); + recphyloxml_processing(&mut sp_tree, &mut gene_trees, &mut options, &config, true, + &transfers, "test_bckg_default.svg".to_string()); + println!("Please open output file 'test_bckg_1.svg' with your browser"); + + // ============================================================================================ + let transfers = vec![]; + let mut options: Options = Options::new(); + let config: Config = Config::new(); + let mut sp_tree: ArenaTree = ArenaTree::default(); + let mut gene_trees:std::vec::Vec> = Vec::new(); + let mut global_roots: std::vec::Vec = Vec::new(); + + + options.node_colors.push("03_duplication".to_string()); + options.node_colors.push("b4_duplication".to_string()); + + options.bckg_color = "Black".to_string(); + + + read_recphyloxml_multi("examples/example_dupli.recphylo".to_string(), + &mut sp_tree, &mut gene_trees, &mut global_roots); + recphyloxml_processing(&mut sp_tree, &mut gene_trees, &mut options, &config, true, + &transfers, "test_bckg_black.svg".to_string()); + println!("Please open output file 'test_bckg_black.svg' with your browser"); + + + // ============================================================================================ + let transfers = vec![]; + let mut options: Options = Options::new(); + let config: Config = Config::new(); + let mut sp_tree: ArenaTree = ArenaTree::default(); + let mut gene_trees:std::vec::Vec> = Vec::new(); + let mut global_roots: std::vec::Vec = Vec::new(); + + + options.node_colors.push("03_duplication".to_string()); + options.node_colors.push("b4_duplication".to_string()); + + options.bckg_color = "#E9C78C".to_string(); + + + read_recphyloxml_multi("examples/example_dupli.recphylo".to_string(), + &mut sp_tree, &mut gene_trees, &mut global_roots); + recphyloxml_processing(&mut sp_tree, &mut gene_trees, &mut options, &config, true, + &transfers, "test_bckg_sepia.svg".to_string()); + println!("Please open output file 'test_bckg_sepia.svg' with your browser"); +} + diff --git a/src/arena.rs b/src/arena.rs index edcb583..db7baf7 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -442,7 +442,9 @@ pub struct Options{ /// user-defined list of colors for genes pub gene_colors: Vec, /// user-defined list of nodes for genes. Children of nodes will be colorised - pub node_colors: Vec + pub node_colors: Vec, + /// svg background color + pub bckg_color: String } impl Options { pub fn new() -> Self { @@ -481,6 +483,7 @@ impl Options { mid_dist:false, gene_colors: Vec::new(), node_colors: Vec::new(), + bckg_color: "White".to_string(), } } } diff --git a/src/drawing.rs b/src/drawing.rs index 8e5d551..c68a9c5 100644 --- a/src/drawing.rs +++ b/src/drawing.rs @@ -59,7 +59,8 @@ pub fn draw_tree ( y_viewbox, height_svg + 2.0 *BLOCK, width_svg + 2.0 *BLOCK, - )), + )) + .set("style","background-color:".to_owned() + &options.bckg_color), false => Document::new() .set("width", width_svg) .set("height", height_svg) @@ -68,7 +69,8 @@ pub fn draw_tree ( y_viewbox, width_svg + 2.0 *BLOCK, height_svg + 2.0 *BLOCK, - )), + )) + .set("style","background-color:".to_owned() + &options.bckg_color), }; let style = Style::new(".gene { font-size: ".to_owned() + &config.gene_police_size.to_string() + "px; fill:" @@ -350,7 +352,8 @@ pub fn draw_sptree_gntrees ( height_svg * 1.1 + 2.0 * BLOCK, width_svg + 2.0 * BLOCK, ) - ), + ) + .set("style","background-color:".to_owned() + &options.bckg_color), false => Document::new() .set("width",width_svg) .set("height",height_svg) @@ -360,8 +363,10 @@ pub fn draw_sptree_gntrees ( width_svg + 0.5 *BLOCK, height_svg *1.1 + 0.5 *BLOCK, ) - ), + ) + .set("style","background-color:".to_owned() + &options.bckg_color), }; + // Initialse la chaine de carctere dediee aux styles des fonts : font pour l'espece let mut recphylostyle:String = ".species { font: italic ".to_owned() + "; font-size: " + &config.species_police_size.to_string() + "px; fill: " @@ -926,6 +931,10 @@ pub fn draw_sptree_gntrees ( let add_style_str :&str = &added_style; recphylostyle.push_str(add_style_str); } + + + + // Ajout le style let style = Style::new(recphylostyle); document.append(style);