mercredi 15 juillet 2015

d3.js enter() update() exit() pattern, but with custom comparison of key value pairs

Is the d3.js enter/update/exit pattern or behaviour at all modifiable so as to allow custom-comparison of arbitrary key / value pairs (read 'objects') instead of the -as far as I can see- default primitive data types?

To correctly calculate the enter/update/exit selections, I would need to custom-compare previous and current arrays of objects (key/value pairs) using their key names (examples: d.duration and other data such as d.whatever).

Imagining the arrays to be vertical selections in a time-based sequence, a typical scenario might (at time divisions 10 and 12) be:

    prev_selection               curr_selection

    ----[10]-- sampling interval=2 --[12]-----
         :                            :
         :  /other data               :  /other data undefined
part:   [0] -duration 6 -----------> [0] -duration undefined, as overlap from prev
         :  \     :                   :  \    :
         :                            :
         :  /other data undefined     :  /other data
part:   [1] -duration undefined      [1] -duration 2
         :  \     :                   :  \    :
         :                            :
         :  /other data               :  /other data undefined
part:   [2] -duration 4 -----------> [2] -duration undefined, as overlap from prev
         :  \     :                   :  \    :
         :                            :
         :  /other data               :  /other data  
part:   [3] -duration 2              [3] -duration 4 
            \     :                      \    :

Any examples handling more or less similar / relevant situations would be more than welcome.

Thanks

Aucun commentaire:

Enregistrer un commentaire