JIDE 3.5.15

com.jidesoft.chart.axis
Class Axis

java.lang.Object
  extended by com.jidesoft.chart.axis.Axis
All Implemented Interfaces:
PropertyChangeListener, EventListener
Direct Known Subclasses:
CategoryAxis, NumericAxis, TimeAxis

public class Axis
extends Object
implements PropertyChangeListener

Represents an axis in the chart display.

Author:
Simon White (swhite@catalysoft.com)

Field Summary
static double MIN_RESOLUTION
           
static String PROPERTY_AXIS_COLOR
           
static String PROPERTY_LABEL
           
static String PROPERTY_MINOR_TICK_COLOR
           
static String PROPERTY_MINOR_TICK_LENGTH
           
static String PROPERTY_RANGE
           
static String PROPERTY_STROKE
           
static String PROPERTY_TICK_CALCULATOR
           
static String PROPERTY_TICK_COLOR
           
static String PROPERTY_TICK_FONT
           
static String PROPERTY_TICK_LABEL_COLOR
           
static String PROPERTY_TICK_LENGTH
           
static String PROPERTY_TICKS
           
static String PROPERTY_UPDATE_OTHER_AXES
           
 
Constructor Summary
Axis()
          No-args constructor
Axis(AutoPositionedLabel label)
          Create an axis using the given label
Axis(double min, double max)
          Create an axis using the supplied minimum and maximum values to set the range of the axis.
Axis(Range<?> newRange)
          Create an axis using the given range to define the minimum and maximum values
Axis(Range<?> newRange, String labelText)
          Create an Axis, using the text as the label
Axis(String labelText)
          Create an axis using the supplied text to create a label
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          A property change event will be fired when this axis changes its range.
 boolean equals(Object o)
           
 Color getAxisColor()
          Returns the color to use when painting the axis
 AxisRenderer getAxisRenderer()
           
 InvertibleTransform<Double> getAxisTransform()
           
 Range<Double> getDomain()
           
 double getFloatingPosition()
          Returns the floating position.
 AutoPositionedLabel getLabel()
           
 Integer getLabelWidth()
           
 Color getMinorTickColor()
          Returns the value for the minor tick Color
 int getMinorTickLength()
          Returns the length of minor ticks, in pixels
 Range<?> getOutputRange()
          Returns the range of values for this axis, after the transformation (if any) has been applied
 AxisPlacement getPlacement()
          Returns the placement of the axis
 AxisQuantity getQuantity()
          Returns the quantity for the axis, i.e.
 Range<?> getRange()
           
 Stroke getStroke()
          Returns the stroke used when drawing the axis
 TickCalculator getTickCalculator()
          Returns the tick calculator
 Color getTickColor()
          Returns the tick color for the axis
 Font getTickFont()
          Returns the font currently used for tick labels
 Color getTickLabelColor()
          Returns the color used for tick labels on this axis
 int getTickLabelOffset()
           
 double getTickLabelRotation()
          Returns the current tick label rotation, given in radians.
 int getTickLength()
          Returns the length of major ticks, in pixels
 Tick[] getTicks()
          Returns an array of ticks for this axis
 int hashCode()
           
 boolean isFlipped()
           
 boolean isLabelVisible()
          Returns whether the label should be visible
 boolean isTicksVisible()
          Returns whether ticks are currently visible
 boolean isVisible()
          Returns whether the axis is currently visible
 int labelWidth(Graphics g, Font tickFont, Orientation orientation)
          Determines how much space to allow for the tick labels at the side of an axis
 int labelWidth(Graphics g, Font tickFont, Orientation orientation, Tick[] ticks)
           
 double maximum()
          Returns the maximum of the input range
 double midPoint()
          Calculates the mid point of the range
 double minimum()
          Returns the minimum of the input range
 void propertyChange(PropertyChangeEvent evt)
           
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a listener that receives notification of property changes.
 void render(Graphics g, int x, int y, int length, Orientation orientation)
          Render the axis onto the supplied graphics context
 void setAxisColor(Color axisColor)
          Specify the color to use when painting the axis
 void setAxisRenderer(AxisRenderer axisRenderer)
          Sets the renderer for the axis
 void setAxisTransform(InvertibleTransform<Double> axisTransform)
           
 void setDomain(Range<Double> domain)
           
 void setFlipped(boolean flipped)
           
 void setFloatingPosition(double floatingPos)
          Sets the floating position.
 void setLabel(AutoPositionedLabel newValue)
           
 void setLabel(String text)
           
 void setLabelVisible(boolean labelVisible)
          Specify whether the axis label is visible.
 void setLabelWidth(Integer labelWidth)
          The label width is the variable part of the width of the axis.
 void setMinorTickColor(Color minorTickColor)
          Specify the color used for painting minor ticks.
 void setMinorTickLength(int minorTickLength)
          Specify the length of minor ticks, in pixels
 void setPlacement(AxisPlacement placement)
          Specifies whether the axis is to be placed at the leading or trailing edge of the interval, or placed in the centre
 void setRange(double min, double max)
          Sets the range for the axis to be a numeric range with the supplied minimum and maximum values
 void setRange(Range<?> range)
          Sets the range for the axis to be the supplied range
 void setRange(Range<?> range, boolean updateOtherAxes)
          Set the range of the axis.
 void setRange(Range<?> range, boolean updateOtherAxes, boolean fireEvent)
          Sets the range, with the option of not firing a property change event.
 void setStroke(Stroke stroke)
          Specifies the stroke to use for the axis
 void setTickCalculator(TickCalculator tickCalculator)
          Specify the tick calculator to use for this axis.
 void setTickColor(Color tickColor)
          The chart class contains a tickColor attribute, but you can override that value by setting the tick color on an instance of Axis.
 void setTickFont(Font tickFont)
          Specify the font to use for tick labels
 void setTickLabelColor(Color tickLabelColor)
          Sets the tick label color and overrides the default value set in the Chart class
 void setTickLabelOffset(int offset)
          Specify a gap between the tick and the tick label
 void setTickLabelRotation(double tickLabelRotation)
          Specify a rotation for the tick labels, given in radians.
 void setTickLength(int tickLength)
          Specify the length of major ticks, in pixels
 void setTicksVisible(boolean ticksVisible)
          Specify whether ticks should be visible
 void setVisible(boolean visible)
          Specify whether the axis should be visible.
 String toString()
           
protected  void updateTicks()
          Updates the cached array of ticks
static Range<?> zoom(Axis axis, double magnificationFactor)
          Adjusts this axis by zooming on the realValue and using the supplied magnification factor.
static Range<?> zoomFromPosition(Axis axis, double magnificationFactor, double position)
          This method zooms by keeping the given position (for example, the origin) of an axis static
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_RESOLUTION

public static final double MIN_RESOLUTION
See Also:
Constant Field Values

PROPERTY_TICKS

public static final String PROPERTY_TICKS
See Also:
Constant Field Values

PROPERTY_TICK_FONT

public static final String PROPERTY_TICK_FONT
See Also:
Constant Field Values

PROPERTY_TICK_LENGTH

public static final String PROPERTY_TICK_LENGTH
See Also:
Constant Field Values

PROPERTY_MINOR_TICK_LENGTH

public static final String PROPERTY_MINOR_TICK_LENGTH
See Also:
Constant Field Values

PROPERTY_RANGE

public static final String PROPERTY_RANGE
See Also:
Constant Field Values

PROPERTY_UPDATE_OTHER_AXES

public static final String PROPERTY_UPDATE_OTHER_AXES
See Also:
Constant Field Values

PROPERTY_LABEL

public static final String PROPERTY_LABEL
See Also:
Constant Field Values

PROPERTY_TICK_LABEL_COLOR

public static final String PROPERTY_TICK_LABEL_COLOR
See Also:
Constant Field Values

PROPERTY_TICK_CALCULATOR

public static final String PROPERTY_TICK_CALCULATOR
See Also:
Constant Field Values

PROPERTY_AXIS_COLOR

public static final String PROPERTY_AXIS_COLOR
See Also:
Constant Field Values

PROPERTY_TICK_COLOR

public static final String PROPERTY_TICK_COLOR
See Also:
Constant Field Values

PROPERTY_MINOR_TICK_COLOR

public static final String PROPERTY_MINOR_TICK_COLOR
See Also:
Constant Field Values

PROPERTY_STROKE

public static final String PROPERTY_STROKE
See Also:
Constant Field Values
Constructor Detail

Axis

public Axis()
No-args constructor


Axis

public Axis(String labelText)
Create an axis using the supplied text to create a label

Parameters:
labelText - the text of the label

Axis

public Axis(AutoPositionedLabel label)
Create an axis using the given label

Parameters:
label - the label to use for the axis

Axis

public Axis(double min,
            double max)
Create an axis using the supplied minimum and maximum values to set the range of the axis. This assumes we are using a purely numerical axis (rather than categorical values or a time line).

Parameters:
min - the minimum value of the range
max - the maximum value of the range

Axis

public Axis(Range<?> newRange)
Create an axis using the given range to define the minimum and maximum values

Parameters:
newRange - the new range of the axis

Axis

public Axis(Range<?> newRange,
            String labelText)
Create an Axis, using the text as the label

Parameters:
newRange - the range of the axis, defining minimum and maximum values
labelText - the text to use in the label for the axis
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
A property change event will be fired when this axis changes its range.

Parameters:
listener - the listener to receive notification of changes

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a listener that receives notification of property changes.

Parameters:
listener - the listener

getTickCalculator

public TickCalculator getTickCalculator()
Returns the tick calculator

Returns:
the tick calculator

setTickCalculator

public void setTickCalculator(TickCalculator tickCalculator)

Specify the tick calculator to use for this axis.

Note: We add ourselves as a PropertyChangeListener to the tick calculator in case there are changes (such as NumberFormatChanges) that require the ticks to be updated.

Parameters:
tickCalculator - the tick calculator

getAxisRenderer

public AxisRenderer getAxisRenderer()

getTickLabelRotation

public double getTickLabelRotation()
Returns the current tick label rotation, given in radians.

Returns:
the current tick label rotation

setTickLabelRotation

public void setTickLabelRotation(double tickLabelRotation)
Specify a rotation for the tick labels, given in radians. So for example, to rotate the x axis text by 45 degrees use Math.PI/4 for climbing text or -Math.PI/4 for descending text.

Parameters:
tickLabelRotation - a rotation given in radians

getTickLabelOffset

public int getTickLabelOffset()

setTickLabelOffset

public void setTickLabelOffset(int offset)
Specify a gap between the tick and the tick label

Parameters:
offset - the gap between the tick and the tick label

getTickLength

public int getTickLength()
Returns the length of major ticks, in pixels

Returns:
the length of major ticks, in pixels

setTickLength

public void setTickLength(int tickLength)
Specify the length of major ticks, in pixels

Parameters:
tickLength - the new length for major ticks

getMinorTickLength

public int getMinorTickLength()
Returns the length of minor ticks, in pixels

Returns:
the length of minor ticks, in pixels

setMinorTickLength

public void setMinorTickLength(int minorTickLength)
Specify the length of minor ticks, in pixels

Parameters:
minorTickLength - the new length for minor ticks

getTickColor

public Color getTickColor()
Returns the tick color for the axis

Returns:
the tick color for the axis

setTickColor

public void setTickColor(Color tickColor)
The chart class contains a tickColor attribute, but you can override that value by setting the tick color on an instance of Axis.

Parameters:
tickColor - the color to use when painting ticks on this axis

getMinorTickColor

public Color getMinorTickColor()
Returns the value for the minor tick Color

Returns:
the Color used for painting minor ticks

setMinorTickColor

public void setMinorTickColor(Color minorTickColor)
Specify the color used for painting minor ticks. If this value is not set (i.e., null), minor ticks will be painted the same color as major ticks

Parameters:
minorTickColor - the Color for minor ticks, or null for the same color as major ticks

getTickLabelColor

public Color getTickLabelColor()
Returns the color used for tick labels on this axis

Returns:
the color used for tick labels on this axis

setTickLabelColor

public void setTickLabelColor(Color tickLabelColor)
Sets the tick label color and overrides the default value set in the Chart class

Parameters:
tickLabelColor - the color to use for tick labels

getTickFont

public Font getTickFont()
Returns the font currently used for tick labels

Returns:
the font currently used for tick labels

setTickFont

public void setTickFont(Font tickFont)
Specify the font to use for tick labels

Parameters:
tickFont - the font to use for tick labels

isVisible

public boolean isVisible()
Returns whether the axis is currently visible

Returns:
whether the axis is currently visible

setVisible

public void setVisible(boolean visible)
Specify whether the axis should be visible. An invisible axis takes up no space. Axes are visible by default. If you change the visibility of an axis at run time you will need to repaint the chart.

Parameters:
visible - true if the axis should be visible; false to make it invisible.

isLabelVisible

public boolean isLabelVisible()
Returns whether the label should be visible

Returns:
whether the label should be visible

setLabelVisible

public void setLabelVisible(boolean labelVisible)
Specify whether the axis label is visible.

Sometimes you might want to specify an axis label, but then set it to be invisible. This can help, for example, when aligning the charts in a multi-chart layout

Parameters:
labelVisible - whether the label should be visible

getLabelWidth

public Integer getLabelWidth()

setLabelWidth

public void setLabelWidth(Integer labelWidth)
The label width is the variable part of the width of the axis.

Use this only to fix the label width at a specific value; otherwise the label width is automatically computed.

Parameters:
labelWidth - the width of the variable width part of the axis, in pixels

labelWidth

public int labelWidth(Graphics g,
                      Font tickFont,
                      Orientation orientation,
                      Tick[] ticks)

labelWidth

public int labelWidth(Graphics g,
                      Font tickFont,
                      Orientation orientation)
Determines how much space to allow for the tick labels at the side of an axis

Returns:
the (maximum) tick label width in pixels

setAxisRenderer

public void setAxisRenderer(AxisRenderer axisRenderer)
Sets the renderer for the axis

Parameters:
axisRenderer - the axis renderer

setRange

public void setRange(double min,
                     double max)
Sets the range for the axis to be a numeric range with the supplied minimum and maximum values

Parameters:
min - the minimum value for the range
max - the maximum value for the range

setRange

public void setRange(Range<?> range)
Sets the range for the axis to be the supplied range

Parameters:
range - the new range

setRange

public void setRange(Range<?> range,
                     boolean updateOtherAxes)
Set the range of the axis.


setRange

public void setRange(Range<?> range,
                     boolean updateOtherAxes,
                     boolean fireEvent)
Sets the range, with the option of not firing a property change event. This can be useful when considering performance, but only when you know that there will be an update to the chart soon anyway (probably because of some other related event).


getDomain

public Range<Double> getDomain()

setDomain

public void setDomain(Range<Double> domain)

getQuantity

public AxisQuantity getQuantity()
Returns the quantity for the axis, i.e. is the axis for numeric, time or category values? By default an axis is for numeric values, but subclasses should override this appropriately.

Returns:
the quantity for the axis

getOutputRange

public Range<?> getOutputRange()
Returns the range of values for this axis, after the transformation (if any) has been applied

Returns:
a Range

getRange

public Range<?> getRange()
Returns:
the range of values for this axis, before the transformation (if any) has been applied

getAxisTransform

public InvertibleTransform<Double> getAxisTransform()

setAxisTransform

public void setAxisTransform(InvertibleTransform<Double> axisTransform)

getLabel

public AutoPositionedLabel getLabel()

setLabel

public void setLabel(String text)

setLabel

public void setLabel(AutoPositionedLabel newValue)

maximum

public double maximum()
Returns the maximum of the input range

Returns:
the maximum of the input range

minimum

public double minimum()
Returns the minimum of the input range

Returns:
the minimum of the input range

midPoint

public double midPoint()
Calculates the mid point of the range

Returns:
the mid point of the range

getPlacement

public AxisPlacement getPlacement()
Returns the placement of the axis

Returns:
the placement of the axis
See Also:
AxisPlacement

setPlacement

public void setPlacement(AxisPlacement placement)
Specifies whether the axis is to be placed at the leading or trailing edge of the interval, or placed in the centre

Parameters:
placement - the placement of the axis

getFloatingPosition

public double getFloatingPosition()
Returns the floating position. This is only relevant when the axis is displayed with an axis placement of FLOATING

Returns:
the position of the axis on the other axis

setFloatingPosition

public void setFloatingPosition(double floatingPos)
Sets the floating position. The floating position is the real axis position when the axis is being displayed in floating mode. By default it will be zero.

Parameters:
floatingPos - the new floating position as a real coordinate value

getAxisColor

public Color getAxisColor()
Returns the color to use when painting the axis

Returns:
the color to use when painting the axis

setAxisColor

public void setAxisColor(Color axisColor)
Specify the color to use when painting the axis

Parameters:
axisColor - the color to use for the Axis

getStroke

public Stroke getStroke()
Returns the stroke used when drawing the axis

Returns:
the Stroke used when drawing the axis

setStroke

public void setStroke(Stroke stroke)
Specifies the stroke to use for the axis

Parameters:
stroke - the stroke to use for the axis

getTicks

public Tick[] getTicks()
Returns an array of ticks for this axis

Returns:
an array of ticks for this axis

updateTicks

protected void updateTicks()
Updates the cached array of ticks


isTicksVisible

public boolean isTicksVisible()
Returns whether ticks are currently visible

Returns:
whether ticks are visible

setTicksVisible

public void setTicksVisible(boolean ticksVisible)
Specify whether ticks should be visible

Parameters:
ticksVisible - a boolean value to indicate whether ticks should be visible

isFlipped

public boolean isFlipped()

setFlipped

public void setFlipped(boolean flipped)

zoom

public static Range<?> zoom(Axis axis,
                            double magnificationFactor)
Adjusts this axis by zooming on the realValue and using the supplied magnification factor. It keeps the midpoint of the axis static.

Parameters:
axis - the axis to be zoomed
magnificationFactor - the factor by which we wish to zoom
Returns:
the new zoomed range

zoomFromPosition

public static Range<?> zoomFromPosition(Axis axis,
                                        double magnificationFactor,
                                        double position)
This method zooms by keeping the given position (for example, the origin) of an axis static

Parameters:
axis - the axis being zoomed
magnificationFactor - the magnification factor being applied for the zoom "param position the position of the zoom along the axis (in terms of user coordinates)
Returns:
the new zoomed range for the axis

render

public void render(Graphics g,
                   int x,
                   int y,
                   int length,
                   Orientation orientation)
Render the axis onto the supplied graphics context

Parameters:
g - the Graphics context
x - the x coordinate for the axis
y - the y coordinate for the axis
length - the length of the axis
orientation - the orientation of the axis; horizontal or vertical

toString

public String toString()
Overrides:
toString in class Object

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

JIDE 3.5.15