Skip to content
Tree

Tree

A tree diagram.

Tree

Usage

from dataviz_mojo import tree
from dataviz_mojo.plot import save

def main() raises:
    var ids: List[String] = [
        "CEO", "Engineering", "Sales", "Backend", "Frontend", "Enterprise", "SMB",
    ]
    var parent_ids: List[String] = ["", "CEO", "CEO", "Engineering", "Engineering", "Sales", "Sales"]
    var values: List[Float64] = [0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0]

    var c = tree(ids, parent_ids, values)
    save(c, "docs/src/examples/out_tree.svg")

Args:

  • ids: Every node’s unique id, flattened (not nested), one entry per node.
  • parent_ids: Each node’s parent id (must be a value present in ids, or empty for the single root); paired with ids[i].
  • values: Each leaf node’s magnitude (unused by tree()’s own layout, but still validated non-negative – see Plot. encode_hierarchy()’s docstring).
  • theme: Full styling knobs beyond this function’s own parameters (colors, margins, fonts, gridlines, …) – see Theme’s docstring.
  • width: Pixel width of the returned Plot (.size()).
  • height: Pixel height of the returned Plot (.size()).
  • title: The chart’s title, shown above the plot.
  • subtitle: A secondary line shown under the title.
  • x_title: The x-axis caption.
  • y_title: The y-axis caption.