| 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 |
package dr.app.gui.chart; |
| 27 |
|
| 28 |
import dr.stats.Variate; |
| 29 |
|
| 30 |
import java.awt.*; |
| 31 |
import java.awt.geom.GeneralPath; |
| 32 |
import java.util.List; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public class LinePlot extends Plot.AbstractPlot { |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public LinePlot(Variate.N xData, Variate.N yData) { |
| 49 |
super(xData, yData); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public LinePlot(List<Double> xData, List<Double> yData) { |
| 56 |
super(xData, yData); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
protected void paintData(Graphics2D g2, Variate.N xData, Variate.N yData) { |
| 63 |
|
| 64 |
double x = transformX(((Number) xData.get(0)).doubleValue()); |
| 65 |
double y = transformY(((Number) yData.get(0)).doubleValue()); |
| 66 |
|
| 67 |
GeneralPath path = new GeneralPath(); |
| 68 |
path.moveTo((float) x, (float) y); |
| 69 |
|
| 70 |
int n = xData.getCount(); |
| 71 |
boolean failed = false; |
| 72 |
for (int i = 1; i < n; i++) { |
| 73 |
x = transformX(((Number) xData.get(i)).doubleValue()); |
| 74 |
y = transformY(((Number) yData.get(i)).doubleValue()); |
| 75 |
if (x == Double.NEGATIVE_INFINITY || y == Double.NEGATIVE_INFINITY || |
| 76 |
Double.isNaN(x) || Double.isNaN(y)) { |
| 77 |
failed = true; |
| 78 |
} else if (failed) { |
| 79 |
failed = false; |
| 80 |
path.moveTo((float) x, (float) y); |
| 81 |
} else { |
| 82 |
path.lineTo((float) x, (float) y); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
g2.setPaint(linePaint); |
| 87 |
g2.setStroke(lineStroke); |
| 88 |
|
| 89 |
g2.draw(path); |
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
|