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

selection.data #4

Closed
daenenk opened this issue Nov 20, 2015 · 3 comments
Closed

selection.data #4

daenenk opened this issue Nov 20, 2015 · 3 comments

Comments

@daenenk
Copy link

daenenk commented Nov 20, 2015

The current implementation requires a Function3 as key function.

def data[NewDatum](data: js.Array[NewDatum], key:js.Function3[NewDatum, Int, Int, String]): Update[NewDatum] = js.native

This implementation gives execution errors when running with d3.js (master 20 May 2015 > tag 3.5.9)
complaining that the 3 argument is undefined iso Int.

The d3.js documentation only describes a function with one or two arguments: datum and index.

This can be corrected :

def data[NewDatum](data: js.Array[NewDatum], key: js.Function2[NewDatum, Int, String]): Update[NewDatum] = js.native
@spaced
Copy link
Owner

spaced commented Nov 22, 2015

Its even more complicated:
The key function is called twice during the data binding process, which proceeds in two phases.
key function must be a js.ThisFunction2[Datum|NewDatum,js.UndefOr[NewDatum], Int, String]
In first loop d is undefined, this is Datum
In second loop d is NewDatum and this is also NewDatum
See also http://stackoverflow.com/questions/27577368/d3-js-key-function-running-twice-on-simple-selector-array-combo

@spaced spaced closed this as completed in 9f3f0de Nov 22, 2015
@spaced
Copy link
Owner

spaced commented Nov 22, 2015

Please reopen if you are not happy with the solution.

@daenenk
Copy link
Author

daenenk commented Nov 27, 2015

Indeed, it is more complex than I initially thought. Have a look to the example I posted on the force layout Issue; it is related.
Would it make sense to bound the NewDatum?

def data[NewDatum <: Datum]( ...

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

2 participants