module type GraphvizFormatter =
sig
val header:
+ ?graph_type:string ->
?name:string -> ?graph_attrs:(attribute list) ->
?node_attrs:(attribute list) -> ?edge_attrs:(attribute list) ->
Format.formatter ->
struct
let attribute fmt (k, v) = fprintf fmt "@[<hv2>%s=@,\"%s\",@]" k v
let attributes attrs fmt = List.iter (attribute fmt) attrs
+ let quote_string quote s = if quote then "\"" ^s ^ "\"" else s
let node name ~quote ?(attrs = []) fmt =
- let quote_string = if quote then "\"" else "" in
- fprintf fmt "@[<hov2>%s%s%s@ [" quote_string name quote_string;
+ fprintf fmt "@[<hov2>%s@ [" (quote_string quote name);
attributes attrs fmt;
fprintf fmt "];@]@,"
- let header ?(name = "g") ?(graph_attrs = []) ?node_attrs ?edge_attrs fmt =
- fprintf fmt "@[<hv2>strict digraph %s {@," name;
+ let edge ~quote name1 name2 ?(attrs = []) fmt =
+ fprintf fmt "@[<hov2>%s ->@ %s@ ["
+ (quote_string quote name1) (quote_string quote name2);
+ attributes attrs fmt;
+ fprintf fmt "];@]@,"
+
+ let header ?(graph_type = "digraph") ?(name = "g") ?(graph_attrs = []) ?node_attrs ?edge_attrs fmt =
+ fprintf fmt "@[<hv2>%s %s {@," graph_type name;
List.iter (fun (k, v) -> fprintf fmt "@[<hv2>%s=@,%s;@]@," k v)
graph_attrs;
(match node_attrs with
| None -> ())
let node = node ~quote:true
- let edge name1 name2 ?(attrs = []) fmt =
- fprintf fmt "@[<hov2>\"%s\" ->@ \"%s\"@ [" name1 name2;
- attributes attrs fmt;
- fprintf fmt "];@]@,"
+ let edge = edge ~quote:true
let raw s fmt = pp_print_string fmt s
let trailer fmt = fprintf fmt "@,}@]%!"
end