Skip to content

PhyloTree

Cargo featurefeatures = ["biology"]

PhyloTree reads a tree in Newick format (Newick::parse, which says where a malformed string goes wrong) and grows it from the root at the left, width pixels from the root to the leaves and row pixels between leaves:

  • Scale: when every branch has a length the tree is drawn to scale; otherwise it is a cladogram, with the leaves in one column.
  • Growth: from delay the branches draw outward one level every step seconds, and each leaf’s name appears as its branch arrives.
  • Traits: named inner nodes are traits shared by everything after them, marked on the branch that leads to them ((Mouse,Human)hair).
  • Highlight: highlight names a node whose clade turns highlight_color at highlight_at.

Names with spaces are quoted ('four limbs') or written with _. Gallery scene: PhyloTree (vertebrates, then the mammals).

PhyloTree demo, first frame
PhyloTree 7 s
use fframes_kit::prelude::*;
use fframes_kit::kits::biology::Newick;
let tree = Newick::parse("((Cat:1,Dog:1):2,Fish:3)root;").unwrap();
assert_eq!(tree.leaves(), ["Cat", "Dog", "Fish"]);
assert!(Newick::parse("((Cat,Dog)").is_err());
fn pets<'a>(ui: &mut Ui<'a, '_, '_>) -> Svgr<'a> {
ui.show(PhyloTree {
newick: "((Cat:1,Dog:1)mammals:2,Fish:3);".into(),
highlight: Some("mammals".into()),
highlight_at: 3.0,
..ui.defaults()
})
}

Components are plain structs. Set the fields you need and fill the rest with ..ui.defaults(): the defaults below come from the current theme (theme. values are fields of Theme).

Field Type Default Description
newick String — The tree in Newick notation, e.g. ((a:1,b:1)c:2,d:3);; branch lengths are optional.
delay f32 0.0 Seconds after the container’s start before the first branches draw.
step f32 0.55 Seconds each level of branches takes to draw outward.
center (f64, f64) (-0.7, -0.4) The middle of the tree, in units of ui.space.
width f32 1000.0 Pixels from the root to the leaves.
row f32 66.0 Pixels between neighbouring leaves.
highlight Option<String> None Name of a node whose clade is highlighted; None for none.
highlight_at f32 0.0 Seconds after delay when the highlighted clade starts to turn highlight_color.
branch_color Color theme.colors.muted Colour of the branches.
highlight_color Color theme.colors.accent Colour the highlighted clade turns.
trait_color Color Color::hex("#ffd43b") Colour of the trait marks and names on the branches.
name_style TextStyle theme.typography.caption The font of the leaf names: family, size in pixels and weight.
trait_style TextStyle trait_style The font of the trait names: family, size in pixels and weight.
text_color Color theme.colors.text Colour of the leaf names.
enter Option<FadeIn> None Fade in at the start; None for none.
exit Option<FadeOut> None Fade out before the end; None for none.

Feature biology · Source