Repository navigation
Expand file tree
/
Copy pathMain.pde
More file actions
328 lines (314 loc) · 11.6 KB
/
Copy pathMain.pde
File metadata and controls
328 lines (314 loc) · 11.6 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
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
WidgetList widgetList;
WidgetList widgetList1;
WidgetList widgetList2;
WidgetList widgetList3;
WidgetList widgetList4;
PImage globe;
PImage planeSymbol;
final int homeScreen = 0;
final int flightScreen = 1;
final int divertedScreen = 2;
final int cancelledScreen = 3;
final int heatMapScreen = 4;
final int barChartScreen = 5;
final int pieChartScreen = 6;
final int loadingFrameAmount = 64;
PImage[] loadingGif = new PImage[loadingFrameAmount];
int count = 0;
HeatMap theHeatMap;
PShape theUSImage;
searchBar theSearchBar;
searchBar theChartSearchBar;
boolean searchBarActive;
barChart theBarChart;
String barChartLabel;
String barChartLabel2;
Data flightData;
PieChart thePieChart;
diverted diverted;
searchBar divertedSearchBar;
ControlP5 cp5;
ExecutorService executorService;
readDataTask readInTheData;
float xBarpos;
CancelledFlights theCancelledFLights;
void setup()
{
executorService = Executors.newCachedThreadPool();
readInTheData = new readDataTask("readAllData!");
flightData = new Data("flights_full.csv");
//flightData.setData();
executorService.execute(readInTheData);
cp5 = new ControlP5(this);
theBarChart = new barChart(100, 130, 40, 40, "flights_full.csv", cp5);
executorService.execute(theBarChart.readTimes);
executorService.execute(theBarChart.readStates);
barChartLabel = "Change to State";
barChartLabel2 = "Departures";
globe = loadImage("BG Pic.jpg");
planeSymbol = loadImage("Plane Symbol.png");
theUSImage = loadShape("theUS.svg");
theHeatMap = new HeatMap(200, 264, theUSImage, "flights_full.csv");
diverted = new diverted(100, 130, flightData);
size(1512, 982);
// for loop to load in array of image frames for loading gif
for (int i = 0; i < loadingFrameAmount; i++)
{
String frameName = "frame_"+ nf(i, 3) +"_delay-0.03s.gif";
loadingGif[i] = loadImage(frameName);
}
widgetList = new WidgetList();
widgetList.addButton("Flights", color(255, 255, 0), flightScreen);
widgetList.addButton("Diverted Flights", color(255, 255, 0), divertedScreen);
widgetList.addButton("Cancelled Flights", color(255, 255, 0), cancelledScreen);
widgetList1 = new WidgetList();
widgetList1.addFlightScreenButton("Main Menu", color(255, 255, 0), homeScreen);
widgetList1.addFlightScreenButton("Bar Chart", color(255, 255, 0), barChartScreen);
widgetList1.addFlightScreenButton("Pie Chart", color(255, 255, 0), pieChartScreen);
//widgetList1.addFlightScreenButton("List", color(255, 255, 0), 1);
widgetList1.addFlightScreenButton("Heat Map", color(255, 255, 0), 4);
widgetList2 = new WidgetList();
widgetList2.addFlightScreenButton("Main Menu", color(255, 255, 0), homeScreen);
widgetList3 = new WidgetList();
widgetList3.addFlightScreenButton("Main Menu", color(255,255,0), homeScreen);
theSearchBar = new searchBar(1280, 95, 210, 70, "type text here...", color(210, 210, 0), "null", false);
theChartSearchBar = new searchBar(1230, 700, 200, 70, "type text here...", color(210, 210, 0), "null", false);
divertedSearchBar = new searchBar(1200, 150, 210, 70, "type text here...", color(210, 210, 0), "null", false);
widgetList4 = new WidgetList();
widgetList4.addBarChartButton(barChartLabel, color(255,255,0), barChartScreen);
widgetList4.addBarChartButton(barChartLabel2, color(255,255,0), barChartScreen);
searchBarActive = false;
thePieChart = new PieChart(400, 500, 600, flightData, color(209,38,72),color(38,122,209));
xBarpos = 799;
theCancelledFLights = new CancelledFlights(100, 130, flightData);
}
// draw uses a count to check which sscreen it's on and then draws using other classes
void draw()
{
if(count == homeScreen)
{
background(0);
widgetList.display(); // widgetList is 3 buttons to choose between our main three pages
fill(255, 255, 0);
textSize(75);
text("Flight Visualiser", (width / 2) + 35, 100);
textSize(50);
image(globe, 0, 732, 1512, 250);
image(planeSymbol, width / 2 - 305, 65, 75, 75);
}
else if(count == flightScreen)
{
background(0);
textSize(25);
widgetList1.display(); // widgetList1 is our tabs buttons at the top which allow you to switch between screens easily
} // widgetList1 iis displayed on all screens under the "Flights" banner
else if (count == heatMapScreen)
{ // heat map screen draws heat map and search bar to screen
background(255, 255, 0);
textSize(25);
widgetList1.display();
theHeatMap.draw();
theHeatMap.drawStates();
theSearchBar.display();
if(searchBarActive) // checks if search bar is in use
{
theSearchBar.adjustText();
}
}
else if (count == barChartScreen) // bar chart screen draws bar chart and search bar to screen
{
background(255, 255, 0);
textSize(25);
widgetList1.display();
theBarChart.draw();
textSize(25);
widgetList4.display();
theChartSearchBar.display();
if(searchBarActive) // checks if search bar is in use
{
theChartSearchBar.adjustText();
}
}
else if (count == pieChartScreen) // pie chart screen
{
textSize(25);
background(255, 255, 0);
widgetList1.display();
thePieChart.draw();
}
else if(count == divertedScreen) // diverted screen displays a list of diverted flights and a search bar
{
diverted.draw();
if(divertedSearchBar.active)
{
divertedSearchBar.adjustText();
}
}
else if(count == cancelledScreen) // cancelled screen displays a list of cancelled flights and a search bar
{
background(0);
widgetList3.display();
theCancelledFLights.draw();
if(divertedSearchBar.active)
{
divertedSearchBar.adjustText();
}
}
if ( count != barChartScreen ) {
theBarChart.d1.setVisible(false);
theBarChart.d2.setVisible(false);
theBarChart.d3.setVisible(false);
theBarChart.d4.setVisible(false);
}
if (count == flightScreen || count == heatMapScreen || count == barChartScreen || count == pieChartScreen) {
fill(0);
rect(0, 0, 1512, 30);
xBarpos -= 1;
if (xBarpos < -800) {
xBarpos = 2200;
}
fill(255);
textSize(25);
text("The Flight Visualizer - by Jake Casserly, Darragh Considine, Rosie Cassidy, Naomi Cunnigham, Luke Hand and Keith Lyons", xBarpos, 12);
}
}
void mouseMoved() // checks all buttons for the mouse hovering over
{
widgetList.checkButtonsBorder(mouseX, mouseY);
widgetList1.checkButtonsBorder(mouseX, mouseY);
widgetList2.checkButtonsBorder(mouseX, mouseY);
widgetList3.checkButtonsBorder(mouseX, mouseY);
widgetList4.checkButtonsBorder(mouseX, mouseY);
theSearchBar.checkBorder(mouseX, mouseY);
divertedSearchBar.checkBorder(mouseX, mouseY);
}
void mousePressed() // checks what button is pressed to see which screen to change to and which array list of buttons to display
{
if(count == homeScreen)
{
widgetList.checkButtons(mouseX, mouseY);
}
else if(count == flightScreen || count == heatMapScreen || count == barChartScreen || count == pieChartScreen)
{
widgetList1.checkButtons(mouseX, mouseY);
}
else if(count == divertedScreen)
{
widgetList2.checkButtons(mouseX, mouseY);
}
else if(count == cancelledScreen)
{
widgetList3.checkButtons(mouseX, mouseY);
}
if(count == barChartScreen)
{
widgetList4.checkButtons(mouseX, mouseY);
}
if (theSearchBar.checkSearchBar(mouseX, mouseY)) {
theSearchBar.result();
}
if (theChartSearchBar.checkSearchBar(mouseX, mouseY)) {
theChartSearchBar.result();
println(searchBarActive);
}
if (divertedSearchBar.checkSearchBar(mouseX, mouseY)) {
divertedSearchBar.result();
}
if(widgetList4.checkBarChartButton(mouseX, mouseY, 1220, 110) && count == barChartScreen)
{
println(barChartLabel2);
if (barChartLabel == "Change to Time" || barChartLabel == "Change to State") {
if(theBarChart.xAxis == "state")
{
theBarChart.xAxis = "time";
}
else
{
theBarChart.xAxis = "state";
}
if(barChartLabel == "Change to Time")
{
widgetList4.setBarChartButtonLabel("Change to State", 1);
barChartLabel = "Change to State";
}
else
{
widgetList4.setBarChartButtonLabel("Change to Time", 1);
barChartLabel = "Change to Time";
}
}
}
if(widgetList4.checkBarChartButton(mouseX, mouseY, 1220, 200) && count == barChartScreen) {
if (barChartLabel2 == "Arrivals" || barChartLabel2 == "Departures") {
if(theBarChart.departures == true)
{
theBarChart.departures = false;
println("heremm");
}
else
{
theBarChart.departures = true;
println("heremmtrue");
}
if(barChartLabel2 == "Arrivals")
{
widgetList4.setBarChartButtonLabel("Departures", 2);
barChartLabel2 = "Departures";
}
else
{
widgetList4.setBarChartButtonLabel("Arrivals", 2);
barChartLabel2 = "Arrivals";
}
}
}
if(theSearchBar.checkSearchBar(mouseX, mouseY))
{
searchBarActive = true;
}
if(theChartSearchBar.checkSearchBar(mouseX, mouseY))
{
searchBarActive = true;
}
if(divertedSearchBar.checkSearchBar(mouseX, mouseY))
{
searchBarActive = true;
}
// N.Cunningham added events for PieChart radio buttons 23:00 09/04/24
if(thePieChart.radioTime.checkMouse(mouseX,mouseY)) thePieChart.query = thePieChart.SHOW_TIME;
else if(thePieChart.radioScheduled.checkMouse(mouseX,mouseY)) thePieChart.query = thePieChart.SHOW_SCHEDULED;
else if(thePieChart.radioAirports.checkMouse(mouseX,mouseY)) thePieChart.query = thePieChart.SHOW_AIRPORTS;
}
void controlEvent(ControlEvent theEvent) {
// DropdownList is of type ControlGroup.
// A controlEvent will be triggered from inside the ControlGroup class.
// therefore you need to check the originator of the Event with
// if (theEvent.isGroup())
// to avoid an error message thrown by controlP5.
if (theEvent.isGroup())
{
// to avoid an error message thrown by controlP5.
println(theEvent.getValue());
theBarChart.state1 = theBarChart.allStates[(int)theEvent.getValue()];
print(theBarChart.state1);
}
if (theEvent.isFrom(theBarChart.d1)) {
theBarChart.state1 = theBarChart.allStates[(int)theEvent.getValue()];
theBarChart.state1num = (int)theEvent.getValue();
}
else if (theEvent.isFrom(theBarChart.d2)) {
theBarChart.state2 = theBarChart.allStates[(int)theEvent.getValue()];
theBarChart.state2num = (int)theEvent.getValue();
}
else if (theEvent.isFrom(theBarChart.d3)) {
//theBarChart.time1 = theBarChart.allStates[(int)theEvent.getValue()];
theBarChart.time1num = (int)theEvent.getValue();
}
else if (theEvent.isFrom(theBarChart.d4)) {
//theBarChart.time1 = theBarChart.allStates[(int)theEvent.getValue()];
theBarChart.time2num = (int)theEvent.getValue();
}
if (theEvent.isController()) {
println("event from controller : "+theEvent.getController().getValue()+" from "+theEvent.getController());
}
}