From: Stefano Zacchiroli Date: Wed, 19 Jul 2006 17:29:44 +0000 (+0000) Subject: - enable header to output graphs attributes and graph-wide node and edge X-Git-Tag: 0.4.95@7852~1177 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=0ece452577dc3d9e593c862c0531367aa6d8840a;p=helm.git - enable header to output graphs attributes and graph-wide node and edge attributes - quote nodes only when needed --- diff --git a/components/extlib/graphvizPp.ml b/components/extlib/graphvizPp.ml index aa472f769..4804699e0 100644 --- a/components/extlib/graphvizPp.ml +++ b/components/extlib/graphvizPp.ml @@ -29,7 +29,11 @@ type attribute = string * string (* pair *) module type GraphvizFormatter = sig - val header: ?name:string -> Format.formatter -> unit + val header: + ?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,11 +49,24 @@ 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 ?(name = "g") ?(graph_attrs = []) ?node_attrs ?edge_attrs fmt = + fprintf fmt "@[strict digraph %s {@," 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; attributes attrs fmt; diff --git a/components/extlib/graphvizPp.mli b/components/extlib/graphvizPp.mli index fa635a971..a10831dca 100644 --- a/components/extlib/graphvizPp.mli +++ b/components/extlib/graphvizPp.mli @@ -31,7 +31,15 @@ type attribute = string * string (* pair *) module type GraphvizFormatter = sig - val header: ?name:string -> Format.formatter -> unit + (** @param name graph name + * @param graph_attrs graph attributes + * @param node_attrs graph-wide node attributes + * @param edge_attrs graph-wide edge attributes *) + val header: + ?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 ->