forked from OmarShafie/hadith
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
602 lines (568 loc) · 24 KB
/
demo.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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
<!DOCTYPE html>
<html lang="ar">
<head>
<title>Hadith Visual Search Engine</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" />
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<link rel="dns-prefetch" href="//fonts.googleapis.com" />
<link href="https://fonts.googleapis.com/css?family=Amiri|El+Messiri&display=swap" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.0.2/papaparse.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.0.2/papaparse.min.js"></script>
<script src="parser.js"></script>
<script src="https://github.com/niklasvh/html2canvas/releases/download/0.5.0-alpha1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.min.js"></script>
<script src="hadithViz.js"></script>
<link rel="stylesheet" type="text/css" href="main.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" />
</head>
<body id="screen">
<nav id="sidebar" class="active">
<ul class="list-unstyled components mb-5">
<li class="active fab icon">
<a onclick="openNav()">
<span class="fa fa-bars"></span>
</a>
</li>
<li class="active">
<a onclick="openSearch()"><span class="fa fa-search"></span>Search بحث</a>
</li>
<li class="active">
<a onclick="openSettings()"><span class="fa fa-sliders-h"></span>Settings إعدادات</a>
</li>
<li class="active">
<a onclick="" href="https://github.com/OmarShafie/hadith"><span class="fa fa-info-circle"></span>About الدليل</a>
</li>
</ul>
</nav>
<div id="mySidenav" class="sidenav bg-dark text-center">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<ul style="align-items: center;" class="list-unstyled components mb-5">
<li class="active">
<a onclick="openSearch()"><span class="fa fa-search"></span>Search بحث</a>
</li>
<li class="active">
<a onclick="openSettings()"><span class="fa fa-sliders-h"></span>Settings إعدادات</a>
</li>
<li class="active">
<a onclick=""><span class="fa fa-info-circle"></span>About الدليل</a>
</li>
</ul>
</div>
<form id="mySidesearch" class="sidesearch bg-dark text-center">
<h3> Search Form <br> صفحة البحث <span class="fa fa-search"></span></h3>
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<div hidden class="justify-content-center" style="margin: 10px">
<label> - Sources المصادر - </label>
<select class="selectpicker" multiple data-live-search="true">
<option id="0" value="1" selected> Bukhari البخاري</option>
<option id="1" value="2" selected> Muslim مسلم</option>
<option id="2" value="3" selected> Malik مالك</option>
<option id="3" value="4" selected> Nasa'i النسائي</option>
<option id="4" value="5" selected> Abu Daw'ud أبو داود</option>
<option id="5" value="6" selected> Termithi الترمذي</option>
<option id="6" value="7" selected> Daremi الدارمي</option>
<option id="7" value="8" selected> Ibn Majah ابن ماجه</option>
<option id="8" value="9" selected> Ahmad أحمد</option>
</select>
</div>
<div class="justify-content-center" style="margin: 10px">
<label> - Task Example التمرين - </label>
<select id="task" class="selectpicker" onchange="load_task()">
<option disabled selected value> -- Select a task -- </option>
<option> 1. Hadith Analysis استعراض الحديث</option>
<option> 2. Matn Comparison فروق المتون</option>
<option> 3. Paths Comparison الرفع والوقف</option>
<option disabled> 4. Hadith Disorders العلل</option>
</select>
</div>
<div class="justify-content-center autocomplete" style="margin: 10px">
<label for="pattern-query"> - Task Discription تفاصيل التمرين - </label>
<p style="color: orange;" id="task_description"></p>
<input hidden type="search" class="form-control " id="pattern-query" dir="rtl" required placeholder="مثلا: @محمد بن مسلم"
autocomplete="on" />
</div>
<div class="justify-content-center" style="margin: 10px">
<label for="hadith-query"> - Task Questions أسئلة التمرين - </label>
<p style="color: orange;" id="task_questions"> </p>
<input hidden type="search" class="form-control " id="hadith-query" dir="rtl" value =" " required placeholder="مثلا: الأعمال بالنية"
autocomplete="on" />
<label hidden id="pattern-error" style="color:orange"></label>
</div>
<div class="justify-content-center mx-3 form-inline">
<div>
<button type="button" id="load_task_btn" class="btn btn-primary" disabled>
Load Task عرض التمرين
</button>
<script>
function load_task() {
$("#load_task_btn").prop("disabled", false);
var task_id = document.getElementById("task").selectedIndex;
load_task_data(task_id-1);
load_task_discription(task_id-1);
}
$(function () {
$("#load_task_btn").click(function () {
$("#submit").click();
});
});
function load_task_data(task_id) {
var dir = "https://raw.githubusercontent.com/OmarShafie/hadith/master/data/";
input_file = dir + "demo/task0"+task_id+".csv";
if (input_file){
new_upload = true;
inputType = "demoTask";
document.getElementById("submit").click();
closeNav();
openSearch();
}
}
function load_task_discription(task_id) {
var tasks = [{"task_description": "In this task, you will examine the following (إنما الأعمال بالنية) hadith by visualizing the isnad tree.",
"task_questions": "Who is the 'Common Link' In this Hadith?\n Where is the book sources that this hadith can be found?"},
{"task_description": "In this task, you will examine the differences between the Matns of hadith (إن في المال حقا).",
"task_questions": "Can you identify what is the key differences between different instances? Which is more likely to be accepted?"},
{"task_description": "In this task, you will examine the differences between the Isnads of a hadith.",
"task_questions": "Who is the 'Common Link' In this Hadith?\n Was this Hadith attributed to the Prophet (p.b.u.h.)"},
]
document.getElementById("task_description").innerHTML = tasks[task_id]["task_description"];
document.getElementById("task_questions").innerHTML = tasks[task_id]["task_questions"];
return;
}
</script>
<button hidden type="button" id="submit" class="btn btn-primary">
Load عرض
</button>
</div>
</div>
<div class="justify-content-center">
<label id="btnMessage"></label>
<label id="data-error" style="color:orange"></label>
</div>
<div id="resultTable"></div>
<div class="justify-content-center mx-3 form-inline">
<div>
<button type="button" disabled id="draw" class="btn btn-primary">
Draw رسم
</button>
</div>
</div>
</form>
<form id="mySidesettings" class="sidesearch bg-dark text-center">
<h3>Settings Form <br> صفحة الإعدادات<span class="fa fa-sliders-h"></span></h3>
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<div class="justify-content-center" style="margin: 10px">
<label> - Links Coloring تغيير العرض - </label>
<select id="sankey_view" class="selectpicker" data-width="fit">
<option selected> Group by Matn <br> تمييز المتون بالألوان </option>
<option> Group by Sanad <br> تمييز الأسانيد بالألوان</option>
<option> Multiple Matn Alignment <br> مقارنة المتون بالألوان </option>
</select>
</div>
<br>
<div hidden class="row px-2 justify-content-between">
Friendly colors (20 colors) <br> ألوان سهلة:
<label class="switch">
<input id="distinguishableColorsSwitch" type="checkbox" checked/>
<span class="switchSlider round"></span>
</label>
</div>
<br>
<div hidden class="row px-2 justify-content-between">
Clear Route <br> إعادة الترتيب:
<label class="switch">
<input id="clearRouteSwitch" type="checkbox" />
<span class="switchSlider round"></span>
</label>
</div>
<br>
<div hidden class="row px-2 justify-content-between">
Day Light Theme <br> خلفية بيضاء:
<label class="switch">
<input id="DayThemeSwitch" type="checkbox" checked />
<span class="switchSlider round"></span>
</label>
</div>
<br>
<div hidden class="row px-2 justify-content-between">
Log Scale <br> مقياس لوغاريتمي:
<label class="switch">
<input id="logScaleSwitch" type="checkbox" />
<span class="switchSlider round"></span>
</label>
</div>
<br>
<div hidden >
<button type="button" id="rotate" class="btn btn-primary">
Rotate قلب <i class="fa fa-sync-alt"></i>
</button>
</div>
<br>
<div hidden class="row justify-content-center form-inline">
<div class="col form-inline slidecontainer">
<p>
Nodes Spread تباعد الطرق<span id="demo"></span>
<input type="range" min="1" max="5" value="3" class="slider" id="myRange" />
</p>
</div>
</div>
<button type="button" id="saveTopPdf" class="btn btn-primary">
Save Chart <br> حفظ التشجير <i class="fa fa-image"></i>
</button>
</form>
<div class="container-fluid">
<div id="header">
<br />
<br />
<h1 class="text-center">The Hadith Visual Search Engine</h1>
<h2 class="text-center small">
- محرك بحثي بصري لتتبع الأحاديث النبوية - <br>
Visual analysis of Hadith Isnad tree
</h2>
<h2 class="text-center" id="debugger"></h2>
</div>
<div class="row justify-content-center my-legend">
<div class="legend-title">
<!--Narrator Grade Legend:-->
</div>
<div class="legend-scale">
<ul class="legend-labels">
<li style="width: 65%;">Narrator Grades الجرح والتعديل</li>
<li style="width: 5%"></li>
</ul>
<ul class="legend-labels">
<li><span style="background:#002700;"></span>صحابي</li>
<li><span style="background:#005800;"></span>ثقة ثقة</li>
<li><span style="background:#008a00;"></span>ثقة</li>
<li><span style="background:#7cb840;"></span>صدوق</li>
<li><span style="background:#dde086;"></span>مقبول</li>
<!--li><span style="background:#d8c100;"></span>تغير \ اختلط</li-->
<!--li><span style="background:#f0a30a;"></span>مدلس</li-->
<li><span style="background:#fbb268;"></span>لين</li>
<li><span style="background:#ed6a57;"></span>ضعيف</li>
<li><span style="background:#de425b;"></span>منكر \ متروك</li>
<li><span style="background:#a20025;"></span>كذاب</li>
<li><span style="background:silver;"></span>مجهول \ مستور</li>
</ul>
</div>
<span class="tooltiptext" id="gradeTooltip">Tooltip text</span>
</div>
<div id="sankey_container" class="row justify-content-center">
<div id="sankey_basic" class="horizontal-sankey"></div>
</div>
<br />
</div>
<script>
var isVertical = false; //vertical
var node_is_selected = false;
function openSearch() {
document.getElementById("mySidesearch").style.width = "320px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("mySidesearch").style.width = "0";
document.getElementById("mySidesettings").style.width = "0";
}
function openNav() {
document.getElementById("mySidenav").style.width = "320px";
}
function openSettings() {
document.getElementById("mySidesettings").style.width = "330px";
}
var sankey_h = 0;
var sankey_w = 0;
var inputFeild = document.getElementById("mySidesearch");
/*
inputFeild.addEventListener("keyup", function (event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("submit").click();
}
});
*/
google.charts.load("current", {
packages: ["sankey"]
});
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value;
slider.oninput = function () {
output.innerHTML = this.value;
};
var selection_array = [];
var clickDisabled = true;
function drawChart(data) {
// Sets chart options.
//var screen_h = Math.min(screen.width,screen.height - 170);
var node_height = 25;
var nodeWidth = 12;
var layers_density = layers_count.map(set => set.length);
var dense_layer_count = layers_density[layers_density.indexOf(Math.max(...layers_density))];
var padding = parseInt(slider.value) * Math.min(node_height/2,
Math.sqrt(dense_layer_count)*node_height);
var expected_lable_length = isVertical? 50:150;
var verticalDistance = isVertical? expected_lable_length*4 : padding; // between nodes
var horizontalDistance = isVertical? padding : (expected_lable_length); // between nodes
sankey_h = dense_layer_count * node_height + (dense_layer_count-1)* verticalDistance;
sankey_w = isVertical? Math.max(longest_sanad * verticalDistance,
Math.min(screen.width, screen.height) - 80 /*menue*/ - 2*nodeWidth) :
Math.max(longest_sanad * horizontalDistance,
Math.max(screen.width, screen.height) - 80 /*menu*/ - 2*nodeWidth)
document
.querySelector("#screen")
.style.setProperty(
"width",
Math.max(//if the tree was small
80 + (isVertical ? sankey_h : sankey_w),
Math.max(screen.width, screen.height)
) - nodeWidth + "px"
);
document
.querySelector("#sankey_basic")
.style.setProperty("margin-bottom", (isVertical ? 0 : -100) + "px");
document
.querySelector("#sankey_basic")
.style.setProperty("height", sankey_h + "px");
document
.querySelector("#sankey_container")
.style.setProperty(
"height",
(isVertical ? sankey_w : sankey_h) + "px"
);
options = {
width: sankey_w,
height: sankey_h,
tooltip: {
isHtml: true
},
sankey: {
allowHtml: true,
tooltip: {
isHtml: true
},
iterations: clearRoute()?0:1000,
link: {
color: {
fill: "lightslategray",
stroke: 'black', strokeWidth: 0.5,
//fillOpacity: 0.5
}
},
node: {
interactivity: true,
nodePadding: padding,
labelPadding: 5,
width: nodeWidth,
label: {
fontName: "Amiri",
bold: true,
italic: true
}
}
}
};
var chartDiv = document.getElementById("sankey_basic");
chart = new google.visualization.Sankey(chartDiv);
var colorNodes = {};
var textIndex = 0;
var rectIndex = 0;
var observer = new MutationObserver(function (mutations) {
var pathIndex = 0;
mutations.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
if (node.tagName === "text") {
node_color = gradeToColor(
getNarratorGrade(getNarratorFromName(node.innerHTML))
);
colorNodes[textIndex] = node_color;
textIndex++;
if (node.getAttribute("text-anchor") !== "start") {
node.setAttribute("text-anchor", "start");
node.setAttribute("x", parseInt(node.getAttribute("x")) + 20);
}
/*SVGRect = node.getBBox();
var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
rect.setAttribute("x", SVGRect.x);
rect.setAttribute("y", SVGRect.y);
rect.setAttribute("width", SVGRect.width);
rect.setAttribute("height", SVGRect.height);
rect.setAttribute("rx", 15);
rect.setAttribute("fill", node_color);
rect.setAttribute("class", "node_lable_box");
node.parentElement.insertBefore(rect, node);
*/
}
if (node.tagName === "rect" && node.getAttribute("class") !== "node_lable_box") {
node.setAttribute("fill", colorNodes[rectIndex]);
rectIndex++;
}
if (node.tagName === "path") {
node.setAttribute("fill", colorLinks[pathIndex]);
if (node.getAttribute("fill-opacity") !== "0.8" && !node_is_selected) {
node.setAttribute("fill-opacity", g_opacity());
}
pathIndex++;
}
});
});
});
observer.observe(chartDiv, {
childList: true,
subtree: true
});
google.visualization.events.addListener(chart, "select", function () {
var sel = chart.getSelection();
if (sel.length) {
console.log(sel);
node_is_selected = true;
//window.open('http://www.bing.com');
} else {
node_is_selected = false;
}
});
google.visualization.events.addListener(chart, "onmouseover", function (e) {
if (e.name) {
var gradeTooltip = document.querySelector("#gradeTooltip");
gradeTooltip.style.setProperty("visibility", "visible");
const narrator = getNarratorFromName(e.name);;
gradeTooltip.innerHTML =
lookupNarrator(narrator)["name"] +
" : <span style = 'color :" +
gradeToColor(getNarratorGrade(narrator)) +
";'>" +
getNarratorGrade(narrator) +
"</span>" +
" ( " +
getNarratorPlaces(narrator) +
" , " +
getNarratorBirth_text(narrator) +
"~" +
getNarratorDeath_text(narrator) +
" )";
}
if (!e.name) {
clickDisabled = false;
}
});
google.visualization.events.addListener(chart, "onmouseout", function (
e
) {
if (e.name && !node_is_selected) {
var gradeTooltip = document.querySelector("#gradeTooltip");
gradeTooltip.style.setProperty("visibility", "hidden");
}
if (!e.name) {
clickDisabled = true;
}
});
chart.draw(data, options);
closeNav();
document.querySelectorAll("svg")[0].setAttribute("width", parseInt(sankey_w + expected_lable_length + 2*nodeWidth) + "px");
}
var xOffset;
var yOffset;
const el = document.querySelector("#screen"); //tooltip
el.style.setProperty("--v", "none");
el.addEventListener(
"click",
e => {
xOffset =
(isVertical ?
(parseInt(
document
.querySelector("#screen")
.style.getPropertyValue("width")
.split("px")[0]
) +
sankey_h) /
2 -
100 :
100) +
600 / 2;
yOffset =
(isVertical ?
sankey_w - 300 / 2 :
sankey_h +
300 / 2 +
document.querySelector("#header").offsetHeight +
30) + 50;
if (
el.style.getPropertyValue("--v") != "block" &&
!clickDisabled &&
document.getElementById("mySidesearch").style.width ==
document.getElementById("mySidesettings").style.width
) {
el.style.setProperty(
"--x",
(isVertical ?
Math.min(
sankey_w -
(300 + document.querySelector("#header").offsetHeight),
Math.max(-150, -e.pageY + yOffset)
) :
Math.min(sankey_w - 600, Math.max(0, e.pageX - xOffset))) +
"px"
);
el.style.setProperty(
"--y",
(isVertical ?
Math.max(
-sankey_h + 150,
Math.min(-400 - 50, e.pageX - xOffset)
) :
Math.max(-sankey_h, Math.min(-300 + 50, e.pageY - yOffset))) +
"px"
);
el.style.setProperty("--v", "block");
}
},
true
);
el.addEventListener("mousemove", e => {
var xPos = -80 +
Math.max(
e.pageX - parseInt(el.style.getPropertyValue("--x").split("px")[0]),
parseInt(el.style.getPropertyValue("--x").split("px")[0]) - e.pageX
);
var yPos =
150 +
e.pageY -
yOffset -
parseInt(el.style.getPropertyValue("--y").split("px")[0]);
if (el.style.getPropertyValue("--v") == "block") {
if (xPos > 590 || xPos < 10 || yPos > 290 || yPos < 10) {
el.style.setProperty("--v", "none");
clickDisabled = true;
}
}
});
</script>
</body>
<footer style="height: 20px; text-align: center;" class="justify-content-center" >
<i class="fa fa-copyright"></i> 2019 <a href="https://www.linkedin.com/in/omarshafie/">Omar Shafie</a> in Doha, Qatar- All Rights
Reserved -
</footer>
<div id="card" dir="rtl" style="visibility: hidden;">
<div id="rsz">
<div class="row pt-2 align-items-center">
<label class="switch mx-2">
<input id="dotificationSwitch" type="checkbox">
<span class="switchSlider round"></span>
</label>
تنقيط المتفق Dotification :
</div>
<div id="card_content">
</div>
</div>
</div>
</html>