graphify add

This commit is contained in:
javad committed 2026-10-09 17:18:17 +03:30
1 parent f19d8ee6a7
commit 91768be145
20 files changed
+21700 -1

No files matched your search

+360
View File
@@ -0,0 +1,360 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>graphify - graphify-out/graph.html</title>
<script src="https://unpkg.com/vis-network@9.1.6/standalone/umd/vis-network.min.js"
integrity="sha384-Ux6phic9PEHJ38YtrijhkzyJ8yQlH8i/+buBR8s3mAZOJrP1gwyvAcIYl3GWtpX1"
crossorigin="anonymous"></script>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: #0f0f1a; color: #e0e0e0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; display: flex; height: 100vh; overflow: hidden; }
#graph { flex: 1; }
#sidebar { width: 280px; background: #1a1a2e; border-left: 1px solid #2a2a4e; display: flex; flex-direction: column; overflow: hidden; }
#search-wrap { padding: 12px; border-bottom: 1px solid #2a2a4e; }
#search { width: 100%; background: #0f0f1a; border: 1px solid #3a3a5e; color: #e0e0e0; padding: 7px 10px; border-radius: 6px; font-size: 13px; outline: none; }
#search:focus { border-color: #4E79A7; }
#search-results { max-height: 140px; overflow-y: auto; padding: 4px 12px; border-bottom: 1px solid #2a2a4e; display: none; }
.search-item { padding: 4px 6px; cursor: pointer; border-radius: 4px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item:hover { background: #2a2a4e; }
#info-panel { padding: 14px; border-bottom: 1px solid #2a2a4e; min-height: 140px; }
#info-panel h3 { font-size: 13px; color: #aaa; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
#info-content { font-size: 13px; color: #ccc; line-height: 1.6; }
#info-content .field { margin-bottom: 5px; }
#info-content .field b { color: #e0e0e0; }
#info-content .empty { color: #555; font-style: italic; }
.neighbor-link { display: block; padding: 2px 6px; margin: 2px 0; border-radius: 3px; cursor: pointer; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid #333; }
.neighbor-link:hover { background: #2a2a4e; }
#neighbors-list { max-height: 160px; overflow-y: auto; margin-top: 4px; }
#legend-wrap { flex: 1; overflow-y: auto; padding: 12px; }
#legend-wrap h3 { font-size: 13px; color: #aaa; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; border-radius: 4px; font-size: 12px; }
.legend-item:hover { background: #2a2a4e; padding-left: 4px; }
.legend-item.dimmed { opacity: 0.35; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.legend-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-count { color: #666; font-size: 11px; }
#stats { padding: 10px 14px; border-top: 1px solid #2a2a4e; font-size: 11px; color: #555; }
#legend-controls { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding: 4px 0; }
#legend-controls label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; color: #aaa; user-select: none; }
#legend-controls label:hover { color: #e0e0e0; }
.legend-cb, #select-all-cb { appearance: none; -webkit-appearance: none; width: 14px; height: 14px; border: 1.5px solid #3a3a5e; border-radius: 3px; background: #0f0f1a; cursor: pointer; position: relative; flex-shrink: 0; }
.legend-cb:checked, #select-all-cb:checked { background: #4E79A7; border-color: #4E79A7; }
.legend-cb:checked::after, #select-all-cb:checked::after { content: ''; position: absolute; left: 3.5px; top: 1px; width: 4px; height: 7px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
#select-all-cb:indeterminate { background: #4E79A7; border-color: #4E79A7; }
#select-all-cb:indeterminate::after { content: ''; position: absolute; left: 2px; top: 5px; width: 8px; height: 2px; background: #fff; border: none; transform: none; }
</style>
</head>
<body>
<div id="graph"></div>
<div id="sidebar">
<div id="search-wrap">
<input id="search" type="text" placeholder="Search nodes..." autocomplete="off">
<div id="search-results"></div>
</div>
<div id="info-panel">
<h3>Node Info</h3>
<div id="info-content"><span class="empty">Click a node to inspect it</span></div>
</div>
<div id="legend-wrap">
<h3>Communities</h3>
<div id="legend-controls">
<label><input type="checkbox" id="select-all-cb" checked onchange="toggleAllCommunities(!this.checked)">Select All</label>
</div>
<div id="legend"></div>
</div>
<div id="stats">548 nodes &middot; 887 edges &middot; 80 communities</div>
</div>
<script>
const RAW_NODES = [{"id": "admin_models_user", "label": "User", "color": {"background": "#4E79A7", "border": "#4E79A7", "highlight": {"background": "#ffffff", "border": "#4E79A7"}}, "size": 15.5, "font": {"size": 12, "color": "#ffffff"}, "title": "User", "community": 0, "community_name": "User Action Views", "source_file": "admin/models.py", "file_type": "code", "degree": 21}, {"id": "admin_panel_models_action", "label": "Action", "color": {"background": "#4E79A7", "border": "#4E79A7", "highlight": {"background": "#ffffff", "border": "#4E79A7"}}, "size": 15.2, "font": {"size": 12, "color": "#ffffff"}, "title": "Action", "community": 0, "community_name": "User Action Views", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 20}, {"id": "admin_panel_models_productcategory", "label": "ProductCategory", "color": {"background": "#4E79A7", "border": "#4E79A7", "highlight": {"background": "#ffffff", "border": "#4E79A7"}}, "size": 13.7, "font": {"size": 0, "color": "#ffffff"}, "title": "ProductCategory", "community": 0, "community_name": "User Action Views", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 14}, {"id": "admin_panel_models_articletype", "label": "ArticleType", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.3, "font": {"size": 0, "color": "#ffffff"}, "title": "ArticleType", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 1}, {"id": "admin_panel_models_cachetable", "label": "CacheTable", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.5, "font": {"size": 0, "color": "#ffffff"}, "title": "CacheTable", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 2}, {"id": "admin_panel_models_phonenumber", "label": "PhoneNumber", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.5, "font": {"size": 0, "color": "#ffffff"}, "title": "PhoneNumber", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 2}, {"id": "admin_panel_models_productstockhistory", "label": "ProductStockHistory", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.8, "font": {"size": 0, "color": "#ffffff"}, "title": "ProductStockHistory", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 3}, {"id": "admin_panel_models_productstockhistory_meta", "label": "Meta", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.3, "font": {"size": 0, "color": "#ffffff"}, "title": "Meta", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 1}, {"id": "admin_panel_models_storeroomowner", "label": "StoreRoomOwner", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.8, "font": {"size": 0, "color": "#ffffff"}, "title": "StoreRoomOwner", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 3}, {"id": "admin_panel_models_userprofile", "label": "UserProfile", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.8, "font": {"size": 0, "color": "#ffffff"}, "title": "UserProfile", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 3}, {"id": "admin_panel_models_visitqueue", "label": "VisitQueue", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.5, "font": {"size": 0, "color": "#ffffff"}, "title": "VisitQueue", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 2}, {"id": "admin_panel_models_product", "label": "Product", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 14.7, "font": {"size": 12, "color": "#ffffff"}, "title": "Product", "community": 1, "community_name": "Inventory and Product Models", "source_file": "admin_panel/models.py", "file_type": "code", "degree": 18}, {"id": "admin_panel_models_product_meta", "label": "Meta", "color": {"background": "#F28E2B", "border": "#F28E2B", "highlight": {"background": "#ffffff", "border": "#F28E2B"}}, "size": 10.3, "Line truncated
const RAW_EDGES = [{"from": "admin_models", "to": "admin_models_user", "label": "contains", "title": "contains [EXTRACTED]", "dashes": false, "width": 2, "color": {"opacity": 0.7}, "confidence": "EXTRACTED"}, {"from": "admin_panel_models_action", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_models_factor", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_models_storeroom", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_models_storeroomowner", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_models_storetransferrequest", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_models_userprofile", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_models_visitqueue", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_actionlist", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_actionlistall", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_actionlisttoday", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_actionlistuser", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_actionlistusertoday", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_customeraction", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_customereditaction", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_customernazar", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_customernewaction", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_inventory_movements_report", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_newfactor", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_report", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_views_rezayat_dashboard", "to": "admin_models_user", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_management_commands_send_daily_report", "to": "admin_panel_models_action", "label": "imports", "title": "imports [EXTRACTED]", "dashes": false, "width": 2, "color": {"opacity": 0.7}, "confidence": "EXTRACTED"}, {"from": "admin_panel_management_commands_send_daily_report_command", "to": "admin_panel_models_action", "label": "uses", "title": "uses [INFERRED]", "dashes": true, "width": 1, "color": {"opacity": 0.35}, "confidence": "INFERRED"}, {"from": "admin_panel_models", "to": "admin_panel_models_action", "label": "contains", "title": "contains [EXTRACTED]", "dashes": false, "width": 2, "color": {"opacity": 0.7}, "confidence": "EXTRACTED"}, {"from": "admin_panel_views", "to": "admin_panel_models_action", "label": "imports", "title": "imports [EXTRACTED]", "dashes":Line truncated
const LEGEND = [{"cid": 0, "color": "#4E79A7", "label": "User Action Views", "count": 87}, {"cid": 1, "color": "#F28E2B", "label": "Inventory and Product Models", "count": 60}, {"cid": 2, "color": "#E15759", "label": "Daily Reporting Command", "count": 45}, {"cid": 3, "color": "#76B7B2", "label": "Customer Admin Templates", "count": 34}, {"cid": 4, "color": "#59A14F", "label": "Database Schema Migrations", "count": 33}, {"cid": 5, "color": "#EDC948", "label": "Admin Panel URLs", "count": 33}, {"cid": 6, "color": "#B07AA1", "label": "Database Backup Command", "count": 27}, {"cid": 7, "color": "#FF9DA7", "label": "Initial Database Migrations", "count": 23}, {"cid": 8, "color": "#9C755F", "label": "User Relation Migrations", "count": 23}, {"cid": 9, "color": "#BAB0AC", "label": "Financial and Accounting Views", "count": 22}, {"cid": 10, "color": "#4E79A7", "label": "Invoice Management Logic", "count": 13}, {"cid": 11, "color": "#F28E2B", "label": "Django Admin Configuration", "count": 10}, {"cid": 12, "color": "#E15759", "label": "Core Application Models", "count": 10}, {"cid": 13, "color": "#76B7B2", "label": "Resource Cleanup Command", "count": 10}, {"cid": 14, "color": "#59A14F", "label": "Django App Configurations", "count": 7}, {"cid": 15, "color": "#EDC948", "label": "Timezone-related Migrations", "count": 7}, {"cid": 16, "color": "#B07AA1", "label": "Application Entrypoint Scripts", "count": 7}, {"cid": 17, "color": "#FF9DA7", "label": "Core Admin App", "count": 6}, {"cid": 18, "color": "#9C755F", "label": "Project URL Configuration", "count": 6}, {"cid": 19, "color": "#BAB0AC", "label": "Graphify Tooling", "count": 6}, {"cid": 20, "color": "#4E79A7", "label": "Data Validation Migration", "count": 3}, {"cid": 21, "color": "#F28E2B", "label": "Application Tests", "count": 3}, {"cid": 22, "color": "#E15759", "label": "Database Schema Migration", "count": 2}, {"cid": 23, "color": "#76B7B2", "label": "Database Schema Migration", "count": 2}, {"cid": 24, "color": "#59A14F", "label": "Remove StoreRoom User Relation", "count": 2}, {"cid": 25, "color": "#EDC948", "label": "Database Schema Migration", "count": 2}, {"cid": 26, "color": "#B07AA1", "label": "Add Action Type Field", "count": 2}, {"cid": 27, "color": "#FF9DA7", "label": "Add Action Grade Field", "count": 2}, {"cid": 28, "color": "#9C755F", "label": "Database Schema Migration", "count": 2}, {"cid": 29, "color": "#BAB0AC", "label": "Add Article Payment Status", "count": 2}, {"cid": 30, "color": "#4E79A7", "label": "Add Article Payment Method", "count": 2}, {"cid": 31, "color": "#F28E2B", "label": "Add Customer Last Visit", "count": 2}, {"cid": 32, "color": "#E15759", "label": "Database Schema Migration", "count": 2}, {"cid": 33, "color": "#76B7B2", "label": "Add Sarresid Description", "count": 2}, {"cid": 34, "color": "#59A14F", "label": "Update ProductInStore Options", "count": 2}, {"cid": 35, "color": "#EDC948", "label": "Update ProductInStore Options", "count": 2}, {"cid": 36, "color": "#B07AA1", "label": "AI Tooling Documentation", "count": 2}, {"cid": 37, "color": "#FF9DA7", "label": "Admin Migrations Package", "count": 1}, {"cid": 38, "color": "#9C755F", "label": "Customer Action Partial", "count": 1}, {"cid": 39, "color": "#BAB0AC", "label": "New Customer Base Template", "count": 1}, {"cid": 40, "color": "#4E79A7", "label": "Customer Feedback Partial", "count": 1}, {"cid": 41, "color": "#F28E2B", "label": "Customer Invoice Detail", "count": 1}, {"cid": 42, "color": "#E15759", "label": "Customer Accounting Template", "count": 1}, {"cid": 43, "color": "#76B7B2", "label": "Customer Invoice List", "count": 1}, {"cid": 44, "color": "#59A14F", "label": "Customer Feedback Page", "count": 1}, {"cid": 45, "color": "#EDC948", "label": "Management Commands Package", "count": 1}, {"cid": 46, "color": "#B07AA1", "label": "Management Package", "count": 1}, {"cid": 47, "color": "#FF9DA7", "label": "Admin Panel Migrations Package", "count": 1}, {"cid": 48, "color": "#9C755F", "label": "Action List Template", "count": 1}, {"cid": 49, "color": "#BAB0AC", "label": "New Customer Invoice Page", "count": 1}, {"cid": 50, "color": "#4E79A7", "label": "New Customer Invoice V2", "count": 1}, {"cid": 51, "color": "#F28E2B", "label": "Customer Satisfaction List", "count": 1}, {"cid": 52, "color": "#E15759", "label": "Customer Satisfaction Partial", "count": 1}, {"cid": 53, "color": "#76B7B2", "label": "Customer Debt Management", "count": 1}, {"cid": 54, "color": "#59A14F", "label": "Customer List Page", "count": 1}, {"cid": 55, "color": "#EDC948", "label": "Customer List Backup Template", "count": 1}, {"cid": 56, "color": "#B07AA1", "label": "Waiting List Backup Template", "count": 1}, {"cid": 57, "color": "#FF9DA7", "label": "Financial Dashboard", "count": 1}, {"cid": 58, "color": "#9C755F", "label": "Accounting Main View", "count": 1}, {"cid": 59, "color": "#BAB0AC", "label": "Admin Panel Index Page", "count": 1}, {"cid": 60, "color": "#4E79A7", "label": "New Inventory Line truncated
// HTML-escape helper — prevents XSS when injecting graph data into innerHTML
function esc(s) {
return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');
}
// Build vis datasets
const nodesDS = new vis.DataSet(RAW_NODES.map((n, i) => ({
id: n.id, label: n.label, color: n.color, size: n.size,
font: n.font, title: n.title,
// Fermat/golden-angle spiral seed positions (#3699): spreading nodes out
// before physics runs keeps avoidOverlap from computing near-zero-distance
// repulsion that blows the BarnesHut recursion into a stack overflow on large
// graphs. `i` is the map index — physics still settles small graphs identically.
x: 30 * Math.sqrt(i) * Math.cos(i * 2.4),
y: 30 * Math.sqrt(i) * Math.sin(i * 2.4),
community: n.community, community_name: n.community_name,
source_file: n.source_file, file_type: n.file_type, degree: n.degree,
member_count: n.member_count,
})));
const edgesDS = new vis.DataSet(RAW_EDGES.map((e, i) => ({
id: i, from: e.from, to: e.to,
label: '',
title: e.title,
dashes: e.dashes,
width: e.width,
color: e.color,
arrows: { to: { enabled: true, scaleFactor: 0.5 } },
})));
const container = document.getElementById('graph');
const network = new vis.Network(container, { nodes: nodesDS, edges: edgesDS }, {
physics: {
enabled: true,
solver: 'forceAtlas2Based',
forceAtlas2Based: {
gravitationalConstant: -60,
centralGravity: 0.005,
springLength: 120,
springConstant: 0.08,
damping: 0.4,
avoidOverlap: 0.8,
},
stabilization: { iterations: 200, fit: true },
},
interaction: {
hover: true,
tooltipDelay: 100,
hideEdgesOnDrag: true,
navigationButtons: false,
keyboard: false,
},
nodes: { shape: 'dot', borderWidth: 1.5 },
edges: { smooth: { type: 'continuous', roundness: 0.2 }, selectionWidth: 3 },
});
network.once('stabilizationIterationsDone', () => {
network.setOptions({ physics: { enabled: false } });
});
function showInfo(nodeId) {
const n = nodesDS.get(nodeId);
if (!n) return;
const neighborIds = network.getConnectedNodes(nodeId);
const neighborItems = neighborIds.map(nid => {
const nb = nodesDS.get(nid);
const color = nb ? nb.color.background : '#555';
return `<span class="neighbor-link" style="border-left-color:${esc(color)}" data-nid="${esc(nid)}">${esc(nb ? nb.label : nid)}</span>`;
}).join('');
const isMetaNode = !n.file_type && !n.source_file;
let html = `<div class="field"><b>${esc(n.label)}</b></div>`;
if (!isMetaNode) {
html += `<div class="field">Type: ${esc(n.file_type || 'unknown')}</div>`;
}
html += `<div class="field">Community: ${esc(n.community_name || '')}</div>`;
if (!isMetaNode) {
html += `<div class="field">Source: ${esc(n.source_file || '-')}</div>`;
} else if (n.member_count !== undefined && n.member_count !== null) {
html += `<div class="field">Members: ${esc(n.member_count)}</div>`;
}
html += `<div class="field">Degree: ${n.degree}</div>`;
if (neighborIds.length) {
html += `<div class="field" style="margin-top:8px;color:#aaa;font-size:11px">Neighbors (${neighborIds.length})</div><div id="neighbors-list">${neighborItems}</div>`;
}
document.getElementById('info-content').innerHTML = html;
}
function focusNode(nodeId) {
network.focus(nodeId, { scale: 1.4, animation: true });
network.selectNodes([nodeId]);
showInfo(nodeId);
}
// Neighbor links use a data attribute + one delegated listener rather than an
// inline onclick. A node id/label sourced from a document or a scraped URL
// (graphify add) can contain a double-quote; dropping the stringified id
// unescaped into a quoted onclick both broke every link and allowed a hostile
// source to inject an event handler into the local report (stored XSS, #1838).
// esc() on data-nid keeps the value inside the attribute; the listener reads it
// back verbatim. Bound to document so it survives the innerHTML rebuild that
// recreates #neighbors-list on each showInfo().
document.addEventListener('click', e => {
const el = e.target.closest('.neighbor-link');
if (el && el.dataset.nid !== undefined) focusNode(el.dataset.nid);
});
// Track hovered node — hover detection is more reliable than click params
let hoveredNodeId = null;
network.on('hoverNode', params => {
hoveredNodeId = params.node;
container.style.cursor = 'pointer';
});
network.on('blurNode', () => {
hoveredNodeId = null;
container.style.cursor = 'default';
});
container.addEventListener('click', () => {
if (hoveredNodeId !== null) {
showInfo(hoveredNodeId);
network.selectNodes([hoveredNodeId]);
}
});
network.on('click', params => {
if (params.nodes.length > 0) {
showInfo(params.nodes[0]);
} else if (hoveredNodeId === null) {
document.getElementById('info-content').innerHTML = '<span class="empty">Click a node to inspect it</span>';
}
});
const searchInput = document.getElementById('search');
const searchResults = document.getElementById('search-results');
searchInput.addEventListener('input', () => {
const q = searchInput.value.toLowerCase().trim();
searchResults.innerHTML = '';
if (!q) { searchResults.style.display = 'none'; return; }
const matches = RAW_NODES.filter(n => n.label.toLowerCase().includes(q)).slice(0, 20);
if (!matches.length) { searchResults.style.display = 'none'; return; }
searchResults.style.display = 'block';
matches.forEach(n => {
const el = document.createElement('div');
el.className = 'search-item';
el.textContent = n.label;
el.style.borderLeft = `3px solid ${n.color.background}`;
el.style.paddingLeft = '8px';
el.onclick = () => {
network.focus(n.id, { scale: 1.5, animation: true });
network.selectNodes([n.id]);
showInfo(n.id);
searchResults.style.display = 'none';
searchInput.value = '';
};
searchResults.appendChild(el);
});
});
document.addEventListener('click', e => {
if (!searchResults.contains(e.target) && e.target !== searchInput)
searchResults.style.display = 'none';
});
const hiddenCommunities = new Set();
const selectAllCb = document.getElementById('select-all-cb');
function updateSelectAllState() {
const total = LEGEND.length;
const hidden = hiddenCommunities.size;
selectAllCb.checked = hidden === 0;
selectAllCb.indeterminate = hidden > 0 && hidden < total;
}
function toggleAllCommunities(hide) {
document.querySelectorAll('.legend-item').forEach(item => {
hide ? item.classList.add('dimmed') : item.classList.remove('dimmed');
});
document.querySelectorAll('.legend-cb').forEach(cb => {
cb.checked = !hide;
});
LEGEND.forEach(c => {
if (hide) hiddenCommunities.add(c.cid); else hiddenCommunities.delete(c.cid);
});
const updates = RAW_NODES.map(n => ({ id: n.id, hidden: hide }));
nodesDS.update(updates);
updateSelectAllState();
}
const legendEl = document.getElementById('legend');
LEGEND.forEach(c => {
const item = document.createElement('div');
item.className = 'legend-item';
const cb = document.createElement('input');
cb.type = 'checkbox';
cb.className = 'legend-cb';
cb.checked = true;
cb.addEventListener('change', (e) => {
e.stopPropagation();
if (cb.checked) {
hiddenCommunities.delete(c.cid);
item.classList.remove('dimmed');
} else {
hiddenCommunities.add(c.cid);
item.classList.add('dimmed');
}
const updates = RAW_NODES
.filter(n => n.community === c.cid)
.map(n => ({ id: n.id, hidden: !cb.checked }));
nodesDS.update(updates);
updateSelectAllState();
});
item.innerHTML = `<div class="legend-dot" style="background:${c.color}"></div>
<span class="legend-label">${c.label}</span>
<span class="legend-count">${c.count}</span>`;
item.prepend(cb);
item.onclick = (e) => {
if (e.target === cb) return;
cb.checked = !cb.checked;
cb.dispatchEvent(new Event('change'));
};
legendEl.appendChild(item);
});
</script>
<script>
// Render hyperedges as shaded regions
const hyperedges = [{"id": "customer_retention_flow", "label": "Customer Satisfaction & Collection", "nodes": ["admin_panel_templates_admin_panel_report_rezayat", "admin_panel_templates_admin_panel_report_debtors_no_vosol", "admin_panel_customer_customernazarinc"], "relation": "participate_in", "confidence": "EXTRACTED", "confidence_score": 0.9}, {"id": "customer_management_flow", "label": "Customer Management Flow", "nodes": ["admin_panel_customer_base_new", "admin_panel_customer_action_inc", "admin_panel_customer_id_factor", "admin_panel_customer_hesabdari"], "relation": "participate_in", "confidence": "EXTRACTED", "confidence_score": 1.0}, {"id": "financial_management_flow", "label": "Financial & Debt Management", "nodes": ["admin_panel_templates_admin_panel_financial_dashboard", "admin_panel_templates_admin_panel_hesabdari"], "relation": "participate_in", "confidence": "EXTRACTED", "confidence_score": 1.0}, {"id": "inventory_management_flow", "label": "Inventory Management System", "nodes": ["admin_panel_templates_admin_panel_store", "admin_panel_templates_admin_panel_store_transfers", "admin_panel_templates_admin_panel_report_inventory_movements", "admin_panel_templates_admin_panel_operationsbk"], "relation": "participate_in", "confidence": "EXTRACTED", "confidence_score": 1.0}, {"id": "login_form", "label": "Login Form", "nodes": ["admin_panel_templates_admin_panel_login", "django_url_admin_panel_p_login", "django_csrf_token", "form_field_username", "form_field_password"], "relation": "form", "confidence": "EXTRACTED", "source_file": "admin_panel/templates/admin_panel/login.html"}, {"id": "new_store_form", "label": "New Store Form", "nodes": ["admin_panel_templates_admin_panel_storebk1", "django_url_admin_panel_newstore", "django_csrf_token", "form_field_storename"], "relation": "form", "confidence": "EXTRACTED", "source_file": "admin_panel/templates/admin_panel/storeBK1.html"}, {"id": "store_inventory_display", "label": "Store Inventory Display", "nodes": ["admin_panel_templates_admin_panel_storebk1", "template_variable_productsum", "product_property_product_name", "product_property_mojodi"], "relation": "participate_in", "confidence": "EXTRACTED", "source_file": "admin_panel/templates/admin_panel/storeBK1.html"}, {"id": "customer_interaction_flow", "label": "Customer Lifecycle Management", "nodes": ["admin_panel_templates_admin_panel_customers"], "relation": "participate_in", "confidence": "INFERRED", "confidence_score": 0.85}, {"id": "customer_lifecycle_management", "label": "Customer Interaction Lifecycle", "nodes": ["admin_panel_templates_admin_panel_customers", "admin_panel_templates_admin_panel_customerNew", "admin_panel_templates_admin_panel_customerRezayat"], "relation": "form", "confidence": "INFERRED", "confidence_score": 0.85, "source_file": "admin_panel/templates/admin_panel/customers.html"}, {"id": "financial_management_flow", "label": "Financial & Debt Management Flow", "nodes": ["admin_panel_templates_admin_panel_customerSarresid", "admin_panel_templates_admin_panel_hesabdari", "admin_panel_templates_admin_panel_financial_dashboard"], "relation": "participate_in", "confidence": "INFERRED", "confidence_score": 0.9, "source_file": "admin_panel/templates/admin_panel/financial_dashboard.html"}, {"id": "settle_due_payment_flow", "label": "Settle Due Payment Flow", "nodes": ["admin_panel_templates_admin_panel_hesabdaricheckpassfail_html", "admin_panel_url_passcheck", "admin_panel_url_pardakhtnesiye"], "relation": "participate_in", "confidence": "INFERRED", "confidence_score": 0.9, "source_file": "admin_panel/templates/admin_panel/hesabdariCheckPassFail.html"}, {"id": "accounting_flow", "label": "Accounting and Billing Flow", "nodes": ["admin_panel_templates_admin_panel_basehesabdari", "admin_panel_templates_admin_panel_bedehi", "admin_panel_templates_admin_panel_hesabdariheckpass", "concept_url_admin_panel_hesabdari", "concept_url_admin_panel_bedehi", "concept_url_admin_panel_pardakhtnesiye"], "relation": "participate_in", "confidence": "INFERRED", "source_file": "admin_panel/templates/admin_panel/baseHesabdari.html"}, {"id": "check_clearing_flow", "label": "Check Clearing Flow", "nodes": ["admin_panel_templates_admin_panel_hesabdariresidnashode", "admin_panel_views_passcheck"], "relation": "participate_in", "confidence": "INFERRED", "source_file": "admin_panel/templates/admin_panel/hesabdariResidNashode.html"}, {"id": "customer_management_flow", "label": "Customer Management Flow", "nodes": ["admin_panel_templates_admin_panel_customerbase", "admin_panel_templates_admin_panel_customerbasenew", "admin_panel_templates_admin_panel_customeraction", "admin_panel_templates_admin_panel_customerid", "admin_panel_templates_admin_panel_customeridfactorbackup", "concept_url_admin_panel_customers", "concept_url_admin_panel_customeredit", "concept_url_admin_panel_newfactor"], "relation": "participate_in", "confidence": "INFERRED", "source_file": "admin_panel/templates/admin_panel/customerBase.html"}, {"Line truncated
// afterDrawing passes ctx already transformed to network coordinate space.
// Draw node positions raw — no manual pan/zoom/DPR math needed.
// Andrew's monotone chain. Returns the hull in counter-clockwise order, which
// is what the perimeter must be traced in. Collinear and duplicate points
// collapse to the extremes, so degenerate member sets render as a segment
// rather than a zero-area crossed path.
function convexHull(pts) {
const p = pts.slice().sort((a, b) => (a.x - b.x) || (a.y - b.y));
if (p.length < 3) return p;
const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const build = seq => {
const out = [];
for (const q of seq) {
while (out.length >= 2 && cross(out[out.length - 2], out[out.length - 1], q) <= 0) out.pop();
out.push(q);
}
out.pop();
return out;
};
const hull = build(p).concat(build(p.slice().reverse()));
return hull.length >= 3 ? hull : p;
}
network.on('afterDrawing', function(ctx) {
hyperedges.forEach(h => {
const positions = h.nodes
.map(nid => network.getPositions([nid])[nid])
.filter(p => p !== undefined);
if (positions.length < 2) return;
ctx.save();
ctx.globalAlpha = 0.12;
ctx.fillStyle = '#6366f1';
ctx.strokeStyle = '#6366f1';
ctx.lineWidth = 2;
ctx.beginPath();
// Centroid and expanded hull in network coordinates.
// The perimeter must follow hull order, not h.nodes order: tracing the
// raw member order self-intersects whenever the layout does not happen
// to place members in angular order, filling as crossed wedges.
const cx = positions.reduce((s, p) => s + p.x, 0) / positions.length;
const cy = positions.reduce((s, p) => s + p.y, 0) / positions.length;
const hull = convexHull(positions);
const expanded = hull.map(p => ({
x: cx + (p.x - cx) * 1.15,
y: cy + (p.y - cy) * 1.15
}));
ctx.moveTo(expanded[0].x, expanded[0].y);
expanded.slice(1).forEach(p => ctx.lineTo(p.x, p.y));
ctx.closePath();
ctx.fill();
ctx.globalAlpha = 0.4;
ctx.stroke();
// Label
ctx.globalAlpha = 0.8;
ctx.fillStyle = '#4f46e5';
ctx.font = 'bold 11px sans-serif';
ctx.textAlign = 'center';
ctx.fillText(h.label, cx, cy - 5);
ctx.restore();
});
});
</script>
</body>
</html>