Package stripchart :: Module scaleutils
[show private | hide private]
[frames | no frames]

Module stripchart.scaleutils

Helper functions for scale-type widgets.
Function Summary
Produce a decimal summary of a number.
  tickSize(lblSize, componentSize, scaleRange, msds)
Calculate the tick size for a grade widget.

Variable Summary
str __author__ = 'Jonathan Merritt <j.merritt@pgrad.unimelb....

Function Details


Produce a decimal summary of a number.

A decimal summary of a number consists of its sign (sign), its most significant digit (msd), and its decimal exponent (exp). These components are returned as a tuple in that order: (sign, msd, exp).

It is important to be able to acquire this information about a number in order to create a scale for a plot or graph. The reason is that scales are typically in graduations of some sensible unit value (like 1.0, 2.0, 3.0, instead of 1.1, 2.2, 3.3). Also see the tickSize function below.

Some examples:
>>> decimalSummary(42)
(1, 4, 1)

>>> decimalSummary(-54321)
(-1, 5, 4)

>>> decimalSummary(-0.0072)
(-1, 7, -3)
x - Number for which to produce a summary.
           (type=Real number.)
Returns a tuble of (sign, msd, exp), with all components as integers.

See Also: tickSize

tickSize(lblSize, componentSize, scaleRange, msds=None)

Calculate the tick size for a grade widget.

This is an algorithm to find the tick size for a grade widget, or any other widget that has the same requirements. The basic requirement is that the tick size should have an acceptable most-significant digit, and should comfortably fit a label within the size of the widget. This allows the labels, which occur at increments of the tick size, to fit correctly without overlapping each other, etc.

This function returns the smallest allowable tick size, for which the most significant digit is a member of msds (or of the default set of 1, 2, and 5), and for which the labels of the ticks will not overlap each other when drawn on the component.

For example,
>>> tickSize(10, 100, 100)

>>> tickSize(9, 100, 100)

>>> tickSize(9, 100, 100, [1, 2, 5])

>>> tickSize(9, 100, 100, [])  # 1 is always implicitly allowed

>>> tickSize(10, 100, 100, [1, 3, 5])
lblSize - Size (height or width) of the label. This size will typically be in pixels.
           (type=Real number.)
componentSize - Size (height or width) of the component; typically in pixels.
           (type=Real number.)
scaleRange - Range of the scale, in scale units, not pixels.
           (type=Real number.)
msds - Sequence of most-significant digits which are permissable. If this sequence is omitted then the default digits 1, 2 and 5 are used. The smallest appropriate msd is used. The digit 1 is always an implicit member of this sequence.
           (type=Sequence of integers.)
Tick size of the grade widget, in scale units.

Variable Details


'Jonathan Merritt <>'                    

Generated by Epydoc 2.0 on Sat Oct 25 11:04:43 2003