Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update generated svg format for ubuntu Image Viewer #15

Open
wants to merge 1 commit into
base: release1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/bargraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def make_svg_bargraph(labels, heights, categories,
barheight=100, barwidth=12, show_labels=True, filename=None):
unitheight = float(barheight) / max(heights)
textheight = barheight if show_labels else 0
labelsize = float(barwidth)
labelsize = int(barwidth)
gap = float(barwidth) / 4
textsize = barwidth + gap
rollup = max(heights)
Expand All @@ -129,15 +129,15 @@ def make_svg_bargraph(labels, heights, categories,
# Add units scale on left
for h in [1, (max(heights) + 1) // 2, max(heights)]:
et.SubElement(svg, 'text', x='0', y='0',
style=('font-family:sans-serif;font-size:%dpx;text-anchor:end;'+
'alignment-baseline:hanging;' +
'transform:translate(%dpx, %dpx);') %
(textsize, x - gap, basey - h * unitheight)).text = str(h)
transform='translate({:d}, {:d})'.format(int(x - gap), int(basey - h * unitheight)),
style=('font-family:sans-serif;font-size:{:d};text-anchor:end;'\
.format(int(textsize))+
'alignment-baseline:hanging')
).text = str(h)
et.SubElement(svg, 'text', x='0', y='0',
style=('font-family:sans-serif;font-size:%dpx;text-anchor:middle;'+
'transform:translate(%dpx, %dpx) rotate(-90deg)') %
(textsize, x - gap - 1.2 * textsize, basey - h * unitheight / 2)
).text = 'units'
transform='translate({:d}, {:d}) rotate(-90)'.format( int(x - gap - 1.2 * textsize), int(basey - h * unitheight / 2.0)),
style=('font-family:sans-serif;font-size:{:d};text-anchor:middle'.format(int(textsize)))
).text = 'units'
# Draw big category background rectangles
for catindex, (cat, catcount) in enumerate(categories):
if not catcount:
Expand All @@ -162,9 +162,9 @@ def make_svg_bargraph(labels, heights, categories,
x += barwidth
if show_labels:
et.SubElement(svg, 'text', x='0', y='0',
style=('font-family:sans-serif;font-size:%dpx;text-anchor:end;'+
'transform:translate(%dpx, %dpx) rotate(-45deg);') %
(labelsize, x, basey + textmargin)).text = fix(label)
transform="translate({:d}, {:d}) rotate(-45)".format(int(x), int(basey + textmargin)),
style=('font-family:sans-serif;font-size:{:d};text-anchor:end'.format(labelsize))
).text = fix(label)
x += gap
catcount -= 1
# Text lables for each category
Expand All @@ -173,11 +173,12 @@ def make_svg_bargraph(labels, heights, categories,
if not catcount:
continue
et.SubElement(svg, 'text', x='0', y='0',
style=('font-family:sans-serif;font-size:%dpx;text-anchor:end;'+
'transform:translate(%dpx, %dpx) rotate(-90deg);') %
(textsize, x + (barwidth + gap) * catcount - gap,
basey - rollup * unitheight + gap)).text = '%d %s' % (
catcount, fix(cat + ('s' if catcount != 1 else '')))
transform="translate({:d}, {:d}) rotate(-90)"\
.format(int(x + (barwidth + gap) * catcount - gap),
int(basey - rollup * unitheight + gap)),
style=('font-family:sans-serif;font-size:{:d};text-anchor:end'.format(int(textsize)))
).text = '{:d} {:s}'.format(
int(catcount), fix(cat + ('s' if catcount != 1 else '')))
x += (barwidth + gap) * catcount
# Output - this is the bare svg.
result = et.tostring(svg)
Expand Down