Built with blockbuilder.org
forked from rubin2ma's block: Genome Browser
forked from rubin2ma's block: Genome Browser
forked from rubin2ma's block: Genome Browser
forked from rubin2ma's block: Genome Browser
xxxxxxxxxx
<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!
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
var gene_data = [{"name":"1", "start": 50,"end":100, "direction": "F", "function": "function_1"},
{"name":"2", "start": 110,"end":200, "direction": "F", "function": "function_2"},
{"name":"3", "start": 250,"end":350, "direction": "R", "function": "function_3"},
{"name":"4", "start": 400,"end":600, "direction": "F", "function": "function_4"}]
console.log(gene_data);
svg.selectAll("rect") //selects anything in the svg data file
.data(gene_data) //data join... what connects the data to making the pic
.enter()
.append("rect")
.attr("y",function(d) {if ( d.direction=="F" ) {return 100;} else {return 160;}})
.attr("x", function(d) {if ( d.direction=="F" ) {return 0-(d.end-d.start);} else {return 960;}})
.attr("f", function(d) {return d.function;})
.attr("width", function(d) {return d.end-d.start;})
.attr("height", 50)
.attr("fill", function (d) {if (d.direction=="F"){return "Tomato";} else {return "Turquoise";}})
.transition()
.duration(1500)
.delay(function(d, i) {return i *1500})
.attr("x", function(d) {return d.start;})
;
</script>
</body>
https://d3js.org/d3.v4.min.js