Package edu.cnu.mdi.splot.plot
Class NiceScale
java.lang.Object
edu.cnu.mdi.splot.plot.NiceScale
Utility for generating "nice" axis bounds and tick spacing.
Produces a tick spacing from the set {1, 2, 5}×10^n and expands the requested min/max to "nice" endpoints aligned to that spacing.
-
Constructor Summary
ConstructorsConstructorDescriptionNiceScale(double min, double max) Convenience constructor: defaults to 10 ticks including ends, not forced to include zero.NiceScale(double min, double max, int numTicks) Convenience constructor: not forced to include zero.NiceScale(double min, double max, int numTicks, boolean includeZero) Instantiates a new instance of the NiceScale class. -
Method Summary
Modifier and TypeMethodDescriptiondoubleGet the nice plot max (expanded and aligned).doubleGet the nice plot min (expanded and aligned).intGet the number of ticks (including the ends).intThe actual number of ticks returned bygetTicks().double[]getTicks()Return the tick locations from niceMin to niceMax inclusive.doubleGet the tick spacing.voidsetMaxTicks(int maxTicks) Sets maximum number of tick marks we're comfortable with (including ends).voidsetMinMaxPoints(double min, double max) Sets the minimum and maximum data points for the axis.
-
Constructor Details
-
NiceScale
public NiceScale(double min, double max) Convenience constructor: defaults to 10 ticks including ends, not forced to include zero.- Parameters:
min- minimum data valuemax- maximum data value
-
NiceScale
public NiceScale(double min, double max, int numTicks) Convenience constructor: not forced to include zero.- Parameters:
min- minimum data valuemax- maximum data valuenumTicks- number of ticks including ends (min 2 recommended)
-
NiceScale
public NiceScale(double min, double max, int numTicks, boolean includeZero) Instantiates a new instance of the NiceScale class.- Parameters:
min- the minimum data point on the axismax- the maximum data point on the axisnumTicks- the number of ticks including the endsincludeZero- if true, expand min/max so that 0 is included
-
-
Method Details
-
getTickSpacing
public double getTickSpacing()Get the tick spacing.- Returns:
- tick spacing
-
getNiceMin
public double getNiceMin()Get the nice plot min (expanded and aligned).- Returns:
- nice min
-
getNiceMax
public double getNiceMax()Get the nice plot max (expanded and aligned).- Returns:
- nice max
-
getNumTicks
public int getNumTicks()Get the number of ticks (including the ends).- Returns:
- number of ticks
-
setMinMaxPoints
public void setMinMaxPoints(double min, double max) Sets the minimum and maximum data points for the axis. Recomputes tick spacing and nice endpoints.- Parameters:
min- minimum data valuemax- maximum data value
-
setMaxTicks
public void setMaxTicks(int maxTicks) Sets maximum number of tick marks we're comfortable with (including ends). Recomputes tick spacing and nice endpoints.- Parameters:
maxTicks- maximum number of ticks (min 2)
-
getTicks
public double[] getTicks()Return the tick locations from niceMin to niceMax inclusive.- Returns:
- array of tick values (never null)
-
getTickCount
public int getTickCount()The actual number of ticks returned bygetTicks().- Returns:
- tick count
-