X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Fhtml.ml;h=c7990b32c74f40824348b78c5fb8076f42ec18d3;hp=858b43fdbd8948cc3297285d5d07cb3a4bc99ab1;hb=9a127b83fbb1171ebd36e6f42780093412a5e91a;hpb=9efb3171eb9f70c92d7814a56684ef5f1eedf004 diff --git a/src/html.ml b/src/html.ml index 858b43f..c7990b3 100644 --- a/src/html.ml +++ b/src/html.ml @@ -2,15 +2,19 @@ open Format module M = Map.Make(struct type t = int let compare = compare end) let info = Hashtbl.create 2017 +let final = Hashtbl.create 2017 +let max_round = ref 0 let add_info (nodeid:int) (i:int) s = + if i > !max_round then max_round := i; let m = try Hashtbl.find info nodeid with Not_found -> M.empty in let old_s = try M.find i m with Not_found -> "" in let s' = old_s ^ s in let m' = M.add i s' m in Hashtbl.replace info nodeid m' + let buff = Buffer.create 20 let fmt = formatter_of_buffer buff @@ -23,19 +27,31 @@ let trace nodeid i = let s = Buffer.contents buff in add_info nodeid i s) fmt +let finalize_node n r b = + Hashtbl.replace final n (b,r) + let gen_trace (type s) = (); fun t tree -> let module T = (val (t) : Tree.S with type t = s) in let rec loop odot ohtml node parent = if node == T.nil then () else begin - let s_node = "node" ^ (string_of_int (T.preorder tree node)) in - fprintf odot "%s[ id=\"%s\" label=\"%s\"];\n" - s_node s_node (QName.to_string (T.tag tree node)); let m = try Hashtbl.find info (T.preorder tree node) with Not_found -> M.empty in + let node_id = T.preorder tree node in + let marked, last_round = try Hashtbl.find final node_id with Not_found -> + Printf.eprintf ">>> %i\n%!" node_id; false, !max_round; + in + let s_node = "node" ^ (string_of_int node_id) in + fprintf odot "%s[ id=\"%s\" label=\"%s\" style=filled fillcolor=\"%f,1.0,1.0\"\ +shape=\"%s\" ];\n" + s_node + s_node + (QName.to_string (T.tag tree node)) + (1.0 -. (float (last_round+1) /. float (!max_round+1))) + (if marked then "oval" else "box") ; fprintf ohtml "data['%s'] = new Array();\n" s_node; M.iter (fun i s -> fprintf ohtml "data['%s'][%i] = '%s';\n" s_node i s)