-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathda.js
More file actions
100 lines (77 loc) · 2.09 KB
/
da.js
File metadata and controls
100 lines (77 loc) · 2.09 KB
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
88
89
90
91
92
93
94
95
96
97
98
var size = 600;
var planetSize = size/6;
var stroke = planetSize / 4;
var width = size,
height = size,
radius = (Math.min(width, height) - 2*planetSize) / 2;
var color = function(value)
{
var c = 120 * value;
return 'hsl('+ c +',100%,60%)';
};
var arc = d3.svg.arc()
.outerRadius(radius - stroke*2)
.innerRadius(radius * 0.3);
var labelArc = d3.svg.arc()
.outerRadius(radius - stroke*2)
.innerRadius(radius - stroke*3);
var labelBorder = d3.svg.arc()
.outerRadius(planetSize)
//.innerRadius(planetSize - stroke)
.startAngle(0)
.endAngle(Math.PI * 2);
var labelBackground = d3.svg.arc()
.outerRadius(planetSize - stroke)
.innerRadius(0)
.startAngle(0)
.endAngle(Math.PI * 2);
var pie = d3.layout.pie()
.value(function(d) { return 1; });
var data = [
{
"symbol": "🔑",
"value": 0.33
},
{
"symbol": "🔒",
"value": 0.66
},
{
"symbol": "💡",
"value": 0.0
}
];
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.data([data])
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var g = svg.selectAll(".arc")
.data(pie)
.enter().append("g")
.attr("class", "arc");
/*
g.append("path")
.attr("d", arc)
.style("fill", function(d) { return color(d.data.value); });
*/
g.append("path")
.attr("d", labelArc)
.style("fill", "black")
.style("stroke", "black");
/*g.append("path")
.attr("d", labelBackground)
.attr("transform", function(d) { return "translate(" + labelArc.centroid(d) + ")"; })
.style("fill", "white");*/
g.append("path")
.attr("d", labelBorder)
.attr("transform", function(d) { return "translate(" + labelArc.centroid(d) + ")"; })
.style("fill", "black");
g.append("text")
.attr("transform", function(d) { return "translate(" + labelArc.centroid(d) + ")"; })
.attr("dy", (planetSize * 0.3) + "px")
.style("fill","white")
.style("font", planetSize + "px sans-serif")
.style("text-anchor", "middle")
.text(function(d) { return d.data.symbol; });