- All Implemented Interfaces:
Graph.Graphic
- Enclosing class:
- Graphs
- Axis lines are vertical and horizontal lines that go through the point (0.0, 0.0) in graph coordinate space.
- Coarse-grid lines are lines spaced by a specified spacing, which is the same in the X and Y directions.
- Fine-grid lines are lines at locations that subdivide the coarse grid so that two adjacent and parallel course-grid lines will be separated by (N-1) fine-grid lines, where N is the subspacing divisor. When N is 1, a fine grid is not shown.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Color
The default color for the axes passing through (0.0, 0.0)static final String
The default color for the axes passing through (0.0, 0.0) as a CSS specification.static final Color
The default color for the coarse-grained grid.static final String
The default color for the course-grained grid as a CSS specification.static final double
The default stroke width for a Cartesian grid.static final Color
The default color for the fine-grained grid.static final String
The default color for the fine-grained grid as a CSS specification. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTo
(Graph g, Graphics2D g2d, Graphics2D g2dGCS) Add this object to a graph.Get the color for the axis.double
Get the grid spacing.Get the color for the coarse-grid lines.double
Get the width of the stroke used to draw grid lines.int
Get the grid subspacing divisor.Get the color for the fine-grid lines.void
Set the colors for grid lines.void
setSpacing
(double spacing) Set the grid spacing.void
setStrokeWidth
(double strokeWidth) Set the width of the stroke used to draw grid lines.void
setSubspacing
(int subspacing) Set the grid subspacing divisor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.graphs.Graph.Graphic
boundingBox
-
Field Details
-
SPACING_COLOR_CSS
The default color for the course-grained grid as a CSS specification.- See Also:
-
SUBSPACING_COLOR_CSS
The default color for the fine-grained grid as a CSS specification.- See Also:
-
AXIS_COLOR_CSS
The default color for the axes passing through (0.0, 0.0) as a CSS specification.- See Also:
-
SPACING_COLOR
The default color for the coarse-grained grid. -
SUBSPACING_COLOR
The default color for the fine-grained grid. -
AXIS_COLOR
The default color for the axes passing through (0.0, 0.0) -
STROKE_WIDTH
public static final double STROKE_WIDTHThe default stroke width for a Cartesian grid.- See Also:
-
-
Constructor Details
-
CartesianGrid
public CartesianGrid()Constructor. -
CartesianGrid
public CartesianGrid(double spacing, int subspacing) Constructor.- Parameters:
spacing
- the grid spacing in GCS (Graph Coordinate Space) units; 0.0 for a defaultsubspacing
- the subspacing divisor
-
-
Method Details
-
getSpacing
public double getSpacing()Get the grid spacing. This defines the spacing for course-grid lines. A value of 0.0 indicates that a default value will be used. The default assumes that roughly 10 increments should appear before the lower and upper values defined for the graph in either the X or Y direction, whichever is shortest.- Returns:
- the grid spacing in GCS (Graph Coordinate Space) units
-
getSubspacing
public int getSubspacing()Get the grid subspacing divisor.- Returns:
- the grid subspacing divisor
-
setSpacing
public void setSpacing(double spacing) Set the grid spacing.- Parameters:
spacing
- the grid spacing in GCS (Graph Coordinate Space) units; 0.0 or a negative value for a default
-
setSubspacing
public void setSubspacing(int subspacing) Set the grid subspacing divisor. The value determines how a coarse grid is partitioned into a fine grid. Each box in the coarse grid is partitioned intosubspacing
boxes along each axis. For example,- If subspacing is 1, coarse-grid boxes are not partitioned.
- If subspacing is 2, coarse-grid boxes are halved in each direction, creating 4 fine-grid boxes per coarse-grid box.
- If subspacing is 5, coarse-grid boxes are split into fifths with a total of 25 boxes per coarse-grid box.
- Parameters:
subspacing
- the subspacing divisor; 0 or a negative value will be replaced with 1
-
getSpacingColor
Get the color for the coarse-grid lines.- Returns:
- the coarse-grid line color
-
getSubspacingColor
Get the color for the fine-grid lines.- Returns:
- the fine-grid line color
-
getAxisColor
Get the color for the axis. A point is on the axis if in graph coordinate space either x = 0 or y = 0. The width of a line representing an axis is the same as for other lines in the grid.- Returns:
- the axis-line color
-
setColors
Set the colors for grid lines. When a point is drawn, the axis color is used if the point is on an axis, otherwise the spacing color is drawn if the point is on the coarse grid. If the point is not on the coarse grid (which includes the axes), and is on the fine grid, the subspacing color is used. If the axis color is the same as the spacing color, the axis will not be visually discernible.- Parameters:
axisColor
- the color for the axis; null for a defaultspacingColor
- the color for the coarse grid; null for a defaultsubspacingColor
- the color for the fine grid; null for a default
-
getStrokeWidth
public double getStrokeWidth()Get the width of the stroke used to draw grid lines.- Returns:
- the stroke width
-
setStrokeWidth
public void setStrokeWidth(double strokeWidth) Set the width of the stroke used to draw grid lines.- Parameters:
strokeWidth
- the stroke width; 0.0 or negative for the default
-
addTo
Description copied from interface:Graph.Graphic
Add this object to a graph. The drawing operation is assumed to be a complex one that might involve fills, etc.Any modifications to g2d or g2dGCS made by an implementation of this method should be undone before this method returns. For classes provided by the org.bzdev.anim2d package, such modifications must be undone before this method returns.
Two graphics contexts are provided as arguments. g2d will typically be used as the first argument to the graph's draw or fill methods. In this case, the shape of an object is described in graph coordinate space but the widths of strokes drawn by fill operations, gradient paint, etc., have user-space units. The result is that line widths as they appear in an image are not sensitive to the mapping from graph coordinate space to user space. One should use the draw and fill methods specified by
Graph
, using g2d as their first argument. By contrast, if a line width, etc., should be in graph-coordinate space units, one can use the g2dGCS argument directly. This will rarely be done when plotting a graph but is useful in animations.- Specified by:
addTo
in interfaceGraph.Graphic
- Parameters:
g
- the graph on which this object should be drawng2d
- the user-space Graphics2D to use to draw the Graphicg2dGCS
- the graph-coordinate space Graphics2D to use to draw the Graphic
-