Class BasicTicker

java.lang.Object
uk.ac.starlink.ttools.plot2.BasicTicker
All Implemented Interfaces:
Ticker

public abstract class BasicTicker extends 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 
    Defines a specific rule for generating major and minor axis tick marks.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final BasicTicker
    Ticker for linear axes.
    static final BasicTicker
    Ticker for logarithmic axes.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BasicTicker(boolean logFlag)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    getTicks(double dlo, double dhi, boolean withMinor, Captioner captioner, Orientation[] orients, 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LINEAR

      public static final BasicTicker LINEAR
      Ticker for linear axes.
    • LOG

      public static final BasicTicker LOG
      Ticker for logarithmic axes.
  • Constructor Details

    • BasicTicker

      protected BasicTicker(boolean logFlag)
      Constructor.
      Parameters:
      logFlag - true for logarithmic axis, false for linear
  • Method Details

    • 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, and adjust. Increasing adjust 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 value
      dhi - maximum axis data value
      approxMajorCount - guide value for number of major ticks in range
      adjust - adjusts density of major ticks, zero is normal
    • getTicks

      public TickRun getTicks(double dlo, double dhi, boolean withMinor, Captioner captioner, Orientation[] orients, int npix, double crowding)
      Description copied from interface: Ticker
      Generates tick marks for labelling a plot axis.

      The supplied list of orientations is attempted in order; if the required crowding can be satisfied by any of them, that orientation will be used. If it can't be supplied by any (because of unavoidable label overlap) a lower crowding value may be used.

      Specified by:
      getTicks in interface Ticker
      Parameters:
      dlo - minimum axis data value
      dhi - maximum axis data value
      withMinor - if true minor axes are included, if false only major (labelled) ones are
      captioner - caption painter
      orients - array of label orientations in order of preference, must contain at least one element
      npix - number of pixels along the axis
      crowding - 1 for normal tick density on the axis, lower for fewer labels, higher for more
      Returns:
      tick array along with orientation actually used
    • 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 rule
      dlo - minimum axis data value
      dhi - 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 rule
      dlo - minimum axis data value
      dhi - 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 - multiplier
      exp - 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 marks
      axis - axis on which the ticks will be drawn
      captioner - caption painter
      orient - label orientation
      Returns:
      true iff some of the ticks are so close to each other that their labels will overlap