diff --git a/src/app.css b/src/app.css index 8a26f05..1953be8 100644 --- a/src/app.css +++ b/src/app.css @@ -157,3 +157,12 @@ @apply fill-[#d6c1a8]; } } +@layer components { + .leather-legend { + @apply flex-shrink-0 p-4 bg-primary-0 dark:bg-primary-1000 rounded-lg shadow + border border-gray-200 dark:border-gray-800; + } + .tooltip-leather { + @apply bg-primary-0 dark:bg-primary-1000 text-gray-800 dark:text-gray-300; + } +} diff --git a/src/lib/components/EventNetwork.svelte b/src/lib/components/EventNetwork.svelte index 920f977..f872068 100644 --- a/src/lib/components/EventNetwork.svelte +++ b/src/lib/components/EventNetwork.svelte @@ -8,13 +8,16 @@ let svg: SVGSVGElement; let isDarkMode = false; const nodeRadius = 20; - const dragRadius = 10; + const dragRadiusMultiplier = 2; const linkDistance = 5; const warmupClickEnergy = 0.9; // Energy to restart simulation on drag let container: HTMLDivElement; let width: number; let height: number; + let windowHeight: number; + + $: graphHeight = windowHeight ? Math.max(windowHeight * 0.2, 400) : 400; $: if (container) { width = container.clientWidth || 800; @@ -199,7 +202,7 @@ .join("marker") .attr("id", "arrowhead") .attr("viewBox", "0 -5 20 20") - .attr("refX", nodeRadius + 10) + .attr("refX", nodeRadius * dragRadiusMultiplier) .attr("refY", 0) .attr("markerWidth", 8) .attr("markerHeight", 8) @@ -309,8 +312,9 @@ .append("div") .attr( "class", - "fixed hidden bg-primary-0 dark:bg-primary-1000 " + - "text-gray-800 dark:text-gray-300 " + + "tooltip-leather fixed hidden p-4 rounded shadow-lg " + + "bg-primary-0 dark:bg-primary-800 " + + "border border-gray-200 dark:border-gray-800 " + "p-4 rounded shadow-lg border border-gray-200 dark:border-gray-800 " + "transition-colors duration-200", ) @@ -375,6 +379,14 @@ onMount(() => { isDarkMode = document.body.classList.contains("dark"); + // Add window resize listener + const handleResize = () => { + windowHeight = window.innerHeight; + }; + + // Initial resize + windowHeight = window.innerHeight; + window.addEventListener("resize", handleResize); // Watch for theme changes const themeObserver = new MutationObserver((mutations) => { @@ -383,7 +395,7 @@ const newIsDarkMode = document.body.classList.contains("dark"); if (newIsDarkMode !== isDarkMode) { isDarkMode = newIsDarkMode; - drawNetwork(); + // drawNetwork(); } } }); @@ -392,9 +404,12 @@ const resizeObserver = new ResizeObserver((entries) => { for (const entry of entries) { width = entry.contentRect.width; - height = entry.contentRect.height * 1 || width * 1.0; + height = graphHeight; } - // if (svg) drawNetwork(); + + // first remove all nodes and links + d3.select(svg).selectAll("*").remove(); + drawNetwork(); }); // Start observers @@ -417,47 +432,39 @@ } -# /lib/components/EventNetwork.svelte -