Controlling labeled ticks
Labeled ticks visualize the numeric limits of axes. They are represented by the ILTickCollection class, wich can get accessed via the
LabeledTicks member of each axis:
panel.Axes[0].LabeledTicks
Each tick is composed of
- four small tick lines and
- a corresponding label (number),
Tick lines start at a main axis line and run perpendicular to that line over a
certain length. That length is dynamically adjusted by multiplying the actual display length of the
viewing cube by the ILTickCollection.TickFraction member.
One may also determine, if the tick line run into or out of the cube (Direction)
and which ticks are displayed: near or far ticks (Display). The term 'near' means the side,
where the axis chooses to display the tick labels on. 'Far' is the opposite side (no tick labels shown).
The color of tick lines can be set for 'far' ticks and for 'near' ticks independently.
Tick labels are drawn next to one tick line for each position. The axis automatically determines,
where and how to draw the label, so it will always be readable by the user - no matter, how the cube is
rotated. One can set font, color and padding for the labels. The ILTickCollection.Precision
member specifies, how many digits the true numbers are rounded to at most.
In the following example the efect of Padding is demonstrated. The example contains a form with
an ILPanel and a scroll bar. Use the scroll bar to set the padding in realtime. Increasing the padding
will increase the space between labels and the axis lines, which in turn will cause the whole viewing cube to shrink.
int labPadding = hScrollBar1.Value / 3;
m_panel.Axes[1].LabeledTicks.Padding = labPadding;
// invalidating the panel, causes redraw
m_panel.Invalidate();

Example demonstrating the effect of Padding
Download the complete example as VS2005 solution here.
Positioning of 'nice labels'
Its a nontrivial task to find nice looking labels between the axis limits. ILTickCollection
manages this automatically on default (Mode member). The user may give a hint, which numbers
to prefer. The RenderingHint can be set to one of the following values:
| RenderingHint value | Description |
|---|---|
| Filled | Tick labels will optimally fill the whole axis length. |
| Multiple1 | Multiples of 10^n will be prefered for label steps. |
| Multiple2 | multiples of 2*10^n will be prefered for label steps |
| Multiple5 | multiples of 5*10^n will be prefered for label steps |
| Auto | Try to find the optimal division for tick label steps [default]. This setting is a combination of the other ones. Multiple of 5 are prefered over multiple of 2 and so on. Only, if the resulting labels count differs too much from the number given by the available space, the next setting is tried. |
We provide another example, demonstrating the effect of the RenderingHint property. Use the combo box
at runtime to choose between available settings. The effect is displayed on the Y axis immediately.
private void comboBox1_SelectedValueChanged(object sender, EventArgs e) {
try {
TickLabelRenderingHint hint
= (TickLabelRenderingHint)Enum.Parse(
typeof(TickLabelRenderingHint),comboBox1.Text);
// suggest the rendering method to axis
m_panel.Axes.YAxis.LabeledTicks.RenderingHint = hint;
m_panel.Axes.YAxis.LabeledTicks.LabelColor = Color.Red;
// cause the immediate redraw of the ILPanel
m_panel.Invalidate();
} catch (Exception) {
}
}
Download the complete example as VS2005 solution here.
ILTickCollection summary
The following table lists all important properties for the ILTickCollection class.
| Member | Description |
|---|---|
| Tick Lines | |
Direction | Do ticks run into or outside the viewing cube? |
Display | Which ticks are displayed? Near side or both sides? (Default: both) |
FarColor | Color for far ticks, if visible. (Default: Gray) |
NearColor | Color for near ticks. (Default: Gray) |
TickFraction | Length of tick lines, relative to overall viewing cube length. (Default: 1/10th) |
| Tick Labels | |
Alignment | Current alignment for tick labels. Determined automatically while drawing. (readonly) |
Font | Label font. Use this property to set font and size for tick labels. |
LabelColor | Label Color. (Default: black) |
Padding | Padding between labels in pixels. This value forces additional space between labels and between labels and axis. (Default: 10) |
Precision | Maximum count of digits the label number is rounded to. (Default: 5) |
| Positioning | |
Mode | Determine, if the right (i.e. 'nice') numbers for labels are to be found automatically (default), or manually. |
RenderingHint | Give a hint for optimal label numbers. (Default: Auto) |