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 DrawableTextLine
The title and label strings.protected DrawableTextLine
Fields 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 TypeMethodDescriptionvoid
Specify a tick mark for the X axis.void
Specify a tick mark for the Y axis.void
draw
(DrawingPanel panel, Graphics g) Draws the plot by implementing the drawable interface.protected void
drawPlot
(DrawingPanel panel, Graphics graphics) Draws the axes onto the specified panelgetInterior
(DrawingPanel panel) Implements the Dimensioned interface.int
getTitle()
Get the title of the graph, or an empty string if there is none.double
getX()
Gets the drawing location.Get the label for the X (horizontal) axis, or null if none has been set.double
getY()
Gets the drawing location.Get the label for the Y (vertical) axis, or null if none has been set.boolean
isXLog()
Return whether the X axis is drawn with a logarithmic scale.boolean
isYLog()
Return whether the Y axis is drawn with a logarithmic scale.void
resizeFonts
(double factor, DrawingPanel panel) Resizes fonts by the specified factor.void
setLabelFont
(String name) Set the label font, which is used for axis labels and legend labels.void
setShowMajorXGrid
(boolean showGrid) Shows a grid line for every x axis major tickmark.void
setShowMajorYGrid
(boolean showGrid) Shows a grid line for every y axis major tickmark.void
setShowMinorXGrid
(boolean showGrid) Shows a grid line for every x axis minor tickmark.void
setShowMinorYGrid
(boolean showGrid) Shows a grid line for every y axis minor tickmark.void
setTickLength
(int len) void
Set the title of the graph.void
setTitleFont
(String name) Set the title font.void
setX
(double x) Sets the drawing location.void
Set the label for the X (horizontal) axis.void
setXLog
(boolean xlog) Specify whether the X axis is drawn with a logarithmic scale.void
setY
(double y) Sets the drawing location.void
Set the label for the Y (vertical) axis.void
setYLog
(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, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opensourcephysics.display.Drawable
isInteractive
Methods 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:
setTitle
in interfaceDrawableAxes
- Overrides:
setTitle
in 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:
setXLabel
in 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:
setXLog
in 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:
setYLabel
in 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:
setYLog
in 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:
getTitle
in interfaceDrawableAxes
- Overrides:
getTitle
in classAbstractAxes
- Returns:
- The title.
-
getXLabel
Get the label for the X (horizontal) axis, or null if none has been set.- Specified by:
getXLabel
in interfaceDrawableAxes
- Returns:
- The X label.
-
isXLog
public boolean isXLog()Return whether the X axis is drawn with a logarithmic scale.- Specified by:
isXLog
in 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:
getYLabel
in interfaceDrawableAxes
- Returns:
- The Y label.
-
isYLog
public boolean isYLog()Return whether the Y axis is drawn with a logarithmic scale.- Specified by:
isYLog
in interfaceCartesianAxes
- Returns:
- True if the Y axis is logarithmic.
-
resizeFonts
Resizes fonts by the specified factor.- Specified by:
resizeFonts
in interfaceDrawableAxes
- Overrides:
resizeFonts
in 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:
setShowMajorXGrid
in 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:
setShowMinorXGrid
in 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:
setShowMajorYGrid
in 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:
setShowMinorYGrid
in interfaceDrawableAxes
- 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 interfaceCartesianAxes
-
setY
public void setY(double y) Description copied from interface:CartesianAxes
Sets the drawing location.- Specified by:
setY
in interfaceCartesianAxes
-
getX
public double getX()Description copied from interface:CartesianAxes
Gets the drawing location.- Specified by:
getX
in interfaceCartesianAxes
- Returns:
- the x location
-
getY
public double getY()Description copied from interface:CartesianAxes
Gets the drawing location.- Specified by:
getY
in interfaceCartesianAxes
- Returns:
- the y location
-
getInterior
Implements the Dimensioned interface.- Specified by:
getInterior
in interfaceDimensioned
- Parameters:
panel
- DrawingPanel- Returns:
- Dimension
-
setTickLength
public void setTickLength(int len)
-