Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * LinePlot.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: A line plot.
36 *
37 * @author Andrew Rambaut
38 * @author Alexei Drummond
39 * @version $Id: LinePlot.java,v 1.8 2005/05/24 20:25:59 rambaut Exp $
40 */
41
42 public class LinePlot extends Plot.AbstractPlot {
43
44
45 /**
46 * Constructor
47 */
48 public LinePlot(Variate.N xData, Variate.N yData) {
49 super(xData, yData);
50 }
51
52 /**
53 * Constructor
54 */
55 public LinePlot(List<Double> xData, List<Double> yData) {
56 super(xData, yData);
57 }
58
59 /**
60 * Paint data series
61 */
62 protected void paintData(Graphics2D g2, Variate.N xData, Variate.N yData) {
63
64 double x = transformX(((Number) xData.get(0)).doubleValue());
65 double y = transformY(((Number) yData.get(0)).doubleValue());
66
67 GeneralPath path = new GeneralPath();
68 path.moveTo((float) x, (float) y);
69
70 int n = xData.getCount();
71 boolean failed = false;
72 for (int i = 1; i < n; i++) {
73 x = transformX(((Number) xData.get(i)).doubleValue());
74 y = transformY(((Number) yData.get(i)).doubleValue());
75 if (x == Double.NEGATIVE_INFINITY || y == Double.NEGATIVE_INFINITY ||
76 Double.isNaN(x) || Double.isNaN(y)) {
77 failed = true;
78 } else if (failed) {
79 failed = false;
80 path.moveTo((float) x, (float) y);
81 } else {
82 path.lineTo((float) x, (float) y);
83 }
84 }
85
86 g2.setPaint(linePaint);
87 g2.setStroke(lineStroke);
88
89 g2.draw(path);
90 }
91
92 }
93