-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScatterGraphPanel.java
46 lines (36 loc) · 1.26 KB
/
ScatterGraphPanel.java
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
/*
Scatter Graph Panel object for Parkrun data collector
Daniel Mesham
28 January 2017
*/
import javax.swing.*;
import java.awt.*;
import java.lang.Math;
class ScatterGraphPanel extends GraphPanel {
private GraphPoint[][] dataPoints;
private static int size = 1;
private static Color[] COLORS = { Color.RED, Color.GREEN, Color.BLUE, Color.ORANGE, Color.MAGENTA, Color.CYAN, Color.PINK, Color.YELLOW };
public ScatterGraphPanel(int widthIn, int heightIn, double maxX, double maxY, GraphPoint[][] dataPointsIn) {
super(widthIn, heightIn, maxX, maxY);
dataPoints = dataPointsIn;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i < dataPoints.length; i ++) {
int colorIndex = i % COLORS.length;
plot(dataPoints[i], COLORS[colorIndex], g);
}
}
private void plot(GraphPoint[] dataIn, Color colorIn, Graphics g) {
Color oldColor = g.getColor();
g.setColor(colorIn);
for (GraphPoint gp : dataIn) {
int x = xCoord(gp);
int y = yCoord(gp);
int offset = (int) Math.floor(size/2);
g.fillRect(x-1,y-1,size,size);
}
g.setColor(oldColor);
}
}