Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type-safety issues #16

Open
yminsky opened this issue Dec 29, 2015 · 0 comments
Open

type-safety issues #16

yminsky opened this issue Dec 29, 2015 · 0 comments

Comments

@yminsky
Copy link

yminsky commented Dec 29, 2015

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant