org.opensha.commons.gui.plot.jfreechart
Class JFreeLogarithmicAxis

java.lang.Object
  extended by org.jfree.chart.axis.Axis
      extended by org.jfree.chart.axis.ValueAxis
          extended by org.jfree.chart.axis.LogAxis
              extended by org.opensha.commons.gui.plot.jfreechart.JFreeLogarithmicAxis
All Implemented Interfaces:
Serializable, Cloneable, org.jfree.util.PublicCloneable

public class JFreeLogarithmicAxis
extends org.jfree.chart.axis.LogAxis

A numerical axis that uses a logarithmic scale.

Author:
Michael Duffy
See Also:
Serialized Form

Field Summary
protected  boolean expTickLabelsFlag
          Flag set true for "1e#"-style tick labels.
static double LOG10_VALUE
          Useful constant for log(10).
protected  boolean log10TickLabelsInPowerFlag
          Flag set true for representing the tick labels as the super script of 10
protected  boolean minorAxisTickLabelFlag
          Flag set true to show the tick labels for minor axis
protected  NumberFormat numberFormatterObj
          Number formatter for generating numeric strings.
static double SMALL_LOG_VALUE
          Smallest arbitrarily-close-to-zero value allowed.
protected  boolean strictValuesFlag
          Flag set true make axis throw exception if any values are <= 0 and 'allowNegativesFlag' is false.
 
Fields inherited from class org.jfree.chart.axis.ValueAxis
DEFAULT_AUTO_RANGE, DEFAULT_AUTO_RANGE_MINIMUM_SIZE, DEFAULT_AUTO_TICK_UNIT_SELECTION, DEFAULT_INVERTED, DEFAULT_LOWER_BOUND, DEFAULT_LOWER_MARGIN, DEFAULT_RANGE, DEFAULT_UPPER_BOUND, DEFAULT_UPPER_MARGIN, MAXIMUM_TICK_COUNT
 
Fields inherited from class org.jfree.chart.axis.Axis
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_LINE_PAINT, DEFAULT_AXIS_LINE_STROKE, DEFAULT_AXIS_VISIBLE, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_LABELS_VISIBLE, DEFAULT_TICK_MARK_INSIDE_LENGTH, DEFAULT_TICK_MARK_OUTSIDE_LENGTH, DEFAULT_TICK_MARK_PAINT, DEFAULT_TICK_MARK_STROKE, DEFAULT_TICK_MARKS_VISIBLE
 
Constructor Summary
JFreeLogarithmicAxis(String label)
           
 
Method Summary
 void autoAdjustRange()
          Rescales the axis to ensure that all data is visible.
protected  double computeLogCeil(double upper)
          Returns the smallest (closest to negative infinity) double value that is not less than the argument, is equal to a mathematical integer and satisfying the condition that log base 10 of the value is an integer (i.e., the value returned will be a power of 10: 1, 10, 100, 1000, etc.).
protected  double computeLogFloor(double lower)
          Returns the largest (closest to positive infinity) double value that is not greater than the argument, is equal to a mathematical integer and satisfying the condition that log base 10 of the value is an integer (i.e., the value returned will be a power of 10: 1, 10, 100, 1000, etc.).
protected  org.jfree.chart.axis.AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)
          Draws the axis line, tick marks and tick mark labels.
 boolean getExpTickLabelsFlag()
          Returns the 'expTickLabelsFlag' flag.
 boolean getLog10TickLabelsInPowerFlag()
          Returns the 'log10TickLabelsInPowerFlag' flag.
 boolean getMinorAxisTickLabelFlag()
           
 boolean getStrictValuesFlag()
          Returns the 'strictValuesFlag' flag; if true then this axis will throw a runtime exception if any of its values are less than or equal to zero; if false then the axis will adjust for values less than or equal to zero as needed.
protected  String makeTickLabel(double val)
          Converts the given value to a tick label string.
protected  String makeTickLabel(double val, boolean forceFmtFlag)
          Converts the given value to a tick label string.
 List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)
          Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).
 List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)
          Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).
 void setExpTickLabelsFlag()
          Sets the 'expTickLabelsFlag' flag to true for for "1e#"-style tick labels, false for representing the power of 10 in superScript.
 void setLog10TickLabelsInPowerFlag()
          Sets the 'log10TickLabelsInPowerFlag' flag to true for representing the power of 10 in superScript , false for "1e#"-style tick labels.
 void setMinorAxisTickLabelFlag(boolean flag)
          Sets the minorAxisTickLabelFlag to true for showing the tick labels for minor axis, else sets it false.
 void setStrictValuesFlag(boolean flgVal)
          Sets the 'strictValuesFlag' flag; if true; then this axis will throw a runtime exception if any of its values are less than or equal to zero; if false then the axis will adjust for values less than or equal to zero as needed.
protected  void setupNumberFmtObj()
          Sets up the number formatter object according to the 'expTickLabelsFlag' flag.
 void setVerticalAnchorShift(float verticalAnchorShift)
          This allows you to shift the tick labels vertically to fix some overlap issues (specifically with X axis).
protected  double switchedLog10(double val)
          Returns the log10 value, depending on if values between 0 and 1 are being plotted.
 
Methods inherited from class org.jfree.chart.axis.LogAxis
calculateLog, calculateValue, configure, createLogTickUnits, createTickLabel, draw, equals, estimateMaximumTickLabelHeight, estimateMaximumTickLabelWidth, exponentLengthToJava2D, getBase, getNumberFormatOverride, getSmallestValue, getTickUnit, hashCode, java2DToValue, pan, refreshTicks, selectAutoTickUnit, selectHorizontalAutoTickUnit, selectVerticalAutoTickUnit, setBase, setNumberFormatOverride, setSmallestValue, setTickUnit, setTickUnit, valueToJava2D, zoomRange
 
Methods inherited from class org.jfree.chart.axis.ValueAxis
calculateAnchorPoint, centerRange, clone, drawAxisLine, findMaximumTickLabelHeight, findMaximumTickLabelWidth, getAutoRangeMinimumSize, getAutoTickIndex, getDefaultAutoRange, getDownArrow, getFixedAutoRange, getLeftArrow, getLowerBound, getLowerMargin, getMinorTickCount, getRange, getRightArrow, getStandardTickUnits, getUpArrow, getUpperBound, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isInverted, isNegativeArrowVisible, isPositiveArrowVisible, isVerticalTickLabels, lengthToJava2D, reserveSpace, resizeRange, resizeRange, resizeRange2, setAutoRange, setAutoRange, setAutoRangeMinimumSize, setAutoRangeMinimumSize, setAutoTickIndex, setAutoTickUnitSelection, setAutoTickUnitSelection, setDefaultAutoRange, setDownArrow, setFixedAutoRange, setInverted, setLeftArrow, setLowerBound, setLowerMargin, setMinorTickCount, setNegativeArrowVisible, setPositiveArrowVisible, setRange, setRange, setRange, setRangeAboutValue, setRangeWithMargins, setRangeWithMargins, setRangeWithMargins, setRightArrow, setStandardTickUnits, setUpArrow, setUpperBound, setUpperMargin, setVerticalTickLabels
 
Methods inherited from class org.jfree.chart.axis.Axis
addChangeListener, createAndAddEntity, createAttributedLabel, drawAttributedLabel, drawLabel, fireChangeEvent, getAttributedLabel, getAxisLinePaint, getAxisLineStroke, getFixedDimension, getLabel, getLabelAngle, getLabelEnclosure, getLabelFont, getLabelInsets, getLabelLocation, getLabelPaint, getMinorTickMarkInsideLength, getMinorTickMarkOutsideLength, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, hasListener, isAxisLineVisible, isMinorTickMarksVisible, isTickLabelsVisible, isTickMarksVisible, isVisible, labelAnchorH, labelAnchorV, labelLocationX, labelLocationY, notifyListeners, removeChangeListener, setAttributedLabel, setAttributedLabel, setAxisLinePaint, setAxisLineStroke, setAxisLineVisible, setFixedDimension, setLabel, setLabelAngle, setLabelFont, setLabelInsets, setLabelInsets, setLabelLocation, setLabelPaint, setMinorTickMarkInsideLength, setMinorTickMarkOutsideLength, setMinorTickMarksVisible, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG10_VALUE

public static final double LOG10_VALUE
Useful constant for log(10).


SMALL_LOG_VALUE

public static final double SMALL_LOG_VALUE
Smallest arbitrarily-close-to-zero value allowed.

See Also:
Constant Field Values

strictValuesFlag

protected boolean strictValuesFlag
Flag set true make axis throw exception if any values are <= 0 and 'allowNegativesFlag' is false.


numberFormatterObj

protected final NumberFormat numberFormatterObj
Number formatter for generating numeric strings.


expTickLabelsFlag

protected boolean expTickLabelsFlag
Flag set true for "1e#"-style tick labels.


log10TickLabelsInPowerFlag

protected boolean log10TickLabelsInPowerFlag
Flag set true for representing the tick labels as the super script of 10


minorAxisTickLabelFlag

protected boolean minorAxisTickLabelFlag
Flag set true to show the tick labels for minor axis

Constructor Detail

JFreeLogarithmicAxis

public JFreeLogarithmicAxis(String label)
Method Detail

setStrictValuesFlag

public void setStrictValuesFlag(boolean flgVal)
Sets the 'strictValuesFlag' flag; if true; then this axis will throw a runtime exception if any of its values are less than or equal to zero; if false then the axis will adjust for values less than or equal to zero as needed.

Parameters:
flgVal - true for strict enforcement.

getStrictValuesFlag

public boolean getStrictValuesFlag()
Returns the 'strictValuesFlag' flag; if true then this axis will throw a runtime exception if any of its values are less than or equal to zero; if false then the axis will adjust for values less than or equal to zero as needed.

Returns:
true if strict enforcement is enabled.

setExpTickLabelsFlag

public void setExpTickLabelsFlag()
Sets the 'expTickLabelsFlag' flag to true for for "1e#"-style tick labels, false for representing the power of 10 in superScript.


setupNumberFmtObj

protected void setupNumberFmtObj()
Sets up the number formatter object according to the 'expTickLabelsFlag' flag.


getExpTickLabelsFlag

public boolean getExpTickLabelsFlag()
Returns the 'expTickLabelsFlag' flag.

Returns:
true for "1e#"-style tick labels, false for log10 or regular numeric tick labels.

setLog10TickLabelsInPowerFlag

public void setLog10TickLabelsInPowerFlag()
Sets the 'log10TickLabelsInPowerFlag' flag to true for representing the power of 10 in superScript , false for "1e#"-style tick labels.


getLog10TickLabelsInPowerFlag

public boolean getLog10TickLabelsInPowerFlag()
Returns the 'log10TickLabelsInPowerFlag' flag.

Returns:
true for representing the power of 10 in superScript , false for "1e#"-style or "10^n"-style tick labels.

setMinorAxisTickLabelFlag

public void setMinorAxisTickLabelFlag(boolean flag)
Sets the minorAxisTickLabelFlag to true for showing the tick labels for minor axis, else sets it false. If "1e#" style of labelling is being used then this function will not show the minor axis tick labelling if flag set to true.

Parameters:
flag - : sets the minorAxisTickLabel flag to true or false

getMinorAxisTickLabelFlag

public boolean getMinorAxisTickLabelFlag()
Returns:
true if minorAxis tick labels are to shown, false if they are not to be shown.

refreshTicksHorizontal

public List refreshTicksHorizontal(Graphics2D g2,
                                   Rectangle2D dataArea,
                                   org.jfree.ui.RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).

Overrides:
refreshTicksHorizontal in class org.jfree.chart.axis.LogAxis
Parameters:
g2 - the graphics device.
dataArea - the area in which the plot should be drawn.
edge - the location of the axis.

switchedLog10

protected double switchedLog10(double val)
Returns the log10 value, depending on if values between 0 and 1 are being plotted. If negative values are not allowed and the lower bound is between 0 and 10 then a normal log is returned; otherwise the returned value is adjusted if the given value is less than 10.

Parameters:
val - the value.
Returns:
log10(val).

refreshTicksVertical

public List refreshTicksVertical(Graphics2D g2,
                                 Rectangle2D dataArea,
                                 org.jfree.ui.RectangleEdge edge)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).

Overrides:
refreshTicksVertical in class org.jfree.chart.axis.LogAxis
Parameters:
g2 - the graphics device.
dataArea - the area in which the plot should be drawn.
edge - the axis location.

setVerticalAnchorShift

public void setVerticalAnchorShift(float verticalAnchorShift)
This allows you to shift the tick labels vertically to fix some overlap issues (specifically with X axis).

Parameters:
verticalAnchorShift -

drawTickMarksAndLabels

protected org.jfree.chart.axis.AxisState drawTickMarksAndLabels(Graphics2D g2,
                                                                double cursor,
                                                                Rectangle2D plotArea,
                                                                Rectangle2D dataArea,
                                                                org.jfree.ui.RectangleEdge edge)
Draws the axis line, tick marks and tick mark labels.

Overrides:
drawTickMarksAndLabels in class org.jfree.chart.axis.ValueAxis
Parameters:
g2 - the graphics device.
cursor - the cursor.
plotArea - the plot area.
dataArea - the data area.
edge - the edge that the axis is aligned with.
Returns:
The width or height used to draw the axis.

makeTickLabel

protected String makeTickLabel(double val,
                               boolean forceFmtFlag)
Converts the given value to a tick label string.

Parameters:
val - the value to convert.
forceFmtFlag - true to force the number-formatter object to be used.
Returns:
The tick label string.

makeTickLabel

protected String makeTickLabel(double val)
Converts the given value to a tick label string.

Parameters:
val - the value to convert.
Returns:
The tick label string.

computeLogFloor

protected double computeLogFloor(double lower)
Returns the largest (closest to positive infinity) double value that is not greater than the argument, is equal to a mathematical integer and satisfying the condition that log base 10 of the value is an integer (i.e., the value returned will be a power of 10: 1, 10, 100, 1000, etc.).

Parameters:
lower - a double value below which a floor will be calcualted.
Returns:
10N with N .. { 1 ... }

computeLogCeil

protected double computeLogCeil(double upper)
Returns the smallest (closest to negative infinity) double value that is not less than the argument, is equal to a mathematical integer and satisfying the condition that log base 10 of the value is an integer (i.e., the value returned will be a power of 10: 1, 10, 100, 1000, etc.).

Parameters:
upper - a double value above which a ceiling will be calcualted.
Returns:
10N with N .. { 1 ... }

autoAdjustRange

public void autoAdjustRange()
Rescales the axis to ensure that all data is visible.

Overrides:
autoAdjustRange in class org.jfree.chart.axis.LogAxis