Package uk.ac.starlink.ttools.plot
Class GraphSurface
- java.lang.Object
-
- uk.ac.starlink.ttools.plot.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
-
-
Field Summary
-
Fields inherited from interface uk.ac.starlink.ttools.plot.PlotSurface
MAX_COORD
-
-
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()
-
-
-
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 drawxLog
- true iff X axis is logarithmically scaledyLog
- true iff Y axis is logarithmically scaledxFlip
- true iff X axis is invertedyFlip
- 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 toGraphics.setClip(java.awt.Shape)
- i.e. probably a Rectangle.- Specified by:
getClip
in interfacePlotSurface
- 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 overrideJComponent.paintComponent(java.awt.Graphics)
to give a plotting background in accordance with the most recently set PlotState.- Specified by:
getComponent
in interfacePlotSurface
- 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 interfacePlotSurface
- Parameters:
xlo
- (approximate) lower bound of X coordinateylo
- (approximate) lower bound of Y coordinatexhi
- (approximate) upper bound of X coordinateyhi
- (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 interfacePlotSurface
- Parameters:
x
- data space X coordinatey
- data space Y coordinateinsideOnly
- 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 interfacePlotSurface
- Parameters:
px
- graphics space X coordinatepy
- graphics space Y coordinateinsideOnly
- 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 byPlotSurface.getComponent()
next paints itself it should do so following the specifications made here.- Specified by:
setState
in interfacePlotSurface
- 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 interfacePlotSurface
- Parameters:
g
- graphics context
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-