D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
biovisualize
Full window
Github gist
Selection sort
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> <style> div{ width: 50px; height: 50px; } </style> </head> <body> <script> var divs = d3.select('body').selectAll('div') .data([ {foo: 1, bar: 3, color: 'red'}, {foo: 2, bar: 2, color: 'blue'}, {foo: 3, bar: 1, color: 'green'} ]) .enter().append('div') .style({ 'background-color': function(d){ return d.color; } }); divs.sort(function(a, b){ var sortKey = 'foo'; return a[sortKey] - b[sortKey]; }); </script> </body>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js