public class Histogram extends PlotBox
When calling the public methods, in most cases the changes will not be visible until paint() has been called. To request that this be done, call repaint(). One exception is addPoint(), which makes the affect of the new point visible immediately (or nearly immediately) if the plot is visible on the screen.
The ASCII format for the file file 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 is identified with a color (see the base class).
The appearance of the histogram can be altered by the following commands:
Bars: width Bars: width, offsetThe width is a real number specifying the width of the bars as a fraction of the bin width. It usually has a value less than or equal to one, and defaults to 0.5. The offset is a real number specifying how much the bar of the i th data set is offset from the previous one. This allows bars to "peek out" from behind the ones in front. It defaults to 0.15. Note that the frontmost data set will be the first one.
The width of each bin of the histogram can be specified using:
BinWidth: widthThis is given in whatever units the data has. By default, each bin is centered at x = nw, where w is the width of the bin and n is an integer. That bin represents values in the range (x - w/2, x + w/2). The alignment of the bins can be changed with the following command:
BinOffset: offsetIf this method is used with argument o, then each bin is centered at x = nw + o, and represents values in the range (x - w/2 + o, x + w/2 + o). So for example, if o = w/2, then each bin represents values from nw to (n + 1)w for some integer n. The default offset is 0.5, half the default bin width.
To 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. The data itself is given by a sequence of numbers, one per line. The numbers are specified as strings that can be parsed by the Double parser in Java. It is also possible to specify the numbers using all the formats accepted by the Plot class, so that the same data may be plotted by both classes. The x data is ignored, and only the y data is used to calculate the histogram.
Yellow (cxh) |
Yellow (cxh) |
PlotBox.ButtonListener, PlotBox.CommandListener, PlotBox.DragListener, PlotBox.ZoomListener
javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
protected int |
_currentdataset
The current dataset.
|
protected java.util.Vector |
_histogram
A vector of histogram data.
|
protected java.util.Vector |
_points
A vector of datasets.
|
_background, _bottomPadding, _colors, _documentBase, _foreground, _grid, _height, _leftPadding, _LOG10SCALE, _lrx, _lry, _originalXhigh, _originalXlow, _originalXRangeGiven, _originalYhigh, _originalYlow, _originalYRangeGiven, _padding, _plotImage, _preferredHeight, _preferredWidth, _rangesGivenByZooming, _rightPadding, _specifiedPlotRectangle, _topPadding, _ulx, _uly, _usecolor, _width, _wrap, _wrapHigh, _wrapLow, _xBottom, _xhighgiven, _xlog, _xlowgiven, _xMax, _xMin, _xRangeGiven, _xscale, _xTop, _yBottom, _yhighgiven, _ylog, _ylowgiven, _yMax, _yMin, _yRangeGiven, _yscale, _yTop, PTPLOT_RELEASE
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
Histogram() |
Modifier and Type | Method and Description |
---|---|
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 |
_drawPlot(java.awt.Graphics graphics,
boolean clearfirst,
java.awt.Rectangle drawRect)
Draw the axes and then plot the histogram.
|
protected boolean |
_parseLine(java.lang.String line)
Parse a line that gives plotting information.
|
protected void |
_resetScheduledTasks()
Reset a scheduled redraw tasks.
|
protected void |
_scheduledRedraw()
Perform a scheduled redraw.
|
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 value)
In the specified data set, add the specified value to the
histogram.
|
void |
addPoint(int dataset,
double x,
double y,
boolean connected)
In the specified data set, add the specified y value to the
histogram.
|
void |
clear(boolean format)
Clear the plot of all data points.
|
void |
exportToPlot(java.io.PrintWriter output,
java.lang.String dtd)
Write plot data information to the specified output stream in PlotML,
but in such a way that the Plot class can read it and reproduce the
histogram.
|
void |
fillPlot()
Rescale so that the data that is currently plotted just fits.
|
void |
samplePlot()
Create a sample plot.
|
void |
setBars(double width,
double offset)
Set the width and offset of the bars.
|
void |
setBinOffset(double offset)
Set the offset of the bins, in whatever units the data are given.
|
void |
setBinWidth(double width)
Set the width of the bins, in whatever units the data are given.
|
void |
setSeed(java.lang.Long seed)
Set the seed of the random number generator used to create
the sample plot.
|
void |
write(java.io.Writer out,
java.lang.String dtd)
Write the current data and plot configuration to the
specified stream in PlotML syntax.
|
void |
writeData(java.io.PrintWriter output)
Write plot data information to the specified output stream in PlotML.
|
void |
writeFormat(java.io.PrintWriter output)
Write plot format information to the specified output stream.
|
_automaticRescale, _drawPlot, _drawPoint, _exportLatexPlotData, _help, _setButtonsVisibility, _setPadding, _timedRepaint, _writeOldSyntax, _zoom, _zoomBox, _zoomStart, addCaptionLine, addXTick, addYTick, clearCaptions, clearLegends, deferIfNecessary, destroy, export, exportImage, exportImage, exportImage, exportImage, exportImage, exportLatex, getCaptions, getColor, getColorByName, getColors, getDataurl, getDocumentBase, getGrid, getLegend, getLegendDataset, getPlotRectangle, getPreferredSize, getTitle, getXAutoRange, getXLabel, getXLog, getXRange, getXTicks, getYAutoRange, getYLabel, getYLog, getYRange, getYTicks, init, paintComponent, parseFile, parseFile, print, read, read, removeLegend, renameLegend, resetAxes, setAutomaticRescale, setBackground, setBackground, setBounds, setButtons, setCaptions, setColor, setColors, setColors, setDataurl, setDocumentBase, setForeground, setForeground, setGrid, setLabelFont, setPlotRectangle, setPlotRectangle, setSize, setTimedRepaint, setTitle, setTitleFont, setWrap, setXLabel, setXLog, setXRange, setYLabel, setYLog, setYRange, write, write, writeOldSyntax, zoom
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
repaint
protected int _currentdataset
protected java.util.Vector _points
protected java.util.Vector _histogram
public void addLegend(int dataset, java.lang.String legend)
addLegend
in interface PlotBoxInterface
addLegend
in class PlotBox
dataset
- The dataset index.legend
- The label for the dataset.PlotBox.renameLegend(int, String)
public void addPoint(int dataset, double value)
In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the point will not be added immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.
dataset
- The data set index.value
- The new value.public void addPoint(int dataset, double x, double y, boolean connected)
dataset
- The data set index.x
- Ignored.y
- The Y position of the new point.connected
- Ignoredpublic void clear(boolean format)
In order to work well with swing and be thread safe, this method actually defers execution to the event dispatch thread, where all user interface actions are performed. Thus, the clear will not be executed immediately (unless you call this method from within the event dispatch thread). All the methods that do this deferring coordinate so that they are executed in the order that you called them.
clear
in interface PlotBoxInterface
clear
in class PlotBox
format
- If true, clear the format controls as well.public void exportToPlot(java.io.PrintWriter output, java.lang.String dtd)
output
- A buffered print writer.dtd
- The DTD, or null to reference the default.public void fillPlot()
fillPlot
in interface PlotBoxInterface
fillPlot
in class PlotBox
public void samplePlot()
samplePlot
in interface PlotBoxInterface
samplePlot
in class PlotBox
public void setBars(double width, double offset)
width
- The width of the bars.offset
- The offset per data set.public void setBinOffset(double offset)
offset
- The bin offset.public void setBinWidth(double width)
width
- The width of the bins.public void setSeed(java.lang.Long seed)
seed
- The seed.samplePlot()
public void write(java.io.Writer out, java.lang.String dtd)
write
in interface PlotBoxInterface
write
in class PlotBox
out
- An output writer.dtd
- The reference (URL) for the DTD, or null to use the
PUBLIC DTD.public void writeData(java.io.PrintWriter output)
writeData
in interface PlotBoxInterface
writeData
in class PlotBox
output
- A buffered print writer.public void writeFormat(java.io.PrintWriter output)
writeFormat
in interface PlotBoxInterface
writeFormat
in class PlotBox
output
- A buffered print writer.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 _drawPlot(java.awt.Graphics graphics, boolean clearfirst, java.awt.Rectangle drawRect)
Note that this is synchronized so that points are not added by other threads while the drawing is occurring. This method should be called only from the event dispatch thread, consistent with swing policy.
protected boolean _parseLine(java.lang.String line)
_parseLine
in class PlotBox
line
- A command line.
It is not synchronized, so its caller should be.protected void _resetScheduledTasks()
_resetScheduledTasks
in class PlotBox
protected void _scheduledRedraw()
_scheduledRedraw
in class PlotBox