Skip to content

Instantly share code, notes, and snippets.

@clodio
Last active February 7, 2017 13:45
Show Gist options
  • Select an option

  • Save clodio/74e49901d861c55298160c6bee59f7b9 to your computer and use it in GitHub Desktop.

Select an option

Save clodio/74e49901d861c55298160c6bee59f7b9 to your computer and use it in GitHub Desktop.
charade

Sunburst with Labels HT kEUR new

{
"name": "sna",
"children": [{
"name": "BBA indirect",
"children": [{
"name": "BASE PLUS",
"size": 2553
}, {
"name": "ETO",
"size": 24325
}, {
"name": "IOS ARVATO",
"size": 11683
}, {
"name": "PN DATA",
"size": 5980
}, {
"name": "UNISERVICES INFORMATIQUE",
"size": 0
}]
}, {
"name": "BBA-CHARADE B2C direct",
"children": [{
"name": "SNA",
"size": 739224
}]
}, {
"name": "CHARADE B2B indirect",
"children": [{
"name": "SOGEC DATAMARK SERVICES",
"size": 40588
}, {
"name": "UNISERVICES INFORMATIQUE",
"size": 1750
}]
}, {
"name": "CHARADE B2C direct",
"children": [{
"name": "ASPHERIA RADAR",
"size": 53941
}, {
"name": "DOCAPOST PREPROD",
"size": 2577
}, {
"name": "DOCAPOST PROD",
"size": 116704
}, {
"name": "ECRM LAPOSTE VIA ATOS",
"size": 297703
}, {
"name": "EVA_SNA LA POSTE",
"size": 146604
}, {
"name": "SNA",
"size": 713508
}]
}, {
"name": "CHARADE B2C indirect",
"children": [{
"name": "ACXIOM",
"size": 206050
}, {
"name": "BASE PLUS",
"size": 853849
}, {
"name": "ETO",
"size": 357159
}, {
"name": "HSK MD",
"size": 1054843
}, {
"name": "IOS ARVATO",
"size": 291970
}, {
"name": "PAGES JAUNES MARKETING SERVICES",
"size": 319266
}, {
"name": "PN DATA",
"size": 317609
}, {
"name": "SOGEC DATAMARK SERVICES",
"size": 7464919
}, {
"name": "UNISERVICES INFORMATIQUE",
"size": 811235
}]
}, {
"name": "CHARADE B2C indirect (strict)",
"children": [{
"name": "BISNODE FRANCE",
"size": 3207904
}]
}]
}
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
stroke: #fff;
fill-rule: evenodd;
cursor: pointer
}
text {
font-family: Arial, sans-serif;
font-size: 11px;
cursor: pointer;
}
</style>
<body>
Charade : Nb Adresses par client/gamme pour 2016
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 1500,
height = 1000,
radius = Math.min(width, height) / 2;
var x = d3.scale.linear()
.range([0, 2 * Math.PI]);
var y = d3.scale.linear()
.range([0, radius]);
var color = d3.scale.category20c();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + (height / 2 + 10) + ")");
var partition = d3.layout.partition()
.value(function(d) {
return d.size;
});
var arc = d3.svg.arc()
.startAngle(function(d) {
return Math.max(0, Math.min(2 * Math.PI, x(d.x)));
})
.endAngle(function(d) {
return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx)));
})
.innerRadius(function(d) {
return Math.max(0, y(d.y));
})
.outerRadius(function(d) {
return Math.max(0, y(d.y + d.dy));
});
d3.json("data.json", function(error, root) {
var g = svg.selectAll("g")
.data(partition.nodes(root))
.enter().append("g");
var path = g.append("path")
.attr("d", arc)
.style("fill", function(d) {
return color((d.children ? d : d.parent).name);
})
.on("click", click)
.on("mouseover", doHover)
.on("mouseout", unDoHover);
var text = g.append("text")
.attr("transform", function(d) {
return "rotate(" + computeTextRotation(d) + ")";
})
.attr("x", function(d) {
return y(d.y);
})
.attr("dx", "6") // margin
.attr("dy", ".35em") // vertical-align
.text(function(d) {
return d.name;
}).on("click", click)
.on("mouseover", doHover)
.on("mouseout", unDoHover);
function click(d) {
// fade out all text elements
text.transition().attr("opacity", 0);
path.transition()
.duration(750)
.attrTween("d", arcTween(d))
.each("end", function(e, i) {
// check if the animated element's data e lies within the visible angle span given in d
if (e.x >= d.x && e.x < (d.x + d.dx)) {
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
stroke: #fff;
fill-rule: evenodd;
}
text {
font-family: Arial, sans-serif;
font-size: 12px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 1500,
height = 1000,
radius = Math.min(width, height) / 2;
var x = d3.scale.linear()
.range([0, 2 * Math.PI]);
var y = d3.scale.linear()
.range([0, radius]);
var color = d3.scale.category20c();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + (height / 2 + 10) + ")");
var partition = d3.layout.partition()
.value(function(d) { return d.size; });
var arc = d3.svg.arc()
.startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
.endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
.innerRadius(function(d) { return Math.max(0, y(d.y)); })
.outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });
d3.json("flare.json", function(error, root) {
var g = svg.selectAll("g")
.data(partition.nodes(root))
.enter().append("g");
var path = g.append("path")
.attr("d", arc)
.style("fill", function(d) { return color((d.children ? d : d.parent).name); })
.on("click", click);
var text = g.append("text")
.attr("transform", function(d) { return "rotate(" + computeTextRotation(d) + ")"; })
.attr("x", function(d) { return y(d.y); })
.attr("dx", "6") // margin
.attr("dy", ".35em") // vertical-align
.text(function(d) { return d.name; });
function click(d) {
// fade out all text elements
text.transition().attr("opacity", 0);
path.transition()
.duration(750)
.attrTween("d", arcTween(d))
.each("end", function(e, i) {
// check if the animated element's data e lies within the visible angle span given in d
if (e.x >= d.x && e.x < (d.x + d.dx)) {
// get a selection of the associated text element
var arcText = d3.select(this.parentNode).select("text");
// fade in the text element and recalculate positions
arcText.transition().duration(750)
.attr("opacity", 1)
.attr("transform", function() { return "rotate(" + computeTextRotation(e) + ")" })
.attr("x", function(d) { return y(d.y); });
}
});
}
});
d3.select(self.frameElement).style("height", height + "px");
// Interpolate the scales!
function arcTween(d) {
var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
yd = d3.interpolate(y.domain(), [d.y, 1]),
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
return function(d, i) {
return i
? function(t) { return arc(d); }
: function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); };
};
}
function computeTextRotation(d) {
return (x(d.x + d.dx / 2) - Math.PI / 2) / Math.PI * 180;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment