|
jfreechart example source code file (IntervalXYDelegate.java)
The jfreechart IntervalXYDelegate.java source code
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2009, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -----------------------
* IntervalXYDelegate.java
* -----------------------
* (C) Copyright 2004-2009, by Andreas Schroeder and Contributors.
*
* Original Author: Andreas Schroeder;
* Contributor(s): David Gilbert (for Object Refinery Limited);
*
* Changes
* -------
* 31-Mar-2004 : Version 1 (AS);
* 15-Jul-2004 : Switched getX() with getXValue() and getY() with
* getYValue() (DG);
* 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG);
* 04-Nov-2004 : Added argument check for setIntervalWidth() method (DG);
* 17-Nov-2004 : New methods to reflect changes in DomainInfo (DG);
* 11-Jan-2005 : Removed deprecated methods in preparation for the 1.0.0
* release (DG);
* 21-Feb-2005 : Made public and added equals() method (DG);
* 06-Oct-2005 : Implemented DatasetChangeListener to recalculate
* autoIntervalWidth (DG);
* 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
* 06-Mar-2009 : Implemented hashCode() (DG);
*
*/
package org.jfree.data.xy;
import java.io.Serializable;
import org.jfree.chart.HashUtilities;
import org.jfree.data.DomainInfo;
import org.jfree.data.Range;
import org.jfree.data.RangeInfo;
import org.jfree.data.general.DatasetChangeEvent;
import org.jfree.data.general.DatasetChangeListener;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.util.PublicCloneable;
/**
* A delegate that handles the specification or automatic calculation of the
* interval surrounding the x-values in a dataset. This is used to extend
* a regular {@link XYDataset} to support the {@link IntervalXYDataset}
* interface.
* <p>
* The decorator pattern was not used because of the several possibly
* implemented interfaces of the decorated instance (e.g.
* {@link TableXYDataset}, {@link RangeInfo}, {@link DomainInfo} etc.).
* <p>
* The width can be set manually or calculated automatically. The switch
* autoWidth allows to determine which behavior is used. The auto width
* calculation tries to find the smallest gap between two x-values in the
* dataset. If there is only one item in the series, the auto width
* calculation fails and falls back on the manually set interval width (which
* is itself defaulted to 1.0).
*/
public class IntervalXYDelegate implements DatasetChangeListener,
DomainInfo, Serializable, Cloneable, PublicCloneable {
/** For serialization. */
private static final long serialVersionUID = -685166711639592857L;
/**
* The dataset to enhance.
*/
private XYDataset dataset;
/**
* A flag to indicate whether the width should be calculated automatically.
*/
private boolean autoWidth;
/**
* A value between 0.0 and 1.0 that indicates the position of the x-value
* within the interval.
*/
private double intervalPositionFactor;
/**
* The fixed interval width (defaults to 1.0).
*/
private double fixedIntervalWidth;
/**
* The automatically calculated interval width.
*/
private double autoIntervalWidth;
/**
* Creates a new delegate that.
*
* @param dataset the underlying dataset (<code>null not permitted).
*/
public IntervalXYDelegate(XYDataset dataset) {
this(dataset, true);
}
/**
* Creates a new delegate for the specified dataset.
*
* @param dataset the underlying dataset (<code>null not permitted).
* @param autoWidth a flag that controls whether the interval width is
* calculated automatically.
*/
public IntervalXYDelegate(XYDataset dataset, boolean autoWidth) {
if (dataset == null) {
throw new IllegalArgumentException("Null 'dataset' argument.");
}
this.dataset = dataset;
this.autoWidth = autoWidth;
this.intervalPositionFactor = 0.5;
this.autoIntervalWidth = Double.POSITIVE_INFINITY;
this.fixedIntervalWidth = 1.0;
}
/**
* Returns <code>true if the interval width is automatically
* calculated, and <code>false otherwise.
*
* @return A boolean.
*/
public boolean isAutoWidth() {
return this.autoWidth;
}
/**
* Sets the flag that indicates whether the interval width is automatically
* calculated. If the flag is set to <code>true, the interval is
* recalculated.
* <p>
* Note: recalculating the interval amounts to changing the data values
* represented by the dataset. The calling dataset must fire an
* appropriate {@link DatasetChangeEvent}.
*
* @param b a boolean.
*/
public void setAutoWidth(boolean b) {
this.autoWidth = b;
if (b) {
this.autoIntervalWidth = recalculateInterval();
}
}
/**
* Returns the interval position factor.
*
* @return The interval position factor.
*/
public double getIntervalPositionFactor() {
return this.intervalPositionFactor;
}
/**
* Sets the interval position factor. This controls how the interval is
* aligned to the x-value. For a value of 0.5, the interval is aligned
* with the x-value in the center. For a value of 0.0, the interval is
* aligned with the x-value at the lower end of the interval, and for a
* value of 1.0, the interval is aligned with the x-value at the upper
* end of the interval.
* <br>
Other jfreechart examples (source code examples)Here is a short list of links related to this jfreechart IntervalXYDelegate.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.