forked from hspencer/s70
-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotation.js
157 lines (143 loc) · 4.29 KB
/
annotation.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
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
/**
* a annotation is a representation of an observation from Casiopea
* that connects 1 or more chapters
*
*/
class Annotation {
constructor(o) {
this.title = o.fulltext;
this.url = o.fullurl;
this.note = o.printouts.Nota[0];
this.side = 15;
this.over = false;
this.myEdges = [];
this.author = [];
for (let i = 0; i < o.printouts.Autor.length; i++) {
this.author.push(o.printouts.Autor[i].fulltext);
}
// crea el cuerpo físico de la observación
let options = {
friction: 0.5,
frictionAir: 0.9,
frictionStatic: 0.19,
restitution: 0.9,
sleepThreshold: 10,
mass: this.w / 10
};
this.body = Bodies.circle(width / 2 + random(-2, 2), height / 2 + random(-2, 2), this.side, options);
World.add(world, this.body);
this.connectedNames = o.printouts["Páginas Relacionadas"];
this.connected = [];
for (let i = 0; i < this.connectedNames.length; i++) {
let t = this.connectedNames[i].fulltext;
for(let i = 0; i < caps.length; i++){
if(caps[i].title === t){
// print("iguales!!");
this.connected.push(caps[i]);
// crea el vértice con los capítulos conectados
let e = new Edge(this, caps[i], annotationEdges);
this.myEdges.push(e);
let edgeOptions = {
label: "spring",
length: random(10, 20),
stiffness: 0.001,
bodyA: this.body,
bodyB: caps[i].body
}
// crea el vértice con opciones diferentes al arreglo principaln
e.createLinkWith(edgeOptions);
}
}
}
}
display() {
let pos = this.body.position;
this.x = pos.x;
this.y = pos.y;
if (dist(this.x, this.y, mouseX, mouseY) < this.side / 2) {
this.over = true;
for(let i = 0; i < this.myEdges.length; i++){
this.myEdges[i].selected = true;
// this.connected[i].col = color(0);
push();
translate(this.connected[i].x, this.connected[i].y);
rotate(this.connected[i].angle);
rectMode(CENTER);
fill(0);
rect(0, 0, this.connected[i].side, this.connected[i].side);
pop();
}
} else {
this.over = false;
for(let i = 0; i < this.myEdges.length; i++){
this.myEdges[i].selected = false;
// this.connected[i].col = this.connected[i].colOriginal;
}
}
push();
translate(pos.x, pos.y);
if (this.over) {
stroke(0);
strokeWeight(2);
fill(0);
} else {
stroke(0, 90);
strokeWeight(1);
fill(255);
}
circle(0, 0, this.side);
// 3 lines
let l = this.side/4;
let h = l*.7;
line(-l, -h, l, -h);
line(-l, 0, l, 0);
line(-l, h, l, h);
pop();
}
}
function buildAnnotations() {
// build main array 'obs'
for (let key in obsData.query.results) {
let result = obsData.query.results[key];
let o = new Annotation(result);
obs.push(o);
print(result.fulltext);
}
}
function drawAnnotations() {2
for (n of obs) {
n.display();
if (mConstraint.body === n.body || n.over) {
displayAnnotationDetails(n);
current = n;
}
}
}
function displayAnnotationDetails(c) {
velo();
noStroke();
textFont(sans);
textSize(18);
textLeading(18);
textAlign(LEFT, TOP);
textWrap(WORD);
fill(100);
rectMode(CORNER);
text(c.note, 0, 30, 320, height);
textFont(serif);
textAlign(CENTER);
textSize(12);
fill(90);
text("click para ver", width / 2, height - 18);
fill(50);
textFont(sansBold);
textSize(16);
textAlign(LEFT);
text(c.title.toUpperCase(), 0, 5);
}
function velo(){
noStroke();
fill(255, 200);
rectMode(CORNER);
rect(0, 0, width, height);
}