|
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||
java.lang.Object | +--Plotter
Responsible for plotting graphs. As many applets require special
functionality, this class has grown a little too feature-rich.
The first step to improve this class would be to take out some of the
specialised behaviour (such as folding the x-axis) into several subclasses
(the strategy employed with RotatedPlotter).
Plotter2 went some way towards improving this class,
providing extra methods to simplify common tasks; the subclassing
was mostly to break up the code, rather than to separate the
functionality.
| Field Summary | |
protected static double |
ABS_MAX
|
protected static double |
ABS_MIN
|
protected boolean |
axes
true if axes will be drawn, else false |
protected double |
bottomMargin
When scaling to fit, the upper bound of the
y range will be extended by this proportion. |
protected Solvable |
eqn
The Solvable object providing solution data |
protected boolean |
fold
true if the x axis will be folded, else
false |
protected double |
foldSize
The size of the folding interval |
protected boolean |
foldSym
true if the folding interval is centred on the origin,
else false |
boolean |
infY
Set this to true if the y axis is to be infinite. |
protected boolean |
interpolate
true if values will be interpolated, else
false |
protected boolean |
log
true if the vertical scale is logarithmic, else
false |
protected int |
majorTickSize
The length of the line drawn to indicate a major tick |
protected double |
maxX
The maximum x value for which the Solvable
object will be evaluated. |
protected double |
maxY
The maximum y value to be included on the graph |
protected int |
minorTickSize
The length of the line drawn to indicate a minor tick |
protected double |
minX
The minimum x value for which the Solvable
object will be evaluated. |
protected double |
minY
The minimum y value to be included on the graph |
boolean |
noUnitsX
Set this to true to suppress numerical labels, but still
draw the main label for the axis. |
boolean |
noUnitsY
Set this to true to suppress numerical labels, but still
draw the main label for the axis. |
protected double |
rangeX
The difference maxX - minX |
protected double |
rangeY
The difference maxY - minY |
protected double[] |
soln
The cache of graph data to be plotted |
protected int |
tickRatio
The number of minor ticks per major tick |
protected double |
topMargin
When scaling to fit, the upper bound of the
y range will be extended by this proportion. |
protected double |
viewLeft
The minimum x value to be included on the graph |
protected double |
viewRange
The difference viewRight - viewLeft |
protected double |
viewRight
The maximum x value to be included on the graph |
protected GraphLabel |
xLabel
The main label for the x axis |
protected boolean |
xScale
true if the horizontal scale will be drawn, else
false |
protected GraphLabel |
yLabel
The main label for the y axis |
protected boolean |
yScale
true if the vertical scale will be drawn, else
false |
| Constructor Summary | |
Plotter(Solvable s)
Creates a new plotter to graph the specifed Solvable object. |
|
| Method Summary | |
protected double |
chooseTickSize(double range)
Attempts to calculate an approprite tick size (distance between minor ticks) based on the size of the axis. |
void |
copyScale(Plotter p)
Sets the view range, x range and y range of this plotter according to the settings of another. |
protected double |
fold(double x,
double f,
boolean sym)
Returns the folded version of an x coordinate. |
double |
fromScreenX(int x,
int w)
Converts the specified x value from screen space to graph space |
double |
fromScreenY(int y,
int h)
Converts the specified y value from screen space to graph space |
protected static double |
getMax(double[] vals,
int left,
int right)
Returns the maximum value from an array |
protected static double |
getMin(double[] vals,
int left,
int right)
Returns the minimum value from an array |
int |
getSpaceX(java.awt.FontMetrics fm)
Calculates the size of the gap between the left edge of the display and the start of the actual graph area. |
int |
getSpaceY(java.awt.FontMetrics fm)
Calculates the size of the gap between the bottom edge of the display and the start of the actual graph area. |
boolean |
isInterpolated()
Returns true if y values between samples will be
interpolated, else false |
boolean |
isLogarithmic()
Returns whether graph data should be log()'d before plotting |
void |
labelAxisX(java.awt.Graphics g,
int w,
int h)
Labels the x axis. |
void |
labelAxisY(java.awt.Graphics g,
int w,
int h)
Labels the y axis. |
void |
paint(java.awt.Graphics g,
int w,
int h)
Paints the graph, axes and scales. |
void |
paintAxes(java.awt.Graphics g,
int w,
int h)
Paints a set of axes (the lines x=0, y=0). |
void |
paintGraph(java.awt.Graphics g,
int w,
int h)
Paints the graph (without scales, labels or axes). |
void |
paintGraphFolded(java.awt.Graphics g,
int w,
int h,
double fold,
boolean sym)
Paints the graph (without scales, labels or axes), with a folded x axis. |
protected void |
paintLabelBelow(java.awt.Graphics g,
java.lang.String s,
int x,
int y)
Paints a string just below the specified point, centred horizontally. |
protected void |
paintLabelToLeft(java.awt.Graphics g,
java.lang.String s,
int x,
int y)
Paints a string just to the left of specified point, centred vertically. |
void |
paintVerticalMarkers(java.awt.Graphics g,
int w,
int h,
double[] markers)
Plots vertical markers at the specified coordinates. |
protected void |
scaleToFit()
Adjusts the minY, maxY and
rangeY parameters so that the y axis range
is set to the minimum interval into which all graph data falls. |
protected void |
scaleToFit(int left,
int right)
Adjusts the minY, maxY and
rangeY parameters so that the y axis range
is set to the minimum interval into which all graph data within
the specified interval falls. |
protected void |
setAxes(boolean b)
Set to true if axes (x = 0, y = 0) should
be displayed, else false |
protected void |
setFold(boolean b)
Used to enable or disable folding |
protected void |
setFold(boolean b,
double size,
boolean sym)
Used to enable or disable folding, and sets the folding parameters. |
protected void |
setFold(double size,
boolean sym)
Enables folding, and sets the folding parameters. |
void |
setInterpolated(boolean b)
Set to true if y values between samples should be
interpolated, else false |
protected void |
setLabels(java.lang.String x,
java.lang.String y)
Sets the labels for the axes. |
void |
setLogarithmic(boolean b)
Sets whether graph data should be log()'d before plotting |
void |
setRangeX(double min,
double max)
Sets the range for the x axis. |
void |
setRangeY(double min,
double max)
Sets the portion of the x axis displayed on the graph. |
protected void |
setScalesEnabled(boolean x,
boolean y)
Enables or disables the x and y scales |
void |
setView(double min,
double max)
Sets the portion of the x axis displayed on the graph. |
void |
setViewAndRange(double min,
double max)
Combines a call to setView() and
setRangeX(), passing the same
interval bounds to each. |
protected double |
snap(double d,
double base)
Helper method to round off d to the nearest multiple of
base |
protected void |
squareValues()
Convenience method to square all the y values. |
int |
toScreenX(double x,
int w)
Converts the specified x value from graph space to screen space |
int |
toScreenY(double y,
int h)
Converts the specified y value from graph space to screen space |
protected java.lang.String |
toString(double d)
Convenience method to format a double for display. |
protected void |
updateSolution(int steps)
Updates this plotter's cache of solution data. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
protected int minorTickSize
protected int majorTickSize
protected int tickRatio
protected boolean log
true if the vertical scale is logarithmic, else
falseprotected boolean interpolate
true if values will be interpolated, else
falseprotected boolean axes
true if axes will be drawn, else falseprotected boolean xScale
true if the horizontal scale will be drawn, else
falseprotected boolean yScale
true if the vertical scale will be drawn, else
falseprotected boolean fold
true if the x axis will be folded, else
falseprotected boolean foldSym
true if the folding interval is centred on the origin,
else falsepublic boolean noUnitsX
true to suppress numerical labels, but still
draw the main label for the axis.public boolean noUnitsY
true to suppress numerical labels, but still
draw the main label for the axis.public boolean infY
true if the y axis is to be infinite.
A messy hack; if a graph is to be scaled to fit, and the data is known
to become infinite, setting this flag will provide a meaningful label
(eg. "Infinity") on the y axis.protected GraphLabel xLabel
protected GraphLabel yLabel
protected double[] soln
protected Solvable eqn
protected double foldSize
protected double topMargin
scaling to fit, the upper bound of the
y range will be extended by this proportion.protected double bottomMargin
scaling to fit, the upper bound of the
y range will be extended by this proportion.protected double minX
Solvable
object will be evaluated.protected double maxX
Solvable
object will be evaluated.protected double viewLeft
protected double viewRight
protected double minY
protected double maxY
protected double viewRange
viewRight - viewLeftprotected double rangeX
maxX - minXprotected double rangeY
maxY - minYprotected static double ABS_MIN
protected static double ABS_MAX
| Constructor Detail |
public Plotter(Solvable s)
| Method Detail |
public void paintVerticalMarkers(java.awt.Graphics g,
int w,
int h,
double[] markers)
g - The Graphics surface on which to paintw - The width (in pixels) of the available display areah - The height (in pixels) of the available display areamarkers - An array of x coordinates at which markers
public void paintAxes(java.awt.Graphics g,
int w,
int h)
g - The Graphics surface on which to paintw - The width (in pixels) of the available display areah - The height (in pixels) of the available display area
public void labelAxisX(java.awt.Graphics g,
int w,
int h)
g - The Graphics surface on which to paintw - The width (in pixels) of the available display areah - The height (in pixels) of the available display area
public void labelAxisY(java.awt.Graphics g,
int w,
int h)
g - The Graphics surface on which to paintw - The width (in pixels) of the available display areah - The height (in pixels) of the available display area
protected void paintLabelBelow(java.awt.Graphics g,
java.lang.String s,
int x,
int y)
protected void paintLabelToLeft(java.awt.Graphics g,
java.lang.String s,
int x,
int y)
protected java.lang.String toString(double d)
double for display.
Implementation is via a call to BaseApplet2.toString().
public void paint(java.awt.Graphics g,
int w,
int h)
g - The Graphics surface on which to paintw - The width (in pixels) of the available display areah - The height (in pixels) of the available display areapublic int getSpaceX(java.awt.FontMetrics fm)
fm - The FontMetrics with which the graph will be renderedpublic int getSpaceY(java.awt.FontMetrics fm)
fm - The FontMetrics with which the graph will be rendered
public void paintGraph(java.awt.Graphics g,
int w,
int h)
g - The Graphics surface on which to paintw - The width (in pixels) of the available display areah - The height (in pixels) of the available display area
public void paintGraphFolded(java.awt.Graphics g,
int w,
int h,
double fold,
boolean sym)
sym parameter.g - The Graphics surface on which to paintw - The width (in pixels) of the available display areah - The height (in pixels) of the available display areafold - The width (in graph units) of the interval over which
to fold.sym - true if the graph should be folded onto
an interval centred at the origin, else
false
protected double fold(double x,
double f,
boolean sym)
x - The value to foldf - The width (in graph units) of the interval over which
to fold.sym - true if the graph should be folded onto an
interval centred at the origin, else falseprotected void updateSolution(int steps)
steps - The number of x values at which the solution
should be sampledprotected void scaleToFit()
minY, maxY and
rangeY parameters so that the y axis range
is set to the minimum interval into which all graph data falls.
protected void scaleToFit(int left,
int right)
minY, maxY and
rangeY parameters so that the y axis range
is set to the minimum interval into which all graph data within
the specified interval falls.left - The minimum bound for the x-axis intervalright - The maximum bound for the x-axis interval
public int toScreenX(double x,
int w)
x - The valuew - The width (in pixels) of the available display area
public int toScreenY(double y,
int h)
y - The valueh - The height (in pixels) of the available display area
public double fromScreenX(int x,
int w)
x - The valuew - The width (in pixels) of the available display area
public double fromScreenY(int y,
int h)
y - The valueh - The height (in pixels) of the available display area
protected double snap(double d,
double base)
d to the nearest multiple of
base
public void setRangeX(double min,
double max)
setView()), but does determine the
range of values for which the solution is evaluated. For graphs
where the values are not independed (eg. numerical integration), this
is often set larger than than the view range.
public void setView(double min,
double max)
setRange()), but may overlap or be
entirely outside that interval (although it is difficult to think of
a useful application of the latter).
public void setViewAndRange(double min,
double max)
setView() and
setRangeX(), passing the same
interval bounds to each.
public void setRangeY(double min,
double max)
public void copyScale(Plotter p)
p - The plotter, whose example this shall followprotected void squareValues()
public boolean isInterpolated()
true if y values between samples will be
interpolated, else falsepublic void setInterpolated(boolean b)
true if y values between samples should be
interpolated, else false
protected static double getMax(double[] vals,
int left,
int right)
vals - The dataleft - The index at which to begin searchingright - The index at which to stop searching
protected static double getMin(double[] vals,
int left,
int right)
vals - The dataleft - The index at which to begin searchingright - The index at which to stop searchingprotected double chooseTickSize(double range)
Bug: does not take size of display area into account
range - The size of the axisprotected void setAxes(boolean b)
true if axes (x = 0, y = 0) should
be displayed, else false
protected void setLabels(java.lang.String x,
java.lang.String y)
x - The label for the x axisy - The label for the y axis
protected void setScalesEnabled(boolean x,
boolean y)
x - true if the x axis is to have a scaley - true if the y axis is to have a scaleprotected void setFold(boolean b)
protected void setFold(boolean b,
double size,
boolean sym)
b - true if folding should be enabled, else
falsesize - The size of interval over which to foldsym - true if the interval extends in both
directions from the origin, else false
protected void setFold(double size,
boolean sym)
size - The size of interval over which to foldsym - true if the interval extends in both
directions from the origin, else falsepublic boolean isLogarithmic()
public void setLogarithmic(boolean b)
|
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||