Package smile.plot.swing
Class Canvas
java.lang.Object
smile.plot.swing.Canvas
Canvas for mathematical plots.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a graphical shape to the canvas.void
Add a graphical shape to the canvas.void
Add a PropertyChangeListener to the listener list.void
clear()
Remove all graphic plots from the canvas.void
extendBound
(double[] lowerBound, double[] upperBound) Extend lower and upper bounds.void
extendLowerBound
(double[] bound) Extend lower bounds.void
extendUpperBound
(double[] bound) Extend upper bounds.getAxis
(int i) Returns the i-th axis.getAxisLabel
(int i) Returns the label/legend of an axis.String[]
Returns the labels/legends of axes.double[]
Returns the lower bounds.double
Returns the size of margin, which is not used as plot area.Returns an array of all the listeners that were added to the PropertyChangeSupport object with addPropertyChangeListener().Returns the list of shapes in the canvas.getTitle()
Returns the main title of canvas.Returns the color for title.Returns the font for title.double[]
Returns the upper bounds.boolean
Returns true if legends are visible.void
paint
(Graphics2D g2d, int width, int height) Paints the canvas.panel()
Returns a Swing JPanel of the canvas.void
Remove a graphical shape from the canvas.void
Remove a graphical shape from the canvas.void
Remove a PropertyChangeListener from the listener list.setAxisLabel
(int i, String label) Sets the label/legend of an axis.setAxisLabels
(String... labels) Sets the labels/legends of axes.void
setBound
(double[] lowerBound, double[] upperBound) Extend lower and upper bounds.setLegendVisible
(boolean visible) Sets if legends are visible.setMargin
(double margin) Sets the size of margin in [0.0, 0.3] on each side.Set the main title of canvas.setTitleColor
(Color color) Set the color for title.setTitleFont
(Font font) Set the font for title.toBufferedImage
(int width, int height) Exports the plot to an image.window()
Shows the plot in a window.
-
Constructor Details
-
Canvas
public Canvas(double[] lowerBound, double[] upperBound) Constructor -
Canvas
public Canvas(double[] lowerBound, double[] upperBound, boolean extendBound) Constructor
-
-
Method Details
-
addPropertyChangeListener
Add a PropertyChangeListener to the listener list. The listener is registered for all properties. The same listener object may be added more than once, and will be called as many times as it is added. If listener is null, no exception is thrown and no action is taken. -
removePropertyChangeListener
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties. If listener was added more than once to the same event source, it will be notified one less time after being removed. If listener is null, or was never added, no exception is thrown and no action is taken. -
getPropertyChangeListeners
Returns an array of all the listeners that were added to the PropertyChangeSupport object with addPropertyChangeListener(). -
toBufferedImage
Exports the plot to an image.- Parameters:
width
- the width of image.height
- the height of image.
-
isLegendVisible
public boolean isLegendVisible()Returns true if legends are visible. -
setLegendVisible
Sets if legends are visible. -
getMargin
public double getMargin()Returns the size of margin, which is not used as plot area. Currently, all four sides have the same margin size.- Returns:
- the size of margin.
-
setMargin
Sets the size of margin in [0.0, 0.3] on each side. Currently, all four sides have the same margin size.- Parameters:
margin
- the size of margin.
-
getTitle
Returns the main title of canvas. -
setTitle
Set the main title of canvas. -
getTitleFont
Returns the font for title. -
setTitleFont
Set the font for title. -
getTitleColor
Returns the color for title. -
setTitleColor
Set the color for title. -
getAxis
Returns the i-th axis. -
getAxisLabels
Returns the labels/legends of axes. -
getAxisLabel
Returns the label/legend of an axis. -
setAxisLabels
Sets the labels/legends of axes. -
setAxisLabel
Sets the label/legend of an axis. -
getShapes
Returns the list of shapes in the canvas.- Returns:
- the list of shapes in the canvas.
-
add
Add a graphical shape to the canvas. -
remove
Remove a graphical shape from the canvas. -
add
Add a graphical shape to the canvas. -
remove
Remove a graphical shape from the canvas. -
clear
public void clear()Remove all graphic plots from the canvas. -
getLowerBounds
public double[] getLowerBounds()Returns the lower bounds. -
getUpperBounds
public double[] getUpperBounds()Returns the upper bounds. -
extendLowerBound
public void extendLowerBound(double[] bound) Extend lower bounds. -
extendUpperBound
public void extendUpperBound(double[] bound) Extend upper bounds. -
extendBound
public void extendBound(double[] lowerBound, double[] upperBound) Extend lower and upper bounds. -
setBound
public void setBound(double[] lowerBound, double[] upperBound) Extend lower and upper bounds. -
paint
Paints the canvas. -
panel
Returns a Swing JPanel of the canvas. -
window
Shows the plot in a window.- Returns:
- a new JFrame that contains the plot.
- Throws:
InterruptedException
InvocationTargetException
-