# Algorithm Wiki

### Site Tools

This is an old revision of the document!

# Visualisation

<head> <script src="http://d3js.org/d3.v2.js"></script> <link rel="stylesheet" type="text/css" href="graph.css"/> <script src="graph.js"></script> <script type="text/javascript"> var graph = new Graph(20);   window.onload = function() { chart = graph.createGraph(d3.select("#chart")) }   function args() { return graph.array; }   var oldI;   function update(n, x, isRunning, duration, prev) { if (duration < 0) { return; // State-less visualisation. } if (x) { graph.drawGraph(duration);   var sortedN = x.lookupInScope("sortedN"); var idx = x.lookupInScope("i"); var bars = chart.selectAll("rect.data").data(graph.array, function(d) {return d.hash;}); // Increase the sorted section when we have an index being moved down. if (typeof idx !== "undefined") { sortedN++; } bars.classed("sorted", function(d, i) {return sortedN && i<sortedN}); if (idx !== oldI) { bars.classed("index", function(d, i) {return i===idx}); oldI = idx; } } } </script> </head> <body> <div style="position:absolute;padding:2px"> <button onclick="graph.randomise(200)">Random</button> <button onclick="graph.randomise(5)">Few Unique</button> <button onclick="graph.almostSorted()">Almost sorted</button> <button onclick="graph.reverse()">Reverse</button> </div> <div id="chart"></div> </body>