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: LineChartRenderer.java
021: Created on 6. September, 19:19
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.Area;
029: import de.progra.charting.CoordSystem;
030: import java.awt.geom.AffineTransform;
031: import de.progra.charting.PointToPixelTranslator;
032: import java.awt.Graphics2D;
033: import java.awt.Color;
034: import de.progra.charting.model.ChartDataModel;
035:
036: /**
037: * This renderer creates a LineChart.
038: * @author mueller
039: * @version 1.0
040: */
041: public class LineChartRenderer extends AbstractChartRenderer {
042:
043: /** Creates new LineChartRenderer
044: * @param rcm the RowColorModel needed to determine the right colors
045: * @param cs the CoordSystem used to translate values into points
046: * @param model the DataModel that should be rendered
047: */
048: public LineChartRenderer(CoordSystem cs, ChartDataModel model) {
049: super (cs, model);
050: }
051:
052: /** Finally renders the Object in the Graphics object.
053: * @param g the Graphics2D object in which to render
054: */
055: public void renderChart(Graphics2D g) {
056: ChartDataModel m = getChartDataModel();
057: RowColorModel rcm = getRowColorModel();
058: AffineTransform yaxis1 = getTransform(CoordSystem.FIRST_YAXIS);
059:
060: int datasetcount = m.getDataSetNumber();
061: Point2D val;
062: Point2D paint = null;
063: Point2D oldpaint = null;
064: boolean numericalcolumns = m.isColumnNumeric();
065: float modelVal = 0f;
066: //System.out.println("** Render LineChart.-");
067: for (int set = 0; set < datasetcount; set++) {
068: for (int value = 0; value < m.getDataSetLength(set); value++) {
069: modelVal = m.getValueAt(set, value).floatValue();
070:
071: if (modelVal != modelVal
072: || modelVal == Float.NEGATIVE_INFINITY
073: || modelVal == Float.POSITIVE_INFINITY) {
074: //System.out.print(".");
075: oldpaint = null;
076: continue;
077: }
078:
079: if (numericalcolumns)
080: val = new Point2D.Float(
081: ((Number) m.getColumnValueAt(set, value))
082: .floatValue(), modelVal);
083: else
084: val = new Point2D.Float((float) value, modelVal);
085:
086: //System.out.println("** Rendered "+val);
087: oldpaint = paint;
088:
089: if (yaxis1.transform(val, null) != null) {
090: paint = yaxis1.transform(val, null);
091: //System.out.println("** val = "+val+" paint = "+paint);
092: } else
093: continue;
094:
095: g.setColor(rcm.getColor(set));
096:
097: if (oldpaint != null) {
098: g.drawLine((int) oldpaint.getX(), (int) oldpaint
099: .getY(), (int) paint.getX(), (int) paint
100: .getY());
101: }
102: }
103: oldpaint = null;
104: paint = null;
105: }
106: }
107: }
|