DrawGrid
is used to draw GridLines and its labels on a UserView. It is notably used by Plotter to draw the grid lines on a plot but can also be used to add grid lines to any UserView
, e.g. behind sliders or another GUI element.
See the example below for its basic use in a UserView.
Note that DrawGrid
does not hold any reference to the UserView
but is meant to have its -draw
method called inside of the -drawFunc
of the UserView
. It only needs to know what bounds to draw the grid lines in and what the horizontal and vertical GridLines
are.
bounds |
A Point or Rect describing the size and position of the grid within the parent view (not including any labels). |
horzGrid |
A grid lines object for the x-axis, instantiated via GridLines, or ControlSpec: -grid method, or |
vertGrid |
A grid lines object for the y-axis, see horzGrid. |
A DrawGrid
.
The warp behavior of the horizGrid and vertGrid is based on the warp behavior of the ControlSpec
used by the grid lines object assigned to each axis.
Multiple DrawGrid
may be used to draw grids on a single UserView.
See -preview if you'd like to preview modifications of this DrawGrid
. See Examples below.
This draws to the currently active UserView. This method is meant to be called from inside the -drawFunc of a UserView
.
nil
See the example below for its basic use in a UserView, including how to manage its bounds when the enclosing view resizes.
Set the x-axis grid lines.
g |
An AbstractGridLines subclass, instantiated via GridLines, or ControlSpec: -grid method, or |
Self.
Set the y-axis grid lines.
g |
An AbstractGridLines subclass, instantiated via GridLines, or ControlSpec: -grid method, or |
Self.
Get/set bounds describing the extents of the grid (not including any labels).
b |
A Rect. |
A Rect.
Set the colors of the grid lines for each axis.
colors |
An Array of two colors for the x and y grid lines, respectively. |
Self.
Get/set opacity.
A Float
.
Set the line dash pattern. The value should be a FloatArray of values that specify the lengths of the alternating dashes and spaces. For example, FloatArray[10.0, 3.0, 5.0, 3.0]
, for dashes of lengths 10.0
and 5.0
pixels, separated by spaces of 3.0
pixels. See Pen: *lineDash.
Self.
A DrawGridX
object that draws the x (horizontal) axis. In general you shouldn't need to set this.
A DrawGridX
.
A DrawGridY
object that draws the y (vertical) axis. In general you shouldn't need to set this.
A DrawGridY
.
Set the approximate number of grid lines ("ticks") for each axis. If set, the number of ticks is fixed and numTicks
takes precedence over -tickSpacing. If nil
, the number of grid lines change with the view size, constrained by the tickSpacing
. Default: nil
.
See Examples below.
x |
Approximate number of grid lines ("ticks") for the x-axis. |
y |
Approximate number of grid lines for the y-axis. |
The resulting number of ticks is approximate because of the underlying algorithm in AbstractGridLines: -niceNum, which tries to find suitable values for the grid lines based on the data range and your requested numTicks
. You can observe the behavior of GridLines:-niceNum
with this snippet:
Set the minimum spacing between grid lines ("ticks") for each axis. The number of grid lines will change with the view size, but won't be spaced less than this tickSpacing
, allowing you to control the density of grid lines. However if -numTicks is not nil
, it takes precedence over tickSpacing
.
See Examples below.
x |
Minimum spacing between grid lines ("ticks") on the x-axis (pixels, default: 64). |
y |
Minimum spacing between grid lines on the y-axis (pixels, default: 64). |
Preview this DrawGrid
object by creating a window with a view showing the DrawGrid
in its current state.
If the DrawGrid
is modified, you can -refresh
the returned UserView
to see its updated state, or simply call -preview
again to update the view (or create the preview again if the Window
was closed). See Examples below.
A UserView which draws this DrawGrid
.
Safely make a copy of this object and its working members.
A new DrawGrid
.
For previewing the look and feel of your GridLines
, you can render your DrawGrid
using the -preview method:
Use DrawGrid
's convenience methods to set the grids' properties, then refresh the view:
Or just call .preview
again and it will refresh the existing view:
Proterties of the individual x- and y-grids can also be accessed and changed separately: