Skip to content

Instantly share code, notes, and snippets.

@xaviershay
Created January 1, 2009 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xaviershay/42169 to your computer and use it in GitHub Desktop.
Save xaviershay/42169 to your computer and use it in GitHub Desktop.
// Live tables!
// This example works on http://en.wikipedia.org/wiki/Table_(information)
// Paste into firebug console
require = function (src){
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', src);
// InsertBefore for IE.
// IE crashes on using appendChild before the head tag has been closed.
var head = document.getElementsByTagName('head').item(0);
head.insertBefore(script, head.firstChild);
}
css = function (src){
var script = document.createElement('link');
script.setAttribute('type', 'text/css');
script.setAttribute('rel', 'stylesheet');
script.setAttribute('href', src);
// InsertBefore for IE.
// IE crashes on using appendChild before the head tag has been closed.
var head = document.getElementsByTagName('head').item(0);
head.insertBefore(script, head.firstChild);
}
css("http://xaviershay.github.com/tufte-graph/tufte-graph.css");
require("http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js");
require("http://xaviershay.github.com/tufte-graph/jquery.enumerable.js");
require("http://xaviershay.github.com/tufte-graph/raphael.js");
require("http://xaviershay.github.com/tufte-graph/jquery.tufte-graph.js");
window.setTimeout(function() {
var j = jQuery;
var table = j(j('table.wikitable').get(0));
table.after('<div class="graph" id="age-table" style="width: 500px; height: 200px; margin: 50px;"></div>');
var column = function(element, n) { return j(element).find('td:nth-child(' + n + ')').text(); }
j('#age-table').tufteBar({
data: table.find('tr:gt(0)').collect(function() { return [column(this, 3) * 1, column(this, 1) + ' ' + column(this, 2)]; }),
axisLabel: function() { return this[1] }
})
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment