Package uk.ac.starlink.ttools.plot2
Class BasicTicker
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.BasicTicker
-
- All Implemented Interfaces:
Ticker
public abstract class BasicTicker extends java.lang.Object implements Ticker
Partial Ticker implementation based on a rule defining a sequence of ticks. Concrete subclasses must implement a method to create a Rule suitable for a given range, and this is used to provide suitable ticks for particular circumstances, including avoiding label overlap.- Since:
- 17 Oct 2013
- Author:
- Mark Taylor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
BasicTicker.Rule
Defines a specific rule for generating major and minor axis tick marks.
-
Field Summary
Fields Modifier and Type Field Description static BasicTicker
LINEAR
Ticker for linear axes.static BasicTicker
LOG
Ticker for logarithmic axes.
-
Constructor Summary
Constructors Modifier Constructor Description protected
BasicTicker(boolean logFlag)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract BasicTicker.Rule
createRule(double dlo, double dhi, double approxMajorCount, int adjust)
Returns a new rule for labelling an axis in a given range.static Tick[]
getMajorTicks(BasicTicker.Rule rule, double dlo, double dhi)
Use a given rule to generate major ticks in a given range of coordinates.static Tick[]
getMinorTicks(BasicTicker.Rule rule, double dlo, double dhi)
Use a given rule to generate minor ticks in a given range of coordinates.BasicTicker.Rule
getRule(double dlo, double dhi, Captioner captioner, Orientation orient, int npix, double crowding)
Returns a Rule suitable for a given axis labelling job.Tick[]
getTicks(double dlo, double dhi, boolean withMinor, Captioner captioner, Orientation orient, int npix, double crowding)
Generates tick marks for labelling a plot axis.static Caption
linearLabel(long mantissa, int exp)
Generates a major tick mark label suitable for use with linear axes.static boolean
overlaps(Tick[] ticks, Axis axis, Captioner captioner, Orientation orient)
Determines whether the labels for a set of tick marks would overlap when painted on a given axis.
-
-
-
Field Detail
-
LINEAR
public static final BasicTicker LINEAR
Ticker for linear axes.
-
LOG
public static final BasicTicker LOG
Ticker for logarithmic axes.
-
-
Method Detail
-
createRule
public abstract BasicTicker.Rule createRule(double dlo, double dhi, double approxMajorCount, int adjust)
Returns a new rule for labelling an axis in a given range. The tick density is determined by two parameters,approxMajorCount
, which gives a baseline value for the number of ticks required over the given range, andadjust
. Increasingadjust
will give more major ticks, and decreasing it will give fewer ticks. Each value of adjust should result in a different tick count.- Parameters:
dlo
- minimum axis data valuedhi
- maximum axis data valueapproxMajorCount
- guide value for number of major ticks in rangeadjust
- adjusts density of major ticks, zero is normal
-
getTicks
public Tick[] getTicks(double dlo, double dhi, boolean withMinor, Captioner captioner, Orientation orient, int npix, double crowding)
Description copied from interface:Ticker
Generates tick marks for labelling a plot axis.- Specified by:
getTicks
in interfaceTicker
- Parameters:
dlo
- minimum axis data valuedhi
- maximum axis data valuewithMinor
- if true minor axes are included, if false only major (labelled) ones arecaptioner
- caption painterorient
- label orientationnpix
- number of pixels along the axiscrowding
- 1 for normal tick density on the axis, lower for fewer labels, higher for more- Returns:
- tick array
-
getRule
public BasicTicker.Rule getRule(double dlo, double dhi, Captioner captioner, Orientation orient, int npix, double crowding)
Returns a Rule suitable for a given axis labelling job. This starts off by generating ticks at roughly a standard separation, guided by the crowding parameter. However, if the resulting ticks are so close as to overlap, it backs off until it finds a set of ticks that can be displayed in a tidy fashion.- Parameters:
dlo
- minimum axis data valuedhi
- maximum axis data valuecaptioner
- caption painterorient
- label orientationnpix
- number of pixels along the axiscrowding
- 1 for normal tick density on the axis, lower for fewer labels, higher for more- Returns:
- basic tick generation rule
-
getMajorTicks
public static Tick[] getMajorTicks(BasicTicker.Rule rule, double dlo, double dhi)
Use a given rule to generate major ticks in a given range of coordinates.- Parameters:
rule
- tick generation ruledlo
- minimum axis data valuedhi
- maximum axis data value- Returns:
- array of major ticks
-
getMinorTicks
public static Tick[] getMinorTicks(BasicTicker.Rule rule, double dlo, double dhi)
Use a given rule to generate minor ticks in a given range of coordinates.- Parameters:
rule
- tick generation ruledlo
- minimum axis data valuedhi
- maximum axis data value- Returns:
- array of minor ticks
-
linearLabel
public static Caption linearLabel(long mantissa, int exp)
Generates a major tick mark label suitable for use with linear axes. Some care is required assembling the label, to make sure we avoid rounding issues (like 0.999999999999). Double.toString() is not good enough.- Parameters:
mantissa
- multiplierexp
- power of 10- Returns:
- tick label text
-
overlaps
public static boolean overlaps(Tick[] ticks, Axis axis, Captioner captioner, Orientation orient)
Determines whether the labels for a set of tick marks would overlap when painted on a given axis.- Parameters:
ticks
- major tick marksaxis
- axis on which the ticks will be drawncaptioner
- caption painterorient
- label orientation- Returns:
- true iff some of the ticks are so close to each other that their labels will overlap
-
-