X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Fhtml.ml;h=4119f23f54e3221d9f88f363ed0cfbaa1fdd20b4;hp=858b43fdbd8948cc3297285d5d07cb3a4bc99ab1;hb=556c8805fcfd27f485bdd63cd704e4df7eac8a06;hpb=b36e4b15dcfe069fcbdb535520c505f89d922837 diff --git a/src/html.ml b/src/html.ml index 858b43f..4119f23 100644 --- a/src/html.ml +++ b/src/html.ml @@ -3,39 +3,45 @@ module M = Map.Make(struct type t = int let compare = compare end) let info = Hashtbl.create 2017 +let max_round = ref ~-1 -let add_info (nodeid:int) (i:int) s = - 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 add_info (nodeid:int) (i:int) (oldi: int) s = + if i > !max_round then max_round := i; + if i <= oldi || oldi < 0 then begin + 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' + end let buff = Buffer.create 20 let fmt = formatter_of_buffer buff -let trace nodeid i = +let trace nodeid i oldi = let () = pp_print_flush fmt (); Buffer.clear buff in kfprintf (fun fmt -> pp_print_flush fmt (); let s = Buffer.contents buff in - add_info nodeid i s) fmt + add_info nodeid i oldi s) fmt 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 last_round = try fst (M.max_binding m) with Not_found -> 0 in + let s_node = "node" ^ (string_of_int (T.preorder tree node)) in + fprintf odot "%s[ id=\"%s\" label=\"%s\" style=filled fillcolor=\"%f,1.0,1.0\"];\n" + s_node s_node (QName.to_string (T.tag tree node)) + (0.2 *. (1.0 -. (float last_round /. float !max_round))) ; 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)