-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphic.pde
290 lines (228 loc) · 7.17 KB
/
graphic.pde
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
class graphicClass{ //THIS CLASS DRAWS THE GRAPHIC FOR POPUP SKETCH
PFont font; //VARIABLE FONT
valueTable data; //Creating data table from file to be used by graphic class
void drawvalues(int type){
smooth();
data= new valueTable();
String buffer[]=data.get_table_lines();
float rangeData[]=findMaxMin(buffer,type); //Returns minvalue(0) and maxvalue(1) of Year
float rangeYear[]=findMaxMin(buffer,0); //Returns minvalue(0) and maxvalue(1) of Data
textFont(popup2Font);
beginShape(); //Begins Shape of polygon
vertex(X0,Y0);
for(int i=1;i<buffer.length;i++){
String[] col = split(buffer[i],',');
float RositaSalamo0=float(col[0]);
float m0= map(RositaSalamo0,rangeYear[0],rangeYear[1],X0+8,X1-8); //Mapping Year range into graph
float RositaSalamo1=float(col[type]);
float m1= map(RositaSalamo1,rangeData[0],rangeData[1],Y0-1,Y1*R+10); //Mapping Data range into graph
vertex(m0,m1);
}
//curveVertex(X0,Y0);
vertex(X1-1,Y0);
vertex(X1-1,Y0);
endShape(CLOSE);
fill(backColor);
noStroke();
beginShape(); //CLEARING LEFT PART OF GRAPH (Y AXIS)
vertex(X0-70,Y0+h/14);
vertex(X0,Y0+h/14);
vertex(X0,Y1-h/14);
vertex(X0-70,Y1-h/14);
endShape(CLOSE);
DecimalFormat df = new DecimalFormat("#.##");
if (type<5){ //IF VALUE IS AN INDICATOR
//DRAWING VALUES ON Y AXIS (LEFT)
fill(COLOR[0],COLOR[1],COLOR[2]);
float RD0=(rangeData[0]);
float RD1=(rangeData[1]);
String percentage = df.format(RD0);
String percentage2 = df.format(RD1);
String percentage3 = df.format(RD0+(RD1-RD0)/2);
text(percentage,X0-23,Y0);
text(percentage2,X0-23,Y1);
text(percentage3,X0-23,Y0+(Y1-Y0)/2);
clearJunk(); //CLEARS BORDERS OF GRAPH AREA FOR STETIC PURPOSES
}
else{ //IF VALUE IS A WORD
fill(COLORDATA[0],COLORDATA[1],COLORDATA[2]);
float RD0=(rangeData[0]);
float RD1=(rangeData[1]);
String percentage4 = df.format(RD0);
String percentage5 = df.format(RD1);
String percentage6 = df.format(RD0+(RD1-RD0)/2);
text(percentage4,X1+15,Y0);
text(percentage5,X1+15,Y1);
text(percentage6,X1+15,Y0+(Y1-Y0)/2);
clearJunk();
}
}
void movegraphdown(){
if (select!=drawselect){
if (move==1){
R=R+a;
a=a+0.0098;
fill(25);
rect(0,height,-X0,Y0);
if ((Y1*R)>=Y0){ //Implement animation effect
move=0;
a=0;
clearJunk(); //just in case...
drawselect=select;
M1=compute.mean(WORDCOLUMN); //THIS IS A HEAVY COMPUTING OPERATION
SD1=compute.SD(WORDCOLUMN); //THIS IS A HEAVY COMPUTING OPERATION
V1=pow(SD1,2);
r=compute.correlate(WORDCOLUMN,drawselect); //THIS IS A HEAVY COMPUTING OPERATION AND SHOULD NEVER BE DONE IN LOOP
t=compute.tvalue(WORDCOLUMN,drawselect); //THIS OPERATION IS DEPENDENT ON RESULTS OF r and SD1
}
}
}
}
void movegraphup(){
if (move==0){
R=R-a;
a=a+0.0098;
fill(25);
rect(0,height,-X0,Y0);
if (Y1*R<=Y1){ //Implement animation effect
move=2;
R=1;
a=0;
clearJunk(); //just in case...
}
}
}
void cleargraph(){ //CLEARS GRAPH CONTENTS AND REDRAWS INFO
//CREATING EMPTY RECTANGLE THAT OVERWRITES ENTIRE GRAPH
fill(graphbackColor);
noStroke();
beginShape();
vertex(X0+ST,Y0);
vertex(X1-ST,Y0);
vertex(X1-ST,Y1-height/13); //added -height/10 to clear the "jump" when falling
vertex(X0+ST,Y1-height/13);
endShape();
//CREATING RECTANGLE THAT OVERWRITES TOP PARAMETERS AREA
beginShape();
fill(backColor);
vertex(X0+ST,Y1);
vertex(X1-ST,Y1);
vertex(X1-ST,Y1-height/13); //added -height/10 to clear the "jump" when falling
vertex(X0+ST,Y1-height/13);
endShape();
//CREATING RECTANGLE THAT OVERWRITES BOTTOM PARAMETERS AREA
/*beginShape();
fill(backColor);
vertex(X0,Y0);
vertex(X1,Y0);
vertex(X1,Y0+height/10); //added -height/10 to clear the "jump" when falling
vertex(X0,Y0+height/10);
endShape();
*/
/*
fill(backColor);
beginShape(); //CLEARING LEFT PART OF GRAPH (Y AXIS)
vertex(X0,Y0+h/10);
vertex(300,Y0+h/10);
vertex(300,Y1-h/10);
vertex(X0,Y1-h/10);
endShape(CLOSE);
fill(backColor);
beginShape(); //CLEARING RIGHT PART OF GRAPH (Y AXIS)
vertex(X1+40,Y0+h/10);
vertex(X1,Y0+h/10);
vertex(X1,Y1-h/10);
vertex(X1+40,Y1-h/10);
endShape(CLOSE);
*/
if(select==1){
beginShape();
fill(graphbackColor);
vertex(X0+ST,Y1);
vertex(X0+ST,Y1-height/13); //added -height/10 to clear the "jump" when falling
vertex(X0+(X1-X0)/4,Y1-height/13);
vertex(X0+(X1-X0)/4,Y1);
endShape();
}
else if(select==2){
beginShape();
fill(graphbackColor);
vertex(X0+(X1-X0)/4,Y1);
vertex(X0+(X1-X0)/4,Y1-height/13); //added -height/10 to clear the "jump" when falling
vertex(X0+(X1-X0)/2,Y1-height/13);
vertex(X0+(X1-X0)/2,Y1);
endShape();
}
else if(select==3){
beginShape();
fill(graphbackColor);
vertex(X1-(X1-X0)/2,Y1);
vertex(X1-(X1-X0)/2,Y1-height/13); //added -height/10 to clear the "jump" when falling
vertex(X1-(X1-X0)/4,Y1-height/13);
vertex(X1-(X1-X0)/4,Y1);
endShape();
}
else if(select==4){
beginShape();
fill(graphbackColor);
vertex(X1-(X1-X0)/4,Y1);
vertex(X1-(X1-X0)/4,Y1-height/13); //added -height/10 to clear the "jump" when falling
vertex(X1-ST,Y1-height/13);
vertex(X1-ST,Y1);
endShape();
}
stroke(sColor,12);
strokeWeight(3);
//DRAWING BACKGROUND LINES
line(X0+ST,Y0+(Y1-Y0)/2,X1-ST,Y0+(Y1-Y0)/2);
line(X0+(X1-X0)/4,Y0,X0+(X1-X0)/4,Y1);
line(X0+(X1-X0)/2,Y0,X0+(X1-X0)/2,Y1);
line(X1-(X1-X0)/4,Y0,X1-(X1-X0)/4,Y1);
strokeWeight(1);
}
void clearJunk(){
noStroke();
fill(backColor);
beginShape(); //CLEARING BOTTOM PART (YEAR VALUES)
vertex(X0,Y0+1);
vertex(X1,Y0+1);
vertex(X1,Y0+80);
vertex(X0,Y0+80);
endShape(CLOSE);
fill(backColor);
beginShape(); //CLEARING BOTTOM PART OF GRAPH
vertex(X0,Y0);
vertex(X1,Y0);
vertex(X1,Y0+3);
vertex(X0,Y0+3);
endShape(CLOSE);
beginShape();
vertex(X1-ST,Y0); //CLEARING RIGHT PART OF GRAPH
vertex(X1,Y0);
vertex(X1,Y1-height/13);
vertex(X1-ST,Y1-height/13);
endShape(CLOSE);
beginShape();
vertex(X0+ST,Y0); //CLEARING LEFT PART OF GRAPH
vertex(X0,Y0);
vertex(X0,Y1-height/13);
vertex(X0+ST,Y1-height/13);
endShape(CLOSE);
}
float[] findMaxMin(String[] buffer,int type){
float maxvalue=MIN_FLOAT; //max value of our data type
float minvalue=MAX_FLOAT; //minimum value of our data type
for(int i=1;i<buffer.length;i++){
String[] col = split(buffer[i],',');
float f0=float(col[type]);
if (f0>maxvalue){
maxvalue=f0;
}
if (f0<minvalue){
minvalue=f0;
}
}
float[] ret = {minvalue, maxvalue};
return(ret);
}
}