-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
The d3 API isn't quite as type-safe as I might have expected. Here's an example of a simple bit of code that doesn't behave the way I would expect. In particular, the function passed to datum is not applied to the data before its handed to the closure passed to data. I'm presumably fundamentally confused about what datum is supposed to be doing in D3, but the types don't help, and it's pretty disturbing to have typesafe code fail with null pointer errors....
open D3
open Printf
let logf k = ksprintf (fun s -> Firebug.console##log (Js.string s)) k
let view =
select ".foo"
|. selectAll "rect"
|. datum (fun l _ ->
logf "[datum] len:%d" (List.length l);
List.map (fun x -> (x,x)) l
)
|. data (fun x _ ->
logf "[data] len:%d" (List.length x);
x)
|. enter
|. append "rect"
|. attr "width" (fun _ (_,i) _ -> sprintf "%d" i)
let () =
run ~node:(Dom_html.document##body) view [1;2;3;4]
Metadata
Metadata
Assignees
Labels
No labels