mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
feat(app): virtual tag nodes in the graph, network and tree
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9a671a27c4
commit
42a87b1a2a
4 files changed
+66
-12
No files matched your search
@@ -55,6 +55,9 @@ class GraphModel {
|
||||
|
||||
bool isHub(int i) => node(i).isHub;
|
||||
|
||||
/// Whether node `i` is a virtual tag node (a name, not a page).
|
||||
bool isTag(int i) => node(i).isTag;
|
||||
|
||||
/// Whether the graph has any hub (folder-like page).
|
||||
late final bool hasHubs = data.nodes.any((n) => n.isHub);
|
||||
|
||||
@@ -170,11 +173,12 @@ class GraphModel {
|
||||
];
|
||||
}
|
||||
|
||||
/// Tag pages actually used as tags, most used first.
|
||||
/// Tag nodes (and pages targeted by inline `#tag` references) actually used as tags,
|
||||
/// most used first.
|
||||
late final List<int> tags = () {
|
||||
final count = <int, int>{};
|
||||
for (var e = 0; e < edgeCount; e++) {
|
||||
if (kind(e) == EdgeKind.tag) {
|
||||
if (kind(e) == EdgeKind.tag || kind(e) == EdgeKind.tagged) {
|
||||
count[target(e)] = (count[target(e)] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
@@ -292,7 +296,9 @@ class GraphFilter {
|
||||
: {
|
||||
tag!,
|
||||
for (final e in g.adjacency[tag!])
|
||||
if (g.kind(e) == EdgeKind.tag && g.target(e) == tag) g.source(e),
|
||||
if ((g.kind(e) == EdgeKind.tag || g.kind(e) == EdgeKind.tagged) &&
|
||||
g.target(e) == tag)
|
||||
g.source(e),
|
||||
};
|
||||
String day(int i) {
|
||||
final ms = g.node(i).createdAt.toInt();
|
||||
|
||||
@@ -619,7 +619,9 @@ class _NetworkPainter extends CustomPainter {
|
||||
.putIfAbsent(((r + _ringWidth) * 2).round(), _Buf.new)
|
||||
.add2(pos[2 * k], pos[2 * k + 1]);
|
||||
}
|
||||
final ci = g.isJournal(sub.nodes[k]) ? -2 : s._colorIndex[k];
|
||||
final ci = g.isTag(sub.nodes[k])
|
||||
? -3
|
||||
: (g.isJournal(sub.nodes[k]) ? -2 : s._colorIndex[k]);
|
||||
final key = (ci, (r * 2).round());
|
||||
buckets.putIfAbsent(key, _Buf.new).add2(pos[2 * k], pos[2 * k + 1]);
|
||||
}
|
||||
@@ -637,7 +639,9 @@ class _NetworkPainter extends CustomPainter {
|
||||
}
|
||||
for (final MapEntry(key: (ci, d2), value: pts) in buckets.entries) {
|
||||
if (pts.n == 0) continue;
|
||||
var c = ci == -2 ? journalColor : (ci < 0 ? colors.muted : palette[ci]);
|
||||
var c = ci == -3
|
||||
? colors.accent
|
||||
: (ci == -2 ? journalColor : (ci < 0 ? colors.muted : palette[ci]));
|
||||
if (dim) c = c.withValues(alpha: 0.25);
|
||||
if (brain != null) c = colors.faint;
|
||||
canvas.drawRawPoints(
|
||||
@@ -649,6 +653,17 @@ class _NetworkPainter extends CustomPainter {
|
||||
..strokeCap = StrokeCap.round,
|
||||
);
|
||||
}
|
||||
// Tag nodes are hollow rings (a name, not a page).
|
||||
if (brain == null) {
|
||||
for (var k = 0; k < sub.length; k++) {
|
||||
if (!visible(k) || !g.isTag(sub.nodes[k])) continue;
|
||||
canvas.drawCircle(
|
||||
Offset(pos[2 * k], pos[2 * k + 1]),
|
||||
s._radius[k] * 0.5,
|
||||
Paint()..color = colors.paper,
|
||||
);
|
||||
}
|
||||
}
|
||||
// Activation glow (brain), highlighted and focused nodes on top.
|
||||
if (brain != null) {
|
||||
for (var k = 0; k < sub.length; k++) {
|
||||
|
||||
@@ -81,6 +81,7 @@ List<TreeItem> _hubBranches(GraphModel g) {
|
||||
// namespace branch).
|
||||
for (var i = 0; i < g.nodeCount; i++) {
|
||||
if (!g.isHub(i) &&
|
||||
!g.isTag(i) &&
|
||||
!g.isJournal(i) &&
|
||||
!nested.contains(i) &&
|
||||
!g.node(i).title.contains('/')) {
|
||||
@@ -99,11 +100,13 @@ TreeItem buildNamespaceTree(GraphModel g, {String name = 'Graph'}) {
|
||||
final ns = TreeItem('Namespaces');
|
||||
final byTitle = <String, int>{};
|
||||
for (var i = 0; i < g.nodeCount; i++) {
|
||||
if (!g.isJournal(i)) byTitle[g.node(i).title.toLowerCase()] = i;
|
||||
if (!g.isJournal(i) && !g.isTag(i)) {
|
||||
byTitle[g.node(i).title.toLowerCase()] = i;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < g.nodeCount; i++) {
|
||||
final t = g.node(i).title;
|
||||
if (g.isJournal(i) || !t.contains('/')) continue;
|
||||
if (g.isJournal(i) || g.isTag(i) || !t.contains('/')) continue;
|
||||
var at = ns;
|
||||
final parts = t.split('/');
|
||||
for (var k = 0; k < parts.length; k++) {
|
||||
@@ -119,7 +122,10 @@ TreeItem buildNamespaceTree(GraphModel g, {String name = 'Graph'}) {
|
||||
final item = TreeItem('#${g.node(tag).title}', global: tag);
|
||||
final seen = <int>{};
|
||||
for (final e in g.adjacency[tag]) {
|
||||
if (g.kind(e) != EdgeKind.tag || g.target(e) != tag) continue;
|
||||
final k = g.kind(e);
|
||||
if ((k != EdgeKind.tag && k != EdgeKind.tagged) || g.target(e) != tag) {
|
||||
continue;
|
||||
}
|
||||
final s = g.source(e);
|
||||
if (seen.add(s)) {
|
||||
item.children.add(TreeItem(g.node(s).title, global: s));
|
||||
@@ -227,6 +233,7 @@ class TreeCanvas extends StatefulWidget {
|
||||
super.key,
|
||||
required this.model,
|
||||
required this.onTap,
|
||||
this.onTag,
|
||||
this.name = 'Graph',
|
||||
});
|
||||
final GraphModel model;
|
||||
@@ -235,6 +242,10 @@ class TreeCanvas extends StatefulWidget {
|
||||
final String name;
|
||||
final void Function(int global) onTap;
|
||||
|
||||
/// Called with the tag name when a tag (which has no page) is clicked; falls back to
|
||||
/// [onTap] when null.
|
||||
final void Function(String name)? onTag;
|
||||
|
||||
@override
|
||||
State<TreeCanvas> createState() => TreeCanvasState();
|
||||
}
|
||||
@@ -466,6 +477,20 @@ class TreeCanvasState extends State<TreeCanvas> {
|
||||
setState(_relayout);
|
||||
}
|
||||
|
||||
/// Opens the page (or tag) behind `t`, as a click on its name does.
|
||||
void openItem(TreeItem t) {
|
||||
if (t.global != null) _open(t.global!);
|
||||
}
|
||||
|
||||
void _open(int global) {
|
||||
final g = widget.model;
|
||||
if (g.isTag(global) && widget.onTag != null) {
|
||||
widget.onTag!(g.node(global).title);
|
||||
} else {
|
||||
widget.onTap(global);
|
||||
}
|
||||
}
|
||||
|
||||
void _onTap(Offset local) {
|
||||
final k = _hitNode(local);
|
||||
if (k != null) {
|
||||
@@ -473,13 +498,13 @@ class TreeCanvasState extends State<TreeCanvas> {
|
||||
if (t.children.isNotEmpty) {
|
||||
toggle(t);
|
||||
} else if (t.global != null) {
|
||||
widget.onTap(t.global!);
|
||||
_open(t.global!);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final l = _hitLabel(local);
|
||||
if (l?.global != null) {
|
||||
widget.onTap(l!.global!);
|
||||
openItem(l!);
|
||||
} else if (l != null) {
|
||||
toggle(l);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user