Skip to content

Commit

Permalink
[canvas- graph-] recalculate view after zooming/moving it
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef committed Aug 26, 2024
1 parent 00176bc commit f4aea55
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion 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
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 f4aea55

Please sign in to comment.