Add landscape navigation and minimap

This commit is contained in:
2026-11-05 22:25:42 +00:00
parent 281c166834
commit 4a63aa7b0b
3 changed files with 14 additions and 2 deletions
+12 -2
View File
@@ -22,6 +22,10 @@ const eventLog = ref<string[]>([])
const packetProgress = ref(0)
const importError = ref('')
const fileInput = ref<HTMLInputElement | null>(null)
const minimapEl = ref<HTMLCanvasElement | null>(null)
const searchQuery = ref('')
const categoryFilter = ref('all')
const dataTypeFilter = ref('all')
const placingPreset = ref<SystemPreset | null>(null)
const selectedCapabilityIds = ref<string[]>([])
const presentationMode = ref(false)
@@ -118,6 +122,8 @@ function enableTransformation() { if (selectedConnection.value && !selectedConne
function recordsForSelectedSystem(kind: TransferKind) { if (!selectedSystem.value) return []; return transferHistory.value.filter((record) => kind === 'sent' ? record.senderId === selectedSystem.value?.id : record.destinationId === selectedSystem.value?.id) }
function systemName(id: string) { return landscape.value.systems.find((system) => system.id === id)?.name || id }
const latestSelectedRecord = computed(() => selectedSystem.value ? transferHistory.value.filter((record) => record.destinationId === selectedSystem.value?.id).slice(-1)[0] : undefined)
const matchesSystem = (system: SystemModel) => { const query = searchQuery.value.trim().toLowerCase(); const queryMatch = !query || `${system.name} ${system.description}`.toLowerCase().includes(query); const categoryMatch = categoryFilter.value === 'all' || system.category === categoryFilter.value; const dataMatch = dataTypeFilter.value === 'all' || landscape.value.connections.some((connection) => connection.dataType === dataTypeFilter.value && (connection.sourceId === system.id || connection.targetId === system.id)); return queryMatch && categoryMatch && dataMatch }
function isSystemDimmed(system: SystemModel) { if (!matchesSystem(system)) return true; if (!playing.value || !currentConnections.value.length) return false; return !currentConnections.value.some((connection) => connection.sourceId === system.id || connection.targetId === system.id) }
function animatePacket(duration: number) {
stopAnimation(); const started = performance.now()
const tick = (now: number) => { packetProgress.value = Math.min(1, (now - started) / duration); drawPackets(); if (packetProgress.value < 1) animationFrame = requestAnimationFrame(tick); else if (playing.value) setTimeout(finishStep, 180 / speed.value) }
@@ -142,7 +148,7 @@ function buildNode(system: SystemModel) {
if (system.capabilities.length) node.addWidget('button', 'Actions ▸', null, () => { node.showActions = !node.showActions; node.widgets[0].name = node.showActions ? 'Actions ▾' : 'Actions ▸'; graphCanvas?.draw(true, true) })
node.onDblClick = () => selectSystem(system.id)
node.onMouseDown = () => selectSystem(system.id)
node.onDrawForeground = function(ctx: CanvasRenderingContext2D) { ctx.fillStyle = '#8d9bb8'; ctx.font = '11px Inter, sans-serif'; ctx.fillText(system.category.toUpperCase(), 12, 76); if (node.showActions) { ctx.fillStyle = '#c9d3e8'; ctx.font = '10px Inter, sans-serif'; system.capabilities.forEach((capability: CapabilityModel, index: number) => ctx.fillText(`${capability.name}: ${capability.actions.map((item) => item.name).join(', ')}`, 12, 92 + index * 13)) } }
node.onDrawForeground = function(ctx: CanvasRenderingContext2D) { const dimmed = isSystemDimmed(system); ctx.save(); ctx.globalAlpha = dimmed ? .28 : 1; ctx.fillStyle = '#8d9bb8'; ctx.font = '11px Inter, sans-serif'; ctx.fillText(system.category.toUpperCase(), 12, 76); if (node.showActions) { ctx.fillStyle = '#c9d3e8'; ctx.font = '10px Inter, sans-serif'; system.capabilities.forEach((capability: CapabilityModel, index: number) => ctx.fillText(`${capability.name}: ${capability.actions.map((item) => item.name).join(', ')}`, 12, 92 + index * 13)) } ctx.restore() }
graph.add(node); return node
}
function connectionLabel(connection: ConnectionModel) { return connection.showCableLabel === false ? '' : `${connection.label} · ${connection.protocol || 'HTTPS'} · ${connection.dataType || 'JSON'} · ${connection.deliveryMethod || 'immediate'}` }
@@ -176,6 +182,8 @@ function drawPackets() {
const packetColor = failureState.value === 'none' ? '#f8c15c' : '#ef627d'; ctx.save(); ctx.fillStyle = packetColor; ctx.shadowColor = packetColor; ctx.shadowBlur = 18; ctx.beginPath(); ctx.arc(x, y, failureState.value === 'none' ? 7 : 9, 0, Math.PI * 2); ctx.fill(); ctx.restore()
}
}
function fitToScreen() { if (!graphCanvas || !canvasEl.value || !landscape.value.systems.length) return; const xs = landscape.value.systems.map((system) => system.position[0]); const ys = landscape.value.systems.map((system) => system.position[1]); const minX = Math.min(...xs); const minY = Math.min(...ys); const maxX = Math.max(...xs) + 220; const maxY = Math.max(...ys) + 130; graphCanvas.ds.scale = Math.min(.95, Math.max(.45, Math.min((canvasEl.value.width - 80) / (maxX - minX), (canvasEl.value.height - 80) / (maxY - minY)))); graphCanvas.ds.offset = [40 - minX * graphCanvas.ds.scale, 40 - minY * graphCanvas.ds.scale]; graphCanvas.draw(true, true); drawMinimap() }
function drawMinimap() { const canvas = minimapEl.value; if (!canvas) return; const ctx = canvas.getContext('2d'); if (!ctx) return; ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = '#0d121e'; ctx.fillRect(0, 0, canvas.width, canvas.height); const scale = Math.min(canvas.width / 1200, canvas.height / 670); for (const system of landscape.value.systems) { ctx.fillStyle = isSystemDimmed(system) ? '#283248' : system.color; ctx.fillRect(system.position[0] * scale, system.position[1] * scale, 34, 20) } }
function exportJson() {
const blob = new Blob([JSON.stringify(landscape.value, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'system-landscape.json'; link.click(); URL.revokeObjectURL(url)
}
@@ -184,7 +192,8 @@ function importJson(event: Event) {
const reader = new FileReader(); reader.onload = () => { try { landscape.value = validateLandscape(JSON.parse(String(reader.result))); selectedScenarioId.value = landscape.value.scenarios[0]?.id || ''; importError.value = ''; persist(); rebuildGraph() } catch (error) { importError.value = error instanceof Error ? error.message : 'Invalid landscape file.' } }; reader.readAsText(file); input.value = ''
}
watch(landscape, persist, { deep: true })
onMounted(() => { if (!canvasEl.value) return; graphCanvas = new LGraphCanvas(canvasEl.value, graph); graphCanvas.background_image = null; graphCanvas.render_shadows = false; graphCanvas.ds.scale = 0.85; graphCanvas.onDrawForeground = drawPackets; rebuildGraph() })
watch([searchQuery, categoryFilter, dataTypeFilter, playing, currentStep], () => { graphCanvas?.draw(true, true); drawMinimap() })
onMounted(() => { if (!canvasEl.value) return; graphCanvas = new LGraphCanvas(canvasEl.value, graph); graphCanvas.background_image = null; graphCanvas.render_shadows = false; graphCanvas.ds.scale = 0.85; graphCanvas.onDrawForeground = drawPackets; rebuildGraph(); drawMinimap() })
onUnmounted(stopAnimation)
</script>
@@ -216,5 +225,6 @@ onUnmounted(stopAnimation)
<section v-if="currentStep" class="guided-card panel"><span class="eyebrow">GUIDED STEP {{ stepIndex + 1 }}</span><strong>{{ currentStep.explanation }}</strong><p>{{ selectedScenario?.description }}</p></section><button class="presentation-toggle ghost" @click="presentationMode = !presentationMode">{{ presentationMode ? 'Exit presentation' : 'Presentation mode' }}</button>
<section v-if="selectedScenario" class="failure-config panel"><div><span class="eyebrow">STEP OUTCOMES</span><strong>Failure and recovery routing</strong><p class="muted">Choose how a simulated step behaves. Retry is limited to one automatic attempt per reset.</p></div><div v-for="(step, index) in selectedScenario.steps" :key="step.id" class="failure-row"><b>{{ index + 1 }}. {{ step.explanation }}</b><select v-model="step.outcome"><option value="success">Success</option><option value="rejected">Reject data</option><option value="timeout">Time out</option></select><select v-model="step.retryStepId"><option value="">No retry</option><option v-for="candidate in selectedScenario.steps" :key="candidate.id" :value="candidate.id" :disabled="candidate.id === step.id">Retry step {{ selectedScenario.steps.indexOf(candidate) + 1 }}</option></select><select v-model="step.recoveryStepId"><option value="">No recovery step</option><option v-for="candidate in selectedScenario.steps" :key="candidate.id" :value="candidate.id" :disabled="candidate.id === step.id">Recover at step {{ selectedScenario.steps.indexOf(candidate) + 1 }}</option></select></div></section>
<section v-if="selectedConnection" class="connection-properties panel"><span class="eyebrow">CONNECTION PROPERTIES</span><div class="property-grid"><label>Protocol<select v-model="selectedConnection.protocol"><option>HTTPS</option><option>HTTP</option><option>GraphQL</option><option>SMTP</option><option>Webhook</option><option>Message queue</option></select></label><label>Data type<select v-model="selectedConnection.dataType"><option>JSON</option><option>Form data</option><option>CSV</option><option>Event</option><option>Binary</option></select></label><label>Delivery<select v-model="selectedConnection.deliveryMethod"><option value="immediate">Immediate</option><option value="scheduled">Scheduled</option><option value="manual">Manual</option></select></label><label class="checkbox-label"><input v-model="selectedConnection.showCableLabel" type="checkbox" /> Show cable label</label></div></section>
<section class="navigation-panel panel"><div class="nav-fields"><label>Search systems<input v-model="searchQuery" placeholder="Name or description" /></label><label>Category<select v-model="categoryFilter"><option value="all">All categories</option><option value="application">Application</option><option value="service">Service</option><option value="data">Data</option><option value="external">External</option></select></label><label>Data type<select v-model="dataTypeFilter"><option value="all">All data types</option><option>JSON</option><option>Form data</option><option>CSV</option><option>Event</option><option>Binary</option></select></label><button class="ghost" @click="fitToScreen">Fit to screen</button></div><div class="minimap-wrap"><span class="eyebrow">MINIMAP</span><canvas ref="minimapEl" width="220" height="120"></canvas></div></section>
</main>
</template>