@aiready/components 0.1.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useForceSimulation.ts","../../src/utils/cn.ts","../../src/charts/ForceDirectedGraph.tsx"],"names":["useRef","useState","useEffect","d32","zoom"],"mappings":";;;;;;;AAsKO,SAAS,kBAAA,CACd,YAAA,EACA,YAAA,EACA,OAAA,EAC0B;AAC1B,EAAA,MAAM;AAAA,IACJ,cAAA,GAAiB,IAAA;AAAA,IACjB,YAAA,GAAe,GAAA;AAAA,IACf,YAAA,GAAe,CAAA;AAAA,IACf,iBAAA,GAAoB,CAAA;AAAA,IACpB,eAAA,GAAkB,EAAA;AAAA,IAClB,cAAA,GAAiB,GAAA;AAAA,IACjB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA,GAAa,MAAA;AAAA,IACb,aAAA,GAAgB;AAAA,GAClB,GAAI,OAAA;AAEJ,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA2B,YAAY,CAAA;AACjE,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA2B,YAAY,CAAA;AACjE,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,KAAK,CAAA;AAChD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAS,CAAC,CAAA;AAEpC,EAAA,MAAM,aAAA,GAAgB,OAA6D,IAAI,CAAA;AAEvF,EAAA,SAAA,CAAU,MAAM;AAEd,IAAA,MAAM,SAAA,GAAY,aAAa,GAAA,CAAI,CAAC,UAAU,EAAE,GAAG,MAAK,CAAE,CAAA;AAC1D,IAAA,MAAM,SAAA,GAAY,aAAa,GAAA,CAAI,CAAC,UAAU,EAAE,GAAG,MAAK,CAAE,CAAA;AAG1D,IAAA,MAAM,UAAA,GACH,EAAA,CAAA,eAAA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AA,GAAS,MAAA;AAAA,sBACnD,WAAA,EAAa,aAAa,CAAA,GAAI,CAAA;AAAA,sBAC9B,OAAA,EAAS,SAAA,IAAa,UAAA,GAAa,CAAA,GAAI,GAAA;AAAA,sBACvC,SAAA,EAAU;AAAA;AAAA,mBACZ;AAAA,kBACC,cAAA,IAAkB,KAAK,KAAA,oBACtB,GAAA;AAAA,oBAAC,MAAA;AAAA,oBAAA;AAAA,sBACC,GAAG,QAAA,GAAW,EAAA;AAAA,sBACd,IAAA,EAAK,MAAA;AAAA,sBACL,QAAA,EAAS,IAAA;AAAA,sBACT,UAAA,EAAW,QAAA;AAAA,sBACX,gBAAA,EAAiB,QAAA;AAAA,sBACjB,aAAA,EAAc,MAAA;AAAA,sBACd,SAAA,EAAU,aAAA;AAAA,sBAET,QAAA,EAAA,IAAA,CAAK;AAAA;AAAA;AACR;AAAA,eAAA;AAAA,cA7BG,IAAA,CAAK;AAAA,aA+BZ;AAAA,UAEJ,CAAC;AAAA,SAAA,EACH;AAAA;AAAA;AAAA,GACF;AAEJ;AAEA,kBAAA,CAAmB,WAAA,GAAc,oBAAA","file":"ForceDirectedGraph.js","sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport * as d3 from 'd3';\n\nexport interface SimulationNode extends d3.SimulationNodeDatum {\n id: string;\n [key: string]: any;\n}\n\nexport interface SimulationLink extends d3.SimulationLinkDatum<SimulationNode> {\n source: string | SimulationNode;\n target: string | SimulationNode;\n [key: string]: any;\n}\n\nexport interface ForceSimulationOptions {\n /**\n * Strength of the charge force (repulsion between nodes)\n * @default -300\n */\n chargeStrength?: number;\n\n /**\n * Distance for links between nodes\n * @default 100\n */\n linkDistance?: number;\n\n /**\n * Strength of the link force\n * @default 1\n */\n linkStrength?: number;\n\n /**\n * Strength of collision detection\n * @default 1\n */\n collisionStrength?: number;\n\n /**\n * Radius for collision detection (node size)\n * @default 10\n */\n collisionRadius?: number;\n\n /**\n * Strength of centering force\n * @default 0.1\n */\n centerStrength?: number;\n\n /**\n * Width of the simulation space\n */\n width: number;\n\n /**\n * Height of the simulation space\n */\n height: number;\n\n /**\n * Alpha decay rate (how quickly the simulation cools down)\n * @default 0.0228\n */\n alphaDecay?: number;\n\n /**\n * Velocity decay (friction)\n * @default 0.4\n */\n velocityDecay?: number;\n}\n\nexport interface UseForceSimulationReturn {\n /**\n * Current nodes with positions\n */\n nodes: SimulationNode[];\n\n /**\n * Current links\n */\n links: SimulationLink[];\n\n /**\n * Restart the simulation\n */\n restart: () => void;\n\n /**\n * Stop the simulation\n */\n stop: () => void;\n\n /**\n * Whether the simulation is currently running\n */\n isRunning: boolean;\n\n /**\n * Current alpha value (simulation heat)\n */\n alpha: number;\n}\n\n/**\n * Hook for managing d3-force simulations\n * Automatically handles simulation lifecycle, tick updates, and cleanup\n *\n * @param initialNodes - Initial nodes for the simulation\n * @param initialLinks - Initial links for the simulation\n * @param options - Configuration options for the force simulation\n * @returns Simulation state and control functions\n *\n * @example\n * ```tsx\n * function NetworkGraph() {\n * const nodes = [\n * { id: 'node1', name: 'Node 1' },\n * { id: 'node2', name: 'Node 2' },\n * { id: 'node3', name: 'Node 3' },\n * ];\n *\n * const links = [\n * { source: 'node1', target: 'node2' },\n * { source: 'node2', target: 'node3' },\n * ];\n *\n * const { nodes: simulatedNodes, links: simulatedLinks, restart } = useForceSimulation(\n * nodes,\n * links,\n * {\n * width: 800,\n * height: 600,\n * chargeStrength: -500,\n * linkDistance: 150,\n * }\n * );\n *\n * return (\n * <svg width={800} height={600}>\n * {simulatedLinks.map((link, i) => (\n * <line\n * key={i}\n * x1={(link.source as SimulationNode).x}\n * y1={(link.source as SimulationNode).y}\n * x2={(link.target as SimulationNode).x}\n * y2={(link.target as SimulationNode).y}\n * stroke=\"#999\"\n * />\n * ))}\n * {simulatedNodes.map((node) => (\n * <circle\n * key={node.id}\n * cx={node.x}\n * cy={node.y}\n * r={10}\n * fill=\"#69b3a2\"\n * />\n * ))}\n * </svg>\n * );\n * }\n * ```\n */\nexport function useForceSimulation(\n initialNodes: SimulationNode[],\n initialLinks: SimulationLink[],\n options: ForceSimulationOptions\n): UseForceSimulationReturn {\n const {\n chargeStrength = -300,\n linkDistance = 100,\n linkStrength = 1,\n collisionStrength = 1,\n collisionRadius = 10,\n centerStrength = 0.1,\n width,\n height,\n alphaDecay = 0.0228,\n velocityDecay = 0.4,\n } = options;\n\n const [nodes, setNodes] = useState<SimulationNode[]>(initialNodes);\n const [links, setLinks] = useState<SimulationLink[]>(initialLinks);\n const [isRunning, setIsRunning] = useState(false);\n const [alpha, setAlpha] = useState(1);\n\n const simulationRef = useRef<d3.Simulation<SimulationNode, SimulationLink> | null>(null);\n\n useEffect(() => {\n // Create a copy of nodes and links to avoid mutating the original data\n const nodesCopy = initialNodes.map((node) => ({ ...node }));\n const linksCopy = initialLinks.map((link) => ({ ...link }));\n\n // Create the simulation\n const simulation = d3\n .forceSimulation<SimulationNode>(nodesCopy)\n .force(\n 'link',\n d3\n .forceLink<SimulationNode, SimulationLink>(linksCopy)\n .id((d) => d.id)\n .distance(linkDistance)\n .strength(linkStrength)\n )\n .force('charge', d3.forceManyBody().strength(chargeStrength))\n .force('center', d3.forceCenter(width / 2, height / 2).strength(centerStrength))\n .force(\n 'collision',\n d3.forceCollide<SimulationNode>().radius(collisionRadius).strength(collisionStrength)\n )\n .alphaDecay(alphaDecay)\n .velocityDecay(velocityDecay);\n\n simulationRef.current = simulation;\n\n // Update state on each tick\n simulation.on('tick', () => {\n setNodes([...nodesCopy]);\n setLinks([...linksCopy]);\n setAlpha(simulation.alpha());\n setIsRunning(simulation.alpha() > simulation.alphaMin());\n });\n\n simulation.on('end', () => {\n setIsRunning(false);\n });\n\n // Cleanup on unmount\n return () => {\n simulation.stop();\n };\n }, [\n initialNodes,\n initialLinks,\n chargeStrength,\n linkDistance,\n linkStrength,\n collisionStrength,\n collisionRadius,\n centerStrength,\n width,\n height,\n alphaDecay,\n velocityDecay,\n ]);\n\n const restart = () => {\n if (simulationRef.current) {\n simulationRef.current.alpha(1).restart();\n setIsRunning(true);\n }\n };\n\n const stop = () => {\n if (simulationRef.current) {\n simulationRef.current.stop();\n setIsRunning(false);\n }\n };\n\n return {\n nodes,\n links,\n restart,\n stop,\n isRunning,\n alpha,\n };\n}\n\n/**\n * Hook for creating a draggable force simulation\n * Provides drag handlers that can be attached to node elements\n *\n * @param simulation - The d3 force simulation instance\n * @returns Drag behavior that can be applied to nodes\n *\n * @example\n * ```tsx\n * function DraggableNetworkGraph() {\n * const simulation = useRef<d3.Simulation<SimulationNode, SimulationLink>>();\n * const drag = useDrag(simulation.current);\n *\n * return (\n * <svg>\n * {nodes.map((node) => (\n * <circle\n * key={node.id}\n * {...drag}\n * cx={node.x}\n * cy={node.y}\n * r={10}\n * />\n * ))}\n * </svg>\n * );\n * }\n * ```\n */\nexport function useDrag(simulation: d3.Simulation<SimulationNode, any> | null | undefined) {\n const dragStarted = (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0.3).restart();\n node.fx = node.x;\n node.fy = node.y;\n };\n\n const dragged = (event: any, node: SimulationNode) => {\n node.fx = event.x;\n node.fy = event.y;\n };\n\n const dragEnded = (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0);\n node.fx = null;\n node.fy = null;\n };\n\n return {\n onDragStart: dragStarted,\n onDrag: dragged,\n onDragEnd: dragEnded,\n };\n}","import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * Merges class names using clsx and tailwind-merge\n * @param inputs - Class values to merge\n * @returns Merged class names\n */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}","import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport * as d3 from 'd3';\nimport {\n useForceSimulation,\n type SimulationNode,\n type SimulationLink,\n type ForceSimulationOptions,\n} from '../hooks/useForceSimulation';\nimport { cn } from '../utils/cn';\n\nexport interface GraphNode extends SimulationNode {\n id: string;\n label?: string;\n color?: string;\n size?: number;\n group?: string;\n}\n\nexport interface GraphLink extends SimulationLink {\n color?: string;\n width?: number;\n label?: string;\n}\n\nexport interface ForceDirectedGraphProps {\n /**\n * Array of nodes to display\n */\n nodes: GraphNode[];\n\n /**\n * Array of links between nodes\n */\n links: GraphLink[];\n\n /**\n * Width of the graph container\n */\n width: number;\n\n /**\n * Height of the graph container\n */\n height: number;\n\n /**\n * Force simulation options\n */\n simulationOptions?: Partial<ForceSimulationOptions>;\n\n /**\n * Whether to enable zoom and pan\n * @default true\n */\n enableZoom?: boolean;\n\n /**\n * Whether to enable node dragging\n * @default true\n */\n enableDrag?: boolean;\n\n /**\n * Callback when a node is clicked\n */\n onNodeClick?: (node: GraphNode) => void;\n\n /**\n * Callback when a node is hovered\n */\n onNodeHover?: (node: GraphNode | null) => void;\n\n /**\n * Callback when a link is clicked\n */\n onLinkClick?: (link: GraphLink) => void;\n\n /**\n * Selected node ID\n */\n selectedNodeId?: string;\n\n /**\n * Hovered node ID\n */\n hoveredNodeId?: string;\n\n /**\n * Default node color\n * @default \"#69b3a2\"\n */\n defaultNodeColor?: string;\n\n /**\n * Default node size\n * @default 10\n */\n defaultNodeSize?: number;\n\n /**\n * Default link color\n * @default \"#999\"\n */\n defaultLinkColor?: string;\n\n /**\n * Default link width\n * @default 1\n */\n defaultLinkWidth?: number;\n\n /**\n * Whether to show node labels\n * @default true\n */\n showNodeLabels?: boolean;\n\n /**\n * Whether to show link labels\n * @default false\n */\n showLinkLabels?: boolean;\n\n /**\n * Additional CSS classes\n */\n className?: string;\n}\n\nexport const ForceDirectedGraph: React.FC<ForceDirectedGraphProps> = ({\n nodes: initialNodes,\n links: initialLinks,\n width,\n height,\n simulationOptions,\n enableZoom = true,\n enableDrag = true,\n onNodeClick,\n onNodeHover,\n onLinkClick,\n selectedNodeId,\n hoveredNodeId,\n defaultNodeColor = '#69b3a2',\n defaultNodeSize = 10,\n defaultLinkColor = '#999',\n defaultLinkWidth = 1,\n showNodeLabels = true,\n showLinkLabels = false,\n className,\n}) => {\n const svgRef = useRef<SVGSVGElement>(null);\n const gRef = useRef<SVGGElement>(null);\n const [transform, setTransform] = useState({ k: 1, x: 0, y: 0 });\n\n // Initialize simulation\n const { nodes, links, restart } = useForceSimulation(initialNodes, initialLinks, {\n width,\n height,\n ...simulationOptions,\n });\n\n // Set up zoom behavior\n useEffect(() => {\n if (!enableZoom || !svgRef.current || !gRef.current) return;\n\n const svg = d3.select(svgRef.current);\n const g = d3.select(gRef.current);\n\n const zoom = d3\n .zoom<SVGSVGElement, unknown>()\n .scaleExtent([0.1, 10])\n .on('zoom', (event) => {\n g.attr('transform', event.transform);\n setTransform(event.transform);\n });\n\n svg.call(zoom);\n\n return () => {\n svg.on('.zoom', null);\n };\n }, [enableZoom]);\n\n // Set up drag behavior\n const handleDragStart = useCallback(\n (event: React.MouseEvent, node: GraphNode) => {\n if (!enableDrag) return;\n event.stopPropagation();\n node.fx = node.x;\n node.fy = node.y;\n restart();\n },\n [enableDrag, restart]\n );\n\n const handleDrag = useCallback(\n (event: React.MouseEvent, node: GraphNode) => {\n if (!enableDrag) return;\n const svg = svgRef.current;\n if (!svg) return;\n\n const rect = svg.getBoundingClientRect();\n const x = (event.clientX - rect.left - transform.x) / transform.k;\n const y = (event.clientY - rect.top - transform.y) / transform.k;\n\n node.fx = x;\n node.fy = y;\n },\n [enableDrag, transform]\n );\n\n const handleDragEnd = useCallback(\n (event: React.MouseEvent, node: GraphNode) => {\n if (!enableDrag) return;\n event.stopPropagation();\n node.fx = null;\n node.fy = null;\n },\n [enableDrag]\n );\n\n const handleNodeClick = useCallback(\n (node: GraphNode) => {\n onNodeClick?.(node);\n },\n [onNodeClick]\n );\n\n const handleNodeMouseEnter = useCallback(\n (node: GraphNode) => {\n onNodeHover?.(node);\n },\n [onNodeHover]\n );\n\n const handleNodeMouseLeave = useCallback(() => {\n onNodeHover?.(null);\n }, [onNodeHover]);\n\n const handleLinkClick = useCallback(\n (link: GraphLink) => {\n onLinkClick?.(link);\n },\n [onLinkClick]\n );\n\n return (\n <svg\n ref={svgRef}\n width={width}\n height={height}\n className={cn('bg-white dark:bg-gray-900', className)}\n >\n <defs>\n {/* Arrow marker for directed graphs */}\n <marker\n id=\"arrow\"\n viewBox=\"0 0 10 10\"\n refX=\"20\"\n refY=\"5\"\n markerWidth=\"6\"\n markerHeight=\"6\"\n orient=\"auto\"\n >\n <path d=\"M 0 0 L 10 5 L 0 10 z\" fill={defaultLinkColor} />\n </marker>\n </defs>\n\n <g ref={gRef}>\n {/* Render links */}\n {links.map((link, i) => {\n const source = link.source as GraphNode;\n const target = link.target as GraphNode;\n if (!source.x || !source.y || !target.x || !target.y) return null;\n\n return (\n <g key={`link-${i}`}>\n <line\n x1={source.x}\n y1={source.y}\n x2={target.x}\n y2={target.y}\n stroke={link.color || defaultLinkColor}\n strokeWidth={link.width || defaultLinkWidth}\n opacity={0.6}\n className=\"cursor-pointer transition-opacity hover:opacity-100\"\n onClick={() => handleLinkClick(link)}\n />\n {showLinkLabels && link.label && (\n <text\n x={(source.x + target.x) / 2}\n y={(source.y + target.y) / 2}\n fill=\"#666\"\n fontSize=\"10\"\n textAnchor=\"middle\"\n dominantBaseline=\"middle\"\n pointerEvents=\"none\"\n >\n {link.label}\n </text>\n )}\n </g>\n );\n })}\n\n {/* Render nodes */}\n {nodes.map((node) => {\n if (!node.x || !node.y) return null;\n\n const isSelected = selectedNodeId === node.id;\n const isHovered = hoveredNodeId === node.id;\n const nodeSize = node.size || defaultNodeSize;\n const nodeColor = node.color || defaultNodeColor;\n\n return (\n <g\n key={node.id}\n transform={`translate(${node.x},${node.y})`}\n className=\"cursor-pointer\"\n onClick={() => handleNodeClick(node)}\n onMouseEnter={() => handleNodeMouseEnter(node)}\n onMouseLeave={handleNodeMouseLeave}\n onMouseDown={(e) => handleDragStart(e, node)}\n onMouseMove={(e) => handleDrag(e, node)}\n onMouseUp={(e) => handleDragEnd(e, node)}\n >\n <circle\n r={nodeSize}\n fill={nodeColor}\n stroke={isSelected ? '#000' : isHovered ? '#666' : 'none'}\n strokeWidth={isSelected ? 3 : 2}\n opacity={isHovered || isSelected ? 1 : 0.9}\n className=\"transition-all\"\n />\n {showNodeLabels && node.label && (\n <text\n y={nodeSize + 15}\n fill=\"#333\"\n fontSize=\"12\"\n textAnchor=\"middle\"\n dominantBaseline=\"middle\"\n pointerEvents=\"none\"\n className=\"select-none\"\n >\n {node.label}\n </text>\n )}\n </g>\n );\n })}\n </g>\n </svg>\n );\n};\n\nForceDirectedGraph.displayName = 'ForceDirectedGraph';"]}
1
+ {"version":3,"sources":["../../src/hooks/useForceSimulation.ts","../../src/utils/cn.ts","../../src/charts/ForceDirectedGraph.tsx"],"names":["d3","useRef","useState","useEffect","pack","zoom"],"mappings":";;;;;;;AA2KO,SAAS,kBAAA,CACd,YAAA,EACA,YAAA,EACA,OAAA,EAC6E;AAC7E,EAAA,MAAM;AAAA,IACJ,cAAA,GAAiB,IAAA;AAAA,IACjB,YAAA,GAAe,GAAA;AAAA,IACf,YAAA,GAAe,CAAA;AAAA,IACf,iBAAA,GAAoB,CAAA;AAAA,IACpB,eAAA,GAAkB,EAAA;AAAA,IAClB,cAAA,GAAiB,GAAA;AAAA,IACjB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA,GAAa,MAAA;AAAA,IACb,aAAA,GAAgB,GAAA;AAAA,IAChB;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA2B,YAAY,CAAA;AACjE,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA2B,YAAY,CAAA;AACjE,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,KAAK,CAAA;AAChD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAS,CAAC,CAAA;AAEpC,EAAA,MAAM,aAAA,GAAgB,OAA6D,IAAI,CAAA;AAEvF,EAAA,SAAA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ectedGraph.js","sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport * as d3 from 'd3';\n\nexport interface SimulationNode extends d3.SimulationNodeDatum {\n id: string;\n [key: string]: any;\n}\n\nexport interface SimulationLink extends d3.SimulationLinkDatum<SimulationNode> {\n source: string | SimulationNode;\n target: string | SimulationNode;\n [key: string]: any;\n}\n\nexport interface ForceSimulationOptions {\n /**\n * Strength of the charge force (repulsion between nodes)\n * @default -300\n */\n chargeStrength?: number;\n\n /**\n * Distance for links between nodes\n * @default 100\n */\n linkDistance?: number;\n\n /**\n * Strength of the link force\n * @default 1\n */\n linkStrength?: number;\n\n /**\n * Strength of collision detection\n * @default 1\n */\n collisionStrength?: number;\n\n /**\n * Radius for collision detection (node size)\n * @default 10\n */\n collisionRadius?: number;\n\n /**\n * Strength of centering force\n * @default 0.1\n */\n centerStrength?: number;\n\n /**\n * Width of the simulation space\n */\n width: number;\n\n /**\n * Height of the simulation space\n */\n height: number;\n\n /**\n * Alpha decay rate (how quickly the simulation cools down)\n * @default 0.0228\n */\n alphaDecay?: number;\n\n /**\n * Velocity decay (friction)\n * @default 0.4\n */\n velocityDecay?: number;\n\n /**\n * Optional tick callback invoked on each simulation tick with current nodes/links and the simulation instance\n */\n onTick?: (nodes: SimulationNode[], links: SimulationLink[], sim: d3.Simulation<SimulationNode, SimulationLink>) => void;\n}\n\nexport interface UseForceSimulationReturn {\n /**\n * Current nodes with positions\n */\n nodes: SimulationNode[];\n\n /**\n * Current links\n */\n links: SimulationLink[];\n\n /**\n * Restart the simulation\n */\n restart: () => void;\n\n /**\n * Stop the simulation\n */\n stop: () => void;\n\n /**\n * Whether the simulation is currently running\n */\n isRunning: boolean;\n\n /**\n * Current alpha value (simulation heat)\n */\n alpha: number;\n}\n\n/**\n * Hook for managing d3-force simulations\n * Automatically handles simulation lifecycle, tick updates, and cleanup\n *\n * @param initialNodes - Initial nodes for the simulation\n * @param initialLinks - Initial links for the simulation\n * @param options - Configuration options for the force simulation\n * @returns Simulation state and control functions\n *\n * @example\n * ```tsx\n * function NetworkGraph() {\n * const nodes = [\n * { id: 'node1', name: 'Node 1' },\n * { id: 'node2', name: 'Node 2' },\n * { id: 'node3', name: 'Node 3' },\n * ];\n *\n * const links = [\n * { source: 'node1', target: 'node2' },\n * { source: 'node2', target: 'node3' },\n * ];\n *\n * const { nodes: simulatedNodes, links: simulatedLinks, restart } = useForceSimulation(\n * nodes,\n * links,\n * {\n * width: 800,\n * height: 600,\n * chargeStrength: -500,\n * linkDistance: 150,\n * }\n * );\n *\n * return (\n * <svg width={800} height={600}>\n * {simulatedLinks.map((link, i) => (\n * <line\n * key={i}\n * x1={(link.source as SimulationNode).x}\n * y1={(link.source as SimulationNode).y}\n * x2={(link.target as SimulationNode).x}\n * y2={(link.target as SimulationNode).y}\n * stroke=\"#999\"\n * />\n * ))}\n * {simulatedNodes.map((node) => (\n * <circle\n * key={node.id}\n * cx={node.x}\n * cy={node.y}\n * r={10}\n * fill=\"#69b3a2\"\n * />\n * ))}\n * </svg>\n * );\n * }\n * ```\n */\nexport function useForceSimulation(\n initialNodes: SimulationNode[],\n initialLinks: SimulationLink[],\n options: ForceSimulationOptions\n): UseForceSimulationReturn & { setForcesEnabled: (enabled: boolean) => void } {\n const {\n chargeStrength = -300,\n linkDistance = 100,\n linkStrength = 1,\n collisionStrength = 1,\n collisionRadius = 10,\n centerStrength = 0.1,\n width,\n height,\n alphaDecay = 0.0228,\n velocityDecay = 0.4,\n onTick,\n } = options;\n\n const [nodes, setNodes] = useState<SimulationNode[]>(initialNodes);\n const [links, setLinks] = useState<SimulationLink[]>(initialLinks);\n const [isRunning, setIsRunning] = useState(false);\n const [alpha, setAlpha] = useState(1);\n\n const simulationRef = useRef<d3.Simulation<SimulationNode, SimulationLink> | null>(null);\n\n useEffect(() => {\n // Create a copy of nodes and links to avoid mutating the original data\n const nodesCopy = initialNodes.map((node) => ({ ...node }));\n const linksCopy = initialLinks.map((link) => ({ ...link }));\n\n // Create the simulation\n const simulation = d3\n .forceSimulation<SimulationNode>(nodesCopy)\n .force(\n 'link',\n d3\n .forceLink<SimulationNode, SimulationLink>(linksCopy)\n .id((d) => d.id)\n .distance((d: any) => (d && d.distance != null ? d.distance : linkDistance))\n .strength(linkStrength)\n )\n .force('charge', d3.forceManyBody().strength(chargeStrength))\n .force('center', d3.forceCenter(width / 2, height / 2).strength(centerStrength))\n .force(\n 'collision',\n d3\n .forceCollide<SimulationNode>()\n .radius((d: any) => {\n // Use node-specific size when available and add configured padding to ensure minimum spacing\n const nodeSize = (d && d.size) ? d.size : 10;\n return nodeSize + collisionRadius;\n })\n .strength(collisionStrength)\n )\n .alphaDecay(alphaDecay)\n .velocityDecay(velocityDecay);\n\n simulationRef.current = simulation;\n\n // Update state on each tick\n simulation.on('tick', () => {\n try {\n if (typeof onTick === 'function') onTick(nodesCopy, linksCopy, simulation);\n } catch (e) {\n // ignore user tick errors\n }\n setNodes([...nodesCopy]);\n setLinks([...linksCopy]);\n setAlpha(simulation.alpha());\n setIsRunning(simulation.alpha() > simulation.alphaMin());\n });\n\n simulation.on('end', () => {\n setIsRunning(false);\n });\n\n // Cleanup on unmount\n return () => {\n simulation.stop();\n };\n }, [\n initialNodes,\n initialLinks,\n chargeStrength,\n linkDistance,\n linkStrength,\n collisionStrength,\n collisionRadius,\n centerStrength,\n width,\n height,\n alphaDecay,\n velocityDecay,\n onTick,\n ]);\n\n const restart = () => {\n if (simulationRef.current) {\n simulationRef.current.alpha(1).restart();\n setIsRunning(true);\n }\n };\n\n const stop = () => {\n if (simulationRef.current) {\n simulationRef.current.stop();\n setIsRunning(false);\n }\n };\n\n const originalForcesRef = useRef({ charge: chargeStrength, link: linkStrength, collision: collisionStrength });\n const forcesEnabledRef = useRef(true);\n\n const setForcesEnabled = (enabled: boolean) => {\n const sim = simulationRef.current;\n if (!sim) return;\n // avoid repeated updates\n if (forcesEnabledRef.current === enabled) return;\n forcesEnabledRef.current = enabled;\n\n try {\n // Only toggle charge and link forces to avoid collapse; keep collision/centering\n const charge: any = sim.force('charge');\n if (charge && typeof charge.strength === 'function') {\n charge.strength(enabled ? originalForcesRef.current.charge : 0);\n }\n\n const link: any = sim.force('link');\n if (link && typeof link.strength === 'function') {\n link.strength(enabled ? originalForcesRef.current.link : 0);\n }\n } catch (e) {\n // ignore\n }\n };\n\n return {\n nodes,\n links,\n restart,\n stop,\n isRunning,\n alpha,\n setForcesEnabled,\n };\n}\n\n/**\n * Hook for creating a draggable force simulation\n * Provides drag handlers that can be attached to node elements\n *\n * @param simulation - The d3 force simulation instance\n * @returns Drag behavior that can be applied to nodes\n *\n * @example\n * ```tsx\n * function DraggableNetworkGraph() {\n * const simulation = useRef<d3.Simulation<SimulationNode, SimulationLink>>();\n * const drag = useDrag(simulation.current);\n *\n * return (\n * <svg>\n * {nodes.map((node) => (\n * <circle\n * key={node.id}\n * {...drag}\n * cx={node.x}\n * cy={node.y}\n * r={10}\n * />\n * ))}\n * </svg>\n * );\n * }\n * ```\n */\nexport function useDrag(simulation: d3.Simulation<SimulationNode, any> | null | undefined) {\n const dragStarted = (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0.3).restart();\n node.fx = node.x;\n node.fy = node.y;\n };\n\n const dragged = (event: any, node: SimulationNode) => {\n node.fx = event.x;\n node.fy = event.y;\n };\n\n const dragEnded = (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0);\n node.fx = null;\n node.fy = null;\n };\n\n return {\n onDragStart: dragStarted,\n onDrag: dragged,\n onDragEnd: dragEnded,\n };\n}","import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/**\n * Merges class names using clsx and tailwind-merge\n * @param inputs - Class values to merge\n * @returns Merged class names\n */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}","import React, { useCallback, useEffect, useRef, useState, forwardRef, useImperativeHandle } from 'react';\nimport * as d3 from 'd3';\nimport {\n useForceSimulation,\n type SimulationNode,\n type SimulationLink,\n type ForceSimulationOptions,\n} from '../hooks/useForceSimulation';\nimport { cn } from '../utils/cn';\n\nexport interface GraphNode extends SimulationNode {\n id: string;\n label?: string;\n color?: string;\n size?: number;\n group?: string;\n}\n\nexport interface GraphLink extends SimulationLink {\n color?: string;\n width?: number;\n label?: string;\n}\n\nexport interface ForceDirectedGraphHandle {\n /**\n * Pin all nodes in place\n */\n pinAll: () => void;\n\n /**\n * Unpin all nodes (release constraints)\n */\n unpinAll: () => void;\n\n /**\n * Reset all nodes to auto-layout (unpin and restart simulation)\n */\n resetLayout: () => void;\n\n /**\n * Fit all nodes in the current view\n */\n fitView: () => void;\n\n /**\n * Get currently pinned node IDs\n */\n getPinnedNodes: () => string[];\n\n /**\n * Toggle dragging mode\n */\n setDragMode: (enabled: boolean) => void;\n}\n\nexport interface ForceDirectedGraphProps {\n /**\n * Array of nodes to display\n */\n nodes: GraphNode[];\n\n /**\n * Array of links between nodes\n */\n links: GraphLink[];\n\n /**\n * Width of the graph container\n */\n width: number;\n\n /**\n * Height of the graph container\n */\n height: number;\n\n /**\n * Force simulation options\n */\n simulationOptions?: Partial<ForceSimulationOptions>;\n\n /**\n * Whether to enable zoom and pan\n * @default true\n */\n enableZoom?: boolean;\n\n /**\n * Whether to enable node dragging\n * @default true\n */\n enableDrag?: boolean;\n\n /**\n * Callback when a node is clicked\n */\n onNodeClick?: (node: GraphNode) => void;\n\n /**\n * Callback when a node is hovered\n */\n onNodeHover?: (node: GraphNode | null) => void;\n\n /**\n * Callback when a link is clicked\n */\n onLinkClick?: (link: GraphLink) => void;\n\n /**\n * Selected node ID\n */\n selectedNodeId?: string;\n\n /**\n * Hovered node ID\n */\n hoveredNodeId?: string;\n\n /**\n * Default node color\n * @default \"#69b3a2\"\n */\n defaultNodeColor?: string;\n\n /**\n * Default node size\n * @default 10\n */\n defaultNodeSize?: number;\n\n /**\n * Default link color\n * @default \"#999\"\n */\n defaultLinkColor?: string;\n\n /**\n * Default link width\n * @default 1\n */\n defaultLinkWidth?: number;\n\n /**\n * Whether to show node labels\n * @default true\n */\n showNodeLabels?: boolean;\n\n /**\n * Whether to show link labels\n * @default false\n */\n showLinkLabels?: boolean;\n\n /**\n * Additional CSS classes\n */\n className?: string;\n\n /**\n * Manual layout mode: disables forces, allows free dragging\n * @default false\n */\n manualLayout?: boolean;\n\n /**\n * Callback when manual layout mode is toggled\n */\n onManualLayoutChange?: (enabled: boolean) => void;\n\n /**\n * Package bounds computed by the parent (pack layout): map of `pkg:group` -> {x,y,r}\n */\n packageBounds?: Record<string, { x: number; y: number; r: number }>;\n}\n\nexport const ForceDirectedGraph = forwardRef<ForceDirectedGraphHandle, ForceDirectedGraphProps>(\n (\n {\n nodes: initialNodes,\n links: initialLinks,\n width,\n height,\n simulationOptions,\n enableZoom = true,\n enableDrag = true,\n onNodeClick,\n onNodeHover,\n onLinkClick,\n selectedNodeId,\n hoveredNodeId,\n defaultNodeColor = '#69b3a2',\n defaultNodeSize = 10,\n defaultLinkColor = '#999',\n defaultLinkWidth = 1,\n showNodeLabels = true,\n showLinkLabels = false,\n className,\n manualLayout = false,\n onManualLayoutChange,\n packageBounds,\n },\n ref\n ) => {\n const svgRef = useRef<SVGSVGElement>(null);\n const gRef = useRef<SVGGElement>(null);\n const [transform, setTransform] = useState({ k: 1, x: 0, y: 0 });\n const dragNodeRef = useRef<GraphNode | null>(null);\n const dragActiveRef = useRef(false);\n const [pinnedNodes, setPinnedNodes] = useState<Set<string>>(new Set());\n const internalDragEnabledRef = useRef(enableDrag);\n\n // Update the ref when enableDrag prop changes\n useEffect(() => {\n internalDragEnabledRef.current = enableDrag;\n }, [enableDrag]);\n\n // Initialize simulation with manualLayout mode\n const onTick = (nodesCopy: any[], _linksCopy: any[], _sim: any) => {\n const bounds = packageBounds && Object.keys(packageBounds).length ? packageBounds : undefined;\n // fallback: if parent didn't provide packageBounds, compute locally from initialNodes\n let effectiveBounds = bounds;\n if (!effectiveBounds) {\n try {\n const counts: Record<string, number> = {};\n (initialNodes || []).forEach((n: any) => {\n if (n && n.kind === 'file') {\n const g = n.packageGroup || 'root';\n counts[g] = (counts[g] || 0) + 1;\n }\n });\n const children = Object.keys(counts).map((k) => ({ name: k, value: counts[k] }));\n if (children.length > 0) {\n const root = d3.hierarchy<any>({ children } as any).sum((d: any) => d.value as number);\n const pack = d3.pack().size([width, height]).padding(30);\n const packed = pack(root);\n const map: Record<string, { x: number; y: number; r: number }> = {};\n if (packed.children) {\n packed.children.forEach((c: any) => {\n map[`pkg:${c.data.name}`] = { x: c.x, y: c.y, r: c.r * 0.95 };\n });\n effectiveBounds = map;\n }\n }\n } catch (e) {\n // ignore fallback errors\n }\n }\n if (!effectiveBounds) return;\n try {\n Object.values(nodesCopy).forEach((n: any) => {\n if (!n) return;\n // only constrain file nodes (package nodes have their own fx/fy)\n if (n.kind === 'package') return;\n const pkg = n.packageGroup;\n if (!pkg) return;\n const bound = effectiveBounds[`pkg:${pkg}`];\n if (!bound) return;\n const margin = (n.size || 10) + 12;\n const dx = (n.x || 0) - bound.x;\n const dy = (n.y || 0) - bound.y;\n const dist = Math.sqrt(dx * dx + dy * dy) || 0.0001;\n const maxDist = Math.max(1, bound.r - margin);\n if (dist > maxDist) {\n const desiredX = bound.x + dx * (maxDist / dist);\n const desiredY = bound.y + dy * (maxDist / dist);\n // apply a soft corrective velocity toward the desired position\n const softness = 0.08;\n n.vx = (n.vx || 0) + (desiredX - n.x) * softness;\n n.vy = (n.vy || 0) + (desiredY - n.y) * softness;\n }\n });\n } catch (e) {\n // ignore\n }\n };\n\n const { nodes, links, restart, stop, setForcesEnabled } = useForceSimulation(initialNodes, initialLinks, {\n width,\n height,\n chargeStrength: manualLayout ? 0 : undefined,\n onTick,\n ...simulationOptions,\n });\n\n // If package bounds are provided, add a tick-time clamp via the hook's onTick option\n useEffect(() => {\n if (!packageBounds) return;\n // nothing to do here because the hook will call onTick passed in creation; we need to recreate simulation to use onTick\n // So restart the simulation to pick up potential changes in node bounds.\n try { restart(); } catch (e) {}\n }, [packageBounds, restart]);\n\n // If manual layout is enabled or any nodes are pinned, disable forces\n useEffect(() => {\n try {\n if (manualLayout || pinnedNodes.size > 0) setForcesEnabled(false);\n else setForcesEnabled(true);\n } catch (e) {\n // ignore\n }\n }, [manualLayout, pinnedNodes, setForcesEnabled]);\n\n // Expose imperative handle for parent components\n useImperativeHandle(\n ref,\n () => ({\n pinAll: () => {\n const newPinned = new Set<string>();\n nodes.forEach((node) => {\n node.fx = node.x;\n node.fy = node.y;\n newPinned.add(node.id);\n });\n setPinnedNodes(newPinned);\n restart();\n },\n\n unpinAll: () => {\n nodes.forEach((node) => {\n node.fx = null;\n node.fy = null;\n });\n setPinnedNodes(new Set());\n restart();\n },\n\n resetLayout: () => {\n nodes.forEach((node) => {\n node.fx = null;\n node.fy = null;\n });\n setPinnedNodes(new Set());\n restart();\n },\n\n fitView: () => {\n if (!svgRef.current || !nodes.length) return;\n\n // Calculate bounds\n let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;\n nodes.forEach((node) => {\n if (node.x !== undefined && node.y !== undefined) {\n const size = node.size || 10;\n minX = Math.min(minX, node.x - size);\n maxX = Math.max(maxX, node.x + size);\n minY = Math.min(minY, node.y - size);\n maxY = Math.max(maxY, node.y + size);\n }\n });\n\n if (!isFinite(minX)) return;\n\n const padding = 40;\n const nodeWidth = maxX - minX;\n const nodeHeight = maxY - minY;\n const scale = Math.min(\n (width - padding * 2) / nodeWidth,\n (height - padding * 2) / nodeHeight,\n 10\n );\n\n const centerX = (minX + maxX) / 2;\n const centerY = (minY + maxY) / 2;\n\n const x = width / 2 - centerX * scale;\n const y = height / 2 - centerY * scale;\n\n if (gRef.current && svgRef.current) {\n const svg = d3.select(svgRef.current);\n const newTransform = d3.zoomIdentity.translate(x, y).scale(scale);\n svg.transition().duration(300).call(d3.zoom<SVGSVGElement, unknown>().transform as any, newTransform);\n setTransform(newTransform);\n }\n },\n\n getPinnedNodes: () => Array.from(pinnedNodes),\n\n setDragMode: (enabled: boolean) => {\n internalDragEnabledRef.current = enabled;\n },\n }),\n [nodes, pinnedNodes, restart, width, height]\n );\n\n // Notify parent when manual layout mode changes (uses the prop so it's not unused)\n useEffect(() => {\n try {\n if (typeof onManualLayoutChange === 'function') onManualLayoutChange(manualLayout);\n } catch (e) {\n // ignore errors from callbacks\n }\n }, [manualLayout, onManualLayoutChange]);\n\n // Set up zoom behavior\n useEffect(() => {\n if (!enableZoom || !svgRef.current || !gRef.current) return;\n\n const svg = d3.select(svgRef.current);\n const g = d3.select(gRef.current);\n\n const zoom = d3\n .zoom<SVGSVGElement, unknown>()\n .scaleExtent([0.1, 10])\n .on('zoom', (event) => {\n g.attr('transform', event.transform);\n setTransform(event.transform);\n });\n\n svg.call(zoom);\n\n return () => {\n svg.on('.zoom', null);\n };\n }, [enableZoom]);\n\n // Set up drag behavior with global listeners for smoother dragging\n const handleDragStart = useCallback(\n (event: React.MouseEvent, node: GraphNode) => {\n if (!enableDrag) return;\n event.preventDefault();\n event.stopPropagation();\n // pause forces while dragging to avoid the whole graph moving\n dragActiveRef.current = true;\n dragNodeRef.current = node;\n node.fx = node.x;\n node.fy = node.y;\n setPinnedNodes((prev) => new Set([...prev, node.id]));\n try { stop(); } catch (e) {}\n },\n [enableDrag, restart]\n );\n\n useEffect(() => {\n if (!enableDrag) return;\n\n const handleWindowMove = (event: MouseEvent) => {\n if (!dragActiveRef.current || !dragNodeRef.current) return;\n const svg = svgRef.current;\n if (!svg) return;\n const rect = svg.getBoundingClientRect();\n const x = (event.clientX - rect.left - transform.x) / transform.k;\n const y = (event.clientY - rect.top - transform.y) / transform.k;\n dragNodeRef.current.fx = x;\n dragNodeRef.current.fy = y;\n };\n\n const handleWindowUp = () => {\n if (!dragActiveRef.current) return;\n // Keep fx/fy set to pin the node where it was dropped.\n try { setForcesEnabled(true); restart(); } catch (e) {}\n dragNodeRef.current = null;\n dragActiveRef.current = false;\n };\n\n const handleWindowLeave = (event: MouseEvent) => {\n if (event.relatedTarget === null) handleWindowUp();\n };\n\n window.addEventListener('mousemove', handleWindowMove);\n window.addEventListener('mouseup', handleWindowUp);\n window.addEventListener('mouseout', handleWindowLeave);\n window.addEventListener('blur', handleWindowUp);\n\n return () => {\n window.removeEventListener('mousemove', handleWindowMove);\n window.removeEventListener('mouseup', handleWindowUp);\n window.removeEventListener('mouseout', handleWindowLeave);\n window.removeEventListener('blur', handleWindowUp);\n };\n }, [enableDrag, transform]);\n\n // Attach d3.drag behavior to node groups rendered by React. This helps make\n // dragging more robust across transforms and pointer behaviors.\n useEffect(() => {\n if (!gRef.current || !enableDrag) return;\n const g = d3.select(gRef.current);\n const dragBehavior = d3\n .drag<SVGGElement, unknown>()\n .on('start', function (event) {\n try {\n const target = (event.sourceEvent && (event.sourceEvent.target as Element)) || (event.target as Element);\n const grp = target.closest?.('g.node') as Element | null;\n const id = grp?.getAttribute('data-id');\n if (!id) return;\n const node = nodes.find((n) => n.id === id) as GraphNode | undefined;\n if (!node) return;\n if (!internalDragEnabledRef.current) return;\n if (!event.active) restart();\n dragActiveRef.current = true;\n dragNodeRef.current = node;\n node.fx = node.x;\n node.fy = node.y;\n setPinnedNodes((prev) => new Set([...prev, node.id]));\n } catch (e) {\n // ignore\n }\n })\n .on('drag', function (event) {\n if (!dragActiveRef.current || !dragNodeRef.current) return;\n const svg = svgRef.current;\n if (!svg) return;\n const rect = svg.getBoundingClientRect();\n const x = (event.sourceEvent.clientX - rect.left - transform.x) / transform.k;\n const y = (event.sourceEvent.clientY - rect.top - transform.y) / transform.k;\n dragNodeRef.current.fx = x;\n dragNodeRef.current.fy = y;\n })\n .on('end', function () {\n // re-enable forces when drag ends\n try { setForcesEnabled(true); restart(); } catch (e) {}\n dragNodeRef.current = null;\n dragActiveRef.current = false;\n });\n\n try {\n g.selectAll('g.node').call(dragBehavior as any);\n } catch (e) {\n // ignore attach errors\n }\n\n return () => {\n try {\n g.selectAll('g.node').on('.drag', null as any);\n } catch (e) {\n /* ignore */\n }\n };\n }, [gRef, enableDrag, nodes, transform, restart]);\n\n const handleNodeClick = useCallback(\n (node: GraphNode) => {\n onNodeClick?.(node);\n },\n [onNodeClick]\n );\n\n const handleNodeDoubleClick = useCallback(\n (event: React.MouseEvent, node: GraphNode) => {\n event.stopPropagation();\n if (!enableDrag) return;\n if (node.fx === null || node.fx === undefined) {\n node.fx = node.x;\n node.fy = node.y;\n setPinnedNodes((prev) => new Set([...prev, node.id]));\n } else {\n node.fx = null;\n node.fy = null;\n setPinnedNodes((prev) => {\n const next = new Set(prev);\n next.delete(node.id);\n return next;\n });\n }\n restart();\n },\n [enableDrag, restart]\n );\n\n const handleCanvasDoubleClick = useCallback(() => {\n nodes.forEach((node) => {\n node.fx = null;\n node.fy = null;\n });\n setPinnedNodes(new Set());\n restart();\n }, [nodes, restart]);\n\n const handleNodeMouseEnter = useCallback(\n (node: GraphNode) => {\n onNodeHover?.(node);\n },\n [onNodeHover]\n );\n\n const handleNodeMouseLeave = useCallback(() => {\n onNodeHover?.(null);\n }, [onNodeHover]);\n\n const handleLinkClick = useCallback(\n (link: GraphLink) => {\n onLinkClick?.(link);\n },\n [onLinkClick]\n );\n\n return (\n <svg\n ref={svgRef}\n width={width}\n height={height}\n className={cn('bg-white dark:bg-gray-900', className)}\n onDoubleClick={handleCanvasDoubleClick}\n >\n <defs>\n {/* Arrow marker for directed graphs */}\n <marker\n id=\"arrow\"\n viewBox=\"0 0 10 10\"\n refX=\"20\"\n refY=\"5\"\n markerWidth=\"6\"\n markerHeight=\"6\"\n orient=\"auto\"\n >\n <path d=\"M 0 0 L 10 5 L 0 10 z\" fill={defaultLinkColor} />\n </marker>\n </defs>\n\n <g ref={gRef}>\n \n {/* Render links */}\n {links.map((link, i) => {\n const source = link.source as GraphNode;\n const target = link.target as GraphNode;\n if (source.x == null || source.y == null || target.x == null || target.y == null) return null;\n\n return (\n <g key={`link-${i}`}>\n <line\n x1={source.x}\n y1={source.y}\n x2={target.x}\n y2={target.y}\n stroke={link.color || defaultLinkColor}\n strokeWidth={link.width || defaultLinkWidth}\n opacity={0.6}\n className=\"cursor-pointer transition-opacity hover:opacity-100\"\n onClick={() => handleLinkClick(link)}\n />\n {showLinkLabels && link.label && (\n <text\n x={(source.x + target.x) / 2}\n y={(source.y + target.y) / 2}\n fill=\"#666\"\n fontSize=\"10\"\n textAnchor=\"middle\"\n dominantBaseline=\"middle\"\n pointerEvents=\"none\"\n >\n {link.label}\n </text>\n )}\n </g>\n );\n })}\n\n {/* Render nodes */}\n {nodes.map((node) => {\n if (node.x == null || node.y == null) return null;\n\n const isSelected = selectedNodeId === node.id;\n const isHovered = hoveredNodeId === node.id;\n const nodeSize = node.size || defaultNodeSize;\n const nodeColor = node.color || defaultNodeColor;\n\n return (\n <g\n key={node.id}\n transform={`translate(${node.x},${node.y})`}\n className=\"cursor-pointer node\"\n data-id={node.id}\n onClick={() => handleNodeClick(node)}\n onDoubleClick={(event) => handleNodeDoubleClick(event, node)}\n onMouseEnter={() => handleNodeMouseEnter(node)}\n onMouseLeave={handleNodeMouseLeave}\n onMouseDown={(e) => handleDragStart(e, node)}\n >\n <circle\n r={nodeSize}\n fill={nodeColor}\n stroke={isSelected ? '#000' : isHovered ? '#666' : 'none'}\n strokeWidth={pinnedNodes.has(node.id) ? 3 : isSelected ? 2.5 : isHovered ? 2 : 1.5}\n opacity={isHovered || isSelected ? 1 : 0.9}\n className=\"transition-all\"\n />\n {pinnedNodes.has(node.id) && (\n <circle\n r={nodeSize + 4}\n fill=\"none\"\n stroke=\"#ff6b6b\"\n strokeWidth={1}\n opacity={0.5}\n className=\"pointer-events-none\"\n />\n )}\n {showNodeLabels && node.label && (\n <text\n y={nodeSize + 15}\n fill=\"#333\"\n fontSize=\"12\"\n textAnchor=\"middle\"\n dominantBaseline=\"middle\"\n pointerEvents=\"none\"\n className=\"select-none\"\n >\n {node.label}\n </text>\n )}\n </g>\n );\n })}\n {/* Package boundary circles (from parent pack layout) - drawn on top for visibility */}\n {packageBounds && Object.keys(packageBounds).length > 0 && (\n <g className=\"package-boundaries\" pointerEvents=\"none\">\n {Object.entries(packageBounds).map(([pid, b]) => (\n <g key={pid}>\n <circle\n cx={b.x}\n cy={b.y}\n r={b.r}\n fill=\"rgba(148,163,184,0.06)\"\n stroke=\"#475569\"\n strokeWidth={2}\n strokeDasharray=\"6 6\"\n opacity={0.9}\n />\n <text\n x={b.x}\n y={Math.max(12, b.y - b.r + 14)}\n fill=\"#475569\"\n fontSize={11}\n textAnchor=\"middle\"\n pointerEvents=\"none\"\n >\n {pid.replace(/^pkg:/, '')}\n </text>\n </g>\n ))}\n </g>\n )}\n </g>\n </svg>\n );\n }\n);\n\nForceDirectedGraph.displayName = 'ForceDirectedGraph';"]}
@@ -20,6 +20,7 @@ interface ForceSimulationOptions {
20
20
  height: number;
21
21
  alphaDecay?: number;
22
22
  velocityDecay?: number;
23
+ onTick?: (nodes: SimulationNode[], links: SimulationLink[], sim: d3.Simulation<SimulationNode, SimulationLink>) => void;
23
24
  }
24
25
  interface UseForceSimulationReturn {
25
26
  nodes: SimulationNode[];
@@ -29,7 +30,9 @@ interface UseForceSimulationReturn {
29
30
  isRunning: boolean;
30
31
  alpha: number;
31
32
  }
32
- declare function useForceSimulation(initialNodes: SimulationNode[], initialLinks: SimulationLink[], options: ForceSimulationOptions): UseForceSimulationReturn;
33
+ declare function useForceSimulation(initialNodes: SimulationNode[], initialLinks: SimulationLink[], options: ForceSimulationOptions): UseForceSimulationReturn & {
34
+ setForcesEnabled: (enabled: boolean) => void;
35
+ };
33
36
  declare function useDrag(simulation: d3.Simulation<SimulationNode, any> | null | undefined): {
34
37
  onDragStart: (event: any, node: SimulationNode) => void;
35
38
  onDrag: (event: any, node: SimulationNode) => void;
@@ -13,7 +13,8 @@ function useForceSimulation(initialNodes, initialLinks, options) {
13
13
  width,
14
14
  height,
15
15
  alphaDecay = 0.0228,
16
- velocityDecay = 0.4
16
+ velocityDecay = 0.4,
17
+ onTick
17
18
  } = options;
18
19
  const [nodes, setNodes] = useState(initialNodes);
19
20
  const [links, setLinks] = useState(initialLinks);
@@ -25,13 +26,20 @@ function useForceSimulation(initialNodes, initialLinks, options) {
25
26
  const linksCopy = initialLinks.map((link) => ({ ...link }));
26
27
  const simulation = d3.forceSimulation(nodesCopy).force(
27
28
  "link",
28
- d3.forceLink(linksCopy).id((d) => d.id).distance(linkDistance).strength(linkStrength)
29
+ d3.forceLink(linksCopy).id((d) => d.id).distance((d) => d && d.distance != null ? d.distance : linkDistance).strength(linkStrength)
29
30
  ).force("charge", d3.forceManyBody().strength(chargeStrength)).force("center", d3.forceCenter(width / 2, height / 2).strength(centerStrength)).force(
30
31
  "collision",
31
- d3.forceCollide().radius(collisionRadius).strength(collisionStrength)
32
+ d3.forceCollide().radius((d) => {
33
+ const nodeSize = d && d.size ? d.size : 10;
34
+ return nodeSize + collisionRadius;
35
+ }).strength(collisionStrength)
32
36
  ).alphaDecay(alphaDecay).velocityDecay(velocityDecay);
33
37
  simulationRef.current = simulation;
34
38
  simulation.on("tick", () => {
39
+ try {
40
+ if (typeof onTick === "function") onTick(nodesCopy, linksCopy, simulation);
41
+ } catch (e) {
42
+ }
35
43
  setNodes([...nodesCopy]);
36
44
  setLinks([...linksCopy]);
37
45
  setAlpha(simulation.alpha());
@@ -55,7 +63,8 @@ function useForceSimulation(initialNodes, initialLinks, options) {
55
63
  width,
56
64
  height,
57
65
  alphaDecay,
58
- velocityDecay
66
+ velocityDecay,
67
+ onTick
59
68
  ]);
60
69
  const restart = () => {
61
70
  if (simulationRef.current) {
@@ -69,13 +78,33 @@ function useForceSimulation(initialNodes, initialLinks, options) {
69
78
  setIsRunning(false);
70
79
  }
71
80
  };
81
+ const originalForcesRef = useRef({ charge: chargeStrength, link: linkStrength, collision: collisionStrength });
82
+ const forcesEnabledRef = useRef(true);
83
+ const setForcesEnabled = (enabled) => {
84
+ const sim = simulationRef.current;
85
+ if (!sim) return;
86
+ if (forcesEnabledRef.current === enabled) return;
87
+ forcesEnabledRef.current = enabled;
88
+ try {
89
+ const charge = sim.force("charge");
90
+ if (charge && typeof charge.strength === "function") {
91
+ charge.strength(enabled ? originalForcesRef.current.charge : 0);
92
+ }
93
+ const link = sim.force("link");
94
+ if (link && typeof link.strength === "function") {
95
+ link.strength(enabled ? originalForcesRef.current.link : 0);
96
+ }
97
+ } catch (e) {
98
+ }
99
+ };
72
100
  return {
73
101
  nodes,
74
102
  links,
75
103
  restart,
76
104
  stop,
77
105
  isRunning,
78
- alpha
106
+ alpha,
107
+ setForcesEnabled
79
108
  };
80
109
  }
81
110
  function useDrag(simulation) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useForceSimulation.ts"],"names":[],"mappings":";;;;AAsKO,SAAS,kBAAA,CACd,YAAA,EACA,YAAA,EACA,OAAA,EAC0B;AAC1B,EAAA,MAAM;AAAA,IACJ,cAAA,GAAiB,IAAA;AAAA,IACjB,YAAA,GAAe,GAAA;AAAA,IACf,YAAA,GAAe,CAAA;AAAA,IACf,iBAAA,GAAoB,CAAA;AAAA,IACpB,eAAA,GAAkB,EAAA;AAAA,IAClB,cAAA,GAAiB,GAAA;AAAA,IACjB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA,GAAa,MAAA;AAAA,IACb,aAAA,GAAgB;AAAA,GAClB,GAAI,OAAA;AAEJ,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA2B,YAAY,CAAA;AACjE,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA2B,YAAY,CAAA;AACjE,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,SAAS,KAAK,CAAA;AAChD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAS,CAAC,CAAA;AAEpC,EAAA,MAAM,aAAA,GAAgB,OAA6D,IAAI,CAAA;AAEvF,EAAA,SAAA,CAAU,MAAM;AAEd,IAAA,MAAM,SAAA,GAAY,aAAa,GAAA,CAAI,CAAC,UAAU,EAAE,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A,CAAM,CAAA;AAChB,IAAA,IAAA,CAAK,KAAK,KAAA,CAAM,CAAA;AAAA,EAClB,CAAA;AAEA,EAAA,MAAM,SAAA,GAAY,CAAC,KAAA,EAAY,IAAA,KAAyB;AACtD,IAAA,IAAI,CAAC,UAAA,EAAY;AACjB,IAAA,IAAI,CAAC,KAAA,CAAM,MAAA,EAAQ,UAAA,CAAW,YAAY,CAAC,CAAA;AAC3C,IAAA,IAAA,CAAK,EAAA,GAAK,IAAA;AACV,IAAA,IAAA,CAAK,EAAA,GAAK,IAAA;AAAA,EACZ,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,WAAA;AAAA,IACb,MAAA,EAAQ,OAAA;AAAA,IACR,SAAA,EAAW;AAAA,GACb;AACF","file":"useForceSimulation.js","sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport * as d3 from 'd3';\n\nexport interface SimulationNode extends d3.SimulationNodeDatum {\n id: string;\n [key: string]: any;\n}\n\nexport interface SimulationLink extends d3.SimulationLinkDatum<SimulationNode> {\n source: string | SimulationNode;\n target: string | SimulationNode;\n [key: string]: any;\n}\n\nexport interface ForceSimulationOptions {\n /**\n * Strength of the charge force (repulsion between nodes)\n * @default -300\n */\n chargeStrength?: number;\n\n /**\n * Distance for links between nodes\n * @default 100\n */\n linkDistance?: number;\n\n /**\n * Strength of the link force\n * @default 1\n */\n linkStrength?: number;\n\n /**\n * Strength of collision detection\n * @default 1\n */\n collisionStrength?: number;\n\n /**\n * Radius for collision detection (node size)\n * @default 10\n */\n collisionRadius?: number;\n\n /**\n * Strength of centering force\n * @default 0.1\n */\n centerStrength?: number;\n\n /**\n * Width of the simulation space\n */\n width: number;\n\n /**\n * Height of the simulation space\n */\n height: number;\n\n /**\n * Alpha decay rate (how quickly the simulation cools down)\n * @default 0.0228\n */\n alphaDecay?: number;\n\n /**\n * Velocity decay (friction)\n * @default 0.4\n */\n velocityDecay?: number;\n}\n\nexport interface UseForceSimulationReturn {\n /**\n * Current nodes with positions\n */\n nodes: SimulationNode[];\n\n /**\n * Current links\n */\n links: SimulationLink[];\n\n /**\n * Restart the simulation\n */\n restart: () => void;\n\n /**\n * Stop the simulation\n */\n stop: () => void;\n\n /**\n * Whether the simulation is currently running\n */\n isRunning: boolean;\n\n /**\n * Current alpha value (simulation heat)\n */\n alpha: number;\n}\n\n/**\n * Hook for managing d3-force simulations\n * Automatically handles simulation lifecycle, tick updates, and cleanup\n *\n * @param initialNodes - Initial nodes for the simulation\n * @param initialLinks - Initial links for the simulation\n * @param options - Configuration options for the force simulation\n * @returns Simulation state and control functions\n *\n * @example\n * ```tsx\n * function NetworkGraph() {\n * const nodes = [\n * { id: 'node1', name: 'Node 1' },\n * { id: 'node2', name: 'Node 2' },\n * { id: 'node3', name: 'Node 3' },\n * ];\n *\n * const links = [\n * { source: 'node1', target: 'node2' },\n * { source: 'node2', target: 'node3' },\n * ];\n *\n * const { nodes: simulatedNodes, links: simulatedLinks, restart } = useForceSimulation(\n * nodes,\n * links,\n * {\n * width: 800,\n * height: 600,\n * chargeStrength: -500,\n * linkDistance: 150,\n * }\n * );\n *\n * return (\n * <svg width={800} height={600}>\n * {simulatedLinks.map((link, i) => (\n * <line\n * key={i}\n * x1={(link.source as SimulationNode).x}\n * y1={(link.source as SimulationNode).y}\n * x2={(link.target as SimulationNode).x}\n * y2={(link.target as SimulationNode).y}\n * stroke=\"#999\"\n * />\n * ))}\n * {simulatedNodes.map((node) => (\n * <circle\n * key={node.id}\n * cx={node.x}\n * cy={node.y}\n * r={10}\n * fill=\"#69b3a2\"\n * />\n * ))}\n * </svg>\n * );\n * }\n * ```\n */\nexport function useForceSimulation(\n initialNodes: SimulationNode[],\n initialLinks: SimulationLink[],\n options: ForceSimulationOptions\n): UseForceSimulationReturn {\n const {\n chargeStrength = -300,\n linkDistance = 100,\n linkStrength = 1,\n collisionStrength = 1,\n collisionRadius = 10,\n centerStrength = 0.1,\n width,\n height,\n alphaDecay = 0.0228,\n velocityDecay = 0.4,\n } = options;\n\n const [nodes, setNodes] = useState<SimulationNode[]>(initialNodes);\n const [links, setLinks] = useState<SimulationLink[]>(initialLinks);\n const [isRunning, setIsRunning] = useState(false);\n const [alpha, setAlpha] = useState(1);\n\n const simulationRef = useRef<d3.Simulation<SimulationNode, SimulationLink> | null>(null);\n\n useEffect(() => {\n // Create a copy of nodes and links to avoid mutating the original data\n const nodesCopy = initialNodes.map((node) => ({ ...node }));\n const linksCopy = initialLinks.map((link) => ({ ...link }));\n\n // Create the simulation\n const simulation = d3\n .forceSimulation<SimulationNode>(nodesCopy)\n .force(\n 'link',\n d3\n .forceLink<SimulationNode, SimulationLink>(linksCopy)\n .id((d) => d.id)\n .distance(linkDistance)\n .strength(linkStrength)\n )\n .force('charge', d3.forceManyBody().strength(chargeStrength))\n .force('center', d3.forceCenter(width / 2, height / 2).strength(centerStrength))\n .force(\n 'collision',\n d3.forceCollide<SimulationNode>().radius(collisionRadius).strength(collisionStrength)\n )\n .alphaDecay(alphaDecay)\n .velocityDecay(velocityDecay);\n\n simulationRef.current = simulation;\n\n // Update state on each tick\n simulation.on('tick', () => {\n setNodes([...nodesCopy]);\n setLinks([...linksCopy]);\n setAlpha(simulation.alpha());\n setIsRunning(simulation.alpha() > simulation.alphaMin());\n });\n\n simulation.on('end', () => {\n setIsRunning(false);\n });\n\n // Cleanup on unmount\n return () => {\n simulation.stop();\n };\n }, [\n initialNodes,\n initialLinks,\n chargeStrength,\n linkDistance,\n linkStrength,\n collisionStrength,\n collisionRadius,\n centerStrength,\n width,\n height,\n alphaDecay,\n velocityDecay,\n ]);\n\n const restart = () => {\n if (simulationRef.current) {\n simulationRef.current.alpha(1).restart();\n setIsRunning(true);\n }\n };\n\n const stop = () => {\n if (simulationRef.current) {\n simulationRef.current.stop();\n setIsRunning(false);\n }\n };\n\n return {\n nodes,\n links,\n restart,\n stop,\n isRunning,\n alpha,\n };\n}\n\n/**\n * Hook for creating a draggable force simulation\n * Provides drag handlers that can be attached to node elements\n *\n * @param simulation - The d3 force simulation instance\n * @returns Drag behavior that can be applied to nodes\n *\n * @example\n * ```tsx\n * function DraggableNetworkGraph() {\n * const simulation = useRef<d3.Simulation<SimulationNode, SimulationLink>>();\n * const drag = useDrag(simulation.current);\n *\n * return (\n * <svg>\n * {nodes.map((node) => (\n * <circle\n * key={node.id}\n * {...drag}\n * cx={node.x}\n * cy={node.y}\n * r={10}\n * />\n * ))}\n * </svg>\n * );\n * }\n * ```\n */\nexport function useDrag(simulation: d3.Simulation<SimulationNode, any> | null | undefined) {\n const dragStarted = (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0.3).restart();\n node.fx = node.x;\n node.fy = node.y;\n };\n\n const dragged = (event: any, node: SimulationNode) => {\n node.fx = event.x;\n node.fy = event.y;\n };\n\n const dragEnded = (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0);\n node.fx = null;\n node.fy = null;\n };\n\n return {\n onDragStart: dragStarted,\n onDrag: dragged,\n onDragEnd: dragEnded,\n };\n}"]}
1
+ {"version":3,"sources":["../../src/hooks/useForceSimulation.ts"],"names":[],"mappings":";;;;AA2KO,SAAS,kBAAA,CACd,YAAA,EACA,YAAA,EACA,OAAA,EAC6E;AAC7E,EAAA,MAAM;AAAA,IACJ,cAAA,GAAiB,IAAA;AAAA,IACjB,YAAA,GAAe,GAAA;AAAA,IACf,YAAA,GAAe,CAAA;AAAA,IACf,iBAAA,GAAoB,CAAA;AAAA,IACpB,eAAA,GAAkB,EAAA;AAAA,IAClB,cAAA,GAAiB,GAAA;AAAA,IACjB,KAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA,GAAa,MAAA;AAAA,IACb,aAAA,GAAgB,GAAA;AAAA,IAChB;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAA2B,YAAY,CAAA;AACjE,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GA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,IACA,OAAA;AAAA,IACA,IAAA;AAAA,IACA,SAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF;AA+BO,SAAS,QAAQ,UAAA,EAAmE;AACzF,EAAA,MAAM,WAAA,GAAc,CAAC,KAAA,EAAY,IAAA,KAAyB;AACxD,IAAA,IAAI,CAAC,UAAA,EAAY;AACjB,IAAA,IAAI,CAAC,KAAA,CAAM,MAAA,aAAmB,WAAA,CAAY,GAAG,EAAE,OAAA,EAAQ;AACvD,IAAA,IAAA,CAAK,KAAK,IAAA,CAAK,CAAA;AACf,IAAA,IAAA,CAAK,KAAK,IAAA,CAAK,CAAA;AAAA,EACjB,CAAA;AAEA,EAAA,MAAM,OAAA,GAAU,CAAC,KAAA,EAAY,IAAA,KAAyB;AACpD,IAAA,IAAA,CAAK,KAAK,KAAA,CAAM,CAAA;AAChB,IAAA,IAAA,CAAK,KAAK,KAAA,CAAM,CAAA;AAAA,EAClB,CAAA;AAEA,EAAA,MAAM,SAAA,GAAY,CAAC,KAAA,EAAY,IAAA,KAAyB;AACtD,IAAA,IAAI,CAAC,UAAA,EAAY;AACjB,IAAA,IAAI,CAAC,KAAA,CAAM,MAAA,EAAQ,UAAA,CAAW,YAAY,CAAC,CAAA;AAC3C,IAAA,IAAA,CAAK,EAAA,GAAK,IAAA;AACV,IAAA,IAAA,CAAK,EAAA,GAAK,IAAA;AAAA,EACZ,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,WAAA;AAAA,IACb,MAAA,EAAQ,OAAA;AAAA,IACR,SAAA,EAAW;AAAA,GACb;AACF","file":"useForceSimulation.js","sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport * as d3 from 'd3';\n\nexport interface SimulationNode extends d3.SimulationNodeDatum {\n id: string;\n [key: string]: any;\n}\n\nexport interface SimulationLink extends d3.SimulationLinkDatum<SimulationNode> {\n source: string | SimulationNode;\n target: string | SimulationNode;\n [key: string]: any;\n}\n\nexport interface ForceSimulationOptions {\n /**\n * Strength of the charge force (repulsion between nodes)\n * @default -300\n */\n chargeStrength?: number;\n\n /**\n * Distance for links between nodes\n * @default 100\n */\n linkDistance?: number;\n\n /**\n * Strength of the link force\n * @default 1\n */\n linkStrength?: number;\n\n /**\n * Strength of collision detection\n * @default 1\n */\n collisionStrength?: number;\n\n /**\n * Radius for collision detection (node size)\n * @default 10\n */\n collisionRadius?: number;\n\n /**\n * Strength of centering force\n * @default 0.1\n */\n centerStrength?: number;\n\n /**\n * Width of the simulation space\n */\n width: number;\n\n /**\n * Height of the simulation space\n */\n height: number;\n\n /**\n * Alpha decay rate (how quickly the simulation cools down)\n * @default 0.0228\n */\n alphaDecay?: number;\n\n /**\n * Velocity decay (friction)\n * @default 0.4\n */\n velocityDecay?: number;\n\n /**\n * Optional tick callback invoked on each simulation tick with current nodes/links and the simulation instance\n */\n onTick?: (nodes: SimulationNode[], links: SimulationLink[], sim: d3.Simulation<SimulationNode, SimulationLink>) => void;\n}\n\nexport interface UseForceSimulationReturn {\n /**\n * Current nodes with positions\n */\n nodes: SimulationNode[];\n\n /**\n * Current links\n */\n links: SimulationLink[];\n\n /**\n * Restart the simulation\n */\n restart: () => void;\n\n /**\n * Stop the simulation\n */\n stop: () => void;\n\n /**\n * Whether the simulation is currently running\n */\n isRunning: boolean;\n\n /**\n * Current alpha value (simulation heat)\n */\n alpha: number;\n}\n\n/**\n * Hook for managing d3-force simulations\n * Automatically handles simulation lifecycle, tick updates, and cleanup\n *\n * @param initialNodes - Initial nodes for the simulation\n * @param initialLinks - Initial links for the simulation\n * @param options - Configuration options for the force simulation\n * @returns Simulation state and control functions\n *\n * @example\n * ```tsx\n * function NetworkGraph() {\n * const nodes = [\n * { id: 'node1', name: 'Node 1' },\n * { id: 'node2', name: 'Node 2' },\n * { id: 'node3', name: 'Node 3' },\n * ];\n *\n * const links = [\n * { source: 'node1', target: 'node2' },\n * { source: 'node2', target: 'node3' },\n * ];\n *\n * const { nodes: simulatedNodes, links: simulatedLinks, restart } = useForceSimulation(\n * nodes,\n * links,\n * {\n * width: 800,\n * height: 600,\n * chargeStrength: -500,\n * linkDistance: 150,\n * }\n * );\n *\n * return (\n * <svg width={800} height={600}>\n * {simulatedLinks.map((link, i) => (\n * <line\n * key={i}\n * x1={(link.source as SimulationNode).x}\n * y1={(link.source as SimulationNode).y}\n * x2={(link.target as SimulationNode).x}\n * y2={(link.target as SimulationNode).y}\n * stroke=\"#999\"\n * />\n * ))}\n * {simulatedNodes.map((node) => (\n * <circle\n * key={node.id}\n * cx={node.x}\n * cy={node.y}\n * r={10}\n * fill=\"#69b3a2\"\n * />\n * ))}\n * </svg>\n * );\n * }\n * ```\n */\nexport function useForceSimulation(\n initialNodes: SimulationNode[],\n initialLinks: SimulationLink[],\n options: ForceSimulationOptions\n): UseForceSimulationReturn & { setForcesEnabled: (enabled: boolean) => void } {\n const {\n chargeStrength = -300,\n linkDistance = 100,\n linkStrength = 1,\n collisionStrength = 1,\n collisionRadius = 10,\n centerStrength = 0.1,\n width,\n height,\n alphaDecay = 0.0228,\n velocityDecay = 0.4,\n onTick,\n } = options;\n\n const [nodes, setNodes] = useState<SimulationNode[]>(initialNodes);\n const [links, setLinks] = useState<SimulationLink[]>(initialLinks);\n const [isRunning, setIsRunning] = useState(false);\n const [alpha, setAlpha] = useState(1);\n\n const simulationRef = useRef<d3.Simulation<SimulationNode, SimulationLink> | null>(null);\n\n useEffect(() => {\n // Create a copy of nodes and links to avoid mutating the original data\n const nodesCopy = initialNodes.map((node) => ({ ...node }));\n const linksCopy = initialLinks.map((link) => ({ ...link }));\n\n // Create the simulation\n const simulation = d3\n .forceSimulation<SimulationNode>(nodesCopy)\n .force(\n 'link',\n d3\n .forceLink<SimulationNode, SimulationLink>(linksCopy)\n .id((d) => d.id)\n .distance((d: any) => (d && d.distance != null ? d.distance : linkDistance))\n .strength(linkStrength)\n )\n .force('charge', d3.forceManyBody().strength(chargeStrength))\n .force('center', d3.forceCenter(width / 2, height / 2).strength(centerStrength))\n .force(\n 'collision',\n d3\n .forceCollide<SimulationNode>()\n .radius((d: any) => {\n // Use node-specific size when available and add configured padding to ensure minimum spacing\n const nodeSize = (d && d.size) ? d.size : 10;\n return nodeSize + collisionRadius;\n })\n .strength(collisionStrength)\n )\n .alphaDecay(alphaDecay)\n .velocityDecay(velocityDecay);\n\n simulationRef.current = simulation;\n\n // Update state on each tick\n simulation.on('tick', () => {\n try {\n if (typeof onTick === 'function') onTick(nodesCopy, linksCopy, simulation);\n } catch (e) {\n // ignore user tick errors\n }\n setNodes([...nodesCopy]);\n setLinks([...linksCopy]);\n setAlpha(simulation.alpha());\n setIsRunning(simulation.alpha() > simulation.alphaMin());\n });\n\n simulation.on('end', () => {\n setIsRunning(false);\n });\n\n // Cleanup on unmount\n return () => {\n simulation.stop();\n };\n }, [\n initialNodes,\n initialLinks,\n chargeStrength,\n linkDistance,\n linkStrength,\n collisionStrength,\n collisionRadius,\n centerStrength,\n width,\n height,\n alphaDecay,\n velocityDecay,\n onTick,\n ]);\n\n const restart = () => {\n if (simulationRef.current) {\n simulationRef.current.alpha(1).restart();\n setIsRunning(true);\n }\n };\n\n const stop = () => {\n if (simulationRef.current) {\n simulationRef.current.stop();\n setIsRunning(false);\n }\n };\n\n const originalForcesRef = useRef({ charge: chargeStrength, link: linkStrength, collision: collisionStrength });\n const forcesEnabledRef = useRef(true);\n\n const setForcesEnabled = (enabled: boolean) => {\n const sim = simulationRef.current;\n if (!sim) return;\n // avoid repeated updates\n if (forcesEnabledRef.current === enabled) return;\n forcesEnabledRef.current = enabled;\n\n try {\n // Only toggle charge and link forces to avoid collapse; keep collision/centering\n const charge: any = sim.force('charge');\n if (charge && typeof charge.strength === 'function') {\n charge.strength(enabled ? originalForcesRef.current.charge : 0);\n }\n\n const link: any = sim.force('link');\n if (link && typeof link.strength === 'function') {\n link.strength(enabled ? originalForcesRef.current.link : 0);\n }\n } catch (e) {\n // ignore\n }\n };\n\n return {\n nodes,\n links,\n restart,\n stop,\n isRunning,\n alpha,\n setForcesEnabled,\n };\n}\n\n/**\n * Hook for creating a draggable force simulation\n * Provides drag handlers that can be attached to node elements\n *\n * @param simulation - The d3 force simulation instance\n * @returns Drag behavior that can be applied to nodes\n *\n * @example\n * ```tsx\n * function DraggableNetworkGraph() {\n * const simulation = useRef<d3.Simulation<SimulationNode, SimulationLink>>();\n * const drag = useDrag(simulation.current);\n *\n * return (\n * <svg>\n * {nodes.map((node) => (\n * <circle\n * key={node.id}\n * {...drag}\n * cx={node.x}\n * cy={node.y}\n * r={10}\n * />\n * ))}\n * </svg>\n * );\n * }\n * ```\n */\nexport function useDrag(simulation: d3.Simulation<SimulationNode, any> | null | undefined) {\n const dragStarted = (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0.3).restart();\n node.fx = node.x;\n node.fy = node.y;\n };\n\n const dragged = (event: any, node: SimulationNode) => {\n node.fx = event.x;\n node.fy = event.y;\n };\n\n const dragEnded = (event: any, node: SimulationNode) => {\n if (!simulation) return;\n if (!event.active) simulation.alphaTarget(0);\n node.fx = null;\n node.fy = null;\n };\n\n return {\n onDragStart: dragStarted,\n onDrag: dragged,\n onDragEnd: dragEnded,\n };\n}"]}
package/dist/index.d.ts CHANGED
@@ -19,9 +19,28 @@ export { useDebounce } from './hooks/useDebounce.js';
19
19
  export { useD3, useD3WithResize } from './hooks/useD3.js';
20
20
  export { ForceSimulationOptions, SimulationLink, SimulationNode, UseForceSimulationReturn, useDrag, useForceSimulation } from './hooks/useForceSimulation.js';
21
21
  export { ForceDirectedGraph, ForceDirectedGraphProps, GraphLink, GraphNode } from './charts/ForceDirectedGraph.js';
22
+ import React__default from 'react';
22
23
  import 'class-variance-authority/types';
23
- import 'react';
24
24
  import 'class-variance-authority';
25
25
  import 'react/jsx-runtime';
26
26
  import 'clsx';
27
27
  import 'd3';
28
+
29
+ interface GraphControlsProps {
30
+ dragEnabled?: boolean;
31
+ onDragToggle?: (enabled: boolean) => void;
32
+ manualLayout?: boolean;
33
+ onManualLayoutToggle?: (enabled: boolean) => void;
34
+ onPinAll?: () => void;
35
+ onUnpinAll?: () => void;
36
+ onReset?: () => void;
37
+ onFitView?: () => void;
38
+ pinnedCount?: number;
39
+ totalNodes?: number;
40
+ visible?: boolean;
41
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
42
+ className?: string;
43
+ }
44
+ declare const GraphControls: React__default.FC<GraphControlsProps>;
45
+
46
+ export { GraphControls, type GraphControlsProps };