Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

selection.data key with simple function #9

Closed
daenenk opened this issue Dec 1, 2015 · 0 comments
Closed

selection.data key with simple function #9

daenenk opened this issue Dec 1, 2015 · 0 comments

Comments

@daenenk
Copy link

daenenk commented Dec 1, 2015

To make the API useful

 svg.selectAll[Node](".node").data(force.nodes(), (d: Node, i: Int) => d.id)

should compile, but (d: Node, i: Int) => d.id is not lifted or recognised as a js.thisFunction2

I've read http://stackoverflow.com/questions/27577368/d3-js-key-function-running-twice-on-simple-selector-array-combo. The current definition might be technically spoken correct but of little use if you don't overload it as to accept the above. Instantiating from js.thisFunction2 may be useful to mimic this binding from js in scala. But to pass a closure as argument, it just makes things complex. The point made on stackoverflow is that the passed function should work both on the selected data as well on the new data.
In case of

 svg.selectAll[Node](".node").data[N1,N2](force.nodes(): js.Array[N1] , (d: N2, i: Int) => d.id)

The type relation should be: N2 >: N1 and N2 >: Node
or when N2 == Node then N1 <: Node

as such I would propose both, next to the thisFunction based API if you like

def data[NewDatum <: Datum](data: js.Array[NewDatum], key: js.Function1[Datum, String]): Update[NewDatum] = js.native
def data[NewDatum <: Datum](data: js.Array[NewDatum], key: js.Function2[Datum, Int, String]): Update[NewDatum] = js.native
@spaced spaced changed the title selection.data (re-opened) selection.data key with simple function Dec 2, 2015
@spaced spaced closed this as completed in 2d6b07c Dec 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant