1.0.1 • Published 11 months ago

react-force-directed-graph v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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

1.0.1

11 months ago

1.0.0

11 months ago