示例#1
0
文件: IncGraphSVG.py 项目: csarn/cpip
 def _plotRootChildToChild(self, theSvg, theDatumL, theTpt):
     """Join up children of root node with vertical lines."""
     assert (len(self._children) > 0)
     assert (self.isRoot)
     self.commentFunctionBegin(theSvg)
     ptNextL = None
     for i, datumChildL in self._enumerateChildren(theDatumL, theTpt):
         if i > 0:
             ptPrevL = theTpt.prevdcL(
                 self._children[i].bb.plotPointSelf(datumChildL),
                 self._children[i].bb.box,
             )
             with SVGWriter.SVGLine(
                     theSvg,
                     theTpt.pt(ptNextL),
                     theTpt.pt(ptPrevL),
                     self.ATTRS_LINE_ROOT_CHILDREN_JOIN,
             ):
                 pass
         ptNextL = theTpt.nextdcL(
             self._children[i].bb.plotPointSelf(datumChildL),
             self._children[i].bb.box,
         )
     self.commentFunctionEnd(theSvg)
示例#2
0
    def test_04(self):
        """TestSVGlWriter.test_04(): a line.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/shapes.html#LineElement"""
        myF = io.StringIO()
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myF, myViewPort) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters(
                    'Example line01 - lines expressed in user coordinates')
            #xS.comment(" Show outline of canvas using 'rect' element ")
            myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1))
            myBx = Coord.Box(Coord.baseUnitsDim(1198), Coord.baseUnitsDim(398))
            with SVGWriter.SVGRect(xS, myPt, myBx, {
                    'fill': "none",
                    'stroke': "blue",
                    'stroke-width': "2"
            }):
                pass
            # Make a group
            with SVGWriter.SVGGroup(xS, {'stroke': 'green'}):
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(100),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(300),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "5"}):
                    pass
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(300),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(500),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "10"}):
                    pass
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(500),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(700),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "15"}):
                    pass
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(700),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(900),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "20"}):
                    pass
                with SVGWriter.SVGLine(
                        xS,
                        Coord.Pt(Coord.baseUnitsDim(900),
                                 Coord.baseUnitsDim(300)),
                        Coord.Pt(Coord.baseUnitsDim(1100),
                                 Coord.baseUnitsDim(100)),
                    {'stroke-width': "25"}):
                    pass
        #print
        #print myF.getvalue()
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="4.00cm" version="1.1" width="12.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Example line01 - lines expressed in user coordinates</desc>
  <rect fill="none" height="398px" stroke="blue" stroke-width="2" width="1198px" x="1px" y="1px" />
  <g stroke="green">
    <line stroke-width="5" x1="100px" x2="300px" y1="300px" y2="100px" />
    <line stroke-width="10" x1="300px" x2="500px" y1="300px" y2="100px" />
    <line stroke-width="15" x1="500px" x2="700px" y1="300px" y2="100px" />
    <line stroke-width="20" x1="700px" x2="900px" y1="300px" y2="100px" />
    <line stroke-width="25" x1="900px" x2="1100px" y1="300px" y2="100px" />
  </g>
</svg>
""")
示例#3
0
文件: IncGraphSVG.py 项目: csarn/cpip
    def _plotChevron(self, theSvg, theDl, theTpt):
        """Plots a wedge to represent the relative number of tokens in me and
        my children.
        D------------------.------------------|
        |                                     |
        |------------------.------------------|
        |                                     |
        A-----------B------.------D-----------|
        |            \     .     /            |
        |             \    .    /             |
        |              \   .   /              |
        |               \  .  /               |
        |                \ . /                |
        ------------------\C/------------------
        We plot in the order D moveto A moveto B lineto C lineto D lineto B
        """
        mySelfTokCount = self.tokenCounter.tokenCountNonWs(isAll=False)
        if mySelfTokCount == 0 and self._numChildSigTokens == 0:
            return
        # Find D
        myDl = self._bb.plotPointSelf(theDl)
        # Point C, all use this
        myPtC = Coord.newPt(myDl, self._bb.width.scale(0.5), self._bb.depth)
        # Increment by one or two histogram depths to point A
        if self.__mustPlotSelfHistogram():
            myDl = Coord.newPt(myDl, None, self.HIST_DEPTH)
        if self.__mustPlotChildHistogram():
            myDl = Coord.newPt(myDl, None, self.HIST_DEPTH)
        # Figure out move to B
        if self._numChildSigTokens == 0:
            # Chevron takes full width
            polyLogicalPtS = [
                myDl,
                myPtC,
                Coord.newPt(myDl, self._bb.width, None),
            ]
        else:
            ratioChevron = 1.0 * mySelfTokCount / (self._numChildSigTokens +
                                                   mySelfTokCount)
            myChevronOffset = self._bb.width.scale(0.5 * ratioChevron)
            #theSvg.comment(' Chevron offset: %s ' % str(myChevronOffset))
            # Offset to B
            myDl = Coord.newPt(myDl,
                               self._bb.width.scale(0.5) - myChevronOffset,
                               None)
            polyLogicalPtS = [
                myDl,
                myPtC,
                Coord.newPt(myDl, myChevronOffset.scale(2.0), None),
            ]

        polyPhysicalPtS = [theTpt.pt(p) for p in polyLogicalPtS]
        #theSvg.comment(' \npolyPhysicalPtS: %s \n' % str([str(p) for p in polyPhysicalPtS]))
        j = 1
        while j < len(polyPhysicalPtS):
            with SVGWriter.SVGLine(
                    theSvg,
                    polyPhysicalPtS[j - 1],
                    polyPhysicalPtS[j],
                {
                    'stroke-width': "2",
                    'stroke': "black",
                },
            ):
                pass
            j += 1
示例#4
0
文件: IncGraphSVG.py 项目: csarn/cpip
 def _plotSelfToChildren(self, theSvg, theDatumL, theTpt):
     """Plot links from me to my children to a stream at the
     (self) logical datum point."""
     assert (len(self._children) > 0)
     assert (not self.isRoot)
     #print 'TRACE: plotSelfToChildren()', theDatumL
     myDatumL = self._bb.plotPointSelf(theDatumL)
     #nameP = self.nodeName
     for i, datumChildL in self._enumerateChildren(theDatumL, theTpt):
         if self._children[i].condCompState:
             if self._children[i].numTokens > 0:
                 myAttrsTo = self.ATTRS_LINE_NORMAL_TO
                 myAttrsFrom = self.ATTRS_LINE_NORMAL_FROM
             else:
                 myAttrsTo = self.ATTRS_LINE_MT_TO
                 myAttrsFrom = self.ATTRS_LINE_MT_FROM
         else:
             myAttrsTo = self.ATTRS_LINE_CONDITIONAL_TO
             myAttrsFrom = self.ATTRS_LINE_CONDITIONAL_FROM
         #nameC = self._children[i]._dataMap['name']
         if theTpt.positiveSweepDir:
             childOrd = len(self._children) - i - 1
         else:
             childOrd = i
         # Parent to child
         linePtsFirst = [
             theTpt.pt(l) for l in (
                 self._bb.pcRoll(myDatumL, childOrd),
                 self._bb.pcTo(myDatumL, childOrd),
                 self._children[i].bb.pcLand(datumChildL),
                 self._children[i].bb.pcStop(datumChildL),
             )
         ]
         # Now child to parent
         linePtsSecond = [
             theTpt.pt(l) for l in (
                 self._children[i].bb.cpRoll(datumChildL),
                 self._children[i].bb.cpTo(datumChildL),
                 self._bb.cpLand(myDatumL, childOrd),
                 self._bb.cpStop(myDatumL, childOrd),
             )
         ]
         if theTpt.positiveSweepDir:
             linePtsSecond, linePtsFirst = linePtsFirst, linePtsSecond
         j = 1
         #theSvg.comment(' %s to %s ' % (nameP, nameC))
         while j < len(linePtsFirst):
             with SVGWriter.SVGLine(
                     theSvg,
                     linePtsFirst[j - 1],
                     linePtsFirst[j],
                     myAttrsTo,
             ):
                 pass
             j += 1
         j = 1
         #theSvg.comment(' %s to %s ' % (nameC, nameP))
         while j < len(linePtsSecond):
             with SVGWriter.SVGLine(
                     theSvg,
                     linePtsSecond[j - 1],
                     linePtsSecond[j],
                     myAttrsFrom,
             ):
                 pass
             j += 1