-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
483 lines (447 loc) · 17.3 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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://d3js.org/d3.v6.min.js"></script>
<!-- <script src="index.js"></script> -->
<title>FloomieBloomie 1.0</title>
<link rel="icon" type="image/png" href="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/271/cherry-blossom_1f338.png"/>
<style>
@import url('https://fonts.googleapis.com/css2?family=Nunito&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;700&display=swap');
html, body {
margin: 0;
padding: 0;
border: 0;
background-color: #FFCAD3;
font-family: 'Nunito';
}
table, tr, td {
border: 1px solid black;
vertical-align: middle;
}
table {
width: 100%;
}
#Title {
padding-top: 60px;
font-weight: 700;
padding-bottom: 20px;
text-align: center;
font-size:40px;
padding-left: 24px;
padding-right: 24px;
}
#Notes {
padding-top: 30px;
padding-left: 50px;
padding-right: 50px;
text-align: center;
padding-bottom: 110px;
}
#LeftButton {
text-align: left;
}
#RightButton {
text-align: right;
}
#Notes {
text-align: center;
/*padding-left:50px;
padding-right:50px;*/
}
#PutItHere {
text-align:center;
padding-top: 5px;
padding-bottom: 10px;
}
#titlebar {
font-weight:700;
font-size:25px;
background-color: #FF7F9A;
padding-top: 12px;
padding-left: 12px;
padding-bottom: 12px;
}
#subsubtitlebar {
background-color: #FFA3B6;
padding-top: 12px;
padding-left: 24px;
padding-right: 24px;
padding-bottom: 12px;
}
#subtitlebar {
padding: 12px;
background-color: #333;
color: #fff;
position: fixed;
bottom: 0;
width: 100%;
}
svg {
/* width: auto;
height: auto;
max-width: 100%;
max-height: 100%;*/
}
</style>
</head>
<body>
<div id="titlebar">FloomieBloomie<span style="float:right;"><a href="https://github.com/ryomams/FloomieBloomie"><img src="assets/gh.png" style="padding-right: 12px;" /></a></span></div>
<div id="subsubtitlebar"><a href="javascript:history.go(0)" style="color: #000;">Reload</a><span style="float:right;"> Mood: <span id="htm_mood">X</span> | Significance: <span id="htm_sig">X</span></span></div>
<div id="Title">Hover over a petal to see the activity it represents!</div>
<div id="PutItHere"><!-- SVG Will Generate Here --></div>
<div id="Notes"><b>Notes</b><br /><p id="Notes_Tofill">An activity's notes will appear here as you hover! You can click on the arrows to switch between days.</p></div>
<div id="subtitlebar">By <a href="https://github.com/NSDawn" style="color: #fff">Nishant Suria</a> and <a href="https://ryoma.ms" style="color:#fff;">Ryoma Marta-Sugawara</a><span style="float:right; padding-right:24px;">For <a href="https://www.ucsc.edu/" style="color:#fff;">UCSC</a>'s <a href="https://catalog.ucsc.edu/en/Current/General-Catalog/Courses/CMPM-Computational-Media/Lower-Division/CMPM-35" style="color:#fff;">CMPM 35</a></span></div>
<script>
// inititalization of new class 'Vector2', which stores an x and y
//allows for data entry in cartesian or polar form, then automatically converts it during intialization.
class Vector2 {
constructor(in_a, in_b, in_type = 'rect') {
if (in_type == 'rect') {
this.x = in_a;
this.y = in_b;
this.r = Math.sqrt(this.x ^ 2 + this.y ^ 2);
this.theta = Math.atan(this.y / this.x);
}
else if (in_type == 'polar') {
this.r = in_a;
this.theta = in_b;
this.x = this.r * Math.cos(in_b);
this.y = this.r * Math.sin(this.theta);
this.cx = this.x + CTR.x;
this.cy = this.y + CTR.y;
}
}
}
//our beautiful petals!
class Petal {
constructor(in_title, in_mood, in_significance, in_notes = "", in_color = "#ffffff", in_date) {
//these are all the variables and pieces of data each petal will store
this.title = in_title;
this.mood = in_mood;
this.significance = in_significance;
this.notes = in_notes;
this.color = in_color;
this.path; // used to assign a svg path to each petal
this.date = in_date;
}
}
// function that formats inputs into the form that path() uses
function p(str1, str2, str3 = "", str4 = "", str5 = "", str6 = "", str7 = "", str8 = "") {
let output = "";
output += str1; output += " "; output += str2;
if (str3 != "") {
output += " "; output += str3;
}
if (str4 != "") {
output += " "; output += str4;
}
if (str5 != "") {
output += " "; output += str5;
}
if (str6 != "") {
output += " "; output += str6;
}
if (str7 != "") {
output += " "; output += str7;
}
if (str8 != "") {
output += " "; output += str8;
}
return output;
}
//some constants we'll be referencing, so that we don't have to type them ALL THE TIME >:(
const s = " ";
const PI = Math.PI;
const PHI = (1 + Math.sqrt(5)) / 2;
const cs = new Vector2(900, 600, 'rect'); // cs = canvas_size
const CTR = new Vector2(cs.x/2, cs.y/2, 'rect');
const PETAL_SIZE = 300;
const ROTATION_SPEED = 1/1000;
//remnants of an all-nighter:
//console.log("I feel like I'm going insane rn");
//let's make an svg!
let svg = d3.select("#PutItHere").append("svg")
.attr("width", cs.x)
.attr("height", cs.y)
.style("background-color", "#FFCAD3");
//the gray bg of the flower
let circle_Bound = svg.append("circle")
.attr("fill", "#AAA")
.attr("cx", 300 + 150)
.attr("cy", 300)
.attr("r", 300)
.on("mouseover", printDumbShit);
//svg.select(circle_Bound).on("mouseover", printDumbShit);
//the little chevrons you see in the buttons.
let arrowLeft = svg.append("image")
.attr("href", "assets/cleft.svg")
.attr("x", 0)
.attr("y", 250)
.attr("width", "100")
.attr("height", "100");
let arrowRight = svg.append("image")
.attr("href", "assets/cright.svg")
.attr("x", 800)
.attr("y", 250)
.attr("width", "100")
.attr("height", "100");
//the actual buttons that you end up clicking on
let circleRight = svg.append("circle")
.attr("fill", "#FFA3B6")
.attr("cx", 850)
.attr("cy", 300)
.attr("r", 50)
.attr("opacity", 0.5)
.attr("class", "circleRight")
.on("mouseover", eventMouseoverButton)
.on("mousedown", eventMousedownButton)
.on("mouseup", eventMouseoverButton)
.on("mouseout", eventMouseoutButton);
let circleLeft = svg.append("circle")
.attr("fill", "#FFA3B6")
.attr("cx", 50)
.attr("cy", 300)
.attr("r", 50)
.attr("opacity", 0.5)
.attr("class", "circleLeft")
.on("mouseover", eventMouseoverButton)
.on("mousedown", eventMousedownButton)
.on("mouseup", eventMouseoverButton)
.on("mouseout", eventMouseoutButton);
/*const arrowLeft = svg.append("image")
.attr("href", "assets/cleft.svg")
.attr("x", 20)
.attr("y", 250)
.attr("width", "100")
.attr("height", "100");*/
//text functions to set html and svg text to certain things
function setTitle(text) {
let e = document.getElementById("Title");
e.innerHTML = text;
}
function setNotes(text) {
let e = document.getElementById("Notes_Tofill");
e.innerHTML = text;
}
function setYear(text) {
text_Year.text(text);
}
function setDate(text) {
text_Date.text(text);
}
function setMood(text) {
let e = document.getElementById("htm_mood");
e.innerHTML = text;
}
function setSignificance(text) {
let e = document.getElementById("htm_sig");
e.innerHTML = text;
}
//... and then there's this. ignore this. we're tired.
function printDumbShit() {
console.log("Floomie eats children!");
}
//button event handlers
function eventMouseoverButton() {
d3.select(this).attr("fill", "#FF7F9A");
}
function eventMousedownButton() {
d3.select(this).attr("fill", "#FFFFFF");
buttonPressed = d3.select(this).attr("class");
//i screwed this logic up bad but it's 3:30 am and i don't care enough to fix it
if (buttonPressed == "CircleRight") {
dayIterator -= 1;
if (dayIterator < 0) {
dayIterator = uniqueDates.length - 1;
}
} else {
dayIterator += 1;
if(dayIterator > (uniqueDates.length - 1)) {
dayIterator = 0;
}
}
currentDay = uniqueDates[dayIterator];
}
function eventMouseoutButton() {
d3.select(this).attr("fill", "#FFA3B6");
}
//petal event handlers... for handling the events of petals!
let petalIndex = 0;
function eventMouseoverPetal() {
d3.select(this).attr("opacity", 0.5);
console.log(d3.select(this).attr("who"));
ii = parseInt(d3.select(this).attr("who"));
setMood(petals[ii].mood);
setSignificance(petals[ii].significance);
setNotes(petals[ii].notes);
setTitle(petals[ii].title);
//setDate("butthole");
}
function eventMouseoutPetal() {
d3.select(this).attr("opacity", 1);
setMood("X");
setSignificance("X");
setNotes("An activity's notes will appear here as you hover! You can click on the arrows to switch between days.");
setTitle("Hover over a petal!");
}
//some variables for petals uwu
let petals = []; //all the petals to render
let dates = []; //all the possible dates
let uniqueDates = []; //a SET of dates
let currentDay; //what day should we display?
let dayIterator; //what day are we on in data?
// csv parsing time!
d3.csv("assets/data_clean.csv").then(function(data) {
data_length = data.length;
for (let i = 0; i < data.length; i++) {
//make me some petals
const petal_data = new Petal(data[i].Activity, data[i].Mood, data[i].Significance, data[i].Notes, significanceColor(data[i].Significance), data[i].Date);
//also up-date the DATES (haha get it cuz date)
dates.push(data[i].Date);
currentDay = data[i].Date;
petals.push(petal_data);
}
uniqueDates = [...new Set(dates)];
dayIterator = uniqueDates.indexOf(currentDay);
console.log(uniqueDates);
// setting the path shapes to the elements in petals[]
for (let i = 0; i < petals.length; i++) {
const ENDPT = new Vector2(PETAL_SIZE, (((2/PHI) * i)) * PI, 'polar'); //we're mimicking the way plants make petals with phi!! (shoutouts to vi hart we love youuu)
const UNDERMIDPT1 = new Vector2(ENDPT.r / 3, ENDPT.theta - PI/6, 'polar');
const UNDERMIDPT2 = new Vector2(ENDPT.r * 2/3, ENDPT.theta - PI/6, 'polar');
const OVERMIDPT1 = new Vector2(ENDPT.r / 3, ENDPT.theta + PI/6, 'polar');
const OVERMIDPT2 = new Vector2(ENDPT.r * 2/3, ENDPT.theta + PI/6, 'polar');
//create a petal shape that can be rendered at any angle
petals[i].path = svg.append('path')
.attr("d", p("M", CTR.x, CTR.y) + s + p("C", UNDERMIDPT1.cx, UNDERMIDPT1.cy, UNDERMIDPT2.cx, UNDERMIDPT2.cy, ENDPT.cx, ENDPT.cy) + s + p("C", OVERMIDPT2.cx, OVERMIDPT2.cy, OVERMIDPT1.cx, OVERMIDPT1.cy, CTR.x, CTR.y))
.attr("stroke", "#AAA")
.attr("stroke_width", "2")
.attr("fill", petals[i].color)
.attr("who", i)
.on("mouseover", eventMouseoverPetal)
.on("mouseout", eventMouseoutPetal)
;
//draw the pistol elements (where the date is)
let circle = svg.append("circle")
.attr("fill", "#FFD479")
.attr("stroke-width", 3)
.attr("stroke", "#000")
.attr("cx", 300 + 150)
.attr("cy", 300)
.attr("r", 50);
let text_Date = svg.append("text")
.attr("x", 264 + 150)
.attr("y", 300)
.attr("font-family", "Courier New")
.attr("font-size", "25px")
.attr("font-weight", "bold")
.attr("fill", "black")
.text(currentDay);
let text_Year = svg.append("text")
.attr("x", 276 + 150)
.attr("y", 327)
.attr("font-family", "Courier New")
.attr("font-size", "20px")
.attr("font-weight", "italics")
.attr("fill", "black")
.text("2020");
}
// update the elements in petals[] and animate
let intervalsElapsed = 0;
let n = 0;
let m = 1;
let t = d3.interval(function(elapsed) {
intervalsElapsed += 1;
n = (intervalsElapsed * ROTATION_SPEED);
m = (Math.sin((100 * n) % (2*PI)) * 0.02) + 1;
for (let i = 0; i < petals.length; i++) {
if (petals[i].date == currentDay) {
const ENDPT = new Vector2(PETAL_SIZE * m, ((((2/PHI) * i) + n) % 2) * PI, 'polar');
const UNDERMIDPT1 = new Vector2(ENDPT.r / 3, ENDPT.theta - PI/6, 'polar');
const UNDERMIDPT2 = new Vector2(ENDPT.r * 2/3, ENDPT.theta - PI/6, 'polar');
const OVERMIDPT1 = new Vector2(ENDPT.r / 3, ENDPT.theta + PI/6, 'polar');
const OVERMIDPT2 = new Vector2(ENDPT.r * 2/3, ENDPT.theta + PI/6, 'polar');
petals[i].path
.attr("d", p("M", CTR.x, CTR.y) + s + p("C", UNDERMIDPT1.cx, UNDERMIDPT1.cy, UNDERMIDPT2.cx, UNDERMIDPT2.cy, ENDPT.cx, ENDPT.cy) + s + p("C", OVERMIDPT2.cx, OVERMIDPT2.cy, OVERMIDPT1.cx, OVERMIDPT1.cy, CTR.x, CTR.y))
.attr("stroke", "#AAA")
.attr("stroke_width", "2")
.attr("fill", petals[i].color)
.on("mouseover", eventMouseoverPetal)
.on("mouseout", eventMouseoutPetal)
;
} else {
petals[i].path
.attr("stroke", "rgba(0,0,0,0.0)")
.attr("fill", "none")
.on("mouseover", printDumbShit)
.on("mouseout", printDumbShit)
;
}
}
//pistol elements... again
let circle = svg.append("circle")
.attr("fill", "#FFD479")
.attr("stroke-width", 3)
.attr("stroke", "#000")
.attr("cx", 300 + 150)
.attr("cy", 300)
.attr("r", 50);
let text_Date = svg.append("text")
.attr("x", 264 + 150)
.attr("y", 300)
.attr("font-family", "Courier New")
.attr("font-size", "25px")
.attr("font-weight", "bold")
.attr("fill", "black")
.text(currentDay);
let text_Year = svg.append("text")
.attr("x", 276 + 150)
.attr("y", 327)
.attr("font-family", "Courier New")
.attr("font-size", "20px")
.attr("font-weight", "italics")
.attr("fill", "black")
.text("2020");
}, 60);
});
//assign a color to significance
function significanceColor(in_int) {
let output;
switch (in_int) {
case "0":
output = "#8cd1ff";
break;
case "1":
output = "#82eaff";
break;
case "2":
output = "#73fffa";
break;
case "3":
output = "#65fcdc";
break;
case "4":
output = "#59ffbf";
break;
case "5":
output = "#48fab5";
break;
case "6":
output = "#3bf58b";
default:
console.log("significance value could not be read.");
output = false;
}
return output;
}
/*TODO:
-Animate circles on hover
-Figure out clickiness
-Load Data
-Split Data by day
-Combine Nishant's code with mine
*/
</script>
</body>
</html>