⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultcontourdataset.java

📁 提供JFreechart图表功能, 提供JFreechart图表功能,提供JFreechart图表功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2007, 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.]
 *
 * --------------------------
 * DefaultContourDataset.java
 * --------------------------
 * (C) Copyright 2002-2007, by David M. O'Donnell and Contributors.
 *
 * Original Author:  David M. O'Donnell;
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *
 * Changes (from 23-Jan-2003)
 * --------------------------
 * 23-Jan-2003 : Added standard header (DG);
 * 20-May-2003 : removed member vars numX and numY, which were never used (TM);
 * 06-May-2004 : Now extends AbstractXYZDataset (DG);
 * 15-Jul-2004 : Switched getX() with getXValue(), getY() with getYValue() and 
 *               getZ() with getZValue() methods (DG);
 * ------------- JFREECHART 1.0.x --------------------------------------------
 * 31-Jan-2007 : Deprecated (DG);
 * 
 */

package org.jfree.data.contour;

import java.util.Arrays;
import java.util.Date;
import java.util.Vector;

import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYBlockRenderer;
import org.jfree.data.Range;
import org.jfree.data.xy.AbstractXYZDataset;
import org.jfree.data.xy.XYDataset;

/**
 * A convenience class that provides a default implementation of the 
 * {@link ContourDataset} interface.
 * 
 * @deprecated This class is no longer supported (as of version 1.0.4).  If 
 *     you are creating contour plots, please try to use {@link XYPlot} and 
 *     {@link XYBlockRenderer}.
 */
public class DefaultContourDataset extends AbstractXYZDataset 
                                   implements ContourDataset {

    /** The series name (this dataset supports only one series). */
    protected Comparable seriesKey = null;

    /** Storage for the x values. */
    protected Number[] xValues = null;

    /** Storage for the y values. */
    protected Number[] yValues = null;

    /** Storage for the z values. */
    protected Number[] zValues = null;

    /** The index for the start of each column in the data. */
    protected int[] xIndex = null;

    /** Flags that track whether x, y and z are dates. */
    boolean[] dateAxis = new boolean[3];

    /**
     * Creates a new dataset, initially empty.
     */
    public DefaultContourDataset() {
        super();
    }

    /**
     * Constructs a new dataset with the given data.
     *
     * @param seriesKey  the series key.
     * @param xData  the x values.
     * @param yData  the y values.
     * @param zData  the z values.
     */
    public DefaultContourDataset(Comparable seriesKey,
                                 Object[] xData,
                                 Object[] yData,
                                 Object[] zData) {

        this.seriesKey = seriesKey;
        initialize(xData, yData, zData);
    }

    /**
     * Initialises the dataset.
     * 
     * @param xData  the x values.
     * @param yData  the y values.
     * @param zData  the z values.
     */
    public void initialize(Object[] xData,
                           Object[] yData,
                           Object[] zData) {

        this.xValues = new Double[xData.length];
        this.yValues = new Double[yData.length];
        this.zValues = new Double[zData.length];

        // We organise the data with the following assumption:
        // 1) the data are sorted by x then y
        // 2) that the data will be represented by a rectangle formed by
        //    using x[i+1], x, y[j+1], and y.
        // 3) we march along the y-axis at the same value of x until a new 
        //    value x is found at which point we will flag the index 
        //    where x[i+1]<>x[i]

        Vector tmpVector = new Vector(); //create a temporary vector
        double x = 1.123452e31; // set x to some arbitary value (used below)
        for (int k = 0; k < this.xValues.length; k++) {
            if (xData[k] != null) {
                Number xNumber;
                if (xData[k] instanceof Number) {
                    xNumber = (Number) xData[k];
                }
                else if (xData[k] instanceof Date) {
                    this.dateAxis[0] = true;
                    Date xDate = (Date) xData[k];
                    xNumber = new Long(xDate.getTime()); //store data as Long
                }
                else {
                    xNumber = new Integer(0);
                }
                this.xValues[k] = new Double(xNumber.doubleValue()); 
                    // store Number as Double

                // check if starting new column
                if (x != this.xValues[k].doubleValue()) {
                    tmpVector.add(new Integer(k)); //store index where new 
                                                   //column starts
                    x = this.xValues[k].doubleValue(); 
                                             // set x to most recent value
                }
            }
        }

        Object[] inttmp = tmpVector.toArray();
        this.xIndex = new int[inttmp.length];  // create array xIndex to hold 
                                               // new column indices

        for (int i = 0; i < inttmp.length; i++) {
            this.xIndex[i] = ((Integer) inttmp[i]).intValue();
        }
        for (int k = 0; k < this.yValues.length; k++) { // store y and z axes 
                                                        // as Doubles
            this.yValues[k] = (Double) yData[k];
            if (zData[k] != null) {
                this.zValues[k] = (Double) zData[k];
            }
        }
    }

    /**
     * Creates an object array from an array of doubles.
     *
     * @param data  the data.
     *
     * @return An array of <code>Double</code> objects.
     */
    public static Object[][] formObjectArray(double[][] data) {
        Object[][] object = new Double[data.length][data[0].length];

        for (int i = 0; i < object.length; i++) {
            for (int j = 0; j < object[i].length; j++) {
                object[i][j] = new Double(data[i][j]);
            }
        }
        return object;
    }

    /**
     * Creates an object array from an array of doubles.
     *
     * @param data  the data.
     *
     * @return An array of <code>Double</code> objects.
     */
    public static Object[] formObjectArray(double[] data) {
        Object[] object = new Double[data.length];
        for (int i = 0; i < object.length; i++) {
            object[i] = new Double(data[i]);
        }
        return object;
    }

    /**
     * Returns the number of items in the specified series.  This method 
     * is provided to satisfy the {@link XYDataset} interface implementation.
     *
     * @param series  must be zero, as this dataset only supports one series.
     *
     * @return The item count.
     */
    public int getItemCount(int series) {
        if (series > 0) {
            throw new IllegalArgumentException("Only one series for contour");
        }
        return this.zValues.length;
    }

    /**
     * Returns the maximum z-value.
     *
     * @return The maximum z-value.
     */
    public double getMaxZValue() {
        double zMax = -1.e20;
        for (int k = 0; k < this.zValues.length; k++) {
            if (this.zValues[k] != null) {
                zMax = Math.max(zMax, this.zValues[k].doubleValue());
            }
        }
        return zMax;
    }

    /**
     * Returns the minimum z-value.
     *
     * @return The minimum z-value.
     */
    public double getMinZValue() {
        double zMin = 1.e20;
        for (int k = 0; k < this.zValues.length; k++) {
            if (this.zValues[k] != null) {
                zMin = Math.min(zMin, this.zValues[k].doubleValue());
            }
        }
        return zMin;
    }

    /**
     * Returns the maximum z-value within visible region of plot.
     *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -