Dagre layout engine implemented in MoonBit
moon add Milky2018/moon_dagreimport {
"Milky2018/moon_dagre" @dagre,
}///|
fn main {
let g = dagre.new_graph(directed=true, multigraph=true, compound=true)
g.set_node(
"a",
label=dagre
.empty_attrs()
.tap(n => {
n.set_float("width", 80.0)
n.set_float("height", 40.0)
}),
)
g.set_node(
"b",
label=dagre
.empty_attrs()
.tap(n => {
n.set_float("width", 80.0)
n.set_float("height", 40.0)
}),
)
g.set_edge("a", "b", label=dagre.attrs_value(dagre.empty_attrs()))
dagre.layout(g)
// Read computed coordinates from node labels:
// g.node("a").get_float("x"), g.node("a").get_float("y"), ...
}pub struct Graph {
directed : Bool
multigraph : Bool
compound : Bool
graph_label : Attrs
nodes : Map[String, Attrs]
node_order : Array[String]
node_index : Map[String, Int]
node_seen : Set[String]
edges : Map[String, EdgeRecord]
edge_order : Array[String]
edge_seen : Set[String]
parent_by_node : Map[String, String]
children_by_node : Map[String, Set[String]]
child_seq : Int
child_add_index : Map[String, Int]
default_edge_label_fn : () -> Value
fn new(directed? : Bool, multigraph? : Bool, compound? : Bool) -> Graph
}pub struct OrderBarycenterEntry {
v : String
barycenter : Double?
weight : Double?
}Dagre layout engine implemented in MoonBit