-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_concept.html
More file actions
309 lines (243 loc) · 11.5 KB
/
example_concept.html
File metadata and controls
309 lines (243 loc) · 11.5 KB
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
<!DOCTYPE html>
<html>
<head>
<title>History of the Pointless Battle of Nothing </title>
<meta charset="utf-8" >
<meta name="author" content="Curtis J. Brown <mrbrown8@juno.com>" >
<meta name="description" content="" >
<meta name="keywords" content="" >
<meta name="generator" content="https://github.com/mrbrown8/html_vertical_timelines" >
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- https://stackoverflow.com/questions/9943771/adding-a-favicon-to-a-static-html-page -->
<link rel="icon" type="image/x-icon" href="data:image/svg+xml,<svg id=%22s%22 width=%2248%22 height=%2248%22 version=%221.1%22 viewBox=%220 0 12.7 12.7%22 xmlns=%22http://www.w3.org/2000/svg%22><g id=%22l%22 fill=%22%23f1e9d2%22><rect id=%22r%22 x=%220%22 y=%220%22 width=%2212.7%22 height=%2212.7%22 ry=%220%22 stroke-miterlimit=%222.4%22 stroke-width=%220%22 style=%22paint-order:markers fill stroke%22/><path id=%22p%22 d=%22m6.35-0.0v12.7%22 fill-rule=%22evenodd%22 stroke=%22%23000001%22 stroke-width=%221%22/><circle id=%22c%22 cx=%226.35%22 cy=%226.35%22 r=%222.56%22 stroke=%22%23000001%22/></g></svg>" />
<script>
// Date strings can be flexible. See https://www.w3schools.com/js/js_date_formats.asp for examples.
// timepoint_list array elements:
// [0] = user provided date
// [1] = user provided event description
// [2] = calculated JSDate object
// [3] = calculated relative distance from previous point
// [4] = calculated percentage of distance to total timerange
var timepoint_list = [// YYYY-MM-DD
["1921-10-01", "Event 1"],
["1921-12-09", "Event 2"],
["1922-04-01", "Event 3"],
["1922-04-28", "Event 4"]
//["", ""],
//["", ""]
];
const millisecondsInADay = 1000 * 60 * 60 * 24;
const num_of_timepoints = timepoint_list.length ;
const months_en = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const months_short_en = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const daysofweek_en = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const daysofweek_short_en = ["Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"];
const daysofweek_short_jp = ["日", "月", "火", "水", "木", "金", "土"]; // ~曜日
const year_jp = "年"; const month_jp = "月"; const day_jp = "日";
// Add JS Date objects to each row
for (let i = 0; i < num_of_timepoints; i++) {
let dateobject = new Date(timepoint_list[i][0]);
if ( isNaN(dateobject) ) {
throw new Error("Bad date format: " + timepoint_list[i][0] + ", entry number: " + i );
}
timepoint_list[i].push(dateobject);
}
// Calculate total time range
const startDate = timepoint_list[0][2];
const endDate = timepoint_list[num_of_timepoints - 1][2];
const timerange = ( endDate - startDate ) / millisecondsInADay;
console.log("timerange is (" + timerange + ") days" );
// calculate distances to next timepoint
for (let i = 0; i < num_of_timepoints - 1 ; i++) {
let distance = ( timepoint_list[i+1][2] - timepoint_list[i][2] ) / millisecondsInADay;
timepoint_list[i].push(distance) // add, to the timepoint, the relative distance to the next point
let percentage = distance / timerange; // a decimal ranging from 0.00 to 1.00
timepoint_list[i].push(percentage)
console.log("for " + i + " , distance is " + distance + ", percentage is " + percentage);
}
timepoint_list[num_of_timepoints - 1].push(0); // the last timepoint has no next point to distance to
console.log("for " + (num_of_timepoints - 1) + " , distance is " + (timepoint_list[num_of_timepoints - 1][3]));
// This JS code is in <head> & therfore cannot yet refer to HTML elements
// Make sure HTML is loaded first (or rewrite to put this JS in <body>)
// https://stackoverflow.com/questions/436411/where-should-i-put-script-tags-in-html-markup
// https://www.javascripttutorial.net/javascript-dom/javascript-domcontentloaded/
document.addEventListener('DOMContentLoaded', () => {
var ul_element = document.getElementById("timeline_ul");
for (let i = 0; i < num_of_timepoints; i++) {
let distance = "";
if (timepoint_list[i][3] == 0) {
distance = "";
} else {
//distance = 'style="margin-bottom:' + timepoint_list[i][3] + 'pt"';
//distance = 'style="height:' + timepoint_list[i][3] + 'pt"';
//distance = 'style="height:' + (timepoint_list[i][4])*100 + 'vh"';
distance = 'style="height:' + (timepoint_list[i][4])*100 + 'mm"';
//distance = 'style="height: calc(' + (timepoint_list[i][4])*100 + 'vh - 3 * var(--spacing)"';
}
//console.log("for " + i + " , distance is " + (distance) );
let showdate = months_short_en[timepoint_list[i][2].getMonth()] + " " +
timepoint_list[i][2].getDate() + ", " +
timepoint_list[i][2].getFullYear();
let tooltipdate = daysofweek_en[timepoint_list[i][2].getDay()] + ", " +
months_en[timepoint_list[i][2].getMonth()] + " " +
timepoint_list[i][2].getDate() + ", " +
timepoint_list[i][2].getFullYear();
let li_element = ` <li class="event" data-date="${showdate}" title="${tooltipdate}" ${distance}>\n`
+ ` <p>${timepoint_list[i][1]}</p>\n`
+ ` </li>`;
timeline_ul.innerHTML += li_element;
}
console.log(timepoint_list);
});
</script>
<style>
:root {
/* Variables */
/* --background: #252827; */
--background: #fcf5e5; // parchment-ish
--color-primary: #004ffc;
--color-light: white;
/* --color-dim: #6c6d6d; */
--color-dim: black;
--line: 4px;
--spacing: 50px;
--font-title: 'Helvetica', sans-serif;
--font-text: 'Times New Roman', serif;
}
/* Base */
body {
background: var(--background);
font-size: 16px;
}
p {
/* font-weight: 300; */
/* margin-block-start: 0em */
/* margin-block-end: 0em */
margin: 0;
}
a {
color: var(--color-dim);
text-decoration: none;
text-transform: uppercase;
display: block;
letter-spacing: .3em;
font-size: .6em;
font-weight: 400;
background: #252727;
padding: .3rem 1rem;
margin: 1.9rem 0 0 0;
float: right;
}
a:hover {
color: var(--color-light);
background: var(--color-primary);
border-bottom: .35em solid black;
}
h1 {
color: var(--color-dim);
font-family: var(--font-title);
font-size: 2.4em;
font-weight: 400;
letter-spacing: 1.5px;
}
#timeline-content {
margin-top: var(--spacing);
text-align: center;
}
/* Timeline CSS magic*/
.timeline { /* applied to the <ul> element */
/* border-left: var(--line) solid var(--color-primary); */
border-left: var(--line) solid black;
border-bottom-right-radius: var(--radius);
border-top-right-radius: var(--radius);
background: fade(var(--color-light), 3%);
color: fade(white, 80%);
font-family: var(--font-text);
font-size: 1.03em;
font-weight: 100;
margin: var(--spacing) auto;
max-width: 40%;
letter-spacing: 0.5px;
line-height: 1.4em;
list-style: none;
position: relative;
padding: var(--spacing);
text-align: left;
h1 {
color: var(--color-dim);
font-family: var(--font-title);
font-size: 1.4em;
font-weight: 100;
letter-spacing: 1.5px;
}
h2, h3 {
color: var(--color-dim);
font-family: var(--font-title);
font-size: 1.4em;
font-weight: 400;
letter-spacing: 1.5px;
}
.event { /* applied to <li> elements */
--background: #fcf5e5; // parchment;
--color-light: white;
--color-primary: #000000;
--date: 120px;
--dot: 13px;
--dotborder: 4px;
--font-title: 'Helvetica';
--spacing: 50px;
--line: 4px;
/* border-bottom: 1px dashed fade(var(--color-light), 10%); */
border-bottom: 1px dashed fade(black, 90%);;
/* padding-bottom: calc(var(--spacing) * 0.5); */
/* margin-bottom: var(--spacing); */
position: relative;
&:last-of-type {
padding-bottom: 0;
margin-bottom: 0;
border: none;
}
&:before, &:after {
position: absolute;
display: block;
top: 0;
}
&:before { /* dates */
/* variables here won't inherit from :root , a seemingly dumb oversight */
/* https://stackoverflow.com/questions/12124953/can-the-before-and-after-pseudo-elements-inherit-height-from-the-parent-elemen */
/* https://stackoverflow.com/questions/71462808/why-css-variables-are-not-inherited-in-pseudo-elements */
left: calc( (((var(--date) * 0.6) + var(--spacing) + var(--line) + var(--dot) + (var(--dotborder) * 2)) * 1.5) * -1 );
color: fade(var(--color-light), 40%);
content: attr(data-date);
font-weight: 100;
font-size: 0.9em;
font-family: var(--font-text);
min-width: var(--date);
text-align: right;
}
&:after { /* circles on the li elements*/
/* variables here won't inherit from :root */
/* box-shadow: 0 0 0 var(--dotborder) fade(var(--color-primary),100%); */ /* offset-x | offset-y | blur-radius | spread-radius | color */
box-shadow: 0 0 0 var(--dotborder) var(--color-primary);
left: calc((var(--spacing) + var(--line) + (var(--dot) * 0.35)) * -1);
/* background: lighten(var(--background),5%); */
background: var(--background);
border-radius: 50%;
height: var(--dot);
width: var(--dot);
content: "";
top: 5px;
overflow-y: auto; /* we can accomodate big items, but maintain proportional size of container */
}
}
}
</style>
</head>
<body>
<div id="timeline-content">
<h1 id="inpage-title">Timeline</h1>
<ul class="timeline" id="timeline_ul">
</ul>
</div>
</body>
</html>