<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Monorepo Visualizer | Dependency Graph & Freshness</title>
<!-- Fonts: Inter (UI), Playfair Display (Headings) -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Playfair+Display:wght@700;900&display=swap" rel="stylesheet">
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
sans: ['Inter', 'sans-serif'],
serif: ['Playfair Display', 'serif'],
},
colors: {
cyber: {
blue: '#00f3ff',
purple: '#bc13fe',
pink: '#ff0055',
},
slate: {
900: '#0a0a0a',
800: '#151515',
}
},
animation: {
'pulse-slow': 'pulse 4s cubic-bezier(0.4, 0, 0.6, 1) infinite',
}
}
}
}
</script>
<style>
/* Noise Texture Overlay */
.noise-overlay {
position: fixed;
top: 0; left: 0; width: 100%; height: 100%;
pointer-events: none;
z-index: 50;
opacity: 0.05;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}
/* 3D Canvas */
#graph-canvas {
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
z-index: 0;
outline: none;
}
/* Glassmorphism Utilities */
.glass-panel {
background: rgba(20, 20, 20, 0.6);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}
.glass-button {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
backdrop-filter: blur(4px);
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.glass-button:hover {
background: rgba(255, 255, 255, 0.15);
border-color: rgba(255, 255, 255, 0.3);
transform: translateY(-2px);
box-shadow: 0 0 15px rgba(0, 243, 255, 0.2);
}
/* Dynamic Background Mesh */
.mesh-bg {
position: fixed;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
width: 150vw; height: 150vw;
background: radial-gradient(circle at center, rgba(20, 20, 40, 0.8) 0%, rgba(10, 10, 10, 1) 70%);
z-index: -1;
filter: blur(50px);
opacity: 0.6;
animation: rotateMesh 60s linear infinite;
}
.orb {
position: absolute;
border-radius: 50%;
filter: blur(80px);
mix-blend-mode: screen;
}
.orb-1 {
top: 20%; left: 20%;
width: 40vw; height: 40vw;
background: radial-gradient(circle, rgba(0, 243, 255, 0.15), transparent 70%);
animation: float 20s ease-in-out infinite alternate;
}
.orb-2 {
bottom: 20%; right: 20%;
width: 35vw; height: 35vw;
background: radial-gradient(circle, rgba(188, 19, 254, 0.15), transparent 70%);
animation: float 25s ease-in-out infinite alternate-reverse;
}
@keyframes rotateMesh {
0% { transform: translate(-50%, -50%) rotate(0deg); }
100% { transform: translate(-50%, -50%) rotate(360deg); }
}
@keyframes float {
0% { transform: translate(0, 0); }
100% { transform: translate(30px, -50px); }
}
/* Typography Utilities */
.text-outline {
color: transparent;
-webkit-text-stroke: 1px rgba(255, 255, 255, 0.2);
}
/* Loading Overlay */
#loader {
position: fixed; inset: 0; background: #000;
z-index: 100;
display: flex; justify-content: center; align-items: center;
transition: opacity 1s ease;
}
</style>
<!-- Import Map for Three.js & Addons -->
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
</head>
<body class="bg-slate-900 text-white overflow-hidden font-sans antialiased selection:bg-cyber-blue selection:text-black">
<!-- Noise Grain -->
<div class="noise-overlay"></div>
<!-- Dynamic 3D Background Mesh -->
<div class="mesh-bg pointer-events-none">
<div class="orb orb-1"></div>
<div class="orb orb-2"></div>
</div>
<!-- Loading Screen -->
<div id="loader">
<div class="text-center">
<h2 class="font-serif text-3xl text-white animate-pulse">Analyzing Dependencies...</h2>
</div>
</div>
<!-- UI Layout -->
<div class="relative z-10 w-full h-full pointer-events-none flex flex-col justify-between p-6 md:p-12">
<!-- Header -->
<header class="flex justify-between items-start pointer-events-auto">
<div>
<div class="flex items-center gap-2 mb-2">
<div class="w-2 h-2 bg-cyber-blue rounded-full animate-pulse shadow-[0_0_10px_#00f3ff]"></div>
<span class="text-xs font-bold tracking-[0.2em] text-gray-400 uppercase">System Status: ONLINE</span>
</div>
<h1 class="font-serif text-5xl md:text-7xl font-bold leading-tight">
DEPENDENCY<br>
<span class="text-outline">VISUALIZER</span>
</h1>
</div>
<div class="hidden md:block text-right">
<div class="text-sm text-gray-400 mb-1">Active Monorepo</div>
<div class="text-2xl font-bold tracking-widest">@CORP/PLATFORM</div>
</div>
</header>
<!-- Main Content Area (3D Canvas is background, UI floats here) -->
<main class="flex-grow relative flex items-center">
<!-- Empty center allows 3D scene to be seen -->
</main>
<!-- Sidebar / Control Panel (Bottom Left) -->
<aside class="pointer-events-auto w-full max-w-xs space-y-6">
<!-- Stats Card -->
<div class="glass-panel p-6 rounded-2xl border-l-4 border-cyber-blue transition-transform hover:scale-[1.02] duration-300">
<div class="flex justify-between items-end mb-4">
<h3 class="text-sm font-semibold text-gray-300 uppercase tracking-wider">Repository Health</h3>
<span class="text-xs font-mono text-cyber-blue" id="date-display">--</span>
</div>
<div class="grid grid-cols-2 gap-4">
<div class="flex flex-col">
<span class="text-3xl font-bold font-mono" id="total-count">0</span>
<span class="text-xs text-gray-500">PACKAGES</span>
</div>
<div class="flex flex-col items-end">
<span class="text-3xl font-bold font-mono text-cyber-pink" id="stale-count">0</span>
<span class="text-xs text-gray-500">STALE (>30d)</span>
</div>
</div>
<!-- Progress Bar for SLA -->
<div class="mt-4 w-full h-1 bg-gray-800 rounded-full overflow-hidden">
<div id="sla-bar" class="h-full bg-gradient-to-r from-cyber-blue to-cyber-purple w-0 transition-all duration-1000 ease-out"></div>
</div>
<p class="mt-2 text-xs text-gray-500">Freshness SLA Compliance: <span id="compliance-percent" class="text-white">0%</span></p>
</div>
<!-- Controls & Legend -->
<div class="glass-panel p-5 rounded-2xl">
<h3 class="text-sm font-semibold text-gray-300 uppercase tracking-wider mb-4">Filters & Impact</h3>
<div class="space-y-3">
<label class="flex items-center justify-between cursor-pointer group">
<span class="text-sm text-gray-400 group-hover:text-white transition-colors">Highlight Risk</span>
<div class="relative">
<input type="checkbox" id="risk-toggle" class="sr-only peer" checked>
<div class="w-10 h-6 bg-gray-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-cyber-blue"></div>
</div>
</label>
<label class="flex items-center justify-between cursor-pointer group">
<span class="text-sm text-gray-400 group-hover:text-white transition-colors">Physics Enable</span>
<div class="relative">
<input type="checkbox" id="physics-toggle" class="sr-only peer">
<div class="w-10 h-6 bg-gray-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-cyber-purple"></div>
</div>
</label>
</div>
<div class="mt-6 border-t border-gray-700 pt-4">
<h4 class="text-xs font-bold text-gray-400 uppercase mb-2">SLA Legend</h4>
<div class="flex flex-wrap gap-3">
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full bg-emerald-500 shadow-[0_0_8px_rgba(16,185,129,0.6)]"></span>
<span class="text-xs text-gray-500">< 7d</span>
</div>
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full bg-amber-500 shadow-[0_0_8px_rgba(245,158,11,0.6)]"></span>
<span class="text-xs text-gray-500">7-30d</span>
</div>
<div class="flex items-center gap-2">
<span class="w-3 h-3 rounded-full bg-rose-500 shadow-[0_0_8px_rgba(244,63,94,0.6)]"></span>
<span class="text-xs text-gray-500">> 30d</span>
</div>
</div>
</div>
</div>
</aside>
<!-- Sticky Tooltip (Follows mouse) -->
<div id="tooltip" class="fixed pointer-events-none hidden glass-panel p-4 rounded-xl z-50 max-w-sm transform -translate-x-1/2 -translate-y-full transition-opacity duration-200 opacity-0">
<div class="flex items-start justify-between gap-4">
<div>
<h4 class="font-bold text-white text-lg font-serif" id="tt-name">Package Name</h4>
<span id="tt-type" class="text-xs text-cyber-blue uppercase tracking-wider text-xs">Type</span>
<div class="mt-2 space-y-1 text-sm text-gray-400">
<p>Version: <span id="tt-version" class="text-gray-200 font-mono">1.0.0</span></p>
<p>Updated: <span id="tt-date" class="text-gray-200 font-mono">--</span></p>
</div>
<div id="tt-risk" class="mt-2 text-xs hidden px-2 py-1 rounded bg-rose-500/20 text-rose-400 border border-rose-500/30">
⚠️ STALE: Risk of breaking changes
</div>
</div>
<div class="h-10 w-10 rounded-full bg-gray-800 flex items-center justify-center border border-gray-700">
<span class="text-lg" id="tt-icon">📦</span>
</div>
</div>
</div>
</div>
<!-- Canvas -->
<canvas id="graph-canvas"></canvas>
<!-- Application Logic -->
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
// --- Configuration ---
const CONFIG = {
nodeCount: 80,
edgeCountMultiplier: 1.5,
colors: {
fresh: 0x10b981, // Emerald 500
warning: 0xf59e0b, // Amber 500
stale: 0xf43f5e, // Rose 500
edge: 0x444444,
highlightEdge: 0xffffff
},
staleThresholdDays: 30,
warningThresholdDays: 7,
bloomStrength: 1.2,
bloomRadius: 0.5,
bloomThreshold: 0.1
};
// --- State ---
const state = {
nodesData: [],
edgesData: [],
sceneNodes: [], // Array of meshes
sceneEdges: [], // Array of lines
highlightedNode: null,
isPhysicsEnabled: false,
riskHighlightEnabled: true,
hoveredNode: null,
raycaster: new THREE.Raycaster(),
mouse: new THREE.Vector2(),
selectionNode: null,
time: 0
};
// --- DOM Elements ---
const canvas = document.getElementById('graph-canvas');
const tooltip = document.getElementById('tooltip');
const ttName = document.getElementById('tt-name');
const ttType = document.getElementById('tt-type');
const ttVersion = document.getElementById('tt-version');
const ttDate = document.getElementById('tt-date');
const ttIcon = document.getElementById('tt-icon');
const loader = document.getElementById('loader');
// UI Panels
const totalCountEl = document.getElementById('total-count');
const staleCountEl = document.getElementById('stale-count');
const slaBarEl = document.getElementById('sla-bar');
const complianceEl = document.getElementById('compliance-percent');
const dateDisplayEl = document.getElementById('date-display');
// --- Data Generation ---
function randomDate(daysAgo) {
const date = new Date();
date.setDate(date.getDate() - Math.floor(Math.random() * daysAgo));
return date.toISOString().split('T')[0];
}
function generateData() {
const types = ['core', 'utils', 'ui', 'api', 'db', 'deploy', 'config', 'test'];
const nodes = [];
const edges = [];
// Generate Nodes
for (let i = 0; i < CONFIG.nodeCount; i++) {
const daysOld = Math.floor(Math.random() * 180); // Max 6 months old
const lastUpdated = randomDate(daysOld);
const freshness = getFreshnessLevel(daysOld);
nodes.push({
id: `pkg-${i}`,
name: `@corp/${types[Math.floor(Math.random()*types.length)]}-${i}`,
type: types[Math.floor(Math.random()*types.length)],
version: `${Math.floor(Math.random()*5)}.${Math.floor(Math.random()*10)}.${Math.floor(Math.random()*20)}`,
lastUpdated: lastUpdated,
daysOld: daysOld,
freshness: freshness
});
}
// Generate Edges (Dependencies)
for (let i = 0; i < CONFIG.nodeCount * CONFIG.edgeCountMultiplier; i++) {
const sourceIdx = Math.floor(Math.random() * CONFIG.nodeCount);
const targetIdx = Math.floor(Math.random() * CONFIG.nodeCount);
if (sourceIdx !== targetIdx) {
// Avoid duplicates
const exists = edges.find(e => e.source === sourceIdx && e.target === targetIdx);
if (!exists) {
edges.push({ source: sourceIdx, target: targetIdx });
}
}
}
return { nodes, edges };
}
function getFreshnessLevel(days) {
if (days < CONFIG.warningThresholdDays) return 'fresh';
if (days < CONFIG.staleThresholdDays) return 'warning';
return 'stale';
}
function getColorByFreshness(level) {
switch(level) {
case 'fresh': return CONFIG.colors.fresh;
case 'warning': return CONFIG.colors.warning;
case 'stale': return CONFIG.colors.stale;
default: return 0xffffff;
}
}
// --- Initialize ---
state.nodesData = generateData().nodes;
state.edgesData = generateData().edges; // Re-generated but count matches lines roughly
// Actually link edges from the same generation batch to ensure consistency
const generated = generateData();
state.nodesData = generated.nodes;
state.edgesData = generated.edges;
// Update UI Stats
totalCountEl.innerText = state.nodesData.length;
const staleCount = state.nodesData.filter(n => n.freshness === 'stale').length;
staleCountEl.innerText = staleCount;
today = new Date();
dateDisplayEl.innerText = today.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
const compliance = Math.round(((state.nodesData.length - staleCount) / state.nodesData.length) * 100);
complianceEl.innerText = `${compliance}%`;
slaBarEl.style.width = `${compliance}%`;
if(compliance < 70) slaBarEl.classList.remove('bg-gradient-to-r', 'from-cyber-blue', 'to-cyber-purple');
else slaBarEl.classList.add('bg-gradient-to-r', 'from-cyber-blue', 'to-cyber-purple');
// --- Three.js Setup ---
const scene = new THREE.Scene();
// Fog for depth
scene.fog = new THREE.FogExp2(0x0a0a0a, 0.0015);
const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 20, 60);
const renderer = new THREE.WebGLRenderer({ canvas: canvas, alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.toneMapping = THREE.ReinhardToneMapping;
// Controls
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
controls.maxDistance = 150;
controls.minDistance = 10;
// --- Post Processing (Bloom) ---
const composer = new EffectComposer(renderer);
const renderPass = new RenderPass(scene, camera);
composer.addPass(renderPass);
const bloomPass = new UnrealBloomPass(
new THREE.Vector2(window.innerWidth, window.innerHeight),
CONFIG.bloomStrength,
CONFIG.bloomRadius,
CONFIG.bloomThreshold
);
composer.addPass(bloomPass);
// --- Graph Construction ---
const sphereGeom = new THREE.SphereGeometry(1, 32, 32);
// Shader-like material using MeshStandard for performance + bloom
const sphereMaterial = new THREE.MeshStandardMaterial({
roughness: 0.4,
metalness: 0.8,
emissive: 0x000000,
emissiveIntensity: 0.5
});
const lineMaterial = new THREE.LineBasicMaterial({
color: CONFIG.colors.edge,
transparent: true,
opacity: 0.2
});
// Create Nodes
state.nodesData.forEach((data, idx) => {
const color = getColorByFreshness(data.freshness);
const material = sphereMaterial.clone();
material.color.setHex(color);
material.emissive.setHex(color);
const mesh = new THREE.Mesh(sphereGeom, material);
// Random initial positions scattering
mesh.position.set(
(Math.random() - 0.5) * 80,
(Math.random() - 0.5) * 80,
(Math.random() - 0.5) * 80
);
mesh.userData = {
id: data.id,
originalScale: mesh.scale.clone(),
baseColor: color,
data: data,
neighbors: new Set(),
velocity: new THREE.Vector3()
};
scene.add(mesh);
state.sceneNodes.push(mesh);
});
// Add neighbors to node data
state.edgesData.forEach(edge => {
const sourceNode = state.sceneNodes[edge.source];
const targetNode = state.sceneNodes[edge.target];
if (sourceNode && targetNode) {
sourceNode.userData.neighbors.add(targetNode);
targetNode.userData.neighbors.add(sourceNode);
}
});
// Create Edges
// Use BufferGeometry for lines efficiency
const edgeLines = new THREE.Group();
state.edgesData.forEach(edge => {
const sourceNode = state.sceneNodes[edge.source];
const targetNode = state.sceneNodes[edge.target];
if (sourceNode && targetNode) {
const positions = new Float32Array([
sourceNode.position.x, sourceNode.position.y, sourceNode.position.z,
targetNode.position.x, targetNode.position.y, targetNode.position.z
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
const line = new THREE.Line(geometry, lineMaterial.clone());
line.userData = {
source: sourceNode,
target: targetNode,
baseOpacity: 0.2
};
edgeLines.add(line);
state.sceneEdges.push(line);
}
});
scene.add(edgeLines);
// --- Physics Simulation (Simple Force Directed) ---
function updatePhysics() {
if (!state.isPhysicsEnabled) return;
const damping = 0.85;
const repulsion = 0.8;
const attraction = 0.05;
const centerGravity = 0.005;
// 1. Repulsion (Coulomb)
for (let i = 0; i < state.sceneNodes.length; i++) {
const nodeA = state.sceneNodes[i];
for (let j = i + 1; j < state.sceneNodes.length; j++) {
const nodeB = state.sceneNodes[j];
const diff = new THREE.Vector3().subVectors(nodeA.position, nodeB.position);
const distSq = diff.lengthSq();
if (distSq === 0) diff.set(Math.random(), Math.random(), Math.random());
const dist = Math.sqrt(distSq);
const force = repulsion / (distSq + 0.01);
diff.normalize().multiplyScalar(force);
if (state.highlightedNode === nodeA || state.highlightedNode === nodeB) {
diff.multiplyScalar(0.1); // Reduce repulsion during interaction
}
nodeB.userData.velocity.add(diff);
nodeA.userData.velocity.sub(diff);
}
}
// 2. Attraction (Springs)
state.sceneEdges.forEach(line => {
const nodeA = line.userData.source;
const nodeB = line.userData.target;
const diff = new THREE.Vector3().subVectors(nodeB.position, nodeA.position);
const dist = diff.length();
const stretch = dist - 4; // Rest length approx 4
const force = diff.normalize().multiplyScalar(stretch * attraction);
if (state.highlightedNode === nodeA || state.highlightedNode === nodeB) {
return; // Keep edges tight? maybe weaker
}
nodeB.userData.velocity.add(force);
nodeA.userData.velocity.sub(force);
});
// 3. Center Gravity
state.sceneNodes.forEach(node => {
const toCenter = new THREE.Vector3(0,0,0).sub(node.position).multiplyScalar(centerGravity);
node.userData.velocity.add(toCenter);
// Update position
node.position.add(node.userData.velocity);
node.userData.velocity.multiplyScalar(damping);
});
}
// --- Interaction Logic ---
function onMouseMove(event) {
state.mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
state.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
// Tooltip follows mouse
if (state.hoveredNode && tooltip.classList.contains('opacity-100')) {
const x = event.clientX;
const y = event.clientY - 20;
tooltip.style.transform = `translate(${x}px, ${y}px) translateX(-50%) translateY(-100%)`; // Keep anchor top-center
// Actually CSS handles transform mostly, but we need position
tooltip.style.left = `${x}px`;
tooltip.style.top = `${y}px`;
}
}
function checkIntersection() {
state.raycaster.setFromCamera(state.mouse, camera);
const intersects = state.raycaster.intersectObjects(state.sceneNodes);
if (intersects.length > 0) {
const object = intersects[0].object;
if (state.hoveredNode !== object) {
// Reset previous hover
resetHighlights();
state.hoveredNode = object;
highlightImpact(object);
// Show Tooltip
showTooltip(object);
}
} else {
if (state.hoveredNode) {
resetHighlights();
state.hoveredNode = null;
hideTooltip();
}
}
}
function highlightImpact(node) {
const neighbors = node.userData.neighbors;
const connectedEdges = state.sceneEdges.filter(e => e.userData.source === node || e.userData.target === node);
// Highlight Node
node.scale.setScalar(1.5);
node.material.emissiveIntensity = 2.0;
// Highlight Neighbors
state.sceneNodes.forEach(n => {
if (n === node) return;
if (neighbors.has(n)) {
n.visible = true;
n.material.opacity = 1;
n.scale.setScalar(1.2);
} else {
if (state.riskHighlightEnabled && state.highlightedNode === node) {
n.visible = false; // Hide unrelated nodes for "Impact Surfacing" clarity
} else {
n.material.opacity = 0.1;
n.scale.setScalar(0.8);
}
}
});
// Highlight Edges
state.sceneEdges.forEach(line => {
const isConnected = line.userData.source === node || line.userData.target === node;
if (isConnected) {
line.material.opacity = 1;
line.material.color.setHex(CONFIG.colors.highlightEdge);
line.material.linewidth = 2; // Note: Webgl limitation, usually 1px
} else {
line.material.opacity = 0.05;
line.material.color.setHex(CONFIG.colors.edge);
}
});
}
function resetHighlights() {
state.sceneNodes.forEach(node => {
node.scale.copy(node.userData.originalScale);
node.material.emissiveIntensity = 0.5;
node.visible = true;
node.material.opacity = 1;
// Fade out
// node.material.opacity = 0.6;
});
state.sceneEdges.forEach(line => {
line.material.opacity = line.userData.baseOpacity;
line.material.color.setHex(CONFIG.colors.edge);
});
}
function showTooltip(node) {
const data = node.userData.data;
ttName.innerText = data.name;
ttName.className = `font-bold text-white text-lg font-serif ${getFreshnessClass(data.freshness)}`;
ttType.innerText = data.type.toUpperCase();
ttVersion.innerText = data.version;
ttDate.innerText = data.lastUpdated;
const riskEl = document.getElementById('tt-risk');
if (data.freshness === 'stale') {
riskEl.classList.remove('hidden');
} else {
riskEl.classList.add('hidden');
}
tooltip.style.display = 'block';
// Force reflow
void tooltip.offsetWidth;
tooltip.classList.remove('opacity-0', 'pointer-events-none');
tooltip.classList.add('opacity-100');
}
function hideTooltip() {
tooltip.classList.remove('opacity-100');
tooltip.classList.add('opacity-0', 'pointer-events-none');
setTimeout(() => {
if (tooltip.classList.contains('opacity-0')) {
tooltip.style.display = 'none';
}
}, 200);
}
function getFreshnessClass(freshness) {
if (freshness === 'fresh') return 'text-emerald-400';
if (freshness === 'warning') return 'text-amber-400';
return 'text-rose-400';
}
// --- Event Listeners ---
window.addEventListener('resize', onWindowResize);
window.addEventListener('mousemove', onMouseMove);
// window.addEventListener('click', onMouseClick); // Optional
document.getElementById('risk-toggle').addEventListener('change', (e) => {
state.riskHighlightEnabled = e.target.checked;
if (state.hoveredNode) resetHighlights(); // Re-evaluate if we should dim others
});
document.getElementById('physics-toggle').addEventListener('change', (e) => {
state.isPhysicsEnabled = e.target.checked;
// Disable controls if physics are running to prevent cam fighting? No, separate.
});
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
composer.setSize(window.innerWidth, window.innerHeight);
}
// --- Animation Loop ---
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = clock.getDelta();
state.time += delta;
controls.update();
updatePhysics();
checkIntersection();
// Subtle rotation of whole group if selected? No, user controls via orbit.
// Idle rotation for aesthetics
if (!state.hoveredNode && !state.selectionNode) {
scene.rotation.y += 0.001;
} else {
scene.rotation.y += 0.0002;
}
// Pulse effect for stale nodes
state.sceneNodes.forEach(node => {
const data = node.userData.data;
if (data.freshness === 'stale') {
const pulse = Math.sin(state.time * 3) * 0.5 + 1;
node.material.opacity = 0.6 + (pulse * 0.2);
}
});
composer.render();
}
// --- Entry Animation ---
// Using simple custom animation loop before "real" loop to avoid Tween lib dependency complexity
// But we can just play the DOM loader removal.
window.addEventListener('load', () => {
setTimeout(() => {
loader.style.opacity = '0';
setTimeout(() => {
loader.style.display = 'none';
animate(); // Start loop
}, 1000);
}, 1500); // Fake loading time for effect
// Initial camera position animation
camera.position.set(0, 100, 150);
camera.lookAt(0,0,0);
// Animate camera to default
const startPos = camera.position.clone();
const endPos = new THREE.Vector3(0, 20, 60);
let progress = 0;
function introAnim() {
progress += 0.02;
if (progress <= 1) {
camera.position.lerpVectors(startPos, endPos, progress);
requestAnimationFrame(introAnim);
}
}
introAnim();
});
</script>
</body>
</html>