-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
260 lines (226 loc) · 7.48 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=1000">
<title>Sp-filling curves, compare 1</title>
<script src="https://d3js.org/d3.v5.min.js"></script><!-- offline ./src/d3.v5.min.js -->
<script src="./src/GSfc4q.js"></script>
<script src="./src/curves-grid.js"></script>
<style>
body {
text-align: center;
}
table {
padding:10px;
border-bottom: 1px solid #ddd;
border-top: 1px solid #ddd;
}
#chartsContainer svg.theChart path.curve {
stroke:#666; /* light gray */
fill:none;
stroke-width:4; /* 0.25 to 5 */
stroke-linecap: square;
opacity:0.6; /* 0 to 0.5 */
}
#chartsContainer svg.theChart path.curve_dash {
animation: _dash_ 3s linear 1s infinite running;
stroke-dasharray: 5;
stroke-dashoffset: 2;
}
@keyframes _dash_ { /* complement of path.curve_dash */
from { stroke-dashoffset: 22; }
to { stroke-dashoffset: 5; }
}
#chartsContainer svg.theChart {
margin: 10px;
}
#chartsContainer svg.theChart rect.catchall {
cursor:pointer;
pointer-events: all;
}
#chartsContainer svg.theChart rect {
opacity:0.8; /* 0.5 to 1*/
}
#chartsContainer svg text.gridCaption {
font-size: 11pt;
fill: #000;
style: label;
font-family: monospace;
}
#chartsContainer div.theChartTooltip {
display: none;
position: absolute;
margin-top: 22px;
margin-left: -1px;
padding: 5px;
border-radius: 3px;
font: 16px sans-serif;
color: #eee;
background: rgba(0,0,140,0.9);
text-align: center;
pointer-events: none;
z-index: 999;
}
#chartsContainer div.theChartTooltip code,
#chartsContainer span.numCells {
font-weight: bold;
}
#chartsContainer div.theChartTooltip code:first-child {
font-size: 150%;
}
</style>
<script>
'use strict';
var globOrder_exact = 2; // change selected option. BUG: ignoring 0.5, 1.5, etc.
var crvID0_showDecimal = false;
var distinctColors = {}
const conf_canvasWidth_min = 320;
GSfc4q.conf_alertLevel = 1;
var xzoomNode;
//var xbaseNode;
var mrtGrid,hlbGrid;
var globOrder = Math.ceil(globOrder_exact);
var globOrder_isHalf = (globOrder != globOrder_exact);
function changeLblBase(base) {
// check is valid /std|dec|32/
let level = mrtGrid.sfc4.level
let isGhs = false;
if (base=='ghs') {isGhs = true; base='32'}
if (base=='32' && (level%2.5)) {
alert("Base32 can be used\nonly on levels 2.5, 5, 10, etc.")
return false;
}
mrtGrid.layout.labelGeo=isGhs
hlbGrid.layout.labelGeo=isGhs
mrtGrid.lblBase=base
hlbGrid.lblBase=base
changeLayout(level) // refresh all
return true;
}
function redoOrderOptions(mode='all',max=15) {
let modeAll = (mode=='all');
let modeInt = (mode=='int');
let opts = [
...Array( modeAll? max: Math.ceil(max/2) ).keys()
].map(x => modeAll?
(0.5 + x/2):
( modeInt? parseInt(1+x): (0.5+x) )
);
document.getElementById('toggle-level').innerHTML = opts
.map(x => `<option${(x==globOrder_exact)? ' selected':''}>${x}</option>`)
.join()
;
}
function setFormOption(domId,val) {
var sel = document.getElementById(domId),
opts = sel.options;
for (var i = 0; i < opts.length; i++) if (opts[i].label == val)
sel.selectedIndex = i;
}
//////
function toggleLevel(v) {
if (!v) v = mrtGrid.sfc4.level;
globOrder_exact = v
globOrder = Math.ceil(v)
globOrder_isHalf = (globOrder!=v)
changeLayout()
}
function changeLayout() {
hlbGrid.refreshProperties(globOrder_exact)
mrtGrid.refreshProperties(globOrder_exact)
d3.select('#morton-chart span.numCells').text(mrtGrid.sfc4.nKeys)
d3.select('#hilbert-chart span.numCells').text(hlbGrid.sfc4.nKeys)
hlbGrid.build(false)
mrtGrid.build(false)
if (mrtGrid.layout.circles) mrtGrid.buildCaption() // only one draw
}
/////
function ONLOAD() {
// Inits, interface:
xzoomNode = document.getElementById('xzoom');
redoOrderOptions('all');
document.getElementById("form1").reset();// reset selected options of page history.
setFormOption('toggle-level',globOrder_exact);
const toggles = ['rects','labelMain','labelIJ','circles','drawCurve','level'];
// Build grids:
let hlb = new GSfc4qLbl_Hilbert(globOrder,'4h') // int level
hlbGrid = new GridOfCurve_D3('hilbert-chart', hlb);
let mrt = new GSfc4qLbl_Morton(globOrder,'4h') // int level
mrtGrid = new GridOfCurve_D3('morton-chart', mrt);
if (mrtGrid.layout.circles) mrtGrid.buildCaption(); // only one draw
const togglesD3 = d3.selectAll( toggles.map(t=>'#toggle-'+t).join(',') );
togglesD3.on("change", ()=> { // toggle updating layout
for (const t of toggles) {
let active = document.getElementById('toggle-'+t).checked;
mrtGrid.layout[t]=active;
hlbGrid.layout[t]=active;
}
//bug togglesD3.call( obj=> { let active = obj.property('checked'); let name = obj.property('i').slice(6); })
mrtGrid.refresh_D3_state() // testando onde usar
hlbGrid.refresh_D3_state()
changeLayout() // refresh all
});
} // \ONLOAD
////////////
</script>
</head>
<body onload="ONLOAD()">
<form id="form1">
Hierarchical <b>level</b> <i>L</i> of <span style="color:red">grid</span> refinement = <a href="https://en.wikipedia.org/wiki/Space-filling_curve">Space-filling <span style="color:blue">curve</span></a> level:
<select id="toggle-level" onchange="toggleLevel(this.value)"></select>
<select id="xopts" onchange="redoOrderOptions(this.value)">
<option value="all">all L</option>
<option value="int">L int</option>
<option value="half">half L</option>
</select>
Hierarchical <a href="http://osm.codes/_foundations/art1.pdf" target="_blank">cell codes</a>:
<select
onchange="if (!changeLblBase(this.value)) this.selectedIndex=this.oldIndex" onFocus="this.oldIndex=this.selectedIndex"
>
<option value="std">Standard</option>
<option value="4">base 4h</option>
<option value="dec">Decimal</option>
<option value="16">base 16h</option>
<option value="ghs">base 32ghs</option>
<option value="32">base 32nvu</option>
</select>
<br/> <br/>
<table id="chartsContainer" border="0" width="90%" align="center">
<tr>
<td id="morton-chart" width="50%"><a href="https://en.wikipedia.org/wiki/Z-order_curve">MORTON CURVE</a>
in a grid of <span class="numCells"></span> cells<br/>
<svg class="theChart"></svg>
<div class="theChartTooltip"></div>
</td>
<td id="rainbow" width="45"><svg></svg></td>
<td id="hilbert-chart" width="50%"><a href="https://en.wikipedia.org/wiki/Hilbert_curve">HILBERT CURVE</a>
in a grid of <span class="numCells"></span> cells<br/>
<svg class="theChart"></svg>
<div class="theChartTooltip"></div>
</td>
</tr>
</table>
<br/>
Turn on/off: <label><input type="checkbox" checked="1" id="toggle-labelMain" value="1" /> Labels</label>
<label><input type="checkbox" checked="1" id="toggle-circles" value="1" /> Circles</label>
<label><input type="checkbox" checked="1" id="toggle-drawCurve" value="1" /> Curve</label>
<label><input type="checkbox" checked="1" id="toggle-labelIJ" value="1" /> Coordinates (<i>i,j</i>)</label>
<label><input type="checkbox" checked="1" id="toggle-rects" value="1" /> Grid</label>
<br/>
Zoom/pan:
<select id="xzoom">
<option value="1" selected>Enable
<option value="0">Disable<!--
<option value="-1">RESET and Enable
<option value="-2">RESET and Disable -->
</select>
<a href="https://github.com/ppKrauss/Sfc4q">Sources</a>
</form>
</body>
</html>