Index of every page on this site: llms.txt
All skills
spences10 avatar

/svelte-layerchart

@5fe4989
Run it yourself

Svelte LayerChart patterns. Use for chart components with tooltip snippets, Chart context access, and all Svelte 5 snippet patterns for tooltips, gradients, highlights, and axes.

Use this Skill: https://skilld.dev/gh/spences10/svelte-skills-kit/svelte-layerchart

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesgraph-patterns.md

≈699 tokens on demand. Your agent reads this file only when SKILL.md points to it.

LayerChart Graph & Network Patterns

ForceGraph Basic

<script lang="ts">
	import {
		Chart,
		ForceSimulation,
		Group,
		Link,
		ForceGraph,
		Svg,
		Text,
	} from 'layerchart'
	import {
		forceCenter,
		forceCollide,
		forceLink,
		forceManyBody,
	} from 'd3-force'

	type Node = { id: string; label: string; group?: string }
	type LinkType = { source: string; target: string }

	let { nodes, links }: { nodes: Node[]; links: LinkType[] } = $props()
</script>

<div class="h-96">
	<Chart>
		<Svg>
			<ForceGraph {nodes} {links}>
				<ForceSimulation
					forces={{
						charge: forceManyBody().strength(-100),
						center: forceCenter(),
						collide: forceCollide(20),
						link: forceLink().id((d) => d.id),
					}}
				>
					{#snippet children({ simulation })}
						{#each simulation.links as link}
							<Link
								data={link}
								class="stroke-surface-content/30"
							/>
						{/each}
						{#each simulation.nodes as node}
							<Group x={node.x} y={node.y}>
								<circle r="8" class="fill-primary" />
								<Text
									value={node.label}
									dy={-12}
									textAnchor="middle"
									class="text-xs"
								/>
							</Group>
						{/each}
					{/snippet}
				</ForceSimulation>
			</ForceGraph>
		</Svg>
	</Chart>
</div>

ForceGraph with Transform (Zoom/Pan)

<Chart>
	<Canvas>
		<Transform mode="canvas" initialTransform={{ scale: 0.8 }}>
			<ForceGraph {nodes} {links}>
				<ForceSimulation>
					<!-- ... -->
				</ForceSimulation>
			</ForceGraph>
		</Transform>
	</Canvas>
</Chart>

CRITICAL: Use mode="canvas" for zoom/pan controls in Canvas context.

Force Configuration

import {
  forceCenter,
  forceCollide,
  forceLink,
  forceManyBody,
  forceX,
  forceY,
} from "d3-force";

const forces = {
  // Repulsion between nodes
  charge: forceManyBody().strength(-200),

  // Center gravity
  center: forceCenter(),

  // Prevent overlap
  collide: forceCollide(30),

  // Link distance
  link: forceLink()
    .id((d) => d.id)
    .distance(50),

  // Pull toward x/y positions
  x: forceX().strength(0.1),
  y: forceY().strength(0.1),
};

Node Styling by Group

{#each simulation.nodes as node}
	<Group x={node.x} y={node.y}>
		<circle
			r={node.size ?? 8}
			class={node.group === 'primary'
				? 'fill-primary'
				: 'fill-secondary'}
		/>
	</Group>
{/each}

Link Styling

{#each simulation.links as link}
	<Link
		data={link}
		class="stroke-surface-content/20"
		strokeWidth={link.weight ?? 1}
	/>
{/each}

Common Imports

import {
  Canvas,
  Chart,
  ForceGraph,
  ForceSimulation,
  Group,
  Link,
  Svg,
  Text,
  Transform,
} from "layerchart";
import { forceCenter, forceCollide, forceLink, forceManyBody } from "d3-force";

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts25d3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides safe documentation and code patterns for using the LayerChart Svelte library, including component snippets for Svelte 5.

  • Socket25d

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 5fe4989. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago

README badge

README badge for spences10/svelte-skills-kit/svelte-layerchart