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.
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.
blurImage
blurImage( java.awt.image.BufferedImage im, int size ) → BufferedImage
blur the image with a Guassian blur.
Parameters
im -
size - the size of the blur, roughly in pixels.
Returns:
image
search for examples
view on GitHub
view source
calculateAT
calculateAT( org.das2.graph.DasAxis xaxis0, org.das2.graph.DasAxis yaxis0, org.das2.graph.DasAxis xaxis1, org.das2.graph.DasAxis yaxis1 ) → 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 source
calculateManualTicks
calculateManualTicks( String lticks, DatumRange dr, boolean log ) → 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.
Parameters
lticks -
dr -
log -
Returns:
org.das2.graph.TickVDescriptor
search for examples
view on GitHub
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 -
result -
clip -
Returns:
int
search for examples
view on GitHub
view source
copyAxis
copyAxis( org.das2.graph.DasAxis a ) → DasAxis
return a copy of the plot. It does not have the
row and column set to its own row and column.
Parameters
a -
Returns:
org.das2.graph.DasAxis
search for examples
view on GitHub
view source
copyColorBar
copyColorBar( org.das2.graph.DasColorBar a ) → DasColorBar
return a copy of the plot. It does not have the
row and column set to its own row and column.
Parameters
a -
Returns:
org.das2.graph.DasColorBar
search for examples
view on GitHub
view source
copyPlot
copyPlot( org.das2.graph.DasPlot p ) → 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 -
Returns:
org.das2.graph.DasPlot
search for examples
view on GitHub
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 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 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 source
getGaussianBlurFilter
getGaussianBlurFilter( int radius, boolean horizontal ) → 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 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 source
guessPlot
guessPlot( QDataSet ds ) → 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 source
guessRenderer
guessRenderer( QDataSet ds ) → Renderer
legacy guess that is used who-knows-where. Autoplot has much better code
for guessing, refer to it.
Parameters
ds -
Returns:
org.das2.graph.Renderer
search for examples
view on GitHub
view source
guessXAxis
guessXAxis( QDataSet ds ) → DasAxis
Returns:
org.das2.graph.DasAxis
search for examples
view on GitHub
view source
guessYAxis
guessYAxis( QDataSet dsz ) → DasAxis
Returns:
org.das2.graph.DasAxis
search for examples
view on GitHub
view source
guessZAxis
guessZAxis( QDataSet dsz ) → DasAxis
Returns:
org.das2.graph.DasAxis
search for examples
view on GitHub
view source
invTransformRange
invTransformRange( org.das2.graph.DasAxis axis, double x1, double x2 ) → DatumRange
Returns:
org.das2.datum.DatumRange
search for examples
view on GitHub
view source
lineIntersection
lineIntersection( java.awt.geom.Line2D line1, java.awt.geom.Line2D line2, boolean noBoundsCheck ) → Point2D
returns the point where the two line segments intersect, or null.
Parameters
line1 -
line2 -
noBoundsCheck - if true, then do not check the segment bounds.
Returns:
java.awt.geom.Point2D
search for examples
view on GitHub
view source
lineRectangleIntersection
lineRectangleIntersection( java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Rectangle2D r0 ) → 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 -
p1 -
r0 -
Returns:
null or the point along the rectangle
search for examples
view on GitHub
view source
lineRectangleMask
lineRectangleMask( java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Rectangle2D r ) → 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 source
newDasPlot
newDasPlot( org.das2.graph.DasCanvas canvas, DatumRange x, DatumRange y ) → 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 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 source
perpendicularLine
perpendicularLine( java.awt.geom.Line2D line, java.awt.Point p, double len ) → 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 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.
Parameters
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
it - 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.
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 source
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 source
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 source
shortenLine
shortenLine( java.awt.geom.Line2D line, double l1, double l2 ) → 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 source
shrinkRectangle
shrinkRectangle( java.awt.Rectangle bounds, int percent ) → 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 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 -
range -
Returns:
double[]
search for examples
view on GitHub
view source
visualize
visualize( QDataSet ds ) → DasPlot
get a plot and add it to a JFrame.
Parameters
ds -
Returns:
org.das2.graph.DasPlot
search for examples
view on GitHub
view source