treemap oct 2016 cumul HT keur
-
-
Save clodio/7d1d2f403e70d235b8d053ba3190e7e0 to your computer and use it in GitHub Desktop.
Treemap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
border: no | |
height: 600 | |
license: gpl-3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "sna", | |
"children": [{ | |
"name": "nominatif", | |
"children": [{ | |
"name": "charade BBA", | |
"children": [{ | |
"name": "ACXIOM", | |
"size": 21 | |
}, { | |
"name": "ARVATO", | |
"size": 50 | |
}, { | |
"name": "BASE_PLUS", | |
"size": 136 | |
}, { | |
"name": "B_and_C", | |
"size": 424 | |
}, { | |
"name": "ETO", | |
"size": 68 | |
}, { | |
"name": "HSK_MD", | |
"size": 141 | |
}, { | |
"name": "PJMS", | |
"size": 84 | |
}, { | |
"name": "PN_DATA", | |
"size": 72 | |
}, { | |
"name": "SOGEC_", | |
"size": 1052 | |
}, { | |
"name": "USI", | |
"size": 120 | |
}, { | |
"name": "SNA", | |
"size": 14 | |
} | |
] | |
}, { | |
"name": "charade ENT", | |
"children": [{ | |
"name": "inconnu", | |
"size": 9 | |
}] | |
}, { | |
"name": "Estocade", | |
"children": [{ | |
"name": "inconnu", | |
"size": 87 | |
}] | |
}, { | |
"name": "Nouveaux voisins", | |
"children": [{ | |
"name": "CARTEGIE", | |
"size": 321 | |
}, { | |
"name": "MEDIAPOST", | |
"size": 485 | |
} | |
] | |
}, { | |
"name": "Robinson", | |
"children": [{ | |
"name": "inconnu", | |
"size": 42 | |
}] | |
}] | |
}, { | |
"name": "geographique", | |
"children": [{ | |
"name": "geographique", | |
"children": [{ | |
"name": "AMABIS", | |
"size": 247 | |
}, { | |
"name": "EXPERIAN", | |
"size": 486 | |
}, { | |
"name": "MEDIAPOST", | |
"size": 1384 | |
}, { | |
"name": "UNISERV_GMBH", | |
"size": 441 | |
} | |
] | |
}] | |
}, { | |
"name": "expertise", | |
"children": [{ | |
"name": "inconnu", | |
"children": [{ | |
"name": "inconnu", | |
"size": 38 | |
}] | |
}] | |
}] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<style> | |
form { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
} | |
svg { | |
font: 10px sans-serif; | |
} | |
</style> | |
<svg width="960" height="570"></svg> | |
<form> | |
<label><input type="radio" name="mode" value="sumBySize" checked> Size</label> | |
<label><input type="hidden" name="mode" value="sumByCount"> Count</label> | |
</form> | |
<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 fader = function(color) { return d3.interpolateRgb(color, "#fff")(0.2); }, | |
color = d3.scaleOrdinal(d3.schemeCategory20.map(fader)), | |
format = d3.format(",d"); | |
var treemap = d3.treemap() | |
.tile(d3.treemapResquarify) | |
.size([width, height]) | |
.round(true) | |
.paddingInner(1); | |
d3.json("flare.json", function(error, data) { | |
if (error) throw error; | |
var root = d3.hierarchy(data) | |
.eachBefore(function(d) { d.data.id = (d.parent ? d.parent.data.id + "." : "") + d.data.name; }) | |
.sum(sumBySize) | |
.sort(function(a, b) { return b.height - a.height || b.value - a.value; }); | |
treemap(root); | |
var cell = svg.selectAll("g") | |
.data(root.leaves()) | |
.enter().append("g") | |
.attr("transform", function(d) { return "translate(" + d.x0 + "," + d.y0 + ")"; }); | |
cell.append("rect") | |
.attr("id", function(d) { return d.data.id; }) | |
.attr("width", function(d) { return d.x1 - d.x0; }) | |
.attr("height", function(d) { return d.y1 - d.y0; }) | |
.attr("fill", function(d) { return color(d.parent.data.id); }); | |
cell.append("clipPath") | |
.attr("id", function(d) { return "clip-" + d.data.id; }) | |
.append("use") | |
.attr("xlink:href", function(d) { return "#" + d.data.id; }); | |
cell.append("text") | |
.attr("clip-path", function(d) { return "url(#clip-" + d.data.id + ")"; }) | |
.selectAll("tspan") | |
.data(function(d) { return d.data.name.split(/(?=[A-Z][^A-Z])/g); }) | |
.enter().append("tspan") | |
.attr("x", 4) | |
.attr("y", function(d, i) { return 13 + i * 10; }) | |
.text(function(d) { return d; }); | |
cell.append("title") | |
.text(function(d) { return d.data.id + "\n" + format(d.value); }); | |
d3.selectAll("input") | |
.data([sumBySize, sumByCount], function(d) { return d ? d.name : this.value; }) | |
.on("change", changed); | |
}); | |
function sumByCount(d) { | |
return d.children ? 0 : 1; | |
} | |
function sumBySize(d) { | |
return d.size; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment