| 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 |
|
| 32 |
public class LineDistributionPlot extends Plot.AbstractPlot { |
| 33 |
|
| 34 |
private Variate gradients = null; |
| 35 |
private Variate intercepts = null; |
| 36 |
|
| 37 |
private int lineCount = 0; |
| 38 |
private double x1, x2; |
| 39 |
private double[] y1; |
| 40 |
private double[] y2; |
| 41 |
|
| 42 |
private boolean isCalibrated = false; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public LineDistributionPlot(Variate gradients, Variate intercepts) { |
| 48 |
this.gradients = gradients; |
| 49 |
this.intercepts = intercepts; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
@Override |
| 56 |
public void paintPlot(Graphics2D g2, double xScale, double yScale, |
| 57 |
double xOffset, double yOffset, int plotNumber, int plotCount) { |
| 58 |
|
| 59 |
if (gradients == null || intercepts == null) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
super.paintPlot(g2, xScale, yScale, xOffset, yOffset, plotNumber, plotCount); |
| 64 |
|
| 65 |
if (!isCalibrated) { |
| 66 |
x1 = xAxis.getMinAxis(); |
| 67 |
x2 = xAxis.getMaxAxis(); |
| 68 |
|
| 69 |
lineCount = gradients.getCount(); |
| 70 |
y1 = new double[lineCount]; |
| 71 |
y2 = new double[lineCount]; |
| 72 |
|
| 73 |
for (int i = 0; i < lineCount; i++) { |
| 74 |
y1[i] = ( (Double) gradients.get(i) * x1) + (Double) intercepts.get(i); |
| 75 |
y2[i] = ( (Double) gradients.get(i) * x2) + (Double) intercepts.get(i); |
| 76 |
} |
| 77 |
|
| 78 |
isCalibrated = true; |
| 79 |
} |
| 80 |
|
| 81 |
Paint paint = new Color((float) 0.1, (float) 0.1, (float) 0.1, |
| 82 |
(float) (50.0 / lineCount)); |
| 83 |
|
| 84 |
g2.setPaint(paint); |
| 85 |
g2.setStroke(lineStroke); |
| 86 |
|
| 87 |
for (int i = 0; i < lineCount; i++) { |
| 88 |
drawLine(g2, x1, y1[i], x2, y2[i]); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
@Override |
| 96 |
protected void paintData(Graphics2D g2, Variate.N xData, Variate.N yData) { |
| 97 |
|
| 98 |
} |
| 99 |
} |