Example #1
0
 def test_revert_to_default(self):
     scales = [FixedScale(resolution = 1.0),
               FixedScale(resolution = 10.0),
               FixedScale(resolution = 100.0)]
     ticker = ScaleSystem(*scales)
     ticks = ticker.ticks(2.0, 3.0, 10)
     self.check_ticks(ticks, frange(2.0, 3.0, 0.1))
Example #2
0
    def ticks(self, start, end, desired_ticks=None):
        """ Returns the set of "nice" positions on this scale that enclose and
        fall inside the interval (*start*,*end*).

        Implements AbstractScale. The *start* and *end* parameters are
        floating-point seconds since the epoch.
        """

        if self.unit in self.CALENDAR_UNITS:
            return self.cal_ticks(start, end)
        elif self.unit in ("milliseconds", "microseconds"):
            if start == end or (end - start) < self.SECS_PER_UNIT[self.unit]:
                return [start]
            secs_per_unit = self.SECS_PER_UNIT[self.unit]
            start /= secs_per_unit
            end /= secs_per_unit
            if desired_ticks is None:
                min, max, delta = heckbert_interval(start, end, enclose=True)
            else:
                min, max, delta = heckbert_interval(start,
                                                    end,
                                                    desired_ticks,
                                                    enclose=True)
            min *= secs_per_unit
            max *= secs_per_unit
            delta *= secs_per_unit
            return frange(min, max, delta)
        else:
            return trange(start, end, **{self.unit: self.val})
Example #3
0
    def ticks(self, start, end, desired_ticks=None):
        """ Returns the set of "nice" positions on this scale that enclose and
        fall inside the interval (*start*,*end*).

        Implements AbstractScale. The *start* and *end* parameters are
        floating-point seconds since the epoch.
        """

        if self.unit in self.CALENDAR_UNITS:
            return self.cal_ticks(start, end)
        elif self.unit in ("milliseconds", "microseconds"):
            if start == end or (end - start) < self.SECS_PER_UNIT[self.unit]:
                return [start]
            secs_per_unit = self.SECS_PER_UNIT[self.unit]
            start /= secs_per_unit
            end /= secs_per_unit
            if desired_ticks is None:
                min, max, delta = heckbert_interval(start, end, enclose=True)
            else:
                min, max, delta = heckbert_interval(start, end, desired_ticks, enclose=True)
            min *= secs_per_unit
            max *= secs_per_unit
            delta *= secs_per_unit
            return frange(min, max, delta)
        else:
            return trange(start, end, **{self.unit: self.val})
Example #4
0
 def test_revert_to_default(self):
     scales = [FixedScale(resolution = 1.0),
               FixedScale(resolution = 10.0),
               FixedScale(resolution = 100.0)]
     ticker = ScaleSystem(*scales)
     ticks = ticker.ticks(2.0, 3.0, 10)
     self.check_ticks(ticks, frange(2.0, 3.0, 0.1))
Example #5
0
 def test_fixed_scales(self):
     scales = [FixedScale(resolution = 1.0),
               FixedScale(resolution = 10.0),
               FixedScale(resolution = 100.0)]
     ticker = ScaleSystem(default_scale=None, *scales)
     self.check_ticks(ticker.ticks(5, 35, 3), (10.0, 20.0, 30.0))
     self.check_ticks(ticker.ticks(5, 35, 20), frange(5.0, 35.0, 1.0))
     self.check_ticks(ticker.ticks(5, 614, 10), (100, 200, 300, 400, 500, 600))
Example #6
0
 def test_fixed_scales(self):
     scales = [FixedScale(resolution = 1.0),
               FixedScale(resolution = 10.0),
               FixedScale(resolution = 100.0)]
     ticker = ScaleSystem(default_scale=None, *scales)
     self.check_ticks(ticker.ticks(5, 35, 3), (10.0, 20.0, 30.0))
     self.check_ticks(ticker.ticks(5, 35, 20), frange(5.0, 35.0, 1.0))
     self.check_ticks(ticker.ticks(5, 614, 10), (100, 200, 300, 400, 500, 600))
Example #7
0
 def test_defaults(self):
     ticker = ScaleSystem()
     ticks = ticker.ticks(5, 30, 10)
     self.check_ticks(ticks, frange(5.0, 30.0, 2.5))
Example #8
0
 def test_pow10(self):
     scale = Pow10Scale()
     ticks = scale.ticks(5, 15, 8)
     self.check_ticks(ticks, frange(5, 15, 1.0))
     ticks = scale.ticks(5, 105, 8)
     self.check_ticks(ticks, frange(10, 100, 10.0))
Example #9
0
 def test_defaults(self):
     ticker = ScaleSystem()
     ticks = ticker.ticks(5, 30, 10)
     self.check_ticks(ticks, frange(5.0, 30.0, 2.5))
Example #10
0
 def test_pow10(self):
     scale = Pow10Scale()
     ticks = scale.ticks(5,15,8)
     self.check_ticks(ticks, frange(5, 15, 1.0))
     ticks = scale.ticks(5,105,8)
     self.check_ticks(ticks, frange(10, 100, 10.0))