📄 np_plot.py
字号:
for s in self.sets: if s.callback == None or s.hidden[-1]: continue i1, i2 = s.curr_indices[-1] for d in s.data[i1:i2+1]: if ymin <= d[1] <= ymax and xmin <= d[0] <= xmax: try: for p in d[3]: if not tdict.has_key(p): tdict[p] = None except IndexError: # this data doesn't have a tags list pass tlist = tdict.keys() if len(tlist): s.callback(tlist) ############################################################################## def mouse_3_down(self, event): self.mouse_3_down_all(event, 0) ############################################################################## def mouse_3_shift_down(self, event): self.mouse_3_down_all(event, 1) ############################################################################## def mouse_3_down_all(self, event, shift): canv = event.widget xpos = canv.canvasx(event.x) ypos = canv.canvasy(event.y) xpos = MAX(xpos, self.bounds[0]) xpos = MIN(xpos, self.bounds[1]) ypos = MIN(ypos, self.bounds[3]) ypos = MAX(ypos, self.bounds[2]) TEXT = canv.create_text #print 'xy', xpos, ypos col = 'white' if shift: gt = canv.gettags co = canv.coords nr = canv.find_enclosed(xpos-10, ypos-10, xpos+10, ypos+10) nrc = [n for n in nr if 'ctr' in gt(n)] if nrc: clo = nrc[0] coords = co(clo) dst = hypot(coords[0]-xpos, coords[1]-ypos) for n in nrc[1:]: coords = co(n) ndst = hypot(coords[0]-xpos, coords[1]-ypos) if ndst < dst: dst = ndst clo = n coords = canv.coords(clo) xpos, ypos = coords[0], coords[1] #print 'nr xy', clo, xpos, ypos col = canv.itemcget(clo, 'fill')## else:## xpos = None## self.postxt = TEXT(0, 0, text='') if xpos: x = ((xpos-self.xorg)/self.xscalef) + self.xmin y = ((self.yorg-ypos)/self.yscalef) + self.ymin self.postxt = TEXT(xpos+10, ypos, text='%f %f' % (x, y), anchor=W, fill=col, font=("helvetica", 10, "bold") ) ############################################################################## def mouse_3_drag(self, event): self.mouse_3_drag_all(event, 0) ############################################################################## def mouse_3_shift_drag(self, event): self.mouse_3_drag_all(event, 1) ############################################################################## def mouse_3_drag_all(self, event, shift): canv = event.widget xpos = canv.canvasx(event.x) ypos = canv.canvasy(event.y) xpos = MAX(xpos, self.bounds[0]) xpos = MIN(xpos, self.bounds[1]) ypos = MIN(ypos, self.bounds[3]) ypos = MAX(ypos, self.bounds[2]) bb = canv.bbox(self.postxt) xwi = bb[2] - bb[0] canv.delete(self.postxt) TEXT = canv.create_text col = 'white' if shift: gt = canv.gettags co = canv.coords nr = canv.find_enclosed(xpos-10, ypos-10, xpos+10, ypos+10) nrc = [n for n in nr if 'ctr' in gt(n)] if nrc: clo = nrc[0] coords = co(clo) dst = hypot(coords[0]-xpos, coords[1]-ypos) for n in nrc[1:]: coords = co(n) ndst = hypot(coords[0]-xpos, coords[1]-ypos) if ndst < dst: dst = ndst clo = n coords = canv.coords(clo) xpos, ypos = coords[0], coords[1] #print 'nr xy', clo, xpos, ypos col = canv.itemcget(clo, 'fill') ## else:## xpos = None## self.postxt = TEXT(0, 0, text='') if xpos: x = ((xpos-self.xorg)/self.xscalef) + self.xmin y = ((self.yorg-ypos)/self.yscalef) + self.ymin off = 10 if xpos + xwi - off < self.bounds[1]: anch = W else: off = -off anch = E self.postxt = TEXT(xpos+off, ypos, text='%f %f' % (x, y), anchor=anch, fill=col, font=("helvetica", 10, "bold") ) ############################################################################## def mouse_3_up(self, event): canv = event.widget canv.delete(self.postxt) ############################################################################## def mouse_3_control_down(self, event): canv = event.widget xpos = canv.canvasx(event.x) ypos = canv.canvasy(event.y) xpos = MAX(xpos, self.bounds[0]) xpos = MIN(xpos, self.bounds[1]) ypos = MIN(ypos, self.bounds[3]) ypos = MAX(ypos, self.bounds[2]) self.startx=xpos self.starty=ypos self.scaleline = None self.scaletxt = None self.rscaling = 1 ############################################################################## def mouse_3_control_drag(self, event): canv = event.widget xpos = canv.canvasx(event.x) ypos = canv.canvasy(event.y) xpos = MAX(xpos, self.bounds[0]) xpos = MIN(xpos, self.bounds[1]) ypos = MIN(ypos, self.bounds[3]) ypos = MAX(ypos, self.bounds[2]) if self.startx != xpos or self.starty != ypos: if self.scaletxt: bb = canv.bbox(self.scaletxt) xwi = bb[2] - bb[0] else: xwi = 120 canv.delete(self.scaleline) canv.delete(self.scaletxt) xdelta = (xpos-self.startx)/self.xscalef ydelta = (self.starty-ypos)/self.yscalef TEXT = canv.create_text LINE = canv.create_line off = 10 if xpos + xwi - off < self.bounds[1]: anch = W else: off = -off anch = E self.scaletxt = TEXT(xpos+off, ypos, text='%+f %+f' % (xdelta, ydelta), anchor=anch, fill='white', font=("helvetica", 10, "bold")) self.scaleline = LINE(self.startx, self.starty, xpos, ypos, width=1, fill='white') ############################################################################## def mouse_3_control_up(self, event): canv = event.widget if self.rscaling: canv.delete(self.scaletxt) canv.delete(self.scaleline) self.rscaling = 0 ############################################################################## def find_indices(self, event, sx, sy, append_indices): canv = event.widget x = canv.canvasx(event.x) y = canv.canvasy(event.y) x = MAX(x, self.bounds[0]) x = MIN(x, self.bounds[1]) y = MIN(y, self.bounds[3]) y = MAX(y, self.bounds[2]) xmin = MIN(x, sx)-self.xorg xmax = MAX(x, sx)-self.xorg xminval = xmin/self.xscalef + self.xmin xmaxval = xmax/self.xscalef + self.xmin xrange = xmax - xmin if xrange == 0: return (newi1, newi2) xrangeval = xmaxval - xminval xscalef = float(self.xwi/xrangeval) ymin = self.yorg - MAX(y, sy) ymax = self.yorg - MIN(y, sy) yminval = ymin/self.yscalef + self.ymin ymaxval = ymax/self.yscalef + self.ymin yrange = ymax - ymin if yrange == 0: return (newi1, newi2) yrangeval = ymaxval - yminval yscalef = float(self.yht/yrangeval) #print xminval #i = 0 for s in self.sets: i1, i2 = s.curr_indices[-1] if i1 == None: # this set is zoomed out of range if append_indices: s.curr_indices.append((i1, i2)) s.hidden.append(s.hidden[-1]) continue try: newi1 = find_point(xminval, s.data, i1, i2, P_BEFORE) except NotInRange: #print 'for newi1 value %.3f not in range %.3f-%.3f' % (xminval, s.data[i1][0], s.data[i2][0]) if xminval < s.data[0][0] < xmaxval: #print '%.3f < %.3f < %.3f' % (xminval, s.data[0][0], xmaxval) newi1 = 0 else: #print 'not %.3f < %.3f < %.3f' % (xminval, s.data[0][0], xmaxval) newi1 = None try: newi2 = find_point(xmaxval, s.data, i1, i2, P_AFTER) except NotInRange: #print 'for newi2 value %.3f not in range %.3f-%.3f' % (xmaxval, s.data[i1][0], s.data[i2][0]) if xminval < s.data[-1][0] < xmaxval: #print '%.3f < %.3f < %.3f' % (xminval, s.data[-1][0], xmaxval) newi2 = s.len - 1 else: #print 'not %.3f < %.3f < %.3f' % (xminval, s.data[-1][0], xmaxval) newi2 = None #print 'newi1=%s newi2=%s' % (repr(newi1), repr(newi2)) if newi1 == None: newi2 = None if newi2 == None: newi1 = None if append_indices: s.hidden.append(s.hidden[-1]) s.curr_indices.append((newi1, newi2)) if newi1 == None: try: #s.ops.configure(fg='red') s.ops.top.configure(state=DISABLED) s.ops.hide.configure(state=DISABLED) s.ops.col.configure(state=DISABLED, background='grey') except AttributeError: # only one set pass scaledata = (xmaxval, xminval, ymaxval, yminval, xscalef, yscalef, xrangeval, yrangeval, self.xfloats, self.yfloats)## print 'i1=%d->%d i2=%d->%d' % (self.i1, newi1, self.i2, newi2)## print 'xminval=%.3f xmaxval=%.3f' % (self.data[newi1][0], ## self.data[newi2][0])## print 'xmin=%.3f xmax=%.3f xrange=%.3f' % (xminval, xmaxval, xrangeval) return scaledata ############################################################################## def setup(self): self.order = [] # record of drawing order if not self.sets: return for s in self.sets: s.newcol = s.col #print self.data, self.i1, self.i2 if self.scaledata == None: # first canvas - scale self.scale() else: self.use_scaledata() self.draw_axes() self.draw() self.draw_labels()############################################################################## def draw_title(self, t): TEXT = self.canv.create_text x = self.xorg + self.xwi/2 y = self.yorg + C_BOTMARGIN/2 + 5 # replace DIV t = t.replace('DIV', '/') if self.plot.sspec: t += '-sm.%s' % (self.plot.sspec) TEXT(x, y, text=t, fill=self.fgcol, font=TITLEFONT, anchor=CENTER, tags='la')############################################################################## def basename(self, path): # allow escape for '/' in plot label (eg. interrupts //sec.) i = string.find(path, '//') if i == -1: return os.path.basename(path) else: return os.path.basename(path[:i]) + path[i+1:]############################################################################## def draw_labels(self): c = self.canv TEXT = c.create_text LINE = c.create_line width = self.plotlinewidth x = self.xorg+self.xwi y = C_TITLEMARGIN t = self.plot.title tl = len(t) if tl: self.draw_title(t) ts = self.sets[self.plot.is_top[-1]] p = os.path.split(ts.path)[1] if tl == 0: self.draw_title(p) i = 0 for s in self.sets: if not s.hidden[-1]: #print s.path p = self.basename(s.path) #p = s.path if not len(p): p = '%d' % (i) if len(self.sets) > 1 and self.plot.is_top[-1] == s.indx: p = '> ' + p # add any smoothing suffix p += s.opath # replace DIV p = p.replace('DIV', '/') col = s.col if col == None: col = self.fgcol tt = TEXT(x-10, y, text=p, fill=col, font=TITLEFONT, anchor=NE, tags='la') bb = c.bbox(tt) y = (bb[1]+bb[3])/2 LINE(x-1,y,x+1,y,fill=col, tags='la', width=width) LINE(x,y-1,x,y+1,fill=col, tags='la', width=width) y = bb[3] if self.mode & (MODE_PDF| MODE_HIST): try: inf = '\n%d Samples Min = %.3f Max = %.3f Range = %.3f\nMean = %.3f sd = %.3f, V = %.3f' % (s.tslen, s.min, s.max, s.range, s.mean, s.sd, s.variance) tt = TEXT(x-10, y, text=inf, fill=col, font=LABELFONT, anchor=NE, tags='la') bb = c.bbox(tt) y = bb[3] except AttributeError: # may be no statsdata pass i += 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -