Class PamAxisFX

java.lang.Object
pamViewFX.fxNodes.pamAxis.PamAxisFX

public class PamAxisFX extends Object
Draws an axis on a JavaFX Node.

PamAxis contains all the information needed to draw an axis, the actual drawing is generally called from the paintComponent function in the containing window.

For a good example (in swing but similar to JavaFX), see PamAxisPanel which will automatically draw four axis around a central plot.

Author:
Doug Gillespie
See Also:
  • Property Summary

    Properties
    Type
    Property
    Description
    javafx.beans.value.ObservableValue<? extends String>
    The axis label
    javafx.beans.property.DoubleProperty
     
    javafx.beans.property.DoubleProperty
     
    javafx.beans.property.BooleanProperty
    Get the reverse property for the axis.
    javafx.beans.property.DoubleProperty
    The start x pixel.
    javafx.beans.property.DoubleProperty
    The end x pixel
    javafx.beans.property.DoubleProperty
    The start y pixel
    javafx.beans.property.DoubleProperty
    The end y pixel
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    Internal class to mimic the non-public JavaFx FontMetrics class, no longer available from JavaFX 9 onwards.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    PamAxisFX(double x1, double y1, double x2, double y2, double minVal, double maxVal, boolean aboveLeft, String label, String format)
     
    PamAxisFX(double x1, double y1, double x2, double y2, double minVal, double maxVal, int tickPosition, String label, int labelPos, String format)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    drawAxis(javafx.scene.canvas.GraphicsContext g)
    Draw the axis in the Graphics Context g
    void
    drawAxis(javafx.scene.canvas.GraphicsContext g, double x1, double y1, double x2, double y2)
    Draw the axis in the graphics context g at the given position
    void
    drawGrid(javafx.scene.canvas.GraphicsContext g, com.sun.javafx.geom.Dimension2D plotSize, int minorGrid)
    Draw a grid to go with the axis.
    void
    drawGrid(javafx.scene.canvas.GraphicsContext g, com.sun.javafx.geom.Dimension2D plotSize, javafx.geometry.Insets insets, int minorGrid)
     
    getAutoFormat(boolean isInteger)
     
    static String
    getAutoFormat(double minVal, double maxVal, boolean isInteger)
     
    Work out the optimal format for the axis labels based on analysis of previously used axis labels.
    ArrayList<javafx.geometry.Point2D>
    getAxisPoint2Ds(boolean extraOne)
    Work out the coordinates of all tick marks.
     
    double
    getDataValue(double position)
    Converts a position on the plot into a data value based on the axis max, min and scale.
    static double
    getDefaultScaleEnd(double val, double otherVal)
     
    int
    getExtent(javafx.scene.canvas.GraphicsContext g)
    Gets the dimension of the axis parallel to the direction of the tickmark - i.e.
    int
    getExtent(javafx.scene.canvas.GraphicsContext g, String typicalString)
    Gets the dimension of the axis parallel to the direction of the tickmark - i.e.
    int
    getExtent2(javafx.scene.canvas.GraphicsContext g)
    Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e.
    int
    getExtent2(javafx.scene.canvas.GraphicsContext g, String typicalString)
    Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e.
     
     
     
    Gets the value of the label property.
    int
     
    double
    Label scale can be used to change the scaling of axis labels without changing the underlying axis data that get used for display calculations and projections between screen coordinates and data values.
    double
    Gets the value of the maxVal property.
    double
    Gets the value of the minVal property.
    static int
    getNumDecPlaces(double value)
     
    double
    getPosition(double dataValue)
    The axis knows all about scale and can tell us the pixel value for any given data value.
    javafx.scene.paint.Color
     
    int
     
    double
    The size of the axis in pixels.
    double
    Gets the value of the x1 property.
    double
    Gets the value of the x2 property.
    double
    Gets the value of the y1 property.
    double
    Gets the value of the y2 property.
    boolean
     
    boolean
    Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    javafx.beans.value.ObservableValue<? extends String>
    The axis label
    javafx.beans.property.DoubleProperty
     
    javafx.beans.property.DoubleProperty
     
    javafx.beans.property.BooleanProperty
    Get the reverse property for the axis.
    void
    setAllowScaleMultiples(boolean allowScaleMultiples)
     
    void
    setAngleScales(boolean angleScales)
    Easy way to make scales end at 45, 90, 180, etc and step in sensible 45, 90, etc.
    void
    setAutoFormat(boolean isInteger)
    Automatically set the format of axis labels based on the types of numbers in there.
    void
    setCrampLabels(boolean crampLabels)
    Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.
    void
    setDrawLine(boolean drawLine)
     
    void
    setExtraAxisEndLabel(String extraAxisEndLabel)
     
    void
    setExtraAxisStartLabel(String extraAxStartLabel)
     
    void
    setForceFirstVal(boolean forceFirstVal, double forcedFirstVal)
     
    void
    setFormat(String format)
    Set the format string for writing out numbers on the axis.
    void
    setFractionalScale(boolean fractionalScale)
     
    void
    setInterval(double interval)
    Set the interval between ticks.
    void
    setLabel(String labelTxt)
    Set the axis label text
    void
    setLabelPos(int labelPos)
     
    void
    setLabelScale(double labelScale)
    Label scale can be used to change the scaling of axis labels without changing the underlying axis data that get used for display calculations and projections between screen coordinates and data values.
    void
    setLogScale(boolean logScale)
     
    void
    setLogTenthsScale(boolean logTenthsScale)
     
    void
    setMaxVal(double maxVal)
    Sets the value of the maxVal property.
    void
    setMinVal(double minVal)
    Sets the value of the minVal property.
    void
    setPosition(double x1, double y1, double x2, double y2)
    Set the axis default coordinates
    void
    setRange(double minVal, double maxVal)
    Set the minimum and maximum values for the axis.
    void
    setReversed(boolean reverseAxis2)
    Set whether the axis is reversed.
    void
    setStrokeColor(javafx.scene.paint.Color strokeColor)
    Set the stroke colour.
    void
    setTickPosition(int tickPosition)
     
    void
    setX1(double x1)
    Sets the value of the x1 property.
    void
    setX2(double x2)
    Sets the value of the x2 property.
    void
    setY1(double y1)
    Sets the value of the y1 property.
    void
    setY2(double y2)
    Sets the value of the y2 property.
    javafx.beans.property.DoubleProperty
    The start x pixel.
    javafx.beans.property.DoubleProperty
    The end x pixel
    javafx.beans.property.DoubleProperty
    The start y pixel
    javafx.beans.property.DoubleProperty
    The end y pixel

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Property Details

  • Field Details

  • Constructor Details

    • PamAxisFX

      public PamAxisFX(double x1, double y1, double x2, double y2, double minVal, double maxVal, int tickPosition, String label, int labelPos, String format)
      Parameters:
      x1 - first x coordinate of axis
      y1 - first y coordinate of axis
      x2 - second x coordinate of axis
      y2 - second coordinate of axis
      minVal - minimum axis value
      maxVal - maximum axis value
      tickPosition - tick position (ABOVE_LEFT or BELOW_RIGHT)
      label - text for label (or null if no label)
      labelPos - Position of axis label (LABEL_NEAR_MAX, LABEL_NEAR_MIN or LABEL_NEAR_CENTRE)
      format - format for numbers printed on the display. This must be a standard format String such as "%d", "%f", "%3.1f", "%.2 seconds", etc.
    • PamAxisFX

      public PamAxisFX(double x1, double y1, double x2, double y2, double minVal, double maxVal, boolean aboveLeft, String label, String format)
      Parameters:
      x1 - x1
      y1 - y1
      x2 - x2
      y2 - y2
      minVal - min axis value
      maxVal - max axis value
      aboveLeft - above and / or to the left
      label - axis label
      format - format of numbers
  • Method Details

    • setPosition

      public void setPosition(double x1, double y1, double x2, double y2)
      Set the axis default coordinates
      Parameters:
      x1 -
      y1 -
      x2 -
      y2 -
    • setInterval

      public void setInterval(double interval)
      Set the interval between ticks. This is by default set to INTERVAL_AUTO whereby an interval is chosen so that there is a tick mark approximately every 100 pixels.
      Parameters:
      interval - the interval or INTERVAL_AUTO
    • setRange

      public void setRange(double minVal, double maxVal)
      Set the minimum and maximum values for the axis.
      Parameters:
      minVal - - the minimum value of the axis
      maxVal - - the maximu value of the axis.
    • drawAxis

      public void drawAxis(javafx.scene.canvas.GraphicsContext g, double x1, double y1, double x2, double y2)
      Draw the axis in the graphics context g at the given position
      Parameters:
      g -
      x1 -
      y1 -
      x2 -
      y2 -
    • drawAxis

      public void drawAxis(javafx.scene.canvas.GraphicsContext g)
      Draw the axis in the Graphics Context g
      Parameters:
      g - graphics context to draw on
    • getAxisPoint2Ds

      public ArrayList<javafx.geometry.Point2D> getAxisPoint2Ds(boolean extraOne)
      Work out the coordinates of all tick marks.
      Parameters:
      extraOne -
      Returns:
      list of axis Point2Ds.
    • drawGrid

      public void drawGrid(javafx.scene.canvas.GraphicsContext g, com.sun.javafx.geom.Dimension2D plotSize, int minorGrid)
      Draw a grid to go with the axis. Generally, the graphics handle for grid drawing will be some inner window sitting inside the window containing the axis.
      Parameters:
      g - Graphics context to draw on
      plotSize - size of the graphic
      minorGrid - draw a minor grid as well as lines at the main tick marks.
    • drawGrid

      public void drawGrid(javafx.scene.canvas.GraphicsContext g, com.sun.javafx.geom.Dimension2D plotSize, javafx.geometry.Insets insets, int minorGrid)
    • getExtent2

      public int getExtent2(javafx.scene.canvas.GraphicsContext g)
      Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e. for a vertical axis, it's half the text height, for a horizontal axis it's half the typical string width.
      Parameters:
      g - graphics handle for component the axis is to be draw on
      Returns:
      axis extent in pixels
    • getExtent2

      public int getExtent2(javafx.scene.canvas.GraphicsContext g, String typicalString)
      Gets the dimension of the axis perpendicular to the direction of the tickmark - i.e. for a vertical axis, it's half the text height, for a horizontal axis it's half the typical string width.
      Parameters:
      g - graphics handle for component the axis is to be draw on
      typicalString - typical text string.
      Returns:
      Axis extent
    • getExtent

      public int getExtent(javafx.scene.canvas.GraphicsContext g)
      Gets the dimension of the axis parallel to the direction of the tickmark - i.e. the ticklength + the text height + the label height.
      Parameters:
      g - graphics handle for component the axis is to be draw on
      Returns:
      axis extent in pixels
    • getExtent

      public int getExtent(javafx.scene.canvas.GraphicsContext g, String typicalString)
      Gets the dimension of the axis parallel to the direction of the tickmark - i.e. the ticklength + the text height + the label height.
      Parameters:
      g - graphics handle the axis is being draw on
      typicalString - typical label string for a tick
      Returns:
      axisextent in pixels
    • isLogScale

      public boolean isLogScale()
    • setLogScale

      public void setLogScale(boolean logScale)
    • isDrawLine

      public boolean isDrawLine()
    • setDrawLine

      public void setDrawLine(boolean drawLine)
    • getFormat

      public String getFormat()
    • setFormat

      public void setFormat(String format)
      Set the format string for writing out numbers on the axis.
      Parameters:
      format - format string
    • setAutoFormat

      public void setAutoFormat(boolean isInteger)
      Automatically set the format of axis labels based on the types of numbers in there.
    • getAutoFormat

      public String getAutoFormat(boolean isInteger)
    • getAutoFormat

      public static String getAutoFormat(double minVal, double maxVal, boolean isInteger)
    • getNumDecPlaces

      public static int getNumDecPlaces(double value)
    • isIntegerFormat

      public boolean isIntegerFormat()
    • getLabel

      public String getLabel()
      Gets the value of the label property.
      Property description:
      The axis label
      Returns:
      the value of the label property
      See Also:
    • setLabel

      public void setLabel(String labelTxt)
      Set the axis label text
      Parameters:
      labelTxt -
    • getLabelPos

      public int getLabelPos()
    • setLabelPos

      public void setLabelPos(int labelPos)
    • getTickPosition

      public int getTickPosition()
    • setTickPosition

      public void setTickPosition(int tickPosition)
    • getMaxVal

      public double getMaxVal()
      Gets the value of the maxVal property.
      Property description:
      Returns:
      the value of the maxVal property
      See Also:
    • setMaxVal

      public void setMaxVal(double maxVal)
      Sets the value of the maxVal property.
      Property description:
      Parameters:
      maxVal - the value for the maxVal property
      See Also:
    • getMinVal

      public double getMinVal()
      Gets the value of the minVal property.
      Property description:
      Returns:
      the value of the minVal property
      See Also:
    • setMinVal

      public void setMinVal(double minVal)
      Sets the value of the minVal property.
      Property description:
      Parameters:
      minVal - the value for the minVal property
      See Also:
    • minValProperty

      public javafx.beans.property.DoubleProperty minValProperty()
      Returns:
      the minVal property
      See Also:
    • maxValProperty

      public javafx.beans.property.DoubleProperty maxValProperty()
      Returns:
      the maxVal property
      See Also:
    • getAutoLabelFormat

      public String getAutoLabelFormat()
      Work out the optimal format for the axis labels based on analysis of previously used axis labels.
      Returns:
      some kind of sensible format string !
    • getDefaultScaleEnd

      public static double getDefaultScaleEnd(double val, double otherVal)
    • setForceFirstVal

      public void setForceFirstVal(boolean forceFirstVal, double forcedFirstVal)
    • isLogTenthsScale

      public boolean isLogTenthsScale()
    • setLogTenthsScale

      public void setLogTenthsScale(boolean logTenthsScale)
    • getAxisValues

      public ArrayList<Double> getAxisValues()
    • getX1

      public double getX1()
      Gets the value of the x1 property.
      Property description:
      The start x pixel.
      Returns:
      the value of the x1 property
      See Also:
    • setX1

      public void setX1(double x1)
      Sets the value of the x1 property.
      Property description:
      The start x pixel.
      Parameters:
      x1 - the value for the x1 property
      See Also:
    • getX2

      public double getX2()
      Gets the value of the x2 property.
      Property description:
      The end x pixel
      Returns:
      the value of the x2 property
      See Also:
    • setX2

      public void setX2(double x2)
      Sets the value of the x2 property.
      Property description:
      The end x pixel
      Parameters:
      x2 - the value for the x2 property
      See Also:
    • getY1

      public double getY1()
      Gets the value of the y1 property.
      Property description:
      The start y pixel
      Returns:
      the value of the y1 property
      See Also:
    • setY1

      public void setY1(double y1)
      Sets the value of the y1 property.
      Property description:
      The start y pixel
      Parameters:
      y1 - the value for the y1 property
      See Also:
    • getY2

      public double getY2()
      Gets the value of the y2 property.
      Property description:
      The end y pixel
      Returns:
      the value of the y2 property
      See Also:
    • setY2

      public void setY2(double y2)
      Sets the value of the y2 property.
      Property description:
      The end y pixel
      Parameters:
      y2 - the value for the y2 property
      See Also:
    • x1Property

      public javafx.beans.property.DoubleProperty x1Property()
      The start x pixel.
      Returns:
      the x1 property
      See Also:
    • x2Property

      public javafx.beans.property.DoubleProperty x2Property()
      The end x pixel
      Returns:
      the x2 property
      See Also:
    • y1Property

      public javafx.beans.property.DoubleProperty y1Property()
      The start y pixel
      Returns:
      the y1 property
      See Also:
    • y2Property

      public javafx.beans.property.DoubleProperty y2Property()
      The end y pixel
      Returns:
      the y2 property
      See Also:
    • getPosition

      public double getPosition(double dataValue)
      The axis knows all about scale and can tell us the pixel value for any given data value.
      Parameters:
      dataValue - the value of the data.
      Returns:
      position in pixels along the axis for a given data value.
    • getDataValue

      public double getDataValue(double position)
      Converts a position on the plot into a data value based on the axis max, min and scale.

      This is the exact compliment of getPosition()

      Parameters:
      position - position along the axis in pixels.
      Returns:
      data value.
    • isAllowScaleMultiples

      public boolean isAllowScaleMultiples()
    • setAllowScaleMultiples

      public void setAllowScaleMultiples(boolean allowScaleMultiples)
    • setAngleScales

      public void setAngleScales(boolean angleScales)
      Easy way to make scales end at 45, 90, 180, etc and step in sensible 45, 90, etc. steps.
      Parameters:
      angleScales -
    • isFractionalScale

      public boolean isFractionalScale()
    • setFractionalScale

      public void setFractionalScale(boolean fractionalScale)
    • getExtraAxisStartLabel

      public String getExtraAxisStartLabel()
      Returns:
      the extraAxStartLabel
    • setExtraAxisStartLabel

      public void setExtraAxisStartLabel(String extraAxStartLabel)
      Parameters:
      extraAxStartLabel - the extraAxStartLabel to set
    • getExtraAxisEndLabel

      public String getExtraAxisEndLabel()
      Returns:
      the extraAxisEndLabel
    • setExtraAxisEndLabel

      public void setExtraAxisEndLabel(String extraAxisEndLabel)
      Parameters:
      extraAxisEndLabel - the extraAxisEndLabel to set
    • isCrampLabels

      public boolean isCrampLabels()
      Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.
      Returns:
      the crampLables
    • setCrampLabels

      public void setCrampLabels(boolean crampLabels)
      Cramped labels means that when drawing an axis, the end labels will be shifted to remain within the bounds of the axis itself.
      Parameters:
      crampLabels - the crampLables to set
    • getTotalPixels

      public double getTotalPixels()
      The size of the axis in pixels.
      e.g. if a horizontal axis this would be the width of the display.
      Returns:
      the size of the axis in pixels.
    • setStrokeColor

      public void setStrokeColor(javafx.scene.paint.Color strokeColor)
      Set the stroke colour.
      Parameters:
      strokeColor -
    • getStrokeColor

      public javafx.scene.paint.Color getStrokeColor()
    • labelProperty

      public javafx.beans.value.ObservableValue<? extends String> labelProperty()
      The axis label
      Returns:
      the label property
      See Also:
    • getLabelScale

      public double getLabelScale()
      Label scale can be used to change the scaling of axis labels without changing the underlying axis data that get used for display calculations and projections between screen coordinates and data values. For instance this may be used on a time axis which wants to keep with SI units of seconds, but finds it 'nicer' to display the scale in millisecs, in which case labelScale should be set to 1000.
      Returns:
      the labelScale
    • setLabelScale

      public void setLabelScale(double labelScale)
      Label scale can be used to change the scaling of axis labels without changing the underlying axis data that get used for display calculations and projections between screen coordinates and data values. For instance this may be used on a time axis which wants to keep with SI units of seconds, but finds it 'nicer' to display the scale in millisecs, in which case labelScale should be set to 1000.
      Parameters:
      labelScale - the labelScale to set
    • reverseProperty

      public javafx.beans.property.BooleanProperty reverseProperty()
      Get the reverse property for the axis. The reverse property indicates whether the axis should be display from minimum at top of screen to maximum at bottom of the screen instead of the default vice versa.
      Returns:
      the reverse boolean property.
    • setReversed

      public void setReversed(boolean reverseAxis2)
      Set whether the axis is reversed. This indicates whether the axis should be display from minimum at top of screen to maximum at bottom of the screen instead of the default vice versa.