Created
August 20, 2016 17:42
-
-
Save anonymous/4f2077a727d37f67f3836c8d7e3ea527 to your computer and use it in GitHub Desktop.
d3 poc // source https://jsbin.com/hofeyepula
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> | |
<title>d3 poc</title> | |
<style id="jsbin-css"> | |
.node { | |
fill: #ccc; | |
stroke:#fff; | |
stroke-width:3px; | |
} | |
.link { | |
stroke: #777; | |
stroke-width: 3px; | |
} | |
</style> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
'use strict' | |
const w = 640, h=480; | |
const nodes = [ | |
{x:10,y:10}, | |
{x:20,y:10}, | |
{x:30,y:10} | |
]; | |
const links = [ | |
{source:0,target:1} | |
]; | |
let svg = d3.select('body').append('svg') | |
.attr('width', w).attr('height', h); | |
let force = d3.layout.force().size([w,h]) | |
.nodes(nodes).links(links); | |
force.linkDistance(w/2) | |
let link = svg.selectAll('.link').data(links).enter() | |
.append('line').attr('class', 'link') | |
let node = svg.selectAll('.node').data(nodes).enter() | |
.append('circle').attr('class', 'node') | |
force.on('end', ()=> { | |
node.attr('r', 10) | |
.attr('cx', (d)=>d.x) | |
.attr('cy', (d)=>d.y) | |
link.attr('x1', (d)=>d.source.x) | |
.attr('x2', (d)=>d.target.x) | |
.attr('y1', (d)=>d.source.y) | |
.attr('y2', (d)=>d.target.y) | |
}) | |
force.start() | |
</script> | |
<script id="jsbin-source-css" type="text/css">.node { | |
fill: #ccc; | |
stroke:#fff; | |
stroke-width:3px; | |
} | |
.link { | |
stroke: #777; | |
stroke-width: 3px; | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">'use strict' | |
const w = 640, h=480; | |
const nodes = [ | |
{x:10,y:10}, | |
{x:20,y:10}, | |
{x:30,y:10} | |
]; | |
const links = [ | |
{source:0,target:1} | |
]; | |
let svg = d3.select('body').append('svg') | |
.attr('width', w).attr('height', h); | |
let force = d3.layout.force().size([w,h]) | |
.nodes(nodes).links(links); | |
force.linkDistance(w/2) | |
let link = svg.selectAll('.link').data(links).enter() | |
.append('line').attr('class', 'link') | |
let node = svg.selectAll('.node').data(nodes).enter() | |
.append('circle').attr('class', 'node') | |
force.on('end', ()=> { | |
node.attr('r', 10) | |
.attr('cx', (d)=>d.x) | |
.attr('cy', (d)=>d.y) | |
link.attr('x1', (d)=>d.source.x) | |
.attr('x2', (d)=>d.target.x) | |
.attr('y1', (d)=>d.source.y) | |
.attr('y2', (d)=>d.target.y) | |
}) | |
force.start() | |
</script></body> | |
</html> |
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
.node { | |
fill: #ccc; | |
stroke:#fff; | |
stroke-width:3px; | |
} | |
.link { | |
stroke: #777; | |
stroke-width: 3px; | |
} |
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
'use strict' | |
const w = 640, h=480; | |
const nodes = [ | |
{x:10,y:10}, | |
{x:20,y:10}, | |
{x:30,y:10} | |
]; | |
const links = [ | |
{source:0,target:1} | |
]; | |
let svg = d3.select('body').append('svg') | |
.attr('width', w).attr('height', h); | |
let force = d3.layout.force().size([w,h]) | |
.nodes(nodes).links(links); | |
force.linkDistance(w/2) | |
let link = svg.selectAll('.link').data(links).enter() | |
.append('line').attr('class', 'link') | |
let node = svg.selectAll('.node').data(nodes).enter() | |
.append('circle').attr('class', 'node') | |
force.on('end', ()=> { | |
node.attr('r', 10) | |
.attr('cx', (d)=>d.x) | |
.attr('cy', (d)=>d.y) | |
link.attr('x1', (d)=>d.source.x) | |
.attr('x2', (d)=>d.target.x) | |
.attr('y1', (d)=>d.source.y) | |
.attr('y2', (d)=>d.target.y) | |
}) | |
force.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment