Exemple #1
0
    def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize):
        ''' Reimplements qwt.QwtLinearScaleEngine.divideScale

        :return: (qwt.QwtScaleDiv) a scale division whose ticks are aligned with
                 the natural delta time units '''
        interval = qwt.QwtInterval(x1, x2).normalized()
        if interval.width() <= 0:
            return qwt.QwtScaleDiv()
        d_range = interval.width()
        if d_range < 2:  # 2s
            return qwt.QwtLinearScaleEngine.divideScale(
                self, x1, x2, maxMajSteps, maxMinSteps, stepSize)
        elif d_range < 20:  # 20 s
            s = 1
        elif d_range < 120:  # =60s*2 = 2 minutes
            s = 10
        elif d_range < 1200:  # 60s*20 =20 minutes
            s = 60
        elif d_range < 7200:  # 3600s*2 = 2 hours
            s = 600
        elif d_range < 172800:  # 3600s24*2 = 2 days
            s = 3600
        else:
            s = 86400  # 1 day
        # calculate a step size that respects the base step (s) and also
        # enforces the maxMajSteps
        stepSize = s * int(numpy.ceil(float(d_range // s) / maxMajSteps))
        return qwt.QwtLinearScaleEngine.divideScale(self, x1, x2, maxMajSteps,
                                                    maxMinSteps, stepSize)
Exemple #2
0
 def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize=0.0):
     div = qwt.QwtScaleDiv(x1, x2, self._positions, [], [])
     div.setTicks(qwt.QwtScaleDiv.MajorTick, self._positions)
     return div
Exemple #3
0
    def divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize):
        ''' Reimplements qwt.QwtLinearScaleEngine.divideScale

        **Important**: The stepSize parameter is **ignored**.

        :return: (qwt.QwtScaleDiv) a scale division whose ticks are aligned with
                 the natural time units '''

        # if stepSize != 0:
        #    scaleDiv = qwt.QwtLinearScaleEngine.divideScale(self, x1, x2, maxMajSteps, maxMinSteps, stepSize)
        #    scaleDiv.datetimeLabelFormat = "%Y/%m/%d %H:%M%S.%f"
        #    return scaleDiv

        interval = qwt.QwtInterval(x1, x2).normalized()
        if interval.width() <= 0:
            return qwt.QwtScaleDiv()

        dt1 = datetime.fromtimestamp(interval.minValue())
        dt2 = datetime.fromtimestamp(interval.maxValue())

        if dt1.year < 1900 or dt2.year > 9999:  # limits in time.mktime and datetime
            return qwt.QwtScaleDiv()

        majticks = []
        medticks = []
        minticks = []

        dx = interval.width()

        # = 3600s*24*(365+366) = 2 years (counting a leap year)
        if dx > 63072001:
            format = "%Y"
            for y in range(dt1.year + 1, dt2.year):
                dt = datetime(year=y, month=1, day=1)
                majticks.append(mktime(dt.timetuple()))

        elif dx > 5270400:  # = 3600s*24*61 = 61 days
            format = "%Y %b"
            d = timedelta(days=31)
            dt = dt1.replace(day=1, hour=0, minute=0, second=0,
                             microsecond=0) + d
            while (dt < dt2):
                # make sure that we are on day 1 (even if always sum 31 days)
                dt = dt.replace(day=1)
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 172800:  # 3600s24*2 = 2 days
            format = "%b/%d"
            d = timedelta(days=1)
            dt = dt1.replace(hour=0, minute=0, second=0, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 7200:  # 3600s*2 = 2hours
            format = "%b/%d-%Hh"
            d = timedelta(hours=1)
            dt = dt1.replace(minute=0, second=0, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 1200:  # 60s*20 =20 minutes
            format = "%H:%M"
            d = timedelta(minutes=10)
            dt = dt1.replace(
                minute=(dt1.minute // 10) * 10, second=0, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 120:  # =60s*2 = 2 minutes
            format = "%H:%M"
            d = timedelta(minutes=1)
            dt = dt1.replace(second=0, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 20:  # 20 s
            format = "%H:%M:%S"
            d = timedelta(seconds=10)
            dt = dt1.replace(second=(dt1.second // 10) * 10, microsecond=0) + d
            while (dt < dt2):
                majticks.append(mktime(dt.timetuple()))
                dt += d

        elif dx > 2:  # 2s
            format = "%H:%M:%S"
            majticks = list(range(int(x1) + 1, int(x2)))

        else:  # less than 2s (show microseconds)
            scaleDiv = qwt.QwtLinearScaleEngine.divideScale(
                self, x1, x2, maxMajSteps, maxMinSteps, stepSize)
            self.scaleDraw().setDatetimeLabelFormat("%S.%f")
            return scaleDiv

        # make sure to comply with maxMajTicks
        L = len(majticks)
        if L > maxMajSteps:
            majticks = majticks[::int(numpy.ceil(float(L) / maxMajSteps))]

        scaleDiv = qwt.QwtScaleDiv(interval, minticks, medticks, majticks)
        self.scaleDraw().setDatetimeLabelFormat(format)
        if x1 > x2:
            scaleDiv.invert()

        # START DEBUG
        # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        # for tk in  scaleDiv.ticks(scaleDiv.MajorTick):
        #    print datetime.fromtimestamp(tk).isoformat()
        # print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        # END DEBUG

        return scaleDiv