public class NumberAxis extends ValueAxis implements Cloneable, Serializable
If the axis is set up to automatically determine its range to fit the data,
you can ensure that the range includes zero (statisticians usually prefer
this) by setting the autoRangeIncludesZero
flag to
true
.
The NumberAxis
class has a mechanism for automatically
selecting a tick unit that is appropriate for the current axis range. This
mechanism is an adaptation of code suggested by Laurence Vanhelsuwe.
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_AUTO_RANGE_INCLUDES_ZERO
The default value for the autoRangeIncludesZero flag.
|
static boolean |
DEFAULT_AUTO_RANGE_STICKY_ZERO
The default value for the autoRangeStickyZero flag.
|
static NumberTickUnit |
DEFAULT_TICK_UNIT
The default tick unit.
|
static boolean |
DEFAULT_VERTICAL_TICK_LABELS
The default setting for the vertical tick labels flag.
|
DEFAULT_AUTO_RANGE, DEFAULT_AUTO_RANGE_MINIMUM_SIZE, DEFAULT_AUTO_TICK_UNIT_SELECTION, DEFAULT_INVERTED, DEFAULT_LOWER_BOUND, DEFAULT_LOWER_MARGIN, DEFAULT_RANGE, DEFAULT_UPPER_BOUND, DEFAULT_UPPER_MARGIN, MAXIMUM_TICK_COUNT
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_LINE_PAINT, DEFAULT_AXIS_LINE_STROKE, DEFAULT_AXIS_VISIBLE, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_LABELS_VISIBLE, DEFAULT_TICK_MARK_INSIDE_LENGTH, DEFAULT_TICK_MARK_OUTSIDE_LENGTH, DEFAULT_TICK_MARK_PAINT, DEFAULT_TICK_MARK_STROKE, DEFAULT_TICK_MARKS_VISIBLE
Constructor and Description |
---|
NumberAxis()
Default constructor.
|
NumberAxis(String label)
Constructs a number axis, using default values where necessary.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Returns a clone of the axis.
|
void |
configure()
Configures the axis to work with the specified plot.
|
static TickUnitSource |
createIntegerTickUnits()
Returns a collection of tick units for integer values.
|
static TickUnitSource |
createIntegerTickUnits(Locale locale)
Returns a collection of tick units for integer values.
|
static TickUnitSource |
createStandardTickUnits()
Creates the standard tick units.
|
static TickUnitSource |
createStandardTickUnits(Locale locale)
Creates a collection of standard tick units.
|
AxisState |
draw(Graphics2D g2,
double cursor,
Rectangle2D plotArea,
Rectangle2D dataArea,
org.jfree.ui.RectangleEdge edge,
PlotRenderingInfo plotState)
Draws the axis on a Java 2D graphics device (such as the screen or a
printer).
|
boolean |
equals(Object obj)
Tests the axis for equality with an arbitrary object.
|
boolean |
getAutoRangeIncludesZero()
Returns the flag that indicates whether or not the automatic axis range
(if indeed it is determined automatically) is forced to include zero.
|
boolean |
getAutoRangeStickyZero()
Returns a flag that affects the auto-range when zero falls outside the
data range but inside the margins defined for the axis.
|
MarkerAxisBand |
getMarkerBand()
Returns the (optional) marker band for the axis.
|
NumberFormat |
getNumberFormatOverride()
Returns the number format override.
|
RangeType |
getRangeType()
Returns the axis range type.
|
NumberTickUnit |
getTickUnit()
Returns the tick unit for the axis.
|
int |
hashCode()
Returns a hash code for this object.
|
double |
java2DToValue(double java2DValue,
Rectangle2D area,
org.jfree.ui.RectangleEdge edge)
Converts a coordinate in Java2D space to the corresponding data value,
assuming that the axis runs along one edge of the specified dataArea.
|
List |
refreshTicks(Graphics2D g2,
AxisState state,
Rectangle2D dataArea,
org.jfree.ui.RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the
results in the tick label list (ready for drawing).
|
void |
setAutoRangeIncludesZero(boolean flag)
Sets the flag that indicates whether or not the axis range, if
automatically calculated, is forced to include zero.
|
void |
setAutoRangeStickyZero(boolean flag)
Sets a flag that affects the auto-range when zero falls outside the data
range but inside the margins defined for the axis.
|
void |
setMarkerBand(MarkerAxisBand band)
Sets the marker band for the axis.
|
void |
setNumberFormatOverride(NumberFormat formatter)
Sets the number format override.
|
void |
setRangeType(RangeType rangeType)
Sets the axis range type.
|
void |
setTickUnit(NumberTickUnit unit)
Sets the tick unit for the axis and sends an
AxisChangeEvent to
all registered listeners. |
void |
setTickUnit(NumberTickUnit unit,
boolean notify,
boolean turnOffAutoSelect)
Sets the tick unit for the axis and, if requested, sends an
AxisChangeEvent to all registered listeners. |
double |
valueToJava2D(double value,
Rectangle2D area,
org.jfree.ui.RectangleEdge edge)
Converts a data value to a coordinate in Java2D space, assuming that the
axis runs along one edge of the specified dataArea.
|
centerRange, getAutoRangeMinimumSize, getDefaultAutoRange, getDownArrow, getFixedAutoRange, getLeftArrow, getLowerBound, getLowerMargin, getMinorTickCount, getRange, getRightArrow, getStandardTickUnits, getUpArrow, getUpperBound, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isInverted, isNegativeArrowVisible, isPositiveArrowVisible, isVerticalTickLabels, lengthToJava2D, pan, reserveSpace, resizeRange, resizeRange, resizeRange2, setAutoRange, setAutoRangeMinimumSize, setAutoRangeMinimumSize, setAutoTickUnitSelection, setAutoTickUnitSelection, setDefaultAutoRange, setDownArrow, setFixedAutoRange, setInverted, setLeftArrow, setLowerBound, setLowerMargin, setMinorTickCount, setNegativeArrowVisible, setPositiveArrowVisible, setRange, setRange, setRange, setRangeAboutValue, setRangeWithMargins, setRangeWithMargins, setRangeWithMargins, setRightArrow, setStandardTickUnits, setUpArrow, setUpperBound, setUpperMargin, setVerticalTickLabels, zoomRange
addChangeListener, createAttributedLabel, getAttributedLabel, getAxisLinePaint, getAxisLineStroke, getFixedDimension, getLabel, getLabelAngle, getLabelFont, getLabelInsets, getLabelLocation, getLabelPaint, getMinorTickMarkInsideLength, getMinorTickMarkOutsideLength, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, hasListener, isAxisLineVisible, isMinorTickMarksVisible, isTickLabelsVisible, isTickMarksVisible, isVisible, removeChangeListener, setAttributedLabel, setAttributedLabel, setAxisLinePaint, setAxisLineStroke, setAxisLineVisible, setFixedDimension, setLabel, setLabelAngle, setLabelFont, setLabelInsets, setLabelInsets, setLabelLocation, setLabelPaint, setMinorTickMarkInsideLength, setMinorTickMarkOutsideLength, setMinorTickMarksVisible, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
public static final boolean DEFAULT_AUTO_RANGE_INCLUDES_ZERO
public static final boolean DEFAULT_AUTO_RANGE_STICKY_ZERO
public static final NumberTickUnit DEFAULT_TICK_UNIT
public static final boolean DEFAULT_VERTICAL_TICK_LABELS
public NumberAxis()
public NumberAxis(String label)
label
- the axis label (null
permitted).public RangeType getRangeType()
null
).setRangeType(RangeType)
public void setRangeType(RangeType rangeType)
rangeType
- the range type (null
not permitted).getRangeType()
public boolean getAutoRangeIncludesZero()
public void setAutoRangeIncludesZero(boolean flag)
If the flag is changed to true
, the axis range is
recalculated.
Any change to the flag will trigger an AxisChangeEvent
.
flag
- the new value of the flag.getAutoRangeIncludesZero()
public boolean getAutoRangeStickyZero()
setAutoRangeStickyZero(boolean)
public void setAutoRangeStickyZero(boolean flag)
flag
- the new flag.getAutoRangeStickyZero()
public NumberTickUnit getTickUnit()
Note: if the autoTickUnitSelection
flag is
true
the tick unit may be changed while the axis is being
drawn, so in that case the return value from this method may be
irrelevant if the method is called before the axis has been drawn.
setTickUnit(NumberTickUnit)
,
ValueAxis.isAutoTickUnitSelection()
public void setTickUnit(NumberTickUnit unit)
AxisChangeEvent
to
all registered listeners. A side effect of calling this method is that
the "auto-select" feature for tick units is switched off (you can
restore it using the ValueAxis.setAutoTickUnitSelection(boolean)
method).unit
- the new tick unit (null
not permitted).getTickUnit()
,
setTickUnit(NumberTickUnit, boolean, boolean)
public void setTickUnit(NumberTickUnit unit, boolean notify, boolean turnOffAutoSelect)
AxisChangeEvent
to all registered listeners. In addition, an
option is provided to turn off the "auto-select" feature for tick units
(you can restore it using the
ValueAxis.setAutoTickUnitSelection(boolean)
method).unit
- the new tick unit (null
not permitted).notify
- notify listeners?turnOffAutoSelect
- turn off the auto-tick selection?public NumberFormat getNumberFormatOverride()
null
).setNumberFormatOverride(NumberFormat)
public void setNumberFormatOverride(NumberFormat formatter)
formatter
- the number formatter (null
permitted).getNumberFormatOverride()
public MarkerAxisBand getMarkerBand()
null
).setMarkerBand(MarkerAxisBand)
public void setMarkerBand(MarkerAxisBand band)
The marker band is optional, leave it set to null
if you
don't require it.
band
- the new band (null
permitted).getMarkerBand()
public void configure()
public double valueToJava2D(double value, Rectangle2D area, org.jfree.ui.RectangleEdge edge)
Note that it is possible for the coordinate to fall outside the plotArea.
valueToJava2D
in class ValueAxis
value
- the data value.area
- the area for plotting the data.edge
- the axis location.java2DToValue(double, Rectangle2D, RectangleEdge)
public double java2DToValue(double java2DValue, Rectangle2D area, org.jfree.ui.RectangleEdge edge)
java2DToValue
in class ValueAxis
java2DValue
- the coordinate in Java2D space.area
- the area in which the data is plotted.edge
- the location.valueToJava2D(double, Rectangle2D, RectangleEdge)
public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge, PlotRenderingInfo plotState)
draw
in class Axis
g2
- the graphics device (null
not permitted).cursor
- the cursor location.plotArea
- the area within which the axes and data should be drawn
(null
not permitted).dataArea
- the area within which the data should be drawn
(null
not permitted).edge
- the location of the axis (null
not permitted).plotState
- collects information about the plot
(null
permitted).null
).public static TickUnitSource createStandardTickUnits()
If you don't like these defaults, create your own instance of TickUnits and then pass it to the setStandardTickUnits() method in the NumberAxis class.
ValueAxis.setStandardTickUnits(TickUnitSource)
,
createIntegerTickUnits()
public static TickUnitSource createIntegerTickUnits()
ValueAxis.setStandardTickUnits(TickUnitSource)
,
createStandardTickUnits()
public static TickUnitSource createStandardTickUnits(Locale locale)
NumberFormat
).
If you don't like these defaults, create your own instance of
TickUnits
and then pass it to the
setStandardTickUnits()
method.
locale
- the locale.ValueAxis.setStandardTickUnits(TickUnitSource)
public static TickUnitSource createIntegerTickUnits(Locale locale)
locale
- the locale to use to represent Numbers.ValueAxis.setStandardTickUnits(TickUnitSource)
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)
refreshTicks
in class Axis
g2
- the graphics device.state
- the axis state.dataArea
- the area in which the plot should be drawn.edge
- the location of the axis.public Object clone() throws CloneNotSupportedException
clone
in interface org.jfree.util.PublicCloneable
clone
in class ValueAxis
CloneNotSupportedException
- if some component of the axis does
not support cloning.public boolean equals(Object obj)
Jas4pp 1.5 © Java Analysis Studio for Particle Physics