Class Dataset

All Implemented Interfaces:
Data, Drawable, LogMeasurable, Measurable
Direct Known Subclasses:
DataColumn, DataFunction, HighlightableDataset, HistogramDataset, Stripchart

public class Dataset extends DataTable.DataModel implements Measurable, LogMeasurable, Data
Dataset stores and plots (x,y) points. Dataset is Drawable and can be rendered on a DrawingPanel. Dataset extends AbstractTableModel and can be rendered in a JTable.
Version:
1.0
Author:
Joshua Gould, Wolfgang Christian
  • Field Details

    • model

      public final Dataset.Model model
    • id

      protected static int id
    • datasetID

      protected int datasetID
      Field datasetID: an integer ID that identifies this object
    • columnID

      protected int columnID
      Field columnID: an integer used by DataTool
    • NO_MARKER

      public static final int NO_MARKER
      Field NO_MARKER
      See Also:
    • CIRCLE

      public static final int CIRCLE
      Field CIRCLE
      See Also:
    • SQUARE

      public static final int SQUARE
      Field SQUARE
      See Also:
    • AREA

      public static final int AREA
      Field AREA
      See Also:
    • PIXEL

      public static final int PIXEL
      Field PIXEL
      See Also:
    • BAR

      public static final int BAR
      Field BAR
      See Also:
    • POST

      public static final int POST
      Field POST
      See Also:
    • CUSTOM

      public static final int CUSTOM
      Field POST
      See Also:
    • maxPointsMultiplier

      public static double maxPointsMultiplier
      maxPointsMultiplier: a multiplier for maxPoints
    • xpoints

      protected double[] xpoints
    • ypoints

      protected double[] ypoints
    • shift

      protected double shift
    • generalPath

      protected GeneralPath generalPath
    • xmax

      protected double xmax
    • ymax

      protected double ymax
    • xmin

      protected double xmin
    • ymin

      protected double ymin
    • xmaxLogscale

      protected double xmaxLogscale
    • ymaxLogscale

      protected double ymaxLogscale
    • xminLogscale

      protected double xminLogscale
    • yminLogscale

      protected double yminLogscale
    • index

      protected int index
    • sorted

      protected boolean sorted
    • update

      public int update
    • xColumnDescription

      protected String xColumnDescription
    • yColumnDescription

      protected String yColumnDescription
    • visible

      protected boolean visible
    • maxPoints

      protected int maxPoints
    • errorBars

      protected ArrayList<org.opensourcephysics.display.Dataset.ErrorBar> errorBars
    • customMarker

      protected Shape customMarker
  • Constructor Details

    • Dataset

      public Dataset()
      Dataset constructor.
    • Dataset

      public Dataset(Color _markerColor)
      Dataset constructor specifying the marker color.
      Parameters:
      _markerColor -
    • Dataset

      public Dataset(Color markerColor, Color _lineColor, boolean _connected)
      Dataset constructor specifying the marker color, line color, and whether points are connected.
      Parameters:
      markerColor -
      _lineColor -
      _connected -
  • Method Details

    • set

      public Dataset set(double[] x, double[] y)
    • setID

      public void setID(int id)
      Sets the ID number of this Data.
      Specified by:
      setID in interface Data
      Parameters:
      id - the ID number
    • getID

      public int getID()
      Returns a unique identifier for this Data.
      Specified by:
      getID in interface Data
      Returns:
      the ID number
    • setColumnID

      public void setColumnID(int id)
      Sets the column ID.
      Parameters:
      id - the column ID
    • getColumnID

      public int getColumnID()
      Returns the column ID.
      Returns:
      the column ID
    • setSorted

      public void setSorted(boolean _sorted)
      Sets the sorted flag. Data is sorted by increasing x.
      Parameters:
      _sorted - true<\code> to sort
    • setConnected

      public void setConnected(boolean _connected)
      Sets the data connected flag. Points are connected by straight lines.
      Parameters:
      _connected - true<\code> if points are connected
    • setMarkerColor

      public void setMarkerColor(Color markerColor)
      Sets the data point fill, edge, and error bar colors to the same color.
      Parameters:
      markerColor -
    • setMarkerColor

      public void setMarkerColor(Color _fillColor, Color _edgeColor)
      Sets the data point marker colors. The error bar color is set equal to the edge color.
      Parameters:
      _fillColor -
      _edgeColor -
    • setMarkerColor

      public void setMarkerColor(Color _fillColor, Color _edgeColor, Color _errorBarColor)
      Sets the data point marker colors.
      Parameters:
      _fillColor -
      _edgeColor -
      _errorBarColor -
    • getFillColor

      public Color getFillColor()
      Gets the data point fill color.
      Returns:
      the fill color
    • getFillColors

      public Color[] getFillColors()
      Fill colors for Data interface.
      Specified by:
      getFillColors in interface Data
      Returns:
      color array
    • getEdgeColor

      public Color getEdgeColor()
      Gets the data point edge color.
      Returns:
      the edge color
    • getLineColor

      public Color getLineColor()
      Gets the line color.
      Returns:
      the line color
    • getLineColors

      public Color[] getLineColors()
      Line colors for Data interface.
      Specified by:
      getLineColors in interface Data
      Returns:
      color array
    • setCustomMarker

      public void setCustomMarker(Shape marker)
      Sets a custom marker shape.
      Parameters:
      marker - Shape
    • setMarkerShape

      public void setMarkerShape(int _markerShape)
      Sets the data point marker shape. Shapes are: NO_MARKER, CIRCLE, SQUARE, AREA, PIXEL, BAR, POST
      Parameters:
      _markerShape -
    • getMarkerShape

      public int getMarkerShape()
      Gets the data point marker shape.
      Returns:
      the marker shape
    • setMarkerSize

      public void setMarkerSize(int _markerSize)
      Sets the half-width of the data point marker.
      Parameters:
      _markerSize - in pixels
    • setMaximumPoints

      public void setMaximumPoints(int maxPoints)
      Sets the maximum number of allowed datapoints.
      Parameters:
      maxPoints - int
    • getMarkerSize

      public int getMarkerSize()
      Gets the half-width of the data point marker.
      Returns:
      the marker size in pixels
    • setLineColor

      public void setLineColor(Color _lineColor)
      Sets the color of the lines connecting data points.
      Parameters:
      _lineColor -
    • setXYColumnNames

      public void setXYColumnNames(String _xColumnName, String _yColumnName)
      Sets the column names when rendering this dataset in a JTable.
      Parameters:
      _xColumnName -
      _yColumnName -
    • setXYColumnNames

      public void setXYColumnNames(String xColumnName, String yColumnName, String name)
      Sets the column names and the dataset name.
      Parameters:
      xColumnName -
      yColumnName -
      name -
    • getXColumnName

      public String getXColumnName()
      Gets the x column name.
      Returns:
      String
    • getYColumnName

      public String getYColumnName()
      Gets the y column name.
      Returns:
      String
    • getXColumnDescription

      public String getXColumnDescription()
      Gets the x column description.
      Returns:
      the description (may be null)
    • setXColumnDescription

      public void setXColumnDescription(String desc)
      Sets the x column description.
      Parameters:
      desc - the description (may be null)
    • getYColumnDescription

      public String getYColumnDescription()
      Gets the y column description.
      Returns:
      the description (may be null)
    • setYColumnDescription

      public void setYColumnDescription(String desc)
      Sets the y column description.
      Parameters:
      desc - the description (may be null)
    • setName

      public void setName(String name)
      Sets a name that can be used to identify the dataset.
      Parameters:
      name - String
    • getName

      public String getName()
      Gets the dataset name.
      Specified by:
      getName in interface Data
      Returns:
      String
    • getDataList

      public List<Data> getDataList()
      Some Data objects (e.g., a Group) do not contain data, but a list of Data objects which do. This method is used by Data displaying tools to create as many pages as needed.
      Specified by:
      getDataList in interface Data
      Returns:
      a list of Data objects, or null if this object contains data
    • getColumnNames

      public String[] getColumnNames()
      The column names to be used in the data tool
      Specified by:
      getColumnNames in interface Data
      Returns:
      array of names
    • isMeasured

      public boolean isMeasured()
      Gets the valid measure flag. The measure is valid if the min and max values have been set.
      Specified by:
      isMeasured in interface Measurable
      Returns:
      true<\code> if measure is valid
    • getXMin

      public double getXMin()
      Gets the x world coordinate for the left hand side of the panel.
      Specified by:
      getXMin in interface Measurable
      Returns:
      xmin
    • getXMax

      public double getXMax()
      Gets the x world coordinate for the right hand side of the panel.
      Specified by:
      getXMax in interface Measurable
      Returns:
      xmax
    • getYMin

      public double getYMin()
      Gets y world coordinate for the bottom of the panel.
      Specified by:
      getYMin in interface Measurable
      Returns:
      ymin
    • getYMax

      public double getYMax()
      Gets y world coordinate for the top of the panel.
      Specified by:
      getYMax in interface Measurable
      Returns:
      ymax
    • getXMinLogscale

      public double getXMinLogscale()
      Gets the minimum x needed to draw this object on a log scale.
      Specified by:
      getXMinLogscale in interface LogMeasurable
      Returns:
      minimum
    • getXMaxLogscale

      public double getXMaxLogscale()
      Gets the maximum x needed to draw this object on a log scale.
      Specified by:
      getXMaxLogscale in interface LogMeasurable
      Returns:
      maximum
    • getYMinLogscale

      public double getYMinLogscale()
      Gets the minimum y needed to draw this object on a log scale.
      Specified by:
      getYMinLogscale in interface LogMeasurable
      Returns:
      minimum
    • getYMaxLogscale

      public double getYMaxLogscale()
      Gets the maximum y needed to draw this object on a log scale on a log scale.
      Specified by:
      getYMaxLogscale in interface LogMeasurable
      Returns:
      maximum
    • getPoints

      public double[][] getPoints()
      Gets a data array containing both x and y values. The data is arranged as an array of (x,y) pairs.
      Returns:
      a double[index][2] array of data
    • isShifted

      public boolean isShifted()
      Gets the shifted property. DataColumn only.
      Returns:
      true if values are shifted
    • setShifted

      public void setShifted(boolean shifted)
      Sets the shifted property to shift the values of all elements. DataColumn only.
      Parameters:
      shift - true to shift the values
    • setShift

      public boolean setShift(double shift)
      Sets the shift used to shift the values of all elements. DataColumn only.
      Parameters:
      shift - the shift
      Returns:
      true if shift was changed
    • getShift

      public double getShift()
      Gets the shift used to shift the values of all elements. DataColumn only.
      Returns:
      the shift
    • setShiftedValue

      public boolean setShiftedValue(int i, double value)
    • getData2D

      public double[][] getData2D()
      Gets a data array containing both x and y values. Implements Data. The data is arranged as a pair of separate x and y arrays.
      Specified by:
      getData2D in interface Data
      Returns:
      a double[2][index] array of data
    • getData3D

      public double[][][] getData3D()
      Returns a null 3D array of data. Implements Data.
      Specified by:
      getData3D in interface Data
      Returns:
      null
    • getDatasets

      public ArrayList<Dataset> getDatasets()
      Returns a list containing this Dataset. Implements Data.
      Specified by:
      getDatasets in interface Data
      Returns:
      ArrayList
    • getXPoints

      public final double[] getXPoints()
      Gets a copy of the xpoints array.
      Returns:
      xpoints clone
    • getXPointsRaw

      public final double[] getXPointsRaw()
      Get xpoints; CAUTION: You must use getIndex() to get the meaningful length of the array data.
      Returns:
      uncloned xpoints
    • getYShifted

      public double getYShifted(int i)
    • getYPoints

      public double[] getYPoints()
      Gets a copy of the ypoints array, with shift added if shifted.
      Returns:
      a clone of the y points (may be shifted)
    • getYPointsRaw

      public final double[] getYPointsRaw()
      CAUTION -- could be a shift in DataColumn set
      Returns:
      uncloned ypoints
    • getY

      public double getY(int i)
    • getValidXPoints

      public double[] getValidXPoints()
      Gets an array of valid xpoints. A point is valid if the ypoint for that index is not Double.NaN.
      Returns:
      valid xpoints, trimmed to (index - nNAN) length
    • getValidYPoints

      public double[] getValidYPoints()
      Gets an array of valid ypoints. A point is valid if the ypoint for that index is not Double.NaN.
      Returns:
      valid ypoints[], trimmed to index length
    • isSorted

      public boolean isSorted()
      Gets the sorted flag.
      Returns:
      true<\code> if the data is sorted
    • isConnected

      public boolean isConnected()
      Gets the data connected flag.
      Returns:
      true<\code> if points are connected
    • getColumnCount

      public int getColumnCount()
      Gets the number of columns for rendering in a JTable.
      Specified by:
      getColumnCount in class DataTable.DataModel
      Returns:
      the count
    • getIndex

      public int getIndex()
      Gets the current index of the array. The index is equal to the number of data points that are currently stored. When data is appended, it will fill the xpoints and ypoints arrays starting at the current index.
      Returns:
      the count
    • getRowCount

      public int getRowCount()
      Gets the number of rows for rendering in a JTable.
      Specified by:
      getRowCount in class DataTable.DataModel
      Returns:
      the count
    • getColumnName

      public String getColumnName(int columnIndex)
      Gets the name of the colummn for rendering in a JTable
      Specified by:
      getColumnName in class DataTable.DataModel
      Parameters:
      columnIndex -
      Returns:
      the name
    • getValueAt

      public double getValueAt(int rowIndex, int columnIndex)
      Specified by:
      getValueAt in class DataTable.DataModel
    • append

      public void append(double x, double y, double delx, double dely)
      Appends a data point and its uncertainty to the Dataset.
      Parameters:
      x -
      y -
      delx -
      dely -
    • append

      public void append(double x, double y)
      Appends an (x,y) datum to the Dataset. A y value of Double.NaN is treated as null in plots and tables.
      Parameters:
      x -
      y -
    • append

      public void append(double[] xpoints, double[] ypoints, double[] delx, double[] dely)
      Appends arrays of data points and uncertainties to the Dataset.
      Parameters:
      xpoints -
      ypoints -
      delx -
      dely -
    • append

      public void append(double[] _xpoints, double[] _ypoints)
      Appends (x,y) arrays to the Dataset. Any y value of Double.NaN is treated as null in plots and tables.
      Parameters:
      _xpoints -
      _ypoints -
    • append

      public void append(double[] _xpoints, double[] _ypoints, int len)
      Allow for raw xpoints, with an index length
      Parameters:
      _xpoints -
      _ypoints -
      len -
    • read

      public void read(String inputFile)
      Reads a file and appends the data contained in the file to this Dataset. The format of the file is x and y coordinates separated by tabs. Lines beginning with # are ignored.
      Parameters:
      inputFile -
    • write

      public void write(String outputFile)
      Writes data from this Dataset to a file. The format of the file is x and y coordinates separated by tabs.
      Parameters:
      outputFile -
    • draw

      public void draw(DrawingPanel drawingPanel, Graphics g)
      Draw this Dataset in the drawing panel.
      Specified by:
      draw in interface Drawable
      Parameters:
      drawingPanel -
      g -
    • drawClip

      protected static void drawClip(Graphics2D g2, DrawingPanel drawingPanel, int offset)
      Expand the clip a bit to allow the marker to extend over the axes if necessary.
      Parameters:
      g2 -
      drawingPanel -
      offset -
    • drawable

      protected boolean drawable()
      Returns:
      true if there is something to draw
    • drawData

      protected void drawData(DrawingPanel drawingPanel, Graphics2D g2)
      Draw the data in the appropriate fashion.
      Parameters:
      drawingPanel -
      g2 -
    • drawScatterPlot

      protected void drawScatterPlot(DrawingPanel drawingPanel, Graphics2D g2)
      Draw the markers at the data points.
      Parameters:
      drawingPanel -
      g2 -
    • clear

      public void clear()
      Clear all data from this Dataset.
    • toString

      public String toString()
      Creates a string representation of the data.
      Overrides:
      toString in class Object
      Returns:
      the data
    • countColumnsVisible

      public static int countColumnsVisible(boolean[] visible)
      Deprecated.
      by Bob Hanson -- see bsColVis
      Counts the number of columns visible
      Parameters:
      visible - array of column visibilities
      Returns:
      number of visible columns
    • setXColumnVisible

      public void setXColumnVisible(boolean b)
      Sets the visibility of the x column of this Dataset in a table view.
      Parameters:
      b - new visibility
    • setYColumnVisible

      public void setYColumnVisible(boolean b)
      Sets the visibility of the y column of this Dataset in a table view.
      Parameters:
      b - new visibility
    • setVisible

      public void setVisible(boolean b)
      Sets the visibility of this Dataset in a DrawingPanel. Only visible panels affect autoscaled panels.
      Parameters:
      b - new visibility
    • getVisible

      public boolean getVisible()
      Gets the visibility of this dataset in the DrawingPanel.
      Returns:
      boolean
    • setStride

      public void setStride(int stride)
      Sets the stride of this Dataset in a table view.
    • isXColumnVisible

      public boolean isXColumnVisible()
      Gets the visibility of the x column of this Dataset in a table view.
      Returns:
      the x column visibility
    • isYColumnVisible

      public boolean isYColumnVisible()
      Gets the visibility of the y column of this Dataset in a table view.
      Returns:
      the x column visibility
    • recalculatePath

      protected void recalculatePath()
      Recalculate the general path.
    • insertionSort

      protected void insertionSort()
      Perform an insertion sort of the data set. Since data will be partially sorted this should be fast. Added by W. Christian.
    • getTranslateInstance

      protected AffineTransform getTranslateInstance(double tx, double ty)
    • findDataSet

      public static Dataset findDataSet(ArrayList<Dataset> datasets, Data newData)
    • getNaNCount

      protected static int getNaNCount(double[] pts, int index)
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns the XML.ObjectLoader for this class.
      Returns:
      the object loader
    • toBoolArray

      public static boolean[] toBoolArray(BitSet bs)
    • convertTableColumnIndex

      public static int convertTableColumnIndex(BitSet visible, int columnIndex)
      Converts a table column in a table model to the appropriate table column. x y index ret best: 1 1 0 0 (index when x) 1 0 0 0 (index when x) 1 1 1 1 (index when y) 0 1 1 1 (index when y) 0 1 0 1 (1 when !x) 1 0 1 0 (0 when !y) equivalent 0 1 0 1 (1 when !x) 0 1 1 1 (1 when !x) 1 0 0 0 (0 when !y) 1 0 1 0 (0 when !y) 1 1 0 0 (index) 1 1 1 1 (index) same as original: 0 1 0 1 (1 when index==0 and !x) 1 0 1 0 (0 when index==1 and !y) 1 0 0 0 (index) 0 1 1 1 (index) 1 1 0 0 (index) 1 1 1 1 (index)
      Parameters:
      visible - array of column visibilities
      columnIndex - table column index to convert --- 0 or 1
      Returns:
      converted table column index
    • loadDatasets

      public static void loadDatasets(ArrayList<Dataset> datasets, Iterator<Dataset> it)
    • getMean

      public double getMean(int xcol)
      Get the mean value of either the x or y points.
      Parameters:
      xcol - 1 for y, 0 for x
      Returns:
      sum(values)/count(values)
    • getX

      public double getX(int i)