interactivethings / d3-comparator

Multi-dimensional comparator function generator for D3
BSD 3-Clause "New" or "Revised" License
28 stars 5 forks source link

Change .dimension() to .sort()? #5

Closed jstcki closed 11 years ago

jstcki commented 11 years ago

Not 100% sure but

d3.comparator()
  .sort(d3.descending, accessor)
  .sort(d3.ascending, accessor2);

seems more eloquent than

d3.comparator()
  .dimension(d3.descending, accessor)
  .dimension(d3.ascending, accessor2);
grossbart commented 11 years ago

Well, the original intent of not using sort was that it doesn't actually sort, right? Because what you do later is myArr.sort(d3.comparator().dimension(d3.descending, function(d){return d.name})), so you create a comparator with certain dimensions, not a sorting-function.

So I still kind of like the naming of dimension. Alternative: orderBy, to take the SQL route.

.sort() reads well, though. Still undecided…

jstcki commented 11 years ago

To me dimension() sounds wrong with something like d3.ascending as the first argument (try to read it as a sentence). But maybe rather .order() so it's not going to be confused with array .sort()?