-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.pde
62 lines (59 loc) · 1.42 KB
/
Graph.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
import org.gicentre.utils.stat.*;
public class Graph extends BarChart {
int X;
int Y;
float min;
float max;
float [] data={};
int maxData;
String title;
public Graph (int X, int Y, float min, float max, PApplet app, int maxData, String title)
{
super(app);
this.X=X;
this.Y=Y;
this.min=min;
this.max=max;
this.title=title;
this.setMinValue(min);
this.setMaxValue(max);
this.maxData=maxData;
setBarGap(4);
setBarColour(color(0,0, 255));
showValueAxis(true);
setValueFormat("#");
showCategoryAxis(true);
}
public void updateData(float newData)
{
//data=append(this.data, currentIndex);
data=append(this.data, newData);
if(data.length>maxData)
{
data=subset(data, 1);
float tempMax=0;
for(float i: data)
{
if(i>tempMax) tempMax=i;
}
if(tempMax<max)
{
max=5*(((int)tempMax)/5+1);
setMaxValue(max);
}
}
if(newData>max)
{
max=5*(((int)newData)/5+1);
setMaxValue(max);
}
setData(this.data);
}
public void drawChart()
{
draw(X, Y, 500, 250);
//println(this.data);
textAlign(CENTER);
text(title, X+250, Y);
}
}