Commits

camlspotter committed ec8785a

animated chart trial. Not successful

Comments (0)

Files changed (2)

     return ()
   end
 
-let _ = google##setOnLoadCallback(drawChart)
+
+let drawChartAnim () = 
+  let data = jsnew (google##visualization##_DataTable) () in
+  data##addColumn(Js.string "number", Js.string "X");
+  data##addColumn(Js.string "number", Js.string "Y");
+
+  (* eval_string of JavaScript object literal fails *)
+  (* Someone has written a patch for a syntax sugar of Javascript object literal. So wait and see. *)
+  let options = Unsafe.literal "{'title':'Random value distribution (Animated)', 
+                                 'width':400, 
+                                 'height':300
+                                }" 
+  in
+
+  let div = match Opt.to_option (Dom_html.window##document##getElementById (Js.string "chart2_div")) with
+    | None -> assert false
+    | Some div -> div
+  in
+  let chart = jsnew (google##visualization##_ScatterChart) (div) in
+  chart##draw(data, options);
+
+  ignore begin
+    Data.get "data.txt" >>= fun rows ->
+    let rec iter = function
+      | [] -> return ()
+      | (x,y)::xys ->
+          data##addRows(Js.array [| Js.array [| Obj.magic x; Obj.magic y; |] |]);
+          Lwt_js.sleep 0.2 >>= fun () ->
+          iter xys (* It seems not to be executed.... Hmmm *)
+    in
+    iter rows
+  end
+
+let do_all () = 
+  drawChart ();
+  drawChartAnim ()
+
+let _ = google##setOnLoadCallback(do_all)
 
   <body>
     <div id="chart_div"></div>
+    <div id="chart2_div"></div>
   </body>
 </html>