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),
where the number is only displayed on certain tick lines - once for the axis, where it is best readable.

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(); 

example6
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 valueDescription
FilledTick labels will optimally fill the whole axis length.
Multiple1Multiples of 10^n will be prefered for label steps.
Multiple2multiples of 2*10^n will be prefered for label steps
Multiple5multiples of 5*10^n will be prefered for label steps
AutoTry 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.

MemberDescription
Tick Lines
DirectionDo ticks run into or outside the viewing cube?
DisplayWhich ticks are displayed? Near side or both sides? (Default: both)
FarColorColor for far ticks, if visible. (Default: Gray)
NearColorColor for near ticks. (Default: Gray)
TickFractionLength of tick lines, relative to overall viewing cube length. (Default: 1/10th)
Tick Labels
AlignmentCurrent alignment for tick labels. Determined automatically while drawing. (readonly)
FontLabel font. Use this property to set font and size for tick labels.
LabelColorLabel Color. (Default: black)
PaddingPadding between labels in pixels. This value forces additional space between labels and between labels and axis. (Default: 10)
PrecisionMaximum count of digits the label number is rounded to. (Default: 5)
Positioning
ModeDetermine, if the right (i.e. 'nice') numbers for labels are to be found automatically (default), or manually.
RenderingHintGive a hint for optimal label numbers. (Default: Auto)

Valid CSS! Valid XHTML 1.0 Transitional