Skip to content

Instantly share code, notes, and snippets.

@hughes
Last active Aug 29, 2015
Embed
What would you like to do?
chargeTest
{"description":"chargeTest","endpoint":"","display":"svg","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":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/K96fKcf.png"}
var nodes = [{charge: -100}, {charge: -100}, {charge: 0}];
var svg = d3.select('svg');
var force = d3.layout.force()
.charge(function (d) { return d.charge; })
.gravity(0.1)
.size([800,300])
.nodes(nodes)
.on('tick', tick)
.start()
var node = svg.selectAll('.node').data(nodes);
node.enter()
.append('circle')
.attr('r', 10)
.attr('fill', function (d) {
return 'rgb('+Math.abs(d.charge*2)+',0,0)';
})
node.call(force.drag)
function tick() {
node.attr('transform', function (d) {
return 'translate(' + d.x + ',' + d.y + ')';
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment