-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotGraph.java
More file actions
55 lines (48 loc) · 1.36 KB
/
PlotGraph.java
File metadata and controls
55 lines (48 loc) · 1.36 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
import java.awt.Color;
import java.util.ArrayList;
import acm.graphics.*;
import acm.program.GraphicsProgram;
public class PlotGraph extends GraphicsProgram {
public static final int radiusofPoint = 5;
/**
* Given a DataPoint, it is added to the graph
* @param p
*/
private GOval datapointToGraphpoint(DataPoint p) {
GOval point = new GOval(radiusofPoint, radiusofPoint);
point.setLocation(p.x[0], p.x[1]);
point.setFilled(true);
//if it is in queue color in red, else i blue
if(p.label == 1) {
point.setColor(Color.red);
} else {
point.setColor(Color.blue);
}
return point;
}
public ArrayList<GOval> buildGraph(ArrayList<DataPoint> arr) {
ArrayList<GOval> point_add = new ArrayList<GOval>();
for(DataPoint data: arr) {
GOval obj = datapointToGraphpoint(data);
point_add.add(obj);
}
return point_add;
}
// public void init() {
// DataPoint p = new DataPoint(new double[] {3.4, 10}, 1);
// DataPoint p1 = new DataPoint(new double[] {4.7, 5}, 0);
// DataPoint p2 = new DataPoint(new double[] {6.7, 8}, 0);
// DataPoint p3 = new DataPoint(new double[] {2.4, 18}, 1);
// ArrayList<DataPoint> d = new ArrayList<DataPoint>();
// d.add(p);
// d.add(p1);
// d.add(p2);
// d.add(p3);
//
// PlotGraph plot = new PlotGraph();
// ArrayList<GOval> goval = plot.buildGraph(d);
// for(GOval oval: goval) {
// add(oval);
// }
// }
}