Package org.opensourcephysics.display
Class Dataset
java.lang.Object
org.opensourcephysics.display.DataTable.DataModel
org.opensourcephysics.display.Dataset
- All Implemented Interfaces:
Data
,Drawable
,LogMeasurable
,Measurable
- Direct Known Subclasses:
DataColumn
,DataFunction
,HighlightableDataset
,HistogramDataset
,Stripchart
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A class to save and load Dataset data in an XMLControl.class
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Field AREAstatic final int
Field BARstatic final int
Field CIRCLEprotected int
Field columnID: an integer used by DataToolstatic final int
Field POSTprotected Shape
protected int
Field datasetID: an integer ID that identifies this objectprotected ArrayList<org.opensourcephysics.display.Dataset.ErrorBar>
protected GeneralPath
protected static int
protected int
protected int
static double
maxPointsMultiplier: a multiplier for maxPointsfinal Dataset.Model
static final int
Field NO_MARKERstatic final int
Field PIXELstatic final int
Field POSTprotected double
protected boolean
static final int
Field SQUAREint
protected boolean
protected String
protected double
protected double
protected double
protected double
protected double[]
protected String
protected double
protected double
protected double
protected double
protected double[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(double[] _xpoints, double[] _ypoints) Appends (x,y) arrays to the Dataset.void
append
(double[] xpoints, double[] ypoints, double[] delx, double[] dely) Appends arrays of data points and uncertainties to the Dataset.void
append
(double[] _xpoints, double[] _ypoints, int len) Allow for raw xpoints, with an index lengthvoid
append
(double x, double y) Appends an (x,y) datum to the Dataset.void
append
(double x, double y, double delx, double dely) Appends a data point and its uncertainty to the Dataset.void
clear()
Clear all data from this Dataset.static int
convertTableColumnIndex
(BitSet visible, int columnIndex) Converts a table column in a table model to the appropriate table column.static int
countColumnsVisible
(boolean[] visible) Deprecated.by Bob Hanson -- see bsColVisvoid
draw
(DrawingPanel drawingPanel, Graphics g) Draw this Dataset in the drawing panel.protected boolean
drawable()
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.protected void
drawData
(DrawingPanel drawingPanel, Graphics2D g2) Draw the data in the appropriate fashion.protected void
drawScatterPlot
(DrawingPanel drawingPanel, Graphics2D g2) Draw the markers at the data points.static Dataset
findDataSet
(ArrayList<Dataset> datasets, Data newData) int
Gets the number of columns for rendering in a JTable.int
Returns the column ID.getColumnName
(int columnIndex) Gets the name of the colummn for rendering in a JTableString[]
The column names to be used in the data tooldouble[][]
Gets a data array containing both x and y values.double[][][]
Returns a null 3D array of data.Some Data objects (e.g., a Group) do not contain data, but a list of Data objects which do.Returns a list containing this Dataset.Gets the data point edge color.Gets the data point fill color.Color[]
Fill colors for Data interface.int
getID()
Returns a unique identifier for this Data.int
getIndex()
Gets the current index of the array.Gets the line color.Color[]
Line colors for Data interface.static XML.ObjectLoader
Returns the XML.ObjectLoader for this class.int
Gets the data point marker shape.int
Gets the half-width of the data point marker.double
getMean
(int xcol) Get the mean value of either the x or y points.getName()
Gets the dataset name.protected static int
getNaNCount
(double[] pts, int index) double[][]
Gets a data array containing both x and y values.int
Gets the number of rows for rendering in a JTable.double
getShift()
Gets the shift used to shift the values of all elements.protected AffineTransform
getTranslateInstance
(double tx, double ty) double[]
Gets an array of valid xpoints.double[]
Gets an array of valid ypoints.double
getValueAt
(int rowIndex, int columnIndex) boolean
Gets the visibility of this dataset in the DrawingPanel.double
getX
(int i) Gets the x column description.Gets the x column name.double
getXMax()
Gets the x world coordinate for the right hand side of the panel.double
Gets the maximum x needed to draw this object on a log scale.double
getXMin()
Gets the x world coordinate for the left hand side of the panel.double
Gets the minimum x needed to draw this object on a log scale.final double[]
Gets a copy of the xpoints array.final double[]
Get xpoints; CAUTION: You must use getIndex() to get the meaningful length of the array data.double
getY
(int i) Gets the y column description.Gets the y column name.double
getYMax()
Gets y world coordinate for the top of the panel.double
Gets the maximum y needed to draw this object on a log scale on a log scale.double
getYMin()
Gets y world coordinate for the bottom of the panel.double
Gets the minimum y needed to draw this object on a log scale.double[]
Gets a copy of the ypoints array, with shift added if shifted.final double[]
CAUTION -- could be a shift in DataColumn setdouble
getYShifted
(int i) protected void
Perform an insertion sort of the data set.boolean
Gets the data connected flag.boolean
Gets the valid measure flag.boolean
Gets the shifted property.boolean
isSorted()
Gets the sorted flag.boolean
Gets the visibility of the x column of this Dataset in a table view.boolean
Gets the visibility of the y column of this Dataset in a table view.static void
loadDatasets
(ArrayList<Dataset> datasets, Iterator<Dataset> it) void
Reads a file and appends the data contained in the file to this Dataset.protected void
Recalculate the general path.set
(double[] x, double[] y) void
setColumnID
(int id) Sets the column ID.void
setConnected
(boolean _connected) Sets the data connected flag.void
setCustomMarker
(Shape marker) Sets a custom marker shape.void
setID
(int id) Sets the ID number of this Data.void
setLineColor
(Color _lineColor) Sets the color of the lines connecting data points.void
setMarkerColor
(Color markerColor) Sets the data point fill, edge, and error bar colors to the same color.void
setMarkerColor
(Color _fillColor, Color _edgeColor) Sets the data point marker colors.void
setMarkerColor
(Color _fillColor, Color _edgeColor, Color _errorBarColor) Sets the data point marker colors.void
setMarkerShape
(int _markerShape) Sets the data point marker shape.void
setMarkerSize
(int _markerSize) Sets the half-width of the data point marker.void
setMaximumPoints
(int maxPoints) Sets the maximum number of allowed datapoints.void
Sets a name that can be used to identify the dataset.boolean
setShift
(double shift) Sets the shift used to shift the values of all elements.void
setShifted
(boolean shifted) Sets the shifted property to shift the values of all elements.boolean
setShiftedValue
(int i, double value) void
setSorted
(boolean _sorted) Sets the sorted flag.void
setStride
(int stride) Sets the stride of this Dataset in a table view.void
setVisible
(boolean b) Sets the visibility of this Dataset in a DrawingPanel.void
setXColumnDescription
(String desc) Sets the x column description.void
setXColumnVisible
(boolean b) Sets the visibility of the x column of this Dataset in a table view.void
setXYColumnNames
(String _xColumnName, String _yColumnName) Sets the column names when rendering this dataset in a JTable.void
setXYColumnNames
(String xColumnName, String yColumnName, String name) Sets the column names and the dataset name.void
setYColumnDescription
(String desc) Sets the y column description.void
setYColumnVisible
(boolean b) Sets the visibility of the y column of this Dataset in a table view.static boolean[]
toBoolArray
(BitSet bs) toString()
Creates a string representation of the data.void
Writes data from this Dataset to a file.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opensourcephysics.display.Drawable
isInteractive
-
Field Details
-
model
-
id
protected static int id -
datasetID
protected int datasetIDField datasetID: an integer ID that identifies this object -
columnID
protected int columnIDField columnID: an integer used by DataTool -
NO_MARKER
public static final int NO_MARKERField NO_MARKER- See Also:
-
CIRCLE
public static final int CIRCLEField CIRCLE- See Also:
-
SQUARE
public static final int SQUAREField SQUARE- See Also:
-
AREA
public static final int AREAField AREA- See Also:
-
PIXEL
public static final int PIXELField PIXEL- See Also:
-
BAR
public static final int BARField BAR- See Also:
-
POST
public static final int POSTField POST- See Also:
-
CUSTOM
public static final int CUSTOMField POST- See Also:
-
maxPointsMultiplier
public static double maxPointsMultipliermaxPointsMultiplier: a multiplier for maxPoints -
xpoints
protected double[] xpoints -
ypoints
protected double[] ypoints -
shift
protected double shift -
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
-
yColumnDescription
-
visible
protected boolean visible -
maxPoints
protected int maxPoints -
errorBars
-
customMarker
-
-
Constructor Details
-
Dataset
public Dataset()Dataset constructor. -
Dataset
Dataset constructor specifying the marker color.- Parameters:
_markerColor
-
-
Dataset
Dataset constructor specifying the marker color, line color, and whether points are connected.- Parameters:
markerColor
-_lineColor
-_connected
-
-
-
Method Details
-
set
-
setID
public void setID(int id) Sets the ID number of this Data. -
getID
public int getID()Returns a unique identifier for this Data. -
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
Sets the data point fill, edge, and error bar colors to the same color.- Parameters:
markerColor
-
-
setMarkerColor
Sets the data point marker colors. The error bar color is set equal to the edge color.- Parameters:
_fillColor
-_edgeColor
-
-
setMarkerColor
Sets the data point marker colors.- Parameters:
_fillColor
-_edgeColor
-_errorBarColor
-
-
getFillColor
Gets the data point fill color.- Returns:
- the fill color
-
getFillColors
Fill colors for Data interface.- Specified by:
getFillColors
in interfaceData
- Returns:
- color array
-
getEdgeColor
Gets the data point edge color.- Returns:
- the edge color
-
getLineColor
Gets the line color.- Returns:
- the line color
-
getLineColors
Line colors for Data interface.- Specified by:
getLineColors
in interfaceData
- Returns:
- color array
-
setCustomMarker
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
Sets the color of the lines connecting data points.- Parameters:
_lineColor
-
-
setXYColumnNames
Sets the column names when rendering this dataset in a JTable.- Parameters:
_xColumnName
-_yColumnName
-
-
setXYColumnNames
Sets the column names and the dataset name.- Parameters:
xColumnName
-yColumnName
-name
-
-
getXColumnName
Gets the x column name.- Returns:
- String
-
getYColumnName
Gets the y column name.- Returns:
- String
-
getXColumnDescription
Gets the x column description.- Returns:
- the description (may be null)
-
setXColumnDescription
Sets the x column description.- Parameters:
desc
- the description (may be null)
-
getYColumnDescription
Gets the y column description.- Returns:
- the description (may be null)
-
setYColumnDescription
Sets the y column description.- Parameters:
desc
- the description (may be null)
-
setName
Sets a name that can be used to identify the dataset.- Parameters:
name
- String
-
getName
Gets the dataset name. -
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 interfaceData
- Returns:
- a list of Data objects, or null if this object contains data
-
getColumnNames
The column names to be used in the data tool- Specified by:
getColumnNames
in interfaceData
- 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 interfaceMeasurable
- 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 interfaceMeasurable
- Returns:
- xmin
-
getXMax
public double getXMax()Gets the x world coordinate for the right hand side of the panel.- Specified by:
getXMax
in interfaceMeasurable
- Returns:
- xmax
-
getYMin
public double getYMin()Gets y world coordinate for the bottom of the panel.- Specified by:
getYMin
in interfaceMeasurable
- Returns:
- ymin
-
getYMax
public double getYMax()Gets y world coordinate for the top of the panel.- Specified by:
getYMax
in interfaceMeasurable
- Returns:
- ymax
-
getXMinLogscale
public double getXMinLogscale()Gets the minimum x needed to draw this object on a log scale.- Specified by:
getXMinLogscale
in interfaceLogMeasurable
- Returns:
- minimum
-
getXMaxLogscale
public double getXMaxLogscale()Gets the maximum x needed to draw this object on a log scale.- Specified by:
getXMaxLogscale
in interfaceLogMeasurable
- Returns:
- maximum
-
getYMinLogscale
public double getYMinLogscale()Gets the minimum y needed to draw this object on a log scale.- Specified by:
getYMinLogscale
in interfaceLogMeasurable
- 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 interfaceLogMeasurable
- 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. -
getData3D
public double[][][] getData3D()Returns a null 3D array of data. Implements Data. -
getDatasets
Returns a list containing this Dataset. Implements Data.- Specified by:
getDatasets
in interfaceData
- 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 classDataTable.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 classDataTable.DataModel
- Returns:
- the count
-
getColumnName
Gets the name of the colummn for rendering in a JTable- Specified by:
getColumnName
in classDataTable.DataModel
- Parameters:
columnIndex
-- Returns:
- the name
-
getValueAt
public double getValueAt(int rowIndex, int columnIndex) - Specified by:
getValueAt
in classDataTable.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
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
Writes data from this Dataset to a file. The format of the file is x and y coordinates separated by tabs.- Parameters:
outputFile
-
-
draw
Draw this Dataset in the drawing panel. -
drawClip
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
Draw the data in the appropriate fashion.- Parameters:
drawingPanel
-g2
-
-
drawScatterPlot
Draw the markers at the data points.- Parameters:
drawingPanel
-g2
-
-
clear
public void clear()Clear all data from this Dataset. -
toString
Creates a string representation of the data. -
countColumnsVisible
public static int countColumnsVisible(boolean[] visible) Deprecated.by Bob Hanson -- see bsColVisCounts 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
-
findDataSet
-
getNaNCount
protected static int getNaNCount(double[] pts, int index) -
getLoader
Returns the XML.ObjectLoader for this class.- Returns:
- the object loader
-
toBoolArray
-
convertTableColumnIndex
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 visibilitiescolumnIndex
- table column index to convert --- 0 or 1- Returns:
- converted table column index
-
loadDatasets
-
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)
-