コード例 #1
0
    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)
コード例 #2
0
    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)