def drawRect_(self, rect): NSImageView.drawRect_(self, rect) if self.cropRectangle: rect = NSZeroRect rect.size = self.frame().size NSColor.whiteColor().set() NSFrameRect(self.cropRectangle) clip = NSBezierPath.bezierPathWithRect_(rect) clip.setWindingRule_(NSEvenOddWindingRule) clip.appendBezierPathWithRect_(self.cropRectangle) clip.addClip() NSColor.blackColor().colorWithAlphaComponent_(0.6).set() NSBezierPath.bezierPathWithRect_(rect).fill()
def drawRect_(self, rect): """ we raw the background gradient and graph outline then clip the inner rect and draw the bars """ bounds = self.bounds() # get our view bounds insetBounds = NSInsetRect(bounds, 2, 2) # set the inside ortion r = NSBezierPath.bezierPathWithRect_( bounds) # create a new bezier rect self.grad.drawInBezierPath_angle_(r, 90.0) # and draw gradient in it self.borderColor.set() # set border to white NSBezierPath.setDefaultLineWidth_(1.0) # set line width for outline NSBezierPath.strokeRect_(bounds) # draw outline NSBezierPath.clipRect_(insetBounds) # set the clipping path insetBounds.size.height -= 2 # leave room at the top (purely my personal asthetic if self.dataQueue: barRect = NSRect() # init the rect # find out the max value so we can scale the graph maxB = max(max(self.dataQueue), self.minHeigth or 1) # disable anti-aliasing since it looks bad shouldAA = NSGraphicsContext.currentContext().shouldAntialias() NSGraphicsContext.currentContext().setShouldAntialias_(False) # draw each bar barRect.origin.x = insetBounds.size.width - self.lineWidth + 2 for sample in reversed(self.dataQueue): # set drawing color if sample >= self.limit: self.lineColorAboveLimit.set() else: self.lineColor.set() barRect.origin.y = insetBounds.origin.y barRect.size.width = self.lineWidth barRect.size.height = ( (int(sample) * insetBounds.size.height) / maxB) NSBezierPath.fillRect_(barRect) barRect.origin.x = barRect.origin.x - self.lineWidth - self.lineSpacing NSGraphicsContext.currentContext().setShouldAntialias_(shouldAA)
def drawRect_(self, rect): """ we raw the background gradient and graph outline then clip the inner rect and draw the bars """ bounds = self.bounds() # get our view bounds insetBounds = NSInsetRect(bounds, 2, 2) # set the inside ortion r = NSBezierPath.bezierPathWithRect_(bounds) # create a new bezier rect self.grad.drawInBezierPath_angle_(r, 90.0) # and draw gradient in it self.borderColor.set() # set border to white NSBezierPath.setDefaultLineWidth_(1.0) # set line width for outline NSBezierPath.strokeRect_(bounds) # draw outline NSBezierPath.clipRect_(insetBounds) # set the clipping path insetBounds.size.height -= 2 # leave room at the top (purely my personal asthetic if self.dataQueue: barRect = NSRect() # init the rect # find out the max value so we can scale the graph maxB = max(max(self.dataQueue), self.minHeigth or 1) # disable anti-aliasing since it looks bad shouldAA = NSGraphicsContext.currentContext().shouldAntialias() NSGraphicsContext.currentContext().setShouldAntialias_(False) # draw each bar barRect.origin.x = insetBounds.size.width - self.lineWidth + 2 for sample in reversed(self.dataQueue): # set drawing color if sample >= self.limit: self.lineColorAboveLimit.set() else: self.lineColor.set() barRect.origin.y = insetBounds.origin.y barRect.size.width = self.lineWidth barRect.size.height = ((int(sample) * insetBounds.size.height) / maxB) NSBezierPath.fillRect_(barRect) barRect.origin.x = barRect.origin.x - self.lineWidth - self.lineSpacing NSGraphicsContext.currentContext().setShouldAntialias_(shouldAA)