public abstract class Graph extends Object
The abstract base class for all Graphs in the Big Faceless Graph Library version 2.x. All the types of Graph in the package have certain things in common.
setXRotation(double)
and friends.
draw
method is called to write
the Graph to an Output
, which could be a PNG image, a PDF or similar. Once
it's drawn to an output, it cannot be redrawn.
Currently the two types of Graph available are PieGraph
and AxesGraph
,
and you should see those classes for more information
Modifier and Type | Field and Description |
---|---|
protected org.faceless.graph2.Canvas |
canvas |
static String |
VERSION
The current version of the Graph library.
|
Modifier | Constructor and Description |
---|---|
protected |
Graph() |
Modifier and Type | Method and Description |
---|---|
void |
addKey(Key key,
double x,
double y)
Set a Key on the graph, and position it at the specified location on the Graph.
|
void |
addKey(Key key,
int position)
Set a Key on the graph and position it at the edges of the Output.
|
void |
addText(String text,
TextStyle style)
Add some text to the Graph.
|
void |
draw(Output out)
Draw the Graph to the specified
Output object. |
Point2D |
getActualOffset()
Return the actual centre value used for this graph.
|
double |
getActualZoom()
Return the actual zoom value used for this graph.
|
void |
interrupt()
Interrupt the
draw() method. |
boolean |
isInterrupted()
Return whether the graph has been interrupted before it could be finalized.
|
boolean |
isOverlapping()
Return true if there were any markers overlapping other markers when this
graph was drawn.
|
void |
setAutoColors(Color c1,
Color c2)
Set the Graph to auto-generate colors for its data by adjusting the
hue, saturation and brightness between the two specified colors.
|
void |
setColorOrdering(String order)
Set the order the auto-generated colors are used.
|
void |
setDefaultColors(Paint[] colors)
Set the default colors for the graph.
|
void |
setFixedAspectRatio(boolean val)
Whether this graph should have a fixed aspect ratio.
|
void |
setFixedSize(double zoom,
double x,
double y)
When plotting a number of graphs that are supposed to be exactly
the same size, this method can be used to set the zoom, x and y
position to fixed values, rather than allowing the graph to be
autosized to fit.
|
static void |
setLicenseKey(String key)
Set the license key for the library.
|
void |
setLightLevel(int level)
Set the level of light (technically, the level of shade) that should
be applied to a graph.
|
void |
setLightVector(int x,
int y,
int z)
Set the vector of where the light is coming from.
|
void |
setMetaData(String key,
String value)
Set some descriptive text on the graph.
|
void |
setOption(String key,
String value)
Set an option to fine-tune the graph's rendering.
|
void |
setXRotation(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 clockwise.
|
void |
setYRotation(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 clockwise.
|
void |
setZRotation(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 clockwise.
|
public static final String VERSION
protected org.faceless.graph2.Canvas canvas
public final void setAutoColors(Color c1, Color c2)
c1
- the first Color in the rangec2
- the first Color in the rangepublic void setDefaultColors(Paint[] colors)
colors
- the colors to usepublic void setColorOrdering(String order)
order
- the ordering to use - "value" or anything else to use the defaultpublic void addKey(Key key, int position)
key
- the Key to use on the graphposition
- where to position the Key - a combination of values from the Align
classpublic void addKey(Key key, double x, double y)
key
- the Key to use on the graphx
- the X co-ordinate to position the key, from 0 to 1y
- the Y co-ordinate to position the key, from 0 to 1public void addText(String text, TextStyle style)
Text
class. The alignment of the style
parameter determines where on the graph the
text is displayed.text
- the text to displaystyle
- the style to display the text inpublic void setXRotation(double val)
val
- the rotation to usepublic void setYRotation(double val)
val
- the rotation to usepublic void setZRotation(double val)
NaN
will rotate the graph to
achieve the maximum possible size. This is unlikely to be useful for
any types of Graph other than PieGraphs.val
- the rotation to usepublic void setFixedAspectRatio(boolean val)
val
- whether to have a fixed aspect ratio or not. Default is true for PieGraphs, false otherwise.public void setFixedSize(double zoom, double x, double y)
When plotting a number of graphs that are supposed to be exactly
the same size, this method can be used to set the zoom, x and y
position to fixed values, rather than allowing the graph to be
autosized to fit. Be warned that for some types of graph (eg.
those plotted against a DateAxis
), the values that should
be set here could seem quite 'odd', so a fair amount of experimentation
will be required to find appropriate values for each graph.
As a hint, for date axes you probably want to set zoom to about 0.0002
and x to something near to -DateAxis.toDouble(date)
, where
"date" is the first date being plotted. For PieGraphs, X and Y should be
about equal to center the graph, which has a default radius of 100.
zoom
- the zoom value, or 0 to auto-sizex
- the amount to add to the X co-ordinates of the graph, or NaN to auto-positiony
- the amount to add to the Y co-ordinates of the graph, or NaN to auto-position.
Remember in graphs, y=0 is at the bottom of the graph, so positive values move
items on the graph up the page.getActualZoom
,
getActualOffset
public double getActualZoom()
setFixedSize(double, double, double)
along with the return value for #getActualOffsets
to produce
a second Pie graph of the same size.
Prior to the call to draw(org.faceless.graph2.Output)
this method returns 0public Point2D getActualOffset()
setFixedSize(double, double, double)
along with the return value for
getActualZoom()
to produce a second Pie graph of the same size.
Prior to the call to draw(org.faceless.graph2.Output)
this method returns nullpublic boolean isOverlapping()
draw(org.faceless.graph2.Output)
this method returns falsepublic final void draw(Output out)
Output
object. Once this method has been
called once, it cannot be called again on the same graph.out
- the Output
to draw the graph toIllegalStateException
- if the graph has already been drawn.public void setLightLevel(int level)
level
- the level of lighting used to shade the graphpublic void setLightVector(int x, int y, int z)
graph.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.x
- the X component of the vectory
- the Y component of the vectorz
- the Z component of the vectorpublic void setMetaData(String key, String value)
Output
being used, but
typically will result in metadata of some sort being embedded in
the final graph. For instance, to set the author of the graph you
could call setMetaData("Author", "Joe Bloggs")
.key
- The type of MetaData to use. Values recognised include
Author, Title, Description and Copyright, although other keys may be
used and will be inserted if possible.value
- the value to insertpublic void setOption(String key, String value)
markerPriority | Always draw markers ahead of faces. This may be needed to correctly display markers in some types of graph. |
---|
public final void interrupt()
draw()
method. This may be called from another thread to
interrupt the drawing routine if the resulting graph is no longer of interest.
The Output
the draw()
method is writing to should be discarded,
as it will be left in an undefined state, as will this object. If this method is called
before the draw()
method has been called, then when it is called it will
exit immediately. If called afterwards, it will have no effect.public final boolean isInterrupted()
draw()
method
will be in an undefined state and should be discarded.public static void setLicenseKey(String key)
Set the license key for the library. When the library is purchased, the Big Faceless Organization supplies a key which removes the "DEMO" stamp on each of the graphs.
Please note this method is static - it should be called BEFORE the first Graph is created, like so:
Graph.setLicenseKey(.....); Graph graph = new AxesGraph();
key
- the license keyCopyright © 2001-2016 Big Faceless Organization