Debian Codegraph @

src/dr/app/gui/chart/LineDistributionPlot.java

raw symbols SCIP
1 /*
2 * LineDistributionPlot.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * Constructor
46 */
47 public LineDistributionPlot(Variate gradients, Variate intercepts) {
48 this.gradients = gradients;
49 this.intercepts = intercepts;
50 }
51
52 /**
53 * Paint actual plot
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 * Paint data series
94 */
95 @Override
96 protected void paintData(Graphics2D g2, Variate.N xData, Variate.N yData) {
97 // do nothing because paintPlot is overridden
98 }
99 }