Beispiel #1
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
 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())