bug fix
This commit is contained in:
1 parent
053c22bc15
commit
3861246ac6
4 files changed
+108
-33
No files matched your search
+45
-16
@@ -7,11 +7,13 @@ from ui_callbacks import switch_to_editor_callback
|
||||
def render_graph_explorer(graph_service):
|
||||
st.header("🕸️ Graph Explorer")
|
||||
|
||||
# Session State initialisieren
|
||||
if "graph_center_id" not in st.session_state: st.session_state.graph_center_id = None
|
||||
|
||||
# Defaults
|
||||
# Defaults speichern für Persistenz
|
||||
st.session_state.setdefault("graph_depth", 2)
|
||||
st.session_state.setdefault("graph_show_labels", True)
|
||||
# Defaults angepasst für BarnesHut (andere Skala!)
|
||||
st.session_state.setdefault("graph_spacing", 150)
|
||||
st.session_state.setdefault("graph_gravity", -3000)
|
||||
|
||||
@@ -19,8 +21,11 @@ def render_graph_explorer(graph_service):
|
||||
|
||||
with col_ctrl:
|
||||
st.subheader("Fokus")
|
||||
|
||||
# Suche
|
||||
search_term = st.text_input("Suche Notiz", placeholder="Titel eingeben...")
|
||||
|
||||
options = {}
|
||||
if search_term:
|
||||
hits, _ = graph_service.client.scroll(
|
||||
collection_name=f"{COLLECTION_PREFIX}_notes",
|
||||
@@ -28,6 +33,7 @@ def render_graph_explorer(graph_service):
|
||||
limit=10
|
||||
)
|
||||
options = {h.payload['title']: h.payload['note_id'] for h in hits}
|
||||
|
||||
if options:
|
||||
selected_title = st.selectbox("Ergebnisse:", list(options.keys()))
|
||||
if st.button("Laden", use_container_width=True):
|
||||
@@ -35,13 +41,16 @@ def render_graph_explorer(graph_service):
|
||||
st.rerun()
|
||||
|
||||
st.divider()
|
||||
|
||||
# View Settings
|
||||
with st.expander("👁️ Ansicht & Layout", expanded=True):
|
||||
st.session_state.graph_depth = st.slider("Tiefe (Tier)", 1, 3, st.session_state.graph_depth)
|
||||
st.session_state.graph_show_labels = st.checkbox("Kanten-Beschriftung", st.session_state.graph_show_labels)
|
||||
|
||||
st.markdown("**Physik (BarnesHut)**")
|
||||
st.session_state.graph_spacing = st.slider("Federlänge", 50, 500, st.session_state.graph_spacing)
|
||||
st.session_state.graph_gravity = st.slider("Abstoßung", -20000, -500, st.session_state.graph_gravity)
|
||||
# ACHTUNG: BarnesHut reagiert anders. Spring Length ist wichtig.
|
||||
st.session_state.graph_spacing = st.slider("Federlänge (Abstand)", 50, 500, st.session_state.graph_spacing, help="Wie lang sollen die Verbindungen sein?")
|
||||
st.session_state.graph_gravity = st.slider("Abstoßung (Gravity)", -20000, -1000, st.session_state.graph_gravity, help="Wie stark sollen sich Knoten abstoßen?")
|
||||
|
||||
if st.button("Reset Layout"):
|
||||
st.session_state.graph_spacing = 150
|
||||
@@ -57,46 +66,62 @@ def render_graph_explorer(graph_service):
|
||||
center_id = st.session_state.graph_center_id
|
||||
|
||||
if center_id:
|
||||
# Action Container oben
|
||||
# Container für Action Bar OBERHALB des Graphen (Layout Fix)
|
||||
action_container = st.container()
|
||||
|
||||
# Graph Laden
|
||||
with st.spinner(f"Lade Graph..."):
|
||||
# Daten laden (Cache wird genutzt)
|
||||
nodes, edges = graph_service.get_ego_graph(
|
||||
center_id,
|
||||
depth=st.session_state.graph_depth,
|
||||
show_labels=st.session_state.graph_show_labels
|
||||
)
|
||||
|
||||
# Fetch Note Data für Button & Debug
|
||||
# Wir holen die Metadaten (inkl. path), was für den Editor-Callback reicht.
|
||||
note_data = graph_service._fetch_note_cached(center_id)
|
||||
|
||||
# Action Bar rendern
|
||||
# --- ACTION BAR RENDEREN ---
|
||||
with action_container:
|
||||
c1, c2 = st.columns([3, 1])
|
||||
with c1: st.caption(f"Aktives Zentrum: **{center_id}**")
|
||||
with c2:
|
||||
c_act1, c_act2 = st.columns([3, 1])
|
||||
with c_act1:
|
||||
st.caption(f"Aktives Zentrum: **{center_id}**")
|
||||
with c_act2:
|
||||
if note_data:
|
||||
st.button("📝 Bearbeiten", use_container_width=True, on_click=switch_to_editor_callback, args=(note_data,))
|
||||
st.button("📝 Bearbeiten",
|
||||
use_container_width=True,
|
||||
on_click=switch_to_editor_callback,
|
||||
args=(note_data,))
|
||||
else:
|
||||
st.error("Datenfehler")
|
||||
st.error("Daten nicht verfügbar")
|
||||
|
||||
with st.expander("🕵️ Data Inspector", expanded=False):
|
||||
# DATA INSPECTOR (Payload Debug)
|
||||
with st.expander("🕵️ Data Inspector (Payload Debug)", expanded=False):
|
||||
if note_data:
|
||||
st.json(note_data)
|
||||
if 'path' in note_data: st.success(f"Pfad OK: {note_data['path']}")
|
||||
else: st.error("Pfad fehlt!")
|
||||
else: st.info("Leer.")
|
||||
if 'path' not in note_data:
|
||||
st.error("ACHTUNG: Feld 'path' fehlt im Qdrant-Payload! Update-Modus wird nicht funktionieren.")
|
||||
else:
|
||||
st.success(f"Pfad gefunden: {note_data['path']}")
|
||||
else:
|
||||
st.info("Keine Daten geladen.")
|
||||
|
||||
if not nodes:
|
||||
st.warning("Keine Daten gefunden.")
|
||||
else:
|
||||
# Physik Config für BarnesHut + Height-Trick
|
||||
# --- CONFIGURATION (BarnesHut) ---
|
||||
# Height-Trick für Re-Render (da key-Parameter nicht funktioniert)
|
||||
# Ändere Height minimal basierend auf Gravity
|
||||
dyn_height = 800 + (abs(st.session_state.graph_gravity) % 5)
|
||||
|
||||
config = Config(
|
||||
width=1000,
|
||||
height=dyn_height,
|
||||
height=dyn_height,
|
||||
directed=True,
|
||||
physics={
|
||||
"enabled": True,
|
||||
# BarnesHut ist der Standard und stabilste Solver für Agraph
|
||||
"solver": "barnesHut",
|
||||
"barnesHut": {
|
||||
"gravitationalConstant": st.session_state.graph_gravity,
|
||||
@@ -116,11 +141,15 @@ def render_graph_explorer(graph_service):
|
||||
|
||||
return_value = agraph(nodes=nodes, edges=edges, config=config)
|
||||
|
||||
# Interaktions-Logik
|
||||
if return_value:
|
||||
if return_value != center_id:
|
||||
# Navigation: Neues Zentrum setzen
|
||||
st.session_state.graph_center_id = return_value
|
||||
st.rerun()
|
||||
else:
|
||||
# Klick auf das Zentrum selbst
|
||||
st.toast(f"Zentrum: {return_value}")
|
||||
|
||||
else:
|
||||
st.info("👈 Bitte wähle links eine Notiz aus.")
|
||||
Reference in new issue
Block a user