Is there a way to override the histogram function? #1608
Unanswered
frosencrantz
asked this question in
Q&A
Replies: 1 comment 6 replies
-
I was able to override it by creating a plugin with the following code. When a histogram is created it adds the status message 'hello from histogram'. The code is a copy-pasted from visidata import AttrColumn, asyncthread, Column, status, vlen, vd
from visidata.freqtbl import FreqTableSheet
from visidata.pivot import PivotSheet
@asyncthread
def reloadPatch(self):
'Generate frequency table then reverse-sort by length.'
PivotSheet.initCols(self) # changed from super().initCols()
# add default bonus columns
for c in [
AttrColumn('count', 'sourcerows', type=vlen),
Column('percent', type=float, getter=lambda col,row: len(row.sourcerows)*100/col.sheet.source.nRows),
]:
self.addColumn(c)
if self.options.disp_histolen and self.options.disp_histogram:
def histogram(col, row):
vd.status("hello from histogram")
histogram = col.sheet.options.disp_histogram
histolen = col.sheet.options.disp_histolen
return histogram*(histolen*len(row.sourcerows)//col.sheet.largest)
c = Column('histogram', type=str, getter=histogram, width=self.options.disp_histolen+2)
self.addColumn(c)
# two more threads
vd.sync(self.addAggregateCols(),
self.groupRows(self.updateLargest))
if self.nCols > len(self.groupByCols)+3: # hide percent/histogram if aggregations added
self.column('percent').hide()
self.column('histogram').hide()
if not [c for c in self.groupByCols if vd.isNumeric(c)]:
self.orderBy(self.column('count'), reverse=True)
FreqTableSheet.reload = reloadPatch |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How does one override the histogram function for the FreqSheet?
visidata/visidata/freqtbl.py
Lines 55 to 58 in 25a412a
I was wondering how hard it would be to change the function to use the Unicode block characterswe to get a smoother graph.
Beta Was this translation helpful? Give feedback.
All reactions