--- glyph.py.original 2010-02-26 09:30:34.000000000 +0100 +++ glyph.py 2010-08-20 12:14:19.000000000 +0200 @@ -663,7 +663,7 @@ timeRange = self.endTime - self.startTime secondsPerPixel = float(timeRange) / float(self.graphWidth) - self.xScaleFactor = float(self.graphWidth) / float(timeRange) #pixels per second + self.xScaleFactor = self.graphWidth / timeRange #pixels per second potential = [c for c in xAxisConfigs if c['seconds'] <= secondsPerPixel and c.get('maxInterval',timeRange+1) > timeRange] if potential: @@ -696,13 +696,16 @@ self.drawText(label,x,y,align='left',valign='middle') #Inverted for right side Y Axis t = self.xLabelStep * math.ceil( float(self.startTime) / self.xLabelStep ) + t = find_first_time( self.startTime, self.xConf['labelUnit'], self.xConf['labelStep'] ) + while t <= self.startTime: + t = find_next_time( t, self.xConf['labelUnit'], self.xConf['labelStep'] ) #Draw the X-labels while t < self.endTime: - label = strftime(self.xConf['format'], localtime(t + self.utcAdjustment + self.userTimeZoneOffset )) - x = self.area['xmin'] + ((t - self.startTime) * self.xScaleFactor) + label = strftime(self.xConf['format'], localtime( t + self.userTimeZoneOffset )) + x = self.area['xmin'] + int((t - self.startTime) * self.xScaleFactor) y = self.area['ymax'] + self.getExtents()['maxAscent'] self.drawText(label,x,y,align='center',valign='top') - t += self.xLabelStep + t = find_next_time( t, self.xConf['labelUnit'], self.xConf['labelStep'] ) def drawGridLines(self): #Horizontal grid lines @@ -728,24 +731,29 @@ bottom = self.area['ymax'] self.ctx.set_line_width(0.25) #First we do minor lines (major's should paint over them) self.setColor( self.params.get('minorGridLineColor',self.defaultMinorGridLineColor) ) - t = self.xMinorGridStep * math.ceil( float(self.startTime) / self.xMinorGridStep ) + t = find_first_time( self.startTime, self.xConf['minorGridUnit'], self.xConf['minorGridStep'] ) + while t <= self.startTime: + t = find_next_time( t, self.xConf['minorGridUnit'], self.xConf['minorGridStep'] ) while t < self.endTime: - x = self.area['xmin'] + ((t - self.startTime) * self.xScaleFactor) + x = self.area['xmin'] + int((t - self.startTime) * self.xScaleFactor) if x < self.area['xmax']: self.ctx.move_to(x, bottom) self.ctx.line_to(x, top) self.ctx.stroke() - t += self.xMinorGridStep - self.ctx.set_line_width(0.33) #Now for the major grid lines + t = find_next_time( t, self.xConf['minorGridUnit'], self.xConf['minorGridStep'] ) + + self.ctx.set_line_width(0.5) #Now for the major grid lines self.setColor( self.params.get('majorGridLineColor',self.defaultMajorGridLineColor) ) - t = self.xMajorGridStep * math.ceil( float(self.startTime) / self.xMajorGridStep ) + t = find_first_time( self.startTime, self.xConf['majorGridUnit'], self.xConf['majorGridStep'] ) + while t <= self.startTime: + t = find_next_time( t, self.xConf['majorGridUnit'], self.xConf['majorGridStep'] ) while t < self.endTime: - x = self.area['xmin'] + ((t - self.startTime) * self.xScaleFactor) + x = self.area['xmin'] + int((t - self.startTime) * self.xScaleFactor) if x < self.area['xmax']: self.ctx.move_to(x, bottom) self.ctx.line_to(x, top) self.ctx.stroke() - t += self.xMajorGridStep + t = find_next_time( t, self.xConf['majorGridUnit'], self.xConf['majorGridStep'] ) #Draw side borders for our graph area self.ctx.set_line_width(0.5) self.ctx.move_to(self.area['xmax'], bottom) @@ -915,3 +923,55 @@ return v, prefix return v, "" + +def find_first_weekday(): + return 0 + +def find_first_time(start,baseinterval,step): + tm = localtime( start ) + newtm = tm + if baseinterval == SEC: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday,tm.tm_hour,tm.tm_min , (tm.tm_sec - (tm.tm_sec % step)), tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == MIN: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday,tm.tm_hour,tm.tm_min - (tm.tm_min % step), 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == HOUR: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday,tm.tm_hour - (tm.tm_hour % step), 0, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == DAY: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday, 0, 0, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == WEEK: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday - (tm.tm_wday -find_first_weekday()), 0, 0, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == MONTH: + newtm = tm.tm_year,tm.tm_mon - (tm.tm_mon % step), 1, 0, 0, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == YEAR: + newtm = tm.tm_year - (tm.tm_year % step), 1, 1, 0, 0, 0, tm.tm_wday, tm.tm_yday, -1 + + return mktime( newtm ) + +def find_next_time(current,baseinterval,step): + tm = localtime( current ) + done = False + ret = current + while not done: + if baseinterval == SEC: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec + step, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == MIN: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday,tm.tm_hour,tm.tm_min + step, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == HOUR: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday,tm.tm_hour + step, 0, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == DAY: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday + step, 0, 0, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == WEEK: + newtm = tm.tm_year,tm.tm_mon, tm.tm_mday + 7*step, 0, 0, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == MONTH: + newtm = tm.tm_year,tm.tm_mon + step, 1, 0, 0, 0, tm.tm_wday, tm.tm_yday, -1 + elif baseinterval == YEAR: + newtm = tm.tm_year + step, 1, 1, 0, 0, 0, tm.tm_wday, tm.tm_yday, -1 + + try: + ret = mktime( newtm ) + done = True + except (ValueError, OverflowError): + done = False + + return ret +