-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
222 lines (186 loc) · 6.43 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Language" content="en" />
<meta name="viewport"
content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, width=device-width" />
<title>Geologic Time</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
a:hover {
color: steelblue;
}
.version-select-title {
display: flex;
align-items: center;
gap: 20px;
position: sticky;
top: 0;
background-color: white;
height: 40px;
}
.version-meta {
display: flex;
gap: 20px;
}
#version-desc {
width: 500px;
}
br {
display: block;
content: "";
margin-top: 1em;
}
#version-img {
height: 400px;
padding: 0 20px;
}
</style>
</head>
<body>
<h1>
geo-timeline
<a href="https://github.com/hongfaqiu/geo-timeline" title="Visit GitHub repository" rel="noopener">
<svg xmlns="http://www.w3.org/2000/svg" aria-label="GitHub" role="img" width="25" viewBox="0 0 512 512">
<rect width="512" height="512" rx="15%" fill="currentColor" />
<path fill="#fff"
d="M335 499c14 0 12 17 12 17H165s-2-17 12-17c13 0 16-6 16-12l-1-50c-71 16-86-28-86-28-12-30-28-37-28-37-24-16 1-16 1-16 26 2 40 26 40 26 22 39 59 28 74 22 2-17 9-28 16-35-57-6-116-28-116-126 0-28 10-51 26-69-3-6-11-32 3-67 0 0 21-7 70 26 42-12 86-12 128 0 49-33 70-26 70-26 14 35 6 61 3 67 16 18 26 41 26 69 0 98-60 120-117 126 10 8 18 24 18 48l-1 70c0 6 3 12 16 12z" />
</svg>
</a>
</h1>
<h2 class="version-select-title">
Select a version:
<select id="version-select">
<!-- Use JavaScript to create options -->
</select>
</h2>
<div class="version-meta">
<img id="version-img">
<p id="version-desc"></p>
</div>
<h1>GeoTimeLine</h1>
<h3>Time: <Input id="time" placeholder="0" /> Ma</h3>
<h3>Level: <Input id="level" placeholder="0" /> </h3>
<h2>Equal distance</h2>
<div id="geoTimeFullWidth"></div>
<h2>Unequal distance</h2>
<div id="unequal"></div>
<h2>Custom width & height (500px by 100px)</h2>
<div id="geoTimeSmall" style="width: 500px"></div>
<h1>GeoTimeScale</h1>
<h3>Stage: <Input id="stage" placeholder="Geologic Time" /> </h3>
<h2>Simplify geoTimeScale</h2>
<div id="geoTimeScale-simple"></div>
<h2>Complete geoTimeScale ( Equal distance )</h2>
<div id="geoTimeScale"></div>
<h1>GeoTimeSlider</h1>
<div id="geoTimeSlider"></div>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<script src="./dist/index.umd.js"></script>
<script type="module">
import TimeScaleVersions from './timescales.js';
function clearAll() {
["geoTimeFullWidth", "unequal", "geoTimeSmall", "geoTimeScale-simple", "geoTimeScale", "geoTimeSlider"].map(id => {
const item = document.getElementById(id)
if (item) item.innerHTML = ''
})
document.getElementById("version-desc").innerHTML = ''
}
function url2geotime(selectedVersion) {
const { data, image, desc, name } = selectedVersion;
clearAll()
const img = document.getElementById("version-img")
if (img) {
img.src = image;
img.alt = name
}
document.getElementById("version-desc").innerHTML = desc
fetch(data).then(async res => {
const intervals = await res.json()
const TimeInput = document.getElementById('time')
const LevelInput = document.getElementById('level')
const StageInput = document.getElementById('stage')
// geotimeLine
const geoTimeLine1 = new timeLine.GeoTimeLine("#geoTimeFullWidth", intervals, {
onChange: (time, level) => {
TimeInput.value = +(+time).toFixed(6)
LevelInput.value = +(+level).toFixed(6)
},
onAfterChange: (time, level) => {
console.log('time:', time, 'level:', level)
}
})
geoTimeLine1.level = 2
geoTimeLine1.time = 2000
const geoTimeLine2 = new timeLine.GeoTimeLine("#unequal", intervals, {
time: 0,
intervalSum: d => d.leaf ? d.start - d.end : 0,
maxZoom: 100
});
const geoTimeLine3 = new timeLine.GeoTimeLine("#geoTimeSmall", intervals, {
height: 100,
time: 2000
});
TimeInput.onchange = function changeTime() {
geoTimeLine1.time = this.value
geoTimeLine2.time = this.value
geoTimeLine3.time = this.value
}
LevelInput.onchange = function changeTime() {
geoTimeLine1.level = this.value
geoTimeLine2.level = this.value
geoTimeLine3.level = this.value
}
// geotimeScale
const geoTimeScale1 = new timeLine.GeoTimeScale("#geoTimeScale-simple", intervals, {
onChange: val => {
StageInput.value = val.data.name
console.log('node: ', val, 'sequence: ', geoTimeScale1.sequence )
},
simplify: true,
height: 70,
});
const geoTimeScale2 = new timeLine.GeoTimeScale("#geoTimeScale", intervals, {
intervalSum: d => d.leaf ? d.start - d.end : 0,
tickLength: 40,
unit: 'ma'
});
geoTimeScale2.stage = 'Cambrian'
StageInput.onchange = function changeTime() {
geoTimeScale1.stage = this.value
geoTimeScale2.stage = this.value
}
// geotimeSlider
const geoTimeSlider = new timeLine.GeoTimeSlider("#geoTimeSlider", intervals, {
onChange: (val) => {
console.log(val);
}
})
})
}
// Create options for the select element
const versionSelect = document.getElementById("version-select");
TimeScaleVersions.map(version => {
const option = document.createElement("option");
option.value = version.name;
option.text = version.name;
if (version.image) {
const image = document.createElement("img");
image.src = version.image;
image.alt = version.name + " image";
option.prepend(image);
}
versionSelect.appendChild(option);
});
url2geotime(TimeScaleVersions[0])
versionSelect.onchange = function() {
const selectedValue = this.value;
const selectedVersion = TimeScaleVersions.find(version => version.name === selectedValue);
url2geotime(selectedVersion)
};
</script>
</body>
</html>