-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
298 lines (270 loc) · 8.97 KB
/
index.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<html>
<head>
<meta charset="utf-8">
<!-- START SIGMA IMPORTS -->
<script src="src/sigma.core.js"></script>
<script src="src/conrad.js"></script>
<script src="src/utils/sigma.utils.js"></script>
<script src="src/utils/sigma.polyfills.js"></script>
<script src="src/sigma.settings.js"></script>
<script src="src/classes/sigma.classes.dispatcher.js"></script>
<script src="src/classes/sigma.classes.configurable.js"></script>
<script src="src/classes/sigma.classes.graph.js"></script>
<script src="src/classes/sigma.classes.camera.js"></script>
<script src="src/classes/sigma.classes.quad.js"></script>
<script src="src/classes/sigma.classes.edgequad.js"></script>
<script src="src/captors/sigma.captors.mouse.js"></script>
<script src="src/captors/sigma.captors.touch.js"></script>
<script src="src/renderers/sigma.renderers.canvas.js"></script>
<script src="src/renderers/sigma.renderers.webgl.js"></script>
<script src="src/renderers/sigma.renderers.svg.js"></script>
<script src="src/renderers/sigma.renderers.def.js"></script>
<script src="src/renderers/webgl/sigma.webgl.nodes.def.js"></script>
<script src="src/renderers/webgl/sigma.webgl.nodes.fast.js"></script>
<script src="src/renderers/webgl/sigma.webgl.edges.def.js"></script>
<script src="src/renderers/webgl/sigma.webgl.edges.fast.js"></script>
<script src="src/renderers/webgl/sigma.webgl.edges.arrow.js"></script>
<script src="src/renderers/canvas/sigma.canvas.labels.def.js"></script>
<script src="src/renderers/canvas/sigma.canvas.hovers.def.js"></script>
<script src="src/renderers/canvas/sigma.canvas.nodes.def.js"></script>
<script src="src/renderers/canvas/sigma.canvas.edges.def.js"></script>
<script src="src/renderers/canvas/sigma.canvas.edges.curve.js"></script>
<script src="src/renderers/canvas/sigma.canvas.edges.arrow.js"></script>
<script src="src/renderers/canvas/sigma.canvas.edges.curvedArrow.js"></script>
<script src="src/renderers/canvas/sigma.canvas.edgehovers.def.js"></script>
<script src="src/renderers/canvas/sigma.canvas.edgehovers.curve.js"></script>
<script src="src/renderers/canvas/sigma.canvas.edgehovers.arrow.js"></script>
<script src="src/renderers/canvas/sigma.canvas.edgehovers.curvedArrow.js"></script>
<script src="src/renderers/canvas/sigma.canvas.extremities.def.js"></script>
<script src="src/renderers/svg/sigma.svg.utils.js"></script>
<script src="src/renderers/svg/sigma.svg.nodes.def.js"></script>
<script src="src/renderers/svg/sigma.svg.edges.def.js"></script>
<script src="src/renderers/svg/sigma.svg.edges.curve.js"></script>
<script src="src/renderers/svg/sigma.svg.labels.def.js"></script>
<script src="src/renderers/svg/sigma.svg.hovers.def.js"></script>
<script src="src/middlewares/sigma.middlewares.rescale.js"></script>
<script src="src/middlewares/sigma.middlewares.copy.js"></script>
<script src="src/misc/sigma.misc.animation.js"></script>
<script src="src/misc/sigma.misc.bindEvents.js"></script>
<script src="src/misc/sigma.misc.bindDOMEvents.js"></script>
<script src="src/misc/sigma.misc.drawHovers.js"></script>
<!-- END SIGMA IMPORTS -->
<script src="plugins/sigma.parsers.gexf/gexf-parser.js"></script>
<script src="plugins/sigma.parsers.gexf/sigma.parsers.gexf.js"></script>
<script src="plugins/sigma.plugins.filter/sigma.plugins.filter.js"></script>
<link href='http://fonts.googleapis.com/css?family=Lato:300,700' rel='stylesheet' type='text/css'>
<div id="container">
<style>
body {
color: #333;
font-size: 14px;
font-family: Lato, sans-serif;
}
#graph-container {
top: 0;
bottom: 0;
left: 0;
right: 0;
position: absolute;
}
#control-pane {
top: 10px;
/*bottom: 10px;*/
right: 10px;
position: absolute;
width: 230px;
background-color: rgb(249, 247, 237);
box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
#control-pane > div {
margin: 10px;
overflow-x: auto;
}
.line {
clear: both;
display: block;
width: 100%;
margin: 0;
padding: 12px 0 0 0;
border-bottom: 1px solid #aac789;
background: transparent;
}
h2, h3, h4 {
padding: 0;
font-variant: small-caps;
}
.green {
color: #437356;
}
h2.underline {
color: #437356;
background: #f4f0e4;
margin: 0;
border-radius: 2px;
padding: 8px 12px;
font-weight: 700;
}
.hidden {
display: none;
visibility: hidden;
}
input[type=range] {
width: 160px;
}
</style>
</head>
<body>
<div id="graph-container"></div>
<div id="control-pane">
<h2 class="underline">台灣種豬品種與肉質基因視覺化</h2>
<div>
<h3>子代數 <span id="min-degree-val">0</span></h3>
0 <input id="min-degree" type="range" min="0" max="0" value="0"> <span id="max-degree-value">0</span><br>
</div>
<div>
<h3>肉質基因</h3>
<select id="node-category">
<option value="" selected>All categories</option>
</select>
</div>
<span class="line"></span>
<div>
<button id="reset-btn">Reset filters</button>
<button id="export-btn">Export</button>
</div>
<div id="dump" class="hidden"></div>
</div>
</div>
<script>
/**
* This is an example on how to use sigma filters plugin on a real-world graph.
*/
var filter;
/**
* DOM utility functions
*/
var _ = {
$: function (id) {
return document.getElementById(id);
},
all: function (selectors) {
return document.querySelectorAll(selectors);
},
removeClass: function(selectors, cssClass) {
var nodes = document.querySelectorAll(selectors);
var l = nodes.length;
for ( i = 0 ; i < l; i++ ) {
var el = nodes[i];
// Bootstrap compatibility
el.className = el.className.replace(cssClass, '');
}
},
addClass: function (selectors, cssClass) {
var nodes = document.querySelectorAll(selectors);
var l = nodes.length;
for ( i = 0 ; i < l; i++ ) {
var el = nodes[i];
// Bootstrap compatibility
if (-1 == el.className.indexOf(cssClass)) {
el.className += ' ' + cssClass;
}
}
},
show: function (selectors) {
this.removeClass(selectors, 'hidden');
},
hide: function (selectors) {
this.addClass(selectors, 'hidden');
},
toggle: function (selectors, cssClass) {
var cssClass = cssClass || "hidden";
var nodes = document.querySelectorAll(selectors);
var l = nodes.length;
for ( i = 0 ; i < l; i++ ) {
var el = nodes[i];
//el.style.display = (el.style.display != 'none' ? 'none' : '' );
// Bootstrap compatibility
if (-1 !== el.className.indexOf(cssClass)) {
el.className = el.className.replace(cssClass, '');
} else {
el.className += ' ' + cssClass;
}
}
}
};
function updatePane (graph, filter) {
// get max degree
var maxDegree = 0,
categories = {};
// read nodes
graph.nodes().forEach(function(n) {
maxDegree = Math.max(maxDegree, graph.degree(n.id));
categories[n.attributes.g3] = true;
})
// min degree
_.$('min-degree').max = maxDegree;
_.$('max-degree-value').textContent = maxDegree;
// node category
var nodecategoryElt = _.$('node-category');
Object.keys(categories).forEach(function(c) {
var optionElt = document.createElement("option");
optionElt.text = c;
nodecategoryElt.add(optionElt);
});
// reset button
_.$('reset-btn').addEventListener("click", function(e) {
_.$('min-degree').value = 0;
_.$('min-degree-val').textContent = '0';
_.$('node-category').selectedIndex = 0;
filter.undo().apply();
_.$('dump').textContent = '';
_.hide('#dump');
});
// export button
_.$('export-btn').addEventListener("click", function(e) {
var chain = filter.export();
console.log(chain);
_.$('dump').textContent = JSON.stringify(chain);
_.show('#dump');
});
}
// Initialize sigma with the dataset:
// e-Diaspora Moroccan corpus of websites
// by Dana Diminescu & Matthieu Renault
// http://www.e-diasporas.fr/wp/moroccan.html
sigma.parsers.gexf('data/Yifan_node.gexf', {
container: 'graph-container',
settings: {
edgeColor: 'default',
defaultEdgeColor: '#ccc'
}
}, function(s) {
// Initialize the Filter API
filter = new sigma.plugins.filter(s);
updatePane(s.graph, filter);
function applyMinDegreeFilter(e) {
var v = e.target.value;
_.$('min-degree-val').textContent = v;
filter
.undo('min-degree')
.nodesBy(function(n) {
return this.degree(n.id) >= v;
}, 'min-degree')
.apply();
}
function applyCategoryFilter(e) {
var c = e.target[e.target.selectedIndex].value;
filter
.undo('node-category')
.nodesBy(function(n) {
return !c.length || n.attributes.g3 === c;
}, 'node-category')
.apply();
}
_.$('min-degree').addEventListener("input", applyMinDegreeFilter); // for Chrome and FF
_.$('min-degree').addEventListener("change", applyMinDegreeFilter); // for IE10+, that sucks
_.$('node-category').addEventListener("change", applyCategoryFilter);
});
</script>
</body>
</html>