Class GraphSurface

  • All Implemented Interfaces:
    PlotSurface

    public class GraphSurface
    extends java.lang.Object
    implements PlotSurface
    Plotting surface for drawing graphs on.
    Since:
    3 Mar 2006
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Constructor Description
      GraphSurface​(javax.swing.JComponent component, boolean xLog, boolean yLog, boolean xFlip, boolean yFlip)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Point dataToGraphics​(double x, double y, boolean insideOnly)
      Converts a point in data space to graphics space.
      java.awt.Shape getClip()
      Returns the clip region in which points may be plotted.
      javax.swing.JComponent getComponent()
      Returns the graphical component on which the plotting surface is displayed.
      double[] graphicsToData​(int px, int py, boolean insideOnly)
      Converts a point in graphics space to data space.
      void paintSurface​(java.awt.Graphics g)
      Paints the plotting surface.
      void setBounds​(java.awt.Rectangle bounds)
      Sets the rectangle within which data points may be plotted.
      void setDataRange​(double xlo, double ylo, double xhi, double yhi)
      Requests a range of data space values to be visible on this plotting surface.
      void setState​(PlotState state)
      Signals to the plot the characteristics of the plot which will be performed.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • GraphSurface

        public GraphSurface​(javax.swing.JComponent component,
                            boolean xLog,
                            boolean yLog,
                            boolean xFlip,
                            boolean yFlip)
        Constructor.
        Parameters:
        component - the component on which this surface will draw
        xLog - true iff X axis is logarithmically scaled
        yLog - true iff Y axis is logarithmically scaled
        xFlip - true iff X axis is inverted
        yFlip - true iff Y axis is inverted
    • Method Detail

      • getClip

        public java.awt.Shape getClip()
        Description copied from interface: PlotSurface
        Returns the clip region in which points may be plotted. The returned shape should be the sort which can be passed to Graphics.setClip(java.awt.Shape) - i.e. probably a Rectangle.
        Specified by:
        getClip in interface PlotSurface
        Returns:
        clip region representing data zone
      • getComponent

        public javax.swing.JComponent getComponent()
        Description copied from interface: PlotSurface
        Returns the graphical component on which the plotting surface is displayed. This will contain things like axes, grids, labels etc. This component will normally override JComponent.paintComponent(java.awt.Graphics) to give a plotting background in accordance with the most recently set PlotState.
        Specified by:
        getComponent in interface PlotSurface
        Returns:
        plot surface display component
      • setDataRange

        public void setDataRange​(double xlo,
                                 double ylo,
                                 double xhi,
                                 double yhi)
        Description copied from interface: PlotSurface
        Requests a range of data space values to be visible on this plotting surface.
        Specified by:
        setDataRange in interface PlotSurface
        Parameters:
        xlo - (approximate) lower bound of X coordinate
        ylo - (approximate) lower bound of Y coordinate
        xhi - (approximate) upper bound of X coordinate
        yhi - (approximate) upper bound of Y coordinate
      • setBounds

        public void setBounds​(java.awt.Rectangle bounds)
        Sets the rectangle within which data points may be plotted. Additional annotations (such as axis labels) may be drawn outside this region.
        Parameters:
        bounds - the region of the component which represents the target for data points; annotations may be drawn outside this region
      • dataToGraphics

        public java.awt.Point dataToGraphics​(double x,
                                             double y,
                                             boolean insideOnly)
        Description copied from interface: PlotSurface
        Converts a point in data space to graphics space. If the insideOnly flag is true, then null will be returned in place of any result which would give a point lying outside the visible plotting area.

        The coordinates of the returned point must have absolute values no greater than PlotSurface.MAX_COORD.

        Specified by:
        dataToGraphics in interface PlotSurface
        Parameters:
        x - data space X coordinate
        y - data space Y coordinate
        insideOnly - true to restrict non-null results to those within the plotting surface
        Returns:
        point in graphics space corresponding to (x,y), or null
      • graphicsToData

        public double[] graphicsToData​(int px,
                                       int py,
                                       boolean insideOnly)
        Description copied from interface: PlotSurface
        Converts a point in graphics space to data space. If the insideOnly flag is true, then null will be returned in place of any result which would give a point lying outside the visible plotting area.
        Specified by:
        graphicsToData in interface PlotSurface
        Parameters:
        px - graphics space X coordinate
        py - graphics space Y coordinate
        insideOnly - true to restrict non-null results to those within the plotting surface
        Returns:
        a 2-element array giving x and y data space coordinates, or null
      • setState

        public void setState​(PlotState state)
        Description copied from interface: PlotSurface
        Signals to the plot the characteristics of the plot which will be performed. Setting this has no immediate effect, but when the component supplied by PlotSurface.getComponent() next paints itself it should do so following the specifications made here.
        Specified by:
        setState in interface PlotSurface
        Parameters:
        state - plot characteristics
      • paintSurface

        public void paintSurface​(java.awt.Graphics g)
        Description copied from interface: PlotSurface
        Paints the plotting surface. This should do roughly the same as getComponent.paintComponent, except that it's public.

        Requiring this here isn't very tidy, but following quite a bit of experimentation I can't work out any other way to do scatter plot image caching while still drawing to a potentially hardware-accelerated graphics context (see ScatterPlot implementation).

        Specified by:
        paintSurface in interface PlotSurface
        Parameters:
        g - graphics context
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object