Interface PlotSurface
- All Known Implementing Classes:
GraphSurface
,PtPlotSurface
Two coordinate spaces are important when dealing with a PlotSurface:
graphics space is referenced in integer coordinates and refers to the
coordinates you deal with when you have a Graphics
object,
and data space is referenced in double coordinates and is
the space in which the data points live.
PlotSurface defines how to do the necessary conversions between them.
- Since:
- 16 Jun 2004
- Author:
- Mark Taylor (Starlink)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Gives the maximum absolute value which should be generated by any of the methods of this class as graphics coordinates. -
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
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.
-
Field Details
-
MAX_COORD
static final int MAX_COORDGives the maximum absolute value which should be generated by any of the methods of this class as graphics coordinates. This number is large, but smaller thanInteger.MAX_VALUE
. Any graphics coordinate comparable withInteger.MAX_VALUE
will be far off the screen, so its exact value is unlikely to matter. The main purpose of mandating this limit is so that generated coordinates can be manipulated without much fear of arithmetic overflow.If the limit were set fairly low (a few thousand?) this could also have the effect of preventing painting commands from attempting to draw lines a kilometre long, which can have an adverse effect on the graphics system. It could also lead to some graphical distortions.
- See Also:
-
-
Method Details
-
dataToGraphics
Converts a point in data space to graphics space. If theinsideOnly
flag is true, thennull
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
MAX_COORD
.- 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
double[] graphicsToData(int px, int py, boolean insideOnly) Converts a point in graphics space to data space. If theinsideOnly
flag is true, thennull
will be returned in place of any result which would give a point lying outside the visible plotting area.- 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
-
getClip
Shape getClip()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 aRectangle
.- Returns:
- clip region representing data zone
-
setState
Signals to the plot the characteristics of the plot which will be performed. Setting this has no immediate effect, but when the component supplied bygetComponent()
next paints itself it should do so following the specifications made here.- Parameters:
state
- plot characteristics
-
setDataRange
void setDataRange(double xlo, double ylo, double xhi, double yhi) Requests a range of data space values to be visible on this plotting surface.- 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
-
getComponent
JComponent getComponent()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 setPlotState
.- Returns:
- plot surface display component
-
paintSurface
Paints the plotting surface. This should do roughly the same asgetComponent.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).- Parameters:
g
- graphics context
-