?? stackedbarrenderer.java
字號:
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* -----------------------
* StackedBarRenderer.java
* -----------------------
* (C) Copyright 2000-2003, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): Richard Atkinson;
* Thierry Saura;
* Christian W. Zuckschwerdt;
*
* $Id: StackedBarRenderer.java,v 1.16 2003/09/08 10:14:30 mungady Exp $
*
* Changes
* -------
* 19-Oct-2001 : Version 1 (DG);
* 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG);
* 23-Oct-2001 : Changed intro and trail gaps on bar plots to use percentage of available space
* rather than a fixed number of units (DG);
* 15-Nov-2001 : Modified to allow for null data values (DG);
* 22-Nov-2001 : Modified to allow for negative data values (DG);
* 13-Dec-2001 : Added tooltips (DG);
* 16-Jan-2002 : Fixed bug for single category datasets (DG);
* 15-Feb-2002 : Added isStacked() method (DG);
* 14-Mar-2002 : Modified to implement the CategoryItemRenderer interface (DG);
* 24-May-2002 : Incorporated tooltips into chart entities (DG);
* 11-Jun-2002 : Added check for (permitted) null info object, bug and fix reported by David
* Basten. Also updated Javadocs. (DG);
* 25-Jun-2002 : Removed redundant import (DG);
* 26-Jun-2002 : Small change to entity (DG);
* 05-Aug-2002 : Small modification to drawCategoryItem method to support URLs for HTML image
* maps (RA);
* 08-Aug-2002 : Added optional linking lines, contributed by Thierry Saura (DG);
* 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
* 24-Oct-2002 : Amendments for changes in CategoryDataset interface and CategoryToolTipGenerator
* interface (DG);
* 05-Nov-2002 : Replaced references to CategoryDataset with TableDataset (DG);
* 26-Nov-2002 : Replaced isStacked() method with getRangeType() method (DG);
* 17-Jan-2003 : Moved plot classes to a separate package (DG);
* 25-Mar-2003 : Implemented Serializable (DG);
* 12-May-2003 : Merged horizontal and vertical stacked bar renderers (DG);
* 30-Jul-2003 : Modified entity constructor (CZ);
* 08-Sep-2003 : Fixed bug 799668 (isBarOutlineDrawn() ignored) (DG);
*
*/
package org.jfree.chart.renderer;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.CategoryItemEntity;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.labels.CategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.CategoryDataset;
import org.jfree.ui.RectangleEdge;
import org.jfree.util.PublicCloneable;
/**
* A stacked bar renderer for use with the {@link org.jfree.chart.plot.CategoryPlot} class.
*
* @author David Gilbert
*/
public class StackedBarRenderer extends BarRenderer
implements Cloneable, PublicCloneable, Serializable {
/** Linking lines flag. */
private boolean linkingLines = false;
/** Points set register. */
private transient double[] pointsRegister = null;
/**
* Creates a new renderer with no tool tip generator and no URL generator.
* <P>
* The defaults (no tool tip or URL generators) have been chosen to minimise the processing
* required to generate a default chart. If you require tool tips or URLs, then you can
* easily add the required generators.
*/
public StackedBarRenderer() {
super();
}
/**
* Returns the range type.
*
* @return the range type.
*/
public RangeType getRangeType() {
return RangeType.STACKED;
}
/**
* Returns a flag to indicate whether or not there are lines between the items.
*
* @return boolean
*/
public boolean hasLinkingLines() {
return this.linkingLines;
}
/**
* Sets or unsets the linking lines between items.
*
* @param status boolean linking lines if true.
*/
public void setLinkingLines(boolean status) {
this.linkingLines = status;
}
/**
* Initialises the renderer.
* <p>
* This method gets called once at the start of the process of drawing a chart.
*
* @param g2 the graphics device.
* @param dataArea the data area.
* @param plot the plot.
* @param index the renderer index (<code>null</code> for the primary renderer).
* @param info optional information collection.
*/
public void initialise(Graphics2D g2,
Rectangle2D dataArea,
CategoryPlot plot,
Integer index,
ChartRenderingInfo info) {
super.initialise(g2, dataArea, plot, index, info);
// calculate the bar width
CategoryAxis domainAxis = getDomainAxis(plot, index);
CategoryDataset data = getDataset(plot, index);
if (data != null) {
PlotOrientation orientation = plot.getOrientation();
double space = 0.0;
if (orientation == PlotOrientation.HORIZONTAL) {
space = dataArea.getHeight();
}
else if (orientation == PlotOrientation.VERTICAL) {
space = dataArea.getWidth();
}
int columns = data.getColumnCount();
double categoryMargin = 0.0;
if (columns > 1) {
categoryMargin = domainAxis.getCategoryMargin();
}
double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin()
- categoryMargin);
if (columns > 0) {
setBarWidth(used / columns);
}
else {
setBarWidth(used);
}
}
}
/**
* Draws a stacked bar for a specific item.
*
* @param g2 the graphics device.
* @param dataArea the plot area.
* @param plot the plot.
* @param domainAxis the domain (category) axis.
* @param rangeAxis the range (value) axis.
* @param data the data.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
public void drawItem(Graphics2D g2,
Rectangle2D dataArea,
CategoryPlot plot,
CategoryAxis domainAxis,
ValueAxis rangeAxis,
CategoryDataset data,
int row,
int column) {
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
drawHorizontalItem(g2, dataArea,
plot, domainAxis, rangeAxis, data, row, column);
}
else if (orientation == PlotOrientation.VERTICAL) {
drawVerticalItem(g2, dataArea,
plot, domainAxis, rangeAxis, data, row, column);
}
}
/**
* Draws a stacked bar for a specific item.
*
* @param g2 the graphics device.
* @param dataArea the plot area.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the data.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
public void drawHorizontalItem(Graphics2D g2,
Rectangle2D dataArea,
CategoryPlot plot,
CategoryAxis domainAxis,
ValueAxis rangeAxis,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -