2017-11-16 23:57:21 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This may be restructured in the future - code to create diagrams will live here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function createTestPieChart(containerId, dataset) {
|
2017-11-18 12:49:33 +01:00
|
|
|
var width = 100;
|
|
|
|
var height = 100;
|
|
|
|
// Build the basic container for the chart
|
2017-11-16 23:57:21 +01:00
|
|
|
var svg = d3.select(containerId)
|
2017-11-18 12:49:33 +01:00
|
|
|
.append("div")
|
|
|
|
.classed("svg-container", true)
|
2017-11-16 23:57:21 +01:00
|
|
|
.append("svg")
|
2017-11-18 12:49:33 +01:00
|
|
|
.attr("preserveAspectRatio", "xMinYMin meet")
|
|
|
|
.attr("viewBox", "0 0 " + width + " " + height + "")
|
|
|
|
.classed("svg-content-responsive", true)
|
2017-11-16 23:57:21 +01:00
|
|
|
.append("g")
|
|
|
|
.attr("transform", "translate(" + (width / 2) + "," + (height / 2) + ")");
|
|
|
|
|
2017-11-18 12:49:33 +01:00
|
|
|
// Preparations are done, now let's build the pie chart
|
|
|
|
var radius = Math.min(width, height) / 2;
|
|
|
|
var color = d3.scaleOrdinal(d3.schemeCategory10);
|
|
|
|
|
2017-11-16 23:57:21 +01:00
|
|
|
var arc = d3.arc()
|
|
|
|
.innerRadius(0)
|
|
|
|
.outerRadius(radius);
|
|
|
|
|
|
|
|
var pie = d3.pie()
|
|
|
|
.value(function(d) { return d.count; })
|
|
|
|
.sort(null);
|
|
|
|
|
|
|
|
var path = svg.selectAll("path")
|
|
|
|
.data(pie(dataset))
|
|
|
|
.enter()
|
|
|
|
.append("path")
|
|
|
|
.attr("d", arc)
|
|
|
|
.attr("fill", function(d, i) {
|
|
|
|
return color(d.data.label);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|