Class AxisScalePolicyManualTicks
- java.lang.Object
-
- info.monitorenter.gui.chart.axis.scalepolicy.AxisScalePolicyManualTicks
-
- All Implemented Interfaces:
IAxisScalePolicy
public class AxisScalePolicyManualTicks extends java.lang.Object implements IAxisScalePolicy
Scale policy implementation that ensures the following:- No label will overwrite the following label.
- No two labels will have the same value.
- Every tick will exactly show the value without rounding errors.
- Always the closest next possible tick is chosen regardless whether it is a major tick or a minor tick (subject to change in favor of major ticks)
While this strategy is quite comfortable and prevents visual oddities there are some consequences to it:
- Major ticks are not guaranteed to be shown. This is because a label of a minor tick label may need so much space that the following major tick has to be skipped (subject to change)
- Detailed control is not easy. E.g. if you want to enforce more ticks to
show up you could:
- Set an
LabelFormatterNumberviaIAxis.setFormatter(IAxisLabelFormatter)that formats little to no digits. But this could have both effects: More labels as the labels take less space or less labels as the value range is so little that an increased formatted value is possible only little times within that range. - Choose major and minor ticks via
IAxis.setMinorTickSpacing(double)andIAxis.setMajorTickSpacing(double)
- Set an
- Performance is not the best. This is because the space for a label has to be computed and pixels have to be transformed from and to the value domain.
- Author:
- Achim Westermann
-
-
Constructor Summary
Constructors Constructor Description AxisScalePolicyManualTicks()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected LabeledValuecreateLabeledValue(double value, double majorTickSpacing, IAxis<?> axis)Just a helper to create a labeled value instance.protected java.util.List<LabeledValue>getLabels(IAxis<?> axis)Returns the labels for this axis.java.util.List<LabeledValue>getScaleValues(java.awt.Graphics g2d, IAxis<?> axis)Returns the array of labeled values that will be used by theto paint labels.Chart2DvoidinitPaintIteration(IAxis<?> axis)Performs expensive calculations for various values that are used by many calls throughout a paint iterations.
-
-
-
Method Detail
-
createLabeledValue
protected LabeledValue createLabeledValue(double value, double majorTickSpacing, IAxis<?> axis)
Just a helper to create a labeled value instance.- Parameters:
value- the value use.majorTickSpacing- if value % majorTickSpacing is zero then the resultingwill be judged as a major tick.LabeledValueaxis- needed to re-parse the value into the label string by using the formatter of it.- Returns:
- the value rounded to minor or major ticks.
-
getLabels
protected java.util.List<LabeledValue> getLabels(IAxis<?> axis)
Returns the labels for this axis.- Returns:
- the labels for the axis.
-
getScaleValues
public java.util.List<LabeledValue> getScaleValues(java.awt.Graphics g2d, IAxis<?> axis)
Description copied from interface:IAxisScalePolicyReturns the array of labeled values that will be used by theto paint labels.Chart2D- Specified by:
getScaleValuesin interfaceIAxisScalePolicy- Parameters:
g2d- Provides information about the graphic context (e.g. font metrics).axis- the axis to work for.- Returns:
- the labeled values that will be used by the
to paint labels.Chart2D - See Also:
IAxisScalePolicy.getScaleValues(java.awt.Graphics, info.monitorenter.gui.chart.IAxis)
-
initPaintIteration
public void initPaintIteration(IAxis<?> axis)
Description copied from interface:IAxisScalePolicyPerforms expensive calculations for various values that are used by many calls throughout a paint iterations.These values are constant throughout a paint iteration by the contract that no point is added removed or changed in this period. Because these values are used from many methods it is impossible to calculate them at a "transparent" method that may perform this caching over a paint period without knowledge from outside. The first method called in a paint iteration is called several further times in the iteration. So this is the common hook to invoke before painting a chart.
- Specified by:
initPaintIterationin interfaceIAxisScalePolicy- Parameters:
axis- the axis to read data from.- See Also:
IAxisScalePolicy.initPaintIteration(info.monitorenter.gui.chart.IAxis)
-
-