X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fextlib%2FgraphvizPp.ml;h=82fa9807de15a786b8bd7e338ca82af3348976e5;hb=8b509d16d4e68dd6568d8d091c0464d4fcefb0fa;hp=18ebd94d9fb690f3c0749a3fef4514022fd3c0dd;hpb=68e83da0f741009b8fdcc89934a251eafabc9012;p=helm.git diff --git a/helm/software/components/extlib/graphvizPp.ml b/helm/software/components/extlib/graphvizPp.ml index 18ebd94d9..82fa9807d 100644 --- a/helm/software/components/extlib/graphvizPp.ml +++ b/helm/software/components/extlib/graphvizPp.ml @@ -29,7 +29,12 @@ type attribute = string * string (* pair *) module type GraphvizFormatter = sig - val header: ?name:string -> Format.formatter -> unit + val header: + ?graph_type:string -> + ?name:string -> ?graph_attrs:(attribute list) -> + ?node_attrs:(attribute list) -> ?edge_attrs:(attribute list) -> + Format.formatter -> + unit val node: string -> ?attrs:(attribute list) -> Format.formatter -> unit val edge: string -> string -> ?attrs:(attribute list) -> Format.formatter -> @@ -45,13 +50,26 @@ module Dot = let attribute fmt (k, v) = fprintf fmt "@[%s=@,\"%s\",@]" k v let attributes attrs fmt = List.iter (attribute fmt) attrs - let header ?(name = "g") fmt = fprintf fmt "@[digraph %s {@," name - let node name ?(attrs = []) fmt = - fprintf fmt "@[%s@ [" name; + let node name ~quote ?(attrs = []) fmt = + let quote_string = if quote then "\"" else "" in + fprintf fmt "@[%s%s%s@ [" quote_string name quote_string; attributes attrs fmt; fprintf fmt "];@]@," + + let header ?(graph_type = "digraph") ?(name = "g") ?(graph_attrs = []) ?node_attrs ?edge_attrs fmt = + fprintf fmt "@[%s %s {@," graph_type name; + List.iter (fun (k, v) -> fprintf fmt "@[%s=@,%s;@]@," k v) + graph_attrs; + (match node_attrs with + | Some attrs -> node "node" ~quote:false ~attrs fmt + | None -> ()); + (match edge_attrs with + | Some attrs -> node "edge" ~quote:false ~attrs fmt + | None -> ()) + + let node = node ~quote:true let edge name1 name2 ?(attrs = []) fmt = - fprintf fmt "@[%s ->@ %s@ [" name1 name2; + fprintf fmt "@[\"%s\" ->@ \"%s\"@ [" name1 name2; attributes attrs fmt; fprintf fmt "];@]@," let raw s fmt = pp_print_string fmt s