mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-15 02:43:17 +02:00
Graph: options for depth colours and dot sizes
This commit is contained in:
1 parent
cc7d624a57
commit
0372a73dd2
8 files changed
+78
-11
No files matched your search
@@ -172,6 +172,10 @@ class AppConfig:
|
||||
# other one opens a dot).
|
||||
GraphShowDirectories: bool = True
|
||||
GraphPanButton: str = "Right"
|
||||
# Directory dots: heading colours by depth (off: all Mauve), and smaller
|
||||
# the deeper they are.
|
||||
GraphColourByDepth: bool = True
|
||||
GraphShrinkByDepth: bool = False
|
||||
# Double-click on a file: True opens it in SaraView's own viewer, False
|
||||
# hands it to the system's default program. The menu always offers the other.
|
||||
OpenFilesInApp: bool = True
|
||||
|
||||
+15
-4
@@ -220,6 +220,8 @@ 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
|
||||
|
||||
|
||||
def DirectoryColour(Depth: int) -> str:
|
||||
@@ -251,6 +253,9 @@ class GraphView(ft.Container):
|
||||
self.PanButton = "Left" if TheApp.Config.GraphPanButton == "Left" else "Right"
|
||||
self.OpenButton = "Right" if self.PanButton == "Left" else "Left"
|
||||
self.ShowDirectories = TheApp.Config.GraphShowDirectories
|
||||
self.ColourByDepth = TheApp.Config.GraphColourByDepth
|
||||
self.ShrinkByDepth = TheApp.Config.GraphShrinkByDepth
|
||||
self.Depths = np.zeros(0) # each dot's depth below the graph's directory
|
||||
self.Layout: Optional[Layout] = None
|
||||
self.ScopePath = ""
|
||||
self.Size = (800.0, 600.0)
|
||||
@@ -276,7 +281,9 @@ class GraphView(ft.Container):
|
||||
)
|
||||
self.CountText = ft.Text("", size=12, color=Palette.Overlay0)
|
||||
LegendItems: list[ft.Control] = []
|
||||
if self.ShowDirectories:
|
||||
if self.ShowDirectories and not self.ColourByDepth:
|
||||
LegendItems += [ft.Text("●", color=Palette.Mauve), ft.Text("Directory", size=12, color=Palette.Overlay0)]
|
||||
elif self.ShowDirectories:
|
||||
LegendItems += [ft.Text("●", color=Palette.Mauve), ft.Text("●", color=Palette.Blue), ft.Text("●", color=Palette.Green),
|
||||
ft.Text("Directories by depth", size=12, color=Palette.Overlay0)]
|
||||
LegendItems += [ft.Text("●", color=Palette.White), ft.Text("File", size=12, color=Palette.Overlay0),
|
||||
@@ -365,8 +372,9 @@ class GraphView(ft.Container):
|
||||
return
|
||||
self.Layout = Layout(Graph)
|
||||
Base = len(Path.split("/")) if Path else 0
|
||||
self.Colours = [DirectoryColour((len(Node["Id"].split("/")) if Node["Id"] else 0) - Base) if Node["IsDirectory"]
|
||||
else Palette.White for Node in self.Layout.Nodes]
|
||||
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)]
|
||||
self.StatusBox.visible = False
|
||||
self.StatusBox.update()
|
||||
# Settle in steps, drawing as it goes, like the web view's animation.
|
||||
@@ -393,7 +401,10 @@ class GraphView(ft.Container):
|
||||
Zoom = math.sqrt(Scale)
|
||||
IsDirectory = np.array([Node["IsDirectory"] for Node in self.Layout.Nodes])
|
||||
Degree = np.sqrt(self.Layout.Degree)
|
||||
self.Radius = np.maximum(2, np.where(IsDirectory, 5 + Degree * 1.6, 3 + Degree * 0.8) * Zoom)
|
||||
DirectoryRadius = 5 + Degree * 1.6
|
||||
if self.ShrinkByDepth:
|
||||
DirectoryRadius = np.maximum(SmallestDirectory, DirectoryRadius * ShrinkPerDepth ** self.Depths)
|
||||
self.Radius = np.maximum(2, np.where(IsDirectory, DirectoryRadius, 3 + Degree * 0.8) * Zoom)
|
||||
|
||||
def _Label(self, Number: int, Colour: str) -> cv.Text:
|
||||
X, Y = self.Screen[Number]
|
||||
|
||||
+9
-1
@@ -120,6 +120,10 @@ def ShowSettingsDialog(TheApp: App, OnSaved: Callable[[bool], None], StartCatego
|
||||
# Graph.
|
||||
GraphDirectoriesSwitch = ft.Switch(label="Show directories (off: only files and the links between them)",
|
||||
value=Config.GraphShowDirectories)
|
||||
ColourByDepthSwitch = ft.Switch(label="Colour directories by depth (off: all purple)",
|
||||
value=Config.GraphColourByDepth)
|
||||
ShrinkByDepthSwitch = ft.Switch(label="Smaller directory dots the deeper they are",
|
||||
value=Config.GraphShrinkByDepth)
|
||||
PanButtonPicker = ft.RadioGroup(
|
||||
ft.Column([
|
||||
ft.Radio(value="Right", label="Right (left-click opens a dot)"),
|
||||
@@ -217,9 +221,11 @@ def ShowSettingsDialog(TheApp: App, OnSaved: Callable[[bool], None], StartCatego
|
||||
OwnAppearance,
|
||||
], spacing=12, scroll=ft.ScrollMode.AUTO),
|
||||
"Graph": ft.Column([
|
||||
_Note("The graph view (Ctrl+G): directories in the heading colours by depth, files white, "
|
||||
_Note("The graph view (Ctrl+G): directories purple or in the heading colours by depth, files white, "
|
||||
"joined to their directory and to the files that reference them."),
|
||||
GraphDirectoriesSwitch,
|
||||
ColourByDepthSwitch,
|
||||
ShrinkByDepthSwitch,
|
||||
ft.Divider(height=1, color=Palette.Surface1),
|
||||
ft.Text("Pan with mouse button"),
|
||||
PanButtonPicker,
|
||||
@@ -261,6 +267,8 @@ def ShowSettingsDialog(TheApp: App, OnSaved: Callable[[bool], None], StartCatego
|
||||
Config.ShowFilesInTree = TreeFilesSwitch.value
|
||||
Config.MarkdownEditing = MarkdownEditingPicker.value or Config.MarkdownEditing
|
||||
Config.GraphShowDirectories = GraphDirectoriesSwitch.value
|
||||
Config.GraphColourByDepth = ColourByDepthSwitch.value
|
||||
Config.GraphShrinkByDepth = ShrinkByDepthSwitch.value
|
||||
Config.GraphPanButton = PanButtonPicker.value or Config.GraphPanButton
|
||||
Config.FontSize = _ReadInt(FontSizeField, Config.FontSize, 8, 32)
|
||||
Config.Mode = ModePicker.value or Config.Mode
|
||||
|
||||
Reference in new issue
Block a user