D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
rasou2ba
Full window
Github gist
making gene rectangles
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> // copy the .json data into a new blockbuilder tab. strings should be in double quotes //read in the data with d3.json.("filename", function(erro,ANYNAME)) //check this by console.log(ANYNAME) d3.json("data.json", function(error, json) { //make an svg with those attirbutes var svg = d3.select("body").append("svg") .attr("width", 1000) .attr("height", 1000) //Select the svg and put some rectuangles in it d3.select("svg").selectAll("rect") //use the .data function to tell it where to get the data from .data(json) //enter data from the data.json file into the DOM. Remember d3 is the glue between the data and the DOM (document object model) .enter() //there's stuff in the data that's not in the DOM and it needs to be entered. .append("rect") //modify the rectangles. .attr("y", 50) //we want all the genes in the same y value so we set that. .attr("height", 50) //this is the same for every gene .attr("x", function(d) {return d.start - d.start}) //width depends on data. the d is a convension that everyone uses and statys the same. For each gene called d return the start .attr("width", function(d) {return d.stop - d.start}) //the larger number - smaller number //set the color based on the data .attr("fill", function(d) {if (d.orientation == "foward") {return "green" ;} else if(d.orientation == "reverse") {return "red"} }); }) </script> </body>
https://d3js.org/d3.v4.min.js