org.das2.graph.GraphUtil
Utilities for drawing graphics and establishing standard behavior.
This provides functions to get a 16x16 icon for a color, getting a Path
from a series of data points, and a "visualize" method for simply looking at
some data.
GraphUtil( )
FILL_TEXTURE_CROSSHASH
FILL_TEXTURE_HASH
FILL_TEXTURE_BACKHASH
FILL_TEXTURE_SOLID
FILL_TEXTURE_NONE
CONNECT_MODE_HISTOGRAM
draw the lines in histogram mode, horizontal to the half-way point, then vertical, then horizontal the rest of the way.
CONNECT_MODE_SCATTER
don't draw connecting lines.
CONNECT_MODE_SERIES
the normal connecting mode from point-to-point in a series.
MAX_TICKS
limit the number of ticks which are computed
blurImage
blurImage( java.awt.image.BufferedImage im, int size ) → java.awt.image.BufferedImage
blur the image with a Guassian blur.
Parameters
im - a BufferedImage
size - the size of the blur, roughly in pixels.
Returns:
image
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
calculateAT
calculateAT( org.das2.graph.DasAxis xaxis0, org.das2.graph.DasAxis yaxis0, org.das2.graph.DasAxis xaxis1, org.das2.graph.DasAxis yaxis1 ) → java.awt.geom.AffineTransform
calculates the AffineTransform between two sets of x and y axes, if possible.
Parameters
xaxis0 - the original reference frame x axis
yaxis0 - the original reference frame y axis
xaxis1 - the new reference frame x axis
yaxis1 - the new reference frame y axis
Returns:
an AffineTransform that transforms data positioned with xaxis0 and yaxis0 on xaxis1 and yaxis1, or null if no such transform exists.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
calculateAT( DatumRange xaxis0, DatumRange yaxis0, org.das2.graph.DasAxis xaxis1, org.das2.graph.DasAxis yaxis1 ) → java.awt.geom.AffineTransform
calculateManualTicks
calculateManualTicks( String lticks, DatumRange dr, boolean log ) → org.das2.graph.TickVDescriptor
calculate a TickVDescriptor for the ticks.
Example specifications:
- +20 - every 20 units, whatever the data units are.
- +20s - every 20 seconds
- 0,20,40,60,100 - explicit locations.
- +20s/4 - every 20 seconds, with four minor divisions.
- +20s/5,10,15 - minor ticks repeat each 20s.
- 100,200,300/50,150,250,350 - explicit list of major and minor ticks.
- *10/+1 - log ticks with linear minor ticks.
- none - no ticks
Parameters
lticks - the specification
dr - the range to cover
log - a boolean
Returns:
null if the string can't be parsed, or the TickVDescriptor
See Also:
https://github.com/autoplot/dev/blob/master/demos/2021/20211130/demoCalculateManualTicks.jy
MAX_TICKS the maximum number of minor or major ticks calculated the maximum number of minor or major ticks calculated
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
clipPath
clipPath( java.awt.geom.PathIterator it, java.awt.geom.GeneralPath result, java.awt.Rectangle clip ) → int
clip the path to within the clip rectangle. Note this may introduce
breaks where the path was continuous before. Note this does not work
with quadTo etc. This was motivated by an old version of Adobe Illustrator
which didn't respect the clip set in the PDF, and with the journal
Nature, which apparently uses an old version of Illustrator.
Parameters
it - a PathIterator
result - a GeneralPath
clip - a Rectangle
Returns:
an int
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
colorIcon
colorIcon( java.awt.Color iconColor, int w, int h ) → javax.swing.Icon
return an icon block with the color and size.
Parameters
iconColor - the color
w - the width in pixels
h - the height in pixels
Returns:
an icon.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
colorImageIcon
colorImageIcon( java.awt.Color iconColor, int w, int h ) → javax.swing.ImageIcon
return an ImageIcon with the color and size.
Parameters
iconColor - a Color
w - an int
h - an int
Returns:
a javax.swing.ImageIcon
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
copyAxis
copyAxis( org.das2.graph.DasAxis a ) → org.das2.graph.DasAxis
return a copy of the plot. It does not have the
row and column set to its own row and column.
Parameters
a - a DasAxis
Returns:
an org.das2.graph.DasAxis
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
copyColorBar
copyColorBar( org.das2.graph.DasColorBar a ) → org.das2.graph.DasColorBar
return a copy of the plot. It does not have the
row and column set to its own row and column.
Parameters
a - a DasColorBar
Returns:
an org.das2.graph.DasColorBar
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
copyPlot
copyPlot( org.das2.graph.DasPlot p ) → org.das2.graph.DasPlot
return a copy of the plot. This will include the Renderers and the
data they contain. The plot is not attached to a canvas or row
and column.
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);
Parameters
p - a DasPlot
Returns:
an org.das2.graph.DasPlot
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
describe
describe( java.awt.geom.GeneralPath path, boolean enumeratePoints ) → String
describe the path for debugging.
Parameters
path - the Path to describe
enumeratePoints - if true, print all the points as well.
Returns:
String description.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
fillWithTexture
fillWithTexture( java.awt.Graphics2D g, java.awt.geom.GeneralPath pbox, java.awt.Color fillColor, String fillTexture ) → void
fill the region using the specified fillTexture.
Parameters
g - the graphics context
pbox - a general path
fillColor - if non-null, set this color to fill and return to the original color
fillTexture - one of the enumerations: none, hash, crosshash, backhash, and solid (and "" is an alias for solid)
Returns:
void (returns nothing)
See Also:
Renderer#CONTROL_KEY_FILL_TEXTURE
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getATScaleTranslateString
getATScaleTranslateString( java.awt.geom.AffineTransform at ) → String
return a string representation of the affine transforms used in DasPlot for
debugging.
Parameters
at - the affine transform
Returns:
a string representation of the affine transforms used in DasPlot for
debugging.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getFontConverter
getFontConverter( org.das2.graph.DasCanvasComponent dcc, String fallbackFont ) → Converter
converts forward from relative font spec to point size, used by
the annotation and axis nodes.
Parameters
dcc - the canvas component.
fallbackFont - the font to use when a font is not available, like "sans-8"
Returns:
the converter that converts between strings like "1em" and the font.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getGaussianBlurFilter
getGaussianBlurFilter( int radius, boolean horizontal ) → java.awt.image.ConvolveOp
return a Gaussian filter for blurring images.
Parameters
radius - the radius filter in pixels.
horizontal - true if horizontal blur.
Returns:
the ConvolveOp
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getPath
getPath( org.das2.graph.DasAxis xAxis, org.das2.graph.DasAxis yAxis, QDataSet ds, boolean histogram, boolean clip ) → java.awt.geom.GeneralPath
get the path for the points, checking for breaks in the data from fill values.
Parameters
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) mode
clip - limit path to what's visible for each axis.
Returns:
the GeneralPath.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getPath( org.das2.graph.DasAxis xAxis, org.das2.graph.DasAxis yAxis, QDataSet xds, QDataSet yds, boolean histogram, boolean clip ) → java.awt.geom.GeneralPath
getPath( org.das2.graph.DasAxis xAxis, org.das2.graph.DasAxis yAxis, QDataSet xds, QDataSet yds, String mode, boolean clip ) → java.awt.geom.GeneralPath
getRicePaperColor
getRicePaperColor( ) → java.awt.Color
return translucent white color for indicating the application is busy.
Returns:
translucent white color
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getSegNameFor
getSegNameFor( int type ) → String
print the name for the segment type
Parameters
type - an int
Returns:
"SEG_MOVETO", etc or "SEG_???"
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getSlopeIntercept
getSlopeIntercept( double x0, double y0, double x1, double y1 ) → double[]
calculates the slope and intercept of a line going through two points.
Parameters
x0 - the first point x
y0 - the first point y
x1 - the second point x
y1 - the second point y
Returns:
a double array with two elements [ slope, intercept ].
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
guessPlot
guessPlot( QDataSet ds ) → org.das2.graph.DasPlot
get a plot and renderer for the dataset.
Parameters
ds - the dataset
Returns:
a plot with a renderer for the dataset.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
guessRenderer
guessRenderer( QDataSet ds ) → org.das2.graph.Renderer
legacy guess that is used who-knows-where. Autoplot has much better code
for guessing, refer to it.
Parameters
ds - a QDataSet
Returns:
an org.das2.graph.Renderer
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
guessXAxis
guessXAxis( QDataSet ds ) → org.das2.graph.DasAxis
Parameters
ds - a QDataSet
Returns:
org.das2.graph.DasAxis
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
guessYAxis
guessYAxis( QDataSet dsz ) → org.das2.graph.DasAxis
Parameters
dsz - a QDataSet
Returns:
org.das2.graph.DasAxis
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
guessZAxis
guessZAxis( QDataSet dsz ) → org.das2.graph.DasAxis
Parameters
dsz - a QDataSet
Returns:
org.das2.graph.DasAxis
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
invTransformRange
invTransformRange( org.das2.graph.DasAxis axis, double x1, double x2 ) → DatumRange
Parameters
axis - a DasAxis
x1 - a double
x2 - a double
Returns:
org.das2.datum.DatumRange
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
lineIntersection
lineIntersection( java.awt.geom.Line2D line1, java.awt.geom.Line2D line2, boolean noBoundsCheck ) → java.awt.geom.Point2D
returns the point where the two line segments intersect, or null.
Parameters
line1 - a Line2D
line2 - a Line2D
noBoundsCheck - if true, then do not check the segment bounds.
Returns:
a java.awt.geom.Point2D
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
lineRectangleIntersection
lineRectangleIntersection( java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Rectangle2D r0 ) → java.awt.geom.Point2D
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.
Parameters
p0 - a Point2D
p1 - a Point2D
r0 - a Rectangle2D
Returns:
null or the point along the rectangle
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
lineRectangleMask
lineRectangleMask( java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Rectangle2D r ) → java.awt.geom.Line2D
return the line segment which is within the rectangle mask.
Parameters
p0 - the first point
p1 - the second point
r - the rectangle
Returns:
null when they do not intersect, or the segment
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
newDasPlot
newDasPlot( org.das2.graph.DasCanvas canvas, DatumRange x, DatumRange y ) → org.das2.graph.DasPlot
create a plot for the canvas, along with the row and column for layout.
Parameters
canvas - the canvas parent for the plot.
x - the x range
y - the y range
Returns:
the plot.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
newGrannyTextEditor
newGrannyTextEditor( ) → org.das2.components.GrannyTextEditor
return a GrannyTextEditor with the Das2Core extras added.
Returns:
an org.das2.components.GrannyTextEditor
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
newGrannyTextRenderer
newGrannyTextRenderer( ) → org.das2.util.GrannyTextRenderer
return a GrannyTextEditor with the Das2Core extras added. Examples
include:
psym;circles;size=0.5em;color=red
- block
- img;https://autoplot.org/Logo96.png;50%
Returns:
an org.das2.util.GrannyTextRenderer
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
parseLayoutLength
parseLayoutLength( String s, double totalWidth, double em ) → double
parse strings like "14em+2pt" into a length in pixels.
- "1em",0,8 -> 8
- "50%",240,0 -> 120
- "4pt",240,8 -> 4
- "4px",240,8 -> 4
- "1em+4pt",240,8 -> 12
Parameters
s - the string specifying ems and pxs
totalWidth - the total with for the normalized length.
em - the size of an em in pixels.
Returns:
the length in pixels
See Also:
DasDevicePosition#parseLayoutStr(java.lang.String)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
perpendicularLine
perpendicularLine( java.awt.geom.Line2D line, java.awt.Point p, double len ) → java.awt.geom.Line2D
create a line perpendicular to the line segment 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.
Parameters
line - a line segment.
p - a point, whose projection is necessarily within the line segment.
len - the length of the resulting line, or
Returns:
line colinear with p and having length abs(len).
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
pointsAlongCurve
pointsAlongCurve( java.awt.geom.PathIterator it, double[] pathlen, java.awt.geom.Point2D.Double[] result, double[] orientation, boolean stopAtMoveTo ) → double
return the points along a curve. Used by ContourRenderer. The returned
result is the remaining path length. Elements of pathlen that are beyond
the total path length are not computed, and the result points will be null.
Note that CUBICTO and QUADTO are not supported.
Parameters
it - PathIterator first point is used to start the length.
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 pathlen
orientation - 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 pathlen
stopAtMoveTo - treat SEG_MOVETO as the end of the path. The pathIterator will be left at this point.
Returns:
the remaining length. Note null may be used for pathlen, result, and orientation and this will simply return the total path length.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
pointsAlongCurve( java.awt.geom.PathIterator it, double[] pathlen, java.awt.geom.Point2D.Double[] result, double[] orientation, boolean stopAtMoveTo, java.util.Map props ) → double
reducePath
reducePath( java.awt.geom.PathIterator it, java.awt.geom.GeneralPath result ) → int
Returns the input GeneralPath filled with new points which will be rendered identically to the input path,
but contains a minimal number of points. We bin average the points within a cell, because discretization
would mess up the label orientation in contour plotting.
a new GeneralPath which will be rendered identically to the input path,
but contains a minimal number of points.
Parameters
it - A path iterator with minute details that will be lost when rendering.
result - A GeneralPath to put the result into.
Returns:
the number of "points" (LINE_TOs) in the result.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
reducePath( java.awt.geom.PathIterator it, java.awt.geom.GeneralPath result, int res ) → int
reducePath20140622
reducePath20140622( java.awt.geom.PathIterator it, java.awt.geom.GeneralPath result, int resn, int resd ) → int
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. This can be all four in one point. We also limit the resolution and
combine points that are basically the same value, using resn and resd (numerator and denominator). For
example (1/5) would mean that points within x of 1/5 of one another are considered vertically collinear.
Parameters
it - input path.
result - output path.
resn - the resolution numerator (e.g. 1)
resd - the resolution denominator (e.g. 5)
Returns:
the number of points.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
shortenLine
shortenLine( java.awt.geom.Line2D line, double l1, double l2 ) → java.awt.geom.Line2D
return line shorted by so many pixels at each end.
Parameters
line - the line
l1 - number of units to adjust the first point, towards the center
l2 - number of units to adjust the second point, towards the center
Returns:
the new line
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
shrinkRectangle
shrinkRectangle( java.awt.Rectangle bounds, int percent ) → java.awt.Rectangle
return rectangle with same center that is percent/100 of the
original width and height.
Parameters
bounds - the original rectangle.
percent - the percent to increase (110% is 10% bigger)
Returns:
a rectangle with same center that is percent/100. of the
original width and height.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
transformRange
transformRange( org.das2.graph.DasAxis axis, DatumRange range ) → double[]
returns pixel range of the datum range, guarenteeing that the first
element will be less than or equal to the second.
Parameters
axis - a DasAxis
range - a DatumRange
Returns:
a double[]
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
visualize
visualize( QDataSet ds ) → org.das2.graph.DasPlot
get a plot and add it to a JFrame.
Parameters
ds - a QDataSet
Returns:
an org.das2.graph.DasPlot
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]