- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScatterGraphPanel.java
More file actions
Latest commit
46 lines (36 loc) · 1.26 KB
/
Copy pathScatterGraphPanel.java
File metadata and controls
46 lines (36 loc) · 1.26 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
/*
Scatter Graph Panel object for Parkrun data collector
Daniel Mesham
28 January 2017
*/
importjavax.swing.*;
importjava.awt.*;
importjava.lang.Math;
classScatterGraphPanelextendsGraphPanel {
privateGraphPoint[][] dataPoints;
privatestaticintsize = 1;
privatestaticColor[] COLORS = { Color.RED, Color.GREEN, Color.BLUE, Color.ORANGE, Color.MAGENTA, Color.CYAN, Color.PINK, Color.YELLOW };
publicScatterGraphPanel(intwidthIn, intheightIn, doublemaxX, doublemaxY, GraphPoint[][] dataPointsIn) {
super(widthIn, heightIn, maxX, maxY);
dataPoints = dataPointsIn;
}
@Override
publicvoidpaintComponent(Graphicsg) {
super.paintComponent(g);
for (inti = 0; i < dataPoints.length; i ++) {
intcolorIndex = i % COLORS.length;
plot(dataPoints[i], COLORS[colorIndex], g);
}
}
privatevoidplot(GraphPoint[] dataIn, ColorcolorIn, Graphicsg) {
ColoroldColor = g.getColor();
g.setColor(colorIn);
for (GraphPointgp : dataIn) {
intx = xCoord(gp);
inty = yCoord(gp);
intoffset = (int) Math.floor(size/2);
g.fillRect(x-1,y-1,size,size);
}
g.setColor(oldColor);
}
}