Open Drup opened 9 years ago
I contemplated implementing an html
alternative that could inject a tyxml tree into the DOM, but simply wasn't familiar with the interface. A function like that could be used in situations like this one, for example.
For select
and run
, I'm not sure I follow, but am imagining a situation where run selector datum view
returns a list of elements contained in the selection that's left over after running view
. Is that what you were thinking? If so, makes sense and could be beneficial, and that could make "run chaining" possible as well which could come in handy in some situations.
I contemplated implementing an html alternative that could inject a tyxml tree into the DOM, but simply wasn't familiar with the interface. A function like that could be used in situations like this one, for example.
This was exactly the example I had in mind, yes. Just use Tyxml_js.To_dom.of_element
to inject things.
For select and run, I'm not sure I follow,
Simply, instead of using a query selector as a string, take a 'a Html5.elt
. I just checked, d3.select
also accepts nodes as input, so it should work out of the box.
After having done the few function to communicate with the instance of tyxml in Tyxml_js
, I tried something slightly crazier ...
It's visible here : https://github.com/Drup/ocaml-d3/tree/more_tyxml
Basically, it's an implementation of the tyxml combinators on top of the append
and attr
functions. It means you can build exactly what you do with append
and attr
using type safe combinators and still use data to figure out the values. It need a patched version of tyxml and jsoo.
At the end, what you get is something of type (data, data) t
(with a fixed data
type).
It could be made much more powerful if I could figure out a way to have a function of type ('a -> 'b . ('b,'b) t) -> ('a, 'a) t)
. I know you don't want it monadic, but it allows really nice things. Is it possible ?
Actually, I think It would be enough to have a function dynamic_append : ('a, string) fn -> ('a, 'a) t
that figures out what to append depending on the data.
I gave another approach a go here. The first version was based on the idea that you could made the value of attribute depends on data, but not the html/svg elements themselves. The second approach is based on the idea that the user write some function of type 'data -> _ Html5.elt
and a function turns that into a ('data,'data) t
. This means you can completely change the shape of the subtree based on the data.
It works !
...ish.
There is a bug due to the fact that the enter selection doesn't support each
and, frankly, I don't know how to solve it. I'm pretty sure it is solvable though, and the resulting interface is very nice.
(this version works with stable tyxml).
Some specific functions could benefit from being tyxml-aware. Do you think it could be done ?
I don't think we can fully type all the interaction (
attr
in particular ...) but some of it could work quite painlessly, I'm thinking of thehtml
andselect
combinators and therun
function.