[ Launch: Tributary inlet ] 5681495 by enjalot
[ Launch: Tributary inlet ] 5675974 by dfeusse
-
-
Save enjalot/5681495 to your computer and use it in GitHub Desktop.
Tributary inlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"Tributary inlet","endpoint":"","display":"div","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/Tf4meva.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [{"grant_title":"New Mexico Business Roundtable","id":1,"organization":"New Mexico Business Roundtable for Educational Excellence","total_amount":5000,"group":"low","Grant start date":"2/4/2010","start_month":2,"start_day":4,"start_year":2010}, | |
{"grant_title":"LA NSC Match","id":2,"organization":"Trustees of Dartmouth College","total_amount":27727,"group":"low","Grant start date":"8/3/2009","start_month":8,"start_day":3,"start_year":2009}, | |
{"grant_title":"Mathematics Assessment for Learning Phase One RFP","id":3,"organization":"Denver School of Science and Technology Inc.","total_amount":36018,"group":"low","Grant start date":"11/12/2009","start_month":11,"start_day":12,"start_year":2009}, | |
{"grant_title":"Convening of Stakeholder Planning Committee for the Institute for Local Innovation in Teaching and Learning","id":4,"organization":"The NEA Foundation for the Improvement of Education","total_amount":38420,"group":"low","Grant start date":"3/11/2010","start_month":3,"start_day":11,"start_year":2010}, | |
{"grant_title":"Conference Support","id":5,"organization":"New Schools for New Orleans","total_amount":50000,"group":"low","Grant start date":"10/12/2009","start_month":10,"start_day":12,"start_year":2008}]; | |
var width = 940, | |
height = 600, | |
layout_gravity = -0.01, | |
damper = 0.1, | |
nodes = [], | |
vis, force, circles, radius_scale; | |
var center = {x: width / 2, y : height / 2}; | |
var year_centers = { | |
"2008": {x: width / 3, y: height / 2}, | |
"2009": {x: width / 2, y: height / 2}, | |
"2010": {x: 2 * width / 3, y: height / 2} | |
}; | |
var fill_color = d3.scale.ordinal() | |
.domain(["low", "medium", "high"]) | |
.range(["#d84b2a", "#beccae", "#7aa25c"]); | |
var max_amount = d3.max(data, function(d) { return parseInt(d.total_amount, 10); }); | |
var radius_scale = d3.scale.pow().exponent(0.5).domain([0, max_amount]).range([2,85]); | |
data.forEach(function(d) { | |
var node = { | |
id: d.id, | |
radius: radius_scale(parseInt(d.total_amount, 10)), | |
value: d.total_amount, | |
name: d.grant_title, | |
org: d.organization, | |
group: d.group, | |
year: d.start_year, | |
x: Math.random() * 900, | |
y: Math.random() * 800 | |
}; | |
nodes.push(node); | |
}); | |
nodes.sort(function(a,b) { return b.value - a.value; }); | |
vis = d3.select("#display").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.attr("id", "svg_vis"); | |
circles = vis.selectAll('circle') | |
.data(nodes, function(d) { return d.id; }); | |
circles.enter() | |
.append("circle") | |
.attr("r", 10) | |
.attr("fill", function(d) { return fill_color(d.group); }) | |
.attr("stroke-width", 2) | |
.attr("stroke", function(d) { return d3.rgb(fill_color(d.group)).darker(); }); | |
//circles.transition().duration(2000).attr("r", function(d) { return d.radius; }); | |
function charge(d) { | |
return -Math.pow(d.radius, 2.0) / 8; | |
} | |
//function start() { | |
force = d3.layout.force() | |
.nodes(nodes) | |
.size([width, height]); | |
// } | |
//force.gravity(layout_gravity) | |
force.gravity(-0.01) | |
.charge(charge) | |
.friction(0.9) | |
.on("tick", function(e) { | |
try { | |
//circles.each(move_towards_year(e.alpha)) | |
force.nodes().forEach(function(d) { | |
var target = year_centers[d.year] | |
d.x = d.x + (center.x - d.x) * (damper + 0.02) * e.alpha; | |
d.y = d.y + (center.y - d.y) * (damper + 0.02) * e.alpha; | |
}) | |
vis.selectAll('circle') | |
.attr("cx", function(d) {return d.x;}) | |
.attr("cy", function(d) {return d.y;}); | |
} catch(err) {} | |
}); | |
force.start(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment