-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTDisplay.pde
115 lines (95 loc) · 3.03 KB
/
CTDisplay.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
//Used to dislay information from the GetCTData Class
class CTDisplay {
CTDisplay() {
fill(0);
textAlign(CENTER);
}
void dataCollate() {
//Used to calculate degrees in chart
float totalNumberofBands =
getCTData.bandA +
getCTData.bandB +
getCTData.bandC +
getCTData.bandD +
getCTData.bandE +
getCTData.bandF +
getCTData.bandG +
getCTData.bandH;
float[] bandAmount = {
getCTData.bandA,
getCTData.bandB,
getCTData.bandC,
getCTData.bandD,
getCTData.bandE,
getCTData.bandF,
getCTData.bandG,
getCTData.bandH
};
int[] listofBandPrices = {
(int)getCTData.bandAPrice,
(int)getCTData.bandBPrice,
(int)getCTData.bandCPrice,
(int)getCTData.bandDPrice,
(int)getCTData.bandEPrice,
(int)getCTData.bandFPrice,
(int)getCTData.bandGPrice,
(int)getCTData.bandHPrice
};
String[] letters = {
"A", "B", "C", "D", "E", "F", "G", "H"
};
textSize(30);
text("Council Tax Distribution", height/4, 40);
textSize(27);
text(currentBorough, height/4, 80);
textSize(22);
text("Households Per Band", height/4, 140);
text("£ per Band", height/4, 560);
textSize(16);
pieChart(height/4, bandAmount, totalNumberofBands, letters);
chart(50, height - height/4 + 50, listofBandPrices, letters);
}
void pieChart(float diameter, float[] data, float total, String[] letters) {
float lastAngle = -HALF_PI; // Sets first angle to start vertically
for (int i = 0; i < data.length; i++) {
float percentage = data[i]/total * 100; //each percentage is calculated
float mapPercent = map(percentage, 0, 100, 0, 360); //then mapped into 360 degrees
float mapCol = map(i, 0, data.length, 0, 255); // colors are set and this will be the same for all band information
int spacer = 35;
int dataHeight = 215 + (i * spacer);
//Chart
noStroke();
fill(mapCol, 40, 100);
arc(150, 350, diameter, diameter, lastAngle, lastAngle+radians(mapPercent));
lastAngle += radians(mapPercent);
//Key
rect(315, dataHeight, spacer, 25);
fill(0);
textAlign(LEFT);
text(letters[i], 360, dataHeight + 20);
text((int)percentage + " %", 390, dataHeight + 20);
}
}
void chart(int xPos, int yPos, int[] data, String[] letters) {
strokeWeight(1);
stroke(0);
line(xPos, yPos, xPos + 400, yPos);
int[] xAxisLabels = {
0, 400, 800, 1200, 1600, 2000, 2400, 2800
};
for (int i = 0; i < letters.length; i++) {
int mapBandPrice = (int)map(data[i], 448.5, 2789.95, 0, 200);
float mapCol = map(i, 0, letters.length, 0, 255);
fill(0);
textAlign(CENTER);
text(letters[i], xPos + 30 + (i * 50), yPos + 20);
textSize(16);
text("£" + data[i], 80 + (i * 50), yPos - mapBandPrice - 30);
pushStyle();
fill(mapCol, 40, 100);
noStroke();
rect(60 + (i * 50), yPos, 40, -mapBandPrice);
popStyle();
}
}
}