+def display_histogram(hist, fullname=True):
+ maxlen = max(list(map(len, iter(hist.keys()))))
+ maxnum = max(hist.values())
+ name_len = min(maxlen, MAX_NAME_LEN)
+ count_len = floor(log10(maxnum) + 1)
+
+ # Tic-per-count or scale all tics proportionally
+ maxtics = opt.width - name_len - count_len - 3 #magic num from line format 'ps'
+ if maxnum > maxtics:
+ def tics(n):
+ return int(maxtics*(float(n)/maxnum))
+ else:
+ def tics(n):
+ return n
+
+ ps = '%%-%is (%%%ii)%%s' % (name_len, count_len)
+ for tag,v in sorted(iter(hist.items()), key=sorter):
+ if v < 1: continue
+
+ if len(tag) > MAX_NAME_LEN:
+ tag = tag[:MAX_NAME_LEN-1] + '~'
+
+ if not fullname:
+ t = tag.split('.')
+ for i in range(len(t)-1):
+ t[i] = ' ' * len(t[i])
+ tag = '.'.join(t)
+ if opt.sep == '':
+ print(ps % (tag, v, '+'*tics(v)))
+ else:
+ print(opt.sep.join((tag, str(v))))