Class Canvas

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

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

    • Canvas Link icon

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

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

    • addPropertyChangeListener Link icon

      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 Link icon

      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 Link icon

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

      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 Link icon

      public boolean isLegendVisible()
      Returns true if legends are visible.
    • setLegendVisible Link icon

      public Canvas setLegendVisible(boolean visible)
      Sets if legends are visible.
    • getMargin Link icon

      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 Link icon

      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 Link icon

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      public void remove(Plot p)
      Remove a graphical shape from the canvas.
    • clear Link icon

      public void clear()
      Remove all graphic plots from the canvas.
    • getLowerBounds Link icon

      public double[] getLowerBounds()
      Returns the lower bounds.
    • getUpperBounds Link icon

      public double[] getUpperBounds()
      Returns the upper bounds.
    • extendLowerBound Link icon

      public void extendLowerBound(double[] bound)
      Extend lower bounds.
    • extendUpperBound Link icon

      public void extendUpperBound(double[] bound)
      Extend upper bounds.
    • extendBound Link icon

      public void extendBound(double[] lowerBound, double[] upperBound)
      Extend lower and upper bounds.
    • setBound Link icon

      public void setBound(double[] lowerBound, double[] upperBound)
      Extend lower and upper bounds.
    • paint Link icon

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

      public PlotPanel panel()
      Returns a Swing JPanel of the canvas.
    • window Link icon

      Shows the plot in a window.
      Returns:
      a new JFrame that contains the plot.
      Throws:
      InterruptedException
      InvocationTargetException