public class PlotUtil extends Object
Modifier and Type | Field and Description |
---|---|
static SplitRunner<CoordSequence> |
COORD_RUNNER
Default SplitRunner for CoordSequences.
|
static int |
DEFAULT_MAX_PIXELS
Maximum size for autoscaled variable-size markers.
|
static Span |
EMPTY_SPAN
Span instance not initialised with any data.
|
static TupleSequence |
EMPTY_TUPLE_SEQUENCE
TupleSequence instance that contains no tuples.
|
static PdfGraphicExporter |
LATEX_PDF_EXPORTER
PDF GraphicExporter suitable for use with JLaTeXMath.
|
static short |
MAX_MARKSIZE
Absolute maximum number of pixels per marker.
|
static int |
MIN_RAMP_UNIT
Minimum number of input differences that fill up a colour ramp.
|
static double |
NEAR_PIXELS
Maximum distance from a click to a clicked-on position.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
approxEquals(double v0,
double v1)
Indicates whether two floating point numbers are approximately equal
to each other.
|
static <T> T[] |
arrayConcat(T[] a1,
T[] a2)
Concatenates two arrays to form a single one.
|
static String |
concatLines(String[] lines)
Concatentates lines, adding a newline character at the end of each.
|
static ConfigMap |
configLimits(ConfigKey<Double> minKey,
ConfigKey<Double> maxKey,
double min,
double max,
int npix)
Utility method to set a minimum/maximum config key pair
to a given pair of minimum/maximum values.
|
static <P,A> A[] |
createAspectArray(SurfaceFactory<P,A> surfFact,
int length)
Returns an empty array suitable (it has the right parameterised type)
for containing elements that are aspects for a given surface factory.
|
static Graphics |
createLineGraphics(Graphics g,
Color color)
Provides a graphics context based on an existing one that is suitable
for drawing lines that may have a sub-unity alpha component.
|
static Icon |
createPlotIcon(PlotPlacement placer,
PlotLayer[] layers,
Map<AuxScale,Span> auxSpans,
DataStore dataStore,
PaperType paperType,
boolean cached,
Collection<Object> storedPlans)
Creates an icon which will paint a surface and the layers on it.
|
static <P> P[] |
createProfileArray(SurfaceFactory<P,?> surfFact,
int length)
Returns an empty array suitable (it has the right parameterised type)
for containing elements that are profiles for a given surface factory.
|
static Span |
createSpan(double lo,
double hi)
Returns a basic span instance with a given lower and upper bound.
|
static <P,A> ZoneContent<P,A>[] |
createZoneContentArray(SurfaceFactory<P,A> surfFact,
int length)
Returns an empty array suitable (it has the right parameterised type)
for containing elements that are ZoneContents for a given
surface factory.
|
static boolean |
doubleEquals(double d1,
double d2)
Indicates whether two double values are equivalent.
|
static boolean |
equals(Object o1,
Object o2)
Compares two possibly null objects for equality.
|
static void |
extendCoordinateRanges(PlotLayer[] layers,
Range[] ranges,
boolean[] logFlags,
boolean doPad,
DataStore dataStore)
Extends existing range objects using range information
for a set of layers which have Cartesian (or similar) coordinates.
|
static String[] |
formatAxisRangeLimits(double lo,
double hi,
boolean isLog,
int npix)
Formats a pair of values representing data bounds of a range
along a graphics axis.
|
static String |
formatNumber(double value,
double epsilon)
Formats a number so that it presents a number of significant figures
corresponding to a supplied small difference.
|
static String |
formatNumber(double value,
String baseFmt,
int nFracDigits)
Numeric formatting utility function.
|
static String |
formatNumberSf(double value,
int nsf)
Numeric formatting utility function for writing a given number
of significant figures.
|
static int |
getButtonChangedIndex(MouseEvent evt)
Determines which mouse button was changed at a given mouse event.
|
static int |
getButtonDownIndex(MouseEvent evt)
Determines which single button is depressed at a given mouse event.
|
static IndicatedRow |
getClosestRow(Surface surface,
DataGeom geom,
int iPosCoord,
java.util.function.Supplier<TupleSequence> tupleSupplier,
TupleRunner runner,
Point2D point)
Scans a tuple sequence to identify the data point which is
plotted closest to a given graphics position.
|
static boolean |
getDefaultTextAntialiasing()
Indicates whether antialiasing of text is turned on or off by
default.
|
static Rectangle |
getGangBounds(Gang gang)
Determines the union of the data bounds of zones in a gang.
|
static String |
getIndexSuffix(int ipos)
Returns a suffix to append to one of a set of similar coordinate
names for disambiguation.
|
static String |
getScaleAxisLabel(PlotLayer[] layers,
AuxScale scale)
Attempts to return a suitable label for an aux axis that may
be referenced in a given list of plot layers.
|
static ValueInfo |
getScaleInfo(PlotLayer[] layers,
AuxScale scale)
Attempts to return input-level metadata about an aux value that may
be referenced in a given list of plot layers.
|
static Tick[] |
getShadowTicks(Tick[] ticks)
Returns an array of tickmarks that resembles the supplied ones,
but with no labels.
|
static int |
hashCode(Object obj)
Returns a hash code for a possibly null object.
|
static int |
ifloor(double x)
Determines the integer not larger than a given non-NaN
floating point value.
|
static boolean |
isFinite(double value)
Indicates whether a value is a definite number.
|
static boolean |
isPointFinite(Point2D.Double gp)
Determines whether both coordinates of a graphics position are
definite numbers.
|
static boolean |
isPointReal(Point2D.Double gp)
Determines whether both coordinates of a graphics position are
not NaNs.
|
static void |
logTimeElapsed(Logger logger,
String phase,
long elapsed)
Writes a message through the logging system
about the supplied elapsed time a named step has taken.
|
static void |
logTimeFromStart(Logger logger,
String phase,
long start)
Writes a message through the logging system
about the elapsed time a named step has taken given a start time.
|
static double[] |
orderPair(double p1,
double p2)
Returns a 2-element array consisting of the two input values
in ascending order.
|
static void |
padRange(Range range,
boolean logFlag)
Pads a data range to provide a bit of extra space at each end
using a standard padding fraction.
|
static void |
quantisePoint(Point2D.Double dpos,
Point gpos)
Maps a floating point graphics position to an integer graphics
position, that is a 2-dimensional grid cell index.
|
static double |
roundNumber(double x,
double epsilon)
Rounds a number to a decimal round value.
|
static double[] |
scaleRange(double min,
double max,
Subrange subrange,
boolean isLog)
Returns a range determined by a fixed range and a subrange within it.
|
static double |
scaleValue(double min,
double max,
double frac)
Does linear scaling between two values.
|
static double |
scaleValue(double min,
double max,
double frac,
boolean isLog)
Returns a value determined by a fixed range and a fractional scale point
within it.
|
static <T> T[] |
singletonArray(T object)
Returns a single-element array from an object with a parameterised type.
|
static boolean |
storeFullPrecision()
Policy for whether to cache full precision coordinates.
|
static Rectangle |
subtractInsets(Rectangle base,
Insets insets)
Returns the rectangle that results from removing the insets from
a given rectangle.
|
static double |
toDouble(Number value)
Turns a Number object into a double primitive.
|
static Picture |
toPicture(Icon icon)
Turns an Icon into a Picture.
|
static double |
toZoom(double unitFactor,
int wheelrot)
Determines a zoom factor from a mouse wheel event and a given
unit zoom factor.
|
static double |
toZoom(double unitFactor,
Point p0,
Point p1,
Boolean isY)
Determines an X, Y or isotropic zoom factor from a pair of
screen positions and a given unit zoom factor.
|
static <A> A |
tupleCollect(SplitCollector<TupleSequence,A> collector,
DataSpec dataSpec,
DataStore dataStore)
Convenience TupleRunner collection method using a DataStore and DataSpec.
|
static double |
unscaleValue(double min,
double max,
double point,
boolean isLog)
Returns the proportional position of a point within a fixed range.
|
public static final TupleSequence EMPTY_TUPLE_SEQUENCE
public static final Span EMPTY_SPAN
public static final PdfGraphicExporter LATEX_PDF_EXPORTER
public static final double NEAR_PIXELS
public static final int DEFAULT_MAX_PIXELS
public static final short MAX_MARKSIZE
public static final int MIN_RAMP_UNIT
public static SplitRunner<CoordSequence> COORD_RUNNER
public static boolean equals(Object o1, Object o2)
o1
- one object or nullo2
- other object or nullpublic static boolean doubleEquals(double d1, double d2)
d1
- first valued2
- second valuepublic static int hashCode(Object obj)
obj
- object or nullpublic static boolean storeFullPrecision()
public static boolean getDefaultTextAntialiasing()
So the current policy is to set the default true for OSX, and false for other platforms.
public static String getIndexSuffix(int ipos)
ipos
- zero-based position number1+ipos
public static void logTimeElapsed(Logger logger, String phase, long elapsed)
logger
- log message destinationphase
- name of step to log time ofelapsed
- elapsed time to report (generally milliseconds)public static void logTimeFromStart(Logger logger, String phase, long start)
logger
- log message destinationphase
- name of step to log time ofstart
- start currentTimeMillis
public static <T> T[] arrayConcat(T[] a1, T[] a2)
a1
- first arraya2
- second arraypublic static String concatLines(String[] lines)
lines
- lines of textpublic static double toDouble(Number value)
value
- number objectpublic static boolean isFinite(double value)
value
- value to testvalue
is non-NaN and non-infinitepublic static boolean isPointFinite(Point2D.Double gp)
gp
- position to testpublic static boolean isPointReal(Point2D.Double gp)
gp
- position to testpublic static void quantisePoint(Point2D.Double dpos, Point gpos)
ifloor(double)
on both coordinates.
The input coordinates must not be NaN.dpos
- input definite floating point graphics positiongpos
- output graphics position objectpublic static int ifloor(double x)
x
- definite floating point valueMath.floor(double)
public static double[] orderPair(double p1, double p2)
p1
- one valuep2
- other valuepublic static Rectangle getGangBounds(Gang gang)
gang
- gangpublic static <T> T[] singletonArray(T object)
object
- array elementpublic static <P> P[] createProfileArray(SurfaceFactory<P,?> surfFact, int length)
surfFact
- surface factorylength
- array sizepublic static <P,A> A[] createAspectArray(SurfaceFactory<P,A> surfFact, int length)
surfFact
- surface factorylength
- array sizepublic static <P,A> ZoneContent<P,A>[] createZoneContentArray(SurfaceFactory<P,A> surfFact, int length)
surfFact
- surface factorylength
- array sizepublic static Picture toPicture(Icon icon)
icon
- icon@Slow public static <A> A tupleCollect(SplitCollector<TupleSequence,A> collector, DataSpec dataSpec, DataStore dataStore)
collector
- collectordataSpec
- data specdataStore
- data store, supplying both the data and the runner@Slow public static void extendCoordinateRanges(PlotLayer[] layers, Range[] ranges, boolean[] logFlags, boolean doPad, DataStore dataStore)
layers
- plot layersranges
- nDataDim
-element array of range objects
to extendlogFlags
- nDataDim
-element array indicating
whether data dimensions are
linear (false) or logarithmic (true),doPad
- whether to add a small standard amount of padding
to the resultdataStore
- data storagepublic static void padRange(Range range, boolean logFlag)
range
- range to padlogFlag
- true for logarithmic scaling, false for linearpublic static ValueInfo getScaleInfo(PlotLayer[] layers, AuxScale scale)
layers
- list of layersscale
- aux item of interestpublic static String getScaleAxisLabel(PlotLayer[] layers, AuxScale scale)
layers
- list of layersscale
- aux item of interest@Slow public static IndicatedRow getClosestRow(Surface surface, DataGeom geom, int iPosCoord, java.util.function.Supplier<TupleSequence> tupleSupplier, TupleRunner runner, Point2D point)
NEAR_PIXELS
.surface
- plot surfacegeom
- maps data positions to graphics positionsiPosCoord
- coordinate index of positional coords in tseqtupleSupplier
- iterable over tuplesrunner
- manages tuple iterationpoint
- reference graphics position@Slow public static Icon createPlotIcon(PlotPlacement placer, PlotLayer[] layers, Map<AuxScale,Span> auxSpans, DataStore dataStore, PaperType paperType, boolean cached, Collection<Object> storedPlans)
storedPlans
object is supplied, it may contain
plans from previous plots. On exit, it will contain the plans
used for this plot.placer
- plot placementlayers
- layers constituting plot contentauxSpans
- requested range information calculated from datadataStore
- data storage objectpaperType
- rendering typecached
- whether to cache pixels for future usestoredPlans
- writable collection of plan objects, or nullpublic static int getButtonChangedIndex(MouseEvent evt)
This method will return an integer in the range 0-3 with the following meaning:
The output of this method is the 'logical' value, so 2 may be returned to indicate simultaneous press of both buttons on a 2-button mouse if it's set up that way. If users have set up their mice strangely then a physical left click might not yield a value of 1 - that's their lookout.
This method is only intended for use when a single button is expected; multi-button gestures are not supported.
We follow the (conventional) usage where ctrl-click means right-click on a single button mouse, and we also currently use shift-click to mean center button. These conventions may be noted in user documentation.
evt
- mouse eventgetButtonDownIndex(java.awt.event.MouseEvent)
public static int getButtonDownIndex(MouseEvent evt)
getButtonChangedIndex(java.awt.event.MouseEvent)
.evt
- mouse eventgetButtonChangedIndex(java.awt.event.MouseEvent)
public static double toZoom(double unitFactor, int wheelrot)
unitFactor
- positive zoom factor corresponding to a
single clickwheelrot
- mouse wheel rotationpublic static double toZoom(double unitFactor, Point p0, Point p1, Boolean isY)
unitFactor
- positive zoom factor corresponding to a
single clickp0
- origin pointp1
- destination pointisY
- direction flag; TRUE for Y zoom, FALSE for X zoom and
null for isotropic zoompublic static double scaleValue(double min, double max, double frac, boolean isLog)
min
- minimum of rangemax
- maximum of rangefrac
- fractional scale pointisLog
- true iff the range is logarithmicpublic static double scaleValue(double min, double max, double frac)
scaleValue(min, max, frac, false)
min
- minimum of rangemax
- maximum of rangefrac
- fractional scale pointpublic static double unscaleValue(double min, double max, double point, boolean isLog)
scaleValue(double, double, double, boolean)
.min
- minimum of rangemax
- maximum of rangepoint
- data valueisLog
- true iff the range is logarithmicpublic static double[] scaleRange(double min, double max, Subrange subrange, boolean isLog)
min
- minimum of rangemax
- maximum of rangesubrange
- sub-range, both ends between 0 and 1isLog
- true iff the range is logarithmicpublic static Span createSpan(double lo, double hi)
lo
- lower bound, may be NaNhi
- upper bound, may be NaNpublic static boolean approxEquals(double v0, double v1)
v0
- one valuev1
- other valuepublic static String formatNumber(double value, String baseFmt, int nFracDigits)
value
- numeric value to formatbaseFmt
- format string as for DecimalFormat
nFracDigits
- fixed number of digits after the decimal pointpublic static String formatNumberSf(double value, int nsf)
value
- numeric value to formatnsf
- (approximate) number of significant figurespublic static String formatNumber(double value, double epsilon)
value
- value to formatepsilon
- small valuepublic static String[] formatAxisRangeLimits(double lo, double hi, boolean isLog, int npix)
lo
- data lower boundhi
- data upper boundisLog
- true for logarithmic axis, false for linearnpix
- approximate number of pixels covered by the rangepublic static double roundNumber(double x, double epsilon)
x
- input valueepsilon
- indicates desired rounding amountpublic static ConfigMap configLimits(ConfigKey<Double> minKey, ConfigKey<Double> maxKey, double min, double max, int npix)
minKey
- config key for minimum valuemaxKey
- config key for maximum valuemin
- minimum valuemax
- maximum valuenpix
- number of pixels (quanta) between min and max;
this is used to determine at what level of
precision to round the config valuespublic static Rectangle subtractInsets(Rectangle base, Insets insets)
base
- input rectangleinsets
- amount that should be excluded from the edges of
the base rectanglepublic static Tick[] getShadowTicks(Tick[] ticks)
ticks
- input tick arraypublic static Graphics createLineGraphics(Graphics g, Color color)
For most purposes, this can be assumed to do the same as:
Graphics g2 = g.create(); g2.setColor(color); return g2;However, it contains an additional hack that should improve output to graphics contexts that do not support transparency, such as to PostScript.
Briefly, for partially transparent colours in a PostScript context, the stroke width is multiplied by the supplied colour's alpha value, so that although the lines are still opaque, they are at least thin enough to look about right. It's better than nothing.
g
- input graphics context, unchanged on exitcolor
- colour with which lines are to be drawn;
may have a non-unity alpha componentCopyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.