public abstract class AbstractChart
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractChart.Side
Indicates a side of the chart
|
Modifier and Type | Field and Description |
---|---|
protected int |
axisColour
Colour of axis lines.
|
protected java.text.DecimalFormat[] |
axisFormatter
For numerical formatting of axis labels.
|
protected int |
axisLabelColour
Colour of axis labels.
|
protected int |
axisValuesColour
Colour of the values shown on a chart axis.
|
protected float[][] |
data
The datasets to be charted.
|
protected boolean |
drawDecorations |
protected processing.core.PGraphics |
graphics
Graphics context in which to send output.
|
protected float[][] |
logTics
Tic mark values for optional axis display.
|
protected processing.core.PApplet |
parent
Parent sketch in which this chart is to be drawn.
|
protected Drawable |
renderer
Alternative renderer for sketchy graphics and other styles.
|
protected boolean |
showEdge
Determines if areal chart features are drawn with an edge or not.
|
protected float[][] |
tics
Tic mark values for optional axis display.
|
protected boolean |
transposeAxes
Determines if the two primary axes should be transposed.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractChart(processing.core.PApplet parent)
Initialises the chart settings.
|
Modifier and Type | Method and Description |
---|---|
protected static float |
convertFromLog(double logValue,
double minLogValue,
double maxLogValue)
Converts the given value assumed to be on a log scale between 0 and 1, to an non-log value.
|
protected static float |
convertToLog(double dataItem,
double minLogValue,
double maxLogValue)
Converts the given value, which is assumed to be positive, to a log value
scaled between 0 and 1
|
protected abstract void |
draw(float xOrigin,
float yOrigin,
float width,
float height)
Should draw the chart within the given bounds.
|
protected float |
getBorder(AbstractChart.Side side)
Reports the internal border between the given edge of the chart and the drawing area.
|
protected float[] |
getData(int dimension)
Reports the data to be displayed along the given axis of the chart.
|
protected boolean |
getIsLogScale(int dimension)
Reports whether or not the data in the given dimension are to be represented on the log10 scale.
|
protected float |
getMax(int dimension)
Reports the maximum value of the data to be charted on the axis of the given dimension.
|
protected float |
getMaxLog(int dimension)
Reports the maximum value of the log10 of the data to be charted on the axis of the given dimension.
|
protected float |
getMin(int dimension)
Reports the minimum value of the data to be charted on the axis of the given dimension.
|
protected float |
getMinBorder()
Reports the minimum internal border between the chart and the drawing area.
|
protected float |
getMinLog(int dimension)
Reports the minimum value of the log10 of the data to be charted on the axis of the given dimension.
|
protected boolean |
getShowAxis(int dimension)
Reports whether or not the axis representing the given dimension is drawn.
|
void |
setAxisColour(int colour)
Determines the colour of the axis lines of the chart
|
void |
setAxisLabelColour(int colour)
Determines the colour of the axis labels of the chart
|
void |
setAxisValuesColour(int colour)
Determines the colour of the axis values of the chart
|
protected void |
setBorder(float border,
AbstractChart.Side side)
Sets the internal border between the given edge of the chart and the drawing area.
|
protected void |
setData(int dimension,
float[] data)
Sets the data to be displayed along the given axis of the chart.
|
void |
setDecorations(boolean drawDecorations)
Determines whether decorations such as title, axes, and labels are drawn or not.
|
protected void |
setFormat(int dimension,
java.lang.String format)
Sets the numerical format for numbers shown on the axis of the given dimension.
|
void |
setGraphics(processing.core.PGraphics graphics)
Sets the the graphics context into which all output is directed.
|
protected void |
setIsLogScale(int dimension,
boolean isLog)
Determines whether or not the data in the given dimension are to be represented on the log10 scale.
|
protected void |
setMax(int dimension,
float max)
Sets the maximum value of the data to be charted on the axis of the given dimension.
|
protected void |
setMin(int dimension,
float min)
Sets the minimum value of the data to be charted on the axis of the given dimension.
|
protected void |
setMinBorder(float border)
Sets the minimum internal border between the edge of the graph and the drawing area.
|
protected void |
setMinBorder(float border,
AbstractChart.Side side)
Sets the minimum internal border between the given edge of the chart and the drawing area.
|
protected void |
setRange(int dimension,
float min,
float max)
Sets the minimum and maximum values of the data to be charted on the axis of the given dimension.
|
void |
setRenderer(Drawable renderer)
Sets the the renderer to be used for drawing graphics.
|
void |
setShowEdge(boolean showEdge)
Determines whether or not to draw lines around and areal chart features.
|
protected void |
showAxis(int dimension,
boolean isVisible,
AbstractChart.Side side)
Determines whether or not the axis representing the given dimension is drawn.
|
protected processing.core.PApplet parent
protected processing.core.PGraphics graphics
protected Drawable renderer
protected float[][] data
protected float[][] tics
protected float[][] logTics
protected boolean transposeAxes
protected java.text.DecimalFormat[] axisFormatter
protected int axisColour
protected int axisValuesColour
protected int axisLabelColour
protected boolean showEdge
protected boolean drawDecorations
protected AbstractChart(processing.core.PApplet parent)
parent
- Sketch in which this chart is to appear.protected abstract void draw(float xOrigin, float yOrigin, float width, float height)
xOrigin
- left-hand pixel coordinate of the area in which to draw the chart.yOrigin
- top pixel coordinate of the area in which to draw the chart.width
- Width in pixels of the area in which to draw the chart.height
- Height in pixels of the area in which to draw the chart.public void setGraphics(processing.core.PGraphics graphics)
graphics
- New graphics context in which the chart is embedded.public void setRenderer(Drawable renderer)
setGraphics()
, any custom renderers will be lost.renderer
- New renderer to be used for drawing graphics.public void setDecorations(boolean drawDecorations)
drawDecorations
- If true, axes, labels and titles can be drawn.public void setAxisColour(int colour)
colour
- Colour of the axis lines of the chart.public void setAxisLabelColour(int colour)
colour
- Colour of the axis labels of the chart.public void setAxisValuesColour(int colour)
colour
- Colour of the axis values of the chart.public void setShowEdge(boolean showEdge)
showEdge
- Edges drawn if true.protected void setData(int dimension, float[] data)
dimension
- Dimension of the data to add.data
- Collection of data items to represent in the chart.protected float[] getData(int dimension)
dimension
- Dimension of the data to report.protected void setRange(int dimension, float min, float max)
Float.NaN
, then the minimum or maximum
value respectively will be set to that of the min/max data items in the given dimension.dimension
- Dimension of the data whose minimum value is to be set.min
- Minimum value to be represented on the axis or Float.NaN
for natural data minimum.max
- Maximum value to be represented on the axis or Float.NaN
for natural data maximum..protected void setMin(int dimension, float min)
Float.NaN
, then the minimum value will be set to
the minimum of the data items in the given dimension.dimension
- Dimension of the data whose minimum value is to be set.min
- Minimum value to be represented on the axis or Float.NaN
if data
minimum is to be used.protected float getMin(int dimension)
dimension
- Dimension of the data whose minimum value is to be retrieved.protected float getMax(int dimension)
dimension
- Dimension of the data whose maximum value is to be retrieved.protected float getMinLog(int dimension)
dimension
- Dimension of the data whose minimum value is to be retrieved.protected float getMaxLog(int dimension)
dimension
- Dimension of the data whose maximum value is to be retrieved.protected void setMax(int dimension, float max)
Float.NaN
, then the maximum value will be set to
the maximum of the data items in the given dimension.dimension
- Dimension of the data whose maximum value is to be set.max
- Maximum value to be represented on the axis or Float.NaN
if data
minimum is to be used.protected void setMinBorder(float border)
border
- Minimum internal border size in pixel units.protected void setMinBorder(float border, AbstractChart.Side side)
setMinBorder()
,
then this method has no effect.border
- Border at the given side in pixel units.side
- Side of the chart to set the minimum border size.protected void setBorder(float border, AbstractChart.Side side)
border
- Border at the given side in pixel units.side
- Side of the chart to set the border size.protected float getMinBorder()
protected float getBorder(AbstractChart.Side side)
getMinBorder()
and large enough to accommodate any axis labelling.side
- Side of the chart to query.protected void showAxis(int dimension, boolean isVisible, AbstractChart.Side side)
dimension
- Dimension of the data to have axis displayed or hidden.isVisible
- Axis is drawn if true.side
- Side of chart along which axis is drawn.protected boolean getShowAxis(int dimension)
dimension
- Dimension of the data to query.protected boolean getIsLogScale(int dimension)
dimension
- Dimension of the data to query.protected void setIsLogScale(int dimension, boolean isLog)
dimension
- Dimension of the data to set.isLog
- True if the data in the given dimension are to be log-scaled or false if linear.protected void setFormat(int dimension, java.lang.String format)
dimension
- Dimension of the data axis to format.format
- Format for numbers on the given data axis.protected static float convertToLog(double dataItem, double minLogValue, double maxLogValue)
dataItem
- Item from which to find log value.minLogValue
- Minimum value of the log10 of dataItem (used to scale result between 0-1)maxLogValue
- Maximum value of the log10 of dataItem (used to scale result between 0-1)protected static float convertFromLog(double logValue, double minLogValue, double maxLogValue)
logValue
- 0-1 log value from which the data value is to be found. If this value is
outside the 0-1 range, a value of 0 will be returned.minLogValue
- Minimum value of the log10 of dataItem (used to unscale the logValue from 0-1)maxLogValue
- Maximum value of the log10 of dataItem (used to unscale the logValue from 0-1)