Reputation: 943
I'm trying to rotate text, and that part is working fine, but I want it to be right-justified and not left. In other words I want the text to end on the perimeter of the circle that I have calculated, not begin. This code draws a circle with 365 ticks on it, with a longer tick each 7 days, and each 7th day number inscribed inside the circle of tick marks.
My code does this:
What I want is this:
import math
import svgwrite
radius_inner = 200
radius_width = 40
radius_outer = radius_inner + radius_width
week_line_start = 10
day_line_start = 16
line_end = 10
day_font_size=15
days = 365
dwg = svgwrite.Drawing('YearWheel.svg')
for i in range(0,days):
angle = (math.pi*2 / days) * i
if i % 7 == 0:
startr = week_line_start
else:
startr = day_line_start
startx = math.sin(angle) * (radius_inner + startr)
endx = math.sin(angle) * (radius_outer - line_end)
starty = -math.cos(angle) * (radius_inner + startr)
endy = -math.cos(angle) * (radius_outer - line_end)
print("({},{}),({},{})".format(startx,starty,endx,endy))
dwg.add(dwg.line((startx,starty), (endx,endy), stroke=svgwrite.rgb(10, 10, 16, '%')))
if i > 0 and i % 7 == 0:
rot = 'rotate({},{}, {})'.format(math.degrees(angle)-90,startx,starty)
dwg.add(dwg.text("{}".format(i), insert=(startx,starty), transform=rot, font_size='{}px'.format(day_font_size)))
dwg.save()
I tried adding ,style="text-align:end"
to the text()
call (saw that mentioned elsewhere on stackoverflow) but that makes no difference.
Ideally I would like the numbers centered "vertically" with the lines as well.
My initial post reported that the style element was causing an error. This was due to one version of my code having , profile='tiny'
in the svgwrite.Drawing
constructor.
Upvotes: 1
Views: 1174
Reputation: 943
I have fixed the right-align, and worked around the centring:
dwg.add( dwg.text( "{}".format(i)
, insert=(startx,starty)
, transform=rot
, style="text-anchor:end;baseline-shift:-33%"
, font_size="{}px".format(day_font_size)
) )
text-anchor
was the style element I was looking for, not text-align
.
baseline-shift
of around -33% gives me the appearance of it being centred, and that's good enough for me.
Upvotes: 1