break pie chart into separate function
This commit is contained in:
parent
a7879677dd
commit
37546c5021
1 changed files with 38 additions and 34 deletions
46
smem
46
smem
|
|
@ -390,12 +390,35 @@ def showtable(rows, fields, columns, sort):
|
|||
l.sort(reverse=bool(options.reverse))
|
||||
|
||||
if options.pie:
|
||||
showpie(l, sort)
|
||||
return
|
||||
|
||||
if not options.no_header:
|
||||
print header
|
||||
|
||||
for k,r in l:
|
||||
print format % tuple([f(v) for f,v in zip(formatter, r)])
|
||||
|
||||
if options.totals:
|
||||
# totals
|
||||
t = []
|
||||
for c in columns:
|
||||
f = fields[c][3]
|
||||
if f:
|
||||
t.append(f([fields[c][1](n) for n in rows]))
|
||||
else:
|
||||
t.append("")
|
||||
|
||||
print "-" * len(header)
|
||||
print format % tuple([f(v) for f,v in zip(formatter, t)])
|
||||
|
||||
def showpie(l, sort):
|
||||
if (l[0][0] < l[-1][0]):
|
||||
l.reverse()
|
||||
try:
|
||||
import pylab
|
||||
except ImportError:
|
||||
sys.write.stderr("pie chart requires matplotlib")
|
||||
sys.stderr.write("pie chart requires matplotlib\n")
|
||||
sys.exit(-1)
|
||||
|
||||
labels = [r[1][-1] for r in l]
|
||||
|
|
@ -422,27 +445,8 @@ def showtable(rows, fields, columns, sort):
|
|||
ax = pylab.axes([0.1, 0.1, 0.8, 0.8])
|
||||
pylab.pie(values, explode = explode, labels=labels,
|
||||
autopct="%.2f%%", shadow=True)
|
||||
pylab.title('%s by %s' % (options.pie, sort))
|
||||
pylab.show()
|
||||
sys.exit(1)
|
||||
|
||||
if not options.no_header:
|
||||
print header
|
||||
|
||||
for k,r in l:
|
||||
print format % tuple([f(v) for f,v in zip(formatter, r)])
|
||||
|
||||
if options.totals:
|
||||
# totals
|
||||
t = []
|
||||
for c in columns:
|
||||
f = fields[c][3]
|
||||
if f:
|
||||
t.append(f([fields[c][1](n) for n in rows]))
|
||||
else:
|
||||
t.append("")
|
||||
|
||||
print "-" * len(header)
|
||||
print format % tuple([f(v) for f,v in zip(formatter, t)])
|
||||
|
||||
parser = optparse.OptionParser("%prog [options]")
|
||||
parser.add_option("-H", "--no-header", action="store_true",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue