From: Enrico Tassi Date: Wed, 19 Dec 2007 15:10:19 +0000 (+0000) Subject: accepts the poly shape for gviz maps X-Git-Tag: make_still_working~5703 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=8da75ffeb862139e8607c5a3a3aa782458da82cb;p=helm.git accepts the poly shape for gviz maps --- diff --git a/helm/software/matita/lablGraphviz.ml b/helm/software/matita/lablGraphviz.ml index d86d943e3..d67584c8c 100644 --- a/helm/software/matita/lablGraphviz.ml +++ b/helm/software/matita/lablGraphviz.ml @@ -53,7 +53,9 @@ class graphviz_impl ?packing () = GMisc.image ~packing:viewport#add ~xalign:0. ~yalign:0. ~xpad:0 ~ypad:0 () in let parse_coords s = - match List.map float_of_string (HExtlib.split ~sep:',' s) with + let xys = HExtlib.split ~sep:' ' s in + let xys = List.flatten (List.map (HExtlib.split ~sep:',') xys) in + match List.map float_of_string xys with | [x1; y1; x2; y2 ] -> x1, y1, x2, y2 | _ -> assert false in object (self) @@ -89,6 +91,29 @@ class graphviz_impl ?packing () = let is_rect l = try List.assoc "shape" l = "rect" with Not_found -> false in + let is_poly l = + try List.assoc "shape" l = "poly" with Not_found -> false + in + let rectify l = + List.map ( + function "coords",c -> + let xys = HExtlib.split ~sep:' ' c in + let xys = + List.map + (fun s -> + match HExtlib.split ~sep:',' s with + | [x; y] -> int_of_string x, int_of_string y + | _ -> assert false) + xys + in + let xs, ys = List.split xys in + let max_x = string_of_int (List.fold_left max 0 xs) in + let max_y = string_of_int (List.fold_left max 0 ys) in + let min_x = string_of_int (List.fold_left min max_int xs) in + let min_y = string_of_int (List.fold_left min max_int ys) in + "coords", min_x^","^min_y^" "^max_x^","^max_y + | x -> x) l + in let p = XmlPushParser.create_parser { XmlPushParser.default_callbacks with @@ -96,6 +121,7 @@ class graphviz_impl ?packing () = Some (fun elt attrs -> match elt with | "area" when is_rect attrs -> areas := attrs :: !areas + | "area" when is_poly attrs -> areas := rectify attrs :: !areas | _ -> ()) } in XmlPushParser.parse p (`File fname); map <- !areas @@ -114,12 +140,13 @@ class graphviz_impl ?packing () = method center_on_href href = (*eprintf "Centering viewport on uri %s\n%!" href;*) - let attrs = - List.find - (fun attrs -> - try List.assoc "href" attrs = href with Not_found -> false) - map in try + let attrs = + List.find + (fun attrs -> + try List.assoc "href" attrs = href with Not_found -> false) + map + in let x1, y1, x2, y2 = parse_coords (List.assoc "coords" attrs) in viewport#hadjustment#clamp_page ~lower:x1 ~upper:x2; viewport#vadjustment#clamp_page ~lower:y1 ~upper:y2;