Skip to content

Commit

Permalink
[canvas- graph-] combine resetBounds and refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef authored and saulpw committed Oct 4, 2024
1 parent 87e635a commit 21e89bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions visidata/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def incrZoom(self, incr):

self.resetBounds()

def resetBounds(self):
def resetBounds(self, refresh=True):
'create canvasBox and cursorBox if necessary, and set visibleBox w/h according to zoomlevels. then redisplay legends.'
if not self.canvasBox:
xmin, ymin, xmax, ymax = None, None, None, None
Expand Down Expand Up @@ -595,6 +595,8 @@ def resetBounds(self):
self.cursorBox = Box(cb_xmin, cb_ymin, self.canvasCharWidth, self.canvasCharHeight)

self.plotlegends()
if refresh:
self.refresh()

def calcTopCursorY(self):
'ymin for the cursor that will align its top with the top edge of the graph'
Expand Down Expand Up @@ -706,6 +708,7 @@ def render(self, h, w):
vd.cancelThread(*(t for t in self.currentThreads if t.name == 'plotAll_async'))
self.labels.clear()
self.resetCanvasDimensions(h, w)
self.resetBounds(refresh=False)
self.render_async()

@asyncthread
Expand Down Expand Up @@ -798,7 +801,7 @@ def deleteSourceRows(self, rows):

Canvas.addCommand('-', 'zoomout-cursor', 'tmp=cursorBox.center; incrZoom(options.disp_zoom_incr); fixPoint(plotviewBox.center, tmp)', 'zoom out from cursor center')
Canvas.addCommand('+', 'zoomin-cursor', 'tmp=cursorBox.center; incrZoom(1.0/options.disp_zoom_incr); fixPoint(plotviewBox.center, tmp)', 'zoom into cursor center')
Canvas.addCommand('_', 'zoom-all', 'sheet.canvasBox = None; sheet.visibleBox = None; sheet.xzoomlevel=sheet.yzoomlevel=1.0; resetBounds(); refresh()', 'zoom to fit full extent')
Canvas.addCommand('_', 'zoom-all', 'sheet.canvasBox = None; sheet.visibleBox = None; sheet.xzoomlevel=sheet.yzoomlevel=1.0; resetBounds()', 'zoom to fit full extent')
Canvas.addCommand('z_', 'set-aspect', 'sheet.aspectRatio = float(input("aspect ratio=", value=aspectRatio)); refresh()', 'set aspect ratio')

# set cursor box with left click
Expand Down
6 changes: 4 additions & 2 deletions visidata/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ def draw_reflines(self, scr):
cattr = update_attr(cattr, colors.color_current_row)
scr.addstr(char_y, char_x, ch, cattr.attr)

def resetBounds(self):
super().resetBounds()
def resetBounds(self, refresh=True):
super().resetBounds(refresh=False)
self.createLabels()
if refresh:
self.refresh()

def moveToRow(self, rowstr):
ymin, ymax = map(float, map(self.parseY, rowstr.split()))
Expand Down

0 comments on commit 21e89bf

Please sign in to comment.