示例#1
0
文件: IncGraphSVG.py 项目: csarn/cpip
 def _plotFileNameStackPopup(self, theSvg, theDatumL, theTpt, idStack):
     """Writes out the file name at the top with a pop-up with the
     absolute path."""
     self.commentFunctionBegin(theSvg, File=self._fileName)
     if self._bb.hasSetArea:
         textPointP = self._fileNamePoint(theDatumL, theTpt)
         assert textPointP is not None
         # Make the trigger box 14 points high to cover the 12 pt text and
         # 12pts per char in the
         triggerBoxP = Coord.Box(
             Coord.baseUnitsDim(12 * len(os.path.basename(self.nodeName))),
             Coord.baseUnitsDim(14))
         triggerPointP = Coord.newPt(
             textPointP,
             triggerBoxP.width.scale(-0.5),
             triggerBoxP.depth.scale(-0.5),
         )
         self.writeAltTextAndMouseOverRect(
             theSvg,
             theSvg.id,
             textPointP,
             self._fileIdStackToListOfStr(idStack),
             triggerPointP,
             triggerBoxP,
         )
     self.commentFunctionEnd(theSvg, File=self._fileName)
示例#2
0
    def test_07(self):
        """TestSVGlWriter.test_07(): text.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/text.html#TextElement"""
        myF = io.StringIO()
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myF, myViewPort,
                                 {'viewBox': "0 0 1000 300"}) as xS:
            with XmlWrite.Element(xS, 'desc'):
                xS.characters("Example text01 - 'Hello, out there' in blue")
            myPt = Coord.Pt(Coord.baseUnitsDim(250), Coord.baseUnitsDim(150))
            with SVGWriter.SVGText(xS, myPt, "Verdans", 55, {'fill': "blue"}):
                xS.characters('Hello, out there')
            #xS.comment(" Show outline of canvas using 'rect' element ")
            myPt = Coord.Pt(Coord.baseUnitsDim(1), Coord.baseUnitsDim(1))
            myBx = Coord.Box(Coord.baseUnitsDim(998), Coord.baseUnitsDim(298))
            with SVGWriter.SVGRect(xS, myPt, myBx, {
                    'fill': "none",
                    'stroke': "blue",
                    'stroke-width': "2"
            }):
                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" viewBox="0 0 1000 300" width="12.00cm" xmlns="http://www.w3.org/2000/svg">
  <desc>Example text01 - &apos;Hello, out there&apos; in blue</desc>
  <text fill="blue" font-family="Verdans" font-size="55" x="250px" y="150px">Hello, out there</text>
  <rect fill="none" height="298px" stroke="blue" stroke-width="2" width="998px" x="1px" y="1px" />
</svg>
""")
示例#3
0
    def test_03(self):
        """TestSVGlWriter.test_03(): an elipse.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/shapes.html#EllipseElement"""
        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 ellipse01 - examples of ellipses')
            #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
            myPt = Coord.Pt(Coord.baseUnitsDim(600), Coord.baseUnitsDim(200))
            myRadX = Coord.baseUnitsDim(250)
            myRadY = Coord.baseUnitsDim(100)
            with SVGWriter.SVGElipse(xS, myPt, myRadX, myRadY, {
                    'fill': "red",
                    'stroke': "blue",
                    'stroke-width': "10"
            }):
                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 ellipse01 - examples of ellipses</desc>
  <rect fill="none" height="398px" stroke="blue" stroke-width="2" width="1198px" x="1px" y="1px" />
  <elipse cx="600px" cy="200px" fill="red" rx="250px" ry="100px" stroke="blue" stroke-width="10" />
</svg>
""")
示例#4
0
    def test_06(self):
        """TestSVGlWriter.test_06(): a polygon.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/shapes.html#PolygonElement"""
        myF = io.StringIO()
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myF, myViewPort,
                                 {'viewBox': "0 0 1200 400"}) 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.SVGPolygon(xS, [
                    Coord.Pt(Coord.baseUnitsDim(350), Coord.baseUnitsDim(75)),
                    Coord.Pt(Coord.baseUnitsDim(379), Coord.baseUnitsDim(161)),
                    Coord.Pt(Coord.baseUnitsDim(469), Coord.baseUnitsDim(161)),
                    Coord.Pt(Coord.baseUnitsDim(397), Coord.baseUnitsDim(215)),
                    Coord.Pt(Coord.baseUnitsDim(423), Coord.baseUnitsDim(301)),
                    Coord.Pt(Coord.baseUnitsDim(350), Coord.baseUnitsDim(250)),
                    Coord.Pt(Coord.baseUnitsDim(277), Coord.baseUnitsDim(301)),
                    Coord.Pt(Coord.baseUnitsDim(303), Coord.baseUnitsDim(215)),
                    Coord.Pt(Coord.baseUnitsDim(231), Coord.baseUnitsDim(161)),
                    Coord.Pt(Coord.baseUnitsDim(321), Coord.baseUnitsDim(161)),
            ], {
                    'fill': 'red',
                    'stroke': 'blue',
                    'stroke-width': "10"
            }):
                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" viewBox="0 0 1200 400" 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" />
  <polygon fill="red" points="350,75 379,161 469,161 397,215 423,301 350,250 277,301 303,215 231,161 321,161" stroke="blue" stroke-width="10" />
</svg>
""")
示例#5
0
    def test_05(self):
        """TestSVGlWriter.test_05(): a polyline.
        Based on http://www.w3.org/TR/2003/REC-SVG11-20030114/shapes.html#PolylineElement"""
        myF = io.StringIO()
        myViewPort = Coord.Box(
            Coord.Dim(12, 'cm'),
            Coord.Dim(4, 'cm'),
        )
        with SVGWriter.SVGWriter(myF, myViewPort,
                                 {'viewBox': "0 0 1200 400"}) 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.SVGPolyline(xS, [
                    Coord.Pt(Coord.baseUnitsDim(50), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(150), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(150), Coord.baseUnitsDim(325)),
                    Coord.Pt(Coord.baseUnitsDim(250), Coord.baseUnitsDim(325)),
                    Coord.Pt(Coord.baseUnitsDim(250), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(350), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(350), Coord.baseUnitsDim(250)),
                    Coord.Pt(Coord.baseUnitsDim(450), Coord.baseUnitsDim(250)),
                    Coord.Pt(Coord.baseUnitsDim(450), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(550), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(550), Coord.baseUnitsDim(175)),
                    Coord.Pt(Coord.baseUnitsDim(650), Coord.baseUnitsDim(175)),
                    Coord.Pt(Coord.baseUnitsDim(650), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(750), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(750), Coord.baseUnitsDim(100)),
                    Coord.Pt(Coord.baseUnitsDim(850), Coord.baseUnitsDim(100)),
                    Coord.Pt(Coord.baseUnitsDim(850), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(950), Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(950), Coord.baseUnitsDim(25)),
                    Coord.Pt(Coord.baseUnitsDim(1050), Coord.baseUnitsDim(25)),
                    Coord.Pt(Coord.baseUnitsDim(1050),
                             Coord.baseUnitsDim(375)),
                    Coord.Pt(Coord.baseUnitsDim(1150),
                             Coord.baseUnitsDim(375)),
            ], {
                    'fill': 'none',
                    'stroke': 'blue',
                    'stroke-width': "5"
            }):
                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" viewBox="0 0 1200 400" 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" />
  <polyline fill="none" points="50,375 150,375 150,325 250,325 250,375 350,375 350,250 450,250 450,375 550,375 550,175 650,175 650,375 750,375 750,100 850,100 850,375 950,375 950,25 1050,25 1050,375 1150,375" stroke="blue" stroke-width="5" />
</svg>
""")
示例#6
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>
""")