Package uk.ac.starlink.ttools.plot
Class GraphSurface
java.lang.Object
uk.ac.starlink.ttools.plot.GraphSurface
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionGraphSurface
(JComponent component, boolean xLog, boolean yLog, boolean xFlip, boolean yFlip) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiondataToGraphics
(double x, double y, boolean insideOnly) Converts a point in data space to graphics space.getClip()
Returns the clip region in which points may be plotted.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
Paints the plotting surface.void
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
Signals to the plot the characteristics of the plot which will be performed.toString()
-
Constructor Details
-
GraphSurface
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 Details
-
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
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
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
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
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
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
-