Skip to content

Commit

Permalink
add fit graph button
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Coder committed Jul 31, 2024
1 parent 16b936f commit 1ad00bc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ogdf_python/matplotlib/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def update_all(self, autoscale=True):
if e in self.edge_styles:
self.update_edge(e)
if autoscale:
self.ax.ignore_existing_data_limits = True
for col in chain((s.coll for s in self.style_nodes.values()), (s.coll for s in self.style_edges.values())):
self.ax.update_datalim(col.get_datalim(self.ax.transData).get_points())
self.ax.autoscale_view()
Expand All @@ -161,7 +162,7 @@ def update_all(self, autoscale=True):
def apply_style(self):
self.ax.set_aspect(1, anchor="C", adjustable="datalim")
self.ax.update_datalim([(0, 0), (100, 100)])
self.ax.autoscale()
self.ax.autoscale(enable=True, axis="both")
self.ax.invert_yaxis()
fig = self.ax.figure
fig.canvas.header_visible = False
Expand All @@ -172,9 +173,17 @@ def apply_style(self):
def update(*args, **kwargs):
self.update_all()

def expand(*args, **kwargs):
# autoscale gets disabled by panning
self.ax.autoscale(enable=True, axis="both")
self.update_all(autoscale=True)

fig.canvas.toolbar.update_ogdf_graph = update
fig.canvas.toolbar.expand_ogdf_graph = expand
fig.canvas.toolbar.toolitems = [*fig.canvas.toolbar.toolitems,
("Update", "Update the Graph", "refresh", "update_ogdf_graph")]
("Update", "Update the Graph", "refresh", "update_ogdf_graph"),
("Fit Graph", "Show the full graph", "expand",
"expand_ogdf_graph")] # arrows-alt
fig.canvas.toolbar_visible = 'visible'

def hide_spines(self):
Expand Down

0 comments on commit 1ad00bc

Please sign in to comment.