Package de.erichseifert.gral.plots.axes


package de.erichseifert.gral.plots.axes

Axes, and the projection between data values and pixels.

The responsibility is split in two. An Axis is a plain value object: it holds the minimum and maximum of the displayed range, whether that range is scaled automatically, and a list of listeners. It knows nothing about drawing. An AxisRenderer owns everything else — the shape the axis follows, the tick marks and their labels, and, most importantly, the coordinate transform:

AxisRenderer rendererX = plot.getAxisRenderer(XYPlot.AXIS_X);
Axis axisX = plot.getAxis(XYPlot.AXIS_X);

// Where does the data value 4.2 end up on screen?
double pixels = rendererX.worldToView(axisX, 4.2, false);

// And the other way round, e.g. to turn a mouse position into a value.
Number value = rendererX.viewToWorld(axisX, pixels, false);

The extrapolate flag decides what happens outside the axis range: with false the result is clamped to the ends of the axis, with true the transform is continued beyond them.

Because the scale lives in the renderer, changing from a linear to a logarithmic axis is a matter of substituting one object:

plot.setAxisRenderer(XYPlot.AXIS_X, new LogarithmicRenderer2D());

AbstractAxisRenderer2D implements the two-dimensional case and is the class to extend for a custom scale; the two shipped subclasses are LinearRenderer2D and LogarithmicRenderer2D. Ticks are produced as Tick objects and come in three flavors (major, minor and custom); custom ticks are supplied as a map from value to label text.