Pablo

sort(fn)

Iterates over the collection re-ordering it based on the sort callback.

Like the native Array.sort.

For example sorting by a circle’s radius:

var svg = Pablo(demoElement).svg({height: 100}),
    circles = Pablo([
      Pablo.circle({r: 50, cy:50, fill: 'green'}),
      Pablo.circle({r: 20, cy:50, fill: 'blue'}),
      Pablo.circle({r: 30, cy:50, fill: 'red'})
   ]),
   positions = [50, 200, 350];

// Sort the circles by their radius
circles.sort(function (a, b) {
  a = Pablo(a).attr('r');
  b = Pablo(b).attr('r');
  return a - b;
});

circles.each(function (item, i) {
  Pablo(item).attr({cx: positions[i]})
             .appendTo(svg)
});
Painting is just another way of keeping a diary.
Pablo Picasso