Sign in

    This version of the module is deprecated: Moved to moonbit-community/moon_dagre. Please migrate your dependency and import paths to moonbit-community/moon_dagre.

    moon_dagre

    Dagre layout engine implemented in MoonBit

    layout
    Download zip
    Author
    Version
    0.2.5
    License
    Apache-2.0
    Last updated
    6 months ago
    Downloads
    1K

    #Milky2018/moon_dagre

    A MoonBit port of the dagre graph layout engine.

    #Install

    moon add Milky2018/moon_dagre

    #Basic Usage

    moon.pkg:
    import { "Milky2018/moon_dagre" @dagre, }

    main.mbt:
    ///|
    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"), ...
    }

    #API

    • Entry points:
      • dagre.new_graph(...)
      • dagre.layout(g)
    • Version:
      • dagre.version()

    For full exported symbols, check pkg.generated.mbti.

    Attr

    pub enum Attr {
    Bool(Bool)
    Int(Int)
    Float(Double)
    String(String)
    Val(Value)
    Point(Point)
    Points(Array[Point])
    Edge(EdgeObj)
    Edges(Array[EdgeObj])
    Strings(Array[String])
    Ints(Array[Int])
    }

    Attrs

    pub struct Attrs {
    map : Map[String, Attr]
    }

    Attrs::contains

    fn Attrs::contains(self : Attrs, key : String) -> Bool

    Attrs::get

    fn Attrs::get(self : Attrs, key : String) -> Attr?

    Attrs::get_bool

    fn Attrs::get_bool(self : Attrs, key : String) -> Bool?

    Attrs::get_bool_or

    fn Attrs::get_bool_or(self : Attrs, key : String, fallback : Bool) -> Bool

    Attrs::get_edge

    fn Attrs::get_edge(self : Attrs, key : String) -> EdgeObj?

    Attrs::get_edges

    fn Attrs::get_edges(self : Attrs, key : String) -> Array[EdgeObj]?

    Attrs::get_float

    fn Attrs::get_float(self : Attrs, key : String) -> Double?

    Attrs::get_float_or

    fn Attrs::get_float_or(self : Attrs, key : String, fallback : Double) -> Double

    Attrs::get_int

    fn Attrs::get_int(self : Attrs, key : String) -> Int?

    Attrs::get_int_or

    fn Attrs::get_int_or(self : Attrs, key : String, fallback : Int) -> Int

    Attrs::get_ints

    fn Attrs::get_ints(self : Attrs, key : String) -> Array[Int]?

    Attrs::get_point

    fn Attrs::get_point(self : Attrs, key : String) -> Point?

    Attrs::get_points

    fn Attrs::get_points(self : Attrs, key : String) -> Array[Point]?

    Attrs::get_string

    fn Attrs::get_string(self : Attrs, key : String) -> String?

    Attrs::get_string_or

    fn Attrs::get_string_or(self : Attrs, key : String, fallback : String) -> String

    Attrs::get_strings

    fn Attrs::get_strings(self : Attrs, key : String) -> Array[String]?

    Attrs::get_value

    fn Attrs::get_value(self : Attrs, key : String) -> Value?

    Attrs::keys

    fn Attrs::keys(self : Attrs) -> Array[String]

    Attrs::length

    fn Attrs::length(self : Attrs) -> Int

    Attrs::remove

    fn Attrs::remove(self : Attrs, key : String) -> Unit

    Attrs::set

    fn Attrs::set(self : Attrs, key : String, value : Attr) -> Unit

    Attrs::set_bool

    fn Attrs::set_bool(self : Attrs, key : String, value : Bool) -> Unit

    Attrs::set_edge

    fn Attrs::set_edge(self : Attrs, key : String, value : EdgeObj) -> Unit

    Attrs::set_edges

    fn Attrs::set_edges(self : Attrs, key : String, value : Array[EdgeObj]) -> Unit

    Attrs::set_float

    fn Attrs::set_float(self : Attrs, key : String, value : Double) -> Unit

    Attrs::set_int

    fn Attrs::set_int(self : Attrs, key : String, value : Int) -> Unit

    Attrs::set_ints

    fn Attrs::set_ints(self : Attrs, key : String, value : Array[Int]) -> Unit

    Attrs::set_point

    fn Attrs::set_point(self : Attrs, key : String, value : Point) -> Unit

    Attrs::set_points

    fn Attrs::set_points(self : Attrs, key : String, value : Array[Point]) -> Unit

    Attrs::set_string

    fn Attrs::set_string(self : Attrs, key : String, value : String) -> Unit

    Attrs::set_strings

    fn Attrs::set_strings(self : Attrs, key : String, value : Array[String]) -> Unit

    Attrs::set_value

    fn Attrs::set_value(self : Attrs, key : String, value : Value) -> Unit

    EdgeObj

    pub struct EdgeObj {
    v : String
    w : String
    name : String?
    }

    EdgeRecord

    type EdgeRecord

    Graph

    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
    }

    Graph::children

    fn Graph::children(self : Graph, v? : String) -> Array[String]

    Graph::edge

    fn Graph::edge(self : Graph, v : String, w : String, name? : String) -> Value?

    Graph::edge_count

    fn Graph::edge_count(self : Graph) -> Int

    Graph::edge_obj

    fn Graph::edge_obj(self : Graph, e : EdgeObj) -> Value?

    Graph::edges

    fn Graph::edges(self : Graph) -> Array[EdgeObj]

    Graph::graph

    fn Graph::graph(self : Graph) -> Attrs

    Graph::has_edge

    fn Graph::has_edge(self : Graph, v : String, w : String, name? : String) -> Bool

    Graph::has_node

    fn Graph::has_node(self : Graph, v : String) -> Bool

    Graph::in_edges

    fn Graph::in_edges(self : Graph, v : String, u? : String) -> Array[EdgeObj]

    Graph::is_compound

    fn Graph::is_compound(self : Graph) -> Bool

    Graph::is_directed

    fn Graph::is_directed(self : Graph) -> Bool

    Graph::is_multigraph

    fn Graph::is_multigraph(self : Graph) -> Bool

    Graph::neighbors

    fn Graph::neighbors(self : Graph, v : String) -> Array[String]

    Graph::new

    fn Graph::new(directed? : Bool, multigraph? : Bool, compound? : Bool) -> Graph

    Graph::node

    fn Graph::node(self : Graph, v : String) -> Attrs

    Graph::node_count

    fn Graph::node_count(self : Graph) -> Int

    Graph::node_edges

    fn Graph::node_edges(self : Graph, v : String, w? : String) -> Array[EdgeObj]

    Graph::node_opt

    fn Graph::node_opt(self : Graph, v : String) -> Attrs?

    Graph::nodes

    fn Graph::nodes(self : Graph) -> Array[String]

    Graph::out_edges

    fn Graph::out_edges(self : Graph, v : String, w? : String) -> Array[EdgeObj]

    Graph::parent

    fn Graph::parent(self : Graph, v : String) -> String?

    Graph::predecessors

    fn Graph::predecessors(self : Graph, v : String) -> Array[String]

    Graph::remove_edge

    fn Graph::remove_edge(self : Graph, v : String, w : String, name? : String) -> Unit

    Graph::remove_edge_obj

    fn Graph::remove_edge_obj(self : Graph, e : EdgeObj) -> Unit

    Graph::remove_node

    fn Graph::remove_node(self : Graph, v : String) -> Unit

    Graph::set_default_edge_label

    fn Graph::set_default_edge_label(self : Graph, f : () -> Value) -> Unit

    Graph::set_edge

    fn Graph::set_edge(self : Graph, v : String, w : String, label? : Value, name? : String) -> Unit

    Graph::set_edge_obj

    fn Graph::set_edge_obj(self : Graph, e : EdgeObj, label? : Value) -> Unit

    Graph::set_graph

    fn Graph::set_graph(self : Graph, label : Attrs) -> Unit

    Graph::set_node

    fn Graph::set_node(self : Graph, v : String, label? : Attrs) -> Unit

    Graph::set_nodes

    fn Graph::set_nodes(self : Graph, vs : Array[String], label? : Attrs) -> Unit

    Graph::set_parent

    fn Graph::set_parent(self : Graph, v : String, parent? : String) -> Unit

    Graph::set_path

    fn Graph::set_path(self : Graph, vs : Array[String], label? : Value) -> Unit

    Graph::sinks

    fn Graph::sinks(self : Graph) -> Array[String]

    Graph::sources

    fn Graph::sources(self : Graph) -> Array[String]

    Graph::successors

    fn Graph::successors(self : Graph, v : String) -> Array[String]

    OrderBarycenterEntry

    pub struct OrderBarycenterEntry {
    v : String
    barycenter : Double?
    weight : Double?
    }

    OrderEntry

    pub struct OrderEntry {
    vs : Array[String]
    i : Int
    barycenter : Double?
    weight : Double?
    }

    OrderResult

    pub struct OrderResult {
    vs : Array[String]
    barycenter : Double?
    weight : Double?
    }

    Partition

    pub struct Partition[T] {
    lhs : Array[T]
    rhs : Array[T]
    }

    Point

    pub struct Point {
    x : Double
    y : Double
    }

    PositionBkAlignment

    pub struct PositionBkAlignment {
    root : Map[String, String]
    align : Map[String, String]
    }

    Rect

    pub struct Rect {
    x : Double
    y : Double
    width : Double
    height : Double
    }

    Value

    pub enum Value {
    VNull
    VBool(Bool)
    VInt(Int)
    VFloat(Double)
    VString(String)
    VAttrs(Attrs)
    }

    acyclic_run

    fn acyclic_run(g : Graph) -> Unit

    acyclic_undo

    fn acyclic_undo(g : Graph) -> Unit

    add_border_node

    fn add_border_node(g : Graph, prefix : String, rank? : Int, order? : Int) -> String

    add_border_segments

    fn add_border_segments(g : Graph) -> Unit

    add_dummy_node

    fn add_dummy_node(g : Graph, typ : String, attrs : Attrs, name : String) -> String

    apply_with_chunking_max

    fn apply_with_chunking_max(values : Array[Int]) -> Int

    apply_with_chunking_min

    fn apply_with_chunking_min(values : Array[Int]) -> Int

    as_non_compound_graph

    fn as_non_compound_graph(g : Graph) -> Graph

    attrs_value

    fn attrs_value(attrs : Attrs) -> Value

    build_layer_matrix

    fn build_layer_matrix(g : Graph) -> Array[Array[String]]

    clone_attrs

    fn clone_attrs(attrs : Attrs) -> Attrs

    clone_value

    fn clone_value(value : Value) -> Value

    components

    fn components(g : Graph) -> Array[Array[String]]

    coordinate_adjust

    fn coordinate_adjust(g : Graph) -> Unit

    coordinate_undo

    fn coordinate_undo(g : Graph) -> Unit

    edge_obj

    fn edge_obj(v : String, w : String, name? : String) -> EdgeObj

    empty_attrs

    fn empty_attrs() -> Attrs

    find_cycles

    fn find_cycles(g : Graph) -> Array[Array[String]]

    greedy_fas

    fn greedy_fas(g : Graph, weight_fn? : (EdgeObj) -> Double) -> Array[EdgeObj]

    intersect_rect

    fn intersect_rect(rect : Rect, pt : Point) -> Point

    layout

    fn layout(g : Graph, debug_timing? : Bool) -> Graph

    layout_layout_graph_debug

    fn layout_layout_graph_debug(input_graph : Graph, stop_before_remove_border_nodes? : Bool, stop_after_rank? : Bool, stop_after_order? : Bool, stop_after_normalize_undo? : Bool, stop_after_coordinate_undo? : Bool, stop_after_translate_graph? : Bool) -> Graph

    layout_run

    fn layout_run(g : Graph, debug_timing? : Bool) -> Graph

    map_values

    fn[V, U] map_values(obj : Map[String, V], f : (V, String) -> U) -> Map[String, U]

    map_values_prop

    fn map_values_prop(obj : Map[String, Attrs], prop : String) -> Map[String, Attr]

    max_rank

    fn max_rank(g : Graph) -> Int

    nesting_graph_cleanup

    fn nesting_graph_cleanup(g : Graph) -> Unit

    nesting_graph_run

    fn nesting_graph_run(g : Graph) -> Unit

    new_graph

    fn new_graph(directed? : Bool, multigraph? : Bool, compound? : Bool) -> Graph

    normalize_ranks

    fn normalize_ranks(g : Graph) -> Unit

    normalize_run

    fn normalize_run(g : Graph) -> Unit

    normalize_undo

    fn normalize_undo(g : Graph) -> Unit

    notime

    fn[T] notime(name : String, thunk : () -> T) -> T

    order_add_subgraph_constraints

    fn order_add_subgraph_constraints(g : Graph, cg : Graph, vs : Array[String]) -> Unit

    order_bary_entry

    fn order_bary_entry(v : String, barycenter? : Double?, weight? : Double?) -> OrderBarycenterEntry

    order_barycenter

    fn order_barycenter(g : Graph, movable? : Array[String]) -> Array[OrderBarycenterEntry]

    order_build_layer_graph

    fn order_build_layer_graph(g : Graph, rank : Int, relationship : String) -> Graph

    order_cross_count

    fn order_cross_count(g : Graph, layering : Array[Array[String]]) -> Double

    order_entry

    fn order_entry(vs : Array[String], i : Int, barycenter? : Double?, weight? : Double?) -> OrderEntry

    order_init_order

    fn order_init_order(g : Graph) -> Array[Array[String]]

    order_resolve_conflicts

    fn order_resolve_conflicts(entries : Array[OrderBarycenterEntry], cg : Graph) -> Array[OrderEntry]

    order_result

    fn order_result(vs : Array[String], barycenter? : Double?, weight? : Double?) -> OrderResult

    order_run

    fn order_run(g : Graph) -> Unit

    order_sort

    fn order_sort(entries : Array[OrderEntry], bias_right? : Bool) -> OrderResult

    order_sort_subgraph

    fn order_sort_subgraph(g : Graph, v : String, cg : Graph, bias_right? : Bool) -> OrderResult

    parent_dummy_chains

    fn parent_dummy_chains(g : Graph) -> Unit

    partition

    fn[T] partition(collection : Array[T], predicate : (T) -> Bool) -> Partition[T]

    pick

    fn pick(source : Attrs, keys : Array[String]) -> Attrs

    point

    fn point(x : Double, y : Double) -> Point

    position

    fn position(g : Graph) -> Unit

    position_bk_add_conflict

    fn position_bk_add_conflict(conflicts : Map[String,
    Set
    [String]], v : String, w : String) -> Unit

    position_bk_align_coordinates

    fn position_bk_align_coordinates(xss : Map[String, Map[String, Double]], align_to : Map[String, Double]) -> Unit

    position_bk_balance

    fn position_bk_balance(xss : Map[String, Map[String, Double]], align? : String) -> Map[String, Double]

    position_bk_find_smallest_width_alignment

    fn position_bk_find_smallest_width_alignment(g : Graph, xss : Map[String, Map[String, Double]]) -> Map[String, Double]

    position_bk_find_type1_conflicts

    fn position_bk_find_type1_conflicts(g : Graph, layering : Array[Array[String]]) -> Map[String,
    Set
    [String]]

    position_bk_find_type2_conflicts

    fn position_bk_find_type2_conflicts(g : Graph, layering : Array[Array[String]]) -> Map[String,
    Set
    [String]]

    position_bk_has_conflict

    fn position_bk_has_conflict(conflicts : Map[String,
    Set
    [String]], v : String, w : String) -> Bool

    position_bk_horizontal_compaction

    fn position_bk_horizontal_compaction(g : Graph, layering : Array[Array[String]], root : Map[String, String], align : Map[String, String], reverse_sep? : Bool) -> Map[String, Double]

    position_bk_vertical_alignment

    fn position_bk_vertical_alignment(g : Graph, layering : Array[Array[String]], conflicts : Map[String,
    Set
    [String]], neighbor_fn : (String) -> Array[String]) -> PositionBkAlignment

    position_bk_x

    fn position_bk_x(g : Graph) -> Map[String, Double]

    position_x

    fn position_x(g : Graph) -> Map[String, Double]

    position_y

    fn position_y(g : Graph) -> Unit

    postorder

    fn postorder(g : Graph, roots : Array[String]) -> Array[String]

    predecessor_weights

    fn predecessor_weights(g : Graph) -> Map[String, Map[String, Double]]

    preorder

    fn preorder(g : Graph, roots : Array[String]) -> Array[String]

    range

    fn range(start : Int, limit? : Int, step? : Int) -> Array[Int]

    rank

    fn rank(g : Graph) -> Unit

    rank_feasible_tree

    fn rank_feasible_tree(g : Graph) -> Graph

    rank_longest_path

    fn rank_longest_path(g : Graph) -> Unit

    rank_network_simplex

    fn rank_network_simplex(g : Graph) -> Unit

    rank_network_simplex_calc_cut_value

    fn rank_network_simplex_calc_cut_value(t : Graph, g : Graph, child : String) -> Int

    rank_network_simplex_enter_edge

    fn rank_network_simplex_enter_edge(t : Graph, g : Graph, edge : EdgeObj) -> EdgeObj

    rank_network_simplex_exchange_edges

    fn rank_network_simplex_exchange_edges(t : Graph, g : Graph, leaving_edge : EdgeObj, entering_edge : EdgeObj) -> Unit

    rank_network_simplex_init_cut_values

    fn rank_network_simplex_init_cut_values(t : Graph, g : Graph) -> Unit

    rank_network_simplex_init_low_lim_values

    fn rank_network_simplex_init_low_lim_values(tree : Graph, root? : String) -> Unit

    rank_network_simplex_leave_edge

    fn rank_network_simplex_leave_edge(tree : Graph) -> EdgeObj?

    rank_slack

    fn rank_slack(g : Graph, e : EdgeObj) -> Int

    rect

    fn rect(x : Double, y : Double, width : Double, height : Double) -> Rect

    remove_empty_ranks

    fn remove_empty_ranks(g : Graph) -> Unit

    simplify

    fn simplify(g : Graph) -> Graph

    successor_weights

    fn successor_weights(g : Graph) -> Map[String, Map[String, Double]]

    time

    fn[T] time(name : String, thunk : () -> T) -> T

    value_as_attrs

    fn value_as_attrs(value : Value?) -> Attrs?

    value_as_bool

    fn value_as_bool(value : Value?) -> Bool?

    value_as_float

    fn value_as_float(value : Value?) -> Double?

    value_as_int

    fn value_as_int(value : Value?) -> Int?

    value_as_string

    fn value_as_string(value : Value?) -> String?

    value_bool

    fn value_bool(v : Bool) -> Value

    value_float

    fn value_float(v : Double) -> Value

    value_int

    fn value_int(v : Int) -> Value

    value_null

    fn value_null() -> Value

    value_string

    fn value_string(v : String) -> Value

    version

    fn version() -> String

    zip_object

    fn[T] zip_object(props : Array[String], values : Array[T]) -> Map[String, T]