Built with blockbuilder.org
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", 2000)
.attr("height", 1000)
/* svg.append("text")
.text("Edit the code below to change me!")
.attr("y", 200)
.attr("x", 120)
.attr("font-size", 36)
.attr("font-family", "monospace")
*/
var genes=[{"name": "1", "start": 50, "end":150, "direction": "F", "function":"function1", "fill": "turquoise"},
{"name": "2", "start": 160, "end":300, "direction": "F", "function":"Function 2", "fill": "skyblue"},
{"name": "3", "start": 250, "end":420, "direction": "R", "function": "Function 3", "fill": "teal"},
{"name": "4", "start": 400, "end":500, "direction": "F", "function": "Function 4"}];
var ruler=[{"name":""}]
console.log(genes);
svgEnter= svg.selectAll("rect")
.data(genes)
.enter()
.append("rect")
.attr("y", function(d) {if (d.direction =="F") {
return 100;} else {return 250;}})
.attr("x", function(d) {if(d.direction=="F") {return 0 - (d.end - d.start);} else{return 2000;}})
.attr("width", function(d) {return d.end-d.start})
.attr("height", 30)
.attr("fill", function (d) {if(d.direction=="F") {return "turquoise";} else{return "salmon";}})
/*
.transition()
.duration(1500)
.attr("height", 30)
*/
.attr("opacity", 1)
/*
.transition()
.duration(1000)
.delay(function (d, i) {return i * 1000})
.attr("opacity", 1)
*/
.transition()
.duration(2000)
.attr("x", function (d) {return d.start})
svgEnter.append("text")
.text(function(d) {return d.name})
.attr("y", function(d) {if (d.direction =="F") {
return 100;} else {return 250;}})
.attr("x", function(d) {if(d.direction=="F") {return 0 - (d.end - d.start);} else{return 2000;}})
.attr("font-family", "monospace")
.attr("font-size", 25)
.transition()
.duration(2000)
.attr("x", function (d) {return d.start})
svg.selectAll("rect")
;
//ttr("fill", function(d) {return d.fill})
//.attr("stroke", "black");
</script>
</body>
https://d3js.org/d3.v4.min.js