-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfovis_brunner_sharma.html
executable file
·153 lines (128 loc) · 4.66 KB
/
infovis_brunner_sharma.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
<!DOCTYPE html>
<html>
<head>
<title>InfoVis - Brunner, Sharma</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="./styles/custom.css">
<link type="text/css" rel="stylesheet" href="./styles/category-colors.css">
</head>
<body>
<div class="root">
<div class="chart">
<script type="text/javascript" src="./scripts/d3.js"></script>
<script type="text/javascript" src="./scripts/d3.layout.js"></script>
<script type="text/javascript">
var w = 1100,
h = 920,
r = 920,
x = d3.scale.linear().range([0, r]),
y = d3.scale.linear().range([0, r]),
panThreshold = 39,
panLevel = 1,
node,
root,
categoryClasses;
// Init color matching JSON
d3.json("data/category-color-matching.json", function(data) {
categoryClasses = data;
});
var pack = d3.layout.pack()
.size([r, r])
.value(function(d) { return d.size; })
var vis = d3.select(".chart").insert("svg:svg", "h2")
.attr("width", w)
.attr("height", h)
.append("svg:g")
.attr("transform", "translate(" + (w - r) / 2 + "," + (h - r) / 2 + ")");
d3.json("data/infovis_bru_sha.json", function(data) {
node = root = data;
var nodes = pack.nodes(root);
vis.selectAll("circle")
.data(nodes)
.enter().append("svg:circle")
.attr("class", function(d) {
var base = d.children ? "parent " : "child ";
// Add custom coloring depending on the category
return base += addCategoryColor(d.name);
})
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("r", function(d) { return d.r; })
.on("click", function(d) { return pan(node == d ? root : d); });
vis.selectAll("text")
.data(nodes)
.enter().append("svg:text")
.attr("class", function(d) {
var base = "text-level-" + d.depth + " ";
return d.children ? base + "parent" : base + "child"; })
.attr("x", function(d) { return d.x; })
.attr("y", function(d) { return d.y; })
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.style("opacity", function(d) {
// +80 due to init
return d.r > ( panThreshold + 80) ? 1 : 0;
})
.text(function(d) { return d.name; });
d3.select(window).on("click", function() { pan(root); });
});
function pan(d, i) {
var k = r / d.r / 2;
x.domain([d.x - d.r, d.x + d.r]);
y.domain([d.y - d.r, d.y + d.r]);
var t = vis.transition()
.duration(d3.event.altKey ? 7500 : 750);
t.selectAll("circle")
.attr("cx", function(d) { return x(d.x); })
.attr("cy", function(d) { return y(d.y); })
.attr("r", function(d) { return k * d.r; });
t.selectAll("text")
.attr("x", function(d) { return x(d.x); })
.attr("y", function(d) { return y(d.y); })
.style("opacity", function(d) {
return k * d.r > (panThreshold + 10) ? 1 : 0;
});
node = d;
d3.event.stopPropagation();
}
// returs color codes depending on the category name
function addCategoryColor(category) {
if(category === undefined) return "";
var defaultClasses = "medium-opacity ",
position = categoryClasses[category];
if(position !== undefined) {
return defaultClasses + "fill-" + position;
}
return "";
}
</script>
</div>
<div class="legend">
<h4>World Explorer</h4>
<h3><span style="margin-left:160px"><i>Brunner Daniel</i></h3></span>
<h3><span style="margin-left:160px"><i>Sharma Adwait</i></h3>
<div class="legend--holder">
<h3><b>Legend</h3></b>
<ul>
<li class="legend--navy">Basic form of government</li>
<li class="legend--blue">Continent</li>
<li class="legend--aqua">Demonym</li>
<li class="legend--teal">Diplomatic relation</li>
<li class="legend--olive">Electrical plug type</li>
<li class="legend--green">Head of government</li>
<li class="legend--lime">Member of</li>
<li class="legend--yellow">Official language</li>
<li class="legend--orange">Shares border with</li>
<li class="legend--red">Territorial entity</li>
<li class="legend--maroon">Top-level internet domain</li>
<li class="legend--fuchsia">Public holiday</li>
<li class="legend--purple">Located in time zone</li>
<li class="legend--black">Population</li>
<li class="legend--gray">Electrical plug type</li>
<li class="legend--silver">Official language</li>
</ul>
</div>
</div>
</div>
</body>
</html>