Ejemplo n.º 1
0
 def loopPaths(self):
     """
     Returns an array of:
     (loopPen, loopPainterPath, skipPen, skipPainterPath)
     for drawing loops and skips
     """
     if self._loopPaths:
         return self._loopPaths
     self._loopPaths = []
     vh = self.vhelix()
     lpen = self._loopitem.getPen()
     spen = self._skipitem.getPen()
     for strandType in (StrandType.Scaffold, StrandType.Staple):
         top = self.strandIsTop(strandType)
         lp = QPainterPath()
         sp = QPainterPath()
         count = len(vh._loop(strandType))
         if count > 0:
             for index, loopsize in vh._loop(strandType).iteritems(): 
                 ul = self.baseLocation(strandType, index)
                 if loopsize > 0:
                     path = self._loopitem.getLoop(top)
                     lp.addPath(path.translated(*ul))
                 else:
                     path = self._skipitem.getSkip()
                     sp.addPath(path.translated(*ul))
             # end for
         # end if
         self._loopPaths.append((lpen, lp, spen, sp))
     # end for
     return self._loopPaths
Ejemplo n.º 2
0
 def shape(self):
     """
     Returns the shape used for selection
     """
     s = QPainterPath()
     s.addPath(self.hexagon_path)
     if self.editable:
         s.addPath(self.stroke)
     return s
Ejemplo n.º 3
0
 def shape(self):
     """
     Returns the shape used for selection
     """
     s = QPainterPath()
     s.addPath(self.hexagon_path)
     if self.editable:
         s.addPath(self.stroke)
     return s
Ejemplo n.º 4
0
    def calculateDatasets(self, scene, axes, datasets):
        """
        Builds the datasets for this renderer.  Each renderer will need to
        subclass and implemenent this method, otherwise, no data will be
        shown in the chart.
        
        :param      scene | <XChartScene>
                    axes | [<
                    datasets | [<XChartDataset>, ..]
        """
        items = self.calculateDatasetItems(scene, datasets)
        if not items:
            scene.clear()
            return

        rect = self.buildData('axis_rect')
        half_size = self.maximumBarSize() / 2.0

        for dataset, item in items.items():
            path = QPainterPath()
            subpaths = []

            for value in dataset.values():
                pos = self.pointAt(axes, value)

                radius = min(rect.bottom() - pos.y(), 8)

                subpath = QPainterPath()

                # create a vertical bar graph
                if self.orientation() == Qt.Vertical:
                    subpath.moveTo(pos.x() - half_size, rect.bottom())
                    subpath.lineTo(pos.x() - half_size, pos.y() + radius)
                    subpath.quadTo(pos.x() - half_size, pos.y(),
                                   pos.x() - half_size + radius, pos.y())
                    subpath.lineTo(pos.x() + half_size - radius, pos.y())
                    subpath.quadTo(pos.x() + half_size, pos.y(),
                                   pos.x() + half_size,
                                   pos.y() + radius)
                    subpath.lineTo(pos.x() + half_size, rect.bottom())
                    subpath.lineTo(pos.x() - half_size, rect.bottom())

                # create a horizontal bar graph
                else:
                    subpath.moveTo(rect.left(), pos.y() - half_size)
                    subpath.lineTo(pos.x(), pos.y() - half_size)
                    subpath.lineTo(pos.x(), pos.y() + half_size)
                    subpath.lineTo(rect.left(), pos.y() + half_size)
                    subpath.lineTo(rect.left(), pos.y() - half_size)

                path.addPath(subpath)
                subpaths.append(subpath)

            item.setPath(path)
            item.setBuildData('subpaths', subpaths)
Ejemplo n.º 5
0
 def calculateDatasets(self, scene, axes, datasets):
     """
     Builds the datasets for this renderer.  Each renderer will need to
     subclass and implemenent this method, otherwise, no data will be
     shown in the chart.
     
     :param      scene | <XChartScene>
                 axes | [<
                 datasets | [<XChartDataset>, ..]
     """
     items = self.calculateDatasetItems(scene, datasets)
     if not items:
         scene.clear()
         return
     
     rect = self.buildData('axis_rect')
     half_size = self.maximumBarSize() / 2.0
     
     for dataset, item in items.items():
         path = QPainterPath()
         subpaths = []
         
         for value in dataset.values():
             pos = self.pointAt(axes, value)
             
             radius = min(rect.bottom() - pos.y(), 8)
             
             subpath = QPainterPath()
             
             # create a vertical bar graph
             if self.orientation() == Qt.Vertical:
                 subpath.moveTo(pos.x() - half_size, rect.bottom())
                 subpath.lineTo(pos.x() - half_size, pos.y() + radius)
                 subpath.quadTo(pos.x() - half_size, pos.y(),
                                pos.x() - half_size + radius, pos.y())
                 subpath.lineTo(pos.x() + half_size - radius, pos.y())
                 subpath.quadTo(pos.x() + half_size, pos.y(),
                                pos.x() + half_size, pos.y() + radius)
                 subpath.lineTo(pos.x() + half_size, rect.bottom())
                 subpath.lineTo(pos.x() - half_size, rect.bottom())
             
             # create a horizontal bar graph
             else:
                 subpath.moveTo(rect.left(), pos.y() - half_size)
                 subpath.lineTo(pos.x(),     pos.y() - half_size)
                 subpath.lineTo(pos.x(),     pos.y() + half_size)
                 subpath.lineTo(rect.left(), pos.y() + half_size)
                 subpath.lineTo(rect.left(), pos.y() - half_size)
             
             path.addPath(subpath)
             subpaths.append(subpath)
         
         item.setPath(path)
         item.setBuildData('subpaths', subpaths)
Ejemplo n.º 6
0
 def segmentPaths(self):
     """Returns an array of (pen, penPainterPath, brush, brushPainterPath)
     for drawing segment lines and handles."""
     if self._segmentPaths:
         return self._segmentPaths
     self._segmentPaths = []
     vh = self.vhelix()
     for strandType in (StrandType.Scaffold, StrandType.Staple):
         top = self.strandIsTop(strandType)
         for [startIndex, startIsXO, endIndex, endIsXO] in\
                                     self._vhelix.getSegments(strandType):
             # Left and right centers for drawing the connecting line
             c1 = self.baseLocation(strandType, startIndex, center=True)
             c2 = self.baseLocation(strandType, endIndex, center=True)
             # Upper left corners for translating the breakpoint handles
             ul1 = self.baseLocation(strandType, startIndex)
             ul2 = self.baseLocation(strandType, endIndex)
             # Now we construct the path to cache
             bp = QPainterPath()
             if not startIsXO:
                 bp.addPath(ppL5.translated(*ul1) if top else\
                                                     ppL3.translated(*ul1))
             if not endIsXO:
                 bp.addPath(ppR3.translated(*ul2) if top else\
                                                     ppR5.translated(*ul2))
             pp = QPainterPath()
             pp.moveTo(*c1)
             pp.lineTo(*c2)
             # Now we combine pen/brush information and push it to the cache
             # _segmentPaths entries take the form:
             # (pen, painterPathToBeDrawnOnlyWithPen,\
             #  brush, paintPathToBeDrawnOnlyWithBrush)
             color = vh.colorOfBase(strandType, startIndex)
             width = styles.PATH_STRAND_STROKE_WIDTH
             pen = QPen(color, width)
             brush = QBrush(color)
             self._segmentPaths.append((pen, pp, brush, bp))
     return self._segmentPaths
Ejemplo n.º 7
0
    def rebuild(self):
        """
        Rebuilds the item based on the current points.
        """
        scene = self.scene()
        if not scene:
            return

        self._subpaths = []

        grid = scene.gridRect()
        typ = self.chartType()

        hruler = scene.horizontalRuler()
        vruler = scene.verticalRuler()

        path = QPainterPath()
        area = QPainterPath()

        self._buildData.clear()
        self._buildData['path_area'] = area

        self.setPos(0, 0)

        # draw a line item
        if typ == XChartScene.Type.Line:
            first = True
            pos = None
            home = None
            self._ellipses = []

            points = self.points()
            if (self.orientation() == Qt.Horizontal):
                points.sort(hruler.compareValues, key=lambda x: x[0])
            else:
                points.sort(vruler.compareValues, key=lambda y: y[1])
                points.reverse()

            for x, y in self.points():
                pos = scene.mapFromChart(x, y)
                if first:
                    home = QPointF(pos.x(), grid.bottom())
                    area.moveTo(home)
                    area.lineTo(pos)
                    path.moveTo(pos)

                    self._ellipses.append(pos)

                    first = False
                else:
                    path.lineTo(pos)
                    area.lineTo(pos)

                    self._ellipses.append(pos)

            if pos and home:
                area.lineTo(pos.x(), grid.bottom())
                area.lineTo(home)

        # draw a bar item
        elif typ == XChartScene.Type.Bar:
            barsize = self.barSize()
            horiz = self.orientation() == Qt.Horizontal

            for x, y in self.points():
                pos = scene.mapFromChart(x, y)
                subpath = QPainterPath()
                if horiz:
                    r = min(grid.bottom() - pos.y(), 8)

                    subpath.moveTo(pos.x() - barsize / 2.0, grid.bottom())
                    subpath.lineTo(pos.x() - barsize / 2.0, pos.y() + r)
                    subpath.quadTo(pos.x() - barsize / 2.0, pos.y(),
                                   pos.x() - barsize / 2.0 + r, pos.y())

                    subpath.lineTo(pos.x() + barsize / 2.0 - r, pos.y())
                    subpath.quadTo(pos.x() + barsize / 2.0, pos.y(),
                                   pos.x() + barsize / 2.0,
                                   pos.y() + r)

                    subpath.lineTo(pos.x() + barsize / 2.0, grid.bottom())
                    subpath.lineTo(pos.x() - barsize / 2.0, grid.bottom())
                else:
                    subpath.moveTo(grid.left(), pos.y() - barsize / 2.0)
                    subpath.lineTo(pos.x(), pos.y() - barsize / 2.0)
                    subpath.lineTo(pos.x(), pos.y() + barsize / 2.0)
                    subpath.lineTo(grid.left(), pos.y() + barsize / 2.0)
                    subpath.lineTo(grid.left(), pos.y() - barsize / 2.0)

                path.addPath(subpath)
                self._subpaths.append((x, y, subpath))

        # draw a pie chart
        elif typ == XChartScene.Type.Pie:
            if self.orientation() == Qt.Horizontal:
                key_index = 0
                value_index = 1
                value_ruler = self.verticalRuler()
            else:
                key_index = 1
                value_index = 0
                value_ruler = self.horizontalRuler()

            pie_values = {}

            for point in self.points():
                key = point[key_index]
                value = point[value_index]

                pie_values.setdefault(key, [])
                pie_values[key].append(value)

            for key, values in pie_values.items():
                pie_values[key] = value_ruler.calcTotal(values)

            total = max(1, value_ruler.calcTotal(pie_values.values()))

            # calculate drawing parameters
            center = self.pieCenter()
            radius = self.radius()
            diameter = radius * 2
            angle = 0
            bound = QRectF(-radius, -radius, diameter, diameter)

            for key, value in sorted(pie_values.items(), key=lambda x: x[1]):
                # calculate the percentage
                perc = float(value) / total

                # calculate the angle as the perc * 360
                item_angle = perc * 360
                self.setPos(center)

                sub_path = QPainterPath()
                sub_path.arcTo(bound, angle, item_angle)
                sub_path.lineTo(0, 0)

                path.addPath(sub_path)
                self._subpaths.append((key, value, sub_path))

                angle += item_angle

        self.setPath(path)
        self._dirty = False
Ejemplo n.º 8
0
 def calculateDatasets(self, scene, axes, datasets):
     """
     Builds the datasets for this renderer.  Each renderer will need to
     subclass and implemenent this method, otherwise, no data will be
     shown in the chart.
     
     :param      scene | <XChartScene>
                 axes | [<
                 datasets | [<XChartDataset>, ..]
     """
     items = self.calculateDatasetItems(scene, datasets)
     if not items:
         scene.clear()
         return
     
     xaxis = scene.chart().horizontalAxis()
     yaxis = scene.chart().verticalAxis()
     data_axis = None
     all_values = []
     
     # determine if we're mapping data aginst the sets themselves, in
     # which case, create a pie chart of the dataset vs. its 
     if isinstance(xaxis, XDatasetAxis):
         per_dataset = False
         data_axis = yaxis
         total = 1
     
     elif isinstance(yaxis, XDatasetAxis):
         per_dataset = False
         total = 1
         data_axis = xaxis
     
     else:
         per_dataset = True
         total = len(items)
     
     if not per_dataset:
         all_values = [dataset.sum(data_axis) \
                       for dataset in datasets]
     
     # generate the build information
     rect = self.buildData('grid_rect')
     rect.setX(rect.x() + 10)
     rect.setY(rect.y() + 10)
     rect.setWidth(rect.width() - 20)
     rect.setHeight(rect.height() - 20)
     
     if rect.width() > rect.height():
         radius = min(rect.width() / 2.0, rect.height() / 2.0)
         x = rect.left()
         y = rect.top() + radius
         deltax = min(radius * 2, rect.width() / float(total + 1))
         deltay = 0
     else:
         radius = min(rect.height() / 2.0, rect.width() / 2.0)
         x = rect.left() + radius
         y = rect.top()
         deltax = 0
         deltay = min(radius * 2, rect.height() / float(total + 1))
     
     # initialize the first pie chart
     angle = 0
     cx = x + deltax
     cy = y + deltay
     
     x += deltax
     y += deltay
     
     for dataset in datasets:
         item = items.get(dataset)
         if not item:
             continue
         
         item.setBuildData('center', QPointF(cx, cy))
         item.setBuildData('radius', radius)
         
         subpaths = []
         bound = QRectF(cx-radius, cy-radius, radius * 2, radius * 2)
         path = QPainterPath()
         if per_dataset:
             data_values = dataset.values(yaxis.name())
             andle = 0
             for value in dataset.values():
                 perc = yaxis.percentOfTotal(value.get(yaxis.name()),
                                             data_values)
                 
                 # calculate the angle as the perc
                 item_angle = perc * 360
                 
                 subpath = QPainterPath()
                 subpath.moveTo(cx, cy)
                 subpath.arcTo(bound, angle, item_angle)
                 subpath.lineTo(cx, cy)
                 
                 path.addPath(subpath)
                 subpaths.append((value.get(xaxis.name()), subpath))
                 
                 angle += item_angle
                 
             cx = x + deltax
             cy = y + deltay
             
             x += deltax
             y += deltay
         else:
             value = dataset.sum(data_axis)
             perc = data_axis.percentOfTotal(value, all_values)
             
             # calculate the angle as the perc
             item_angle = perc * 360
             
             subpath = QPainterPath()
             subpath.moveTo(cx, cy)
             subpath.arcTo(bound, angle, item_angle)
             subpath.lineTo(cx, cy)
             
             path.addPath(subpath)
             subpaths.append((value, subpath))
             
             angle += item_angle
             
         item.setPath(path)
         item.setBuildData('subpaths', subpaths)
Ejemplo n.º 9
0
    def calculateDatasets(self, scene, axes, datasets):
        """
        Builds the datasets for this renderer.  Each renderer will need to
        subclass and implemenent this method, otherwise, no data will be
        shown in the chart.
        
        :param      scene | <XChartScene>
                    axes | [<
                    datasets | [<XChartDataset>, ..]
        """
        items = self.calculateDatasetItems(scene, datasets)
        if not items:
            scene.clear()
            return

        xaxis = scene.chart().horizontalAxis()
        yaxis = scene.chart().verticalAxis()
        data_axis = None
        all_values = []

        # determine if we're mapping data aginst the sets themselves, in
        # which case, create a pie chart of the dataset vs. its
        if isinstance(xaxis, XDatasetAxis):
            per_dataset = False
            data_axis = yaxis
            total = 1

        elif isinstance(yaxis, XDatasetAxis):
            per_dataset = False
            total = 1
            data_axis = xaxis

        else:
            per_dataset = True
            total = len(items)

        if not per_dataset:
            all_values = [dataset.sum(data_axis) \
                          for dataset in datasets]

        # generate the build information
        rect = self.buildData('grid_rect')
        rect.setX(rect.x() + 10)
        rect.setY(rect.y() + 10)
        rect.setWidth(rect.width() - 20)
        rect.setHeight(rect.height() - 20)

        if rect.width() > rect.height():
            radius = min(rect.width() / 2.0, rect.height() / 2.0)
            x = rect.left()
            y = rect.top() + radius
            deltax = min(radius * 2, rect.width() / float(total + 1))
            deltay = 0
        else:
            radius = min(rect.height() / 2.0, rect.width() / 2.0)
            x = rect.left() + radius
            y = rect.top()
            deltax = 0
            deltay = min(radius * 2, rect.height() / float(total + 1))

        # initialize the first pie chart
        angle = 0
        cx = x + deltax
        cy = y + deltay

        x += deltax
        y += deltay

        for dataset in datasets:
            item = items.get(dataset)
            if not item:
                continue

            item.setBuildData('center', QPointF(cx, cy))
            item.setBuildData('radius', radius)

            subpaths = []
            bound = QRectF(cx - radius, cy - radius, radius * 2, radius * 2)
            path = QPainterPath()
            if per_dataset:
                data_values = dataset.values(yaxis.name())
                andle = 0
                for value in dataset.values():
                    perc = yaxis.percentOfTotal(value.get(yaxis.name()),
                                                data_values)

                    # calculate the angle as the perc
                    item_angle = perc * 360

                    subpath = QPainterPath()
                    subpath.moveTo(cx, cy)
                    subpath.arcTo(bound, angle, item_angle)
                    subpath.lineTo(cx, cy)

                    path.addPath(subpath)
                    subpaths.append((value.get(xaxis.name()), subpath))

                    angle += item_angle

                cx = x + deltax
                cy = y + deltay

                x += deltax
                y += deltay
            else:
                value = dataset.sum(data_axis)
                perc = data_axis.percentOfTotal(value, all_values)

                # calculate the angle as the perc
                item_angle = perc * 360

                subpath = QPainterPath()
                subpath.moveTo(cx, cy)
                subpath.arcTo(bound, angle, item_angle)
                subpath.lineTo(cx, cy)

                path.addPath(subpath)
                subpaths.append((value, subpath))

                angle += item_angle

            item.setPath(path)
            item.setBuildData('subpaths', subpaths)
Ejemplo n.º 10
0
    def rebuildMonth(self):
        """
        Rebuilds the current item in month mode.
        """
        scene = self.scene()
        if (not scene):
            return

        start_date = self.dateStart()
        end_date = self.dateEnd()
        min_date = scene.minimumDate()
        max_date = scene.maximumDate()

        # make sure our item is visible
        if (not (min_date <= end_date and start_date <= max_date)):
            self.hide()
            self.setPath(QPainterPath())
            return

        # make sure we have valid range information
        if (start_date < min_date):
            start_date = min_date
            start_inrange = False
        else:
            start_inrange = True

        if (max_date < end_date):
            end_date = max_date
            end_inrange = False
        else:
            end_inrange = True

        start_rect = scene.dateRect(start_date)
        end_rect = scene.dateRect(end_date)

        if (not (start_rect.isValid() and end_rect.isValid())):
            self.hide()
            return

        # rebuild an all day path
        path = QPainterPath()
        self.setPos(0, 0)

        pad = 2
        offset = 18
        height = 16

        min_left = 10
        max_right = scene.width() - 16
        delta_h = start_rect.height()

        # draw the all day event
        if (self.isAllDay()):
            top = start_rect.top()
            left = start_rect.left() + 3
            first = start_inrange

            while (top <= end_rect.top()):
                sub_path = QPainterPath()

                # calculate the end position
                if (end_rect.top() - 2 <= top and end_inrange):
                    at_end = True
                    right = end_rect.right() - pad
                else:
                    at_end = False
                    right = max_right

                if (first):
                    sub_path.moveTo(left, top + offset)
                    text_left = left + 4
                else:
                    sub_path.moveTo(left + height / 2, top + offset)
                    text_left = left + height / 2 + 2

                if (at_end):
                    sub_path.lineTo(right, top + offset)
                    sub_path.lineTo(right, top + offset + height)
                else:
                    sub_path.lineTo(right - height / 2, top + offset)
                    sub_path.lineTo(right, top + offset + height / 2)
                    sub_path.lineTo(right - height / 2, top + offset + height)

                if (first):
                    sub_path.lineTo(left, top + offset + height)
                    sub_path.lineTo(left, top + offset)
                else:
                    sub_path.lineTo(left + height / 2, top + offset + height)
                    sub_path.lineTo(left, top + offset + height / 2)
                    sub_path.lineTo(left + height / 2, top + offset)

                path.addPath(sub_path)

                data = (text_left, top + offset + 1, right, height,
                        Qt.AlignLeft | Qt.AlignVCenter, self.title())

                self._textData.append(data)

                left = min_left
                top += delta_h
                first = False
        else:
            text = '%s: (%s)' % (self.timeStart().toString('h:mm ap'),
                                 self.title())

            font = scene.font()
            left = start_rect.left() + 2 * pad
            top = start_rect.top() + offset

            path.addText(left, top + height / 2, font, text)

        # setup the path for this item
        self.setPath(path)
        self.show()

        # make sure there are no collisions
        while (self.collidingItems()):
            self.setPos(self.pos().x(), self.pos().y() + height + 2)

            # hide the item if out of the visible scope
            if (delta_h - offset <= self.pos().y() + height):
                self.hide()
                break
Ejemplo n.º 11
0
 def rebuildMonth( self ):
     """
     Rebuilds the current item in month mode.
     """
     scene = self.scene()
     if ( not scene ):
         return
     
     start_date  = self.dateStart()
     end_date    = self.dateEnd()
     min_date    = scene.minimumDate()
     max_date    = scene.maximumDate()
     
     # make sure our item is visible
     if ( not (min_date <= end_date and start_date <= max_date)):
         self.hide()
         self.setPath(QPainterPath())
         return
     
     # make sure we have valid range information
     if ( start_date < min_date ):
         start_date    = min_date
         start_inrange = False
     else:
         start_inrange = True
     
     if ( max_date < end_date ):
         end_date     = max_date
         end_inrange  = False
     else:
         end_inrange  = True
     
     start_rect = scene.dateRect(start_date)
     end_rect   = scene.dateRect(end_date)
     
     if ( not (start_rect.isValid() and end_rect.isValid()) ):
         self.hide()
         return
     
     # rebuild an all day path
     path = QPainterPath()
     self.setPos(0, 0)
     
     pad         = 2
     offset      = 18
     height      = 16
     
     min_left    = 10
     max_right   = scene.width() - 16
     delta_h     = start_rect.height()
     
     # draw the all day event
     if ( self.isAllDay() ):
         top   = start_rect.top()
         left  = start_rect.left() + 3
         first = start_inrange
         
         while ( top <= end_rect.top() ):
             sub_path  = QPainterPath()
             
             # calculate the end position
             if ( end_rect.top() - 2 <= top and end_inrange ):
                 at_end = True
                 right = end_rect.right() - pad
             else:
                 at_end = False
                 right = max_right
             
             if ( first ):
                 sub_path.moveTo(left, top + offset)
                 text_left = left + 4
             else:
                 sub_path.moveTo(left + height / 2, top + offset)
                 text_left = left + height / 2 + 2
             
             if ( at_end ):
                 sub_path.lineTo(right, top + offset)
                 sub_path.lineTo(right, top + offset + height)
             else:
                 sub_path.lineTo(right - height / 2, top + offset)
                 sub_path.lineTo(right, top + offset + height / 2)
                 sub_path.lineTo(right - height / 2, top + offset + height)
             
             if ( first ):
                 sub_path.lineTo(left, top + offset + height)
                 sub_path.lineTo(left, top + offset)
             else:
                 sub_path.lineTo(left + height / 2, top + offset + height)
                 sub_path.lineTo(left, top + offset + height / 2)
                 sub_path.lineTo(left + height / 2, top + offset)
             
             path.addPath(sub_path)
             
             data = (text_left,
                     top + offset + 1,
                     right,
                     height,
                     Qt.AlignLeft | Qt.AlignVCenter,
                     self.title())
             
             self._textData.append(data)
             
             left = min_left
             top += delta_h
             first = False
     else:
         text = '%s: (%s)' % (self.timeStart().toString('h:mm ap'), 
                              self.title())
         
         font   = scene.font()
         left   = start_rect.left() + 2 * pad
         top    = start_rect.top() + offset
         
         path.addText(left, top + height / 2, font, text)
     
     # setup the path for this item
     self.setPath(path)
     self.show()
     
     # make sure there are no collisions
     while ( self.collidingItems() ):
         self.setPos(self.pos().x(), self.pos().y() + height + 2)
         
         # hide the item if out of the visible scope
         if ( delta_h - offset <= self.pos().y() + height ):
             self.hide()
             break