| 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 |
public class ErrorBarPlot extends Plot.AbstractPlot { |
| 42 |
public enum Orientation { |
| 43 |
HORIZONTAL, |
| 44 |
VERTICAL |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public ErrorBarPlot(Orientation orientation, Variate.N xData, Variate.N yData, Variate.N errorData) { |
| 51 |
super(xData, yData); |
| 52 |
|
| 53 |
this.errorData = errorData; |
| 54 |
this.orientation = orientation; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public ErrorBarPlot(Orientation orientation, List<Double> xData, List<Double> yData, List<Double> errorData) { |
| 61 |
super(xData, yData); |
| 62 |
|
| 63 |
this.errorData = new Variate.D(errorData); |
| 64 |
this.orientation = orientation; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
protected void paintData(Graphics2D g2, Variate.N xData, Variate.N yData) { |
| 71 |
|
| 72 |
g2.setPaint(linePaint); |
| 73 |
g2.setStroke(lineStroke); |
| 74 |
|
| 75 |
int n = xData.getCount(); |
| 76 |
for (int i = 0; i < n; i++) { |
| 77 |
GeneralPath path = new GeneralPath(); |
| 78 |
|
| 79 |
double x0 = ((Number) xData.get(i)).doubleValue(); |
| 80 |
double y0 = ((Number) yData.get(i)).doubleValue(); |
| 81 |
double e = ((Number) errorData.get(i)).doubleValue() / 2; |
| 82 |
|
| 83 |
float fx = (float)transformX(x0); |
| 84 |
float fy = (float)transformY(y0); |
| 85 |
|
| 86 |
if (!Double.isInfinite(fx) && !Double.isInfinite(fy) && |
| 87 |
!Double.isNaN(fx) && !Double.isNaN(fy)) { |
| 88 |
if (orientation == Orientation.HORIZONTAL) { |
| 89 |
float fx1 = (float)transformX(x0 - e); |
| 90 |
float fx2 = (float)transformX(x0 + e); |
| 91 |
|
| 92 |
path.moveTo(fx, fy); |
| 93 |
path.lineTo(fx1, fy); |
| 94 |
path.moveTo(fx, fy); |
| 95 |
path.lineTo(fx2, fy); |
| 96 |
} else if (orientation == Orientation.VERTICAL) { |
| 97 |
float fy1 = (float)transformY(y0 - e); |
| 98 |
float fy2 = (float)transformY(y0 + e); |
| 99 |
|
| 100 |
path.moveTo(fx, fy); |
| 101 |
path.lineTo(fx, fy1); |
| 102 |
path.moveTo(fx, fy); |
| 103 |
path.lineTo(fx, fy2); |
| 104 |
} |
| 105 |
} |
| 106 |
g2.draw(path); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
private Orientation orientation; |
| 113 |
protected Variate.N errorData = null; |
| 114 |
} |
| 115 |
|