-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBarGraphPanel.java
39 lines (33 loc) · 1.02 KB
/
BarGraphPanel.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
/*
Bar Graph Panel object for Parkrun data collector
Daniel Mesham
28 January 2017
*/
import javax.swing.*;
import java.awt.*;
import java.lang.Math;
class BarGraphPanel extends GraphPanel {
private GraphBar[] dataBars;
private Color color = Color.RED;
public BarGraphPanel(int widthIn, int heightIn, double maxX, double maxY, GraphBar[] dataBarsIn) {
super(widthIn, heightIn, maxX, maxY);
dataBars = dataBarsIn;
}
//@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
plot(dataBars, color, g);
}
private void plot(GraphBar[] dataIn, Color colorIn, Graphics g) {
Color oldColor = g.getColor();
g.setColor(colorIn);
for (GraphBar gb : dataIn) {
int width = lengthToX(gb.getWidth());
int height = lengthToY(gb.getHeight());
int x = valToX(gb.getX());
int y = valToY(0) - height;
g.fillRect(x,y,width,height);
}
g.setColor(oldColor);
}
}