D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
dej611
Full window
Github gist
Graph of Languages Properties Relation by Implication Search on Terraling
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Terraling Explore Implication Graph</title> <script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> <style type="text/css"> path.link { fill: none; stroke: #666; } marker#gte20 { fill: green; } path.link.gte20 { stroke: green; stroke } path.link.gte10 { stroke-dasharray: 0,2 1; } circle { fill: #ccc; stroke: #333; stroke-width: 1.5px; } text { font: 10px sans-serif; pointer-events: none; } text.shadow { stroke: #fff; stroke-width: 3px; stroke-opacity: .8; } </style> </head> <body> <script type="text/javascript"> // Data from Terraling var links = [ {source: "08_Verb Object Subject : Yes", target: "02_Verb Subject : Yes", type: "gte20", lings: "23"}, {source: "08_Verb Object Subject : Yes", target: "03_Verb Object : Yes", type: "gte20", lings: "23"}, {source: "03_Verb Object : No", target: "08_Verb Object Subject : No", type: "gte20", lings: "20"}, {source: "10_Object Verb subject : Yes", target: "03_Verb Object : Yes", type: "gte10", lings: "14"}, {source: "10_Object Verb subject : Yes", target: "05_Subject Verb Object : Yes", type: "gte10", lings: "14"}, {source: "09_Object Subject Verb : NA", target: "02_Verb Subject : No", type: "alone", lings: "1"}, {source: "09_Object Subject Verb : NA", target: "03_Verb Object : No", type: "alone", lings: "1"}, {source: "09_Object Subject Verb : NA", target: "04_Object Verb : Yes", type: "alone", lings: "1"}, {source: "09_Object Subject Verb : NA", target: "05_Subject Verb Object : No", type: "alone", lings: "1"}, {source: "09_Object Subject Verb : NA", target: "06_Subject Object Verb : Yes", type: "alone", lings: "1"}, {source: "09_Object Subject Verb : NA", target: "07_Verb Subject Object : No", type: "alone", lings: "1"}, {source: "09_Object Subject Verb : NA", target: "08_Verb Object Subject : No", type: "alone", lings: "1"}, {source: "09_Object Subject Verb : NA", target: "10_Object Verb subject : NA", type: "alone", lings: "1"}, {source: "10_Object Verb Subject : NA", target: "02_Verb Subject : No", type: "alone", lings: "1"}, {source: "10_Object Verb Subject : NA", target: "03_Verb Object : No", type: "alone", lings: "1"}, {source: "10_Object Verb Subject : NA", target: "04_Object Verb : Yes", type: "alone", lings: "1"}, {source: "10_Object Verb Subject : NA", target: "05_Subject Verb Object : No", type: "alone", lings: "1"}, {source: "10_Object Verb Subject : NA", target: "06_Subject Object Verb : Yes", type: "alone", lings: "1"}, {source: "10_Object Verb Subject : NA", target: "07_Verb Subject Object : No", type: "alone", lings: "1"}, {source: "10_Object Verb Subject : NA", target: "08_Verb Object Subject : No", type: "alone", lings: "1"}, {source: "10_Object Verb Subject : NA", target: "09_Object Subject Verb : NA", type: "alone", lings: "1"} ]; var nodes = {}; // Compute the distinct nodes from the links. links.forEach(function(link) { link.source = nodes[link.source] || (nodes[link.source] = {name: link.source, type: link.type, lings: link.lings}); link.target = nodes[link.target] || (nodes[link.target] = {name: link.target, type: link.type, lings: link.lings}); }); var w = 960, h = 500; var force = d3.layout.force() .nodes(d3.values(nodes)) .links(links) .size([w, h]) .linkDistance(80) .charge(-300) .on("tick", tick) .start(); var svg = d3.select("body").append("svg:svg") .attr("width", w) .attr("height", h); // Per-type markers, as they don't inherit styles. svg.append("svg:defs").selectAll("marker") .data(["alone", "gte20", "gte10"]) .enter().append("svg:marker") .attr("id", String) .attr("viewBox", "0 -5 10 10") .attr("refX", 10) .attr("refY", -1.5) .attr("markerWidth", 8) .attr("markerHeight", 8) .attr("orient", "auto") .append("svg:path") .attr("d", "M0,-5L10,0L0,5"); var path = svg.append("svg:g").selectAll("path") .data(force.links()) .enter().append("svg:path") .attr("class", function(d) { return "link " + d.type; }) .attr("marker-end", function(d) { return "url(#" + d.type + ")"; }); var circle = svg.append("svg:g").selectAll("circle") .data(force.nodes()) .enter().append("svg:circle") .attr("r", 6) .call(force.drag); var text = svg.append("svg:g").selectAll("g") .data(force.nodes()) .enter().append("svg:g"); // A copy of the text with a thick white stroke for legibility. text.append("svg:text") .attr("x", 8) .attr("y", ".31em") .attr("class", "shadow") .text(function(d) { return (/^alone$/).test(d.type) ? '' : d.name; }); text.append("svg:text") .attr("x", 8) .attr("y", ".31em") .text(function(d) { return (/^alone$/).test(d.type) ? '' : d.name; }); var link = canvas.append("g").selectAll("line") .data(links) .enter().append("line") .attr("class", "link") .style("stroke-width", function(d) { return d.lings+'px'; }) .style("stroke", "green") .attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.target.x; }) .attr("y2", function(d) { return d.target.y; }); // Use elliptical arc path segments to doubly-encode directionality. function tick() { path.attr("d", function(d) { var dx = d.target.x - d.source.x, dy = d.target.y - d.source.y, dr = Math.sqrt(dx * dx + dy * dy); return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y; }); circle.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); text.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); } </script> </body> </html>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js