Class Graph
- java.lang.Object
-
- org.faceless.graph.Graph
-
public abstract class Graph extends Object
The abstract base class for all Graphs in the
org.faceless.graphpackage.This class controls the building and rendering of the graph, adding the key and any annotations if necessary and rotating or scaling it as required. It doesn't contain any information about how to lay out the data - this is all taken care of by it's subclasses.
All the types of Graph in the package have certain things in common.
All the graphs are fully 3D. By default they are seen head-on and so look two-dimensional, but can be rotated to any angle to give a 3D effect by calling
optionXRotationand it's friends.They all have data added two them in one of two ways - for discrete data, via the
set()method, and for continuous data via thesetCurve()method. The exact forms of these methods vary from subclass to subclass. The order in which the subsets appear on the Graph is the same as the order in which they were first specified.The look of the Graphs is controlled by calling the
optionmethods, which an be used to set titles, axes labels and so on. As the name implies all of these methods are optional, and don't have to be called to create a Graph.Finally, all the graphs when complete are sent to an output device - be it a PDF document, a
java.awt.Imageor a specific image format. This is done with therender()methodConcrete subclasses in this release are the
PieGraph,BarGraph,TowerBarGraph,DepthBarGraph,LineGraph,AreaGraphandFloatingBarGraph, and more will be added in future releases.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.faceless.graph.Canvascanvasprotected org.faceless.graph.Keykeystatic intKEY_BOXED_BOTTOMThe Graph should have a key in a box at the bottom of the outputstatic intKEY_BOXED_LEFTThe Graph should have a key in a box to the left of the outputstatic intKEY_BOXED_RIGHTThe Graph should have a key in a box to the right of the outputstatic intKEY_BOXED_TOPThe Graph should have a key in a box above the outputstatic intKEY_NONEThe Graph should have no key at allprotected Stylekeyboxstyleprotected doublekeypaddingprotected Stylekeystyleprotected intkeytypeprotected Stringsubtitleprotected Stylesubtitlestyleprotected Stringtitleprotected doubletitlepaddingprotected Styletitlestyleprotected doublexrotationprotected doubleyrotationprotected doublezrotation
-
Constructor Summary
Constructors Modifier Constructor Description protectedGraph()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddElement(org.faceless.graph.Element e)This is the method used to add an Element to the graph.protected voidcomplete()Complete is the first method that's called by a Graph when it's rendered.ColorgetDefaultBorderColor()Returns the value set bysetDefaultBorderColor(java.awt.Color)doublegetFontScale()Return the current font scale.voidoptionDisplayKey(int val)What type of external key to display on the graph.voidoptionFixedAspectRatio(boolean val)Whether this graph should have a fixed aspect ratio.voidoptionKeyBoxStyle(Style val)The Style to give to the box holding the external key.voidoptionKeyStyle(Style val)The Style to give to the text used in the external keyprotected voidoptionRemoveBackFace(boolean val)Whether this graph should have the back-faces of polygons removed for faster rendering.voidoptionSubTitle(String val)The sub-title to give the graphvoidoptionSubTitleStyle(Style val)The Style to give to the sub-title of the graphvoidoptionTitle(String val)The title to give the graphvoidoptionTitleStyle(Style val)The Style to give to the title of the graphvoidoptionXRotation(double val)How far to rotate the graph around the X-axis (the line running from the left of the graph to the right), in degrees.voidoptionYRotation(double val)How far to rotate the graph around the Y-axis (the line running from the top of the graph to the bottom), in degrees.voidoptionZRotation(double val)How far to rotate the graph around the Z-axis (the line running from the front of the graph to the back), in degrees.protected voidpostcomplete()PostComplete is called by a Graph when it's rendered, but after complete.protected voidpostpostcomplete()The unfortunately named PostPostComplete is called last of all by a Graph when it's rendered, to add anything that couldn't quite be laid out correctly on the last pass - usually Text dependant on the position of other text.voidsetDefaultBorderColor(Color c)This method changes the default border color of new styles.voidsetDefaultColors(Paint[] colors)Set the default colors for the graph.voidsetDefaultLineThickness(double thickness)Set the default line thickness for all styles. 1 is the default, 0.5 is half as thick, and so on.voidsetFontScale(double val)Every text element that's created may have it's font automatically scaled up or down by a percentage by setting a different fontscale.static voidsetLicenseKey(String skey)Set the license key for the library.voidsetLightLevel(int level)Set the level of light (technically, the level of shade) that should be applied to a graph.voidsetLightVector(int x, int y, int z)Set the vector of where the light is coming from.voidsetPieEdgeDegrees(double val)Adjust the number of degrees taken by each of the small faces used to draw the edge of a PieGraph.voidtoCanvas(Output o)starts the conversion of the graph from values added through theset()orsetCurve()methods to anOutput.
-
-
-
Field Detail
-
canvas
protected org.faceless.graph.Canvas canvas
-
key
protected org.faceless.graph.Key key
-
keyboxstyle
protected Style keyboxstyle
-
keystyle
protected Style keystyle
-
titlestyle
protected Style titlestyle
-
subtitlestyle
protected Style subtitlestyle
-
title
protected String title
-
subtitle
protected String subtitle
-
keytype
protected int keytype
-
xrotation
protected double xrotation
-
yrotation
protected double yrotation
-
zrotation
protected double zrotation
-
titlepadding
protected double titlepadding
-
keypadding
protected double keypadding
-
KEY_NONE
public static final int KEY_NONE
The Graph should have no key at all- See Also:
- Constant Field Values
-
KEY_BOXED_BOTTOM
public static final int KEY_BOXED_BOTTOM
The Graph should have a key in a box at the bottom of the output- See Also:
- Constant Field Values
-
KEY_BOXED_RIGHT
public static final int KEY_BOXED_RIGHT
The Graph should have a key in a box to the right of the output- See Also:
- Constant Field Values
-
KEY_BOXED_LEFT
public static final int KEY_BOXED_LEFT
The Graph should have a key in a box to the left of the output- See Also:
- Constant Field Values
-
KEY_BOXED_TOP
public static final int KEY_BOXED_TOP
The Graph should have a key in a box above the output- See Also:
- Constant Field Values
-
-
Method Detail
-
addElement
protected final void addElement(org.faceless.graph.Element e)
This is the method used to add an Element to the graph. It is usually called by subclasses of Graph, but is public in case developers want to add their own objects.
-
setDefaultColors
public void setDefaultColors(Paint[] colors)
Set the default colors for the graph. Each new element that is added will use the next color in this list - if there are no unused colors left, the list is reset to the beginning.
-
optionTitle
public void optionTitle(String val)
The title to give the graphDefault: empty string
-
optionSubTitle
public void optionSubTitle(String val)
The sub-title to give the graphDefault: empty string
-
optionTitleStyle
public void optionTitleStyle(Style val)
The Style to give to the title of the graphDefault: Black 16pt Helvetica
-
optionSubTitleStyle
public void optionSubTitleStyle(Style val)
The Style to give to the sub-title of the graphDefault: Black 12pt Helvetica
-
optionXRotation
public void optionXRotation(double val)
How far to rotate the graph around the X-axis (the line running from the left of the graph to the right), in degrees.Default: 0
-
optionYRotation
public void optionYRotation(double val)
How far to rotate the graph around the Y-axis (the line running from the top of the graph to the bottom), in degrees.Default: 0
-
optionZRotation
public void optionZRotation(double val)
How far to rotate the graph around the Z-axis (the line running from the front of the graph to the back), in degrees.Default: 0
-
optionDisplayKey
public void optionDisplayKey(int val)
What type of external key to display on the graph. Valid options for all graphs includeKEY_NONE,KEY_BOXED_BOTTOM,KEY_BOXED_RIGHT,KEY_BOXED_LEFTandKEY_BOXED_TOP, and subclasses (in particular thePieGraphmay have additional values available.Default: Usually
KEY_BOXED_BOTTOM, but may vary for subclasses
-
optionKeyStyle
public void optionKeyStyle(Style val)
The Style to give to the text used in the external keyDefault: Black 10pt Helvetica
-
optionKeyBoxStyle
public void optionKeyBoxStyle(Style val)
The Style to give to the box holding the external key. Only used if theoptionDisplayKeyis set to a variety ofBOXEDDefault: Color #FFFFE0, with a black border
-
optionFixedAspectRatio
public void optionFixedAspectRatio(boolean val)
-
optionRemoveBackFace
protected void optionRemoveBackFace(boolean val)
Whether this graph should have the back-faces of polygons removed for faster rendering.Default: false for subclass
LineGraph, true otherwise
-
complete
protected void complete()
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().
-
postcomplete
protected void postcomplete()
PostComplete is called by a Graph when it's rendered, but after complete. It should add any elements that are required but couldn't be calculated until aftercomplete()(the axes in an axes graph are an example). The last thing it should do before returning is callsuper.postcomplete()
-
postpostcomplete
protected void postpostcomplete()
The unfortunately named PostPostComplete is called last of all by a Graph when it's rendered, to add anything that couldn't quite be laid out correctly on the last pass - usually Text dependant on the position of other text. The last thing it should do before returning is callsuper.postpostcomplete()
-
toCanvas
public final void toCanvas(Output o)
starts the conversion of the graph from values added through the
set()orsetCurve()methods to anOutput.- Parameters:
o- theOutputto pain the graph onto.
-
setLicenseKey
public static void setLicenseKey(String skey)
Set the license key for the library. When the library is purchased, the Big Faceless Organization supplies a key which disables the 30-day use restriction.- Parameters:
skey- the license key
-
setFontScale
public void setFontScale(double val)
Every text element that's created may have it's font automatically scaled up or down by a percentage by setting a different fontscale. This was intended for subclasses ofOutput, so those that use a totally different scaling can set it in one go. But it's useful for the end user too. The default is 1, and a value of 0.5 would make all the text half the original size.Replaces the equivalent static method in the Style class
- Since:
- 1.0.3
-
getFontScale
public double getFontScale()
Return the current font scale. SeesetFontScale(double)Replaces the equivalent static method in the Style class
- Since:
- 1.0.3
-
setLightLevel
public void setLightLevel(int level)
Set the level of light (technically, the level of shade) that should be applied to a graph. A value of 0 is no shading at all, a value of 100 gives deep shadows. The default is 70.Replaces the equivalent static method in the Style class
- Since:
- 1.0.3
-
setLightVector
public void setLightVector(int x, int y, int z)Set the vector of where the light is coming from. The light is assumed to be coming from an infinite distance away in the specified direction, so don't worry about the length of the vector. The default is (1,0,0), which makes the light appear to come from the right side of the graph. Callinggraph.setLightVector(-1,0,1)would put the light to the left and in front of the graph, while a vector (0,-1,0) would put the light directly underneath the graph, for a strange result indeed.Replaces the equivalent static method in the Style class
- Since:
- 1.0.3
-
setDefaultBorderColor
public void setDefaultBorderColor(Color c)
This method changes the default border color of new styles. By default, this is set to black, but it can be set to null for a different look, or a different color altogether. This is useful if the graph is to be rendered over a black background, for example.Replaces the equivalent static method in the Style class
- Since:
- 1.0.3
-
getDefaultBorderColor
public Color getDefaultBorderColor()
Returns the value set bysetDefaultBorderColor(java.awt.Color)Replaces the equivalent static method in the Style class
- Since:
- 1.0.3
-
setDefaultLineThickness
public void setDefaultLineThickness(double thickness)
Set the default line thickness for all styles. 1 is the default, 0.5 is half as thick, and so on. Not all Output classes can use this option. A value of zero means "make the lines as thin as possible".Replaces the equivalent static method in the Style class
- Since:
- 1.0.3
-
setPieEdgeDegrees
public void setPieEdgeDegrees(double val)
Adjust the number of degrees taken by each of the small faces used to draw the edge of a PieGraph. The higher the number of faces, the less noticeable the "banding" effect will be on the edge of a 3D shaded PieGraph, but at the expense of slower rendering. The default value is 5 degrees.Replaces the equivalent static method in the Style class
- Parameters:
val- the number of degrees per face at the edge of a PieGraph- Since:
- 1.0.3
-
-