Skip to content

Instantly share code, notes, and snippets.

@CBasis
Last active January 3, 2018 13:28
Show Gist options
  • Save CBasis/086052e4da981224ced687df6a18e596 to your computer and use it in GitHub Desktop.
Save CBasis/086052e4da981224ced687df6a18e596 to your computer and use it in GitHub Desktop.
Bubble Chart
license: gpl-3.0
height: 960
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

id value
dsmj.log 554
VS0.log.DB_ES1 41320476672
VS0.log.SYSTEMDB.newer 94208
VS0.log.SYSTEMDB 29750636544
VS0.log.DB_ES0 127421808640
VS0.log 4096
VS0.data.SYSTEMDB 66648190976
VS0.data.DB_ES0 934097145856
VS0.data.DB_ES1.DB_ES1 4096
VS0.data.DB_ES1 113590620160
VS0.data.DB_EN0 4096
VS0.data 4096
VS0.config_files.Tue.global 5515
VS0.config_files.Tue.dfvvesvs0hd00 5329
VS0.config_files.Tue 4096
VS0.config_files.COUNT_3.global 5515
VS0.config_files.COUNT_3.dfvvesvs0hd00 5646
VS0.config_files.COUNT_3 4096
VS0.config_files.Fri.global 5515
VS0.config_files.Fri.dfvvesvs0hd00 5329
VS0.config_files.Fri 4096
VS0.config_files.COUNT_6.global 5515
VS0.config_files.COUNT_6.dfvvesvs0hd00 5646
VS0.config_files.COUNT_6 4096
VS0.config_files.COUNT_9.global 5515
VS0.config_files.COUNT_9.dfvvesvs0hd00 5329
VS0.config_files.COUNT_9 4096
VS0.config_files.COUNT_2.global 5515
VS0.config_files.COUNT_2.dfvvesvs0hd00 5646
VS0.config_files.COUNT_2 4096
VS0.config_files.COUNT_4.global 5515
VS0.config_files.COUNT_4.dfvvesvs0hd00 5646
VS0.config_files.COUNT_4 4096
VS0.config_files.COUNT_7.global 5515
VS0.config_files.COUNT_7.dfvvesvs0hd00 5646
VS0.config_files.COUNT_7 4096
VS0.config_files.COUNT_0.global 5515
VS0.config_files.COUNT_0.dfvvesvs0hd00 5646
VS0.config_files.COUNT_0 4096
VS0.config_files.COUNT_1.global 5515
VS0.config_files.COUNT_1.dfvvesvs0hd00 5646
VS0.config_files.COUNT_1 4096
VS0.config_files.COUNT_5.global 5515
VS0.config_files.COUNT_5.dfvvesvs0hd00 5646
VS0.config_files.COUNT_5 4096
VS0.config_files 4096
VS0 4096
$VTHOSTNAME.VS0.DATA.SYSTEMDB 4096
$VTHOSTNAME.VS0.DATA 4096
$VTHOSTNAME.VS0.LOG.SYSTEMDB 4096
$VTHOSTNAME.VS0.LOG.DB_ES1 4096
$VTHOSTNAME.VS0.LOG 4096
$VTHOSTNAME.VS0 4096
$VTHOSTNAME 4096
WS0.log.SYSTEMDB 1052390526976
WS0.log.DB_FS0 399214690304
WS0.log.DB_FS1 292114722816
WS0.log 4096
WS0.data.SYSTEMDB 5369049088
WS0.data.DB_FS0 49291956224
WS0.data.DB_FS1 14395346944
WS0.data.DB_WS0 4096
WS0.data.DB_FN0 4096
WS0.data 4096
WS0.config_files 4096
WS0 4096
XS0.data.SYSTEMDB 6157410304
XS0.data.DB_KN0 19059085312
XS0.data.DB_KS0 36457058304
XS0.data.DB_KS1 6056742912
XS0.data 4096
XS0.log.DB_KN0 22690299904
XS0.log.DB_KS0 26873028608
XS0.log.DB_KS1 17937993728
XS0.log.SYSTEMDB 32914739200
XS0.log 4096
XS0.config_files 4096
XS0 4096
ZS0.data.SYSTEMDB 6241296384
ZS0.data.DB_PS0 51271340032
ZS0.data.DB_PS1 6392287232
ZS0.data.DB_ZS0 4096
ZS0.data 4096
ZS0.log.SYSTEMDB 667246592
ZS0.log.DB_PS1 834719744
ZS0.log.DB_PS0 655249408
ZS0.log 4096
ZS0.config_files 4096
ZS0 4096
<!DOCTYPE html>
<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>
<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 colorBorder = d3.scaleOrdinal(d3.schemeCategory20);
var pack = d3.pack()
.size([width, height])
.padding(1.5);
function extractSID(str) {
var m = /([A-Z0-9])([A-Z0-9][0-9])/.exec(str);
return m ? m[1] : "#000000";
}
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) { console.log(extractSID(d.package)+ "---") ; return color(extractSID(d.package)); })
.style("stroke", "black")
.style("stroke-dasharray", 5.5);
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; })
.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