Ejemplo n.º 1
0
 def draw(self):
     length = 5
     # Draw the horizontal ruler.
     for i in range(1, int(round(self.height / self._step))):
         v, mark = i * self._step, i % self.interval == 0
         line(0, v, mark and length * 3 or length, v, stroke=self.color, strokewidth=0.5)
         if mark:
             self._markers[v].draw(length * 3 - self._markers[v].metrics[0], v + 2)
     # Draw the vertical ruler.
     for i in range(1, int(round(self.width / self._step))):
         v, mark = i * self._step, i % self.interval == 0
         line(v, 0, v, mark and length * 3 or length, stroke=self.color, strokewidth=0.5)
         if mark:
             self._markers[v].draw(v + 2, length * 3 - self._markers[v].fontsize)
     # Draw the crosshair.
     if self.crosshair:
         line(
             0,
             self.canvas.mouse.y,
             self.width,
             self.canvas.mouse.y,
             stroke=self.color,
             strokewidth=0.5,
             strokestyle=DOTTED,
         )
         line(
             self.canvas.mouse.x,
             0,
             self.canvas.mouse.x,
             self.height,
             stroke=self.color,
             strokewidth=0.5,
             strokestyle=DOTTED,
         )
Ejemplo n.º 2
0
 def draw(self):
     length = 5
     # Draw the horizontal ruler.
     for i in range(1, int(round(self.height / self._step))):
         v, mark = i*self._step, i%self.interval==0
         line(0, v, mark and length*3 or length, v, 
                  stroke = self._fill, 
             strokewidth = 0.5)
         if mark:
             self._markers[v].draw(length*3-self._markers[v].metrics[0], v+2)
     # Draw the vertical ruler.
     for i in range(1, int(round(self.width / self._step))):
         v, mark = i*self._step, i%self.interval==0
         line(v, 0, v, mark and length*3 or length, 
                  stroke = self._fill, 
             strokewidth = 0.5)
         if mark:
             self._markers[v].draw(v+2, length*3-self._markers[v].fontsize)
     # Draw the crosshair.
     if self.crosshair:
         line(0, self.canvas.mouse.y, self.width, self.canvas.mouse.y, 
                  stroke = self._fill, 
             strokewidth = 0.5, 
             strokestyle = DOTTED)
         line(self.canvas.mouse.x, 0, self.canvas.mouse.x, self.height, 
                  stroke = self._fill, 
             strokewidth = 0.5, 
             strokestyle = DOTTED)
Ejemplo n.º 3
0
def draw(canvas):
   
    xc=canvas.width/2
    yc=canvas.height/2
    nofill()
    stroke(0.0, 0.25) # 75% transparent black.
    strokewidth(5)
    autoclosepath(close=False)
    triangle(xc, yc, xc+50, yc+100, xc+100, yc)
    line(xc, yc, xc+5, yc+234)
    
    global n,w, points
    
    strokewidth(w)
    line(points[n-1].x, points[n-1].y,points[n].x, points[n].y)

    if n<49:
        # print n, w, points[n].x, points[n].y
        w -= 0.2
        n += 1
    else:canvas.stop()
Ejemplo n.º 4
0
def draw(canvas):

    xc = canvas.width / 2
    yc = canvas.height / 2
    nofill()
    stroke(0.0, 0.25)  # 75% transparent black.
    strokewidth(5)
    autoclosepath(close=False)
    triangle(xc, yc, xc + 50, yc + 100, xc + 100, yc)
    line(xc, yc, xc + 5, yc + 234)

    global n, w, points

    strokewidth(w)
    line(points[n - 1].x, points[n - 1].y, points[n].x, points[n].y)

    if n < 49:
        # print n, w, points[n].x, points[n].y
        w -= 0.2
        n += 1
    else:
        canvas.stop()
def draw(canvas):
    collect_sample()
    
    canvas.clear()

    first = samples[0][0]
    last = samples[-1][0]
    delta = last - first
    if delta == 0.0:
        return
    
    perpixel = HEIGHT / delta

    samps = []
    for (tm,rb) in samples:
        samps.append(rb / tm)

    max = samps[0]
    average = samps[0]
    for rb in samps[1:101]:
        #average = (average + rb) / 2.0
        average += rb
    for rb in samps:
        if rb > max:
            max = rb
    average = average / float(len(samps))
            
    for (tm,mn,mx,avg,stddev) in slowsamples:
        if avg > max:
            max = avg

    if max == 0:
        return

    xrng = float(max) / WIDTH
    nb.stroke(.5,0,0)
    nb.fill(1,0,0)
    y = HEIGHT
    samps.reverse()
    for rb in samps[:FIRST]:
        if rb != 0:
            x = (float(rb)/max) * WIDTH
            if x > WIDTH:
                print "ERR",x
            nb.stroke(1,0,0)
            nb.line(0, y, x, y)
            nb.stroke(0,0,0)
            nb.line(x-1, y, x, y)
        y = y - 1
#    path.lineto(0,y)
#    path.lineto(0,HEIGHT)
#    path.closepath()
#    nb.drawpath(path)

    nb.stroke(0,0,1)
    if False:
        x0 = 0
        for i in range(10,FIRST,10):
            if i >= len(samps):
                break
            avg = 0
            for x in range(i-10,i):
                avg = avg + samps[i]
            avg = avg / 10.0
            x1 = (avg/max) * WIDTH
            nb.line(x0, HEIGHT-i-10, x1, HEIGHT-i)
            x0 = x1
            
    else:
        x1 = (average/max) * WIDTH
        nb.line(x1, HEIGHT, x1, HEIGHT-100)
    

    i = 0
    rbtot = 0
    lasttm = tm

    if False:
        ## this plots a red bar +- one std-deviation with a black bar
        ## for the average
        y = HEIGHT - FIRST - len(slowsamples)
        for (tm,mn,mx,avg,stddev) in slowsamples:
            pxdev = (stddev/max) * WIDTH
            x0 = (float(avg)/max) * WIDTH
            nb.stroke(1,0,0)
            nb.line(x0-pxdev, y, x0+pxdev, y)
            nb.stroke(0,0,0)
            nb.line(x0-1,y,x0+1,y)
            y = y + 1

    elif False:
        ## this plots a red bar between min and max and a black dot for average
        ## (commented code does that, current does line from avg->max)
        y = HEIGHT - FIRST - len(slowsamples)
        for (tm,mn,mx,avg,stddev) in slowsamples:
            x0 = (float(mn)/max) * WIDTH
            x1 = (float(mx)/max) * WIDTH
            x2 = (float(avg)/max) * WIDTH
            nb.stroke(1,0,0)
            nb.line(x2, y, x1, y)
            #nb.stroke(0,0,0)
            #nb.line(x2-1,y,x2+1,y)
            y = y + 1

    elif True:
        ## this just plots the average
        y = HEIGHT - FIRST - len(slowsamples)
        for (tm,mn,mx,avg,stddev) in slowsamples:
            x = (float(avg)/max) * WIDTH
            nb.stroke(1,0,0)
            nb.line(0, y, x, y)
#            nb.stroke(0,0,0)
#            nb.line(x-1,y,x,y)
            y = y + 1

    nb.fontsize(10)
    
    for i in range(0,FIRST+1,50):
        nb.stroke(0,0,0,0.5)
        nb.line(0, HEIGHT-i, WIDTH-22, HEIGHT-i)
        t = nb.Text("%ds"%(i/10), WIDTH-20, HEIGHT-i-4)
        nb.stroke(0,1,0)
        t.draw()
        
    for i in range(FIRST+50,HEIGHT,50):
        nb.stroke(0,0,0,0.5)
        nb.line(0, HEIGHT-i, WIDTH-32, HEIGHT-i)
        t = nb.Text("%ds"%((FIRST/10)+((i-FIRST))), WIDTH-30, HEIGHT-i-4)
        nb.stroke(0,0,1)
        t.draw()

#    nb.fill(0,0,0,.8)
#    t = nb.Text("max: " + str(max), 0, HEIGHT-50)
#    t.fontweight = nb.BOLD
#    t.draw()

    nb.fill(0,0,1,.8)
    x1 = (average/max) * WIDTH
    average = int(average)
    avgtext = str(average/1024) + " KiB/s"
    t = nb.Text(avgtext, x1+2, HEIGHT-12)
    t.fontweight = nb.BOLD
    t.draw()