|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
cox.jmatt.java.MathTools.demo.gpgdemo.GraphPanel
cox.jmatt.java.MathTools.demo.gpgdemo.BarChartPanel
public class BarChartPanel
This panel generates simple bar charts and line charts. It also provides very fine control over exactly how these graphs appear. There are two distinct modes of operation, three types of graphs and lots of options for each combination.
These are options that are consistent across all modes of operation and graph types. The x- and y-axis can be visible or not independently of each other: the '[]Vertical axis pen' and '[]Horizontal axis pen' checkboxes toggle axis visibility. The pen used for each axis is set in the TextArea beside the checkboxes and these are also consistent. If the y-axis is enabled and the '[]Vertical scale' checkbox is enabled there will be tick marks along the y-axis. The interval between them is mode-dependent, though, so the use of the TextArea beside it is covered later. The '[]Show midpoints' checkbox toggles midpoint/data point visibility for bar graphs and line graphs, respectively.
The 'Graph Pen' TextArea is consistent: this is the pen used to draw the graph. The 'Bar Width:Gap' TextArea deserves special attention. This can be one number or two separated by a colon. A single number is the bar width, two numbers are the bar width and the gap between bars. These numbers are always in raw user units (100 per inch by default). The default value is '50:50' which gives a 50-unit (half-inch) bar followed by a 50-unit (half-inch) gap. This is important for all graph types as it determines horizontal spacing.
The final consistent item is the graph data area. This is the TextArea to the right of the display, just under the 'Graph pen' selector. It is a TextArea containing one or more data lines. Each line can take one of two forms:
There are three types of graphs available: bar charts, line graphs and a thin-bar chart. The bar chart is just that: a plain vanilla bar chart. Each data line generates a rectangular bar with the label centered beneath it. If midpoints are enabled they appear as the midpoint of the top of the bar. All bars and gaps are the same width and the only way to change this is with horizontal spacers.
The thin-bar graph is constructed like a bar graph but with a bar width of zero. Any bar width less than 1 (but greater than zero!) generates this type of graph. The bar intervals are still generated along with the gaps but the 'graph' consists of a vertical line from the x-axis (visible or not) to the midpoint of the (invisible!) bar. For best results use a thick pen for this.
The line graph is calculated like an invisible-bar bar chart. The top midpoints are calculated and connected left to right by line segments. Intervals are calculated using bar width and gaps, but without the bars. As with any graph the midpoints may be shown as (obvious!) points or not.
This is where things get a bit complicated.Bar height and the interpretation of the 'Vertical scale' setting (NOT tick-mark visibility!) depend on the mode
of operation. There are two of these: 'raw' mode and 'relative' mode. In raw mode the bar height is given in raw user units: the vertical scale is exactly
the same as the horizontal scale. Each is defined by the SVGTag
'height=', 'width=' and 'viewBox=' attributes. If the '[]Vertical scale' checkbox
is enabled the value set becomes the (raw-unit) distance between the y-axis tick marks. The first one appears on the x-axis and they move upward as far as
they can. This provides absolute control over bar height but if the margins change the graph can overflow it.
Relative mode is the default and this should NOT be changed without a good reason! In relative mode the 'Vertical scale' setting determines how many units high the y-axis is. If tick marks are enabled they will appear but even if the checkbox is disabled the 'Vertical scale' setting is still used! The default value is '10' which means the vertical axis is ten units, regardless of size or viewBox. The bar heights are given in terms of these relative units hence the graph will scale to the size of its margins. The horizontal axis is, of course, still in raw units.
Since this panel generates unique graphs and not 'just' graph paper its scripting capabilities are extended. The reset()
method resets the
panel to its factory defaults, which includes the demo bars in the graph data area. Scripts can call the clearBars()
method to clear the data
area completely. This is especially useful when combined with the addBar()
method which adds a single line to the area. This allows graph data
to be built up line by line which works well with scripting.
As with all the other classes in the gpgdemo.*
package all GUI elements are totally scriptable too.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Panel |
---|
java.awt.Panel.AccessibleAWTPanel |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary |
---|
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
BarChartPanel()
Standard constructor; nothing special is needed. |
Method Summary | |
---|---|
void |
addBar(double pSize,
java.lang.String pLabel)
Add a bar or horizontal space to the bar area. |
void |
clearBars()
Clear the bar data area. |
void |
drawGraph(int mTop,
int mBot,
int mLeft,
int mRight,
SVGTag theGraph)
Draw the bar/line graph. |
void |
eatPizza(java.util.Properties pPizza,
java.lang.String pPrefix)
This method accepts a Properties object and an optional String prefix and attempts to extract configuration data from it. |
void |
reset()
Reset the panel to its defaults. |
void |
setBarChart(boolean isBarChart)
Select the type of graph to generate: 'true' for a bar chart, 'false' for a line graph. |
void |
setBars(java.lang.String[] pBars)
Set the data for the bars or points. |
void |
setBarWidth(double pWidth,
double pGap)
Set the bar width and space between the bars. |
void |
setEnableAxis(boolean pHoriz,
boolean pVert,
boolean pMidpt)
Enable/disable horizontal and vertical axes and bar midpoint marks. |
void |
setPens(int pGraph,
int pText,
int pVAxis,
int pHAxis)
Set the pens used to draw the graph. |
void |
setRelative(boolean pEnable)
Enable/disable relative spacing. |
void |
setVerticalScale(boolean pEnable,
int pScale)
Set the vertical scale and enable/disable tick marks. |
java.lang.String |
toPizza(java.lang.String pPrefix)
This method extracts the configuration and state information from a generator and produces java.util.Properties -style output. |
Methods inherited from class cox.jmatt.java.MathTools.demo.gpgdemo.GraphPanel |
---|
asDouble, asInt, eatGlobalPizza, getKey, getKey, getPen, getPen, GP_DEBUG, loadPizza, setGPDebug, setGPDebugMode, setKey, setKey |
Methods inherited from class java.awt.Panel |
---|
addNotify, getAccessibleContext |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BarChartPanel()
Method Detail |
---|
public void drawGraph(int mTop, int mBot, int mLeft, int mRight, SVGTag theGraph)
drawGraph
in class GraphPanel
mTop
- The top margin of the drawable area.mBot
- The bottom margin of the drawable area.mLeft
- The left margin.mRight
- The right margin.theGraph
- The SVGTag
on which the drawing is to occur.public void setPens(int pGraph, int pText, int pVAxis, int pHAxis)
pGraph
- The pen used for the bars or graph lines.pText
- The pen used for bar/vertex labels.pVAxis
- The vertical axis pen.pHAxis
- The horizontal axis pen.public void setVerticalScale(boolean pEnable, int pScale)
pEnable
- Enable or disable vertical tick marks.pScale
- The vertical scale value.public void setEnableAxis(boolean pHoriz, boolean pVert, boolean pMidpt)
pHoriz
- Enable/disable horizontal axis.pVert
- Enable/disable vertical axis.pMidpt
- Enable/disable bar midpoints.public void setRelative(boolean pEnable)
public void setBarChart(boolean isBarChart)
public void setBarWidth(double pWidth, double pGap)
pWidth
- The width of the bars on the graph.pGap
- The size of the space between bars.public void setBars(java.lang.String[] pBars)
public void clearBars()
public void addBar(double pSize, java.lang.String pLabel)
Add a bar or horizontal space to the bar area. If 'pSize' is zero or less nothing happens. If the label is null or blank a spacing gap is added.
This is a script-only method.
pSize
- The height of the bar or width of the horizontal space.pLabel
- The bar label, if defined. If null or blank a space is added instead.public void reset()
reset
in class GraphPanel
public java.lang.String toPizza(java.lang.String pPrefix)
GraphPanel
This method extracts the configuration and state information from a generator and produces java.util.Properties
-style output. A String
prefix can be prepended to each key. If 'pPrefix' is not null or blank it will be attached to the front of the key String, separated by a single dot. If
the prefix does not end with a dot one will be supplied automatically.
Use of the prefix allows multiple configurations to be stored in a single file. Also, since each generator has its own unique prefix (separate from the one supplied) multiple generator configs can be stored in a single file.
This is primarily a scripting method. It was developed in order to allow the perfect settings to be saved in a (scripting-) language-agnostic way that was also human-readable. The individual property names are typically Java-fied versions of their GUI labels. If MathTools is run from its JAR and the standard GUI is present the instances exposed to scripts are the ones in the GUI, so setting values in the GUI will affect script output and settings made by the script are reflected in the GUI.
toPizza
in class GraphPanel
pPrefix
- The prefix to prepend to each key. Ignored if null or blank.public void eatPizza(java.util.Properties pPizza, java.lang.String pPrefix)
GraphPanel
This method accepts a Properties
object and an optional String prefix and attempts to extract configuration data from it. It complements
toPizza()
. If 'pPizza' is null or empty nothing happens: the method returns silently. If 'pPrefix' is not null or blank it is used as a prefix
to each key. If the String sent in does not end with a dot one will be supplied automatically. All of the keys requested have default valus that match the
ones on the GUI.
Under normal cirucmstances the generator instances exposed to scripts are the ones in the GUI so changes using one are reflected in the other.
eatPizza
in class GraphPanel
pPizza
- A java.util.Properties
object containing configuration data.pPrefix
- An optional prefix to include with each key. Ignored if null or blank.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |