KickJava   Java API By Example, From Geeks To Geeks.

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


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     PlotChartRenderer.java
21     Created on 24. September 2001, 12:39
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.Ellipse2D JavaDoc;
29 import java.awt.geom.Rectangle2D JavaDoc;
30 import java.awt.geom.Area JavaDoc;
31 import de.progra.charting.CoordSystem;
32 import java.awt.geom.AffineTransform JavaDoc;
33 import java.awt.geom.RectangularShape JavaDoc;
34 import de.progra.charting.PointToPixelTranslator;
35 import java.awt.Graphics2D JavaDoc;
36 import java.awt.Color JavaDoc;
37 import de.progra.charting.model.ChartDataModel;
38
39 /**
40  * This renderer creates a PlotChart.
41  * @author mueller
42  * @version 1.0
43  */

44 public class PlotChartRenderer extends AbstractChartRenderer {
45     
46     protected double shapeSize = 10.0;
47     
48     /** Creates new PlotChartRenderer
49      * @param rcm the RowColorModel needed to determine the right colors
50      * @param cs the CoordSystem used to translate values into points
51      * @param model the DataModel that should be rendered
52      */

53     public PlotChartRenderer(CoordSystem cs, ChartDataModel model) {
54         super(cs, model);
55     }
56
57     /** Finally renders the Object in the Graphics object.
58      * @param g the Graphics2D object in which to render
59      */

60     public void renderChart(Graphics2D JavaDoc g) {
61         ChartDataModel m = getChartDataModel();
62         RowColorModel rcm = getRowColorModel();
63         AffineTransform JavaDoc yaxis1 = getTransform(CoordSystem.FIRST_YAXIS);
64         
65         int datasetcount = m.getDataSetNumber();
66         Point2D JavaDoc val;
67         Point2D JavaDoc paint = new Point2D.Float JavaDoc(0f, 0f);
68         boolean numericalcolumns = m.isColumnNumeric();
69   
70         float modelVal = 0f;
71         
72         RectangularShape JavaDoc shape;
73         
74         for(int set = 0; set < datasetcount; set++) {
75             for(int value = 0; value < m.getDataSetLength(set); value++) {
76                 modelVal = m.getValueAt(set, value).floatValue();
77                 
78                 // Catch modelVal == Not A Number
79
if(modelVal != modelVal)
80                     continue;
81                 
82                 if(numericalcolumns)
83                     val = new Point2D.Float JavaDoc(((Number JavaDoc)m.getColumnValueAt(set, value)).floatValue(),
84                                             modelVal);
85                 else
86                     val = new Point2D.Float JavaDoc((float)value,
87                                             modelVal);
88                     
89                 
90                 yaxis1.transform(val, paint);
91                 if(paint == null)
92                     continue;
93                 
94                 g.setColor(rcm.getColor(set));
95                 
96                 shape = rcm.getShape(set);
97                 shape.setFrame(paint.getX() - shapeSize/2, paint.getY() - shapeSize/2, shapeSize, shapeSize);
98                 
99                 g.fill(shape);
100             }
101         }
102    }
103 }
Popular Tags