-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogical.html
172 lines (149 loc) · 4.61 KB
/
logical.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<meta charset="utf-8">
<!-- <meta http-equiv="refresh" content="60"/> -->
<style>
path {
stroke: #e6e8e8;
fill-rule: evenodd;
}
text {
font: 12px/1.2 Helvetica, Arial, sans-serif;
}
text.center {
font: 16px/1.2 Helvetica, Arial, sans-serif;
}
</style>
<body>
<script src="d3.v3.min.js"></script>
<script>
var width = 480,
height = 520,
radius = Math.min(width, height) / 2 - 1;
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+20)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + (height / 2 + 10) + ")");
var partition = d3.layout.partition()
.value(function(d) { return 1; });
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("json/pgdump.php", function(error, root) {
var g = svg.selectAll("g")
.data(partition.nodes(root))
.enter().append("g");
var path = g.append("path")
.attr("d", arc)
.attr("width", 0)
.style("fill", function(d) {
switch (d.depth) {
case 0:
return "#5E6A71";
case 1:
return color((d.children ? d : d.parent).name);
case 2:
switch (d.state) {
case "active+clean": return "#00de00";
case "active+recovery_wait": return "#959595";
case "active+recovering": return "#aaaaaa";
case "stale+active+clean": return "#106e09";
case "stale+active+degraded": return "#c3bb00";
case "active+degraded": return "#e2d900";
case "active+clean+replay": return "#fff500";
case "peering": return "#ba1f69";
case "remapped+peering": return "#ba1f69";
case "active+recovering+remapped": return "#aaaaaa";
case "active+remapped": return "#00ac08";
case "active+recovery_wait+remapped": return "#959595";
case "creating": return "#80d2dc";
default: console.log(d.state); return "#000000";
}
default:
return color((d.children ? d : d.parent).name);
}
})
.on("click", click);
var text = g.append("text")
.attr("transform", function(d) {
switch (d.depth) {
case 0:
return "rotate(0)";
default:
return "rotate(" + computeTextRotation(d) + ")";
}
})
.attr("text-anchor", function(d) { return (d.depth == 0 ? "middle" : "start"); })
.attr("x", function(d) { return y(d.y); })
.attr("dx", "6") // margin
.attr("dy", ".35em") // vertical-align
.text(function(d) {
switch (d.depth) {
case 0:
return "v"+d.version;
case 1:
return d.pool_name;
default:
return "";
}
});
var tooltips = g.append("svg:title").text(function(d) {
switch (d.depth) {
case 0:
return "";
case 1:
return "";
default:
return d.objects+":"+d.state;
}
});
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(300)
.attr("opacity", 1)
.attr("transform", function(d) {
switch (d.depth) {
case 0:
return "rotate(0)";
default:
return "rotate(" + computeTextRotation(d) + ")";
}
})
.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>