Permalink
Browse files

Added linear scale capabilities and example

  • Loading branch information...
raphael-proust committed Apr 23, 2011
1 parent 6574e3c commit 5ce3b35f1b5abbed8443398e37c3bd2285778b95
Showing with 89 additions and 16 deletions.
  1. +38 −4 src/d3.ml
  2. +37 −4 src/d3.mli
  3. +4 −4 src/d3m.ml
  4. +1 −1 src/d3m.mli
  5. +9 −3 tests/barchart_lowlevel.ml
View
@@ -119,7 +119,8 @@ object
-> selection Js.meth
(**Make a function call on each associated datum of the selection. The given
function is called with a datum and its index.*)
function is called with a datum and its index.*) (*TODO: find a way not to
require the int argument.*)
method each :
('data Js.t -> int -> unit) Js.callback
-> selection Js.t Js.meth
@@ -201,7 +202,7 @@ object
'a Js.opt
-> selection Js.t Js.meth
method html_dyn :
(Dom.node Js.t -> Js.js_string Js.t) Js.callback
('a -> int -> Js.js_string Js.t) Js.callback
-> selection Js.t Js.meth
(**Set an event handler on each node in the selection. The first argument is
@@ -268,12 +269,44 @@ class type transition =
object
end
module Scale =
struct
class type ['domain, 'range] t =
object ('self)
method domain : 'domain Js.js_array Js.t -> 'self Js.t Js.meth
method range : 'range Js.js_array Js.t -> 'self Js.t Js.meth
method clamp : bool Js.t -> 'self Js.t Js.meth
method invert : ('range -> 'domain) Js.meth
method interpolate : ('domain -> 'range) Js.meth
end
class type scale =
object
method linear : ('a, 'b) t Js.t Js.meth
(*TODO: other scales*)
end
let to_fun :
('dom, 'range) t Js.t
-> ('dom -> int -> 'range) Js.callback
= Obj.magic
end
class type d3 =
object
(**Do selection on the whole page.*)
inherit with_select
(*TODO: max and other helper functions. *)
(* method transition : transition Js.t Js.meth *)
(*Interpolation*)
@@ -323,11 +356,12 @@ object
-> 'a
-> (float -> 'a) Js.meth
(**Scales*)
method scale : Scale.scale Js.t Js.readonly_prop
end
end
let d3 : d3 Js.t = Js.Unsafe.variable "d3"
View
@@ -120,7 +120,8 @@ object
-> selection Js.meth
(**Make a function call on each associated datum of the selection. The given
function is called with a datum and its index.*)
function is called with a datum and its index.*) (*TODO: find a way not to
require the int argument.*)
method each :
('data Js.t -> int -> unit) Js.callback
-> selection Js.t Js.meth
@@ -202,7 +203,7 @@ object
'a Js.opt
-> selection Js.t Js.meth
method html_dyn :
(Dom.node Js.t -> Js.js_string Js.t) Js.callback
('a -> int -> Js.js_string Js.t) Js.callback
-> selection Js.t Js.meth
(**Set an event handler on each node in the selection. The first argument is
@@ -269,12 +270,43 @@ class type transition =
object
end
module Scale :
sig
class type ['domain, 'range] t =
object ('self)
method domain : 'domain Js.js_array Js.t -> 'self Js.t Js.meth
method range : 'range Js.js_array Js.t -> 'self Js.t Js.meth
method clamp : bool Js.t -> 'self Js.t Js.meth
method invert : ('range -> 'domain) Js.meth
method interpolate : ('domain -> 'range) Js.meth
end
class type scale =
object
method linear : ('a, 'b) t Js.t Js.meth
(*TODO: other scales*)
end
val to_fun :
('dom, 'range) t Js.t
-> ('dom -> int -> 'range) Js.callback
end
class type d3 =
object
(**Do selection on the whole page.*)
inherit with_select
(*TODO: max and other helper functions. *)
(* method transition : transition Js.t Js.meth *)
(*Interpolation*)
@@ -324,11 +356,12 @@ object
-> 'a
-> (float -> 'a) Js.meth
(**Scales*)
method scale : Scale.scale Js.t Js.readonly_prop
end
end
val d3 : d3 Js.t
View
@@ -108,11 +108,11 @@ struct
type 'a t = float -> 'a
let obj x y = d3##interpolateObject(x, y)
let string x y = d3##interpolateString(Js.string x, Js.string y)
let obj x y = d3##interpolateObject(x, y)
let string x y = d3##interpolateString(Js.string x, Js.string y)
let js_string x y = d3##interpolateString(x, y)
let int x y = d3##interpolateRound(x, y)
let float x y = d3##interpolateNumber_float(x, y)
let int x y = d3##interpolateRound(x, y)
let float x y = d3##interpolateNumber_float(x, y)
(*TODO: colors (when available in js_of_ocaml)*)
end
View
@@ -43,7 +43,7 @@ type ('a, 'value) setter =
| Remove
(**Set the property, content, whatever to the given value.*)
| Constant of 'value
(**For each element in the selection, use associated data and index to
(**For each element in the selection, use associated data to
evaluates the new value for the text content, attribute, whatever.*)
| Dynamic of ('a -> int -> 'value)
View
@@ -14,12 +14,18 @@ let chart =
##append(Js.string "div")
##attr(Js.string "class", Js.string "chart")
let x =
D3.d3
##scale
##linear()
##domain(Js.array [|0; 42|])
##range(Js.array [|Js.string "0px"; Js.string "420px"|])
let _ =
chart
##selectAll(Js.string "div")
##data(Js.array data)
##enter()##append(Js.string "div")
##style_dyn(Js.string "width",
Js.wrap_callback (fun i _ -> Js.string (string_of_int (10 * i) ^ "px")))
##text_dyn(Js.wrap_callback (fun i _ -> Js.string (string_of_int i)))
##style_dyn(Js.string "width", D3.Scale.to_fun x)
##text_dyn(Js.wrap_callback (fun v _ -> Js.string (string_of_int v)))

0 comments on commit 5ce3b35

Please sign in to comment.