D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
greenmna
Full window
Github gist
Bubbles for realskiezzzzz
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <svg width="960" height="960" font-family="sans-serif" font-size="10" text-anchor="middle"></svg> <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 salmonella_data=[] var svg = d3.select("svg"), width = +svg.attr("width"), height = +svg.attr("height"); var format = d3.format(",d"); var color = d3.scaleOrdinal(d3.schemeCategory20c); var pack = d3.pack() .size([width, height]) .padding(1.5); //var salmonella_data=[] console.log(salmonella_data) d3.csv("BIO583_Salmonella_data.csv", function(d){ if (d.Isolate) return d; }, function (error, classes){ if (error) throw error; classes.forEach(function(d){ salmonella_data.push({"Isolate": d.Isolate, "Source": d.Source, "Serotype": d.Serotype, "AMR Phenotype": d.AMR_Phenotype, "gene_number": +d.gene_number})}) var root = d3.hierarchy({children: classes}) .each (function (d){ if (Isolate = d.data.Isolate){ var Isolate, i = Isolate.lastIndexOf("."); d.Isolate = Isolate; d.package = Isolate.slice (0,i) d.class = Isolate.slice (i+1) } }); var node = svg.selectAll(".node") .data(pack(root).leaves()) .enter().append("g") .attr("class", "node") .attr("transform", function (d){return "translate(" + d.x + "," + d.y + ")";}); node.append("circle") .attr("Isolate", function(d){return d.Isolate}) .attr("r", function (d) {return d.gene_number}) .attr("Serotype", function (d){return d.Serotype}) .style ("fill", function(d) {return color(d.package); }); /*node.append("clipPath") .attr("Isolate", function(d) {return "clip-" + d.Isolate; }) .append("use") .attr("xlink:href", function (d) {return "#" + d.Isolate; });*/ node.append("text") .attr("clip-path", function (d) {return "url(#clip-" + d.Isolate + ")"}) .selectAll("tspan") .data(function (d) {return d.class.split(/(?=[A-Z][^A-Z])/g); }) .enter().append("tspan") .attr("x", 0) .attr("y", function (d, i, nodes) {return 13 + (i - nodes.length / 2 - 0.5) * 10; }) .text(function (d) {return d}); node.append("title") .text(function (d) {return d.Isolate + "\n" + format(d.value); }); }); //console.log(salmonella_data) </script> </body>
https://d3js.org/d3.v4.min.js