layout verbesserung
This commit is contained in:
1 parent
537a2883bf
commit
f1bcbb1543
2 files changed
+47
-80
No files matched your search
@@ -15,9 +15,7 @@ class GraphExplorerService:
|
||||
nodes_dict = {}
|
||||
unique_edges = {}
|
||||
|
||||
# --- LEVEL 1: Center & direkte Nachbarn ---
|
||||
|
||||
# 1. Center Note
|
||||
# 1. Center Note laden
|
||||
center_note = self._fetch_note_cached(center_note_id)
|
||||
if not center_note: return [], []
|
||||
self._add_node_to_dict(nodes_dict, center_note, level=0)
|
||||
@@ -34,23 +32,19 @@ class GraphExplorerService:
|
||||
if src_id: level_1_ids.add(src_id)
|
||||
if tgt_id: level_1_ids.add(tgt_id)
|
||||
|
||||
# --- LEVEL 2: Nachbarn der Nachbarn ---
|
||||
if depth > 1 and level_1_ids:
|
||||
# Wir nehmen alle IDs aus Level 1 (außer Center, das haben wir schon)
|
||||
# Level 2 Suche (begrenzt, um Chaos zu vermeiden)
|
||||
if depth > 1 and len(level_1_ids) > 1 and len(level_1_ids) < 40: # Limit für Performance
|
||||
l1_subset = list(level_1_ids - {center_note_id})
|
||||
|
||||
if l1_subset:
|
||||
l2_edges = self._find_connected_edges_batch(l1_subset)
|
||||
for edge_data in l2_edges:
|
||||
self._process_edge(edge_data, nodes_dict, unique_edges, current_depth=2)
|
||||
|
||||
# --- GRAPH CONSTRUCTION ---
|
||||
# Graphen bauen
|
||||
final_edges = []
|
||||
for (src, tgt), data in unique_edges.items():
|
||||
kind = data['kind']
|
||||
prov = data['provenance']
|
||||
|
||||
# Dynamische Farbe holen
|
||||
color = get_edge_color(kind)
|
||||
is_smart = (prov != "explicit" and prov != "rule")
|
||||
|
||||
@@ -62,8 +56,8 @@ class GraphExplorerService:
|
||||
return list(nodes_dict.values()), final_edges
|
||||
|
||||
def _find_connected_edges(self, note_ids, note_title=None):
|
||||
"""Findet In- und Outgoing Edges für eine Liste von Note-IDs."""
|
||||
# 1. Chunks zu diesen Notes finden
|
||||
"""Findet In- und Outgoing Edges."""
|
||||
# Chunks finden
|
||||
scroll_filter = models.Filter(
|
||||
must=[models.FieldCondition(key="note_id", match=models.MatchAny(any=note_ids))]
|
||||
)
|
||||
@@ -74,25 +68,29 @@ class GraphExplorerService:
|
||||
|
||||
results = []
|
||||
|
||||
# Outgoing (Source is Chunk)
|
||||
if chunk_ids:
|
||||
# --- OUTGOING SEARCH (Quelle = Chunk ODER Note) ---
|
||||
# FIX: Wir suchen jetzt auch nach der note_id als source_id, falls Edges direkt an der Note hängen
|
||||
source_candidates = chunk_ids + note_ids
|
||||
|
||||
if source_candidates:
|
||||
out_f = models.Filter(must=[
|
||||
models.FieldCondition(key="source_id", match=models.MatchAny(any=chunk_ids)),
|
||||
# FIX: MatchExcept mit **kwargs nutzen wegen 'except' Keyword
|
||||
models.FieldCondition(key="source_id", match=models.MatchAny(any=source_candidates)),
|
||||
# FIX: Pydantic "except" keyword workaround
|
||||
models.FieldCondition(key="kind", match=models.MatchExcept(**{"except": SYSTEM_EDGES}))
|
||||
])
|
||||
res_out, _ = self.client.scroll(self.edges_col, scroll_filter=out_f, limit=100, with_payload=True)
|
||||
results.extend(res_out)
|
||||
|
||||
# Incoming (Target is Chunk OR Title OR NoteID)
|
||||
# --- INCOMING SEARCH (Ziel = Chunk ODER Title ODER Note) ---
|
||||
shoulds = []
|
||||
if chunk_ids: shoulds.append(models.FieldCondition(key="target_id", match=models.MatchAny(any=chunk_ids)))
|
||||
if note_title: shoulds.append(models.FieldCondition(key="target_id", match=models.MatchValue(value=note_title)))
|
||||
# Target = Note ID
|
||||
shoulds.append(models.FieldCondition(key="target_id", match=models.MatchAny(any=note_ids)))
|
||||
|
||||
if shoulds:
|
||||
in_f = models.Filter(
|
||||
# FIX: MatchExcept mit **kwargs nutzen wegen 'except' Keyword
|
||||
# FIX: Pydantic "except" keyword workaround
|
||||
must=[models.FieldCondition(key="kind", match=models.MatchExcept(**{"except": SYSTEM_EDGES}))],
|
||||
should=shoulds
|
||||
)
|
||||
@@ -102,7 +100,7 @@ class GraphExplorerService:
|
||||
return results
|
||||
|
||||
def _find_connected_edges_batch(self, note_ids):
|
||||
"""Batch-Suche für Level 2 (nur ausgehend und eingehend auf Note-Ebene)."""
|
||||
"""Batch-Suche für Level 2."""
|
||||
return self._find_connected_edges(note_ids)
|
||||
|
||||
def _process_edge(self, record, nodes_dict, unique_edges, current_depth):
|
||||
@@ -112,7 +110,6 @@ class GraphExplorerService:
|
||||
kind = payload.get("kind")
|
||||
provenance = payload.get("provenance", "explicit")
|
||||
|
||||
# Resolve
|
||||
src_note = self._resolve_note_from_ref(src_ref)
|
||||
tgt_note = self._resolve_note_from_ref(tgt_ref)
|
||||
|
||||
@@ -121,15 +118,12 @@ class GraphExplorerService:
|
||||
tgt_id = tgt_note['note_id']
|
||||
|
||||
if src_id != tgt_id:
|
||||
# Add Nodes
|
||||
self._add_node_to_dict(nodes_dict, src_note, level=current_depth)
|
||||
self._add_node_to_dict(nodes_dict, tgt_note, level=current_depth)
|
||||
|
||||
# Add Edge (Deduplication Logic)
|
||||
key = (src_id, tgt_id)
|
||||
existing = unique_edges.get(key)
|
||||
|
||||
# Update logic: Explicit > Smart
|
||||
should_update = True
|
||||
is_current_explicit = (provenance in ["explicit", "rule"])
|
||||
if existing:
|
||||
@@ -184,31 +178,22 @@ class GraphExplorerService:
|
||||
|
||||
def _add_node_to_dict(self, node_dict, note_payload, level=1):
|
||||
nid = note_payload.get("note_id")
|
||||
|
||||
# Wenn Node schon da ist, aber wir finden ihn auf einem "höheren" Level (näher am Zentrum),
|
||||
# updaten wir ihn nicht zwingend, außer wir wollen visuelle Eigenschaften ändern.
|
||||
if nid in node_dict: return
|
||||
|
||||
ntype = note_payload.get("type", "default")
|
||||
color = GRAPH_COLORS.get(ntype, GRAPH_COLORS["default"])
|
||||
|
||||
# Größe & Label basierend auf Level
|
||||
if level == 0:
|
||||
size = 40
|
||||
label_prefix = ""
|
||||
elif level == 1:
|
||||
size = 25
|
||||
label_prefix = ""
|
||||
else:
|
||||
size = 15 # Level 2 kleiner
|
||||
label_prefix = ""
|
||||
# Size Adjustment für Hierarchie
|
||||
if level == 0: size = 45
|
||||
elif level == 1: size = 25
|
||||
else: size = 15
|
||||
|
||||
node_dict[nid] = Node(
|
||||
id=nid,
|
||||
label=f"{label_prefix}{note_payload.get('title', nid)}",
|
||||
label=note_payload.get('title', nid),
|
||||
size=size,
|
||||
color=color,
|
||||
shape="dot" if level > 0 else "diamond",
|
||||
title=f"Type: {ntype}\nLevel: {level}\nTags: {note_payload.get('tags')}",
|
||||
font={'color': 'black', 'face': 'arial', 'size': 14 if level < 2 else 10}
|
||||
title=f"Type: {ntype}\nTags: {note_payload.get('tags')}",
|
||||
font={'color': 'black', 'face': 'arial', 'size': 14 if level < 2 else 0}
|
||||
)
|
||||
Reference in new issue
Block a user