-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
sunburst-with-value-accessor.html
87 lines (73 loc) · 2.52 KB
/
sunburst-with-value-accessor.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html lang="en">
<head>
<title>dc.js - Sunburst with Reductio</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/dc.css"/>
<style>
.pie-slice path {
stroke: #fff;
}
.dc-chart .selected path {
stroke-width: 1px;
stroke: #fff;
}
</style>
</head>
<body>
<div class="container">
<script type="text/javascript" src="header.js"></script>
<p>
This example uses <a href="https://github.com/crossfilter/reductio">Reductio</a> to reduce groups.
It generates multiple reductions - the chart uses one of the those using a custom value accessor.
This example also demonstrates fix for issue <a href="https://github.com/dc-js/dc.js/issues/1440">#1440</a>.
</p>
<div id="test"></div>
<script type="text/javascript" src="../js/promise-polyfill.js"></script>
<script type="text/javascript" src="../js/fetch.umd.js"></script>
<script type="text/javascript" src="../js/d3.js"></script>
<script type="text/javascript" src="../js/crossfilter.js"></script>
<script type="text/javascript" src="../js/reductio.js"></script>
<script type="text/javascript" src="../js/dc.js"></script>
<script type="text/javascript">
d3.csv('ordered_returned.csv').then(function (dataset){
dataset.forEach(function(d){
d.number_ordered = +d.number_ordered;
d.number_returned = +d.number_returned;
d.amount = +d.amount;
})
var ndx = crossfilter(dataset);
var dimension = ndx.dimension(function (d) {
return [d.category, d.sub_category];
});
var group = dimension.group();
var reducer = reductio();
reducer
.value('_ordered')
.exception(
function (d) {
return d.item_id;
}
)
.exceptionSum(function (d) {
return d.number_ordered;
});
reducer(group);
var sunBurstChart = dc.sunburstChart("#test");
sunBurstChart
.width(800)
.height(600)
.innerRadius(100)
.dimension(dimension)
.group(group)
.valueAccessor(function (d) {
return d.value._ordered.exceptionSum;
})
.legend(dc.legend());
dc.renderAll();
});
</script>
</div>
</body>
</html>