| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Lines Dataset Visualizer</title> |
| <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=Sora:wght@300;400;500;600;700&display=swap" rel="stylesheet"> |
| <style> |
| :root { |
| --bg-dark: #0c1117; |
| --bg-card: #151d27; |
| --bg-card-hover: #1c2936; |
| --border-color: #2a3847; |
| --text-primary: #e4ebf5; |
| --text-secondary: #6b7d93; |
| --accent-teal: #14b8a6; |
| --accent-amber: #f59e0b; |
| --accent-rose: #f43f5e; |
| --accent-violet: #8b5cf6; |
| --accent-sky: #0ea5e9; |
| --solid-line-color: #14b8a6; |
| --dashed-line-color: #f59e0b; |
| } |
| |
| * { |
| margin: 0; |
| padding: 0; |
| box-sizing: border-box; |
| } |
| |
| body { |
| font-family: 'Sora', sans-serif; |
| background: var(--bg-dark); |
| color: var(--text-primary); |
| min-height: 100vh; |
| background-image: |
| linear-gradient(135deg, rgba(20, 184, 166, 0.03) 0%, transparent 50%), |
| linear-gradient(225deg, rgba(245, 158, 11, 0.03) 0%, transparent 50%), |
| radial-gradient(circle at 50% 50%, rgba(20, 184, 166, 0.02) 0%, transparent 70%); |
| } |
| |
| .header { |
| padding: 0.875rem 1.5rem; |
| border-bottom: 1px solid var(--border-color); |
| display: flex; |
| align-items: center; |
| justify-content: space-between; |
| background: rgba(21, 29, 39, 0.95); |
| backdrop-filter: blur(12px); |
| position: sticky; |
| top: 0; |
| z-index: 100; |
| } |
| |
| .logo { |
| display: flex; |
| align-items: center; |
| gap: 0.75rem; |
| } |
| |
| .logo-icon { |
| width: 38px; |
| height: 38px; |
| background: linear-gradient(135deg, var(--accent-teal), #0d9488); |
| border-radius: 10px; |
| display: flex; |
| align-items: center; |
| justify-content: center; |
| font-size: 1.1rem; |
| box-shadow: 0 4px 15px rgba(20, 184, 166, 0.25); |
| } |
| |
| .logo h1 { |
| font-size: 1.25rem; |
| font-weight: 600; |
| background: linear-gradient(135deg, var(--accent-teal), #5eead4); |
| -webkit-background-clip: text; |
| -webkit-text-fill-color: transparent; |
| } |
| |
| .split-tabs { |
| display: flex; |
| gap: 0.25rem; |
| background: var(--bg-dark); |
| padding: 0.25rem; |
| border-radius: 10px; |
| border: 1px solid var(--border-color); |
| } |
| |
| .split-tab { |
| background: transparent; |
| border: none; |
| color: var(--text-secondary); |
| padding: 0.5rem 1rem; |
| border-radius: 8px; |
| cursor: pointer; |
| font-family: inherit; |
| font-size: 0.8rem; |
| font-weight: 500; |
| transition: all 0.2s; |
| display: flex; |
| align-items: center; |
| gap: 0.5rem; |
| } |
| |
| .split-tab:hover { |
| color: var(--text-primary); |
| background: var(--bg-card-hover); |
| } |
| |
| .split-tab.active { |
| background: var(--accent-teal); |
| color: white; |
| } |
| |
| .split-tab.active.validation { |
| background: var(--accent-sky); |
| } |
| |
| .split-tab.active.test { |
| background: var(--accent-rose); |
| } |
| |
| .split-count { |
| font-family: 'IBM Plex Mono', monospace; |
| font-size: 0.7rem; |
| opacity: 0.8; |
| } |
| |
| .header-controls { |
| display: flex; |
| align-items: center; |
| gap: 2rem; |
| } |
| |
| .sample-nav { |
| display: flex; |
| align-items: center; |
| gap: 0.75rem; |
| } |
| |
| .nav-btn { |
| background: var(--bg-card); |
| border: 1px solid var(--border-color); |
| color: var(--text-primary); |
| padding: 0.5rem 1rem; |
| border-radius: 8px; |
| cursor: pointer; |
| font-family: inherit; |
| font-size: 0.8rem; |
| font-weight: 500; |
| transition: all 0.2s; |
| } |
| |
| .nav-btn:hover:not(:disabled) { |
| background: var(--bg-card-hover); |
| border-color: var(--accent-teal); |
| } |
| |
| .nav-btn:disabled { |
| opacity: 0.35; |
| cursor: not-allowed; |
| } |
| |
| .sample-input-group { |
| display: flex; |
| align-items: center; |
| gap: 0.5rem; |
| } |
| |
| .sample-input { |
| width: 80px; |
| background: var(--bg-card); |
| border: 1px solid var(--border-color); |
| color: var(--text-primary); |
| padding: 0.5rem 0.75rem; |
| border-radius: 6px; |
| font-family: 'IBM Plex Mono', monospace; |
| font-size: 0.85rem; |
| text-align: center; |
| } |
| |
| .sample-input:focus { |
| outline: none; |
| border-color: var(--accent-teal); |
| } |
| |
| .sample-total { |
| color: var(--text-secondary); |
| font-size: 0.85rem; |
| } |
| |
| .stats-bar { |
| display: flex; |
| gap: 1.5rem; |
| align-items: center; |
| } |
| |
| .stat-item { |
| display: flex; |
| align-items: center; |
| gap: 0.4rem; |
| font-size: 0.8rem; |
| } |
| |
| .stat-value { |
| font-family: 'IBM Plex Mono', monospace; |
| font-weight: 600; |
| } |
| |
| .stat-value.teal { color: var(--accent-teal); } |
| .stat-value.amber { color: var(--accent-amber); } |
| .stat-value.rose { color: var(--accent-rose); } |
| |
| .stat-label { |
| color: var(--text-secondary); |
| } |
| |
| .main-container { |
| display: grid; |
| grid-template-columns: 320px 1fr; |
| height: calc(100vh - 62px); |
| } |
| |
| .sidebar { |
| background: var(--bg-card); |
| border-right: 1px solid var(--border-color); |
| overflow-y: auto; |
| padding: 1rem; |
| } |
| |
| .sidebar-section { |
| margin-bottom: 1.25rem; |
| } |
| |
| .section-title { |
| font-size: 0.65rem; |
| text-transform: uppercase; |
| letter-spacing: 0.12em; |
| color: var(--text-secondary); |
| margin-bottom: 0.6rem; |
| font-weight: 600; |
| } |
| |
| .sample-info-card { |
| background: var(--bg-dark); |
| border: 1px solid var(--border-color); |
| border-radius: 10px; |
| padding: 1rem; |
| margin-bottom: 1rem; |
| } |
| |
| .info-row { |
| display: flex; |
| justify-content: space-between; |
| padding: 0.35rem 0; |
| font-size: 0.8rem; |
| } |
| |
| .info-label { |
| color: var(--text-secondary); |
| } |
| |
| .info-value { |
| font-family: 'IBM Plex Mono', monospace; |
| color: var(--accent-teal); |
| font-weight: 500; |
| } |
| |
| .split-badge { |
| display: inline-block; |
| padding: 0.2rem 0.5rem; |
| border-radius: 4px; |
| font-size: 0.7rem; |
| font-weight: 600; |
| text-transform: uppercase; |
| } |
| |
| .split-badge.train { |
| background: rgba(20, 184, 166, 0.15); |
| color: var(--accent-teal); |
| } |
| |
| .split-badge.validation { |
| background: rgba(14, 165, 233, 0.15); |
| color: var(--accent-sky); |
| } |
| |
| .split-badge.test { |
| background: rgba(244, 63, 94, 0.15); |
| color: var(--accent-rose); |
| } |
| |
| .show-all-btn { |
| width: 100%; |
| background: linear-gradient(135deg, var(--accent-teal), #0d9488); |
| border: none; |
| color: white; |
| padding: 0.7rem 1rem; |
| border-radius: 8px; |
| cursor: pointer; |
| font-family: inherit; |
| font-size: 0.85rem; |
| font-weight: 600; |
| transition: all 0.2s; |
| margin-bottom: 0.75rem; |
| } |
| |
| .show-all-btn:hover { |
| transform: translateY(-1px); |
| box-shadow: 0 6px 20px rgba(20, 184, 166, 0.35); |
| } |
| |
| .show-all-btn.active { |
| background: linear-gradient(135deg, var(--accent-amber), #d97706); |
| box-shadow: 0 6px 20px rgba(245, 158, 11, 0.35); |
| } |
| |
| .controls-row { |
| display: flex; |
| gap: 0.5rem; |
| margin-bottom: 0.6rem; |
| } |
| |
| .controls-row .nav-btn { |
| flex: 1; |
| text-align: center; |
| } |
| |
| .line-index { |
| text-align: center; |
| font-family: 'IBM Plex Mono', monospace; |
| font-size: 0.8rem; |
| color: var(--text-secondary); |
| margin-bottom: 0.75rem; |
| } |
| |
| .line-list { |
| display: flex; |
| flex-direction: column; |
| gap: 0.35rem; |
| max-height: 40vh; |
| overflow-y: auto; |
| } |
| |
| .line-entry { |
| background: var(--bg-dark); |
| border: 1px solid var(--border-color); |
| border-radius: 6px; |
| padding: 0.55rem 0.7rem; |
| cursor: pointer; |
| transition: all 0.2s; |
| display: flex; |
| justify-content: space-between; |
| align-items: center; |
| } |
| |
| .line-entry:hover { |
| background: var(--bg-card-hover); |
| border-color: var(--accent-teal); |
| } |
| |
| .line-entry.active { |
| border-color: var(--accent-teal); |
| background: rgba(20, 184, 166, 0.1); |
| } |
| |
| .line-entry.solid .line-type-badge { |
| background: rgba(20, 184, 166, 0.15); |
| color: var(--accent-teal); |
| } |
| |
| .line-entry.dashed .line-type-badge { |
| background: rgba(245, 158, 11, 0.15); |
| color: var(--accent-amber); |
| } |
| |
| .line-name { |
| font-family: 'IBM Plex Mono', monospace; |
| font-size: 0.75rem; |
| color: var(--text-primary); |
| } |
| |
| .line-meta { |
| display: flex; |
| align-items: center; |
| gap: 0.5rem; |
| } |
| |
| .line-type-badge { |
| font-size: 0.6rem; |
| padding: 0.15rem 0.4rem; |
| border-radius: 4px; |
| text-transform: uppercase; |
| font-weight: 600; |
| letter-spacing: 0.05em; |
| } |
| |
| .line-pipeline { |
| font-size: 0.65rem; |
| color: var(--text-secondary); |
| max-width: 100px; |
| overflow: hidden; |
| text-overflow: ellipsis; |
| white-space: nowrap; |
| } |
| |
| .canvas-container { |
| position: relative; |
| overflow: auto; |
| background: #080b0f; |
| display: flex; |
| align-items: center; |
| justify-content: center; |
| background-image: |
| radial-gradient(circle at center, rgba(20, 184, 166, 0.02) 0%, transparent 50%); |
| } |
| |
| .canvas-wrapper { |
| position: relative; |
| display: inline-block; |
| box-shadow: 0 0 80px rgba(0, 0, 0, 0.5); |
| border-radius: 4px; |
| overflow: hidden; |
| } |
| |
| #mainImage { |
| display: block; |
| background: #fff; |
| } |
| |
| #overlayCanvas { |
| position: absolute; |
| top: 0; |
| left: 0; |
| pointer-events: none; |
| } |
| |
| .loading { |
| display: flex; |
| flex-direction: column; |
| align-items: center; |
| justify-content: center; |
| gap: 1rem; |
| padding: 2rem; |
| color: var(--text-secondary); |
| } |
| |
| .spinner { |
| width: 28px; |
| height: 28px; |
| border: 3px solid var(--border-color); |
| border-top-color: var(--accent-teal); |
| border-radius: 50%; |
| animation: spin 0.8s linear infinite; |
| } |
| |
| @keyframes spin { |
| to { transform: rotate(360deg); } |
| } |
| |
| .zoom-controls { |
| position: absolute; |
| bottom: 1rem; |
| right: 1rem; |
| display: flex; |
| gap: 0.4rem; |
| z-index: 10; |
| } |
| |
| .zoom-btn { |
| width: 34px; |
| height: 34px; |
| background: var(--bg-card); |
| border: 1px solid var(--border-color); |
| color: var(--text-primary); |
| border-radius: 8px; |
| cursor: pointer; |
| font-size: 1.1rem; |
| display: flex; |
| align-items: center; |
| justify-content: center; |
| transition: all 0.2s; |
| } |
| |
| .zoom-btn:hover { |
| background: var(--bg-card-hover); |
| border-color: var(--accent-teal); |
| } |
| |
| .legend { |
| position: absolute; |
| bottom: 1rem; |
| left: 1rem; |
| display: flex; |
| gap: 1rem; |
| background: rgba(21, 29, 39, 0.9); |
| padding: 0.5rem 1rem; |
| border-radius: 8px; |
| border: 1px solid var(--border-color); |
| backdrop-filter: blur(8px); |
| z-index: 10; |
| } |
| |
| .legend-item { |
| display: flex; |
| align-items: center; |
| gap: 0.4rem; |
| font-size: 0.75rem; |
| } |
| |
| .legend-line { |
| width: 24px; |
| height: 3px; |
| border-radius: 2px; |
| } |
| |
| .legend-line.solid { |
| background: var(--solid-line-color); |
| } |
| |
| .legend-line.dashed { |
| background: repeating-linear-gradient( |
| 90deg, |
| var(--dashed-line-color) 0px, |
| var(--dashed-line-color) 4px, |
| transparent 4px, |
| transparent 8px |
| ); |
| } |
| |
| .keyboard-hints { |
| position: fixed; |
| bottom: 1rem; |
| left: 50%; |
| transform: translateX(-50%); |
| display: flex; |
| gap: 1.25rem; |
| background: rgba(21, 29, 39, 0.95); |
| padding: 0.5rem 1.25rem; |
| border-radius: 10px; |
| border: 1px solid var(--border-color); |
| font-size: 0.7rem; |
| color: var(--text-secondary); |
| backdrop-filter: blur(10px); |
| } |
| |
| .kbd { |
| background: var(--bg-dark); |
| padding: 0.15rem 0.45rem; |
| border-radius: 4px; |
| font-family: 'IBM Plex Mono', monospace; |
| color: var(--text-primary); |
| font-size: 0.65rem; |
| } |
| |
| .no-data { |
| text-align: center; |
| padding: 2rem; |
| color: var(--text-secondary); |
| font-size: 0.85rem; |
| } |
| |
| .pipelines-section { |
| margin-top: 1rem; |
| } |
| |
| .pipeline-tag { |
| display: inline-block; |
| background: rgba(139, 92, 246, 0.15); |
| color: var(--accent-violet); |
| padding: 0.25rem 0.5rem; |
| border-radius: 4px; |
| font-size: 0.7rem; |
| font-family: 'IBM Plex Mono', monospace; |
| margin: 0.2rem; |
| } |
| |
| |
| ::-webkit-scrollbar { |
| width: 6px; |
| height: 6px; |
| } |
| |
| ::-webkit-scrollbar-track { |
| background: var(--bg-dark); |
| } |
| |
| ::-webkit-scrollbar-thumb { |
| background: var(--border-color); |
| border-radius: 3px; |
| } |
| |
| ::-webkit-scrollbar-thumb:hover { |
| background: var(--accent-teal); |
| } |
| </style> |
| </head> |
| <body> |
| <header class="header"> |
| <div class="logo"> |
| <div class="logo-icon">📊</div> |
| <h1>Lines Dataset</h1> |
| </div> |
| |
| <div class="split-tabs" id="splitTabs"> |
| |
| </div> |
| |
| <div class="header-controls"> |
| <div class="sample-nav"> |
| <button class="nav-btn" id="prevBtn" disabled>← Prev</button> |
| <div class="sample-input-group"> |
| <input type="number" id="sampleInput" class="sample-input" value="0" min="0"> |
| <span class="sample-total">/ <span id="totalSamples">0</span></span> |
| </div> |
| <button class="nav-btn" id="nextBtn">Next →</button> |
| </div> |
| |
| <div class="stats-bar"> |
| <div class="stat-item"> |
| <span class="stat-value teal" id="lineCount">0</span> |
| <span class="stat-label">lines</span> |
| </div> |
| <div class="stat-item"> |
| <span class="stat-value amber" id="sizeInfo">-</span> |
| <span class="stat-label">px</span> |
| </div> |
| </div> |
| </div> |
| </header> |
| |
| <div class="main-container"> |
| <aside class="sidebar"> |
| <div class="sidebar-section"> |
| <h3 class="section-title">Sample Info</h3> |
| <div class="sample-info-card"> |
| <div class="info-row"> |
| <span class="info-label">Split</span> |
| <span class="info-value"><span id="currentSplitBadge" class="split-badge train">train</span></span> |
| </div> |
| <div class="info-row"> |
| <span class="info-label">File</span> |
| <span class="info-value" id="fileName">-</span> |
| </div> |
| <div class="info-row"> |
| <span class="info-label">Source Image</span> |
| <span class="info-value" id="sourceIdx">-</span> |
| </div> |
| <div class="info-row"> |
| <span class="info-label">Crop Index</span> |
| <span class="info-value" id="cropIdx">-</span> |
| </div> |
| <div class="info-row"> |
| <span class="info-label">Dimensions</span> |
| <span class="info-value" id="dimensions">-</span> |
| </div> |
| </div> |
| </div> |
| |
| <div class="sidebar-section"> |
| <h3 class="section-title">Display Controls</h3> |
| <button class="show-all-btn" id="showAllBtn">Show All Lines</button> |
| <div class="controls-row"> |
| <button class="nav-btn" id="prevLineBtn">← Prev</button> |
| <button class="nav-btn" id="nextLineBtn">Next →</button> |
| </div> |
| <div class="line-index" id="lineIndex">-</div> |
| </div> |
| |
| <div class="sidebar-section"> |
| <h3 class="section-title">Lines</h3> |
| <div id="lineList" class="line-list"> |
| <div class="loading"> |
| <div class="spinner"></div> |
| <span>Loading...</span> |
| </div> |
| </div> |
| </div> |
| |
| <div class="sidebar-section pipelines-section" id="pipelinesSection" style="display: none;"> |
| <h3 class="section-title">Pipelines</h3> |
| <div id="pipelinesList"></div> |
| </div> |
| </aside> |
| |
| <main class="canvas-container"> |
| <div class="canvas-wrapper"> |
| <img id="mainImage" alt="Cropped P&ID Image"> |
| <canvas id="overlayCanvas"></canvas> |
| </div> |
| |
| <div class="legend"> |
| <div class="legend-item"> |
| <div class="legend-line solid"></div> |
| <span>Solid</span> |
| </div> |
| <div class="legend-item"> |
| <div class="legend-line dashed"></div> |
| <span>Dashed</span> |
| </div> |
| </div> |
| |
| <div class="zoom-controls"> |
| <button class="zoom-btn" id="zoomOutBtn">−</button> |
| <button class="zoom-btn" id="zoomResetBtn">⟲</button> |
| <button class="zoom-btn" id="zoomInBtn">+</button> |
| </div> |
| </main> |
| </div> |
| |
| <div class="keyboard-hints"> |
| <span><kbd class="kbd">←</kbd> <kbd class="kbd">→</kbd> Samples</span> |
| <span><kbd class="kbd">↑</kbd> <kbd class="kbd">↓</kbd> Lines</span> |
| <span><kbd class="kbd">A</kbd> Toggle All</span> |
| <span><kbd class="kbd">1-3</kbd> Switch Split</span> |
| </div> |
|
|
| <script> |
| |
| const SOLID_COLOR = '#14b8a6'; |
| const DASHED_COLOR = '#f59e0b'; |
| const LINE_WIDTH = 4; |
| const ENDPOINT_RADIUS = 6; |
| |
| |
| let splits = []; |
| let currentSplit = 'train'; |
| let totalSamples = 0; |
| let currentSampleIdx = 0; |
| let currentSample = null; |
| let lines = []; |
| let activeLineIdx = -1; |
| let showAll = false; |
| let zoom = 1; |
| |
| |
| const splitTabs = document.getElementById('splitTabs'); |
| const sampleInput = document.getElementById('sampleInput'); |
| const totalSamplesEl = document.getElementById('totalSamples'); |
| const prevBtn = document.getElementById('prevBtn'); |
| const nextBtn = document.getElementById('nextBtn'); |
| const prevLineBtn = document.getElementById('prevLineBtn'); |
| const nextLineBtn = document.getElementById('nextLineBtn'); |
| const showAllBtn = document.getElementById('showAllBtn'); |
| const lineList = document.getElementById('lineList'); |
| const mainImage = document.getElementById('mainImage'); |
| const overlayCanvas = document.getElementById('overlayCanvas'); |
| const ctx = overlayCanvas.getContext('2d'); |
| const lineCountEl = document.getElementById('lineCount'); |
| const sizeInfoEl = document.getElementById('sizeInfo'); |
| const lineIndexEl = document.getElementById('lineIndex'); |
| const fileNameEl = document.getElementById('fileName'); |
| const sourceIdxEl = document.getElementById('sourceIdx'); |
| const cropIdxEl = document.getElementById('cropIdx'); |
| const dimensionsEl = document.getElementById('dimensions'); |
| const currentSplitBadge = document.getElementById('currentSplitBadge'); |
| const pipelinesSection = document.getElementById('pipelinesSection'); |
| const pipelinesList = document.getElementById('pipelinesList'); |
| |
| |
| async function init() { |
| await loadSplits(); |
| setupEventListeners(); |
| if (splits.length > 0) { |
| setSplit(splits[0].name); |
| } |
| } |
| |
| async function loadSplits() { |
| const response = await fetch('/api/splits'); |
| const data = await response.json(); |
| splits = data.splits; |
| |
| |
| splitTabs.innerHTML = splits.map(split => ` |
| <button class="split-tab ${split.name}" data-split="${split.name}"> |
| ${split.name.charAt(0).toUpperCase() + split.name.slice(1)} |
| <span class="split-count">(${split.sample_count})</span> |
| </button> |
| `).join(''); |
| |
| |
| document.querySelectorAll('.split-tab').forEach(tab => { |
| tab.addEventListener('click', () => setSplit(tab.dataset.split)); |
| }); |
| } |
| |
| async function setSplit(splitName) { |
| currentSplit = splitName; |
| |
| |
| document.querySelectorAll('.split-tab').forEach(tab => { |
| tab.classList.toggle('active', tab.dataset.split === splitName); |
| }); |
| |
| |
| currentSplitBadge.textContent = splitName; |
| currentSplitBadge.className = `split-badge ${splitName}`; |
| |
| |
| const response = await fetch(`/api/${splitName}/stats`); |
| const stats = await response.json(); |
| totalSamples = stats.total_samples; |
| totalSamplesEl.textContent = totalSamples; |
| sampleInput.max = totalSamples - 1; |
| |
| |
| if (totalSamples > 0) { |
| loadSample(0); |
| } else { |
| lineList.innerHTML = '<div class="no-data">No samples in this split</div>'; |
| } |
| } |
| |
| async function loadSample(idx) { |
| if (idx < 0 || idx >= totalSamples) return; |
| |
| currentSampleIdx = idx; |
| sampleInput.value = idx; |
| |
| prevBtn.disabled = idx <= 0; |
| nextBtn.disabled = idx >= totalSamples - 1; |
| |
| |
| const response = await fetch(`/api/${currentSplit}/sample/${idx}`); |
| currentSample = await response.json(); |
| |
| |
| mainImage.src = `/images/${currentSplit}/${currentSample.file_name}`; |
| |
| await new Promise(resolve => { |
| mainImage.onload = resolve; |
| }); |
| |
| setupCanvas(); |
| |
| |
| lines = currentSample.lines || []; |
| lineCountEl.textContent = lines.length; |
| sizeInfoEl.textContent = `${currentSample.width}×${currentSample.height}`; |
| fileNameEl.textContent = currentSample.file_name; |
| sourceIdxEl.textContent = currentSample.source_image_idx; |
| cropIdxEl.textContent = currentSample.crop_idx; |
| dimensionsEl.textContent = `${currentSample.width} × ${currentSample.height}`; |
| |
| |
| const pipelines = currentSample.unique_pipelines || []; |
| if (pipelines.length > 0) { |
| pipelinesSection.style.display = 'block'; |
| pipelinesList.innerHTML = pipelines.map(p => |
| `<span class="pipeline-tag">${p}</span>` |
| ).join(''); |
| } else { |
| pipelinesSection.style.display = 'none'; |
| } |
| |
| renderLineList(); |
| |
| activeLineIdx = -1; |
| showAll = false; |
| showAllBtn.classList.remove('active'); |
| showAllBtn.textContent = 'Show All Lines'; |
| updateLineIndex(); |
| clearCanvas(); |
| } |
| |
| function setupCanvas() { |
| overlayCanvas.width = mainImage.naturalWidth; |
| overlayCanvas.height = mainImage.naturalHeight; |
| overlayCanvas.style.width = mainImage.width + 'px'; |
| overlayCanvas.style.height = mainImage.height + 'px'; |
| } |
| |
| function renderLineList() { |
| if (lines.length === 0) { |
| lineList.innerHTML = '<div class="no-data">No lines in this sample</div>'; |
| return; |
| } |
| |
| const html = lines.map((line, idx) => ` |
| <div class="line-entry ${line.type}" data-idx="${idx}"> |
| <span class="line-name">Line ${idx}</span> |
| <div class="line-meta"> |
| ${line.pipeline ? `<span class="line-pipeline" title="${line.pipeline}">${line.pipeline}</span>` : ''} |
| <span class="line-type-badge">${line.type}</span> |
| </div> |
| </div> |
| `).join(''); |
| |
| lineList.innerHTML = html; |
| |
| document.querySelectorAll('.line-entry').forEach(entry => { |
| entry.addEventListener('click', () => { |
| const idx = parseInt(entry.dataset.idx); |
| selectLine(idx); |
| }); |
| }); |
| } |
| |
| function selectLine(idx) { |
| if (idx < 0 || idx >= lines.length) return; |
| |
| showAll = false; |
| showAllBtn.classList.remove('active'); |
| showAllBtn.textContent = 'Show All Lines'; |
| |
| document.querySelectorAll('.line-entry').forEach(e => e.classList.remove('active')); |
| const entry = document.querySelector(`.line-entry[data-idx="${idx}"]`); |
| if (entry) { |
| entry.classList.add('active'); |
| entry.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); |
| } |
| |
| activeLineIdx = idx; |
| updateLineIndex(); |
| draw(); |
| } |
| |
| function updateLineIndex() { |
| if (activeLineIdx >= 0) { |
| lineIndexEl.textContent = `${activeLineIdx + 1} / ${lines.length}`; |
| } else if (showAll) { |
| lineIndexEl.textContent = `All ${lines.length} lines`; |
| } else { |
| lineIndexEl.textContent = '-'; |
| } |
| } |
| |
| function clearCanvas() { |
| ctx.clearRect(0, 0, overlayCanvas.width, overlayCanvas.height); |
| } |
| |
| function draw() { |
| clearCanvas(); |
| |
| if (showAll) { |
| lines.forEach(line => drawLine(line)); |
| } else if (activeLineIdx >= 0 && activeLineIdx < lines.length) { |
| drawLine(lines[activeLineIdx]); |
| } |
| } |
| |
| function drawLine(line) { |
| const [x1, y1, x2, y2] = line.segment; |
| const color = line.type === 'dashed' ? DASHED_COLOR : SOLID_COLOR; |
| |
| ctx.strokeStyle = color; |
| ctx.fillStyle = color; |
| ctx.lineWidth = LINE_WIDTH; |
| ctx.lineCap = 'round'; |
| |
| if (line.type === 'dashed') { |
| ctx.setLineDash([8, 6]); |
| } else { |
| ctx.setLineDash([]); |
| } |
| |
| |
| ctx.beginPath(); |
| ctx.moveTo(x1, y1); |
| ctx.lineTo(x2, y2); |
| ctx.stroke(); |
| |
| |
| ctx.setLineDash([]); |
| |
| |
| ctx.beginPath(); |
| ctx.arc(x1, y1, ENDPOINT_RADIUS, 0, Math.PI * 2); |
| ctx.fill(); |
| |
| ctx.beginPath(); |
| ctx.arc(x2, y2, ENDPOINT_RADIUS, 0, Math.PI * 2); |
| ctx.fill(); |
| } |
| |
| function toggleShowAll() { |
| showAll = !showAll; |
| if (showAll) { |
| showAllBtn.classList.add('active'); |
| showAllBtn.textContent = 'Hide All Lines'; |
| activeLineIdx = -1; |
| document.querySelectorAll('.line-entry').forEach(e => e.classList.remove('active')); |
| } else { |
| showAllBtn.classList.remove('active'); |
| showAllBtn.textContent = 'Show All Lines'; |
| } |
| updateLineIndex(); |
| draw(); |
| } |
| |
| function setupEventListeners() { |
| sampleInput.addEventListener('change', (e) => { |
| let idx = parseInt(e.target.value); |
| if (isNaN(idx)) idx = 0; |
| idx = Math.max(0, Math.min(totalSamples - 1, idx)); |
| loadSample(idx); |
| }); |
| |
| sampleInput.addEventListener('keydown', (e) => { |
| if (e.key === 'Enter') { |
| sampleInput.blur(); |
| } |
| }); |
| |
| prevBtn.addEventListener('click', () => { |
| if (currentSampleIdx > 0) loadSample(currentSampleIdx - 1); |
| }); |
| |
| nextBtn.addEventListener('click', () => { |
| if (currentSampleIdx < totalSamples - 1) loadSample(currentSampleIdx + 1); |
| }); |
| |
| prevLineBtn.addEventListener('click', () => { |
| if (activeLineIdx > 0) selectLine(activeLineIdx - 1); |
| else if (activeLineIdx === -1 && lines.length > 0) selectLine(lines.length - 1); |
| }); |
| |
| nextLineBtn.addEventListener('click', () => { |
| if (activeLineIdx < lines.length - 1) selectLine(activeLineIdx + 1); |
| else if (activeLineIdx === -1 && lines.length > 0) selectLine(0); |
| }); |
| |
| showAllBtn.addEventListener('click', toggleShowAll); |
| |
| |
| document.getElementById('zoomInBtn').addEventListener('click', () => { |
| zoom = Math.min(4, zoom + 0.25); |
| applyZoom(); |
| }); |
| |
| document.getElementById('zoomOutBtn').addEventListener('click', () => { |
| zoom = Math.max(0.25, zoom - 0.25); |
| applyZoom(); |
| }); |
| |
| document.getElementById('zoomResetBtn').addEventListener('click', () => { |
| zoom = 1; |
| applyZoom(); |
| }); |
| |
| |
| document.addEventListener('keydown', (e) => { |
| if (e.target.tagName === 'INPUT') return; |
| |
| switch (e.key) { |
| case 'ArrowLeft': |
| prevBtn.click(); |
| break; |
| case 'ArrowRight': |
| nextBtn.click(); |
| break; |
| case 'ArrowUp': |
| prevLineBtn.click(); |
| e.preventDefault(); |
| break; |
| case 'ArrowDown': |
| nextLineBtn.click(); |
| e.preventDefault(); |
| break; |
| case 'a': |
| case 'A': |
| toggleShowAll(); |
| break; |
| case '1': |
| if (splits.length >= 1) setSplit(splits[0].name); |
| break; |
| case '2': |
| if (splits.length >= 2) setSplit(splits[1].name); |
| break; |
| case '3': |
| if (splits.length >= 3) setSplit(splits[2].name); |
| break; |
| case '+': |
| case '=': |
| document.getElementById('zoomInBtn').click(); |
| break; |
| case '-': |
| document.getElementById('zoomOutBtn').click(); |
| break; |
| } |
| }); |
| |
| window.addEventListener('resize', () => { |
| setupCanvas(); |
| draw(); |
| }); |
| } |
| |
| function applyZoom() { |
| const wrapper = document.querySelector('.canvas-wrapper'); |
| wrapper.style.transform = `scale(${zoom})`; |
| wrapper.style.transformOrigin = 'center center'; |
| } |
| |
| init(); |
| </script> |
| </body> |
| </html> |
|
|