Ejemplo n.º 1
0
    def __init__(self):

        self.orientation = self.ORIENTATION_MIN_MAX
        self.number_format = NumberFormat()
        for attr in ('position', 'tick_label_position', 'crosses', 'auto',
                     'label_align', 'label_offset', 'cross_between'):
            setattr(self, attr, None)
        self.min = 0
        self.max = None
        self.unit = None
Ejemplo n.º 2
0
def test_builtin_format():
    nFormat = NumberFormat()
    nFormat.format_code = '0.00'
    eq_(nFormat.builtin_format_code(2), nFormat._format_code)
Ejemplo n.º 3
0
def test_builtin_format():
    format = NumberFormat()
    format.format_code = '0.00'
    eq_(format.builtin_format_code(2), format._format_code)
Ejemplo n.º 4
0
def test_builtin_format():
    nFormat = NumberFormat()
    nFormat.format_code = '0.00'
    assert nFormat.builtin_format_code(2) == nFormat.format_code
Ejemplo n.º 5
0
def test_builtin_format():
    format = NumberFormat()
    format.format_code = '0.00'
    eq_(format.builtin_format_code(2), format._format_code)
Ejemplo n.º 6
0
class Axis(object):

    POSITION_BOTTOM = 'b'
    POSITION_LEFT = 'l'
    ORIENTATION_MIN_MAX = "minMax"

    position = None
    tick_label_position = None
    crosses = None
    auto = None
    label_align = None
    label_offset = None
    cross_between = None
    orientation = ORIENTATION_MIN_MAX
    number_format = NumberFormat()
    delete_axis = False

    def __init__(self, auto_axis=True):
        self.auto_axis = auto_axis
        self.min = 0
        self.max = 0
        self.unit = None
        self.title = ''

    def _max_min(self):
        """
        Calculate minimum and maximum for the axis adding some padding.
        There are always a maximum of ten units for the length of the axis.
        """
        value = length = self._max - self._min

        sign = value / value
        zoom = less_than_one(value) or 1
        value = value * zoom
        ab = abs(value)
        value = math.ceil(ab * 1.1) * sign

        # calculate tick
        l = math.log10(abs(value))
        exp = int(l)
        mant = l - exp
        unit = math.ceil(math.ceil(10**mant) * 10**(exp - 1))
        # recalculate max
        value = math.ceil(value / unit) * unit
        unit = unit / zoom

        if value / unit > 9:
            # no more that 10 ticks
            unit *= 2
        self.unit = unit
        scale = value / length
        mini = math.floor(self._min * scale) / zoom
        maxi = math.ceil(self._max * scale) / zoom
        return mini, maxi

    @property
    def min(self):
        if self.auto_axis:
            return self._max_min()[0]
        return self._min

    @min.setter
    def min(self, value):
        self._min = value

    @property
    def max(self):
        if self.auto_axis:
            return self._max_min()[1]
        return self._max

    @max.setter
    def max(self, value):
        self._max = value

    @property
    def unit(self):
        if self.auto_axis:
            self._max_min()
        return self._unit

    @unit.setter
    def unit(self, value):
        self._unit = value
Ejemplo n.º 7
0
def test_builtin_format():
    nFormat = NumberFormat()
    nFormat.format_code = '0.00'
    eq_(nFormat.builtin_format_code(2), nFormat._format_code)