|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Panel | +--ptolemy.plot.PlotBox | +--ptolemy.plot.Plot
A flexible signal plotter. The plot can be configured and data can be provided either through a file with commands or through direct invocation of the public methods of the class.
When calling the public methods, in most cases the changes will not be visible until paint() is called. To request that this be done, call repaint(). One exception is addPoint(), which makes the new point visible immediately if the plot is visible on the screen.
This base class supports a simple file syntax that has largely been replaced by the XML-based PlotML syntax. To read a file or a URL in this older syntax, use the read() method. This older syntax contains any number commands, one per line. Unrecognized commands and commands with syntax errors are ignored. Comments are denoted by a line starting with a pound sign "#". The recognized commands include those supported by the base class, plus a few more. The commands are case insensitive, but are usually capitalized. The number of data sets to be plotted does not need to be specified. Data sets are added as needed. Each dataset can be optionally identified with color (see the base class) or with unique marks. The style of marks used to denote a data point is defined by one of the following commands:
Marks: none Marks: points Marks: dots Marks: variousHere, "points" are small dots, while "dots" are larger. If "various" is specified, then unique marks are used for the first ten data sets, and then recycled. Using no marks is useful when lines connect the points in a plot, which is done by default. If the above directive appears before any DataSet directive, then it specifies the default for all data sets. If it appears after a DataSet directive, then it applies only to that data set.
To disable connecting lines, use:
Lines: offTo reenable them, use
Lines: onYou can also specify "impulses", which are lines drawn from a plotted point down to the x axis. Plots with impulses are often called "stem plots." These are off by default, but can be turned on with the command:
Impulses: onor back off with the command
Impulses: offIf that command appears before any DataSet directive, then the command applies to all data sets. Otherwise, it applies only to the current data set. To create a bar graph, turn off lines and use any of the following commands:
Bars: on Bars: width Bars: width, offsetThe width is a real number specifying the width of the bars in the units of the x axis. The offset is a real number specifying how much the bar of the i < /i>th data set is offset from the previous one. This allows bars to "peek out" from behind the ones in front. Note that the frontmost data set will be the first one. To turn off bars, use
Bars: offTo specify data to be plotted, start a data set with the following command:
DataSet: stringHere, string is a label that will appear in the legend. It is not necessary to enclose the string in quotation marks. To start a new dataset without giving it a name, use:
DataSet:In this case, no item will appear in the legend. New datasets are plotted behind the previous ones. If the following directive occurs:
ReuseDataSets: onThen datasets with the same name will be merged. This makes it easier to combine multiple datafiles that contain the same datasets into one file. By default, this capability is turned off, so datasets with the same name are not merged. The data itself is given by a sequence of commands with one of the following forms:
x, y draw: x, y move: x, y x, y, yLowErrorBar, yHighErrorBar draw: x, y, yLowErrorBar, yHighErrorBar move: x, y, yLowErrorBar, yHighErrorBarThe "draw" command is optional, so the first two forms are equivalent. The "move" command causes a break in connected points, if lines are being drawn between points. The numbers x and y are arbitrary numbers as supported by the Double parser in Java. If there are four numbers, then the last two numbers are assumed to be the lower and upper values for error bars. The numbers can be separated by commas, spaces or tabs.
This plotter has some limitations:
_gridInit()
method in the PlotBox class.
Inner classes inherited from class ptolemy.plot.PlotBox |
PlotBox.DragListener,
PlotBox.ZoomListener |
Field Summary | |
protected int |
_currentdataset
|
protected int |
_marks
|
protected boolean |
_painted
|
protected java.util.Vector |
_points
|
Fields inherited from class ptolemy.plot.PlotBox |
_background,
_bottomPadding,
_colors,
_documentBase,
_foreground,
_grid,
_height,
_leftPadding,
_LOG10SCALE,
_lrx,
_lry,
_PADDING,
_rangesGivenByZooming,
_rightPadding,
_topPadding,
_ulx,
_uly,
_usecolor,
_width,
_wrap,
_xBottom,
_xhighgiven,
_xlog,
_xlowgiven,
_xMax,
_xMin,
_xRangeGiven,
_xscale,
_xTop,
_yBottom,
_yhighgiven,
_ylog,
_ylowgiven,
_yMax,
_yMin,
_yRangeGiven,
_yscale,
_yTop |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT,
CENTER_ALIGNMENT,
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
TOP_ALIGNMENT |
Constructor Summary | |
Plot()
|
Method Summary | |
protected void |
_checkDatasetIndex(int dataset)
Check the argument to ensure that it is a valid data set index. |
protected void |
_drawBar(java.awt.Graphics graphics,
int dataset,
long xpos,
long ypos,
boolean clip)
Draw bar from the specified point to the y axis. |
protected void |
_drawErrorBar(java.awt.Graphics graphics,
int dataset,
long xpos,
long yLowEBPos,
long yHighEBPos,
boolean clip)
Draw an error bar for the specified yLowEB and yHighEB values. |
protected void |
_drawImpulse(java.awt.Graphics graphics,
long xpos,
long ypos,
boolean clip)
Draw a line from the specified point to the y axis. |
protected void |
_drawLine(java.awt.Graphics graphics,
int dataset,
long startx,
long starty,
long endx,
long endy,
boolean clip)
Draw a line from the specified starting point to the specified ending point. |
protected void |
_drawPlot(java.awt.Graphics graphics,
boolean clearfirst)
Draw the axes and then plot all points. |
protected void |
_drawPoint(java.awt.Graphics graphics,
int dataset,
long xpos,
long ypos,
boolean clip)
Put a mark corresponding to the specified dataset at the specified x and y position. |
protected boolean |
_parseLine(java.lang.String line)
Parse a line that gives plotting information. |
protected void |
_write(java.io.PrintWriter output)
Write plot information to the specified output stream in PlotML, an XML extension. |
protected void |
_writeOldSyntax(java.io.PrintWriter output)
Deprecated. |
void |
addLegend(int dataset,
java.lang.String legend)
Add a legend (displayed at the upper right) for the specified data set with the specified string. |
void |
addPoint(int dataset,
double x,
double y,
boolean connected)
In the specified data set, add the specified x, y point to the plot. |
void |
addPointWithErrorBars(int dataset,
double x,
double y,
double yLowEB,
double yHighEB,
boolean connected)
In the specified data set, add the specified x, y point to the plot with error bars. |
void |
clear(boolean format)
Clear the plot of all data points. |
void |
clear(int dataset)
Clear the plot of data points in the specified dataset. |
void |
erasePoint(int dataset,
int index)
Erase the point at the given index in the given dataset. |
void |
fillPlot()
Rescale so that the data that is currently plotted just fits. |
boolean |
getConnected()
Return whether the default is to connect subsequent points with a line. |
boolean |
getImpulses()
Return whether a line will be drawn from any plotted point down to the x axis. |
java.lang.String |
getMarksStyle()
Get the marks style, which is one of "none", "points", "dots", or "various". |
int |
getMaxDataSets()
Deprecated. |
int |
getNumDataSets()
Return the actual number of data sets. |
void |
parseFile(java.lang.String filespec,
java.net.URL documentBase)
Deprecated. |
void |
read(java.io.InputStream in)
Read a file with the old syntax (non-XML). |
void |
samplePlot()
Create a sample plot. |
void |
setBars(boolean on)
Turn bars on or off (for bar charts). |
void |
setBars(double width,
double offset)
Turn bars on and set the width and offset. |
void |
setConnected(boolean on)
If the argument is true, then the default is to connect subsequent points with a line. |
void |
setConnected(boolean on,
int dataset)
If the first argument is true, then by default for the specified dataset, points will be connected by a line. |
void |
setImpulses(boolean on)
If the argument is true, then a line will be drawn from any plotted point down to the x axis. |
void |
setImpulses(boolean on,
int dataset)
If the first argument is true, then a line will be drawn from any plotted point in the specified dataset down to the x axis. |
void |
setMarksStyle(java.lang.String style)
Set the marks style to "none", "points", "dots", or "various". |
void |
setMarksStyle(java.lang.String style,
int dataset)
Set the marks style to "none", "points", "dots", or "various" for the specified dataset. |
void |
setNumSets(int numsets)
Deprecated. |
void |
setPointsPersistence(int persistence)
Calling this method with a positive argument sets the persistence of the plot to the given number of points. |
void |
setReuseDatasets(boolean on)
If the argument is true, then datasets with the same name are merged into a single dataset. |
void |
setSweepsPersistence(int persistence)
A sweep is a sequence of points where the value of X is increasing. |
Methods inherited from class ptolemy.plot.PlotBox |
_help,
_setButtonsVisibility,
addXTick,
addYTick,
export,
getColor,
getColorByName,
getDataurl,
getDocumentBase,
getGrid,
getLegend,
getMinimumSize,
getPreferredSize,
getTitle,
getXLabel,
getXLog,
getXRange,
getXTicks,
getYLabel,
getYLog,
getYRange,
getYTicks,
init,
paint,
parseFile,
read,
setBackground,
setBounds,
setButtons,
setColor,
setDataurl,
setDocumentBase,
setForeground,
setGrid,
setLabelFont,
setSize,
setTitle,
setTitleFont,
setWrap,
setXLabel,
setXLog,
setXRange,
setYLabel,
setYLog,
setYRange,
update,
write,
write,
writeOldSyntax,
zoom |
Methods inherited from class java.awt.Panel |
addNotify |
Methods inherited from class java.awt.Container |
add,
add,
add,
add,
add,
addContainerListener,
addImpl,
countComponents,
deliverEvent,
doLayout,
findComponentAt,
findComponentAt,
getAlignmentX,
getAlignmentY,
getComponent,
getComponentAt,
getComponentAt,
getComponentCount,
getComponents,
getInsets,
getLayout,
getMaximumSize,
insets,
invalidate,
isAncestorOf,
layout,
list,
list,
locate,
minimumSize,
paintComponents,
paramString,
preferredSize,
print,
printComponents,
processContainerEvent,
processEvent,
remove,
remove,
removeAll,
removeContainerListener,
removeNotify,
setCursor,
setFont,
setLayout,
validate,
validateTree |
Methods inherited from class java.awt.Component |
action,
add,
addComponentListener,
addFocusListener,
addInputMethodListener,
addKeyListener,
addMouseListener,
addMouseMotionListener,
addPropertyChangeListener,
addPropertyChangeListener,
bounds,
checkImage,
checkImage,
coalesceEvents,
contains,
contains,
createImage,
createImage,
disable,
disableEvents,
dispatchEvent,
enable,
enable,
enableEvents,
enableInputMethods,
firePropertyChange,
getBackground,
getBounds,
getBounds,
getColorModel,
getComponentOrientation,
getCursor,
getDropTarget,
getFont,
getFontMetrics,
getForeground,
getGraphics,
getHeight,
getInputContext,
getInputMethodRequests,
getLocale,
getLocation,
getLocation,
getLocationOnScreen,
getName,
getParent,
getPeer,
getSize,
getSize,
getToolkit,
getTreeLock,
getWidth,
getX,
getY,
gotFocus,
handleEvent,
hasFocus,
hide,
imageUpdate,
inside,
isDisplayable,
isDoubleBuffered,
isEnabled,
isFocusTraversable,
isLightweight,
isOpaque,
isShowing,
isValid,
isVisible,
keyDown,
keyUp,
list,
list,
list,
location,
lostFocus,
mouseDown,
mouseDrag,
mouseEnter,
mouseExit,
mouseMove,
mouseUp,
move,
nextFocus,
paintAll,
postEvent,
prepareImage,
prepareImage,
printAll,
processComponentEvent,
processFocusEvent,
processInputMethodEvent,
processKeyEvent,
processMouseEvent,
processMouseMotionEvent,
remove,
removeComponentListener,
removeFocusListener,
removeInputMethodListener,
removeKeyListener,
removeMouseListener,
removeMouseMotionListener,
removePropertyChangeListener,
removePropertyChangeListener,
repaint,
repaint,
repaint,
repaint,
requestFocus,
reshape,
resize,
resize,
setBounds,
setComponentOrientation,
setDropTarget,
setEnabled,
setLocale,
setLocation,
setLocation,
setName,
setSize,
setVisible,
show,
show,
size,
toString,
transferFocus |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected int _currentdataset
protected java.util.Vector _points
protected int _marks
protected boolean _painted
Constructor Detail |
public Plot()
Method Detail |
public void addLegend(int dataset, java.lang.String legend)
dataset
- The dataset index.legend
- The label for the dataset.public void addPoint(int dataset, double x, double y, boolean connected)
dataset
- The data set index.x
- The X position of the new point.y
- The Y position of the new point.connected
- If true, a line is drawn to connect to the previous
point.public void addPointWithErrorBars(int dataset, double x, double y, double yLowEB, double yHighEB, boolean connected)
dataset
- The data set index.x
- The X position of the new point.y
- The Y position of the new point.yLowEB
- The low point of the error bar.yHighEB
- The high point of the error bar.connected
- If true, a line is drawn to connect to the previous
point.public void clear(boolean format)
format
- If true, clear the format controls as well.public void clear(int dataset)
dataset
- The dataset to clear.public void erasePoint(int dataset, int index)
dataset
- The data set index.index
- The index of the point to erase.public void fillPlot()
public boolean getConnected()
public boolean getImpulses()
on
- If true, draw a stem plot.public java.lang.String getMarksStyle()
public int getMaxDataSets()
public int getNumDataSets()
public void parseFile(java.lang.String filespec, java.net.URL documentBase)
public void read(java.io.InputStream in) throws java.io.IOException
inputstream
- The input stream.public void samplePlot()
public void setBars(boolean on)
on
- If true, turn bars on.public void setBars(double width, double offset)
width
- The width of the bars.offset
- The offset per data set.public void setConnected(boolean on)
public void setConnected(boolean on, int dataset)
on
- If true, draw lines between points.dataset
- The dataset to which this should apply.public void setImpulses(boolean on)
on
- If true, draw a stem plot.public void setImpulses(boolean on, int dataset)
on
- If true, draw a stem plot.dataset
- The dataset to which this should apply.public void setMarksStyle(java.lang.String style)
style
- A string specifying the style for points.public void setMarksStyle(java.lang.String style, int dataset)
style
- A string specifying the style for points.dataset
- The dataset to which this should apply.public void setNumSets(int numsets)
numsets
- The number of data sets.public void setPointsPersistence(int persistence)
public void setReuseDatasets(boolean on)
on
- If true, then merge datasets.public void setSweepsPersistence(int persistence)
protected void _checkDatasetIndex(int dataset)
dataset
- The data set index.protected void _drawBar(java.awt.Graphics graphics, int dataset, long xpos, long ypos, boolean clip)
graphics
- The graphics context.dataset
- The index of the dataset.xpos
- The x position.ypos
- The y position.clip
- If true, then do not draw outside the range.protected void _drawErrorBar(java.awt.Graphics graphics, int dataset, long xpos, long yLowEBPos, long yHighEBPos, boolean clip)
graphics
- The graphics context.dataset
- The index of the dataset.xpos
- The x position.yLowEBPos
- The lower y position of the error bar.yHighEBPos
- The upper y position of the error bar.clip
- If true, then do not draw above the range.protected void _drawImpulse(java.awt.Graphics graphics, long xpos, long ypos, boolean clip)
graphics
- The graphics context.xpos
- The x position.ypos
- The y position.clip
- If true, then do not draw outside the range.protected void _drawLine(java.awt.Graphics graphics, int dataset, long startx, long starty, long endx, long endy, boolean clip)
graphics
- The graphics context.dataset
- The index of the dataset.startx
- The starting x position.starty
- The starting y position.endx
- The ending x position.endy
- The ending y position.clip
- If true, then do not draw outside the range.protected void _drawPlot(java.awt.Graphics graphics, boolean clearfirst)
wait()
to prevent it plotting
points before the axes have been first drawn. If the second
argument is true, clear the display first.
This method is called by paint(). To cause it to be called you
would normally call repaint(), which eventually causes paint() to
be called.graphics
- The graphics context.clearfirst
- If true, clear the plot before proceeding.protected void _drawPoint(java.awt.Graphics graphics, int dataset, long xpos, long ypos, boolean clip)
graphics
- The graphics context.dataset
- The index of the dataset.xpos
- The x position.ypos
- The y position.clip
- If true, then do not draw outside the range.protected boolean _parseLine(java.lang.String line)
line
- A command line.protected void _write(java.io.PrintWriter output)
output
- A buffered print writer.protected void _writeOldSyntax(java.io.PrintWriter output)
output
- A buffered print writer.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |