-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverlay.pde
More file actions
222 lines (162 loc) · 5.73 KB
/
Copy pathOverlay.pde
File metadata and controls
222 lines (162 loc) · 5.73 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
import java.util.*;
public class Overlay{
Map map;
float filterMax[];
float filterValue[];
int filterToggle[];
//--These are shallow arraylist copies of StateList, in
// various orders
ArrayList<ArrayList<State>> arrayList;
//top 3
ArrayList<ArrayList<State>> stateData;
CircleData[] circleData;
int topNo =3;
public Overlay(Map map){
this.map = map;
filterMax = new float[6];
filterValue = new float[6];
filterToggle = new int[6];
arrayList = new ArrayList<ArrayList<State>>(6);
circleData = new CircleData[6];
stateData = new ArrayList<ArrayList<State>>(6);
fillLists();
/*
//-- future update: try passing functions.
*/
}
//-- Gets called also when percentage turns to numbers and vice versa
void fillLists(){
for(int i=0; i<filterMax.length; i++){
stateData.add(new ArrayList<State>(3));
//int dataType = i+1; //data array in stateData starts with num workers
arrayList.add(new ArrayList<State>(map.getStateList()));
Collections.sort(arrayList.get(i), new StateComparator( numOrPerc ,i));
float max = arrayList.get(i).get(0).getStateData().getDataArray()[i];
filterMax[i] = max;
setMax(i, max, true);
filterValue[i]=filterMax[i];
filterToggle[i]=1;
}
makeCircles();
}
float[] getFilterMax(){
return filterMax;
}
void setMax(int dataType, float max){
setMax(dataType, max, false);
makeCircles();
}
void setMax(int dataType, float max, boolean firstTime){
filterValue[dataType]=max;
//change what gets displayed
int top = topInRange(dataType);
topState(dataType, top);
}
void topState(int dataType, int start){
ArrayList<State> topData = new ArrayList<State>(topNo);
//if(start != -1){ //if there's something in this range
for(int i =0; i< topNo; i++){
if(start+i < arrayList.get(dataType).size() && start+i >= 0){
topData.add(arrayList.get(dataType).get(start+i));
}
}
stateData.set(dataType,topData);
//if it doesn't exist, stateData will have an arraylist of nulls.
}
int topInRange(int dataType){
for (int i =0; i<arrayList.get(dataType).size();i++){
if(arrayList.get(dataType).get(i).getStateData().getDataArray()[dataType] <= filterValue[dataType]){ //data array in stateData starts with num workers
return i;
}
}
return -1;
}
void setFilterToggle(int dataType, int visible){
filterToggle[dataType]=visible;
}
void makeCircles(){
int j =0;
//ArrayList<CircleData> circles = new ArrayList<CircleData>(topNo);
PriorityQueue<CircleData> pqCircle = new PriorityQueue<CircleData>();
for(int i=0; i< stateData.size(); i++){
for(State st: stateData.get(i)){
if (st!=null){
color col = typeColor[i];
int multiplier1 = 0;
int multiplier2 =0;
if(numOrPerc){
multiplier1 = 75;
multiplier2 =30;
}
else{
multiplier1 = 50;
multiplier2 =20;
}
float dataValue = (float)(st.getStateData().getDataArray()[i]);
int diameter = j *10 + (int) (multiplier1*(dataValue/filterMax[i])) +(int)(multiplier2*dataValue/filterMax[0]);
pqCircle.add(new CircleData(st, diameter, i, (int)dataValue, col));
j++;
}
}
j=0;
}
circleData = pqCircle.toArray(new CircleData[6*topNo]);
//circleData.set(dataType, circles);
}
String overlay="";
void drawOverlay(){
for (int i=0; i< circleData.length; i++){
if(circleData[i]!=null && filterToggle[circleData[i].getDataType()]==1){
circleData[i].draw();
}
}
draw.overlayText(overlay);
}//end draw Overlay
void mousePressed(){
//check from lowest diameter to highest
boolean pass = true;
for(int i = circleData.length-1; i>=0; i--){
if(circleData[i]!=null && circleData[i].contains() && filterToggle[circleData[i].getDataType()]==1){
draw.setWindowState(circleData[i].getState());
//mouseMoved();
pass = false;
break;
}
}
if(pass)
reset();
}
void setOverlayState(State state, int dataType){
if(filterToggle[dataType]==1){
for(int i = circleData.length-1; i>=0; i--){
if(circleData[i].getState()==state && circleData[i].getDataType()==dataType){
circleData[i].setBrushing(true);
break;
}
}
}
}
//--this is if I'm outside my overlay mousemove check
void reset(){
overlay="";
for(int i = circleData.length-1; i>=0; i--){
if(circleData[i]!=null){
circleData[i].setBrushing(false); //reset every time
}
}
}
void mouseMoved(){
//check from lowest diameter to highest
// mousePressed();
reset();
draw.pieReset();
for(int i = circleData.length-1; i>=0; i--){
if( circleData[i]!=null && circleData[i].contains() && filterToggle[circleData[i].getDataType()]==1){
overlay=typeName[circleData[i].getDataType()]+" : "+circleData[i].getValue();
circleData[i].setBrushing(true);
draw.windowCheck(circleData[i].getState(), circleData[i].getDataType());
break;
}
}
}
}//end class