Skip to content

Instantly share code, notes, and snippets.

@oravecz
Last active April 1, 2018 21:02
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/0685c2aab974240a02b195c766fe2160 to your computer and use it in GitHub Desktop.
Save oravecz/0685c2aab974240a02b195c766fe2160 to your computer and use it in GitHub Desktop.
MAU per NL Platform
license: gpl-3.0
height: 1080
border: no
scrolling: 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

We can make this file beautiful and searchable if this error is corrected: It looks like row 4 should actually have 2 columns, instead of 3. in line 3.
id,value
nl,
nl.voice,
nl.voice.Alexa,20474000,
nl.voice.Google Home,6902000,
nl.voice.Apple,870000
nl.voice.Other Voice,1624000
nl.text,
nl.text.Facebook Messenger,103550000
nl.text.Apple Message,85000000
nl.text.SnapChat,48670000
nl.text.WhatsApp,18240000
nl.text.Google Hangouts,15620000
nl.text.Messenger by Google,10830000
nl.text.Group Me, 10150000
nl.text.Skype,8720000
nl.text.Kik,8210000
nl.text.LINE,3150000
nl.text.Telegram,2570000
<!DOCTYPE html>
<svg width="800" height="800" font-family="sans-serif" font-size="10" text-anchor="middle"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var format = d3.format(",d");
var color = d3.scaleOrdinal(d3.schemeCategory10);
var pack = d3.pack()
.size([width, height])
.padding(1.5);
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 + ") rotate(90)";
});
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) * 10; })
.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