react-force-directed-graph
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

d3.js force directed graph implementation using React

types

import { SimulationNodeDatum } from 'd3';
import { CSSProperties } from 'react';

export type ID = number;

export type NodeType = string;
export type LinkType = string;

export type NodeAction = {
  title: string;
  icon: string;
  action: (node: Node) => void;
};

export type Node = {
  id: ID;
  name: string;
  type: NodeType;
  actions?: NodeAction[];
  image?: string;
  css?: CSSProperties;
  nodeRadius?: number;
  props?: Record<string, unknown>;
} & SimulationNodeDatum;

export type Link = {
  id: ID;
  source: ID | Node;
  target: ID | Node;
  type: LinkType;
  css?: CSSProperties;
  props?: Record<string, unknown>;
};


export interface ForceDirectedGraphProps {
  nodes: Node[];
  links: Link[];
  nodeRadius?: number;
  fontSize?: number;
  useZoom?: boolean;
}

usage

    import { ForceDirectedGraph, Link, Node } from 'react-force-directed-graph';

    ...
    ...

    const [nodes, setNodes] = useState<Node[]>([]);
    const [links, setLinks] = useState<Link[]>([]);

    <ForceDirectedGraph links={links} nodes={nodes} />

Check the demo app for more complete examples

Screenshot 2023-06-27 at 00 15 20

Package Sidebar

Install

npm i react-force-directed-graph

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

106 kB

Total Files

17

Last publish

Collaborators

  • unixxx