Class PlotTicks
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
ConstructorsConstructorDescriptionPlotTicks(PlotCanvas plotCanvas) Construct aPlotTicksinstance for the given canvas. -
Method Summary
Modifier and TypeMethodDescriptionvoiddraw(Graphics2D g2) Draw all tick marks and tick labels onto the plot canvas.intReturns the major tick length in pixels.intReturns the minor tick length in pixels.intReturns the number of interior major ticks on the X axis (linear mode).intReturns the number of interior major ticks on the Y axis (linear mode).intReturns the number of interior minor ticks per major interval on the X axis.intReturns the number of interior minor ticks per major interval on the Y axis.voidsetDrawBinValue(boolean drawBinVal) Enable or disable bin-index labels on the X axis.voidsetMajorTickLen(int majorTickLen) Set the major tick length in pixels.voidsetMinorTickLen(int minorTickLen) Set the minor tick length in pixels.voidsetNumMajorTickX(int numMajorTickX) Set the number of interior major ticks on the X axis (linear mode).voidsetNumMajorTickY(int numMajorTickY) Set the number of interior major ticks on the Y axis (linear mode).voidsetNumMinorTickX(int numMinorTickX) Set the number of interior minor ticks per major interval on the X axis.voidsetNumMinorTickY(int numMinorTickY) Set the number of interior minor ticks per major interval on the Y axis.voidsetTickFont(Font font) Override the font used for tick labels.
-
Constructor Details
-
PlotTicks
Construct aPlotTicksinstance for the given canvas.- Parameters:
plotCanvas- the canvas this instance will draw ticks on; must not benull
-
-
Method Details
-
setTickFont
Override the font used for tick labels.- Parameters:
font- the replacement font; must not benull
-
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-trueto show bin indices;falseto show raw values
-
draw
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
-