-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.pde
79 lines (56 loc) · 1.44 KB
/
theme.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
PGraphics pickbuffer = null;
int numThemes = 0;
String[] labels;
String[][] values;
Data[] dataValues;
Graph graph;
void setup() {
size(900,400);
background(255);
pickbuffer = createGraphics(width, height, JAVA2D);
smooth();
String[] input = loadStrings("data.csv");
numThemes = input.length-1;
values = new String[numThemes][];
for (int i = 0; i< input.length; i++) {
if (i == 0) labels = split(input[i], ',');
else values[i-1] = split(input[i], ',');
}
dataValues = new Data [numThemes];
float[] totalVals;
totalVals = new float[values[0].length-1];
for (int i = 0; i< numThemes; i++) {
String name = values[i][0];
float[] themeValues;
themeValues = new float[values[i].length-1];
int k = 0;
for(int j = 1; j< values[i].length; j++) {
float val = Float.parseFloat(values[i][j]);
themeValues[k++] = val;
totalVals[j-1] += val;
}
dataValues[i] = new Data(name, themeValues);
}
float maxVal = totalVals[0];
for(int p = 0; p<totalVals.length; p++) {
if (totalVals[p] > maxVal) maxVal = totalVals[p];
}
graph = new Graph(totalVals, maxVal, dataValues,labels);
graph.setupGraph();
}
void draw() {
background(255);
graph.drawGraph();
}
void mouseMoved() {
graph.checkThemes();
}
class Data {
boolean selected = false;
float[] values;
String name;
public Data(String _name, float[] _value) {
values = _value;
name = _name;
}
}