KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > progra > charting > render > LineChartRenderer


1 /*
2     JOpenChart Java Charting Library and Toolkit
3     Copyright (C) 2001 Sebastian Müller
4     http://jopenchart.sourceforge.net
5
6     This library is free software; you can redistribute it and/or
7     modify it under the terms of the GNU Lesser General Public
8     License as published by the Free Software Foundation; either
9     version 2.1 of the License, or (at your option) any later version.
10
11     This library is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14     Lesser General Public License for more details.
15
16     You should have received a copy of the GNU Lesser General Public
17     License along with this library; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20     LineChartRenderer.java
21     Created on 6. September, 19:19
22 */

23
24 package de.progra.charting.render;
25
26 import java.awt.geom.Line2D JavaDoc;
27 import java.awt.geom.Point2D JavaDoc;
28 import java.awt.geom.Area JavaDoc;
29 import de.progra.charting.CoordSystem;
30 import java.awt.geom.AffineTransform JavaDoc;
31 import de.progra.charting.PointToPixelTranslator;
32 import java.awt.Graphics2D JavaDoc;
33 import java.awt.Color JavaDoc;
34 import de.progra.charting.model.ChartDataModel;
35
36 /**
37  * This renderer creates a LineChart.
38  * @author mueller
39  * @version 1.0
40  */

41 public class LineChartRenderer extends AbstractChartRenderer {
42
43     /** Creates new LineChartRenderer
44      * @param rcm the RowColorModel needed to determine the right colors
45      * @param cs the CoordSystem used to translate values into points
46      * @param model the DataModel that should be rendered
47      */

48     public LineChartRenderer(CoordSystem cs, ChartDataModel model) {
49         super(cs, model);
50     }
51     
52     /** Finally renders the Object in the Graphics object.
53      * @param g the Graphics2D object in which to render
54      */

55     public void renderChart(Graphics2D JavaDoc g) {
56         ChartDataModel m = getChartDataModel();
57         RowColorModel rcm = getRowColorModel();
58         AffineTransform JavaDoc yaxis1 = getTransform(CoordSystem.FIRST_YAXIS);
59         
60         int datasetcount = m.getDataSetNumber();
61         Point2D JavaDoc val;
62         Point2D JavaDoc paint = null;
63         Point2D JavaDoc oldpaint = null;
64         boolean numericalcolumns = m.isColumnNumeric();
65         float modelVal = 0f;
66         //System.out.println("** Render LineChart.-");
67
for(int set = 0; set < datasetcount; set++) {
68             for(int value = 0; value < m.getDataSetLength(set); value++) {
69                 modelVal = m.getValueAt(set, value).floatValue();
70                 
71                 if(modelVal != modelVal || modelVal == Float.NEGATIVE_INFINITY || modelVal == Float.POSITIVE_INFINITY) {
72                     //System.out.print(".");
73
oldpaint = null;
74                     continue;
75                 }
76                 
77                 if(numericalcolumns)
78                     val = new Point2D.Float JavaDoc(((Number JavaDoc)m.getColumnValueAt(set, value)).floatValue(),
79                                             modelVal);
80                 else
81                     val = new Point2D.Float JavaDoc((float)value,
82                                             modelVal);
83
84                 //System.out.println("** Rendered "+val);
85
oldpaint = paint;
86                 
87                 if(yaxis1.transform(val, null) != null) {
88                     paint = yaxis1.transform(val, null);
89                     //System.out.println("** val = "+val+" paint = "+paint);
90
}
91                 else
92                     continue;
93
94                 g.setColor(rcm.getColor(set));
95
96                 if(oldpaint != null) {
97                     g.drawLine((int)oldpaint.getX(), (int)oldpaint.getY(),
98                                (int)paint.getX(), (int)paint.getY());
99                 }
100             }
101             oldpaint = null;
102             paint = null;
103         }
104    }
105 }
106
Popular Tags