From 36d24d1735027052c11497676d215f9ce9f89ec7 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Sat, 17 Jan 2026 09:24:33 +0100 Subject: [PATCH] fix(zopk): Naprawa inicjalizacji grafu relacji MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: D3.js ładowane przez base.html PO bloku extra_js, więc initGraph() była wywoływana gdy D3 jeszcze nie istniało. Rozwiązanie: użycie window.addEventListener('load', ...) zamiast natychmiastowego sprawdzenia typeof d3. Co-Authored-By: Claude Opus 4.5 --- templates/admin/zopk_knowledge_graph.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/templates/admin/zopk_knowledge_graph.html b/templates/admin/zopk_knowledge_graph.html index fc619b4..d048ba1 100644 --- a/templates/admin/zopk_knowledge_graph.html +++ b/templates/admin/zopk_knowledge_graph.html @@ -318,15 +318,15 @@ {% endblock %} {% block extra_js %} -// Wait for D3 to load -if (typeof d3 === 'undefined') { - const script = document.createElement('script'); - script.src = 'https://d3js.org/d3.v7.min.js'; - script.onload = initGraph; - document.head.appendChild(script); -} else { - initGraph(); -} +// D3 is loaded by base.html AFTER this block, so we need to wait +// Use window.onload to ensure D3 script from base.html is fully loaded +window.addEventListener('load', function() { + if (typeof d3 !== 'undefined') { + initGraph(); + } else { + console.error('D3.js not loaded!'); + } +}); let simulation, svg, g, link, node, zoom; let currentNodes = [];