Files
@ c95fa8ab1067
Branch filter:
Location: Diana/src/diana/drawer/svg.py - annotation
c95fa8ab1067
1.2 KiB
text/x-python
changed imports
616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 fdd10bc51cf8 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 616c96178973 fdd10bc51cf8 fdd10bc51cf8 fdd10bc51cf8 616c96178973 616c96178973 616c96178973 fdd10bc51cf8 616c96178973 fdd10bc51cf8 616c96178973 616c96178973 616c96178973 | from .base import Base
def adjustFont(base,text):
text=str(text)
if len(text)<2: return round(0.7*base)
elif len(text)<3: return round(0.55*base)
else: return round(0.4*base)
class DiagramPoint:
def __init__(self,x,y,color="",label=""):
self.x=x
self.y=y
self.color=color
self.label=label
def __repr__(self):
return 'DiagramPoint({0},{1},"{2}","{3}")'.format(self.x,self.y,self.color,self.label)
class Svg(Base):
extension="svg"
padding=15
highNumbers=True
def __init__(self,start=0):
super().__init__(start)
self.boardSize=480
self.padding=30
def render(self,templateName,bgcolor=""):
points = [p for (i,p) in sorted(self._index.values(), key=lambda x: x[0])]
stones = [p for p in points if p.color and p.label==""]
moves = [p for p in points if p.color and p.label]
labels = [p for p in points if not p.color and p.label]
params = {
"boardSize":self.boardSize, "padding":self.padding, "stones":stones, "moves":moves,
"labels":labels, "adjustFont":adjustFont, "bgcolor":bgcolor}
return self._env.get_template(templateName).render(params)
def save(self,filename,template="templ.svg",bgcolor=""):
file=open(filename+".svg",'w')
file.write(self.render(template,bgcolor))
file.close()
super().save(filename)
|