@sandeepsj0000/react-graph-visualizer 1.0.0

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.
@@ -0,0 +1,94 @@
1
+ export interface GraphNode {
2
+ id: string;
3
+ label?: string;
4
+ color?: string;
5
+ size?: number;
6
+ metadata?: Record<string, unknown>;
7
+ }
8
+ export interface GraphEdge {
9
+ source: string;
10
+ target: string;
11
+ label?: string;
12
+ weight?: number;
13
+ metadata?: Record<string, unknown>;
14
+ }
15
+ export interface GraphData {
16
+ nodes: GraphNode[];
17
+ edges: GraphEdge[];
18
+ directed?: boolean;
19
+ }
20
+ export interface GraphVisualizerProps {
21
+ data: GraphData;
22
+ width?: number;
23
+ height?: number;
24
+ /** Called when node selection changes */
25
+ onSelectionChange?: (selectedIds: string[], connectedIds: string[]) => void;
26
+ /** Custom node color (default: #4f46e5) */
27
+ nodeColor?: string;
28
+ /** Highlight color for selected/connected nodes (default: #f59e0b) */
29
+ highlightColor?: string;
30
+ /** Color for dimmed (non-selected) nodes (default: #d1d5db) */
31
+ dimColor?: string;
32
+ /** Color for inverted selection highlight (default: #ef4444) */
33
+ invertColor?: string;
34
+ /** Node radius (default: 20) */
35
+ nodeRadius?: number;
36
+ /** Show edge labels */
37
+ showEdgeLabels?: boolean;
38
+ /** Show edge direction arrows for directed graphs */
39
+ showArrows?: boolean;
40
+ /** Custom CSS class for the container */
41
+ className?: string;
42
+ }
43
+ export type SelectionMode = "connected" | "inverted" | "paths";
44
+ export interface PathResult {
45
+ /** Ordered array of node ids forming the path */
46
+ path: string[];
47
+ /** Ordered array of node labels forming the path */
48
+ labels: string[];
49
+ }
50
+ export interface NodeInfo {
51
+ id: string;
52
+ label: string;
53
+ metadata?: Record<string, unknown>;
54
+ /** Number of outgoing edges */
55
+ outDegree: number;
56
+ /** Number of incoming edges */
57
+ inDegree: number;
58
+ /** Total unique neighbors */
59
+ degree: number;
60
+ /** Nodes this node points to */
61
+ outgoingNeighbors: {
62
+ id: string;
63
+ label: string;
64
+ }[];
65
+ /** Nodes that point to this node */
66
+ incomingNeighbors: {
67
+ id: string;
68
+ label: string;
69
+ }[];
70
+ /** All unique neighbors */
71
+ allNeighbors: {
72
+ id: string;
73
+ label: string;
74
+ }[];
75
+ }
76
+ export interface GraphStats {
77
+ nodeCount: number;
78
+ edgeCount: number;
79
+ directed: boolean;
80
+ /** Edge density (0-1) */
81
+ density: number;
82
+ avgDegree: number;
83
+ maxDegree: number;
84
+ minDegree: number;
85
+ /** Number of weakly connected components */
86
+ connectedComponents: number;
87
+ /** Nodes with zero connections */
88
+ isolatedNodes: string[];
89
+ }
90
+ export interface SubgraphResult {
91
+ nodes: GraphNode[];
92
+ edges: GraphEdge[];
93
+ directed: boolean;
94
+ }
@@ -0,0 +1,82 @@
1
+ import { GraphData, PathResult, NodeInfo, GraphStats, SubgraphResult } from "./types";
2
+ import { GraphEngine } from "./graphEngine";
3
+ export interface UseGraphEngineReturn {
4
+ /** The underlying engine instance */
5
+ engine: GraphEngine;
6
+ /** Currently selected node ids */
7
+ selectedNodes: string[];
8
+ /** Select a single node (replaces selection) */
9
+ selectNode: (id: string) => void;
10
+ /** Toggle a node in/out of the multi-selection */
11
+ toggleNode: (id: string) => void;
12
+ /** Select multiple nodes at once */
13
+ selectNodes: (ids: string[]) => void;
14
+ /** Clear all selections */
15
+ clearSelection: () => void;
16
+ /** Nodes connected to the current selection */
17
+ connectedNodes: {
18
+ id: string;
19
+ label: string;
20
+ }[];
21
+ /** Nodes NOT connected to the current selection (inverted) */
22
+ invertedNodes: {
23
+ id: string;
24
+ label: string;
25
+ }[];
26
+ /** All paths between currently selected nodes (when 2+ selected) */
27
+ paths: PathResult[];
28
+ /** Get rich info about any node */
29
+ getNodeInfo: (id: string) => NodeInfo | null;
30
+ /** Find all paths between two nodes */
31
+ findAllPaths: (from: string, to: string, maxDepth?: number) => PathResult[];
32
+ /** Find shortest path between two nodes */
33
+ findShortestPath: (from: string, to: string) => PathResult | null;
34
+ /** Find all paths between multiple nodes */
35
+ findAllPathsBetweenMultiple: (ids: string[]) => PathResult[];
36
+ /** Check reachability */
37
+ areConnected: (from: string, to: string) => boolean;
38
+ /** Get the inverted selection for any node */
39
+ getInvertedSelection: (id: string) => {
40
+ id: string;
41
+ label: string;
42
+ }[];
43
+ /** Get connected nodes for any node */
44
+ getConnectedNodes: (id: string) => {
45
+ id: string;
46
+ label: string;
47
+ }[];
48
+ /** Extract a subgraph of specific node ids */
49
+ getSubgraph: (ids: string[]) => SubgraphResult;
50
+ /** Get a node's neighborhood subgraph */
51
+ getNeighborhoodSubgraph: (id: string) => SubgraphResult;
52
+ /** Get nodes ranked by degree */
53
+ getNodesByDegree: () => {
54
+ id: string;
55
+ label: string;
56
+ degree: number;
57
+ }[];
58
+ /** Get graph statistics */
59
+ getStats: () => GraphStats;
60
+ /** Serialize connected/inverted node list to CSV string */
61
+ toCSV: (nodes?: {
62
+ id: string;
63
+ label: string;
64
+ }[]) => string;
65
+ /** Serialize connected/inverted node list to JSON string */
66
+ toJSON: (nodes?: {
67
+ id: string;
68
+ label: string;
69
+ }[]) => string;
70
+ /** Serialize current paths to CSV string */
71
+ pathsToCSV: (paths?: PathResult[]) => string;
72
+ /** Serialize current paths to JSON string */
73
+ pathsToJSON: (paths?: PathResult[]) => string;
74
+ /** Export full graph as JSON string */
75
+ toGraphJSON: () => string;
76
+ }
77
+ /**
78
+ * React hook for headless graph operations.
79
+ * Provides all graph querying, selection state, and serialization
80
+ * without rendering any UI.
81
+ */
82
+ export declare function useGraphEngine(data: GraphData): UseGraphEngineReturn;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@sandeepsj0000/react-graph-visualizer",
3
+ "version": "1.0.0",
4
+ "description": "React component for interactive graph visualization with node selection, path finding, and export capabilities",
5
+ "main": "dist/index.cjs.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "rollup -c",
13
+ "dev": "rollup -c -w",
14
+ "demo": "vite demo",
15
+ "type-check": "tsc --noEmit",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "peerDependencies": {
19
+ "react": ">=17.0.0",
20
+ "react-dom": ">=17.0.0"
21
+ },
22
+ "devDependencies": {
23
+ "@rollup/plugin-commonjs": "^28.0.0",
24
+ "@rollup/plugin-node-resolve": "^16.0.0",
25
+ "@rollup/plugin-typescript": "^12.1.0",
26
+ "@types/d3": "^7.4.3",
27
+ "@types/react": "^18.2.0",
28
+ "@types/react-dom": "^18.2.0",
29
+ "react": "^18.2.0",
30
+ "react-dom": "^18.2.0",
31
+ "rollup": "^4.24.0",
32
+ "rollup-plugin-peer-deps-external": "^2.2.4",
33
+ "rollup-plugin-postcss": "^4.0.2",
34
+ "tslib": "^2.8.1",
35
+ "typescript": "^5.6.0",
36
+ "vite": "^6.0.0"
37
+ },
38
+ "dependencies": {
39
+ "d3": "^7.9.0"
40
+ },
41
+ "keywords": [
42
+ "react",
43
+ "graph",
44
+ "visualization",
45
+ "network",
46
+ "d3",
47
+ "directed-graph",
48
+ "path-finding",
49
+ "interactive"
50
+ ],
51
+ "license": "MIT",
52
+ "repository": {
53
+ "type": "git",
54
+ "url": ""
55
+ }
56
+ }