Class Axis
- Direct Known Subclasses:
CategoryAxis, LogAxis, NumberAxis, SessionTimeAxis, TimeAxis
Base of every chart axis. An axis owns two ranges: the data range the chart computes from its series, and the visible range the user pans and zooms inside it.
Labels are never laid out by hand: the chart asks the axis for as many ticks as the measured label size allows, so labels on a small screen thin out instead of overlapping.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAxis(int position) Creates an axis at the given position. -
Method Summary
Modifier and TypeMethodDescriptionprotected double[]adjustBounds(double min, double max) Lets a subclass pad or round the automatic bounds; the default rounds a numeric range outward to the nearest nice step so the outermost grid lines sit on the plot edge.protected StringdefaultFormat(double value, double step) The axis' built in formatting; numbers are grouped and localized.protected doubleflatPad(double anchor) How far a range with a single value is padded on each side; 10% of the value, or 1 at zero.format(double value, double step) Formats a tick or value with the custom formatter if set, else the default.static StringformatNumber(double value, int decimals) Formatsvaluewith exactlydecimalsdecimal places through the localization manager.protected doubleforward(double value) Maps a value into the space the axis is linear in; the identity here,log10for a logarithmic axis.doublefromNormalized(double n) The inverse oftoNormalized.doubleThe high end of the data range.doubleThe low end of the data range.The formatter, or null for the axis' default.intThe side of the plot this axis is drawn on.getTitle()The axis title, or null.doubleThe high end of what is on screen.doubleThe low end of what is on screen.protected doubleinverse(double t) The inverse offorward.booleanWhether grid lines are drawn at the ticks.booleanTrue when zero is forced into the range.protected booleanTrue whensetRangepinned the high end, soadjustBoundsmust keep it as given.protected booleanTrue whensetRangepinned the low end, soadjustBoundsmust keep it as given.booleanTrue for an axis drawn left or right of the plot, which maps values vertically.booleanWhether the axis line and labels are drawn.booleanisZoomed()True when the user has zoomed in, so the visible range is narrower than the data.booleanWhether gestures may zoom and pan this axis.voidpan(double normalizedDelta) Pans by a fraction of the visible span; positive moves toward larger values.voidReturns to the full data range.voidrestoreViewport(double min, double max, boolean zoomed) Puts back a viewport exactly asgetVisibleMin(),getVisibleMax()andisZoomed()read it, without clamping or snapping; for undoing a temporary change such as an export, so the screen is left bit for bit as it was even mid-animation.voidsetDataBounds(double min, double max) Called by the chart with the extent of the data on this axis.voidsetDisplayRange(double min, double max) Sets what is drawn for one frame of an animated transition, without clamping and without marking the axis as zoomed; the next data update replaces it.setFormatter(ValueFormatter formatter) Replaces how labels are formatted.setGridVisible(boolean gridVisible) Enables or disables grid lines at the ticks.setIncludeZero(boolean includeZero) Forces zero into the automatic range, as a bar chart's value axis needs.setMaxZoom(double maxZoom) The largest magnification pan and zoom may reach, relative to the full data range.setPosition(int position) Moves the axis to another side.Pins the bounds instead of deriving them from the data; pass null to restore automatic.Sets the title drawn alongside the axis.setVisible(boolean visible) Hides or shows the axis; a hidden axis still maps values.voidsetVisibleRange(double min, double max) Shows exactly[min, max], clamped to the data range and the zoom limit.setZoomEnabled(boolean zoomEnabled) Allows or blocks zooming and panning along this axis.double[]ticks(int maxCount) Ticks for the visible range.doubletoNormalized(double value) Maps a value to 0..1 across the visible range (outside 0..1 when off screen).voidzoom(double factor, double anchor) Zooms around a point.
-
Field Details
-
BOTTOM
public static final int BOTTOMAxis drawn below the plot.- See Also:
-
LEFT
public static final int LEFTAxis drawn left of the plot.- See Also:
-
RIGHT
public static final int RIGHTAxis drawn right of the plot.- See Also:
-
TOP
public static final int TOPAxis drawn above the plot.- See Also:
-
-
Constructor Details
-
Axis
protected Axis(int position) Creates an axis at the given position.
Parameters
position: one ofBOTTOM,LEFT,RIGHTorTOP
-
-
Method Details
-
getPosition
public int getPosition()The side of the plot this axis is drawn on. -
setPosition
Moves the axis to another side. -
isVertical
public boolean isVertical()True for an axis drawn left or right of the plot, which maps values vertically. -
getTitle
The axis title, or null. -
setTitle
-
isVisible
public boolean isVisible()Whether the axis line and labels are drawn. -
setVisible
Hides or shows the axis; a hidden axis still maps values. -
isGridVisible
public boolean isGridVisible()Whether grid lines are drawn at the ticks. -
setGridVisible
Enables or disables grid lines at the ticks. -
getFormatter
The formatter, or null for the axis' default. -
setFormatter
Replaces how labels are formatted. -
setRange
Pins the bounds instead of deriving them from the data; pass null to restore automatic. Bounds given in the wrong order are taken as a range, and two equal bounds are widened by a pad on each side so the axis is never empty. A single bound pinned at the very end of the double range gives way by that pad when the free side has no room left.
Parameters
min: the low end, or null to derive it from the datamax: the high end, or null to derive it from the data
Returns
this axis
-
isMinFixed
protected boolean isMinFixed()True whensetRangepinned the low end, soadjustBoundsmust keep it as given. -
isMaxFixed
protected boolean isMaxFixed()True whensetRangepinned the high end, soadjustBoundsmust keep it as given. -
setIncludeZero
Forces zero into the automatic range, as a bar chart's value axis needs. -
isIncludeZero
public boolean isIncludeZero()True when zero is forced into the range. -
setMaxZoom
The largest magnification pan and zoom may reach, relative to the full data range. -
isZoomEnabled
public boolean isZoomEnabled()Whether gestures may zoom and pan this axis. -
setZoomEnabled
Allows or blocks zooming and panning along this axis. -
setDataBounds
public void setDataBounds(double min, double max) Called by the chart with the extent of the data on this axis.
Parameters
-
min: smallest value of any visible series -
max: largest value of any visible series
-
-
flatPad
protected double flatPad(double anchor) How far a range with a single value is padded on each side; 10% of the value, or 1 at zero. A time axis overrides it, since 10% of an epoch timestamp is years.
Parameters
anchor: the single value
Returns
the pad, positive
-
adjustBounds
protected double[] adjustBounds(double min, double max) Lets a subclass pad or round the automatic bounds; the default rounds a numeric range outward to the nearest nice step so the outermost grid lines sit on the plot edge.
Parameters
-
min: the raw minimum -
max: the raw maximum
Returns
{min, max}to use -
-
getDataMin
public double getDataMin()The low end of the data range. -
getDataMax
public double getDataMax()The high end of the data range. -
getVisibleMin
public double getVisibleMin()The low end of what is on screen. -
getVisibleMax
public double getVisibleMax()The high end of what is on screen. -
setVisibleRange
public void setVisibleRange(double min, double max) Shows exactly[min, max], clamped to the data range and the zoom limit. Showing the whole data range clears the zoom, so later data changes rescale the axis again. -
setDisplayRange
public void setDisplayRange(double min, double max) Sets what is drawn for one frame of an animated transition, without clamping and without marking the axis as zoomed; the next data update replaces it. -
restoreViewport
public void restoreViewport(double min, double max, boolean zoomed) Puts back a viewport exactly as
getVisibleMin(),getVisibleMax()andisZoomed()read it, without clamping or snapping; for undoing a temporary change such as an export, so the screen is left bit for bit as it was even mid-animation.Parameters
-
min: the visible minimum to restore -
max: the visible maximum to restore -
zoomed: the zoom flag to restore
This is an internal hook for
Chart(which lives in another package, so it has to be public); applications zoom withsetViewportandresetViewport. A range that is not finite, or whose minimum exceeds its maximum, is ignored, so it can never put an axis into a state no other method allows. -
-
resetViewport
public void resetViewport()Returns to the full data range. -
isZoomed
public boolean isZoomed()True when the user has zoomed in, so the visible range is narrower than the data. -
zoom
public void zoom(double factor, double anchor) Zooms around a point.
Parameters
-
factor: above 1 magnifies, below 1 shrinks -
anchor: the normalized position (0..1 along the axis) that stays put
-
-
pan
public void pan(double normalizedDelta) Pans by a fraction of the visible span; positive moves toward larger values. -
forward
protected double forward(double value) Maps a value into the space the axis is linear in; the identity here,log10for a logarithmic axis. Zoom, pan and normalization all work in this space. -
inverse
protected double inverse(double t) The inverse offorward. -
toNormalized
public double toNormalized(double value) Maps a value to 0..1 across the visible range (outside 0..1 when off screen). -
fromNormalized
public double fromNormalized(double n) The inverse oftoNormalized. -
ticks
public double[] ticks(int maxCount) Ticks for the visible range.
Parameters
maxCount: the most ticks the measured label size allows
Returns
ascending tick values
-
format
Formats a tick or value with the custom formatter if set, else the default.
Parameters
-
value: the value -
step: neighbouring tick spacing, or 0
Returns
the label
-
-
defaultFormat
The axis' built in formatting; numbers are grouped and localized. -
formatNumber
Formats
valuewith exactlydecimalsdecimal places through the localization manager. Whole numbers print without a decimal point, which the double overload ofL10NManager.formatdoes not guarantee.Parameters
-
value: the number -
decimals: decimal places, 0 or more
Returns
the localized text
-
-