Skip to content

Commit

Permalink
[canvas- graph-] combine resetBounds and refresh
Browse files Browse the repository at this point in the history
And recalculate/redraw more of the graph view after changes like
zooming/moving.
  • Loading branch information
midichef committed Aug 24, 2024
1 parent ad37075 commit 492fecb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions visidata/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,14 @@ def fixPoint(self, plotterPoint, canvasPoint):
'adjust visibleBox.xymin so that canvasPoint is plotted at plotterPoint'
self.visibleBox.xmin = canvasPoint.x - self.canvasW(plotterPoint.x-self.plotviewBox.xmin)
self.visibleBox.ymin = canvasPoint.y - self.canvasH(plotterPoint.y-self.plotviewBox.ymin)
self.refresh()
self.resetBounds()

def zoomTo(self, bbox):
'set visible area to bbox, maintaining aspectRatio if applicable'
self.fixPoint(self.plotviewBox.xymin, bbox.xymin)
self.xzoomlevel=bbox.w/self.canvasBox.w
self.yzoomlevel=bbox.h/self.canvasBox.h
self.resetBounds()

def incrZoom(self, incr):
self.xzoomlevel *= incr
Expand Down Expand Up @@ -702,10 +703,11 @@ def refresh(self):

def render(self, h, w):
'resets plotter, cancels previous render threads, spawns a new render'
self.needsRefresh = False
vd.cancelThread(*(t for t in self.currentThreads if t.name == 'plotAll_async'))
self.labels.clear()
self.resetCanvasDimensions(h, w)
self.resetBounds() # sets needsRefresh to True
self.needsRefresh = False # must not happen before resetBounds()
self.render_async()

@asyncthread
Expand Down Expand Up @@ -798,7 +800,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
4 changes: 2 additions & 2 deletions visidata/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def fixPoint(self, plotterPoint, canvasPoint):
'adjust visibleBox.xymin so that canvasPoint is plotted at plotterPoint'
self.visibleBox.xmin = canvasPoint.x - self.canvasW(plotterPoint.x-self.plotviewBox.xmin)
self.visibleBox.ymin = canvasPoint.y - self.canvasH(self.plotviewBox.ymax-plotterPoint.y)
self.refresh()
self.resetBounds()

def rowsWithin(self, plotter_bbox):
return super().rowsWithin(plotter_bbox, invert_y=True)
Expand All @@ -36,6 +36,7 @@ def zoomTo(self, bbox):
super().zoomTo(bbox)
self.fixPoint(Point(self.plotviewBox.xmin, self.plotviewBox.ymin),
Point(bbox.xmin, bbox.ymax + 1/4*self.canvasCharHeight))
self.resetBounds()

def scaleY(self, canvasY) -> int:
'returns a plotter y coordinate for a canvas y coordinate, with the y direction inverted'
Expand Down Expand Up @@ -122,7 +123,6 @@ def reload(self):

self.xzoomlevel=self.yzoomlevel=1.0
self.resetBounds()
self.refresh()

def draw(self, scr):
windowHeight, windowWidth = scr.getmaxyx()
Expand Down

0 comments on commit 492fecb

Please sign in to comment.