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

📄 dataset.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package graph;import java.awt.*;import java.applet.*;import java.util.*;import java.lang.*;/*******************************************************************************    Class  DataSet******************************************************************************    Copyright (C) 1995, 1996 Leigh Brookshaw****    This program is free software; you can redistribute it and/or modify**    it under the terms of the GNU General Public License as published by**    the Free Software Foundation; either version 2 of the License, or**    (at your option) any later version.****    This program 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 General Public License for more details.****    You should have received a copy of the GNU General Public License**    along with this program; if not, write to the Free Software**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.******************************************************************************    This class is designed to be used in conjunction with **    the Graph2D class and Axis class for plotting 2D graphs.***************************************************************************//** *  This class is designed to hold the data to be plotted. *  It is to be used in conjunction with the Graph2D class and Axis  *  class for plotting 2D graphs. * * @version $Revision: 1.15 $, $Date: 1996/09/24 05:23:41 $ * @author Leigh Brookshaw  */public class DataSet extends Object {/****************************** Public Static Values     **************************//** *    A constant value flag used to specify no straight line segment *    is to join the data points */      public final static int NOLINE    =  0;/** *    A constant value flag used to specify that a straight line segment *    is to join the data points. */      public final static int LINE      =  1;/************************** Public Variables      **********************/  /**    *    The Graphics canvas that is driving the whole show.   * @see graph.Graph2D   */      public Graph2D g2d;  /**   *    The linestyle to employ when joining the data points with   *    straight line segments. Currently only solid and no line   *    are supported.   */      public int   linestyle     = LINE;  /**   *    The color of the straight line segments   */      public Color linecolor     = null;  /**   *    The index of the marker to use at the data points.   * @see graph.Markers   */      public int    marker       = 0;  /**   *    The marker color   */      public Color  markercolor  = null;  /**   *    The scaling factor for the marker. Default value is 1.   */      public double markerscale  = 1.0;  /**   *    The Axis object the X data is attached to. From the Axis object   *    the scaling for the data can be derived.   * @see graph.Axis   */      public Axis xaxis;  /**   *    The Axis object the Y data is attached to.   * @see graph.Axis   */      public Axis yaxis;  /**   * The current plottable X maximum of the data.    * This can be very different from   * true data X maximum. The data is clipped when plotted.   */      public double xmax;   /**   * The current plottable X minimum of the data.    * This can be very different from   * true data X minimum. The data is clipped when plotted.   */      public double xmin;  /**   * The current plottable Y maximum of the data.    * This can be very different from   * true data Y maximum. The data is clipped when plotted.   */      public double ymax;   /**   * The current plottable Y minimum of the data.    * This can be very different from   * true data Y minimum. The data is clipped when plotted.   */      public double ymin;  /**   * Boolean to control clipping of the data window.   * Default value is <em>true</em>, clip the data window.   */      public boolean clipping = true;/************************ Protected Variables      **********************/  /**   * The data X maximum.    * Once the data is loaded this will never change.   */      protected double dxmax;  /**   * The data X minimum.    * Once the data is loaded this will never change.   */      protected double dxmin;  /**   * The data Y maximum.    * Once the data is loaded this will never change.   */      protected double dymax;  /**   * The data Y minimum.    * Once the data is loaded this will never change.   */      protected double dymin;  /**   * The array containing the actual data    */      protected double data[];  /**   * The number of data points stored in the data array   */      protected int length;  /**   *    The X range of the clipped data   */      protected double xrange;  /**   *    The Y range of the clipped data   */      protected double yrange;  /**   *    The length of the example line in the data legend.   */      protected int legend_length = 20;  /**   *    The legend text   */      protected TextLine legend_text = null;  /**   * The X pixel position of the data legend   */      protected int legend_ix;  /**   * The Y pixel position of the data legend   */      protected int legend_iy;  /**   * The X data position of the data legend   */      protected double legend_dx;  /**   * The Y data position of the data legend   */      protected double legend_dy;  /**   *    The amount to increment the data array when the append method is being   *    used.   */      protected int increment = 100;  /**   * The stride of the data. For data pairs (x,y) the stride is 2   */    protected int stride = 2;/************************ Constructors********************/  /**   *  Instantiate an empty data set.   */      public DataSet ( ) {               length = 0;               range(stride);      }  /**   *  Instantiate an empty data set.   *  @param stride the stride of the data set. The default stride is 2.   */      public DataSet (int stride ) throws Exception {               if( stride < 2 ) throw                           new Exception("Invalid stride parameter!");               this.stride = stride;               length = 0;               range(stride);      }  /**   * Instantiate a DataSet with the parsed data. Default stride is 2.   * The double array contains the data. The X data is expected in   * the even indices, the y data in the odd. The integer n is the   * number of data Points. This means that the length of the data   * array is 2*n.   * @param d Array containing the (x,y) data pairs.   * @param n Number of (x,y) data pairs in the array.   * @exception  Exception   *            A Generic exception if it fails to load the   *            parsed array into the class.   */      public DataSet ( double d[], int n ) throws Exception {           int i;           int k = 0;           length = 0;           if ( d  == null || d.length == 0 || n <= 0 ) {              throw new Exception("DataSet: Error in parsed data!");           }//     Copy the data locally.           data = new double[n*stride];           length = n*stride;           System.arraycopy(d, 0, data, 0, length);//     Calculate the data range.           range(stride);      }  /**   * Instantiate a DataSet with the parsed data.   * The double array contains the data. The X data is expected to be in   * indices i*stride where i=0,1,... The Y data is expected to be found   * in indices i*stride+1 where i=0,1,2...   * The integer n is the   * number of data Points. This means that the length of the data   * array is 2*stride.   * @param d Array containing the (x,y) data pairs.   * @param n Number of (x,y) data pairs in the array.   * @param s The stride of the data.   * @exception  Exception   *            A Generic exception if it fails to load the   *            parsed array into the class.   */      public DataSet ( double d[], int n, int s ) throws Exception {          if( s < 2 ) throw                           new Exception("Invalid stride parameter!");           int i;           int k = 0;           length = 0;           if ( d  == null || d.length == 0 || n <= 0 ) {              throw new Exception("DataSet: Error in parsed data!");           }           this.stride = s;//     Copy the data locally.           data = new double[n*stride];           length = n*stride;           System.arraycopy(d, 0, data, 0, length);//     Calculate the data range.           range(stride);      }/********************** Public Methods******************/  /**   * Append data to the data set.   * @param d Array containing (x,y) pairs to append   * @param n Number of (x,y) data pairs in the array.   * @exception Exception   *          A generic exception if it fails to load the   *            parsed array into the class.   */      public void append( double d[], int n ) throws Exception {           int i;           int k = 0;           double tmp[];           int ln = n*stride;           if ( d  == null || d.length == 0 || n <= 0 ) {              throw new Exception("DataSet: Error in append data!");           }           if(data == null) data = new double[increment];//     Copy the data locally.           if( ln+length < data.length ) {               System.arraycopy(d, 0, data, length, ln);               length += ln;	   } else {               tmp = new double[ln+length+increment];               if( length != 0 ) {                 System.arraycopy(data, 0, tmp, 0, length);               }               System.arraycopy(d, 0, tmp, length, ln);               length += ln;               data = tmp;	     }//     Calculate the data range.           range(stride);//     Update the range on Axis that this data is attached to           if(xaxis != null) xaxis.resetRange();           if(yaxis != null) yaxis.resetRange();      }  /**   * Delete data from the data set (start and end are inclusive).   * The first (x,y) pair in the data set start at index 0.   * @param start The start (x,y) pair index.   * @param end   The end (x,y) pair index.   */      public void  delete( int start, int end ) {           int End   = stride*end;           int Start = stride*start;           if(length <= 0) return;           if( End   < Start )         return;           if( Start < 0 )             Start = 0;           if( End > length-stride )        End = length-stride;           if( End < length-stride) {               System.arraycopy(data, End+stride,                                 data, Start, length - End - stride);	     }           length -= End+stride-Start;//     Calculate the data range.           range(stride);      }  /**   * Delete all the data from the data set.   */      public void  deleteData( ) {           length = 0;           data = null;           range(stride);      }  /**   * Draw the straight line segments and/or the markers at the   * data points.   * If this data has been attached to an Axis then scale the data   * based on the axis maximum/minimum otherwise scale using   * the data's maximum/minimum   * @param g Graphics state   * @param bounds The data window to draw into

⌨️ 快捷键说明

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