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.000cm" version="1.1" viewBox="0 0 1000 300" width="12.000cm" xmlns="http://www.w3.org/2000/svg"> <desc>Example text01 - 'Hello, out there' in blue</desc> <text fill="blue" font-family="Verdans" font-size="55" x="250.000px" y="150.000px">Hello, out there</text> <rect fill="none" height="298.000px" stroke="blue" stroke-width="2" width="998.000px" x="1.000px" y="1.000px"/> </svg> """)
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.maxDiff = None 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="4cm" version="1.1" width="12cm" 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> """)
def test_11(self): """TestLogHeaderLAS.test_11(): Plot as top of log with CONS data.""" myLh = LogHeader.APIHeaderLAS(isTopOfLog=True) fp = TestPlotShared.outPath(TEST_SVG_FILE_MAP_HDR[56].fileName) tl = Coord.Pt(Coord.Dim(0.5, 'in'), Coord.Dim(0.25, 'in')) viewPort = myLh.viewPort(tl) with SVGWriter.SVGWriter(open(fp, 'w'), viewPort) as xS: myLh.plot(xS, tl, self._lasFile)
def test_05(self): """TestLogHeaderLAS.test_05(): Plot as not top of log.""" myLh = LogHeader.APIHeaderLAS(isTopOfLog=False) fp = TestPlotShared.outPath(TEST_SVG_FILE_MAP_HDR[50].fileName) tl = Coord.Pt(Coord.Dim(0.0, 'in'), Coord.Dim(0.0, 'in')) viewPort = myLh.viewPort(tl) with SVGWriter.SVGWriter(open(fp, 'w'), viewPort) as xS: myLh.plot(xS, tl)
def test_10(self): """TestLogHeader.test_10(): Plot as not top of log with CONS data.""" myLh = LogHeader.APIHeaderLIS(isTopOfLog=False) fp = TestPlotShared.outPath(TEST_SVG_FILE_MAP_HDR[45].fileName) tl = Coord.Pt(Coord.Dim(0.25, 'in'), Coord.Dim(0.5, 'in')) viewPort = myLh.viewPort(tl) with SVGWriter.SVGWriter(open(fp, 'w'), viewPort) as xS: myLh.plot(xS, tl, [self._lrCONS,])
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.maxDiff = None 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="4cm" version="1.1" viewBox="0 0 1200 400" width="12cm" 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> """)
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.maxDiff = None self.assertEqual( """<?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.000cm" version="1.1" viewBox="0 0 1200 400" width="12.000cm" xmlns="http://www.w3.org/2000/svg"> <desc>Example line01 - lines expressed in user coordinates</desc> <rect fill="none" height="398.000px" stroke="blue" stroke-width="2" width="1198.000px" x="1.000px" y="1.000px"/> <polygon fill="red" points="350.0,75.0 379.0,161.0 469.0,161.0 397.0,215.0 423.0,301.0 350.0,250.0 277.0,301.0 303.0,215.0 231.0,161.0 321.0,161.0" stroke="blue" stroke-width="10"/> </svg> """, myF.getvalue())
def test_01(self): """TestSVGlWriter.test_01(): <desc> and four rectangles. From second example in http://www.w3.org/TR/2003/REC-SVG11-20030114/struct.html#NewDocumentOverview""" myF = io.StringIO() myViewPort = Coord.Box( Coord.Dim(5, 'cm'), Coord.Dim(4, 'cm'), ) with SVGWriter.SVGWriter(myF, myViewPort) as xS: with XmlWrite.Element(xS, 'desc'): xS.characters('Four separate rectangles') myPt = Coord.Pt(Coord.Dim(0.5, 'cm'), Coord.Dim(0.5, 'cm')) myBx = Coord.Box(Coord.Dim(2.0, 'cm'), Coord.Dim(1.0, 'cm')) with SVGWriter.SVGRect(xS, myPt, myBx): pass myPt = Coord.Pt(Coord.Dim(0.5, 'cm'), Coord.Dim(2.0, 'cm')) myBx = Coord.Box(Coord.Dim(1.0, 'cm'), Coord.Dim(1.5, 'cm')) with SVGWriter.SVGRect(xS, myPt, myBx): pass myPt = Coord.Pt(Coord.Dim(3.0, 'cm'), Coord.Dim(0.5, 'cm')) myBx = Coord.Box(Coord.Dim(1.5, 'cm'), Coord.Dim(2.0, 'cm')) with SVGWriter.SVGRect(xS, myPt, myBx): pass myPt = Coord.Pt(Coord.Dim(3.5, 'cm'), Coord.Dim(3.0, 'cm')) myBx = Coord.Box(Coord.Dim(1.0, 'cm'), Coord.Dim(0.5, 'cm')) with SVGWriter.SVGRect(xS, myPt, myBx): pass myPt = Coord.Pt(Coord.Dim(0.01, 'cm'), Coord.Dim(0.01, 'cm')) myBx = Coord.Box(Coord.Dim(4.98, 'cm'), Coord.Dim(3.98, 'cm')) with SVGWriter.SVGRect( xS, myPt, myBx, attrs= { 'fill' : "none", 'stroke' : "blue", 'stroke-width' : ".02cm", } ): 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="4cm" version="1.1" width="5cm" xmlns="http://www.w3.org/2000/svg"> <desc>Four separate rectangles</desc> <rect height="1cm" width="2cm" x="0.5cm" y="0.5cm"/> <rect height="1.5cm" width="1cm" x="0.5cm" y="2cm"/> <rect height="2cm" width="1.5cm" x="3cm" y="0.5cm"/> <rect height="0.5cm" width="1cm" x="3.5cm" y="3cm"/> <rect fill="none" height="3.98cm" stroke="blue" stroke-width=".02cm" width="4.98cm" x="0.01cm" y="0.01cm"/> </svg> """)
def test_00(self): """TestSVGWriter.test_00(): construction.""" myF = io.StringIO() myViewPort = Coord.Box( Coord.Dim(100, 'mm'), Coord.Dim(20, 'mm'), ) with SVGWriter.SVGWriter(myF, myViewPort): 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="20mm" version="1.1" width="100mm" xmlns="http://www.w3.org/2000/svg"/>\n""")
def test_03(self): """TestPlotTrack.test_03(): Construct a log track and plot it in SVG.""" myT = Track.Track( leftPos=Coord.Dim(3.2, 'in'), rightPos=Coord.Dim(5.6, 'in'), gridGn=Track.genLog10Decade2 ) # myCnv = Plot.Canvas(Coord.Dim(6, 'in'), Coord.Dim(8, 'in'), Plot.MarginQtrInch) # myViewPort = Coord.Box( # width=myCnv.width, # depth=myCnv.depth, # ) myViewPort = Coord.Box( width=Coord.Dim(6, 'in'), depth=Coord.Dim(8, 'in'), ) myTl = Coord.Pt(Coord.Dim(0.25, 'in'), Coord.Dim(0.25, 'in')) myF = io.StringIO() with SVGWriter.SVGWriter(myF, myViewPort) as xS: myT.plotSVG(myTl, Coord.Dim(7.5, 'in'), xS) # print() # print(myF.getvalue()) # self.maxDiff = None self.assertEqual("""<?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="8.000in" version="1.1" width="6.000in" xmlns="http://www.w3.org/2000/svg"> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="3.450in" x2="3.450in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="3.811in" x2="3.811in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.023in" x2="4.023in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.172in" x2="4.172in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.289in" x2="4.289in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.384in" x2="4.384in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.464in" x2="4.464in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.534in" x2="4.534in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.595in" x2="4.595in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="4.650in" x2="4.650in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.011in" x2="5.011in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.223in" x2="5.223in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.372in" x2="5.372in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.489in" x2="5.489in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.584in" x2="5.584in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.664in" x2="5.664in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.734in" x2="5.734in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.795in" x2="5.795in" y1="0.250in" y2="7.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="5.850in" x2="5.850in" y1="0.250in" y2="7.750in"/> </svg> """, myF.getvalue() )
def test_04(self): """TestPlotTrack.test_04(): Construct a lin/log/log track and plot it in SVG.""" myTracks = [ Track.Track(leftPos=Coord.Dim(0.0, 'in'), rightPos=Coord.Dim(2.4, 'in'), gridGn=Track.genLinear10), Track.Track(leftPos=Coord.Dim(3.2, 'in'), rightPos=Coord.Dim(5.6, 'in'), gridGn=Track.genLog10Decade2Start2), Track.Track(leftPos=Coord.Dim(5.6, 'in'), rightPos=Coord.Dim(8, 'in'), gridGn=Track.genLog10Decade2Start2), ] # myCnv = Plot.Canvas(Coord.Dim(8.5, 'in'), Coord.Dim(6, 'in'), Plot.MarginQtrInch) # myViewPort = Coord.Box( # width=myCnv.width, # depth=myCnv.depth, # ) myViewPort = Coord.Box( width=Coord.Dim(6, 'in'), depth=Coord.Dim(8, 'in'), ) myTl = Coord.Pt(Coord.Dim(0.25, 'in'), Coord.Dim(0.25, 'in')) myF = io.StringIO() with SVGWriter.SVGWriter(myF, myViewPort) as xS: for t in myTracks: #xS.comment(str(t)) t.plotSVG(myTl, Coord.Dim(5.5, 'in'), xS) # print() # print(myF.getvalue()) # self.maxDiff = None self.assertEqual( """<?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="8.000in" version="1.1" width="6.000in" xmlns="http://www.w3.org/2000/svg"> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="0.250in" x2="0.250in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="0.490in" x2="0.490in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="0.730in" x2="0.730in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="0.970in" x2="0.970in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="1.210in" x2="1.210in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.500" x1="1.450in" x2="1.450in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="1.690in" x2="1.690in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="1.930in" x2="1.930in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="2.170in" x2="2.170in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="2.410in" x2="2.410in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="2.650in" x2="2.650in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="3.450in" x2="3.450in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="3.661in" x2="3.661in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="3.811in" x2="3.811in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="3.928in" x2="3.928in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.023in" x2="4.023in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.103in" x2="4.103in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.172in" x2="4.172in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.234in" x2="4.234in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="4.289in" x2="4.289in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.650in" x2="4.650in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="4.861in" x2="4.861in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.011in" x2="5.011in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.128in" x2="5.128in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.223in" x2="5.223in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.303in" x2="5.303in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.372in" x2="5.372in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="5.434in" x2="5.434in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="5.489in" x2="5.489in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="5.850in" x2="5.850in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="5.850in" x2="5.850in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="6.061in" x2="6.061in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="6.211in" x2="6.211in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="6.328in" x2="6.328in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="6.423in" x2="6.423in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="6.503in" x2="6.503in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="6.572in" x2="6.572in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="6.634in" x2="6.634in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="6.689in" x2="6.689in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="7.050in" x2="7.050in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="7.261in" x2="7.261in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="7.411in" x2="7.411in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="7.528in" x2="7.528in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="7.623in" x2="7.623in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="7.703in" x2="7.703in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="7.772in" x2="7.772in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.250" x1="7.834in" x2="7.834in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="7.889in" x2="7.889in" y1="0.250in" y2="5.750in"/> <line stroke="black" stroke-opacity="1.000" stroke-width="0.750" x1="8.250in" x2="8.250in" y1="0.250in" y2="5.750in"/> </svg> """, myF.getvalue())
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.maxDiff = None self.assertEqual( """<?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.000cm" version="1.1" width="12.000cm" xmlns="http://www.w3.org/2000/svg"> <desc>Example line01 - lines expressed in user coordinates</desc> <rect fill="none" height="398.000px" stroke="blue" stroke-width="2" width="1198.000px" x="1.000px" y="1.000px"/> <g stroke="green"> <line stroke-width="5" x1="100.000px" x2="300.000px" y1="300.000px" y2="100.000px"/> <line stroke-width="10" x1="300.000px" x2="500.000px" y1="300.000px" y2="100.000px"/> <line stroke-width="15" x1="500.000px" x2="700.000px" y1="300.000px" y2="100.000px"/> <line stroke-width="20" x1="700.000px" x2="900.000px" y1="300.000px" y2="100.000px"/> <line stroke-width="25" x1="900.000px" x2="1100.000px" y1="300.000px" y2="100.000px"/> </g> </svg> """, myF.getvalue())
def test_00(self): """TestPlotTrack.test_00(): Construct a lin/log/log track with FEET 1/200 and plot it in SVG.""" myCnv = Plot.Canvas(Coord.Dim(8.5, 'in'), Coord.Dim(12, 'in'), PlotConstants.MarginQtrInch) myViewPort = Coord.Box( width=myCnv.width, depth=myCnv.depth, ) myTopLeft = Coord.Pt(Coord.Dim(0.25, 'in'), Coord.Dim(0.25, 'in')) myF = io.StringIO() myTracks = [ Track.Track(leftPos=Coord.Dim(0.0, 'in'), rightPos=Coord.Dim(2.4, 'in'), gridGn=Track.genLinear10), Track.Track( leftPos=Coord.Dim(2.4, 'in'), rightPos=Coord.Dim(3.2, 'in'), gridGn=None, plotXAxis=True, ), Track.Track(leftPos=Coord.Dim(3.2, 'in'), rightPos=Coord.Dim(5.6, 'in'), gridGn=Track.genLog10Decade2Start2), Track.Track(leftPos=Coord.Dim(5.6, 'in'), rightPos=Coord.Dim(8, 'in'), gridGn=Track.genLog10Decade2Start2), ] with SVGWriter.SVGWriter(myF, myViewPort) as xS: # Do tracks first for t in myTracks: #xS.comment(str(t)) if t.hasGrid: t.plotSVG( myTopLeft, myCnv.depth - myCnv.margins.top - myCnv.margins.bottom, xS, ) # Now XGrid # We are plotting up so xPosStart is at bottom myXposStart = myCnv.depth - myCnv.margins.bottom myXposStop = myCnv.margins.top myXg = XGrid.XGrid(200) # Plot depth lines for pos, stroke in myXg.genXPosStroke(xFrom=4307.5, xInc=False, units=b'FEET'): myXpos = myXposStart + pos if myXpos < myXposStop: break for t in myTracks: if t.hasGrid: with SVGWriter.SVGLine( xS, Coord.Pt(t.left + myCnv.margins.left, myXpos), Coord.Pt(t.right + myCnv.margins.left, myXpos), attrs=Stroke.retSVGAttrsFromStroke(stroke)): pass # Plot depth text textAttrs = { 'text-anchor': 'end', 'dominant-baseline': 'middle', } for pos, val in myXg.genXPosText(xFrom=4307.5, xInc=False, units=b'FEET'): myXpos = myXposStart + pos if myXpos < myXposStop: break for t in myTracks: if t.plotXAxis: myPt = Coord.Pt( t.right + myCnv.margins.left - Coord.Dim(0.05, 'in'), myXpos) with SVGWriter.SVGText(xS, myPt, 'Courier', 16, textAttrs): xS.characters(str(val)) print() print(myF.getvalue())