Class PlotTicks

java.lang.Object
edu.cnu.mdi.splot.plot.PlotTicks

public class PlotTicks extends Object
Draws the tick marks and tick labels on a PlotCanvas.

Tick layout

Ticks are drawn on both the top and bottom edges of the active plot area for the X axis, and on both the left and right edges for the Y axis, so that the plot is framed on all four sides. Major ticks carry value labels; minor ticks do not.

The number of interior major and minor ticks is configurable via the setNum* methods. Log-scale axes draw one major tick per decade plus minor ticks at 2–9 × the decade value; the numMajorTick* setting is not used in log mode.

Histogram mode

When the plot contains histogram data and setDrawBinValue(boolean) has been called with true, the X-axis labels show 1-based bin indices rather than raw data values. This mode is automatically suppressed if the underlying data is not a histogram.

Bar plot mode

When the plot is a bar plot, the X axis shows the name of each data curve centerd on its bar group rather than numeric tick values.

Graphics context

All drawing methods accept Graphics2D directly. No casts from Graphics are performed in this class. Callers that receive a Graphics from AWT (e.g. inside paintComponent) should cast once at the call site:

 @Override
 protected void paintComponent(Graphics g) {
     super.paintComponent(g);
     plotTicks.draw((Graphics2D) g);
 }
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    PlotTicks(PlotCanvas plotCanvas)
    Construct a PlotTicks instance for the given canvas.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Draw all tick marks and tick labels onto the plot canvas.
    int
    Returns the major tick length in pixels.
    int
    Returns the minor tick length in pixels.
    int
    Returns the number of interior major ticks on the X axis (linear mode).
    int
    Returns the number of interior major ticks on the Y axis (linear mode).
    int
    Returns the number of interior minor ticks per major interval on the X axis.
    int
    Returns the number of interior minor ticks per major interval on the Y axis.
    void
    setDrawBinValue(boolean drawBinVal)
    Enable or disable bin-index labels on the X axis.
    void
    setMajorTickLen(int majorTickLen)
    Set the major tick length in pixels.
    void
    setMinorTickLen(int minorTickLen)
    Set the minor tick length in pixels.
    void
    setNumMajorTickX(int numMajorTickX)
    Set the number of interior major ticks on the X axis (linear mode).
    void
    setNumMajorTickY(int numMajorTickY)
    Set the number of interior major ticks on the Y axis (linear mode).
    void
    setNumMinorTickX(int numMinorTickX)
    Set the number of interior minor ticks per major interval on the X axis.
    void
    setNumMinorTickY(int numMinorTickY)
    Set the number of interior minor ticks per major interval on the Y axis.
    void
    Override the font used for tick labels.

    Methods inherited from class java.lang.Object

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

    • PlotTicks

      public PlotTicks(PlotCanvas plotCanvas)
      Construct a PlotTicks instance for the given canvas.
      Parameters:
      plotCanvas - the canvas this instance will draw ticks on; must not be null
  • Method Details

    • setTickFont

      public void setTickFont(Font font)
      Override the font used for tick labels.
      Parameters:
      font - the replacement font; must not be null
    • setDrawBinValue

      public void setDrawBinValue(boolean drawBinVal)
      Enable or disable bin-index labels on the X axis.

      When enabled, X-axis labels show the 1-based histogram bin index instead of the raw data value. This setting is silently ignored if the plot does not contain histogram data.

      Parameters:
      drawBinVal - true to show bin indices; false to show raw values
    • draw

      public void draw(Graphics2D g2)
      Draw all tick marks and tick labels onto the plot canvas.

      This method draws major ticks (with labels) and then minor ticks (without labels) for both axes. Log-scale axes draw their own minor ticks (2–9 × decade) internally; the outer minor-tick loop is skipped for log axes.

      This method is a no-op if the active bounds or data world have not yet been established on the canvas.

      Parameters:
      g2 - the graphics context
    • getNumMajorTickX

      public int getNumMajorTickX()
      Returns the number of interior major ticks on the X axis (linear mode).
      Returns:
      number of major X ticks
    • setNumMajorTickX

      public void setNumMajorTickX(int numMajorTickX)
      Set the number of interior major ticks on the X axis (linear mode).
      Parameters:
      numMajorTickX - the desired count; must be ≥ 0
    • getNumMinorTickX

      public int getNumMinorTickX()
      Returns the number of interior minor ticks per major interval on the X axis.
      Returns:
      number of minor X ticks per interval
    • setNumMinorTickX

      public void setNumMinorTickX(int numMinorTickX)
      Set the number of interior minor ticks per major interval on the X axis.
      Parameters:
      numMinorTickX - the desired count; must be ≥ 0
    • getNumMajorTickY

      public int getNumMajorTickY()
      Returns the number of interior major ticks on the Y axis (linear mode).
      Returns:
      number of major Y ticks
    • setNumMajorTickY

      public void setNumMajorTickY(int numMajorTickY)
      Set the number of interior major ticks on the Y axis (linear mode).
      Parameters:
      numMajorTickY - the desired count; must be ≥ 0
    • getNumMinorTickY

      public int getNumMinorTickY()
      Returns the number of interior minor ticks per major interval on the Y axis.
      Returns:
      number of minor Y ticks per interval
    • setNumMinorTickY

      public void setNumMinorTickY(int numMinorTickY)
      Set the number of interior minor ticks per major interval on the Y axis.
      Parameters:
      numMinorTickY - the desired count; must be ≥ 0
    • getMajorTickLen

      public int getMajorTickLen()
      Returns the major tick length in pixels.
      Returns:
      major tick length
    • setMajorTickLen

      public void setMajorTickLen(int majorTickLen)
      Set the major tick length in pixels.
      Parameters:
      majorTickLen - the desired length; must be ≥ 0
    • getMinorTickLen

      public int getMinorTickLen()
      Returns the minor tick length in pixels.
      Returns:
      minor tick length
    • setMinorTickLen

      public void setMinorTickLen(int minorTickLen)
      Set the minor tick length in pixels.
      Parameters:
      minorTickLen - the desired length; must be ≥ 0