Package org.faceless.graph
Class LineGraph
- java.lang.Object
-
- org.faceless.graph.Graph
-
- org.faceless.graph.AxesGraph
-
- org.faceless.graph.AbstractLineGraph
-
- org.faceless.graph.LineGraph
-
public class LineGraph extends AbstractLineGraph
A subclass of AbstractLineGraph that plots one or more separate curves - a typical Line Graph.
This class changes the default for
optionXAxisAtZero
andoptionYAxisAtZero
to true.Here is a simple example that graphs two curves - the first, a set of datapoints defined by a
DataCurve
, the second aSpline
curve that's fitted to theDataCurve
.import org.faceless.graph.output.ImageOutput; import org.faceless.graph.math.*; import java.awt.Color; // Create a simple datacurve with 4 points. // DataCurve data = new DataCurve(); data.set(1,10); data.set(2,15); data.set(3,8); data.set(5,11); // Plot the data in red on a linegraph, with a diamond // at each point. // LineGraph g = new LineGraph(); g.setCurve("My Data", data, Color.red); g.setCurveMarker("My Data", LineGraph.MARKER_DIAMOND); // Add a "smoothed" version of this DataCurve in green. // Curve smooth = new Spline(Spline.CATMULLROM, data); g.setCurve("Smoothed Data", smooth, Color.green); // Add a title to the graph // g.optionTitle("My First Line Graph"); // Render to an image that's 400x400 // ImageOutput out = new ImageOutput(400,400); out.render(g);
-
-
Field Summary
Fields Modifier and Type Field Description static int
KEY_SHOW_MARKERS
If markers are to be displayed on the key, add this value to the parameter passed toGraph.optionDisplayKey(int)
.static int
MARKER_BIG
Add this value to the marker type to double the size of the marker.static int
MARKER_CIRCLE
A marker in the shape of a circlestatic int
MARKER_DIAMOND
A marker in the shape of a diamondstatic int
MARKER_DOWNTRIANGLE
A marker in the shape of a triangle pointing downstatic int
MARKER_LINE
A marker that looks like a join in the line.static int
MARKER_NOBORDER
Add this value to the marker type to remove the border from around the marker.static int
MARKER_NONE
No marker at all.static int
MARKER_OCTAGON
A marker in the shape of an octagonstatic int
MARKER_SMALL
Add this value to the marker type to reduce the size of the marker.static int
MARKER_SQUARE
A marker in the shape of a squarestatic int
MARKER_UPTRIANGLE
A marker in the shape of a triangle pointing upstatic int
MARKERS_ONLY
A special type of marker indicator that should be OR'ed with the marker type to indicate that only markers should be drawn - i.e. no lines, just markers.-
Fields inherited from class org.faceless.graph.AbstractLineGraph
maxval, maxx, minval, minx
-
Fields inherited from class org.faceless.graph.AxesGraph
absolutemaxy, absoluteminy, axesmaxx, axesmaxy, axesmaxz, axesminx, axesminy, axesminz, axesstyle, boxstyle, data, xaxeslabelstyle, xaxestextstyle, xfloat, xformatter, xwallstyle, yaxeslabelstyle, yaxestextstyle, yfloat, yformatter, ywallstyle, zaxestextstyle, zfloat, zformatter, zwallstyle
-
Fields inherited from class org.faceless.graph.Graph
canvas, key, KEY_BOXED_BOTTOM, KEY_BOXED_LEFT, KEY_BOXED_RIGHT, KEY_BOXED_TOP, KEY_NONE, keyboxstyle, keypadding, keystyle, keytype, subtitle, subtitlestyle, title, titlepadding, titlestyle, xrotation, yrotation, zrotation
-
-
Constructor Summary
Constructors Constructor Description LineGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
complete()
Complete is the first method that's called by a Graph when it's rendered.void
optionLineThickness(double val)
Set the "thickness" of the lines when drawing two-dimensional graphs.protected double
plotLine(int set, Curve c, double prevlastval, double prevval, double lastx, double x, double linewidth, boolean isLast, java.util.Map m)
Actually plot the line.protected void
postDrawLines()
void
setCurveMarker(java.lang.String name, int marker)
Set a marker to show significant points on the curve Not all points have significant points, but forDataCurve
curves there is a significant point at each data item.-
Methods inherited from class org.faceless.graph.AbstractLineGraph
optionCurveDepth, optionFunctionSmoothness, optionMaxDataPoints, optionMaxX, optionMinX, setCurve, setCurve
-
Methods inherited from class org.faceless.graph.AxesGraph
optionAxisStyle, optionBoxColor, optionFloorStyle, optionMaxY, optionMinY, optionXAxisAtZero, optionXAxisLabel, optionXAxisLabelStyle, optionXAxisStyle, optionXAxisTextRotation, optionXFormatter, optionXStretchToZero, optionYAxisAtZero, optionYAxisLabel, optionYAxisLabelStyle, optionYAxisStyle, optionYAxisTextRotation, optionYFormatter, optionYStretchToZero, optionYWallStyle, optionZAxisStyle, optionZFormatter, optionZWallStyle, postcomplete, postpostcomplete, prescalecomplete
-
Methods inherited from class org.faceless.graph.Graph
addElement, getDefaultBorderColor, getFontScale, optionDisplayKey, optionFixedAspectRatio, optionKeyBoxStyle, optionKeyStyle, optionRemoveBackFace, optionSubTitle, optionSubTitleStyle, optionTitle, optionTitleStyle, optionXRotation, optionYRotation, optionZRotation, setDefaultBorderColor, setDefaultColors, setDefaultLineThickness, setFontScale, setLicenseKey, setLightLevel, setLightVector, setPieEdgeDegrees, toCanvas
-
-
-
-
Field Detail
-
KEY_SHOW_MARKERS
public static final int KEY_SHOW_MARKERS
If markers are to be displayed on the key, add this value to the parameter passed toGraph.optionDisplayKey(int)
. For example,linegraph.optionDisplayKey(Graph.KEY_BOXED_BOTTOM + LineGraph.KEY_SHOW_MARKERS)
- Since:
- 1.0.7
- See Also:
- Constant Field Values
-
MARKER_NONE
public static final int MARKER_NONE
No marker at all.- See Also:
- Constant Field Values
-
MARKER_CIRCLE
public static final int MARKER_CIRCLE
A marker in the shape of a circle- Since:
- 1.0.10
- See Also:
- Constant Field Values
-
MARKER_SQUARE
public static final int MARKER_SQUARE
A marker in the shape of a square- See Also:
- Constant Field Values
-
MARKER_OCTAGON
public static final int MARKER_OCTAGON
A marker in the shape of an octagon- See Also:
- Constant Field Values
-
MARKER_DIAMOND
public static final int MARKER_DIAMOND
A marker in the shape of a diamond- See Also:
- Constant Field Values
-
MARKER_LINE
public static final int MARKER_LINE
A marker that looks like a join in the line. This is the default.- See Also:
- Constant Field Values
-
MARKER_UPTRIANGLE
public static final int MARKER_UPTRIANGLE
A marker in the shape of a triangle pointing up- Since:
- 1.0.7
- See Also:
- Constant Field Values
-
MARKER_DOWNTRIANGLE
public static final int MARKER_DOWNTRIANGLE
A marker in the shape of a triangle pointing down- Since:
- 1.0.7
- See Also:
- Constant Field Values
-
MARKER_BIG
public static final int MARKER_BIG
Add this value to the marker type to double the size of the marker. For example,setCurveMarker("mycurve", MARKER_SQUARE+MARKER_BIG)
- Since:
- 1.0.7
- See Also:
- Constant Field Values
-
MARKER_SMALL
public static final int MARKER_SMALL
Add this value to the marker type to reduce the size of the marker. For example,setCurveMarker("mycurve", MARKER_SQUARE+MARKER_SMALL)
- Since:
- 1.0.10
- See Also:
- Constant Field Values
-
MARKER_NOBORDER
public static final int MARKER_NOBORDER
Add this value to the marker type to remove the border from around the marker. For example,setCurveMarker("mycurve", MARKER_CIRCLE+MARKER_NOBORDER)
- Since:
- 1.0.10
- See Also:
- Constant Field Values
-
MARKERS_ONLY
public static final int MARKERS_ONLY
A special type of marker indicator that should be OR'ed with the marker type to indicate that only markers should be drawn - i.e. no lines, just markers. This needs to be used with SQUARES, OCTAGONS, DIAMONDS, CIRCLES and TRIANGLES only - the line will simply disappear if it's used with any other type. For example, to draw a small circle at each point but no line inbetween, do:setCurveMarker("mycurve", MARKER_CIRCLE+MARKER_SMALL+MARKERS_ONLY)
- See Also:
- Constant Field Values
-
-
Method Detail
-
setCurveMarker
public void setCurveMarker(java.lang.String name, int marker)
Set a marker to show significant points on the curve Not all points have significant points, but forDataCurve
curves there is a significant point at each data item. Whether a marker is plotted depends on the value passed to this function.- Parameters:
name
- The name of the curvemarker
- The type if marker. Can beMARKER_NONE
,MARKER_LINE
(the default),MARKER_SQUARE
,MARKER_CIRCLE
MARKER_DIAMOND
,MARKER_OCTAGON
,MARKER_UPTRIANGLE
orMARKER_DOWNTRIANGLE
-
optionLineThickness
public void optionLineThickness(double val)
Set the "thickness" of the lines when drawing two-dimensional graphs. This has no effect if the graph is rotated in the X or Y direction, and may not be supported by all subclasses ofOutput
. It's mainly intended for plotting graphs to high-resolution output devices like PDF or PostScript.
-
complete
protected void complete()
Description copied from class:Graph
Complete is the first method that's called by a Graph when it's rendered. It should take the data from the dataset and add the various elements that it needs to the Graph. The first thing it should do, however, is callsuper.complete()
.
-
plotLine
protected double plotLine(int set, Curve c, double prevlastval, double prevval, double lastx, double x, double linewidth, boolean isLast, java.util.Map m)
Description copied from class:AbstractLineGraph
Actually plot the line. This method needs to be filled in by concrete subclasses of this class. This method must handleNaN
and Infinite values. All current subclasses deal with these by skipping those points and leaving a gap in the line.- Specified by:
plotLine
in classAbstractLineGraph
- Parameters:
set
- The number of the set that's being plottedc
- The curve that's being plottedprevlastval
- The value returned by the last X value from the previous set. Set toDouble.NaN
if there was no previous set, or no last X value.prevval
- The value returned by this X value from the previous set. Set toDouble.NaN
if no previous set.lastx
- The last X value passed in. Set toDouble.NaN
if no previous X value exists.x
- The current X value.linewidth
- The width (or rather depth) of the line to be plotted.isLast
- Whether this X value is the last value in the set.m
- A map which can be used by plotLine to pass data between other calls to plotLine. A common use is to set a "start" value if this is the first X value in the set.
-
postDrawLines
protected void postDrawLines()
- Overrides:
postDrawLines
in classAbstractLineGraph
-
-