Class Figure

java.lang.Object
smile.plot.swing.Figure

public class Figure extends Object
A figure serves as the canvas on which plots and other elements are drawn. It can be conceptualized as the top-level container holding all plot elements, including axes, titles, legends, and annotations.
  • Constructor Details

    • Figure

      public Figure(double[] lowerBound, double[] upperBound)
      Constructor.
      Parameters:
      lowerBound - the lower bound of base.
      upperBound - the upper bound of base.
    • Figure

      public Figure(double[] lowerBound, double[] upperBound, boolean extendBound)
      Constructor.
      Parameters:
      lowerBound - the lower bound of base.
      upperBound - the upper bound of base.
      extendBound - true if extending the bounds for padding.
  • 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.
      Parameters:
      listener - a property change listener.
    • 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.
      Parameters:
      listener - a property change listener.
    • getPropertyChangeListeners

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

      public Projection projection(int width, int height)
      Returns a projection of the figure.
      Parameters:
      width - the canvas width.
      height - the canvas height.
      Returns:
      a projection of the figure.
    • toBufferedImage

      public BufferedImage toBufferedImage(int width, int height)
      Exports the figure to an image.
      Parameters:
      width - the width of image.
      height - the height of image.
      Returns:
      the image of figure.
    • isLegendVisible

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

      public Figure setLegendVisible(boolean visible)
      Sets if legends are visible.
      Parameters:
      visible - the flag if legends are visible.
      Returns:
      this object.
    • 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 Figure 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.
      Returns:
      this object.
    • getTitle

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

      public Figure setTitle(String title)
      Sets the main title of figure.
      Parameters:
      title - the main title of figure.
      Returns:
      this object.
    • getTitleFont

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

      public Figure setTitleFont(Font font)
      Sets the font for title.
      Parameters:
      font - the font for title.
      Returns:
      this object.
    • getTitleColor

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

      public Figure setTitleColor(Color color)
      Sets the color for title.
      Parameters:
      color - the color for title.
      Returns:
      this object.
    • getAxis

      public Axis getAxis(int i)
      Returns the i-th axis.
      Parameters:
      i - the index of axis.
      Returns:
      the i-th axis.
    • getAxisLabels

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

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

      public Figure setAxisLabels(String... labels)
      Sets the labels/legends of axes.
      Parameters:
      labels - the labels/legends of axes.
      Returns:
      this object.
    • setAxisLabel

      public Figure setAxisLabel(int i, String label)
      Sets the label/legend of an axis.
      Parameters:
      i - the index of axis.
      label - the label/legend of axes.
      Returns:
      this object.
    • 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)
      Adds a graphical shape to the canvas.
      Parameters:
      p - the shape.
    • remove

      public void remove(Shape p)
      Removes a graphical shape from the canvas.
      Parameters:
      p - the shape.
    • add

      public void add(Plot p)
      Adds a graphical shape to the canvas.
      Parameters:
      p - the plot.
    • remove

      public void remove(Plot p)
      Removes a graphical shape from the canvas.
      Parameters:
      p - the plot.
    • clear

      public void clear()
      Removes all graphic plots from the canvas.
    • getLowerBounds

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

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

      public void extendLowerBound(double[] bound)
      Extends the lower bounds.
      Parameters:
      bound - the new lower bounds.
    • extendUpperBound

      public void extendUpperBound(double[] bound)
      Extends the upper bounds.
      Parameters:
      bound - the new upper bounds.
    • extendBound

      public void extendBound(double[] lowerBound, double[] upperBound)
      Extends the lower and upper bounds.
      Parameters:
      lowerBound - the new lower bounds.
      upperBound - the new upper bounds.
    • setBound

      public void setBound(double[] lowerBound, double[] upperBound)
      Sets the lower and upper bounds.
      Parameters:
      lowerBound - the new lower bounds.
      upperBound - the new upper bounds.
    • paint

      public void paint(Renderer renderer)
      Paints the figure.
      Parameters:
      renderer - the renderer.
    • show

      Shows the plot in a window.
      Returns:
      a new JFrame that contains the plot.
      Throws:
      InterruptedException - if we're interrupted while waiting for the event dispatching thread to finish executing.
      InvocationTargetException - if an exception is thrown while showing the frame.