diff --git a/src/app.css b/src/app.css index e369c72..c036bb1 100644 --- a/src/app.css +++ b/src/app.css @@ -332,6 +332,9 @@ border-primary-200 has-[:hover]:border-primary-700; @apply dark:bg-primary-1000 dark:border-primary-800 dark:has-[:hover]:bg-primary-950 dark:has-[:hover]:border-primary-500; + max-width: 300px; + min-width: 200px; + overflow: hidden; } /* Tooltip */ diff --git a/src/lib/components/EventInput.svelte b/src/lib/components/EventInput.svelte index e8e61e5..59cc3bd 100644 --- a/src/lib/components/EventInput.svelte +++ b/src/lib/components/EventInput.svelte @@ -493,10 +493,10 @@
-

Publish Nostr Event

+

Publish Nostr Event

- + {#if !isValidKind(kind)} -
+
Kind must be an integer between 0 and 65535 (NIP-01).
{/if} @@ -519,7 +519,7 @@ {/if}
- + {#if extractedMetadata.length > 0} @@ -587,7 +587,7 @@
- +
- +
- + {#if dTagError} -
{dTagError}
+
{dTagError}
{/if}
@@ -631,18 +631,18 @@ >
{#if loading} - Publishing... + Publishing... {/if} {#if error} -
{error}
+
{error}
{/if} {#if success} -
{success}
-
+
{success}
+
Relays: {publishedRelays.join(", ")}
{#if lastPublishedEventId} -
+
Event ID: {lastPublishedEventId} - Show Tag Anchors + Show Tag Anchors
{#if showTagAnchors} @@ -317,7 +317,7 @@ bind:group={tagSortMode} class="w-3 h-3" /> - Count + Count
@@ -343,7 +343,7 @@ title={isDisabled ? `Click to show ${tag.label}` : `Click to hide ${tag.label}`} aria-pressed={!isDisabled} > - + {tag.label} ({tag.count})
@@ -395,12 +395,12 @@ > {showPersonNodes ? 'ON' : 'OFF'} - Show Person Nodes + Show Person Nodes
{#if showPersonNodes}
-
@@ -466,7 +466,7 @@ style="background-color: {person.isFromFollowList ? getEventKindColor(3) : '#10B981'}; opacity: {isDisabled ? 0.3 : 1};" >
- + {person.displayName || person.pubkey} diff --git a/src/lib/navigator/EventNetwork/index.svelte b/src/lib/navigator/EventNetwork/index.svelte index 75fad46..5e6190e 100644 --- a/src/lib/navigator/EventNetwork/index.svelte +++ b/src/lib/navigator/EventNetwork/index.svelte @@ -208,7 +208,9 @@ svgGroup.attr("transform", event.transform); }); + // Initialize with identity transform svgElement.call(zoomBehavior); + svgElement.call(zoomBehavior.transform, d3.zoomIdentity); // Set up arrow marker for links const defs = svgElement.append("defs"); @@ -505,9 +507,10 @@ // Center the nodes when the simulation is done newSimulation.on("end", () => { - if (!starVisualization) { + // Add a small delay to ensure the simulation has fully settled + setTimeout(() => { centerGraph(); - } + }, 100); }); // Create drag handler @@ -1183,17 +1186,59 @@ */ function centerGraph() { if (svg && svgGroup && zoomBehavior) { - const svgWidth = svg.clientWidth || width; - const svgHeight = svg.clientHeight || height; + debug("Centering graph", { width, height }); + + // Get all nodes to calculate bounds + const nodes = svgGroup.selectAll('.node').data(); + if (nodes.length === 0) { + debug("No nodes found for centering"); + return; + } + + // Calculate bounds of all nodes + let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity; + nodes.forEach((node: NetworkNode) => { + if (node.x != null && node.y != null) { + minX = Math.min(minX, node.x); + maxX = Math.max(maxX, node.x); + minY = Math.min(minY, node.y); + maxY = Math.max(maxY, node.y); + } + }); + + // Calculate the center of the graph content + const graphCenterX = (minX + maxX) / 2; + const graphCenterY = (minY + maxY) / 2; + + // Calculate the viewBox center + const viewBoxCenterX = width / 2; + const viewBoxCenterY = height / 2; + + // Calculate the translation needed to center the graph + const translateX = viewBoxCenterX - graphCenterX; + const translateY = viewBoxCenterY - graphCenterY; + + debug("Centering graph", { + graphBounds: { minX, maxX, minY, maxY }, + graphCenter: { graphCenterX, graphCenterY }, + viewBoxCenter: { viewBoxCenterX, viewBoxCenterY }, + translation: { translateX, translateY } + }); - // Reset zoom and center + // Apply the centering transform d3.select(svg) .transition() .duration(750) .call( zoomBehavior.transform, - d3.zoomIdentity.translate(svgWidth / 2, svgHeight / 2).scale(0.8), + d3.zoomIdentity.translate(translateX, translateY).scale(0.8), ); + } else { + debug("Cannot center graph - missing required elements", { + hasSvg: !!svg, + hasSvgGroup: !!svgGroup, + hasZoomBehavior: !!zoomBehavior + }); } } @@ -1348,7 +1393,10 @@ outline size="lg" class="network-control-button btn-leather rounded-lg p-2" - onclick={centerGraph} + onclick={() => { + debug("Center button clicked"); + centerGraph(); + }} aria-label="Center graph" > -