Fix graph crash on reload, even out depth sizes

This commit is contained in:
sarah committed 2026-10-09 10:00:15 +02:00
1 parent 0372a73dd2
commit d616361c2f
3 files changed
+27 -13

No files matched your search

+18 -9
View File
@@ -220,8 +220,11 @@ class Layout:
# Directories go down the heading colours by depth (h1 Mauve, h2 Blue, ...),
# starting again after Red. Files are White.
DepthColours = ["Mauve", "Blue", "Green", "Yellow", "Peach", "Red"]
ShrinkPerDepth = 0.8 # with GraphShrinkByDepth, each level's directory dots are this much smaller
SmallestDirectory = 3 # ...but never smaller than a file's dot
# With GraphShrinkByDepth, directory dots shrink in even steps from their
# usual size to a file dot's size (a file with one link) at this depth (the
# red ones), and stay that size below it.
ShrinkDepth = 5
FileDotRadius = 3.8
def DirectoryColour(Depth: int) -> str:
@@ -370,17 +373,22 @@ class GraphView(ft.Container):
self.Status.value = "Nothing to show here."
self.Status.update()
return
self.Layout = Layout(Graph)
# This thread keeps its own Layout: a Reload meanwhile (the graph
# opening, or the scope changing) clears self.Layout for its own thread.
Settling = Layout(Graph)
Base = len(Path.split("/")) if Path else 0
self.Depths = np.array([(len(Node["Id"].split("/")) if Node["Id"] else 0) - Base for Node in self.Layout.Nodes])
self.Colours = [(DirectoryColour(int(Depth)) if self.ColourByDepth else Palette.Mauve) if Node["IsDirectory"]
else Palette.White for Node, Depth in zip(self.Layout.Nodes, self.Depths)]
Depths = np.array([(len(Node["Id"].split("/")) if Node["Id"] else 0) - Base for Node in Settling.Nodes])
Colours = [(DirectoryColour(int(Depth)) if self.ColourByDepth else Palette.Mauve) if Node["IsDirectory"]
else Palette.White for Node, Depth in zip(Settling.Nodes, Depths)]
if Generation != self.Generation or self.Closed:
return
self.Layout, self.Depths, self.Colours = Settling, Depths, Colours
self.StatusBox.visible = False
self.StatusBox.update()
# Settle in steps, drawing as it goes, like the web view's animation.
while not self.Layout.Settled:
while not Settling.Settled:
for _ in range(TicksPerDraw):
self.Layout.Tick()
Settling.Tick()
if Generation != self.Generation or self.Closed:
return
self._Draw()
@@ -403,7 +411,8 @@ class GraphView(ft.Container):
Degree = np.sqrt(self.Layout.Degree)
DirectoryRadius = 5 + Degree * 1.6
if self.ShrinkByDepth:
DirectoryRadius = np.maximum(SmallestDirectory, DirectoryRadius * ShrinkPerDepth ** self.Depths)
Step = np.minimum(self.Depths, ShrinkDepth) / ShrinkDepth
DirectoryRadius = DirectoryRadius + (FileDotRadius - DirectoryRadius) * Step
self.Radius = np.maximum(2, np.where(IsDirectory, DirectoryRadius, 3 + Degree * 0.8) * Zoom)
def _Label(self, Number: int, Colour: str) -> cv.Text: