public class GraphUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
GraphUtil.Copyable<T>
Classes that implement this interface provide their instances with
the ability to copy themselves in a manner similar to Cloneable objects,
but without the drawbacks of Cloneable.
|
static class |
GraphUtil.DebuggingGeneralPath
DebuggingGeneralPath can be used for debugging.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONNECT_MODE_HISTOGRAM
draw the lines in histogram mode, horizontal to the half-way point, then vertical, then horizontal the rest of the way.
|
static java.lang.String |
CONNECT_MODE_SCATTER
don't draw connecting lines.
|
static java.lang.String |
CONNECT_MODE_SERIES
the normal connecting mode from point-to-point in a series.
|
static java.lang.String |
FILL_TEXTURE_BACKHASH |
static java.lang.String |
FILL_TEXTURE_CROSSHASH |
static java.lang.String |
FILL_TEXTURE_HASH |
static java.lang.String |
FILL_TEXTURE_NONE |
static java.lang.String |
FILL_TEXTURE_SOLID |
static int |
MAX_TICKS
limit the number of ticks which are computed
|
Constructor and Description |
---|
GraphUtil() |
Modifier and Type | Method and Description |
---|---|
static java.awt.image.BufferedImage |
blurImage(java.awt.image.BufferedImage im,
int size)
blur the image with a Guassian blur.
|
static java.awt.geom.AffineTransform |
calculateAT(DasAxis xaxis0,
DasAxis yaxis0,
DasAxis xaxis1,
DasAxis yaxis1)
calculates the AffineTransform between two sets of x and y axes, if possible.
|
static java.awt.geom.AffineTransform |
calculateAT(DatumRange xaxis0,
DatumRange yaxis0,
DasAxis xaxis1,
DasAxis yaxis1) |
static TickVDescriptor |
calculateManualTicks(java.lang.String lticks,
DatumRange dr,
boolean log)
calculate a TickVDescriptor for the ticks.
|
static int |
clipPath(java.awt.geom.PathIterator it,
java.awt.geom.GeneralPath result,
java.awt.Rectangle clip)
clip the path to within the clip rectangle.
|
static javax.swing.Icon |
colorIcon(java.awt.Color iconColor,
int w,
int h)
return an icon block with the color and size.
|
static javax.swing.ImageIcon |
colorImageIcon(java.awt.Color iconColor,
int w,
int h)
return an ImageIcon with the color and size.
|
static DasAxis |
copyAxis(DasAxis a)
return a copy of the plot.
|
static DasColorBar |
copyColorBar(DasColorBar a)
return a copy of the plot.
|
static DasPlot |
copyPlot(DasPlot p)
return a copy of the plot.
|
static java.lang.String |
describe(java.awt.geom.GeneralPath path,
boolean enumeratePoints)
describe the path for debugging.
|
static void |
fillWithTexture(java.awt.Graphics2D g,
java.awt.geom.GeneralPath pbox,
java.awt.Color fillColor,
java.lang.String fillTexture)
fill the region using the specified fillTexture.
|
static java.lang.String |
getATScaleTranslateString(java.awt.geom.AffineTransform at)
return a string representation of the affine transforms used in DasPlot for
debugging.
|
static Converter |
getFontConverter(DasCanvasComponent dcc,
java.lang.String fallbackFont)
converts forward from relative font spec to point size, used by
the annotation and axis nodes.
|
static java.awt.image.ConvolveOp |
getGaussianBlurFilter(int radius,
boolean horizontal)
return a Gaussian filter for blurring images.
|
static java.awt.geom.GeneralPath |
getPath(DasAxis xAxis,
DasAxis yAxis,
QDataSet ds,
boolean histogram,
boolean clip)
get the path for the points, checking for breaks in the data from fill values.
|
static java.awt.geom.GeneralPath |
getPath(DasAxis xAxis,
DasAxis yAxis,
QDataSet xds,
QDataSet yds,
boolean histogram,
boolean clip)
get the path for the points, checking for breaks in the data from fill values.
|
static java.awt.geom.GeneralPath |
getPath(DasAxis xAxis,
DasAxis yAxis,
QDataSet xds,
QDataSet yds,
java.lang.String mode,
boolean clip)
get the path for the points, checking for breaks in the data from fill values or breaks suggested by
linear cadence in the DEPEND_0 of yds.
|
static java.awt.Color |
getRicePaperColor()
return translucent white color for indicating the application is busy.
|
static java.lang.String |
getSegNameFor(int type)
print the name for the segment type
|
static double[] |
getSlopeIntercept(double x0,
double y0,
double x1,
double y1)
calculates the slope and intercept of a line going through two points.
|
static DasPlot |
guessPlot(QDataSet ds)
get a plot and renderer for the dataset.
|
static Renderer |
guessRenderer(QDataSet ds)
legacy guess that is used who-knows-where.
|
static DasAxis |
guessXAxis(QDataSet ds) |
static DasAxis |
guessYAxis(QDataSet dsz) |
static DasAxis |
guessZAxis(QDataSet dsz) |
static DatumRange |
invTransformRange(DasAxis axis,
double x1,
double x2) |
static java.awt.geom.Point2D |
lineIntersection(java.awt.geom.Line2D line1,
java.awt.geom.Line2D line2,
boolean noBoundsCheck)
returns the point where the two line segments intersect, or null.
|
static java.awt.geom.Point2D |
lineRectangleIntersection(java.awt.geom.Point2D p0,
java.awt.geom.Point2D p1,
java.awt.geom.Rectangle2D r0)
return the intersection of a line segment and the edge of a rectangle,
where one point is outside of the rectangle and one is inside.
|
static java.awt.geom.Line2D |
lineRectangleMask(java.awt.geom.Point2D p0,
java.awt.geom.Point2D p1,
java.awt.geom.Rectangle2D r)
return the line segment which is within the rectangle mask.
|
static DasPlot |
newDasPlot(DasCanvas canvas,
DatumRange x,
DatumRange y)
create a plot for the canvas, along with the row and column for layout.
|
static GrannyTextEditor |
newGrannyTextEditor()
return a GrannyTextEditor with the Das2Core extras added.
|
static GrannyTextRenderer |
newGrannyTextRenderer()
return a GrannyTextEditor with the Das2Core extras added.
|
static double |
parseLayoutLength(java.lang.String s,
double totalWidth,
double em)
parse strings like "14em+2pt" into a length in pixels.
|
static java.awt.geom.Line2D |
perpendicularLine(java.awt.geom.Line2D line,
java.awt.Point p,
double len)
create a line perpendicular to the line segment
line , which
would go through p , and have length abs(len) . |
static double |
pointsAlongCurve(java.awt.geom.PathIterator it,
double[] pathlen,
java.awt.geom.Point2D.Double[] result,
double[] orientation,
boolean stopAtMoveTo)
return the points along a curve.
|
static double |
pointsAlongCurve(java.awt.geom.PathIterator it,
double[] pathlen,
java.awt.geom.Point2D.Double[] result,
double[] orientation,
boolean stopAtMoveTo,
java.util.Map<java.lang.String,java.lang.Object> props)
return the points along a curve.
|
static int |
reducePath(java.awt.geom.PathIterator it,
java.awt.geom.GeneralPath result)
Returns the input GeneralPath filled with new points which will be rendered identically to the input path,
but contains a minimal number of points.
|
static int |
reducePath(java.awt.geom.PathIterator it,
java.awt.geom.GeneralPath result,
int res)
Returns the input GeneralPath filled with new points which will be rendered identically to the input path,
but contains a minimal number of points.
|
static int |
reducePath20140622(java.awt.geom.PathIterator it,
java.awt.geom.GeneralPath result,
int resn,
int resd)
New ReducePath reduces a path by keeping track of vertically collinear points, and reducing them to an entry
point, an exit point, min and max.
|
static java.awt.geom.Line2D |
shortenLine(java.awt.geom.Line2D line,
double l1,
double l2)
return line shorted by so many pixels at each end.
|
static java.awt.Rectangle |
shrinkRectangle(java.awt.Rectangle bounds,
int percent)
return rectangle with same center that is percent/100 of the
original width and height.
|
static double[] |
transformRange(DasAxis axis,
DatumRange range)
returns pixel range of the datum range, guarenteeing that the first
element will be less than or equal to the second.
|
static DasPlot |
visualize(QDataSet ds)
get a plot and add it to a JFrame.
|
public static java.lang.String FILL_TEXTURE_CROSSHASH
public static java.lang.String FILL_TEXTURE_HASH
public static java.lang.String FILL_TEXTURE_BACKHASH
public static java.lang.String FILL_TEXTURE_SOLID
public static java.lang.String FILL_TEXTURE_NONE
public static final java.lang.String CONNECT_MODE_HISTOGRAM
public static final java.lang.String CONNECT_MODE_SCATTER
public static final java.lang.String CONNECT_MODE_SERIES
public static final int MAX_TICKS
public static void fillWithTexture(java.awt.Graphics2D g, java.awt.geom.GeneralPath pbox, java.awt.Color fillColor, java.lang.String fillTexture)
g
- the graphics contextpbox
- a general pathfillColor
- if non-null, set this color to fill and return to the original colorfillTexture
- one of the enumerations: none, hash, crosshash, backhash, and solid (and "" is an alias for solid)Renderer.CONTROL_KEY_FILL_TEXTURE
public static GrannyTextRenderer newGrannyTextRenderer()
public static GrannyTextEditor newGrannyTextEditor()
public static DasPlot newDasPlot(DasCanvas canvas, DatumRange x, DatumRange y)
canvas
- the canvas parent for the plot.x
- the x rangey
- the y rangepublic static java.awt.geom.GeneralPath getPath(DasAxis xAxis, DasAxis yAxis, QDataSet ds, boolean histogram, boolean clip)
xAxis
- the x axis.yAxis
- the y axis.ds
- the y values. SemanticOps.xtagsDataSet is used to extract the x values.histogram
- if true, use histogram (stair-step) modeclip
- limit path to what's visible for each axis.public static java.awt.geom.GeneralPath getPath(DasAxis xAxis, DasAxis yAxis, QDataSet xds, QDataSet yds, boolean histogram, boolean clip)
xAxis
- the x axis.yAxis
- the y axis.xds
- the x values.yds
- the y values.histogram
- if true, use histogram (stair-step) modeclip
- limit path to what's visible for each axis.public static final java.lang.String getSegNameFor(int type)
type
- public static java.awt.geom.GeneralPath getPath(DasAxis xAxis, DasAxis yAxis, QDataSet xds, QDataSet yds, java.lang.String mode, boolean clip)
xAxis
- the x axis.yAxis
- the y axis.xds
- the x values.yds
- the y values, possibly containing a DEPEND_0.mode
- one of CONNECT_MODE_SERIES, CONNECT_MODE_SCATTER, or CONNECT_MODE_HISTOGRAMclip
- limit path to what's visible for each axis.CONNECT_MODE_SERIES
,
CONNECT_MODE_SCATTER
,
CONNECT_MODE_HISTOGRAM
public static java.awt.geom.AffineTransform calculateAT(DasAxis xaxis0, DasAxis yaxis0, DasAxis xaxis1, DasAxis yaxis1)
xaxis0
- the original reference frame x axisyaxis0
- the original reference frame y axisxaxis1
- the new reference frame x axisyaxis1
- the new reference frame y axispublic static java.awt.geom.AffineTransform calculateAT(DatumRange xaxis0, DatumRange yaxis0, DasAxis xaxis1, DasAxis yaxis1)
public static Renderer guessRenderer(QDataSet ds)
ds
- public static DasPlot guessPlot(QDataSet ds)
ds
- the datasetpublic static DasAxis copyAxis(DasAxis a)
a
- public static DasColorBar copyColorBar(DasColorBar a)
a
- public static DasPlot copyPlot(DasPlot p)
cnvsNew= new DasCanvas(500,500);
row= new DasRow(cnvsNew,0.2,0.8);
column= new DasColumn(cnvsNew,0.2,0.8);
p= GraphUtil.copyPlot(dp);
cnvsNew.add(p,row,column);
p
- public static DasPlot visualize(QDataSet ds)
ds
- public static int clipPath(java.awt.geom.PathIterator it, java.awt.geom.GeneralPath result, java.awt.Rectangle clip)
it
- result
- clip
- public static int reducePath20140622(java.awt.geom.PathIterator it, java.awt.geom.GeneralPath result, int resn, int resd)
it
- input path.result
- output path.resn
- the resolution numerator (e.g. 1)resd
- the resolution denominator (e.g. 5)public static int reducePath(java.awt.geom.PathIterator it, java.awt.geom.GeneralPath result)
it
- A path iterator with minute details that will be lost when rendering.result
- A GeneralPath to put the result into.public static int reducePath(java.awt.geom.PathIterator it, java.awt.geom.GeneralPath result, int res)
it
- A path iterator with minute details that will be lost when rendering.result
- A GeneralPath to put the result into.res
- limit the resolution in pixelspublic static double pointsAlongCurve(java.awt.geom.PathIterator it, double[] pathlen, java.awt.geom.Point2D.Double[] result, double[] orientation, boolean stopAtMoveTo)
pathlen
- monotonically increasing path lengths at which the position is to be located. May be null if only the total path length is desired.result
- the resultant points will be put into this array. This array should have the same number of elements as pathlenorientation
- the local orientation, in radians, of the point at will be put into this array. This array should have the same number of elements as pathlenit
- PathIterator first point is used to start the length.stopAtMoveTo
- treat SEG_MOVETO as the end of the path. The pathIterator will be left at this point.public static double pointsAlongCurve(java.awt.geom.PathIterator it, double[] pathlen, java.awt.geom.Point2D.Double[] result, double[] orientation, boolean stopAtMoveTo, java.util.Map<java.lang.String,java.lang.Object> props)
pathlen
- monotonically increasing path lengths at which the position is to be located. May be null if only the total path length is desired.result
- the resultant points will be put into this array. This array should have the same number of elements as pathlenorientation
- the local orientation, in radians, of the point at will be put into this array. This array should have the same number of elements as pathlenit
- PathIterator first point is used to start the length.stopAtMoveTo
- treat SEG_MOVETO as the end of the path. The pathIterator will be left at this point.props
- empty map where properties are added.public static double parseLayoutLength(java.lang.String s, double totalWidth, double em)
s
- the string specifying ems and pxstotalWidth
- the total with for the normalized length.em
- the size of an em in pixels.DasDevicePosition.parseLayoutStr(java.lang.String)
public static java.lang.String getATScaleTranslateString(java.awt.geom.AffineTransform at)
at
- the affine transformpublic static double[] getSlopeIntercept(double x0, double y0, double x1, double y1)
x0
- the first point xy0
- the first point yx1
- the second point xy1
- the second point ypublic static java.awt.Color getRicePaperColor()
public static java.awt.image.ConvolveOp getGaussianBlurFilter(int radius, boolean horizontal)
radius
- the radius filter in pixels.horizontal
- true if horizontal blur.public static java.awt.image.BufferedImage blurImage(java.awt.image.BufferedImage im, int size)
im
- size
- the size of the blur, roughly in pixels.public static java.lang.String describe(java.awt.geom.GeneralPath path, boolean enumeratePoints)
path
- the Path to describeenumeratePoints
- if true, print all the points as well.public static java.awt.geom.Point2D lineIntersection(java.awt.geom.Line2D line1, java.awt.geom.Line2D line2, boolean noBoundsCheck)
line1
- line2
- noBoundsCheck
- if true, then do not check the segment bounds.public static java.awt.geom.Line2D lineRectangleMask(java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Rectangle2D r)
p0
- the first pointp1
- the second pointr
- the rectanglepublic static java.awt.geom.Point2D lineRectangleIntersection(java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Rectangle2D r0)
p0
- p1
- r0
- public static double[] transformRange(DasAxis axis, DatumRange range)
axis
- range
- public static DatumRange invTransformRange(DasAxis axis, double x1, double x2)
public static javax.swing.Icon colorIcon(java.awt.Color iconColor, int w, int h)
iconColor
- the colorw
- the width in pixelsh
- the height in pixelspublic static javax.swing.ImageIcon colorImageIcon(java.awt.Color iconColor, int w, int h)
iconColor
- w
- h
- public static java.awt.Rectangle shrinkRectangle(java.awt.Rectangle bounds, int percent)
bounds
- the original rectangle.percent
- the percent to increase (110% is 10% bigger)public static java.awt.geom.Line2D shortenLine(java.awt.geom.Line2D line, double l1, double l2)
line
- the linel1
- number of units to adjust the first point, towards the centerl2
- number of units to adjust the second point, towards the centerpublic static java.awt.geom.Line2D perpendicularLine(java.awt.geom.Line2D line, java.awt.Point p, double len)
line
, which
would go through p
, and have length abs(len)
.
If len is negative, then line.p1,line.p2,p is counter-clockwise.
This is left unimplemented as it's a nice student project.line
- a line segment.p
- a point, whose projection is necessarily within the line segment.len
- the length of the resulting line, orpublic static Converter getFontConverter(DasCanvasComponent dcc, java.lang.String fallbackFont)
dcc
- the canvas component.fallbackFont
- the font to use when a font is not available, like "sans-8"public static TickVDescriptor calculateManualTicks(java.lang.String lticks, DatumRange dr, boolean log)
lticks
- the specificationdr
- the range to coverlog
- https://github.com/autoplot/dev/blob/master/demos/2021/20211130/demoCalculateManualTicks.jy
,
the maximum number of minor or major ticks calculated