public interface PlotSurface
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.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_COORD
Gives the maximum absolute value which should be generated by any
of the methods of this class as graphics coordinates.
|
Modifier and Type | Method and Description |
---|---|
Point |
dataToGraphics(double x,
double y,
boolean insideOnly)
Converts a point in data space to graphics space.
|
Shape |
getClip()
Returns the clip region in which points may be plotted.
|
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(Graphics g)
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 |
setState(PlotState state)
Signals to the plot the characteristics of the plot which will
be performed.
|
static final int MAX_COORD
Integer.MAX_VALUE
.
Any graphics coordinate comparable with Integer.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.
Point dataToGraphics(double x, double y, boolean insideOnly)
The coordinates of the returned point must have absolute values
no greater than MAX_COORD
.
x
- data space X coordinatey
- data space Y coordinateinsideOnly
- true to restrict non-null results to those
within the plotting surfacedouble[] graphicsToData(int px, int py, boolean insideOnly)
px
- graphics space X coordinatepy
- graphics space Y coordinateinsideOnly
- true to restrict non-null results to those
within the plotting surfaceShape getClip()
Graphics.setClip(java.awt.Shape)
- i.e. probably
a Rectangle.void setState(PlotState state)
getComponent()
next paints itself it should do so following the specifications
made here.state
- plot characteristicsvoid setDataRange(double xlo, double ylo, double xhi, double yhi)
xlo
- (approximate) lower bound of X coordinateylo
- (approximate) lower bound of Y coordinatexhi
- (approximate) upper bound of X coordinateyhi
- (approximate) upper bound of Y coordinateJComponent getComponent()
JComponent.paintComponent(java.awt.Graphics)
to give a plotting background in accordance with the most recently
set PlotState.void paintSurface(Graphics g)
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).
g
- graphics contextCopyright © 2023 Central Laboratory of the Research Councils. All Rights Reserved.