From c4c863095c473075623d0f37db0ed05017a6b9be Mon Sep 17 00:00:00 2001 From: Stephanie Gredell Date: Sun, 8 Jun 2025 00:51:30 -0700 Subject: [PATCH] initial protocol prototype - to be enhanced --- static/app.js | 10 +++++++--- static/connection.js | 13 ++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/static/app.js b/static/app.js index 13b80dc..fb45c5f 100644 --- a/static/app.js +++ b/static/app.js @@ -150,8 +150,11 @@ export class CanvasApp { } else { const defaultLabel = 'Read traffic'; const label = prompt('Enter connection label:', defaultLabel); - if (label) { - const conn = new Connection(this.connectionStart, nodeObj, label, this); + const protocol = prompt('Protocol (e.g. HTTP, gRPC, Kafka:', 'HTTP') + if (label && protocol) { + const conn = new Connection(this.connectionStart, nodeObj, label, protocol, this); + conn.protocol = protocol; + conn.protocolText.textContent = protocol; this.connections.push(conn); } this.connectionStart.group.classList.remove('selected'); @@ -234,7 +237,8 @@ export class CanvasApp { source: c.start.id, target: c.end.id, label: c.label || '', - direction: c.direction + direction: c.direction, + protocol: c.protocol || '' })); return { nodes, connections }; diff --git a/static/connection.js b/static/connection.js index de8c8ce..a398e43 100644 --- a/static/connection.js +++ b/static/connection.js @@ -1,11 +1,12 @@ import { generateNodeId, createSVGElement } from './utils.js'; export class Connection { - constructor(startNode, endNode, label, app) { + constructor(startNode, endNode, label, protocol, app) { this.start = startNode; this.end = endNode; this.app = app; this.label = label; + this.protocol = protocol; this.direction = "forward"; this.line = createSVGElement('line', { stroke: '#ccc', 'stroke-width': 2, 'marker-end': 'url(#arrowhead)' @@ -20,8 +21,15 @@ export class Connection { 'text-anchor': 'middle', 'font-size': 12, fill: '#ccc' }); this.text.textContent = label; + this.protocolText = createSVGElement('text', { + 'text-ancor': 'middle', + 'font-size': 10, + fill: '#888' + }); + this.protocolText.textContent = this.protocol || ''; app.canvas.appendChild(this.line); app.canvas.appendChild(this.text); + app.canvas.appendChild(this.protocolText) this.updatePosition(); this.selected = false; @@ -79,6 +87,9 @@ export class Connection { this.hitbox.setAttribute('cx', hbX); this.hitbox.setAttribute('cy', hbY); + + this.protocolText.setAttribute('x', midX); + this.protocolText.setAttribute('y', midY + 12); } toggleDirection() {