Source file chartjs_streaming.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
open Js_of_ocaml

module Axis = struct
  let realtime = Chartjs.Axis.of_string "realtime"
end

class type updateConfig =
  object
    inherit Chartjs.updateConfig

    method preservation : bool Js.t Js.optdef_prop
  end

class type streaming =
  object
    method duration : int Js.optdef_prop

    method ttl : int Js.optdef Js.prop

    method delay : int Js.optdef_prop

    method refresh : int Js.optdef_prop

    method onRefresh : (Chartjs.chart Js.t -> unit) Js.callback Js.opt Js.optdef_prop

    method frameRate : float Js.optdef_prop

    method pause : bool Js.t Js.optdef_prop
  end

let empty_update_config ?preservation () =
  let (obj : updateConfig Js.t) = Js.Unsafe.obj [||] in
  match preservation with
  | None -> obj
  | Some p ->
      obj##.preservation := Js.bool p;
      obj

let empty_streaming_config () = Js.Unsafe.obj [||]

let of_axis axis = (Js.Unsafe.coerce axis)##.realtime

let of_chart_options options = (Js.Unsafe.coerce options)##.plugins##.streaming

let of_global () = Js.Unsafe.global##._Chart##.defaults##.global##.plugins##.streaming

let set_to_axis axis plugin = (Js.Unsafe.coerce axis)##.realtime := plugin

let set_to_chart_options options plugin =
  (Js.Unsafe.coerce options)##.plugins##.streaming := plugin

let set_globally plugin =
  Js.Unsafe.global##._Chart##.defaults##.global##.plugins##.streaming := plugin