Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * ErrorBarPlot.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 error bar plot (to be put under a scatter plot).
36 *
37 * @author Andrew Rambaut
38 * @version $Id: LinePlot.java,v 1.8 2005/05/24 20:25:59 rambaut Exp $
39 */
40
41 public class ErrorBarPlot extends Plot.AbstractPlot {
42 public enum Orientation {
43 HORIZONTAL,
44 VERTICAL
45 }
46
47 /**
48 * Constructor
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 * Constructor
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 * Paint data series
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