Skip to content

Instantly share code, notes, and snippets.

@oravecz
Last active March 2, 2017 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oravecz/65700bcc0d5e440f13fdef632f31e8c9 to your computer and use it in GitHub Desktop.
Save oravecz/65700bcc0d5e440f13fdef632f31e8c9 to your computer and use it in GitHub Desktop.
Bubble Chart
license: gpl-3.0
height: 880
border: no

Bubble charts encode data in the area of circles. Although less perceptually-accurate than bar charts, they can pack hundreds of values into a small space. Implementation based on work by Jeff Heer. Data shows the Flare class hierarchy, also courtesy Jeff Heer.

forked from mbostock's block: Bubble Chart

forked from anonymous's block: Bubble Chart

forked from anonymous's block: Bubble Chart

We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 3 columns, instead of 2. in line 1.
id,value,
text,
text.Slack 4M,4000000
text.Facebook Messenger 500M,500000000
text.Skype 225M,225000000
text.Kik 150M,150000000
text.Line 163M,163500000
text.Telegram 750M,75000000
text.SnapChat 150M,150000000
text.Twitter 140M,140000000
text.Cortana 113M,113000000
text.Cisco Spark 750K,750000
text.Viber 195M,195000000
embed,
embed.Embed Source 1M,1000000
voice,
voice.Amazon Alexa 10M,10000000
voice.Cortana 32M,32000000
voice.Cisco Tropo 150K,150000
voice.Google Home 1M,1000000
<!DOCTYPE html>
<meta charset="utf-8">
<style>
text {
font: 16px sans-serif;
text-anchor: middle;
}
</style>
<svg width="960" height="960"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width");
var format = d3.format(",d");
var color = d3.scaleOrdinal(['#ccccff', "#ccffcc", "#ffcccc"]);
var pack = d3.pack()
.size([width, width])
.padding(7);
d3.csv("flare.csv", function(d) {
d.value = +d.value;
if (d.value) return d;
}, function(error, classes) {
if (error) throw error;
var root = d3.hierarchy({children: classes})
.sum(function(d) { return d.value; })
.each(function(d) {
if (id = d.data.id) {
var id, i = id.lastIndexOf(".");
d.id = id;
d.package = id.slice(0, i);
d.class = id.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("id", function(d) { return d.id; })
.attr("r", function(d) { return d.r; })
.style("fill", function(d) { return color(d.package); });
node.append("clipPath")
.attr("id", function(d) { return "clip-" + d.id; })
.append("use")
.attr("xlink:href", function(d) { return "#" + d.id; });
node.append("text")
.attr("clip-path", function(d) { return "url(#clip-" + d.id + ")"; })
.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) * 20; })
.text(function(d) { return d; });
node.append("title")
.text(function(d) { return d.id + "\n" + format(d.value); });
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment