Class 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.
    • Field Detail

      • LINEAR

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

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

      • BasicTicker

        protected BasicTicker​(boolean logFlag)
        Constructor.
        Parameters:
        logFlag - true for logarithmic axis, false for linear
    • 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, 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 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 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
        orient - label orientation
        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
      • 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 value
        dhi - maximum axis data value
        captioner - caption painter
        orient - label orientation
        npix - number of pixels along the axis
        crowding - 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 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
      • 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