Class PlaneSurface
- All Implemented Interfaces:
PlanarSurface,Surface
- Since:
- 19 Feb 2013
- Author:
- Mark Taylor
-
Constructor Summary
ConstructorsConstructorDescriptionPlaneSurface(int gxlo, int gxhi, int gylo, int gyhi, double dxlo, double dxhi, double dylo, double dyhi, boolean xlog, boolean ylog, boolean xflip, boolean yflip, Tick[] xticks, Tick[] yticks, Orientation xorient, Orientation yorient, String xlabel, String ylabel, Tick[] x2ticks, Tick[] y2ticks, Orientation x2orient, Orientation y2orient, String x2label, String y2label, Captioner captioner, SideFlags annotateflags, Color gridcolor, Color axlabelcolor, boolean islabelposition) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic PlaneSurfacecreateSurface(Rectangle plotBounds, PlaneAspect aspect, boolean xlog, boolean ylog, boolean xflip, boolean yflip, String xlabel, String ylabel, DoubleUnaryOperator x2func, DoubleUnaryOperator y2func, String x2label, String y2label, Captioner captioner, SideFlags annotateflags, double xyfactor, double xcrowd, double ycrowd, OrientationPolicy orientpolicy, boolean minor, boolean shadow, Color gridcolor, Color axlabelcolor, boolean islabelposition) Utility method to create a PlaneSurface from available requirements.booleandataToGraphics(double[] dpos, boolean visibleOnly, Point2D.Double gp) Converts a data space position to a graphics position.booleandataToGraphicsOffset(double[] dpos0, Point2D.Double gpos0, double[] dpos1, boolean visibleOnly, Point2D.Double gpos1) Converts an offset data space position to a graphics position.booleanformatPosition(double[] dpos) Formats the given data space position as a coordinate string.static StringformatPosition(Axis axis, double dpos) Formats a coordinate value for presentation to the user.Axis[]getAxes()Returns the axis objects used by this surface.Returns a captioner suitable for drawing general purpose labels annotating the plot.intReturns 2.double[][]Returns the limits in data coordinates of the plot region.boolean[]Indicates which axes are reversed.boolean[]Indicates the scaling along the two axes.Returns the rectangle within which all of the plot data will appear.getSurround(boolean withScroll) Returns the surround that this surface would like to reserve outside the plot bounds.boolean[]Indicates which axes represent time values.double[]graphicsToData(Point2D gp, Supplier<CoordSequence> dposSupplier) Attempts to turn a graphics position into a data position.inthashCode()booleanisContinuousLine(double[] dpos0, double[] dpos1) Indicates whether a line in graphics space between two given data space positions is continuous.voidPaints the plot surface background.voidPaints the plot surface foreground.
-
Constructor Details
-
PlaneSurface
public PlaneSurface(int gxlo, int gxhi, int gylo, int gyhi, double dxlo, double dxhi, double dylo, double dyhi, boolean xlog, boolean ylog, boolean xflip, boolean yflip, Tick[] xticks, Tick[] yticks, Orientation xorient, Orientation yorient, String xlabel, String ylabel, Tick[] x2ticks, Tick[] y2ticks, Orientation x2orient, Orientation y2orient, String x2label, String y2label, Captioner captioner, SideFlags annotateflags, Color gridcolor, Color axlabelcolor, boolean islabelposition) Constructor.- Parameters:
gxlo- graphics X coordinate lower boundgxhi- graphics X coordinate upper boundgylo- graphics Y coordinate lower boundgyhi- graphics Y coordinate upper bounddxlo- data X coordinate lower bounddxhi- data X coordinate upper bounddylo- data Y coordinate lower bounddyhi- data Y coordinate upper boundxlog- whether to use logarithmic scaling on X axisylog- whether to use logarithmic scaling on Y axisxflip- whether to invert direction of X axisyflip- whether to invert direction of Y axisxticks- array of tickmark objects for X axisyticks- array of tickmark objects for Y axisxorient- tick label orientation on X axisyorient- tick label orientation on Y axisxlabel- text for labelling X axisylabel- text for labelling Y axisx2ticks- array of tickmark objects for secondary X axisy2ticks- array of tickmark objects for secondary Y axisx2orient- tick label orientation on secondary X axisy2orient- tick label orientation on secondary Y axisx2label- text for labelling secondary X axisy2label- text for labelling secondary Y axiscaptioner- text renderer for axis labels etc, or null if absentannotateflags- indicates which sides to annotategridcolor- colour of grid lines, or null if not plottedaxlabelcolor- colour of axis labelsislabelposition- whether formatted positions should include axis labels
-
-
Method Details
-
getPlotBounds
Description copied from interface:SurfaceReturns the rectangle within which all of the plot data will appear. This includes anything that might get drawn by a plot layer, but does not necessarily include axis labels etc.- Specified by:
getPlotBoundsin interfaceSurface- Returns:
- plot data area bounds
-
getSurround
Description copied from interface:SurfaceReturns the surround that this surface would like to reserve outside the plot bounds. This is space outside the rectangle returned bySurface.getPlotBounds()to be used for axis labels etc.If the
withScrollparameter is set, then an attempt will be made to return a surround that will not alter if the current plot is scrolled around a moderate amount. For a one-time plot that's not important, but for an interactive plot it prevents the actual plot position jumping around to accommodate more or less space on the axes according to exactly where ticks happen to fall on the axes.This method is supposed to return only the space that may actually be touched by the plot. The calling code may wish to apply additional padding on top of this for cosmetic reasons.
- Specified by:
getSurroundin interfaceSurface- Parameters:
withScroll- true to reserve space for nicer scrolling- Returns:
- plot data area surround
-
getDataDimCount
public int getDataDimCount()Returns 2.- Specified by:
getDataDimCountin interfaceSurface- Returns:
- number of elements in data space coordinate array
-
dataToGraphics
Description copied from interface:SurfaceConverts a data space position to a graphics position. IfvisibleOnlyis true, then if the return value is true, the exit value ofgPosis guaranteed to be within the plot bounds of this surface.If
visibleOnlyis false, there are no guarantees about the exit value ofgPos, and its coordinates could be infinite or NaN. In this case you might want to perform additional checking, for instance with the utility methodsPlotUtil.isPointFiniteorisPointReal.- Specified by:
dataToGraphicsin interfaceSurface- Parameters:
dpos- dataDimCount-element array containing data space coordinatesvisibleOnly- if true, then the conversion will only succeed when the result falls within the plot bounds of this surfacegp- point object into which the graphics position will be written on success- Returns:
- true iff the conversion succeeds
-
dataToGraphicsOffset
public boolean dataToGraphicsOffset(double[] dpos0, Point2D.Double gpos0, double[] dpos1, boolean visibleOnly, Point2D.Double gpos1) Description copied from interface:SurfaceConverts an offset data space position to a graphics position. Context is given in the form of an existing converted nearby point (both data and graphics positions).This (somewhat hacky) method is required for surfaces in which a data position may map to more than one position in graphics space, for instance sky surfaces with discontinuous longitude. The result does not need to be the same as the result of calling
Surface.dataToGraphics(double[], boolean, java.awt.geom.Point2D.Double), and is not required to be a legal graphics position, but it must make visual sense, for instance when plotting error bars. The semantics of a "nearby point" is not very well defined. There are probably situations in which calling this will not give the result that's wanted, but they will probably be rare.- Specified by:
dataToGraphicsOffsetin interfaceSurface- Parameters:
dpos0- context position in data spacegpos0- context position in graphics space (result of calling dataToGraphics on dpos0)dpos1- query position in data spacevisibleOnly- if true, the call only succeeds if the result is within the plot bounds of this surfacegpos1- point object to which the graphics position of dpos1 will be written on success- Returns:
- true for success, false for no result
-
graphicsToData
Description copied from interface:SurfaceAttempts to turn a graphics position into a data position. This is not always trivial, for instance in a 3D plot one graphics position maps to a line of data positions. ThedposItargument can optionally be supplied to cope with such instances. If a data pos cannot be determined, null is returned. IfdposItis absent, the method will run quickly. If it's present, it may or may not run slowly.- Specified by:
graphicsToDatain interfaceSurface- Parameters:
gp- graphics pointdposSupplier- iterable over dataDimCount-element arrays representing all the data space positions plotted, or null- Returns:
- dataDimCount-element array giving data space position for
gPos, or null if it cannot be determined
-
isContinuousLine
public boolean isContinuousLine(double[] dpos0, double[] dpos1) Description copied from interface:SurfaceIndicates whether a line in graphics space between two given data space positions is continuous.This is not very well-defined, but if drawing a line in graphics coordinates between the graphics coordinates corresponding to the two data coordinates is likely to do something badly wrong, this method should return false. It is intended to deal with the case where a short offset in data coordinates would lead to a line going the wrong way round the sky when it crosses the longitude=+/-PI boundary in an Aitoff projection.
- Specified by:
isContinuousLinein interfaceSurface- Parameters:
dpos0- first dataDimCount-element array containing data space coordinatesdpos1- second dataDimCount-element array containing data space coordinates- Returns:
- true if drawing a graphics line between the two positions should be OK
-
formatPosition
Description copied from interface:SurfaceFormats the given data space position as a coordinate string. If possible the returned string should have the same length and formatting over the whole visible plot surface, so that the representation doesn't jump around when the cursor is moved.- Specified by:
formatPositionin interfaceSurface- Parameters:
dpos- dataDimCount-element array giving data space position- Returns:
- human-readable string representing position
-
getCaptioner
Description copied from interface:SurfaceReturns a captioner suitable for drawing general purpose labels annotating the plot.- Specified by:
getCaptionerin interfaceSurface- Returns:
- captioner
-
paintBackground
Description copied from interface:SurfacePaints the plot surface background. Anything that appears within the plot bounds underneath the data markings must go here.- Specified by:
paintBackgroundin interfaceSurface- Parameters:
g- graphics context
-
paintForeground
Description copied from interface:SurfacePaints the plot surface foreground. Anything that appears on top of the data markings or outside the plot bounds must go here. This may include axes.- Specified by:
paintForegroundin interfaceSurface- Parameters:
g- graphics context
-
getDataLimits
public double[][] getDataLimits()Description copied from interface:PlanarSurfaceReturns the limits in data coordinates of the plot region.- Specified by:
getDataLimitsin interfacePlanarSurface- Returns:
- 2x2 array
{{xlo, xhi}, {ylo, yhi}}
-
getLogFlags
public boolean[] getLogFlags()Description copied from interface:PlanarSurfaceIndicates the scaling along the two axes.- Specified by:
getLogFlagsin interfacePlanarSurface- Returns:
- 2-element array giving horizontal, vertical scaling flags: false for linear, true for logarithmic
-
getFlipFlags
public boolean[] getFlipFlags()Description copied from interface:PlanarSurfaceIndicates which axes are reversed.- Specified by:
getFlipFlagsin interfacePlanarSurface- Returns:
- 2-element array giving horizontal, vertical flip flags; true to invert normal plot direction
-
getTimeFlags
public boolean[] getTimeFlags()Description copied from interface:PlanarSurfaceIndicates which axes represent time values.- Specified by:
getTimeFlagsin interfacePlanarSurface- Returns:
- 2-element array giving horizontal, vertical time flags; true for time axis with data units of seconds, false for normal numeric axis
-
getAxes
Description copied from interface:PlanarSurfaceReturns the axis objects used by this surface.- Specified by:
getAxesin interfacePlanarSurface- Returns:
- 2-element array giving horizontal, vertical axis instances
-
equals
-
hashCode
public int hashCode() -
createSurface
public static PlaneSurface createSurface(Rectangle plotBounds, PlaneAspect aspect, boolean xlog, boolean ylog, boolean xflip, boolean yflip, String xlabel, String ylabel, DoubleUnaryOperator x2func, DoubleUnaryOperator y2func, String x2label, String y2label, Captioner captioner, SideFlags annotateflags, double xyfactor, double xcrowd, double ycrowd, OrientationPolicy orientpolicy, boolean minor, boolean shadow, Color gridcolor, Color axlabelcolor, boolean islabelposition) Utility method to create a PlaneSurface from available requirements. It works out actual data coordinate bounds and tickmarks, and then invokes the constructor.- Parameters:
plotBounds- rectangle which the plot data should occupyaspect- surface view configurationxlog- whether to use logarithmic scaling on X axisylog- whether to use logarithmic scaling on Y axisxflip- whether to invert direction of X axisyflip- whether to invert direction of Y axisxlabel- text for labelling X axisylabel- text for labelling Y axisx2func- function mapping primary to secondary X axis data coord, null for no secondary X axisy2func- function mapping primary to secondary Y axis data coord, null for no secondary Y axisx2label- secondary X axis labely2label- secondary Y axis labelcaptioner- text renderer for axis labels etcannotateflags- which sides to annotatexyfactor- ratio (X axis unit length)/(Y axis unit length), or NaN to use whatever bounds shape and axis limits give youxcrowd- crowding factor for tick marks on X axis; 1 is normalycrowd- crowding factor for tick marks on Y axis; 1 is normalorientpolicy- tick label orientation policyminor- whether to paint minor tick marks on axesshadow- whether to paint shadow ticks on opposite axes if no secondary axisgridcolor- colour of grid lines, or null for noneaxlabelcolor- colour of axis labelsislabelposition- whether to include axis labels in formatted position text- Returns:
- new plot surface
-
formatPosition
Formats a coordinate value for presentation to the user.- Parameters:
axis- axis on which value appearsdpos- data coordinate value- Returns:
- formatted data coordinate string
-