Skip to content

Commit

Permalink
Add option of background color
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpenel committed May 23, 2024
1 parent c5b4d44 commit 96cfc68
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
70 changes: 70 additions & 0 deletions examples/test_bckg_color.rs
Original file line number Diff line number Diff line change
@@ -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<String> = ArenaTree::default();
let mut gene_trees:std::vec::Vec<ArenaTree<String>> = Vec::new();
let mut global_roots: std::vec::Vec<usize> = 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<String> = ArenaTree::default();
let mut gene_trees:std::vec::Vec<ArenaTree<String>> = Vec::new();
let mut global_roots: std::vec::Vec<usize> = 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<String> = ArenaTree::default();
let mut gene_trees:std::vec::Vec<ArenaTree<String>> = Vec::new();
let mut global_roots: std::vec::Vec<usize> = 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");
}

5 changes: 4 additions & 1 deletion src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ pub struct Options{
/// user-defined list of colors for genes
pub gene_colors: Vec<String>,
/// user-defined list of nodes for genes. Children of nodes will be colorised
pub node_colors: Vec<String>
pub node_colors: Vec<String>,
/// svg background color
pub bckg_color: String
}
impl Options {
pub fn new() -> Self {
Expand Down Expand Up @@ -481,6 +483,7 @@ impl Options {
mid_dist:false,
gene_colors: Vec::new(),
node_colors: Vec::new(),
bckg_color: "White".to_string(),
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:"
Expand Down Expand Up @@ -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)
Expand All @@ -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: "
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 96cfc68

Please sign in to comment.