Skip to content

Commit

Permalink
Fix non-subgraph nodes missing in Mermaid output
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed May 13, 2023
1 parent 3726fba commit 6de7454
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ocamlgraph_extra/mermaid.ml
Expand Up @@ -20,9 +20,11 @@ struct
let fprint_graph ppf g =
let module SG = Map.Make(String) in
let subgraphs = ref SG.empty in
let root_vertices = ref [] in
X.iter_vertex (function node ->
match X.get_subgraph node with
| None -> () (* TODO: print also *)
| None ->
root_vertices := node :: !root_vertices
| Some sg ->
let (sg, nodes) =
if SG.mem sg.sg_name !subgraphs then
Expand Down Expand Up @@ -55,6 +57,10 @@ struct
()
in

let print_root_vertices ppf =
pp_print_list print_vertex ppf !root_vertices
in

let rec print_subgraph ppf name =
let sg, nodes = SG.find name !subgraphs in
let children = SG.filter (fun _ (sg, _) -> sg.Graphviz.DotAttributes.sg_parent = Some name) !subgraphs in
Expand Down Expand Up @@ -101,7 +107,8 @@ struct
) g
in

fprintf ppf "@[<v 2>flowchart TD@ %t@ %t@]"
fprintf ppf "@[<v 2>flowchart TD@ %t@ %t@ %t@]"
print_root_vertices
print_subgraphs
print_edges
end

0 comments on commit 6de7454

Please sign in to comment.