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
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.14159Tick 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 Summary
FieldsModifier and TypeFieldDescriptionprotected DrawableTextLineThe title and label strings.protected DrawableTextLineFields inherited from class org.opensourcephysics.display.axes.AbstractAxes
defaultBottomGutter, defaultLeftGutter, defaultRightGutter, defaultTopGutter, drawingPanel, gridcolor, interiorColor, labelFont, labelFormat, superscriptFont, titleFont, titleLine, visible -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSpecify a tick mark for the X axis.voidSpecify a tick mark for the Y axis.voiddraw(DrawingPanel panel, Graphics g) Draws the plot by implementing the drawable interface.protected voiddrawPlot(DrawingPanel panel, Graphics graphics) Draws the axes onto the specified panelgetInterior(DrawingPanel panel) Implements the Dimensioned interface.intgetTitle()Get the title of the graph, or an empty string if there is none.doublegetX()Gets the drawing location.Get the label for the X (horizontal) axis, or null if none has been set.doublegetY()Gets the drawing location.Get the label for the Y (vertical) axis, or null if none has been set.booleanisXLog()Return whether the X axis is drawn with a logarithmic scale.booleanisYLog()Return whether the Y axis is drawn with a logarithmic scale.voidresizeFonts(double factor, DrawingPanel panel) Resizes fonts by the specified factor.voidsetLabelFont(String name) Set the label font, which is used for axis labels and legend labels.voidsetShowMajorXGrid(boolean showGrid) Shows a grid line for every x axis major tickmark.voidsetShowMajorYGrid(boolean showGrid) Shows a grid line for every y axis major tickmark.voidsetShowMinorXGrid(boolean showGrid) Shows a grid line for every x axis minor tickmark.voidsetShowMinorYGrid(boolean showGrid) Shows a grid line for every y axis minor tickmark.voidsetTickLength(int len) voidSet the title of the graph.voidsetTitleFont(String name) Set the title font.voidsetX(double x) Sets the drawing location.voidSet the label for the X (horizontal) axis.voidsetXLog(boolean xlog) Specify whether the X axis is drawn with a logarithmic scale.voidsetY(double y) Sets the drawing location.voidSet the label for the Y (vertical) axis.voidsetYLog(boolean ylog) Specify whether the Y axis is drawn with a logarithmic scale.Methods inherited from class org.opensourcephysics.display.axes.AbstractAxes
getInteriorBackground, isVisible, resetPanelGutters, setDefaultGutters, setInteriorBackground, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opensourcephysics.display.Drawable
isInteractiveMethods inherited from interface org.opensourcephysics.display.axes.DrawableAxes
getInteriorBackground, setInteriorBackground, setVisible
-
Field Details
-
xLine
The title and label strings. -
yLine
-
htFormats
-
-
Constructor Details
-
CartesianType1
Constructor for the AxesType1 object- Parameters:
panel- the panel on which this axes is drawn
-
-
Method Details
-
draw
Draws the plot by implementing the drawable interface. Most of the drawing is done in the DrawPlot method after the gutters are set. -
addXTick
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
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
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
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:
setTitlein interfaceDrawableAxes- Overrides:
setTitlein classAbstractAxes- Parameters:
title- the titlefont_name- an optional font name
-
setTitleFont
Set the title font. The font names understood are those understood by java.awt.Font.decode().- Parameters:
name- A font name.
-
setXLabel
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:
setXLabelin interfaceDrawableAxes- Parameters:
label- the labelfont_name- an optional font name
-
setXLog
public void setXLog(boolean xlog) Specify whether the X axis is drawn with a logarithmic scale.- Specified by:
setXLogin interfaceCartesianAxes- Parameters:
xlog- If true, logarithmic axis is used.
-
setYLabel
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:
setYLabelin interfaceDrawableAxes- Parameters:
label- the labelfont_name- an optional font name
-
setYLog
public void setYLog(boolean ylog) Specify whether the Y axis is drawn with a logarithmic scale.- Specified by:
setYLogin interfaceCartesianAxes- Parameters:
ylog- If true, logarithmic axis is used.
-
getTitle
Get the title of the graph, or an empty string if there is none.- Specified by:
getTitlein interfaceDrawableAxes- Overrides:
getTitlein classAbstractAxes- Returns:
- The title.
-
getXLabel
Get the label for the X (horizontal) axis, or null if none has been set.- Specified by:
getXLabelin interfaceDrawableAxes- Returns:
- The X label.
-
isXLog
public boolean isXLog()Return whether the X axis is drawn with a logarithmic scale.- Specified by:
isXLogin interfaceCartesianAxes- Returns:
- True if the X axis is logarithmic.
-
getYLabel
Get the label for the Y (vertical) axis, or null if none has been set.- Specified by:
getYLabelin interfaceDrawableAxes- Returns:
- The Y label.
-
isYLog
public boolean isYLog()Return whether the Y axis is drawn with a logarithmic scale.- Specified by:
isYLogin interfaceCartesianAxes- Returns:
- True if the Y axis is logarithmic.
-
resizeFonts
Resizes fonts by the specified factor.- Specified by:
resizeFontsin interfaceDrawableAxes- Overrides:
resizeFontsin classAbstractAxes- Parameters:
factor- the factorpanel- the drawing panel on which these axes are drawn
-
getTickLength
public int getTickLength() -
drawPlot
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:
setShowMajorXGridin interfaceDrawableAxes- Parameters:
showGrid- The new drawMajorXGrid value
-
setShowMinorXGrid
public void setShowMinorXGrid(boolean showGrid) Shows a grid line for every x axis minor tickmark.- Specified by:
setShowMinorXGridin interfaceDrawableAxes- 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:
setShowMajorYGridin interfaceDrawableAxes- Parameters:
showGrid- The new drawMajorYGrid value
-
setShowMinorYGrid
public void setShowMinorYGrid(boolean showGrid) Shows a grid line for every y axis minor tickmark.- Specified by:
setShowMinorYGridin interfaceDrawableAxes- Parameters:
showGrid- The new drawMinorYGrid value
-
setX
public void setX(double x) Description copied from interface:CartesianAxesSets the drawing location.- Specified by:
setXin interfaceCartesianAxes
-
setY
public void setY(double y) Description copied from interface:CartesianAxesSets the drawing location.- Specified by:
setYin interfaceCartesianAxes
-
getX
public double getX()Description copied from interface:CartesianAxesGets the drawing location.- Specified by:
getXin interfaceCartesianAxes- Returns:
- the x location
-
getY
public double getY()Description copied from interface:CartesianAxesGets the drawing location.- Specified by:
getYin interfaceCartesianAxes- Returns:
- the y location
-
getInterior
Implements the Dimensioned interface.- Specified by:
getInteriorin interfaceDimensioned- Parameters:
panel- DrawingPanel- Returns:
- Dimension
-
setTickLength
public void setTickLength(int len)
-