Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * AreaPlot.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 import java.awt.geom.GeneralPath;
32 import java.util.List;
33
34 /**
35 * Description: An area plot.
36 *
37 * @author Andrew Rambaut
38 * @author Alexei Drummond
39 * @version $Id: AreaPlot.java,v 1.4 2005/05/24 20:25:59 rambaut Exp $
40 */
41
42 public class AreaPlot extends Plot.AbstractPlot {
43
44 protected Variate.N xData2 = null;
45 protected Variate.N yData2 = null;
46
47 /**
48 * Constructor
49 */
50 public AreaPlot(Variate.N xData, Variate.N yData) {
51 super(xData, yData);
52 }
53
54 /**
55 * Constructor
56 */
57 public AreaPlot(List<Double> xData, List<Double> yData) {
58 super(xData, yData);
59 }
60
61 /**
62 * Constructor
63 */
64 public AreaPlot(Variate.N xData1, Variate.N yData1, Variate.N xData2, Variate.N yData2) {
65 super(xData1, yData1);
66 this.xData2 = xData2;
67 this.yData2 = yData2;
68 }
69
70 /**
71 * Constructor
72 */
73 public AreaPlot(List<Double> xData1, List<Double> yData1, List<Double> xData2, List<Double> yData2) {
74 super(xData1, yData1);
75 this.xData2 = new Variate.D(xData2);
76 this.yData2 = new Variate.D(yData2);
77 }
78
79 /**
80 * Set data
81 */
82 public void setData(List<Double> xData1, List<Double> yData1, List<Double> xData2, List<Double> yData2) {
83 setData(xData1, yData1);
84 this.xData2 = new Variate.D(xData2);
85 this.yData2 = new Variate.D(yData2);
86 }
87
88 /**
89 * Set data
90 */
91 public void setData(Variate.N xData1, Variate.N yData1, Variate.N xData2, Variate.N yData2) {
92 setData(xData1, yData1);
93 this.xData2 = xData2;
94 this.yData2 = yData2;
95 }
96
97 /**
98 * Set axes
99 */
100 public void setAxes(Axis xAxis, Axis yAxis) {
101 super.setAxes(xAxis, yAxis);
102
103 if (xData2 != null && yData2 != null) {
104 setupAxis(xAxis, yAxis, xData2, yData2);
105 }
106 }
107
108 /**
109 * Resets axis ranges (if new data has been added)
110 */
111 public void resetAxes() {
112 super.resetAxes();
113
114 if (xData2 != null && yData2 != null) {
115 setupAxis(xAxis, yAxis, xData2, yData2);
116 }
117 }
118
119 /**
120 * Paint data series
121 */
122 protected void paintData(Graphics2D g2, Variate.N xData, Variate.N yData) {
123
124 double x0 = transformX(((Number) xData.get(0)).doubleValue());
125 double y0 = transformY(((Number) yData.get(0)).doubleValue());
126
127 GeneralPath path = new GeneralPath();
128 path.moveTo((float) x0, (float) y0);
129
130 double x = x0;
131 double y = y0;
132
133 for (int i = 1, n = xData.getCount(); i < n; i++) {
134 x = transformX(((Number) xData.get(i)).doubleValue());
135 y = transformY(((Number) yData.get(i)).doubleValue());
136 path.lineTo((float) x, (float) y);
137 }
138
139 if (xData2 != null & yData2 != null) {
140 for (int i = xData2.getCount() - 1; i >= 0; i--) {
141 x = transformX(((Number) xData2.get(i)).doubleValue());
142 y = transformY(((Number) yData2.get(i)).doubleValue());
143 path.lineTo((float) x, (float) y);
144 }
145
146 } else {
147 double y1 = transformY(0.0);
148 path.lineTo((float) x, (float) y1);
149 path.lineTo((float) x0, (float) y1);
150 path.lineTo((float) x0, (float) y0);
151 }
152
153 path.closePath();
154
155 g2.setPaint(linePaint);
156 g2.setStroke(lineStroke);
157
158 g2.fill(path);
159 }
160
161 }
162