-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpe.html
394 lines (356 loc) · 12.8 KB
/
pe.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PE Sign Frequencies</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Interactive display of sign frequencies from the proto-Elamite script.">
<meta name="author" content="Logan Born">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<!--<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="chart.js/Chart.css">
<script src="chart.js/Chart.bundle.js"></script>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="../../assets/js/html5shiv.js"></script>
<script src="../../assets/js/respond.min.js"></script>
<![endif]-->
<style>
.group{
margin-bottom:50px;
}
.group::after {
content:"";
display:table;
clear:both;
}
.sidebar {
width: 180px;
float: left;
text-align: right;
margin-left:25px;
}
.sidebar > div {
display: table-cell;
text-align:center;
float:right;
max-width:100%;
padding-bottom: 15px;
}
input {
max-width:100%;
}
.display {
width: calc(100% - 250px);
float: right;
}
#loading_shadow {
position: absolute;
top: 0; left: 0;
width: 100vh; height:100vh;
background: rgba(20,20,20,0.8);
}
#loading_overlay {
background: #333;
width: 150px;
margin: 50px auto;
text-align: center;
border-radius: 15px;
}
#loading_overlay > p {
color: #ddd;
padding: 15px;
font-weight: bold;
}
#spin {
margin: auto;
width:1px;
padding: 40px 0 0 0;
}
canvas {
min-height: 200px;
}
</style>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top navbar-sm">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand visible-xs visible-sm" href="https://mrlogarithm.github.io/about-me/software.html">
<svg class="bi bi-chevron-left" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" style="margin-bottom:-2pt;">
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z" clip-rule="evenodd"/>
</svg>Back to Tools
</a>
<a class="navbar-brand visible-md visible-lg" href="https://mrlogarithm.github.io/about-me/software.html">
<svg class="bi bi-chevron-left" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" style="margin-bottom:-2pt;">
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z" clip-rule="evenodd"/>
</svg>Back to Tools
</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
</ul>
</div><!-- navbar-collapse -->
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12 contentarea">
<div class="container"> <!-- container -->
<div class="row"> <!-- mainpage_row -->
<div class="col-md-12"> <!-- content -->
<br>
<header class="pageheader">
<h1>Proto-Elamite <em>n</em>-grams</h1>
</header>
<!--<div id="loading_shadow">
<div id="loading_overlay">
<p>Loading...</p>
</div>
</div>-->
<div class="group">
<div class="sidebar">
<h3>Chart Options</h3>
<label for="pe_n">Length: <span id="pe_n_txt">1</span></label>
<input type="range" min="1" max="13" value="1" id="pe_n" class="pe"/>
<br/>
<br/>
<label for="pe_excor">Exclude corrections?</label>
<input type="checkbox" id="pe_excor" class="pe"/>
<br/>
<br/>
<label for="pe_collapse">Collapse variants?</label>
<input type="checkbox" id="pe_collapse" class="pe"/>
<br/>
<br/>
<label for="pe_search">Search string:</label>
<input type="text" id="pe_search" class="pe"/>
<br/>
<br/>
<label for="pe_range">Plot size: <span id="pe_range_txt" style="display:none;">15</span></label>
<input type="number" min=5 max=1000 value=15 id="pe_range" class="pe"/>
<br/>
<br/>
<button onclick="save_pe()">
Download this view of the data
</button>
</div>
<div class="display">
<canvas id="canvas_pe" class="chart"></canvas>
</div>
</div> <!-- END CHART -->
<div class="group" style="margin-top:15px;">
<div>
<p>This interface presents the <i>n</i>-gram counts hosted at <a href="https://github.com/sfu-natlang/pe-pc-datasets">pe-pc-datasets</a>. These are pre-computed and stored as JSON files which you may access directly <a href="https://raw.githubusercontent.com/sfu-natlang/pe-pc-datasets/master/ngrams/pe_ngrams.json">here</a>.
</p>
<p>
Explanation of parameters:
<ul>
<li>
Length: The length of <em>n</em>-gram to display. Length = 1 will show the frequency of individual signs; Length = 2 will show strings of two signs; etc.
</li>
<li>
Exclude corrections? If checked, corrected signs (annotated with <, >, and ! in the original transcriptions) will not be counted.
</li>
<li>
Collapse variants? If checked, sign variants will be counted as instances of their corresponding basic sign, e.g., M066~A will be counted as an instance of M066.
</li>
<li>
Search string: if a search term is entered, the plot will only display <em>n</em>-grams which contain the search string.
</li>
<li>
Plot size: how many rows to display. <em>n</em>-grams are displayed in order of decreasing frequency. <em>Chart.js breaks when the plot gets too large, so plot size is capped at 1000.</em>
</li>
</ul>
</p>
</div>
</div>
</div><!--end of content -->
</div><!--end of mainpage_row -->
</div><!--end of container -->
</div>
</div>
</div>
<div id="footer">
<div class="container footer" align="center">
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script>
var pe_data;
var labels_pe; // subset of data currently on display
var counts_pe; //
var ctx_pe = document.getElementById('canvas_pe');
var chart_pe = new Chart(ctx_pe);
$().ready( function(){
// Get ngram data as JSON:
$.get({
url: "https://raw.githubusercontent.com/sfu-natlang/pe-pc-datasets/master/ngrams/pe_ngrams.json",
dataType:'json',
success:function(result) {
pe_data = result;
draw_ngrams("pe");
}
});
$('.pe').change( function(){draw_ngrams("pe");} );
//$('#loading_shadow').hide();
});
function draw_ngrams( lang ) {
var opts = {
legend: {
display: false,
},
scales: {
xAxes: [{
ticks: {
beginAtZero: true
}
}],
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
layout: {
padding: {
top: 50,
right: 50,
left: 50,
}
},
responsive: true,
maintainAspectRatio: true,
events: [],
animation: {
duration: .001,
onComplete: function () {
var chartInstance = this.chart,
ctx = chartInstance.ctx;
ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize, Chart.defaults.global.defaultFontStyle, Chart.defaults.global.defaultFontFamily);
ctx.textAlign = 'center';
ctx.textBaseline = 'bottom';
this.data.datasets.forEach(function (dataset, i) {
var meta = chartInstance.controller.getDatasetMeta(i);
meta.data.forEach(function (bar, index) {
var data = dataset.data[index];
ctx.fillText(data, bar._model.x + 15, bar._model.y + 8);
});
});
}
}
};
if ( lang == "pe" ) {
var opt_corr = ["corrections included", "corrections omitted"];
if ( document.getElementById( lang + "_excor").checked ) {
opt_corr = opt_corr[1];
} else {
opt_corr = opt_corr[0];
}
var opt_merge = ["variants separate", "variants merged"];
if ( document.getElementById( lang + "_collapse").checked ) {
opt_merge = opt_merge[1];
} else {
opt_merge = opt_merge[0];
}
// Select correct data view:
var data = pe_data[opt_corr][opt_merge];
}
var n = parseInt(document.getElementById( lang + "_n").value);
document.getElementById( lang + "_n_txt").innerHTML = n;
var search_str = document.getElementById( lang + "_search").value;
function search( sign, str, lang ) {
if (lang == "pe") {
return sign.trim().toLowerCase().includes(str.trim().toLowerCase());
}
}
var dlist = [];
for ( var sign in data ) {
if ( sign.trim().match("^[ X]*$") || sign.includes("...") || (sign.split(" ").length - 1) != n-1 ) {
continue;
} else if ( search_str.trim() == "" || search(sign,search_str,lang) ) {
dlist.push( [data[sign], sign] );
}
}
dlist.sort(function(a,b){
if ( a[0] > b[0] ) {
return 1
} else if (a[0] == b[0] ) {
return 0;
} else {
return -1;
}
});
var labels = [];
var counts = [];
var labels = [];
var plt_size = parseInt(document.getElementById( lang + "_range").value);
if ( plt_size > dlist.length ) {
plt_size = dlist.length;
}
document.getElementById( lang + "_range_txt").innerHTML = plt_size;
for ( var i = 0; i < plt_size; i++ ) {
labels.push( dlist[dlist.length - 1 - i][1] );
counts.push( dlist[dlist.length - 1 - i][0] );
}
size_per_line = 25;
if ( lang == "pe" ) {
var dset = {
labels: labels,
datasets: [{
data: counts,
}]
}
chart_pe.destroy();
//console.log("destroy pe");
chart_pe = new Chart(ctx_pe, {
type: 'horizontalBar',
data: dset,
options: opts,
});
ctx_pe.style.height = plt_size * size_per_line;
counts_pe = counts;
labels_pe = labels;
}
// Fix unresponsive input elements:
window.scrollBy(0,-1);
window.scrollBy(0,1);
}
function save_pe() {
var file_content = "ngram,count\n";
for ( var i = 0; i < counts_pe.length; i++ ) {
file_content += labels_pe[i] + "," + counts_pe[i] + "\n";
}
download(file_content,"pe_ngrams_subset.csv","text/text");
}
function download(data, filename, type) {
var file = new Blob([data], {type: type});
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
else { // Others
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
</script>
</body>
</html>