forked from SteveHodge/ed-systems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystems.html
144 lines (131 loc) · 4.5 KB
/
systems.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Elite Dangerous Systems</title>
<link href="external/jquery-ui.css" rel="stylesheet">
<link href="trilateration.css" rel="stylesheet">
<script src="external/jquery-2.1.1.js"></script>
<script src="external/stupidtable.min.js"></script>
<script src="trilateration.js"></script>
<script>
var systems = null;
var selected = null;
var sysMap = {};
$(document).ready(function () {
$.getJSON('systems.json', function(data) {
systems = data;
var d, i;
for (i = 0; i < systems.length; i++) {
sysMap[systems[i].name] = systems[i];
var contrib = systems[i].region;
if (!systems[i].calculated) contrib += ' (ref)';
$('<tr>')
.attr('system', i)
.click(function() {selectSystem(this)})
.append($('<td>').text(systems[i].name))
.append($('<td>').text(contrib))
.append($('<td>').text(systems[i].x))
.append($('<td>').text(systems[i].y))
.append($('<td>').text(systems[i].z))
.append($('<td>'))
.append($('<td>'))
.appendTo('#tableDiv tbody');
}
// check distance data involves known systems
for (i = 0; i < systems.length; i++) {
if (!('distances' in systems[i])) continue;
for (var j = 0; j < systems[i].distances.length; j++) {
if (!(systems[i].distances[j].system in sysMap)) {
console.log(systems[i].distances[j].system + ' system not found for distance from ' + systems[i].name);
}
}
}
$('#tableDiv table').stupidtable({"optfloat": sortOptionalFloat}).bind('aftertablesort', updateSortArrow);
$('#generate-csv').click(function() {generateCSV(false)});
$('#sort-csv').click(function() {generateCSV(true)});
$('#remove-csv').click(function() {$('#csv-wrapper').hide();});
$('#csv-select').click(function() {
if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents($('#csv-output')[0]);
selection.removeAllRanges();
selection.addRange(range);
}
});
$('#known-systems').text('Known Systems ('+systems.length+')');
selectSystem($('#tableDiv tr[system]')[0]);
});
});
function selectSystem(row) {
if (selected === row) return;
if (selected) {
$(selected).removeClass('selected');
}
selected = row;
$(selected).addClass('selected');
// recalculate distances
if (!selected.hasAttribute('system')) return;
var s0 = systems[selected.getAttribute('system')];
var dists = {};
if ('distances' in s0) $.each(s0.distances, function() {
dists[this.system] = this.distance;
});
$('#tableDiv tr').each(function(i, r) {
if (!r.hasAttribute('system')) {
$(r).children('th:nth-last-child(2)').text('Distance to '+s0.name);
return;
}
var s = systems[r.getAttribute('system')];
$(r).children('td:nth-last-child(2)').last().text(eddist(s0, s).toFixed(2));
$(r).children('td:nth-last-child(1)').last().text(dists[s.name]);
});
}
function generateCSV(sort) {
var csv = [];
$('#tableDiv tr[system]').each(function() {
var s = systems[this.getAttribute('system')];
var added = s.region;
if (s.calculated) added += '-Inferred';
if (s.region === 'Beyond The Pill') added = 'Not Present';
var contrib = '';
if (s.contributed) {
contrib = s.contributed.substr(0,10)+' '+s.contributed.substr(11,8);
}
csv.push("'"+s.name.replace(/'/g,"''")+"',"+s.x+","+s.y+","+s.z+",'"+added+"','"+contrib+"'");
});
if (sort) csv.sort(function(a,b) {return a.localeCompare(b, 'en', {'sensitivity': 'base'});});
$('#csv-output').text('name,pos_x,pos_y,pos_z,[email protected]_id,modified\n' + csv.join('\n'));
$('#csv-wrapper').show();
}
</script>
</head>
<body class="ui-widget">
<h2 id="known-systems">Known Systems</h2>
<button id="generate-csv">Generate CSV</button>
<div id="csv-wrapper" style="display:none">
<button id="remove-csv">Remove CSV</button>
<button id="csv-select">Select All</button>
<button id="sort-csv">Sort Alphabetically</button>
<pre id="csv-output" style="height:50vh; overflow:auto"></pre>
</div>
<div class="table-div" id="tableDiv">
<table>
<thead>
<tr>
<th data-sort="string-ins">System</th>
<th data-sort="string">Region</th>
<th data-sort="float">X</th>
<th data-sort="float">Y</th>
<th data-sort="float">Z</th>
<th data-sort="float">Distance</th>
<th data-sort="optfloat">Crowdsourced Distance</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
</html>