Logo Search packages:      
Sourcecode: wims version File versions

ptolemy::plot::PlotBox Class Reference

Inheritance diagram for ptolemy::plot::PlotBox:

ptolemy::plot::Histogram ptolemy::plot::Plot ptolemy::plot::EditablePlot ptolemy::plot::PlotLive

List of all members.

Detailed Description

This class provides a labeled box within which to place a data plot. A title, X and Y axis labels, tick marks, and a legend are all supported. Zooming in and out is supported. To zoom in, drag the mouse downwards to draw a box. To zoom out, drag the mouse upward.

The box can be configured either through a file with commands or through direct invocation of the public methods of the class.

When calling the methods, in most cases the changes will not be visible until paintComponent() has been called. To request that this be done, call repaint().

A small set of key bindings are provided for convenience. They are:

These commands are provided in a menu by the PlotFrame class. Note that exporting to the clipboard is not allowed in applets (it used to be), so this will result in an error message.

At this time, the two export commands produce encapsulated postscript tuned for black-and-white printers. In the future, more formats may supported. Exporting to the clipboard and to standard output, in theory, is allowed for applets, unlike writing to a file. Thus, these key bindings provide a simple mechanism to obtain a high-resolution image of the plot from an applet, suitable for incorporation in a document. However, in some browsers, exporting to standard out triggers a security violation. You can use the JDK appletviewer instead.

To read commands from a file or URL, the preferred technique is to use one of the classes in the plotml package. That package supports both PlotML, an XML extension for plots, and a historical file format specific to ptplot. The historical file format is understood by the read() method in this class. The syntax of the historical format, documented below, is rudimentary, and will probably not be extended as ptplot evolves. Nonetheless, we document it here since it is directly supported by this class.

The historical format for the file allows 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:

 TitleText: string
 XLabel: string
 YLabel: string
These commands provide a title and labels for the X (horizontal) and Y (vertical) axes. A string is simply a sequence of characters, possibly including spaces. There is no need here to surround them with quotation marks, and in fact, if you do, the quotation marks will be included in the labels.

The ranges of the X and Y axes can be optionally given by commands like:

 XRange: min, max
 YRange: min, max
The arguments min and max are numbers, possibly including a sign and a decimal point. If they are not specified, then the ranges are computed automatically from the data and padded slightly so that datapoints are not plotted on the axes.

The tick marks for the axes are usually computed automatically from the ranges. Every attempt is made to choose reasonable positions for the tick marks regardless of the data ranges (powers of ten multiplied by 1, 2, or 5 are used). However, they can also be specified explicitly using commands like:

 XTicks: label position, label position, ...
 YTicks: label position, label position, ...
A label is a string that must be surrounded by quotation marks if it contains any spaces. A position is a number giving the location of the tick mark along the axis. For example, a horizontal axis for a frequency domain plot might have tick marks as follows:
 XTicks: -PI -3.14159, -PI/2 -1.570795, 0 0, PI/2 1.570795, PI 3.14159
Tick marks could also denote years, months, days of the week, etc.

The X and Y axes can use a logarithmic scale with the following commands:

 XLog: on
 YLog: on
The grid labels represent powers of 10. Note that if a logarithmic scale is used, then the values must be positive. Non-positive values will be silently dropped. Note further that when using logarithmic axes that the log of input data is taken as the data is added to the plot. This means that
XLog: on
YLog: on
should appear before any data. Also, the value of the XTicks, YTicks, XRange or YRange directives should be in log units. So,
XTicks: 1K 3
will display the string
at the 1000 mark.

By default, tick marks are connected by a light grey background grid. This grid can be turned off with the following command:

 Grid: off
It can be turned back on with
 Grid: on
Also, by default, the first ten data sets are shown each in a unique color. The use of color can be turned off with the command:
 Color: off
It can be turned back on with
 Color: on
Finally, the rather specialized command
 Wrap: on
enables wrapping of the X (horizontal) axis, which means that if a point is added with X out of range, its X value will be modified modulo the range so that it lies in range. This command only has an effect if the X range has been set explicitly. It is designed specifically to support oscilloscope-like behavior, where the X value of points is increasing, but the display wraps it around to left. A point that lands on the right edge of the X range is repeated on the left edge to give a better sense of continuity. The feature works best when points do land precisely on the edge, and are plotted from left to right, increasing in X.

All of the above commands can also be invoked directly by calling the the corresponding public methods from some Java procedure.

This class uses features of JDK 1.2, and hence if used in an applet, it can only be viewed by a browser that supports JDK 1.2, or a plugin.

Edward A. Lee, Christopher Brooks, Contributors: Jun Wu (jwu@inin.com.au), William Wu, Robert Kroeger
PlotBox.java,v 2008/04/01 01:19:02 cxh Exp
Ptolemy II 0.2 .ProposedRating Yellow (cxh) .AcceptedRating Yellow (cxh)

Definition at line 244 of file PlotBox.java.

Public Member Functions

synchronized void addLegend (int dataset, String legend)
synchronized void addXTick (String label, double position)
synchronized void addYTick (String label, double position)
synchronized void clear (boolean axes)
synchronized void clearLegends ()
void deferIfNecessary (Runnable action)
synchronized void export (OutputStream out)
synchronized BufferedImage exportImage (BufferedImage bufferedImage)
synchronized BufferedImage exportImage (BufferedImage bufferedImage, Rectangle rectangle, RenderingHints hints, boolean transparent)
synchronized BufferedImage exportImage (Rectangle rectangle)
synchronized BufferedImage exportImage ()
synchronized void fillPlot ()
boolean getColor ()
Color[] getColors ()
String getDataurl ()
URL getDocumentBase ()
boolean getGrid ()
synchronized String getLegend (int dataset)
synchronized int getLegendDataset (String legend)
Rectangle getPlotRectangle ()
synchronized Dimension getPreferredSize ()
synchronized String getTitle ()
synchronized double[] getXAutoRange ()
synchronized String getXLabel ()
boolean getXLog ()
synchronized double[] getXRange ()
synchronized Vector[] getXTicks ()
synchronized double[] getYAutoRange ()
String getYLabel ()
boolean getYLog ()
synchronized double[] getYRange ()
synchronized Vector[] getYTicks ()
void init ()
synchronized void paintComponent (Graphics graphics)
synchronized void parseFile (String filespec, URL documentBase)
void parseFile (String filespec)
 PlotBox ()
synchronized int print (Graphics graphics, PageFormat format, int index) throws PrinterException
synchronized void read (String command)
synchronized void read (InputStream in) throws IOException
String ReadPlotApplet ()
synchronized void removeLegend (int dataset)
synchronized void renameLegend (int dataset, String newName)
synchronized void resetAxes ()
void samplePlot ()
synchronized void setBackground (Color background)
synchronized void setBounds (int x, int y, int width, int height)
synchronized void setButtons (boolean visible)
synchronized void setColor (boolean useColor)
synchronized void setColors (Color[] colors)
void setDataurl (String filespec)
void setDocumentBase (URL documentBase)
synchronized void setForeground (Color foreground)
synchronized void setGrid (boolean grid)
synchronized void setLabelFont (String name)
synchronized void setPlotRectangle (Rectangle rectangle)
synchronized void setSize (int width, int height)
synchronized void setTitle (String title)
synchronized void setTitleFont (String name)
synchronized void setWrap (boolean wrap)
synchronized void setXLabel (String label)
synchronized void setXLog (boolean xlog)
synchronized void setXRange (double min, double max)
synchronized void setYLabel (String label)
synchronized void setYLog (boolean ylog)
synchronized void setYRange (double min, double max)
synchronized void write (Writer out, String dtd)
synchronized void write (OutputStream out, String dtd)
void write (OutputStream out)
synchronized void writeData (PrintWriter output)
synchronized void writeFormat (PrintWriter output)
synchronized void writeOldSyntax (OutputStream out)
synchronized void zoom (double lowx, double lowy, double highx, double highy)

Static Public Member Functions

static Color getColorByName (String name)

Public Attributes

URL _documentBase = null

Static Public Attributes

static final String PTPLOT_RELEASE = "5.7"

Protected Member Functions

synchronized void _drawPlot (Graphics graphics, boolean clearfirst, Rectangle drawRect)
synchronized void _drawPlot (Graphics graphics, boolean clearfirst)
void _drawPoint (Graphics graphics, int dataset, long xpos, long ypos, boolean clip)
void _help ()
boolean _parseLine (String line)
void _setButtonsVisibility (boolean vis)
void _setPadding (double padding)
void _writeOldSyntax (PrintWriter output)

Protected Attributes

Color _background = Color.white
int _bottomPadding = 5
Color _foreground = Color.black
boolean _grid = true
int _height = 300
int _leftPadding = 10
int _lrx = 100
int _lry = 100
double _padding = 0.05
transient BufferedImage _plotImage = null
int _preferredHeight = 300
int _preferredWidth = 500
transient boolean _rangesGivenByZooming = false
int _rightPadding = 10
Rectangle _specifiedPlotRectangle = null
int _topPadding = 10
int _ulx = 1
int _uly = 1
boolean _usecolor = true
int _width = 500
boolean _wrap = false
double _wrapHigh
double _wrapLow
double _xBottom = Double.MAX_VALUE
double _xhighgiven
boolean _xlog = false
double _xlowgiven
transient double _xMax = 0
transient double _xMin = 0
transient boolean _xRangeGiven = false
double _xscale = 1.0
double _xTop = -Double.MAX_VALUE
double _yBottom = Double.MAX_VALUE
double _yhighgiven
boolean _ylog = false
double _ylowgiven
transient double _yMax = 0
transient double _yMin = 0
transient boolean _yRangeGiven = false
double _yscale = 1.0
double _yTop = -Double.MAX_VALUE

Static Protected Attributes

static Color[] _colors
static final double _LOG10SCALE = 1 / Math.log(10)

Package Functions

void _zoom (int x, int y)
void _zoomBox (int x, int y)
void _zoomStart (int x, int y)

Package Attributes

double _originalXhigh = 0.0
double _originalXlow = 0.0
boolean _originalXRangeGiven = false
double _originalYhigh = 0.0
double _originalYlow = 0.0
boolean _originalYRangeGiven = false

Private Member Functions

RenderingHints _defaultImageRenderingHints ()
int _drawLegend (Graphics graphics, int urx, int ury)
synchronized void _executeDeferredActions ()
String _formatLogNum (double num, int numfracdigits)
String _formatNum (double num, int numfracdigits)
Vector _gridInit (double low, double step, boolean labeled, Vector oldgrid)
double _gridRoundUp (Vector grid, double pos)
double _gridStep (Vector grid, double pos, double step, boolean logflag)
void _measureFonts ()
int _numFracDigits (double num)
int _numIntDigits (double num)
void _parsePairs (String line, boolean xtick)
double _roundUp (double val)
void _setXRange (double min, double max)
void _setYRange (double min, double max)

Private Attributes

boolean _actionsDeferred = false
List _deferredActions
transient boolean _drawn = false
transient String[] _errorMsg
String _filespec = null
transient JButton _fillButton = null
transient JButton _formatButton = null
transient double _gridBase = 0.0
transient int _gridCurJuke = 0
Font _labelFont = null
FontMetrics _labelFontMetrics = null
Vector _legendDatasets = new Vector()
Vector _legendStrings = new Vector()
transient JButton _printButton = null
transient JButton _resetButton = null
Font _superscriptFont = null
FontMetrics _superscriptFontMetrics = null
String _title
Font _titleFont = null
FontMetrics _titleFontMetrics = null
int _xExp = 0
String _xlabel
Vector _xticklabels = null
double _xtickMax = 0.0
double _xtickMin = 0.0
Vector _xticks = null
double _xtickscale = 0.0
int _yExp = 0
String _ylabel
Vector _yticklabels = null
double _ytickMax = 0.0
double _ytickMin = 0.0
Vector _yticks = null
double _ytickscale = 0.0
transient boolean _zoomin = false
transient boolean _zooming = false
transient boolean _zoomout = false
transient int _zoomx = -1
transient int _zoomxn = -1
transient int _zoomy = -1
transient int _zoomyn = -1

Static Private Attributes

static final Color _boxColor = Color.orange


class  ButtonListener
class  CommandListener
class  DragListener
class  ZoomListener

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index