D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
jaegerka
Full window
Github gist
Genes Visual Representation
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! d3.json("data.json", function(error, json) { var svg = d3.select("body").append("svg") .attr("width", 1000) .attr("height", 500) d3.select("svg").selectAll("rect") .data(json) .enter() .append("rect") .attr("width", function (d) {return d.stop - d.start} ) .attr("height", 50) .attr("x", function (d) {return d.start}) .attr("y", 100) .attr("fill", function (d) { if (d.direction == "forward") {return "green";} else if (d.direction == "reverse") {return "red"}}) .attr("stroke", "black") .attr("stroke-width", 3) d3.select("svg").selectAll("text") .data(json) .enter() .append("text") .text(function (d) {return d.name}) .attr("height", 50) .attr("width", 50) .attr("y", 142) .attr("x", function(d) {return d.start}) .style("font-size", 22) .style("font-family", "monospace") .style("fill", "black") var rectGroup = svg.append("g") .attr("rectangle", "text") }); </script> </body>
https://d3js.org/d3.v4.min.js