Class Canvas

java.lang.Object
smile.plot.swing.Canvas

public class Canvas extends Object
Canvas for mathematical plots.
  • Constructor Details

    • Canvas

      public Canvas(double[] lowerBound, double[] upperBound)
      Constructor
    • Canvas

      public Canvas(double[] lowerBound, double[] upperBound, boolean extendBound)
      Constructor
  • Method Details

    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      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

      public void removePropertyChangeListener(PropertyChangeListener listener)
      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

      public PropertyChangeListener[] getPropertyChangeListeners()
      Returns an array of all the listeners that were added to the PropertyChangeSupport object with addPropertyChangeListener().
    • toBufferedImage

      public BufferedImage toBufferedImage(int width, int height)
      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

      public Canvas setLegendVisible(boolean visible)
      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

      public Canvas setMargin(double margin)
      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

      public String getTitle()
      Returns the main title of canvas.
    • setTitle

      public Canvas setTitle(String title)
      Set the main title of canvas.
    • getTitleFont

      public Font getTitleFont()
      Returns the font for title.
    • setTitleFont

      public Canvas setTitleFont(Font font)
      Set the font for title.
    • getTitleColor

      public Color getTitleColor()
      Returns the color for title.
    • setTitleColor

      public Canvas setTitleColor(Color color)
      Set the color for title.
    • getAxis

      public Axis getAxis(int i)
      Returns the i-th axis.
    • getAxisLabels

      public String[] getAxisLabels()
      Returns the labels/legends of axes.
    • getAxisLabel

      public String getAxisLabel(int i)
      Returns the label/legend of an axis.
    • setAxisLabels

      public Canvas setAxisLabels(String... labels)
      Sets the labels/legends of axes.
    • setAxisLabel

      public Canvas setAxisLabel(int i, String label)
      Sets the label/legend of an axis.
    • getShapes

      public List<Shape> getShapes()
      Returns the list of shapes in the canvas.
      Returns:
      the list of shapes in the canvas.
    • add

      public void add(Shape p)
      Add a graphical shape to the canvas.
    • remove

      public void remove(Shape p)
      Remove a graphical shape from the canvas.
    • add

      public void add(Plot p)
      Add a graphical shape to the canvas.
    • remove

      public void remove(Plot p)
      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

      public void paint(Graphics2D g2d, int width, int height)
      Paints the canvas.
    • panel

      public PlotPanel 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