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 SummaryNested ClassesModifier and TypeClassDescriptionprotected static classA class to save and load Dataset data in an XMLControl.class
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intField AREAstatic final intField BARstatic final intField CIRCLEprotected intField columnID: an integer used by DataToolstatic final intField POSTprotected Shapeprotected intField datasetID: an integer ID that identifies this objectprotected ArrayList<org.opensourcephysics.display.Dataset.ErrorBar>protected GeneralPathprotected static intprotected intprotected intstatic doublemaxPointsMultiplier: a multiplier for maxPointsfinal Dataset.Modelstatic final intField NO_MARKERstatic final intField PIXELstatic final intField POSTprotected doubleprotected booleanstatic final intField SQUAREintprotected booleanprotected Stringprotected doubleprotected doubleprotected doubleprotected doubleprotected double[]protected Stringprotected doubleprotected doubleprotected doubleprotected doubleprotected double[]
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidappend(double[] _xpoints, double[] _ypoints) Appends (x,y) arrays to the Dataset.voidappend(double[] xpoints, double[] ypoints, double[] delx, double[] dely) Appends arrays of data points and uncertainties to the Dataset.voidappend(double[] _xpoints, double[] _ypoints, int len) Allow for raw xpoints, with an index lengthvoidappend(double x, double y) Appends an (x,y) datum to the Dataset.voidappend(double x, double y, double delx, double dely) Appends a data point and its uncertainty to the Dataset.voidclear()Clear all data from this Dataset.static intconvertTableColumnIndex(BitSet visible, int columnIndex) Converts a table column in a table model to the appropriate table column.static intcountColumnsVisible(boolean[] visible) Deprecated.by Bob Hanson -- see bsColVisvoiddraw(DrawingPanel drawingPanel, Graphics g) Draw this Dataset in the drawing panel.protected booleandrawable()protected static voiddrawClip(Graphics2D g2, DrawingPanel drawingPanel, int offset) Expand the clip a bit to allow the marker to extend over the axes if necessary.protected voiddrawData(DrawingPanel drawingPanel, Graphics2D g2) Draw the data in the appropriate fashion.protected voiddrawScatterPlot(DrawingPanel drawingPanel, Graphics2D g2) Draw the markers at the data points.static DatasetfindDataSet(ArrayList<Dataset> datasets, Data newData) intGets the number of columns for rendering in a JTable.intReturns 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.intgetID()Returns a unique identifier for this Data.intgetIndex()Gets the current index of the array.Gets the line color.Color[]Line colors for Data interface.static XML.ObjectLoaderReturns the XML.ObjectLoader for this class.intGets the data point marker shape.intGets the half-width of the data point marker.doublegetMean(int xcol) Get the mean value of either the x or y points.getName()Gets the dataset name.protected static intgetNaNCount(double[] pts, int index) double[][]Gets a data array containing both x and y values.intGets the number of rows for rendering in a JTable.doublegetShift()Gets the shift used to shift the values of all elements.protected AffineTransformgetTranslateInstance(double tx, double ty) double[]Gets an array of valid xpoints.double[]Gets an array of valid ypoints.doublegetValueAt(int rowIndex, int columnIndex) booleanGets the visibility of this dataset in the DrawingPanel.doublegetX(int i) Gets the x column description.Gets the x column name.doublegetXMax()Gets the x world coordinate for the right hand side of the panel.doubleGets the maximum x needed to draw this object on a log scale.doublegetXMin()Gets the x world coordinate for the left hand side of the panel.doubleGets 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.doublegetY(int i) Gets the y column description.Gets the y column name.doublegetYMax()Gets y world coordinate for the top of the panel.doubleGets the maximum y needed to draw this object on a log scale on a log scale.doublegetYMin()Gets y world coordinate for the bottom of the panel.doubleGets 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 setdoublegetYShifted(int i) protected voidPerform an insertion sort of the data set.booleanGets the data connected flag.booleanGets the valid measure flag.booleanGets the shifted property.booleanisSorted()Gets the sorted flag.booleanGets the visibility of the x column of this Dataset in a table view.booleanGets the visibility of the y column of this Dataset in a table view.static voidloadDatasets(ArrayList<Dataset> datasets, Iterator<Dataset> it) voidReads a file and appends the data contained in the file to this Dataset.protected voidRecalculate the general path.set(double[] x, double[] y) voidsetColumnID(int id) Sets the column ID.voidsetConnected(boolean _connected) Sets the data connected flag.voidsetCustomMarker(Shape marker) Sets a custom marker shape.voidsetID(int id) Sets the ID number of this Data.voidsetLineColor(Color _lineColor) Sets the color of the lines connecting data points.voidsetMarkerColor(Color markerColor) Sets the data point fill, edge, and error bar colors to the same color.voidsetMarkerColor(Color _fillColor, Color _edgeColor) Sets the data point marker colors.voidsetMarkerColor(Color _fillColor, Color _edgeColor, Color _errorBarColor) Sets the data point marker colors.voidsetMarkerShape(int _markerShape) Sets the data point marker shape.voidsetMarkerSize(int _markerSize) Sets the half-width of the data point marker.voidsetMaximumPoints(int maxPoints) Sets the maximum number of allowed datapoints.voidSets a name that can be used to identify the dataset.booleansetShift(double shift) Sets the shift used to shift the values of all elements.voidsetShifted(boolean shifted) Sets the shifted property to shift the values of all elements.booleansetShiftedValue(int i, double value) voidsetSorted(boolean _sorted) Sets the sorted flag.voidsetStride(int stride) Sets the stride of this Dataset in a table view.voidsetVisible(boolean b) Sets the visibility of this Dataset in a DrawingPanel.voidsetXColumnDescription(String desc) Sets the x column description.voidsetXColumnVisible(boolean b) Sets the visibility of the x column of this Dataset in a table view.voidsetXYColumnNames(String _xColumnName, String _yColumnName) Sets the column names when rendering this dataset in a JTable.voidsetXYColumnNames(String xColumnName, String yColumnName, String name) Sets the column names and the dataset name.voidsetYColumnDescription(String desc) Sets the y column description.voidsetYColumnVisible(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.voidWrites data from this Dataset to a file.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.opensourcephysics.display.DrawableisInteractive
- 
Field Details- 
model
- 
idprotected static int id
- 
datasetIDprotected int datasetIDField datasetID: an integer ID that identifies this object
- 
columnIDprotected int columnIDField columnID: an integer used by DataTool
- 
NO_MARKERpublic static final int NO_MARKERField NO_MARKER- See Also:
 
- 
CIRCLEpublic static final int CIRCLEField CIRCLE- See Also:
 
- 
SQUAREpublic static final int SQUAREField SQUARE- See Also:
 
- 
AREApublic static final int AREAField AREA- See Also:
 
- 
PIXELpublic static final int PIXELField PIXEL- See Also:
 
- 
BARpublic static final int BARField BAR- See Also:
 
- 
POSTpublic static final int POSTField POST- See Also:
 
- 
CUSTOMpublic static final int CUSTOMField POST- See Also:
 
- 
maxPointsMultiplierpublic static double maxPointsMultipliermaxPointsMultiplier: a multiplier for maxPoints
- 
xpointsprotected double[] xpoints
- 
ypointsprotected double[] ypoints
- 
shiftprotected double shift
- 
generalPath
- 
xmaxprotected double xmax
- 
ymaxprotected double ymax
- 
xminprotected double xmin
- 
yminprotected double ymin
- 
xmaxLogscaleprotected double xmaxLogscale
- 
ymaxLogscaleprotected double ymaxLogscale
- 
xminLogscaleprotected double xminLogscale
- 
yminLogscaleprotected double yminLogscale
- 
indexprotected int index
- 
sortedprotected boolean sorted
- 
updatepublic int update
- 
xColumnDescription
- 
yColumnDescription
- 
visibleprotected boolean visible
- 
maxPointsprotected int maxPoints
- 
errorBars
- 
customMarker
 
- 
- 
Constructor Details- 
Datasetpublic Dataset()Dataset constructor.
- 
DatasetDataset constructor specifying the marker color.- Parameters:
- _markerColor-
 
- 
DatasetDataset constructor specifying the marker color, line color, and whether points are connected.- Parameters:
- markerColor-
- _lineColor-
- _connected-
 
 
- 
- 
Method Details- 
set
- 
setIDpublic void setID(int id) Sets the ID number of this Data.
- 
getIDpublic int getID()Returns a unique identifier for this Data.
- 
setColumnIDpublic void setColumnID(int id) Sets the column ID.- Parameters:
- id- the column ID
 
- 
getColumnIDpublic int getColumnID()Returns the column ID.- Returns:
- the column ID
 
- 
setSortedpublic void setSorted(boolean _sorted) Sets the sorted flag. Data is sorted by increasing x.- Parameters:
- _sorted-- true<\code> to sort
 
- 
setConnectedpublic void setConnected(boolean _connected) Sets the data connected flag. Points are connected by straight lines.- Parameters:
- _connected-- true<\code> if points are connected
 
- 
setMarkerColorSets the data point fill, edge, and error bar colors to the same color.- Parameters:
- markerColor-
 
- 
setMarkerColorSets the data point marker colors. The error bar color is set equal to the edge color.- Parameters:
- _fillColor-
- _edgeColor-
 
- 
setMarkerColorSets the data point marker colors.- Parameters:
- _fillColor-
- _edgeColor-
- _errorBarColor-
 
- 
getFillColorGets the data point fill color.- Returns:
- the fill color
 
- 
getFillColorsFill colors for Data interface.- Specified by:
- getFillColorsin interface- Data
- Returns:
- color array
 
- 
getEdgeColorGets the data point edge color.- Returns:
- the edge color
 
- 
getLineColorGets the line color.- Returns:
- the line color
 
- 
getLineColorsLine colors for Data interface.- Specified by:
- getLineColorsin interface- Data
- Returns:
- color array
 
- 
setCustomMarkerSets a custom marker shape.- Parameters:
- marker- Shape
 
- 
setMarkerShapepublic void setMarkerShape(int _markerShape) Sets the data point marker shape. Shapes are: NO_MARKER, CIRCLE, SQUARE, AREA, PIXEL, BAR, POST- Parameters:
- _markerShape-
 
- 
getMarkerShapepublic int getMarkerShape()Gets the data point marker shape.- Returns:
- the marker shape
 
- 
setMarkerSizepublic void setMarkerSize(int _markerSize) Sets the half-width of the data point marker.- Parameters:
- _markerSize- in pixels
 
- 
setMaximumPointspublic void setMaximumPoints(int maxPoints) Sets the maximum number of allowed datapoints.- Parameters:
- maxPoints- int
 
- 
getMarkerSizepublic int getMarkerSize()Gets the half-width of the data point marker.- Returns:
- the marker size in pixels
 
- 
setLineColorSets the color of the lines connecting data points.- Parameters:
- _lineColor-
 
- 
setXYColumnNamesSets the column names when rendering this dataset in a JTable.- Parameters:
- _xColumnName-
- _yColumnName-
 
- 
setXYColumnNamesSets the column names and the dataset name.- Parameters:
- xColumnName-
- yColumnName-
- name-
 
- 
getXColumnNameGets the x column name.- Returns:
- String
 
- 
getYColumnNameGets the y column name.- Returns:
- String
 
- 
getXColumnDescriptionGets the x column description.- Returns:
- the description (may be null)
 
- 
setXColumnDescriptionSets the x column description.- Parameters:
- desc- the description (may be null)
 
- 
getYColumnDescriptionGets the y column description.- Returns:
- the description (may be null)
 
- 
setYColumnDescriptionSets the y column description.- Parameters:
- desc- the description (may be null)
 
- 
setNameSets a name that can be used to identify the dataset.- Parameters:
- name- String
 
- 
getNameGets the dataset name.
- 
getDataListSome 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:
- getDataListin interface- Data
- Returns:
- a list of Data objects, or null if this object contains data
 
- 
getColumnNamesThe column names to be used in the data tool- Specified by:
- getColumnNamesin interface- Data
- Returns:
- array of names
 
- 
isMeasuredpublic boolean isMeasured()Gets the valid measure flag. The measure is valid if the min and max values have been set.- Specified by:
- isMeasuredin interface- Measurable
- Returns:
- true<\code> if measure is valid
 
- 
getXMinpublic double getXMin()Gets the x world coordinate for the left hand side of the panel.- Specified by:
- getXMinin interface- Measurable
- Returns:
- xmin
 
- 
getXMaxpublic double getXMax()Gets the x world coordinate for the right hand side of the panel.- Specified by:
- getXMaxin interface- Measurable
- Returns:
- xmax
 
- 
getYMinpublic double getYMin()Gets y world coordinate for the bottom of the panel.- Specified by:
- getYMinin interface- Measurable
- Returns:
- ymin
 
- 
getYMaxpublic double getYMax()Gets y world coordinate for the top of the panel.- Specified by:
- getYMaxin interface- Measurable
- Returns:
- ymax
 
- 
getXMinLogscalepublic double getXMinLogscale()Gets the minimum x needed to draw this object on a log scale.- Specified by:
- getXMinLogscalein interface- LogMeasurable
- Returns:
- minimum
 
- 
getXMaxLogscalepublic double getXMaxLogscale()Gets the maximum x needed to draw this object on a log scale.- Specified by:
- getXMaxLogscalein interface- LogMeasurable
- Returns:
- maximum
 
- 
getYMinLogscalepublic double getYMinLogscale()Gets the minimum y needed to draw this object on a log scale.- Specified by:
- getYMinLogscalein interface- LogMeasurable
- Returns:
- minimum
 
- 
getYMaxLogscalepublic double getYMaxLogscale()Gets the maximum y needed to draw this object on a log scale on a log scale.- Specified by:
- getYMaxLogscalein interface- LogMeasurable
- Returns:
- maximum
 
- 
getPointspublic 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
 
- 
isShiftedpublic boolean isShifted()Gets the shifted property. DataColumn only.- Returns:
- true if values are shifted
 
- 
setShiftedpublic void setShifted(boolean shifted) Sets the shifted property to shift the values of all elements. DataColumn only.- Parameters:
- shift- true to shift the values
 
- 
setShiftpublic 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
 
- 
getShiftpublic double getShift()Gets the shift used to shift the values of all elements. DataColumn only.- Returns:
- the shift
 
- 
setShiftedValuepublic boolean setShiftedValue(int i, double value) 
- 
getData2Dpublic 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.
- 
getData3Dpublic double[][][] getData3D()Returns a null 3D array of data. Implements Data.
- 
getDatasetsReturns a list containing this Dataset. Implements Data.- Specified by:
- getDatasetsin interface- Data
- Returns:
- ArrayList
 
- 
getXPointspublic final double[] getXPoints()Gets a copy of the xpoints array.- Returns:
- xpoints clone
 
- 
getXPointsRawpublic final double[] getXPointsRaw()Get xpoints; CAUTION: You must use getIndex() to get the meaningful length of the array data.- Returns:
- uncloned xpoints
 
- 
getYShiftedpublic double getYShifted(int i) 
- 
getYPointspublic double[] getYPoints()Gets a copy of the ypoints array, with shift added if shifted.- Returns:
- a clone of the y points (may be shifted)
 
- 
getYPointsRawpublic final double[] getYPointsRaw()CAUTION -- could be a shift in DataColumn set- Returns:
- uncloned ypoints
 
- 
getYpublic double getY(int i) 
- 
getValidXPointspublic 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
 
- 
getValidYPointspublic 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
 
- 
isSortedpublic boolean isSorted()Gets the sorted flag.- Returns:
- true<\code> if the data is sorted
 
- 
isConnectedpublic boolean isConnected()Gets the data connected flag.- Returns:
- true<\code> if points are connected
 
- 
getColumnCountpublic int getColumnCount()Gets the number of columns for rendering in a JTable.- Specified by:
- getColumnCountin class- DataTable.DataModel
- Returns:
- the count
 
- 
getIndexpublic 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
 
- 
getRowCountpublic int getRowCount()Gets the number of rows for rendering in a JTable.- Specified by:
- getRowCountin class- DataTable.DataModel
- Returns:
- the count
 
- 
getColumnNameGets the name of the colummn for rendering in a JTable- Specified by:
- getColumnNamein class- DataTable.DataModel
- Parameters:
- columnIndex-
- Returns:
- the name
 
- 
getValueAtpublic double getValueAt(int rowIndex, int columnIndex) - Specified by:
- getValueAtin class- DataTable.DataModel
 
- 
appendpublic 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-
 
- 
appendpublic 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-
 
- 
appendpublic 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-
 
- 
appendpublic 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-
 
- 
appendpublic void append(double[] _xpoints, double[] _ypoints, int len) Allow for raw xpoints, with an index length- Parameters:
- _xpoints-
- _ypoints-
- len-
 
- 
readReads 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-
 
- 
writeWrites data from this Dataset to a file. The format of the file is x and y coordinates separated by tabs.- Parameters:
- outputFile-
 
- 
drawDraw this Dataset in the drawing panel.
- 
drawClipExpand the clip a bit to allow the marker to extend over the axes if necessary.- Parameters:
- g2-
- drawingPanel-
- offset-
 
- 
drawableprotected boolean drawable()- Returns:
- true if there is something to draw
 
- 
drawDataDraw the data in the appropriate fashion.- Parameters:
- drawingPanel-
- g2-
 
- 
drawScatterPlotDraw the markers at the data points.- Parameters:
- drawingPanel-
- g2-
 
- 
clearpublic void clear()Clear all data from this Dataset.
- 
toStringCreates a string representation of the data.
- 
countColumnsVisiblepublic 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
 
- 
setXColumnVisiblepublic void setXColumnVisible(boolean b) Sets the visibility of the x column of this Dataset in a table view.- Parameters:
- b- new visibility
 
- 
setYColumnVisiblepublic void setYColumnVisible(boolean b) Sets the visibility of the y column of this Dataset in a table view.- Parameters:
- b- new visibility
 
- 
setVisiblepublic void setVisible(boolean b) Sets the visibility of this Dataset in a DrawingPanel. Only visible panels affect autoscaled panels.- Parameters:
- b- new visibility
 
- 
getVisiblepublic boolean getVisible()Gets the visibility of this dataset in the DrawingPanel.- Returns:
- boolean
 
- 
setStridepublic void setStride(int stride) Sets the stride of this Dataset in a table view.
- 
isXColumnVisiblepublic boolean isXColumnVisible()Gets the visibility of the x column of this Dataset in a table view.- Returns:
- the x column visibility
 
- 
isYColumnVisiblepublic boolean isYColumnVisible()Gets the visibility of the y column of this Dataset in a table view.- Returns:
- the x column visibility
 
- 
recalculatePathprotected void recalculatePath()Recalculate the general path.
- 
insertionSortprotected 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
- 
getNaNCountprotected static int getNaNCount(double[] pts, int index) 
- 
getLoaderReturns the XML.ObjectLoader for this class.- Returns:
- the object loader
 
- 
toBoolArray
- 
convertTableColumnIndexConverts 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
- 
getMeanpublic 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)
 
- 
getXpublic double getX(int i) 
 
-