Browse Source

Fix a type error. Got rid of unused style and applied a style from the main css. Implemented Svelte props. Made sure entire element is visible on page, and added a hyperlink to the publication based upon eventID. Limit content to 200 chars.

master
Silberengel 11 months ago
parent
commit
ece42f3021
  1. 66
      src/lib/navigator/EventNetwork/NodeTooltip.svelte
  2. 12
      src/lib/navigator/EventNetwork/index.svelte

66
src/lib/navigator/EventNetwork/NodeTooltip.svelte

@ -1,10 +1,17 @@
<script lang="ts"> <script lang="ts">
import type { NetworkNode } from "./types"; import type { NetworkNode } from "./types";
import { onMount } from "svelte";
export let node: NetworkNode; let { node, selected = false, x, y } = $props<{
export let selected: boolean = false; node: NetworkNode;
export let x: number; selected?: boolean;
export let y: number; x: number;
y: number;
}>();
let tooltipElement: HTMLDivElement;
let tooltipX = $state(x + 10);
let tooltipY = $state(y - 10);
function getAuthorTag(node: NetworkNode): string { function getAuthorTag(node: NetworkNode): string {
if (node.event) { if (node.event) {
@ -25,31 +32,66 @@
} }
return "View Publication"; return "View Publication";
} }
function truncateContent(content: string, maxLength: number = 200): string {
if (content.length <= maxLength) return content;
return content.substring(0, maxLength) + "...";
}
// Ensure tooltip is fully visible on screen
onMount(() => {
if (tooltipElement) {
const rect = tooltipElement.getBoundingClientRect();
const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight;
// Check if tooltip goes off the right edge
if (rect.right > windowWidth) {
tooltipX = windowWidth - rect.width - 10;
}
// Check if tooltip goes off the bottom edge
if (rect.bottom > windowHeight) {
tooltipY = windowHeight - rect.height - 10;
}
// Check if tooltip goes off the left edge
if (rect.left < 0) {
tooltipX = 10;
}
// Check if tooltip goes off the top edge
if (rect.top < 0) {
tooltipY = 10;
}
}
});
</script> </script>
<div <div
bind:this={tooltipElement}
class="tooltip-leather fixed p-4 rounded shadow-lg bg-primary-0 dark:bg-primary-800 class="tooltip-leather fixed p-4 rounded shadow-lg bg-primary-0 dark:bg-primary-800
border border-gray-200 dark:border-gray-800 transition-colors duration-200" border border-gray-200 dark:border-gray-800 transition-colors duration-200"
style="left: {x + 10}px; top: {y - 10}px; z-index: 1000;" style="left: {tooltipX}px; top: {tooltipY}px; z-index: 1000;"
> >
<div class="space-y-2"> <div class="space-y-2">
<div class="font-bold text-base">{node.title}</div> <div class="font-bold text-base">
<a href="/publication?id={node.id}" class="text-gray-800 hover:text-primary-400 dark:text-gray-300 dark:hover:text-primary-500">
{node.title}
</a>
</div>
<div class="text-gray-600 dark:text-gray-400 text-sm"> <div class="text-gray-600 dark:text-gray-400 text-sm">
{node.type} ({node.isContainer ? "30040" : "30041"}) {node.type} ({node.isContainer ? "30040" : "30041"})
</div> </div>
<div class="text-gray-600 dark:text-gray-400 text-sm"> <div class="text-gray-600 dark:text-gray-400 text-sm">
Author: {getAuthorTag(node)} Author: {getAuthorTag(node)}
</div> </div>
<div class="text-gray-600 dark:text-gray-400 text-sm">
<a href="/publication?id={node.id}" class="text-blue-500 hover:underline">
{getDTag(node)}
</a>
</div>
{#if node.content} {#if node.content}
<div <div
class="mt-2 text-xs bg-gray-100 dark:bg-gray-800 p-2 rounded overflow-auto max-h-40" class="mt-2 text-xs bg-gray-100 dark:bg-gray-800 p-2 rounded overflow-auto max-h-40"
> >
{node.content} {truncateContent(node.content)}
</div> </div>
{/if} {/if}
{#if selected} {#if selected}

12
src/lib/navigator/EventNetwork/index.svelte

@ -8,6 +8,7 @@
import { createSimulation, setupDragHandlers, applyGlobalLogGravity, applyConnectedGravity } from "./utils/forceSimulation"; import { createSimulation, setupDragHandlers, applyGlobalLogGravity, applyConnectedGravity } from "./utils/forceSimulation";
import Legend from "./Legend.svelte"; import Legend from "./Legend.svelte";
import NodeTooltip from "./NodeTooltip.svelte"; import NodeTooltip from "./NodeTooltip.svelte";
import type { NetworkNode, NetworkLink } from "./types";
let { events = [] } = $props<{ events?: NDKEvent[] }>(); let { events = [] } = $props<{ events?: NDKEvent[] }>();
@ -90,14 +91,14 @@
function updateGraph() { function updateGraph() {
if (!svg || !events?.length || !svgGroup) return; if (!svg || !events?.length || !svgGroup) return;
const { nodes, links } = generateGraph(events, currentLevels); const { nodes, links } = generateGraph(events, Number(currentLevels));
if (!nodes.length) return; if (!nodes.length) return;
// Stop any existing simulation // Stop any existing simulation
if (simulation) simulation.stop(); if (simulation) simulation.stop();
// Create new simulation // Create new simulation
simulation = createSimulation(nodes, links, nodeRadius, linkDistance); simulation = createSimulation(nodes, links, Number(nodeRadius), Number(linkDistance));
const dragHandler = setupDragHandlers(simulation); const dragHandler = setupDragHandlers(simulation);
// Update links // Update links
@ -326,10 +327,3 @@
<Legend /> <Legend />
</div> </div>
<style>
.tooltip {
max-width: 300px;
word-wrap: break-word;
}
</style>
Loading…
Cancel
Save