Download index.html from CSNET/binary-mlm-tree-viewer-mockup: direct link, hf CLI and curl.
- Browser
- Download file 29.7 kB
-
https://huggingface.co/spaces/CSNET/binary-mlm-tree-viewer-mockup/resolve/main/index.html
- Command line
-
hf download hf://spaces/CSNET/binary-mlm-tree-viewer-mockup/index.html
-
curl -L -o index.html https://huggingface.co/spaces/CSNET/binary-mlm-tree-viewer-mockup/resolve/main/index.html
29.7 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Binary MLM Tree Viewer Mockup</title> | |
| <style> | |
| :root { | |
| --primary: #3B82F6; | |
| --secondary: #8B5CF6; | |
| --accent: #10B981; | |
| --danger: #EF4444; | |
| --warning: #F59E0B; | |
| --bg-main: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| --bg-card: rgba(255, 255, 255, 0.25); | |
| --bg-card-hover: rgba(255, 255, 255, 0.4); | |
| --text-primary: #1F2937; | |
| --text-secondary: #6B7280; | |
| --border-color: rgba(255, 255, 255, 0.3); | |
| --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37); | |
| --blur: blur(12px); | |
| --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); | |
| } | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| background: var(--bg-main); | |
| background-attachment: fixed; | |
| color: var(--text-primary); | |
| overflow: hidden; | |
| height: 100vh; | |
| padding: 20px; | |
| } | |
| .container { | |
| display: flex; | |
| flex-direction: column; | |
| height: calc(100vh - 40px); | |
| background: rgba(255, 255, 255, 0.1); | |
| border-radius: 20px; | |
| backdrop-filter: var(--blur); | |
| -webkit-backdrop-filter: var(--blur); | |
| border: 1px solid var(--border-color); | |
| box-shadow: var(--shadow); | |
| overflow: hidden; | |
| } | |
| header { | |
| background: rgba(255, 255, 255, 0.15); | |
| padding: 20px 30px; | |
| border-bottom: 1px solid var(--border-color); | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| flex-wrap: wrap; | |
| gap: 15px; | |
| } | |
| h1 { | |
| font-size: 28px; | |
| font-weight: 700; | |
| background: linear-gradient(45deg, var(--primary), var(--secondary)); | |
| -webkit-background-clip: text; | |
| -webkit-text-fill-color: transparent; | |
| background-clip: text; | |
| } | |
| .controls { | |
| display: flex; | |
| gap: 10px; | |
| flex-wrap: wrap; | |
| } | |
| button { | |
| padding: 10px 20px; | |
| border: none; | |
| border-radius: 10px; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: var(--transition); | |
| background: var(--bg-card); | |
| border: 1px solid var(--border-color); | |
| color: var(--text-primary); | |
| font-size: 14px; | |
| display: flex; | |
| align-items: center; | |
| gap: 5px; | |
| } | |
| button:hover { | |
| background: var(--bg-card-hover); | |
| transform: translateY(-2px); | |
| box-shadow: var(--shadow); | |
| } | |
| button:active { | |
| transform: translateY(0); | |
| } | |
| .tree-container { | |
| flex: 1; | |
| overflow-x: auto; | |
| overflow-y: auto; | |
| padding: 30px; | |
| position: relative; | |
| } | |
| .tree-container::-webkit-scrollbar { | |
| height: 8px; | |
| width: 8px; | |
| } | |
| .tree-container::-webkit-scrollbar-track { | |
| background: rgba(255, 255, 255, 0.1); | |
| border-radius: 10px; | |
| } | |
| .tree-container::-webkit-scrollbar-thumb { | |
| background: linear-gradient(45deg, var(--primary), var(--secondary)); | |
| border-radius: 10px; | |
| } | |
| .tree { | |
| display: inline-block; | |
| min-width: 100%; | |
| transform-origin: center top; | |
| transition: transform 0.3s ease; | |
| } | |
| .node-wrapper { | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| position: relative; | |
| padding: 10px 20px; | |
| } | |
| .node { | |
| background: var(--bg-card); | |
| backdrop-filter: var(--blur); | |
| -webkit-backdrop-filter: var(--blur); | |
| border: 1px solid var(--border-color); | |
| border-radius: 15px; | |
| padding: 15px; | |
| box-shadow: var(--shadow); | |
| transition: var(--transition); | |
| cursor: pointer; | |
| position: relative; | |
| min-width: 180px; | |
| max-width: 220px; | |
| z-index: 2; | |
| } | |
| .node:hover { | |
| transform: translateY(-5px); | |
| background: var(--bg-card-hover); | |
| box-shadow: 0 12px 40px rgba(31, 38, 135, 0.5); | |
| } | |
| .node-header { | |
| display: flex; | |
| align-items: center; | |
| gap: 12px; | |
| margin-bottom: 10px; | |
| } | |
| .avatar { | |
| width: 50px; | |
| height: 50px; | |
| border-radius: 50%; | |
| object-fit: cover; | |
| border: 2px solid var(--border-color); | |
| box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); | |
| } | |
| .node-info h3 { | |
| font-size: 16px; | |
| font-weight: 700; | |
| color: var(--text-primary); | |
| line-height: 1.2; | |
| } | |
| .node-info .position { | |
| font-size: 12px; | |
| font-weight: 600; | |
| color: var(--secondary); | |
| background: rgba(139, 92, 246, 0.2); | |
| padding: 2px 8px; | |
| border-radius: 6px; | |
| display: inline-block; | |
| margin-top: 3px; | |
| } | |
| .scores { | |
| display: flex; | |
| justify-content: space-between; | |
| gap: 10px; | |
| margin-top: 10px; | |
| } | |
| .score-box { | |
| flex: 1; | |
| text-align: center; | |
| padding: 8px; | |
| border-radius: 8px; | |
| background: rgba(255, 255, 255, 0.1); | |
| border: 1px solid var(--border-color); | |
| } | |
| .score-box.left { | |
| background: rgba(59, 130, 246, 0.15); | |
| border-color: rgba(59, 130, 246, 0.3); | |
| } | |
| .score-box.right { | |
| background: rgba(139, 92, 246, 0.15); | |
| border-color: rgba(139, 92, 246, 0.3); | |
| } | |
| .score-label { | |
| font-size: 10px; | |
| color: var(--text-secondary); | |
| text-transform: uppercase; | |
| font-weight: 600; | |
| } | |
| .score-value { | |
| font-size: 14px; | |
| font-weight: 700; | |
| color: var(--text-primary); | |
| } | |
| .toggle-btn { | |
| position: absolute; | |
| top: -8px; | |
| right: -8px; | |
| width: 24px; | |
| height: 24px; | |
| border-radius: 50%; | |
| background: var(--primary); | |
| color: white; | |
| border: 2px solid var(--border-color); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-size: 12px; | |
| font-weight: bold; | |
| cursor: pointer; | |
| transition: var(--transition); | |
| z-index: 3; | |
| } | |
| .toggle-btn:hover { | |
| background: var(--secondary); | |
| transform: scale(1.1); | |
| } | |
| .children { | |
| display: flex; | |
| justify-content: center; | |
| gap: 40px; | |
| margin-top: 40px; | |
| position: relative; | |
| transition: var(--transition); | |
| } | |
| .children.collapsed { | |
| display: none; | |
| } | |
| .children::before { | |
| content: ''; | |
| position: absolute; | |
| top: -20px; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| width: 2px; | |
| height: 20px; | |
| background: linear-gradient(to bottom, var(--primary), var(--secondary)); | |
| opacity: 0.6; | |
| } | |
| .child-wrapper { | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| position: relative; | |
| } | |
| .child-wrapper::before { | |
| content: ''; | |
| position: absolute; | |
| top: -20px; | |
| width: 50%; | |
| height: 2px; | |
| background: linear-gradient(to right, var(--primary), var(--secondary)); | |
| opacity: 0.6; | |
| } | |
| .child-wrapper.left::before { | |
| right: 0; | |
| } | |
| .child-wrapper.right::before { | |
| left: 0; | |
| } | |
| .tooltip { | |
| position: fixed; | |
| background: rgba(0, 0, 0, 0.9); | |
| color: white; | |
| padding: 10px 15px; | |
| border-radius: 8px; | |
| font-size: 12px; | |
| z-index: 1000; | |
| pointer-events: none; | |
| opacity: 0; | |
| transition: opacity 0.3s; | |
| max-width: 250px; | |
| backdrop-filter: blur(10px); | |
| -webkit-backdrop-filter: blur(10px); | |
| border: 1px solid rgba(255, 255, 255, 0.1); | |
| } | |
| .color-dropdown { | |
| position: absolute; | |
| top: 80px; | |
| right: 30px; | |
| background: var(--bg-card); | |
| backdrop-filter: var(--blur); | |
| -webkit-backdrop-filter: var(--blur); | |
| border: 1px solid var(--border-color); | |
| border-radius: 10px; | |
| box-shadow: var(--shadow); | |
| padding: 10px; | |
| z-index: 100; | |
| min-width: 180px; | |
| } | |
| .color-option { | |
| padding: 8px 12px; | |
| cursor: pointer; | |
| border-radius: 6px; | |
| margin-bottom: 5px; | |
| font-size: 14px; | |
| font-weight: 600; | |
| transition: var(--transition); | |
| color: var(--text-primary); | |
| } | |
| .color-option:hover { | |
| background: var(--bg-card-hover); | |
| transform: translateX(5px); | |
| } | |
| .color-option:last-child { | |
| margin-bottom: 0; | |
| } | |
| .hidden { | |
| display: none; | |
| } | |
| @media (max-width: 768px) { | |
| header { | |
| padding: 15px 20px; | |
| } | |
| h1 { | |
| font-size: 22px; | |
| } | |
| button { | |
| padding: 8px 15px; | |
| font-size: 13px; | |
| } | |
| .node { | |
| min-width: 150px; | |
| padding: 12px; | |
| } | |
| .avatar { | |
| width: 40px; | |
| height: 40px; | |
| } | |
| .node-info h3 { | |
| font-size: 14px; | |
| } | |
| .children { | |
| gap: 20px; | |
| } | |
| .color-dropdown { | |
| top: 70px; | |
| right: 20px; | |
| min-width: 150px; | |
| } | |
| .color-option { | |
| font-size: 13px; | |
| padding: 6px 10px; | |
| } | |
| } | |
| header { | |
| padding: 15px 20px; | |
| } | |
| h1 { | |
| font-size: 22px; | |
| } | |
| button { | |
| padding: 8px 15px; | |
| font-size: 13px; | |
| } | |
| .node { | |
| min-width: 150px; | |
| padding: 12px; | |
| } | |
| .avatar { | |
| width: 40px; | |
| height: 40px; | |
| } | |
| .node-info h3 { | |
| font-size: 14px; | |
| } | |
| .children { | |
| gap: 20px; | |
| } | |
| } | |
| @media (max-width: 480px) { | |
| body { | |
| padding: 10px; | |
| } | |
| .container { | |
| height: calc(100vh - 20px); | |
| } | |
| .tree-container { | |
| padding: 15px; | |
| } | |
| .node { | |
| min-width: 130px; | |
| padding: 10px; | |
| } | |
| .avatar { | |
| width: 35px; | |
| height: 35px; | |
| } | |
| .node-info h3 { | |
| font-size: 13px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <header> | |
| <h1>Binary MLM Tree Viewer</h1> | |
| <div class="controls"> | |
| <button id="zoomOut">β Zoom Out</button> | |
| <button id="zoomIn">+ Zoom In</button> | |
| <button id="expandAll">π Expand All</button> | |
| <button id="collapseAll">π Collapse All</button> | |
| <button id="bgColorBtn">π¨ Background</button> | |
| </div> | |
| </header> | |
| <div id="colorDropdown" class="color-dropdown hidden"> | |
| <div class="color-option" data-gradient="linear-gradient(135deg, #667eea 0%, #764ba2 100%)">π£ Purple (Default)</div> | |
| <div class="color-option" data-gradient="linear-gradient(135deg, #3B82F6 0%, #06B6D4 100%)">π΅ Blue</div> | |
| <div class="color-option" data-gradient="linear-gradient(135deg, #10B981 0%, #34D399 100%)">π’ Green</div> | |
| <div class="color-option" data-gradient="linear-gradient(135deg, #F59E0B 0%, #F97316 100%)">π Orange</div> | |
| <div class="color-option" data-gradient="linear-gradient(135deg, #EC4899 0%, #F472B6 100%)">πΈ Pink</div> | |
| <div class="color-option" data-gradient="linear-gradient(135deg, #6B7280 0%, #374151 100%)">π Dark</div> | |
| </div> | |
| <div class="tree-container" id="treeContainer"> | |
| <div class="tree" id="tree"></div> | |
| </div> | |
| </div> | |
| <div class="tooltip" id="tooltip"></div> | |
| <script> | |
| // Mock Data | |
| const mockData = [ | |
| { id: 1, parentId: null, side: null, name: "Tony Stark", position: "Diamond", avatarUrl: "https://static.photos/technology/200x200/1", scoreLeft: 15500, scoreRight: 22500, isExpanded: true, details: "Joined: 2024/01/01 | Total: 38,000 PV | Team Size: 2,450" }, | |
| { id: 2, parentId: 1, side: "L", name: "Steve Rogers", position: "Platinum", avatarUrl: "https://static.photos/people/200x200/2", scoreLeft: 8500, scoreRight: 12000, isExpanded: true, details: "Joined: 2024/02/15 | Total: 20,500 PV | Team Size: 1,200" }, | |
| { id: 3, parentId: 1, side: "R", name: "Bruce Banner", position: "Platinum", avatarUrl: "https://static.photos/science/200x200/3", scoreLeft: 7000, scoreRight: 10500, isExpanded: true, details: "Joined: 2024/03/10 | Total: 17,500 PV | Team Size: 1,050" }, | |
| { id: 4, parentId: 2, side: "L", name: "Natasha Romanoff", position: "Gold", avatarUrl: "https://static.photos/people/200x200/4", scoreLeft: 4500, scoreRight: 3800, isExpanded: true, details: "Joined: 2024/04/20 | Total: 8,300 PV | Team Size: 520" }, | |
| { id: 5, parentId: 2, side: "R", name: "Clint Barton", position: "Gold", avatarUrl: "https://static.photos/outdoor/200x200/5", scoreLeft: 4000, scoreRight: 4200, isExpanded: true, details: "Joined: 2024/05/05 | Total: 8,200 PV | Team Size: 480" }, | |
| { id: 6, parentId: 3, side: "L", name: "Thor Odinson", position: "Gold", avatarUrl: "https://static.photos/abstract/200x200/6", scoreLeft: 3200, scoreRight: 4500, isExpanded: true, details: "Joined: 2024/06/12 | Total: 7,700 PV | Team Size: 450" }, | |
| { id: 7, parentId: 3, side: "R", name: "Loki Laufeyson", position: "Gold", avatarUrl: "https://static.photos/minimal/200x200/7", scoreLeft: 3800, scoreRight: 3000, isExpanded: true, details: "Joined: 2024/07/18 | Total: 6,800 PV | Team Size: 400" }, | |
| { id: 8, parentId: 4, side: "L", name: "Peter Parker", position: "Silver", avatarUrl: "https://static.photos/people/200x200/8", scoreLeft: 2000, scoreRight: 1500, isExpanded: false, details: "Joined: 2024/08/25 | Total: 3,500 PV | Team Size: 180" }, | |
| { id: 9, parentId: 4, side: "R", name: "Wanda Maximoff", position: "Silver", avatarUrl: "https://static.photos/abstract/200x200/9", scoreLeft: 1500, scoreRight: 1800, isExpanded: false, details: "Joined: 2024/09/10 | Total: 3,300 PV | Team Size: 165" }, | |
| { id: 10, parentId: 5, side: "L", name: "Vision", position: "Silver", avatarUrl: "https://static.photos/technology/200x200/10", scoreLeft: 1800, scoreRight: 1700, isExpanded: false, details: "Joined: 2024/10/03 | Total: 3,500 PV | Team Size: 175" }, | |
| { id: 11, parentId: 5, side: "R", name: "Sam Wilson", position: "Silver", avatarUrl: "https://static.photos/outdoor/200x200/11", scoreLeft: 1600, scoreRight: 1900, isExpanded: false, details: "Joined: 2024/11/15 | Total: 3,500 PV | Team Size: 170" }, | |
| { id: 12, parentId: 6, side: "L", name: "Bucky Barnes", position: "Silver", avatarUrl: "https://static.photos/people/200x200/12", scoreLeft: 1400, scoreRight: 1300, isExpanded: false, details: "Joined: 2024/12/01 | Total: 2,700 PV | Team Size: 140" }, | |
| { id: 13, parentId: 6, side: "R", name: "Carol Danvers", position: "Silver", avatarUrl: "https://static.photos/abstract/200x200/13", scoreLeft: 1100, scoreRight: 1600, isExpanded: false, details: "Joined: 2024/12/20 | Total: 2,700 PV | Team Size: 135" }, | |
| { id: 14, parentId: 7, side: "L", name: "Scott Lang", position: "Silver", avatarUrl: "https://static.photos/minimal/200x200/14", scoreLeft: 1200, scoreRight: 1100, isExpanded: false, details: "Joined: 2025/01/05 | Total: 2,300 PV | Team Size: 125" }, | |
| { id: 15, parentId: 7, side: "R", name: "Hope Van Dyne", position: "Silver", avatarUrl: "https://static.photos/people/200x200/15", scoreLeft: 1300, scoreRight: 1000, isExpanded: false, details: "Joined: 2025/01/18 | Total: 2,300 PV | Team Size: 120" }, | |
| { id: 16, parentId: 8, side: "L", name: "Stephen Strange", position: "Bronze", avatarUrl: "https://static.photos/abstract/200x200/16", scoreLeft: 800, scoreRight: 600, isExpanded: false, details: "Joined: 2025/02/10 | Total: 1,400 PV | Team Size: 75" }, | |
| { id: 17, parentId: 8, side: "R", name: "T'Challa", position: "Bronze", avatarUrl: "https://static.photos/nature/200x200/17", scoreLeft: 700, scoreRight: 700, isExpanded: false, details: "Joined: 2025/02/25 | Total: 1,400 PV | Team Size: 70" }, | |
| { id: 18, parentId: 9, side: "L", name: "Shuri", position: "Bronze", avatarUrl: "https://static.photos/technology/200x200/18", scoreLeft: 600, scoreRight: 650, isExpanded: false, details: "Joined: 2025/03/08 | Total: 1,250 PV | Team Size: 65" }, | |
| { id: 19, parentId: 9, side: "R", name: "Okoye", position: "Bronze", avatarUrl: "https://static.photos/people/200x200/19", scoreLeft: 550, scoreRight: 600, isExpanded: false, details: "Joined: 2025/03/20 | Total: 1,150 PV | Team Size: 60" }, | |
| { id: 20, parentId: 10, side: "L", name: "M'Baku", position: "Bronze", avatarUrl: "https://static.photos/outdoor/200x200/20", scoreLeft: 500, scoreRight: 550, isExpanded: false, details: "Joined: 2025/04/02 | Total: 1,050 PV | Team Size: 55" } | |
| ]; | |
| // State Management | |
| let zoomLevel = 1; | |
| const MIN_ZOOM = 0.5; | |
| const MAX_ZOOM = 2; | |
| const ZOOM_STEP = 0.1; | |
| // Utility Functions | |
| function formatNumber(num) { | |
| return num.toLocaleString(); | |
| } | |
| function getPositionColor(position) { | |
| const colors = { | |
| "Diamond": "linear-gradient(45deg, #FFD700, #FFA500)", | |
| "Platinum": "linear-gradient(45deg, #E5E4E2, #C0C0C0)", | |
| "Gold": "linear-gradient(45deg, #FFD700, #FFA000)", | |
| "Silver": "linear-gradient(45deg, #C0C0C0, #A0A0A0)", | |
| "Bronze": "linear-gradient(45deg, #CD7F32, #A0522D)" | |
| }; | |
| return colors[position] || "linear-gradient(45deg, #3B82F6, #8B5CF6)"; | |
| } | |
| // Build Tree Structure | |
| function buildTree(nodeId) { | |
| const node = mockData.find(n => n.id === nodeId); | |
| if (!node) return null; | |
| const children = mockData.filter(n => n.parentId === nodeId); | |
| const leftChild = children.find(c => c.side === "L"); | |
| const rightChild = children.find(c => c.side === "R"); | |
| return { | |
| ...node, | |
| left: leftChild ? buildTree(leftChild.id) : null, | |
| right: rightChild ? buildTree(rightChild.id) : null | |
| }; | |
| } | |
| // Create Node Element | |
| function createNodeElement(node) { | |
| const wrapper = document.createElement('div'); | |
| wrapper.className = 'node-wrapper'; | |
| const nodeDiv = document.createElement('div'); | |
| nodeDiv.className = 'node'; | |
| nodeDiv.dataset.nodeId = node.id; | |
| // Avatar and Info | |
| const hasChildren = node.left || node.right; | |
| nodeDiv.innerHTML = ` | |
| ${hasChildren ? `<div class="toggle-btn">${node.isExpanded ? 'β' : '+'}</div>` : ''} | |
| <div class="node-header"> | |
| <img src="${node.avatarUrl}" alt="${node.name}" class="avatar" onerror="this.src='https://static.photos/people/200x200/1'"> | |
| <div class="node-info"> | |
| <h3>${node.name}</h3> | |
| <span class="position" style="background: ${getPositionColor(node.position)}20; color: ${getPositionColor(node.position).match(/#[a-fA-F0-9]{6}/)[0]}">${node.position}</span> | |
| </div> | |
| </div> | |
| <div class="scores"> | |
| <div class="score-box left"> | |
| <div class="score-label">Left</div> | |
| <div class="score-value">${formatNumber(node.scoreLeft)}</div> | |
| </div> | |
| <div class="score-box right"> | |
| <div class="score-label">Right</div> | |
| <div class="score-value">${formatNumber(node.scoreRight)}</div> | |
| </div> | |
| </div> | |
| `; | |
| wrapper.appendChild(nodeDiv); | |
| // Children Container | |
| if (hasChildren) { | |
| const childrenDiv = document.createElement('div'); | |
| childrenDiv.className = `children ${node.isExpanded ? '' : 'collapsed'}`; | |
| // Left Child | |
| if (node.left) { | |
| const leftWrapper = document.createElement('div'); | |
| leftWrapper.className = 'child-wrapper left'; | |
| leftWrapper.appendChild(createNodeElement(node.left)); | |
| childrenDiv.appendChild(leftWrapper); | |
| } | |
| // Right Child | |
| if (node.right) { | |
| const rightWrapper = document.createElement('div'); | |
| rightWrapper.className = 'child-wrapper right'; | |
| rightWrapper.appendChild(createNodeElement(node.right)); | |
| childrenDiv.appendChild(rightWrapper); | |
| } | |
| wrapper.appendChild(childrenDiv); | |
| } | |
| // Event Listeners | |
| nodeDiv.addEventListener('click', (e) => { | |
| if (e.target.classList.contains('toggle-btn')) { | |
| e.stopPropagation(); | |
| toggleNode(node.id); | |
| } | |
| }); | |
| nodeDiv.addEventListener('mouseenter', (e) => showTooltip(e, node)); | |
| nodeDiv.addEventListener('mouseleave', hideTooltip); | |
| return wrapper; | |
| } | |
| // Toggle Node Expand/Collapse | |
| function toggleNode(nodeId) { | |
| const node = mockData.find(n => n.id === nodeId); | |
| if (node) { | |
| node.isExpanded = !node.isExpanded; | |
| renderTree(); | |
| } | |
| } | |
| // Tooltip Functions | |
| function showTooltip(e, node) { | |
| const tooltip = document.getElementById('tooltip'); | |
| tooltip.innerHTML = ` | |
| <strong>${node.name}</strong><br> | |
| Position: ${node.position}<br> | |
| ${node.details} | |
| `; | |
| tooltip.classList.add('visible'); | |
| updateTooltipPosition(e); | |
| } | |
| function hideTooltip() { | |
| const tooltip = document.getElementById('tooltip'); | |
| tooltip.classList.remove('visible'); | |
| } | |
| function updateTooltipPosition(e) { | |
| const tooltip = document.getElementById('tooltip'); | |
| const rect = tooltip.getBoundingClientRect(); | |
| let x = e.clientX; | |
| let y = e.clientY - rect.height - 10; | |
| if (x + rect.width > window.innerWidth) { | |
| x = window.innerWidth - rect.width - 10; | |
| } | |
| if (y < 10) { | |
| y = e.clientY + 10; | |
| } | |
| tooltip.style.left = x + 'px'; | |
| tooltip.style.top = y + 'px'; | |
| } | |
| // Zoom Functions | |
| function setZoom(level) { | |
| zoomLevel = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, level)); | |
| const tree = document.getElementById('tree'); | |
| tree.style.transform = `scale(${zoomLevel})`; | |
| } | |
| // Expand/Collapse All | |
| function expandAll(expand = true) { | |
| mockData.forEach(node => { | |
| const hasChildren = mockData.some(n => n.parentId === node.id); | |
| if (hasChildren) { | |
| node.isExpanded = expand; | |
| } | |
| }); | |
| renderTree(); | |
| } | |
| // Render Tree | |
| function renderTree() { | |
| const treeContainer = document.getElementById('tree'); | |
| treeContainer.innerHTML = ''; | |
| const rootNode = mockData.find(n => n.parentId === null); | |
| if (rootNode) { | |
| const tree = buildTree(rootNode.id); | |
| treeContainer.appendChild(createNodeElement(tree)); | |
| } | |
| } | |
| // Initialize | |
| document.addEventListener('DOMContentLoaded', () => { | |
| // Load saved background color | |
| const savedGradient = localStorage.getItem('bgGradient'); | |
| if (savedGradient) { | |
| document.documentElement.style.setProperty('--bg-main', savedGradient); | |
| } | |
| renderTree(); | |
| // Zoom Controls | |
| document.getElementById('zoomIn').addEventListener('click', () => { | |
| setZoom(zoomLevel + ZOOM_STEP); | |
| }); | |
| document.getElementById('zoomOut').addEventListener('click', () => { | |
| setZoom(zoomLevel - ZOOM_STEP); | |
| }); | |
| // Mouse wheel zoom (hold Ctrl/Cmd) | |
| document.getElementById('treeContainer').addEventListener('wheel', (e) => { | |
| if (e.ctrlKey || e.metaKey) { | |
| e.preventDefault(); | |
| if (e.deltaY < 0) { | |
| setZoom(zoomLevel + ZOOM_STEP); | |
| } else { | |
| setZoom(zoomLevel - ZOOM_STEP); | |
| } | |
| } | |
| }); | |
| // Expand/Collapse Controls | |
| document.getElementById('expandAll').addEventListener('click', () => expandAll(true)); | |
| document.getElementById('collapseAll').addEventListener('click', () => expandAll(false)); | |
| // Background Color Controls | |
| const bgColorBtn = document.getElementById('bgColorBtn'); | |
| const colorDropdown = document.getElementById('colorDropdown'); | |
| const colorOptions = document.querySelectorAll('.color-option'); | |
| bgColorBtn.addEventListener('click', (e) => { | |
| e.stopPropagation(); | |
| colorDropdown.classList.toggle('hidden'); | |
| }); | |
| colorOptions.forEach(option => { | |
| option.addEventListener('click', () => { | |
| const gradient = option.dataset.gradient; | |
| document.documentElement.style.setProperty('--bg-main', gradient); | |
| localStorage.setItem('bgGradient', gradient); | |
| colorDropdown.classList.add('hidden'); | |
| }); | |
| }); | |
| // Close dropdown when clicking outside | |
| document.addEventListener('click', () => { | |
| colorDropdown.classList.add('hidden'); | |
| }); | |
| // Prevent dropdown from closing when clicking inside it | |
| colorDropdown.addEventListener('click', (e) => { | |
| e.stopPropagation(); | |
| }); | |
| // Mouse move for tooltip | |
| document.addEventListener('mousemove', (e) => { | |
| const tooltip = document.getElementById('tooltip'); | |
| if (tooltip.classList.contains('visible')) { | |
| updateTooltipPosition(e); | |
| } | |
| }); | |
| // Keyboard shortcuts | |
| document.addEventListener('keydown', (e) => { | |
| if (e.key === '+' || e.key === '=') { | |
| setZoom(zoomLevel + ZOOM_STEP); | |
| } else if (e.key === '-') { | |
| setZoom(zoomLevel - ZOOM_STEP); | |
| } else if (e.key === '0') { | |
| setZoom(1); | |
| } | |
| }); | |
| }); | |
| // Update tree on window resize | |
| window.addEventListener('resize', () => { | |
| const treeContainer = document.getElementById('treeContainer'); | |
| const tree = document.getElementById('tree'); | |
| const containerWidth = treeContainer.clientWidth; | |
| const treeWidth = tree.scrollWidth * zoomLevel; | |
| if (treeWidth > containerWidth) { | |
| tree.style.transformOrigin = 'left top'; | |
| } else { | |
| tree.style.transformOrigin = 'center top'; | |
| } | |
| }); | |
| </script> | |
| <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script> | |
| </body> | |
| </html> |