def writeToFile(self, outfile):
        """write svg image to file.
        """
        self.finalizePlot()

        self.mRoot = SVGdraw.drawing()
        self.mDraw = SVGdraw.svg( (0, 0, self.mPageWidth, self.mPageHeight ) , "100%", "100%" )

        kk = self.mElements.keys()
        kk.sort()
        kk.reverse()
        for k in kk:
            for e in self.mElements[k]:
                self.mDraw.addElement( e )
            
        self.mRoot.setSVG(self.mDraw)

        tfile = tempfile.mktemp()
        
        self.mRoot.toXml( tfile )

        lines = open(tfile,"r").readlines()
        
        outfile.write(string.join(lines,""))
        outfile.write("\n")
        
        os.remove(tfile)
Exemple #2
0
def errorsvg(msg):
    s=SVGdraw.svg(width='5cm', height='1cm')
    s.addElement(SVGdraw.text(0,0,msg))
    d=SVGdraw.drawing()
    d.svg=s
    print d.toXml()
    return s
Exemple #3
0
def errorsvg(msg):
    s = SVGdraw.svg(width='5cm', height='1cm')
    s.addElement(SVGdraw.text(0, 0, msg))
    d = SVGdraw.drawing()
    d.svg = s
    print d.toXml()
    return s
Exemple #4
0
    def writeToFile(self, outfile):
        """write svg image to file.
        """
        self.finalizePlot()

        kk = self.mElements.keys()
        kk.sort()
        kk.reverse()

        ## make sure the image size is ok
        min_x, min_y, max_x, max_y = 0, 0, 0, 0
        
        for k in kk:
            for e in self.mElements[k]:
                for x in ('x', 'x2', 'x1'):
                    if x in e.attributes:
                        v = e.attributes[x] 
                        min_x = min(min_x, v )
                        max_x = max(max_x, v )
                for y in ('y', 'y2', 'y1'):
                    if y in e.attributes:
                        v = e.attributes[y]
                        min_y = min(min_y, v )
                        max_y = max(max_y, v )

        min_x, min_y = int(math.floor(min_x)), int(math.floor(min_y))
        max_x, max_y = int(math.floor(max_x)), int(math.floor(max_y))        

        for k in kk:
            for e in self.mElements[k]:
                for x in ('x', 'x2', 'x1'):
                    if x in e.attributes:
                        e.attributes[x] -= min_x
                for x in ('y', 'y2', 'y1'):
                    if y in e.attributes:
                        e.attributes[y] -= min_y

        ## now add all the elements
        self.mRoot = SVGdraw.drawing()
        self.mDraw = SVGdraw.svg( (0, 0, self.mPageWidth - min_x, self.mPageHeight - min_y ) , "100%", "100%" )
                        
        for k in kk:
            for e in self.mElements[k]:
                self.mDraw.addElement( e )
            
        self.mRoot.setSVG(self.mDraw)

        tfile = tempfile.mktemp()
        
        self.mRoot.toXml( tfile )

        lines = open(tfile,"r").readlines()
        
        outfile.write(string.join(lines,""))
        outfile.write("\n")
        
        os.remove(tfile)
Exemple #5
0
	def save(self, filename=None):
		document = SVGdraw.drawing()
		width = str(self.width) + self.units
		height = str(self.height) + self.units
		canvas = SVGdraw.svg(None, width, height)

		self.makeGrid(canvas)

		document.setSVG(canvas)

		if filename:
			document.toXml(filename)
		else:
			return document.toXml()
Exemple #6
0
    def save(self, filename=None):
        document = SVGdraw.drawing()
        width = str(self.width) + self.units
        height = str(self.height) + self.units
        canvas = SVGdraw.svg(None, width, height)

        canvas.addElement(SVGdraw.description(self.description))

        self.makeGrid(canvas)

        document.setSVG(canvas)

        if filename:
            document.toXml(filename)
        else:
            return document.toXml()
    def plot(self,
             filename,
             segments,
             workspace,
             samples):
        nlines = 2 + len(samples)

        height = nlines * self.linewidth * self.linespace

        width = workspace.max()

        print(height, width)

        root = SVGdraw.drawing()
        canvas = SVGdraw.svg((0, 0, width, heigh), "100%", "100%")

        root.setSVG(canvas)

        root.toXml(filename)
    def plot(self, 
             filename,
             segments,
             workspace,
             samples ):
        nlines = 2 + len(samples)
        
        height = nlines * self.linewidth * self.linespace

        width = workspace.max()
        
        print height, width
    
        root = SVGdraw.drawing()
        canvas = SVGdraw.svg( (0, 0, width, heigh), "100%", "100%")

        root.setSVG( canvas )

        root.toXml( filename )
	def toSVG(self):
		#modification du maximum en X : depend du nombre d'element
		global XMAX
		XMAX = len(self.infos)*(BAR_THICKNESS+SPACE)
		# creation du document
		doc=SVGdraw.drawing()
		svg=SVGdraw.svg(None, '100%','100%')
		
		# creation des patterns pour les axes et la grille
		axeX = SVGdraw.pattern(id="axeX",width="20",height="10",patternUnits="userSpaceOnUse")
		axeX.addElement(SVGdraw.path("M 0 0, L 0 10","none","black","0.25"))
		axeX.addElement(SVGdraw.path("M 10 10, V 5","none","lightgray","0.25"))
		axeY = SVGdraw.pattern(id="axeY",width="10",height="20",patternUnits="userSpaceOnUse")
		axeY.addElement(SVGdraw.path("M 0 0, L 10 0","none","black","0.25"))
		axeY.addElement(SVGdraw.path("M 5 10, L 10 10","none","lightgray","0.25"))
		grid = SVGdraw.pattern(id="grid",width="10",height="10",patternUnits="userSpaceOnUse")
		grid.addElement(SVGdraw.path("M 0 0, L 10 0, L 10 10,L 0 10, L 0 0","none","lightgray","0.25"))

		defs=SVGdraw.defs()
		defs.addElement(axeX)
		defs.addElement(axeY)
		defs.addElement(grid)
		svg.addElement(defs)
		
		group=SVGdraw.group(transform="translate(130,130) scale(1,-1)")
		
		# dessin de la grille de fond
		group.addElement(SVGdraw.rect(0,0,XMAX,YMAX,"url(#grid)","lightgray","0.25"))
	
		# dessin des axes
		group.addElement(SVGdraw.rect(0,-10,XMAX,10,"url(#axeX)"))
		group.addElement(SVGdraw.rect(-10,0,10,YMAX,"url(#axeY)"))
		group.addElement(SVGdraw.line(0,0,XMAX,0,"black",1))
		group.addElement(SVGdraw.line(0,0,0,YMAX,"black",1))
		# dessin des fleches des axes
		group.addElement(SVGdraw.polygon([[-3,YMAX],[3,YMAX],[0,YMAX+10]], "black","white"))
		group.addElement(SVGdraw.polygon([[XMAX,-3],[XMAX,3],[XMAX+10,0]], "black","white"))
		
		textgroup=SVGdraw.group(transform="scale(1,-1)")
		# graduations
		for y in range(0,YMAX+STEP,STEP):
			textgroup.addElement(SVGdraw.text(-STEP,y, str(y), 8, text_anchor="middle", transform="translate(0,%d)"%(-y*2)))
		textgroup.addElement(SVGdraw.text(0,YMAX+SPACE, r"%", 8, transform="translate(0,%d)"%(-(YMAX+SPACE)*2)))
		
		# ajout de la legende principale
		legendText = "Repertoire %s - taille %.02f ko"%(self.rootName,float(self.totalSize/1024.0))
		textgroup.addElement(SVGdraw.text(XMAX,YMAX+3*SPACE, legendText,12, "verdana", 
			text_anchor="end", fill="darkblue",transform="translate(0,%d)"%(-(YMAX+3*SPACE)*2)))
		
		group.addElement(textgroup)
		
		# tri des elements selon la taille occupee
		self.infos.sort(self.tupleCmp)
		
		xincr=0
		#self.infos
		for (name,size) in self.infos:
			# calcul du pourcentage de place occupe
			pourcent = (100.0*float(size))/float(self.totalSize)
			height=int(pourcent*YMAX/100);
			# insertion du texte de l'emplacement sur le disque et de la taille occupee en Ko
			legendText = "%s (%### ###.02f ko)"%(name,float(size/1024.0))
			legend = SVGdraw.text(xincr+BAR_THICKNESS/2, -10,legendText,8,"verdana",text_anchor="begin",fill="blue")
			legend.attributes["transform"]="scale(1,-1) translate(0,20) rotate(45,%d,-10)"%(xincr+BAR_THICKNESS/2)
			group.addElement(legend)
			
			#insertion de la barre representant le pourcentage
			group.addElement(SVGdraw.rect(xincr,0,BAR_THICKNESS, height,"green","black",opacity=0.5))
			
			#insertion de la taille en pourcentage a gauche de la barre
			pourcentText=SVGdraw.text(xincr+BAR_THICKNESS/2, height+SPACE,"%02.01f%% "%pourcent,6,
				"arial", text_anchor="middle", fill="black")
			pourcentText.attributes["transform"]="scale(1,-1) translate(0,-%d)"%((height+SPACE)*2)
			group.addElement(pourcentText)
			# augmentation du l'abscisse en X
			xincr = xincr+BAR_THICKNESS+SPACE
			
		svg.addElement(group)
		doc.setSVG(svg)
		doc.toXml(self.svgURL)
Exemple #10
0
 def save(self, filename):
     """Save the revision tree in a file"""
     d = SVG.drawing()
     d.setSVG(self._svg)
     d.toXml(filename)
Exemple #11
0
 def format(self):
     d = SVGdraw.drawing()
     d.setSVG(self.sd)
     return d.toXml()
Exemple #12
0
def out2file(knot, filename, *args, **kwargs):
    f = open(filename, "w")
    d = SVGdraw.drawing()
    d.svg = knot.svgout(*args, **kwargs)
    f.write(d.toXml())
    f.close
Exemple #13
0
    if opts.has_key("-r") or opts.has_key("--radius"):
        rad = float(opts.get("-r") or opts["--radius"])
        if opts.has_key("--circle-scale"):
            circscale = float(opts['--circle-scale'])
    else:
        rad = None
    if opts.has_key("-k") or opts.has_key("--knot-only"):
        # Don't output the svg, just the knot.
        print str(k)
        exit(0)
    s = k.svgout(
        crossings=not (opts.has_key('-n') or opts.has_key('--nocrossings')),
        coloriter=citer,
        circradius=rad,
        circscale=circscale)
    d = SVGdraw.drawing()
    d.svg = s
    print d.toXml()

# An irregular one I found experimenting:
# [(1,1),(2,4),(3,1),(4,16),(5,1),(6,10),(6,4),(7,1),(9,9),(9,1),(10,4),(11,1),(13,9),(13,1),(15,1),(16,8),(17,1),(19,1),(21,11),(21,7),(21,1),(22,4),(23,1),(25,1),(26,4),(27,1),(28,16),(28,12),(29,1),(30,6),(30,4),(31,1)]
# (16 wide, but make sure it's tall enough!)

# An interesting conundrum:
# [(0,2),(0,0),(4,2),(4,0),(5,17),(5,13),(5,9),(5,5),(8,2),(8,0),(11,17),(11,13),(11,9),(11,5),(12,2),(12,0)]
# Irregular bottom.  Length of bottom != wrap zone (I think).  Says it's
# not tyable, but is it?  If I set the xmodulus to 16 by hand, it's fine;
# generates an SVG and all, tyable in 4 strands.  But as it is, the program
# sets the xmodulus to 14.
# XXXXX But its svg file looks like it has bad crossings!
Exemple #14
0
def out2file(knot, filename, *args, **kwargs):
    f=open(filename,"w")
    d=SVGdraw.drawing()
    d.svg=knot.svgout(*args,**kwargs)
    f.write(d.toXml())
    f.close
Exemple #15
0
            citer=citergen()
    circscale=1
    if opts.has_key("-r") or opts.has_key("--radius"):
        rad=float(opts.get("-r") or opts["--radius"])
        if opts.has_key("--circle-scale"):
            circscale=float(opts['--circle-scale'])
    else:
        rad=None
    if opts.has_key("-k") or opts.has_key("--knot-only"):
        # Don't output the svg, just the knot.
        print str(k)
        exit(0)
    s=k.svgout(crossings=not (opts.has_key('-n') or 
                              opts.has_key('--nocrossings')),
               coloriter=citer,circradius=rad,circscale=circscale)
    d=SVGdraw.drawing()
    d.svg=s
    print d.toXml()

# An irregular one I found experimenting:
# [(1,1),(2,4),(3,1),(4,16),(5,1),(6,10),(6,4),(7,1),(9,9),(9,1),(10,4),(11,1),(13,9),(13,1),(15,1),(16,8),(17,1),(19,1),(21,11),(21,7),(21,1),(22,4),(23,1),(25,1),(26,4),(27,1),(28,16),(28,12),(29,1),(30,6),(30,4),(31,1)]
# (16 wide, but make sure it's tall enough!)

# An interesting conundrum: 
# [(0,2),(0,0),(4,2),(4,0),(5,17),(5,13),(5,9),(5,5),(8,2),(8,0),(11,17),(11,13),(11,9),(11,5),(12,2),(12,0)]
# Irregular bottom.  Length of bottom != wrap zone (I think).  Says it's 
# not tyable, but is it?  If I set the xmodulus to 16 by hand, it's fine;
# generates an SVG and all, tyable in 4 strands.  But as it is, the program
# sets the xmodulus to 14.
# XXXXX But its svg file looks like it has bad crossings!