001: /*
002: JOpenChart Java Charting Library and Toolkit
003: Copyright (C) 2001 Sebastian Müller
004: http://jopenchart.sourceforge.net
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: PlotChartRenderer.java
021: Created on 24. September 2001, 12:39
022: */
023:
024: package de.progra.charting.render;
025:
026: import java.awt.geom.Line2D;
027: import java.awt.geom.Point2D;
028: import java.awt.geom.Ellipse2D;
029: import java.awt.geom.Rectangle2D;
030: import java.awt.geom.Area;
031: import de.progra.charting.CoordSystem;
032: import java.awt.geom.AffineTransform;
033: import java.awt.geom.RectangularShape;
034: import de.progra.charting.PointToPixelTranslator;
035: import java.awt.Graphics2D;
036: import java.awt.Color;
037: import de.progra.charting.model.ChartDataModel;
038:
039: /**
040: * This renderer creates a PlotChart.
041: * @author mueller
042: * @version 1.0
043: */
044: public class PlotChartRenderer extends AbstractChartRenderer {
045:
046: protected double shapeSize = 10.0;
047:
048: /** Creates new PlotChartRenderer
049: * @param rcm the RowColorModel needed to determine the right colors
050: * @param cs the CoordSystem used to translate values into points
051: * @param model the DataModel that should be rendered
052: */
053: public PlotChartRenderer(CoordSystem cs, ChartDataModel model) {
054: super (cs, model);
055: }
056:
057: /** Finally renders the Object in the Graphics object.
058: * @param g the Graphics2D object in which to render
059: */
060: public void renderChart(Graphics2D g) {
061: ChartDataModel m = getChartDataModel();
062: RowColorModel rcm = getRowColorModel();
063: AffineTransform yaxis1 = getTransform(CoordSystem.FIRST_YAXIS);
064:
065: int datasetcount = m.getDataSetNumber();
066: Point2D val;
067: Point2D paint = new Point2D.Float(0f, 0f);
068: boolean numericalcolumns = m.isColumnNumeric();
069:
070: float modelVal = 0f;
071:
072: RectangularShape shape;
073:
074: for (int set = 0; set < datasetcount; set++) {
075: for (int value = 0; value < m.getDataSetLength(set); value++) {
076: modelVal = m.getValueAt(set, value).floatValue();
077:
078: // Catch modelVal == Not A Number
079: if (modelVal != modelVal)
080: continue;
081:
082: if (numericalcolumns)
083: val = new Point2D.Float(
084: ((Number) m.getColumnValueAt(set, value))
085: .floatValue(), modelVal);
086: else
087: val = new Point2D.Float((float) value, modelVal);
088:
089: yaxis1.transform(val, paint);
090: if (paint == null)
091: continue;
092:
093: g.setColor(rcm.getColor(set));
094:
095: shape = rcm.getShape(set);
096: shape.setFrame(paint.getX() - shapeSize / 2, paint
097: .getY()
098: - shapeSize / 2, shapeSize, shapeSize);
099:
100: g.fill(shape);
101: }
102: }
103: }
104: }
|