diff --git a/assets/js/app.ts b/assets/js/app.ts index ca2095bc..8af7b809 100644 --- a/assets/js/app.ts +++ b/assets/js/app.ts @@ -613,6 +613,41 @@ const NetworkMap = { } }, + _initControls(this: any) { + const ZOOM_STEP = 0.25 + + const zoomIn = document.getElementById('cy-zoom-in') + const zoomOut = document.getElementById('cy-zoom-out') + const fit = document.getElementById('cy-fit') + + if (zoomIn) { + zoomIn.addEventListener('click', () => { + if (!this.cy) return + this.cy.zoom({ + level: Math.min(this.cy.zoom() + ZOOM_STEP, this.cy.maxZoom()), + renderedPosition: { x: this.cy.width() / 2, y: this.cy.height() / 2 } + }) + }) + } + + if (zoomOut) { + zoomOut.addEventListener('click', () => { + if (!this.cy) return + this.cy.zoom({ + level: Math.max(this.cy.zoom() - ZOOM_STEP, this.cy.minZoom()), + renderedPosition: { x: this.cy.width() / 2, y: this.cy.height() / 2 } + }) + }) + } + + if (fit) { + fit.addEventListener('click', () => { + if (!this.cy) return + this.cy.fit(undefined, 50) + }) + } + }, + initializeCytoscape(this: any, topology: any) { const isDark = document.documentElement.getAttribute('data-theme') === 'dark' @@ -1011,6 +1046,8 @@ const NetworkMap = { 'label': data.label || '' }) }) + + this._initControls() }, updateTopology(this: any, topology: any) { diff --git a/lib/towerops_web/live/network_map_live.html.heex b/lib/towerops_web/live/network_map_live.html.heex index 1ed2e2c1..be3b3077 100644 --- a/lib/towerops_web/live/network_map_live.html.heex +++ b/lib/towerops_web/live/network_map_live.html.heex @@ -180,6 +180,34 @@ data-topology={Jason.encode!(@topology)} > + + +
+ + + +
<%= if @selected_node_detail do %>