-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
executable file
·398 lines (368 loc) · 13.9 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!-- SVG graph renderer based on d3.js
Created as NoMaD experiment at 28.12.13
Author: Evgeny Blokhin -->
<!DOCTYPE html>
<html>
<head>
<title>Semantic Web Genealogical Trees</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<style>
*{font-family:Arial;margin:0;padding:0;}
.edge{
fill:none;
stroke:#fc6;
stroke-width:1px;
}
.edge.isMotherOf{
stroke:#f09;
}
.edge.isFatherOf{
stroke:#09f;
}
circle{
fill:#fff;
stroke:#999;
stroke-width:1px;
cursor:move;
}
text{
font-size:13px;
cursor:pointer;
/*text-shadow:0 2px 0 #fff, 2px 0 0 #fff, 0 -2px 0 #fff, -2px 0 0 #fff;*/
fill:#000;
}
text.shadow{
stroke:#fff;
stroke-width:3px;
stroke-opacity:0.8;
}
marker#isMotherOf{
fill:#f09;
}
marker#isFatherOf{
fill:#09f;
}
#mmreasoner_legend{
position:fixed;z-index:99999;top:0;left:0;padding:10px;width:220px;height:auto;background:#fcfcfc;line-height:1.6em;font-size:0.85em;border-right:1px solid #ddd;border-bottom:1px solid #ddd;
}
ul li{
list-style:none;
}
span.leg_circ{
display:inline-block;width:10px;height:10px;border:1px solid #999;border-radius:6px;margin-right:10px;
}
span.i18n{
display:none;
}
#fileapi_container{
display:none;
width:100%;
height:30px;
position:relative;
margin-top:15px;
}
#fileapi_container button{
width:100%;
position:absolute;
top:0;left:0;
}
#fileapi_container input {
width:100%;
position:absolute;
top:0;left:0;
filter: alpha(opacity=0);
opacity: 0;
}
/* "Fork me on GitHub" CSS ribbon v0.1.1 */
.github-fork-ribbon {
position: fixed;
padding: 2px 0;
background-color: #666;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0)), to(rgba(0, 0, 0, 0.15)));
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.15));
-webkit-box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.5);
box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.5);
font: 500 9px "Helvetica Neue", Helvetica, Arial, sans-serif;
z-index: 9999;
pointer-events: auto;
}
.github-fork-ribbon a,
.github-fork-ribbon a:hover {
color: #fff;
text-decoration: none;
text-shadow: 0 -1px rgba(0, 0, 0, 0.5);
text-align: center;
width: 100px;
line-height: 12px;
display: inline-block;
padding: 2px 0;
border-width: 1px 0;
border-style: dotted;
border-color: #fff;
border-color: rgba(255, 255, 255, 1);
}
.github-fork-ribbon-wrapper {
width: 100px;
height: 100px;
position: fixed;
overflow: hidden;
top: 0;
z-index: 9999;
pointer-events: none;
}
.github-fork-ribbon-wrapper.right {
right: 0;
}
.github-fork-ribbon-wrapper.right .github-fork-ribbon {
top: 16px;
right: -22px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
</style>
<!--[if lt IE 9]>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.1.1/gh-fork-ribbon.ie.min.css" />
<![endif]-->
<script type="text/javascript" src="d3.v3.5.6.min.js"></script>
</head>
<body>
<div id="mmreasoner_legend">
<div style="width:100%;text-align:center;"><b><span class="i18n i18n_ru">Обозначения</span><span class="i18n i18n_en">Legend</span></b>:</div>
<ul>
<li><span style="font-size:2em;color:#f09;">→</span> <span class="i18n i18n_ru">Связи мать — дети</span><span class="i18n i18n_en">Mother-children links</span></li>
<li><span style="font-size:2em;color:#09f;">→</span> <span class="i18n i18n_ru">Связи отец — дети</span><span class="i18n i18n_en">Father-children links</span></li>
<li><span style="font-size:2em;color:#fc6;">—</span> <span class="i18n i18n_ru">Брачные связи</span><span class="i18n i18n_en">Marriage links</span></li>
<li style="color:#06f;"><span class="leg_circ" style="background:#06f;"></span><span class="i18n i18n_ru">Деды и бабки</span><span class="i18n i18n_en">Grandparent</span></li>
<li style="color:#6cf;"><span class="leg_circ" style="background:#6cf;"></span><span class="i18n i18n_ru">Прадеды и прабабки</span><span class="i18n i18n_en">Great-grandparent</span></li>
<li style="color:#396;"><span class="leg_circ" style="background:#396;"></span><span class="i18n i18n_ru">Внуки</span><span class="i18n i18n_en">Grandchildren</span></li>
<li style="color:#9c6;"><span class="leg_circ" style="background:#9c6;"></span><span class="i18n i18n_ru">Правнуки</span><span class="i18n i18n_en">Great-grandchildren</span></li>
<li style="color:#90c;"><span class="leg_circ" style="background:#90c;"></span><span class="i18n i18n_ru">Дядьки и тётки</span><span class="i18n i18n_en">Uncles and aunts</span></li>
<li style="color:#f90;"><span class="leg_circ" style="background:#f90;"></span><span class="i18n i18n_ru">Племянники и племянницы</span><span class="i18n i18n_en">Nephews and nieces</span></li>
<li style="color:#f00;"><span class="leg_circ" style="background:#f00;"></span><span class="i18n i18n_ru">Братья, сёстры, кузены</span><span class="i18n i18n_en">Brothers, sisters, cousins</span></li>
</ul>
<div style="width:100%;text-align:center;"><b><span class="i18n i18n_ru">Язык</span><span class="i18n i18n_en">Language</span></b>: <a href="#en" style="font-size:1.2em;">EN</a> <a href="#ru" style="font-size:1.2em;">RU</a></div>
<div id="fileapi_container"><button><span class="i18n i18n_ru">Загрузить родословную</span><span class="i18n i18n_en">Upload genealogy</span></button><input type="file" id="fileapi" /></div>
</div>
<div class="github-fork-ribbon-wrapper right">
<div class="github-fork-ribbon">
<a href="https://github.com/blokhin/genealogical-trees" target="_top">See on GitHub</a>
</div>
</div>
</body>
<script type="text/javascript">
var rel2col = {
'isGrandParentOf':'#396',
'hasGrandParent':'#06f',
'isGreatGrandParentOf':'#9c6',
'hasGreatGrandParent':'#6cf',
'isUncleOf':'#f90',
'hasUncle':'#90c',
'isGreatUncleOf':'#f90',
'hasGreatUncle':'#90c',
'isAuntOf':'#f90',
'hasAunt':'#90c',
'isGreatAuntOf':'#f90',
'hasGreatAunt':'#90c',
'isFirstCousinOf':'#f00',
'isSecondCousinOf':'#f00',
'isThirdCousinOf':'#f00'
};
var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4){
if (xmlhttp.status == 200){
var source = JSON.parse(xmlhttp.responseText);
build_graph(source);
} else alert("Error loading data!");
}
}
xmlhttp.open("GET", "data/tsars.json");
xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
xmlhttp.send();
window.onhashchange = hash_redraw_react;
document.location.hash ? hash_redraw_react() : document.location.replace('#en');
if (window.File && window.FileReader && window.FileList && window.Blob){
var fileapi = document.getElementById('fileapi'), fileapi_container = document.getElementById('fileapi_container');
fileapi_container.style.display = 'block';
var reader = new FileReader();
fileapi.onchange = function(){
if (!this.files[0] || !this.files[0].size) return alert("Error: file cannot be read (unaccessible?)");
reader.currentFilename = this.files[0].name;
reader.readAsText(this.files[0]);
}
reader.onloadend = function(evt){
var str = evt.target.result;
if (str.indexOf('"type": "label",') > 7){
var source = JSON.parse(str);
build_graph(source);
} else return alert("Error: the file format is not supported!");
}
}
function hash_redraw_react(){
var hash = document.location.hash.substr(1);
if (hash == 'ru'){
var i18n = document.getElementsByClassName('i18n'), i18n_ru = document.getElementsByClassName('i18n_ru');
for (var i=0, i18n_len=i18n.length; i < i18n_len; i++){
i18n[i].style.display = 'none';
}
for (var i=0, i18n_ru_len=i18n_ru.length; i < i18n_ru_len; i++){
i18n_ru[i].style.display = 'inline-block';
}
} else {
var i18n = document.getElementsByClassName('i18n'), i18n_en = document.getElementsByClassName('i18n_en');
for (var i=0, i18n_len=i18n.length; i < i18n_len; i++){
i18n[i].style.display = 'none';
}
for (var i=0, i18n_en_len=i18n_en.length; i < i18n_en_len; i++){
i18n_en[i].style.display = 'inline-block';
}
}
}
function html2utf(s){
var c,m,d = s;
arr=d.match(/&#[0-9]{1,5};/g);
if(arr!=null){
var x;
for (x=0; x<arr.length; x++){
m = arr[x];
c = m.substring(2,m.length-1);
if(c >= -32768 && c <= 65535){
d = d.replace(m, String.fromCharCode(c));
} else {
d = d.replace(m, "");
}
}
}
return d;
}
function build_graph(source){
var edges = [], nodes = {}, relationships = {}, labels = {}, counter = 0;
// Filter edges and compute the distinct nodes from the links
source.forEach(function(link){
if (link.type == 'isWifeOf' || link.type == 'isMotherOf' || link.type == 'isFatherOf'){
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
edges.push(link);
counter++;
} else if (link.type == 'label') {
labels[link.source] = html2utf(link.target);
} else {
if (relationships[link.source]){
if (relationships[link.source][link.type]) relationships[link.source][link.type].push(link.target);
else relationships[link.source][link.type] = [link.target];
} else {
var o = {};
o[link.type] = [link.target];
relationships[link.source] = o;
}
}
});
var table = {};
var i=0;
for (var p in nodes){
table[p] = i++;
}
var width = (counter > 75) ? 2250 : document.body.clientWidth-50;
var height = parseInt(0.8*width);
d3.select("svg").remove();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
// Per-type markers
svg.append("defs").selectAll("marker")
.data(["isMotherOf", "isFatherOf"])
.enter().append("marker")
.attr("id", function(d){return d})
.attr("viewBox", "0 0 40 20")
.attr("refX", 55)
.attr("refY", 10)
.attr("markerWidth", 16)
.attr("markerHeight", 12)
.attr("orient", "auto")
.append("polyline")
.attr("points", "0,0 40,10 0,20 10,10");
var force = d3.layout.force()
.size([width, height])
.nodes(d3.values(nodes)).links(edges)
.linkDistance(80)
.gravity(0.3)
.charge(-2500)
.on("tick", tick);
//.start();
var drag = force.drag()
.on("dragstart", function(d){
d3.select(this).classed("fixed", d.fixed = true);
});
var path = svg.append("g").selectAll("path")
.data(force.links())
.enter().append("path")
.attr("class", function(d) { return "edge " + d.type; })
.attr("marker-end", function(d) { return "url(#" + d.type + ")"; });
var circle = svg.append("g").selectAll("circle")
.data(force.nodes())
.enter().append("circle")
.attr("r", 5)
.attr("id", function(d,i) { return "c_"+table[d.name] })
.call(drag);
var text = svg.append("g").selectAll("g")
.data(force.nodes())
.enter().append("g");
// A copy of the text with a thick white stroke for legibility
text.append("text")
.attr("x", -20)
.attr("y", -10)
.attr("class", "shadow")
.attr("id", function(d,i) { return "s_"+table[d.name] })
.text(function(d) { return labels[d.name]; });
text.append("text")
.attr("x", -20)
.attr("y", -10)
.attr("id", function(d,i) { return "t_"+table[d.name] })
.text(function(d) { return labels[d.name]; });
circle.on("mouseover", function(d) { handle(d) });
text.on("mouseover", function(d) { handle(d) });
circle.on("mouseout", function(d) { dehandle(d) });
text.on("mouseout", function(d) { dehandle(d) });
function tick() {
path.attr("d", direct);
circle.attr("transform", transform);
text.attr("transform", transform);
}
function direct(d) {
return "M" + d.source.x + "," + d.source.y + " " + d.target.x + "," + d.target.y;
}
function transform(d) {
return "translate(" + d.x + "," + d.y + ")";
}
function handle(x){
if (relationships[x.name]){
for (var key in relationships[x.name]){
if (relationships[x.name].hasOwnProperty(key)){
var i;
for (i=0; i<relationships[x.name][key].length; i++){
d3.select('#c_' + table[relationships[x.name][key][i]]).style("fill", rel2col[key]);
d3.select('#t_' + table[relationships[x.name][key][i]]).style("fill", rel2col[key]);
}
}
}
}
}
function dehandle(x){
d3.selectAll('text').style("fill", "#000");
d3.selectAll('circle').style("fill", "#fff");
}
force.start();
for (var i = 5000; i > 0; --i) force.tick();
force.stop();
}
</script>
</html>