interactivethings / d3-grid

D3 grid layout
BSD 3-Clause "New" or "Revised" License
77 stars 10 forks source link

Add .sort() #1

Open jstcki opened 11 years ago

grossbart commented 11 years ago

And boom, it'll be Isotope for d3. :)

ejfox commented 8 years ago

I'm working on a project where I am basically doing this, any interest in a PR to try and integrate underscore's _.sortBy (will just pull it out)?

I'm imagining something like

data = [
{
  name: 'one',
  id: 1,
  value: 5
},
{
  name: 'two',
  id: 2,
  value: 3
},
{
  name: 'three',
  id: 3,
  value: 1
}
]

  pointGrid = d3.layout.grid()
    .points()
    .size([width-100,height-100])
    .data(data)
    .sortBy(function(d){
      return -d.id
    })

  pointGrid.sortBy('value')

and then update/append/remove normally.

jstcki commented 8 years ago

Wow, what a blast from the past, this issue is three years old! 😄

Does this library even need this feature? Isn't it easier to just sort the data (using d3.ascending, underscore, whatever you like …) before passing it into the layout function? See http://bl.ocks.org/herrstucki/5694697