Class CartesianType1

java.lang.Object
org.opensourcephysics.display.axes.AbstractAxes
org.opensourcephysics.display.axes.CartesianType1
All Implemented Interfaces:
CartesianAxes, DrawableAxes, Dimensioned, Drawable
Direct Known Subclasses:
CartesianInteractive

public class CartesianType1 extends AbstractAxes implements CartesianAxes, Dimensioned
A modified version of the ptolemy.plot.PlotBox class designed to work with the OSP drawing framework. See Ptolemy Group Java at UC Berkeley for more information. This class provides a labeled box within which to place a data plot. A title, X and Y axis labels, and tick marks are all supported. The tick marks for the axes are usually computed automatically from the ranges. Every attempt is made to choose reasonable positions for the tick marks regardless of the data ranges (powers of ten multiplied by 1, 2, or 5 are used). However, they can also be specified explicitly using the methods addXTick and addYTick. A label is a string that must be surrounded by quotation marks if it contains any spaces. A position is a number giving the location of the tick mark along the axis. For example, a horizontal axis for a frequency domain plot might have tick marks as follows:
XTicks: -PI -3.14159, -PI/2 -1.570795, 0 0, PI/2 1.570795, PI 3.14159
Tick marks could also denote years, months, days of the week, etc. Exponents are not drawn if min and max values are between 0 and 1000 and a linear scale is used.

The X and Y axes can also use a logarithmic scale. The grid labels represent powers of 10. Note that if a logarithmic scale is used, then the values (before the log of the value is taken) must be positive. Non-positive values will be silently dropped. By default, tick marks are connected by a light grey background grid.

Author:
J. Gould, W. Christian
  • Field Details

  • Constructor Details

    • CartesianType1

      public CartesianType1(PlottingPanel panel)
      Constructor for the AxesType1 object
      Parameters:
      panel - the panel on which this axes is drawn
  • Method Details

    • draw

      public void draw(DrawingPanel panel, Graphics g)
      Draws the plot by implementing the drawable interface. Most of the drawing is done in the DrawPlot method after the gutters are set.
      Specified by:
      draw in interface Drawable
      Parameters:
      panel -
      g -
    • addXTick

      public void addXTick(String label, double position)
      Specify a tick mark for the X axis. The label given is placed on the axis at the position given by position . If this is called once or more, automatic generation of tick marks is disabled. The tick mark will appear only if it is within the X range.
      Parameters:
      label - The label for the tick mark.
      position - The position on the X axis.
    • addYTick

      public void addYTick(String label, double position)
      Specify a tick mark for the Y axis. The label given is placed on the axis at the position given by position . If this is called once or more, automatic generation of tick marks is disabled. The tick mark will appear only if it is within the Y range.
      Parameters:
      label - The label for the tick mark.
      position - The position on the Y axis.
    • setLabelFont

      public void setLabelFont(String name)
      Set the label font, which is used for axis labels and legend labels. The font names understood are those understood by java.awt.Font.decode().
      Parameters:
      name - A font name.
    • setTitle

      public void setTitle(String title, String font_name)
      Set the title of the graph. The font names understood are those understood by java.awt.Font.decode(). If the font name is null, the font remains unchanged.
      Specified by:
      setTitle in interface DrawableAxes
      Overrides:
      setTitle in class AbstractAxes
      Parameters:
      title - the title
      font_name - an optional font name
    • setTitleFont

      public void setTitleFont(String name)
      Set the title font. The font names understood are those understood by java.awt.Font.decode().
      Parameters:
      name - A font name.
    • setXLabel

      public void setXLabel(String label, String font_name)
      Set the label for the X (horizontal) axis. The font names understood are those understood by java.awt.Font.decode(). If the font name is null, the font remains unchanged.
      Specified by:
      setXLabel in interface DrawableAxes
      Parameters:
      label - the label
      font_name - an optional font name
    • setXLog

      public void setXLog(boolean xlog)
      Specify whether the X axis is drawn with a logarithmic scale.
      Specified by:
      setXLog in interface CartesianAxes
      Parameters:
      xlog - If true, logarithmic axis is used.
    • setYLabel

      public void setYLabel(String label, String font_name)
      Set the label for the Y (vertical) axis. The font names understood are those understood by java.awt.Font.decode(). If the font name is null, the font remains unchanged.
      Specified by:
      setYLabel in interface DrawableAxes
      Parameters:
      label - the label
      font_name - an optional font name
    • setYLog

      public void setYLog(boolean ylog)
      Specify whether the Y axis is drawn with a logarithmic scale.
      Specified by:
      setYLog in interface CartesianAxes
      Parameters:
      ylog - If true, logarithmic axis is used.
    • getTitle

      public String getTitle()
      Get the title of the graph, or an empty string if there is none.
      Specified by:
      getTitle in interface DrawableAxes
      Overrides:
      getTitle in class AbstractAxes
      Returns:
      The title.
    • getXLabel

      public String getXLabel()
      Get the label for the X (horizontal) axis, or null if none has been set.
      Specified by:
      getXLabel in interface DrawableAxes
      Returns:
      The X label.
    • isXLog

      public boolean isXLog()
      Return whether the X axis is drawn with a logarithmic scale.
      Specified by:
      isXLog in interface CartesianAxes
      Returns:
      True if the X axis is logarithmic.
    • getYLabel

      public String getYLabel()
      Get the label for the Y (vertical) axis, or null if none has been set.
      Specified by:
      getYLabel in interface DrawableAxes
      Returns:
      The Y label.
    • isYLog

      public boolean isYLog()
      Return whether the Y axis is drawn with a logarithmic scale.
      Specified by:
      isYLog in interface CartesianAxes
      Returns:
      True if the Y axis is logarithmic.
    • resizeFonts

      public void resizeFonts(double factor, DrawingPanel panel)
      Resizes fonts by the specified factor.
      Specified by:
      resizeFonts in interface DrawableAxes
      Overrides:
      resizeFonts in class AbstractAxes
      Parameters:
      factor - the factor
      panel - the drawing panel on which these axes are drawn
    • getTickLength

      public int getTickLength()
    • drawPlot

      protected void drawPlot(DrawingPanel panel, Graphics graphics)
      Draws the axes onto the specified panel
      Parameters:
      panel -
      graphics -
    • setShowMajorXGrid

      public void setShowMajorXGrid(boolean showGrid)
      Shows a grid line for every x axis major tickmark. Also disables minor grid if showGrid is false.
      Specified by:
      setShowMajorXGrid in interface DrawableAxes
      Parameters:
      showGrid - The new drawMajorXGrid value
    • setShowMinorXGrid

      public void setShowMinorXGrid(boolean showGrid)
      Shows a grid line for every x axis minor tickmark.
      Specified by:
      setShowMinorXGrid in interface DrawableAxes
      Parameters:
      showGrid - The new drawMinorXGrid value
    • setShowMajorYGrid

      public void setShowMajorYGrid(boolean showGrid)
      Shows a grid line for every y axis major tickmark. Also disables minor grid if showGrid is false.
      Specified by:
      setShowMajorYGrid in interface DrawableAxes
      Parameters:
      showGrid - The new drawMajorYGrid value
    • setShowMinorYGrid

      public void setShowMinorYGrid(boolean showGrid)
      Shows a grid line for every y axis minor tickmark.
      Specified by:
      setShowMinorYGrid in interface DrawableAxes
      Parameters:
      showGrid - The new drawMinorYGrid value
    • setX

      public void setX(double x)
      Description copied from interface: CartesianAxes
      Sets the drawing location.
      Specified by:
      setX in interface CartesianAxes
    • setY

      public void setY(double y)
      Description copied from interface: CartesianAxes
      Sets the drawing location.
      Specified by:
      setY in interface CartesianAxes
    • getX

      public double getX()
      Description copied from interface: CartesianAxes
      Gets the drawing location.
      Specified by:
      getX in interface CartesianAxes
      Returns:
      the x location
    • getY

      public double getY()
      Description copied from interface: CartesianAxes
      Gets the drawing location.
      Specified by:
      getY in interface CartesianAxes
      Returns:
      the y location
    • getInterior

      public Dimension getInterior(DrawingPanel panel)
      Implements the Dimensioned interface.
      Specified by:
      getInterior in interface Dimensioned
      Parameters:
      panel - DrawingPanel
      Returns:
      Dimension
    • setTickLength

      public void setTickLength(int len)