Esempio n. 1
0
 def plotLine(self, ptFrom, ptTo, stroke):
     """Plots a line. Points are Coord.Pt objects. theStroke is a Plot.Stroke object."""
     with SVGWriter.SVGLine(self._svg,
                            ptFrom,
                            ptTo,
                            attrs=self._retSVGAttrsFromStroke(stroke)):
         pass
Esempio n. 2
0
 def plotSVG(self, topLeft, depth, theSVGWriter):
     """Plot the track gridlines.
     topLeft - A Coord.Pt() object that is the top left of the canvas.
     depth - A Coord.Dim() object that is the total depth of the grid below topLeft.
     drive - The plot driver."""
     if self._gridGn is not None:
         botLeft = Coord.newPt(topLeft, incY=depth)
         for stroke, pos in self._gridGn(self._lP.value, self._rP.value):
             # Compute the line position
             topP = Coord.newPt(topLeft,
                                incX=Coord.Dim(pos, self._lP.units))
             botP = Coord.newPt(botLeft,
                                incX=Coord.Dim(pos, self._lP.units))
             with SVGWriter.SVGLine(
                     theSVGWriter,
                     topP,
                     botP,
                     attrs=Stroke.retSVGAttrsFromStroke(stroke)):
                 pass
Esempio n. 3
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.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())