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

Play balls with tyxml #1

Open
Drup opened this issue Sep 29, 2015 · 5 comments
Open

Play balls with tyxml #1

Drup opened this issue Sep 29, 2015 · 5 comments

Comments

@Drup
Copy link
Contributor

Drup commented Sep 29, 2015

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 the html and select combinators and the run function.

@seliopou
Copy link
Owner

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.

@Drup
Copy link
Contributor Author

Drup commented Sep 29, 2015

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.

@Drup
Copy link
Contributor Author

Drup commented Sep 30, 2015

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 ?

@Drup
Copy link
Contributor Author

Drup commented Sep 30, 2015

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.

@Drup
Copy link
Contributor Author

Drup commented Oct 1, 2015

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).

seliopou added a commit that referenced this issue Oct 8, 2015
The previous interface for the run operation was too restrictive, as it
required D3 operations to run on trees that were attached to the
document. With this interface, it is now possible to run D3 operations
on trees that are not attached, for example those that have been
generated using tyxml.

Related to #1, #2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants