-
Notifications
You must be signed in to change notification settings - Fork 0
/
datapoint.js
69 lines (61 loc) · 1.74 KB
/
datapoint.js
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
hoverColor = "rgb(0, 255, 255)";
coldColor = [0, 0, 255];
hotColor = [255, 0, 0];
datapointSize = 10;
datapointSizeHover = 20;
class datapoint {
date = null;
title = "";
description = "";
heat = 0;
heatNormalized = 0;
constructor(date, title, description, heat) {
if (date != null)
this.date = date;
else console.log("Date is null");
if (title != null)
this.title = title;
if (description != null)
this.description = description;
if (heat != null)
this.heat = heat;
}
size = 10;
baseSize = 10;
sizeGoal = 10;
clicked = false;
offset = 0;
offsetGoal = 0;
_color = { r: 255, g: 0, b: 0 };
get color() {
if (this.hovering) {
return hoverColor;
} else {
return "rgb(" + this._color.r + "," + this._color.g + "," + this._color.b + ")";
}
}
set color(value) {
this._color = value;
}
_hovering = false;
get hovering() {
return this._hovering || this.clicked;
}
set hovering(value) {
this._hovering = value;
if (value) {
this.sizeGoal = datapointSizeHover * (this.heatNormalized + 0.4);
} else {
this.sizeGoal = datapointSize * (this.heatNormalized + 0.4);
}
}
update() {
this.size += (this.sizeGoal - this.size) * 0.1;
this.offset += (this.offsetGoal - this.offset) * 0.1;
this.color = {
r: coldColor[0] + (hotColor[0] - coldColor[0]) * this.heatNormalized,
g: coldColor[1] + (hotColor[1] - coldColor[1]) * this.heatNormalized,
b: coldColor[2] + (hotColor[2] - coldColor[2]) * this.heatNormalized
};
}
}