1.1.7 • Published 4 years ago

react-graph-visualizer v1.1.7

Weekly downloads
12
License
MIT
Repository
github
Last release
4 years ago

react-graph-visualizer

a react component to visualize interactive directed and weighted graphs easily.

NPM JavaScript Style Guide

Install

npm install --save react-graph-visualizer

Examples

1. Demo

the Demo contains five code examples with their results.

2. The debt settler app

Alt Text

the Debt settler is react app made using the react-graph-visualizer.

Usage

import React, { useState, useRef } from "react";
import Graph from "react-graph-visualizer";

function App() {
  const graphRef = useRef();
  const [graph, setGraph] = useState({
    nodes: [
      {
        name: "A",
        id: 1
      },
      {
        name: "B",
        id: 2
      }
    ],
    links: [
      {
        source: 1,
        target: 2,
        label: "A-B"
      }
    ]
  });
  return (
    <Graph
      ref={graphRef}
      initialGraph={graph}
      width={850}
      height={450}
      backgroundColor={"white"}
    />
  );
}

export default App;

to change the graph data call the function setGraph as follow.

graphRef.current.setGraph(newGraphData);

API

PropTypeDefaultDescription
idstring/component id, required when using multiple component in the same page.
initialGraphobject{nodes:[],links:[]}Graph initial data
initialGraph.nodesArray[]The nodes array of objects {name:string, id:number, img=string}
initialGraph.linksArray[]The links array of objects {source:number, target:number, label:string}
widthnumber700the vertical length of the component.
heightnumber500the horizontal length of the component.
refRef object/The ref object to use to change graph data.
backgroundColorstring#e5e6e7The component background color.
linkStyle.directedbooleantrueSpecifies the type of the graph, directed or undirected.
linkStyle.distancenumber300The length of the links, or the distance between the nodes.
linkStyle.colorstringblackLinks color: "red", "orange", "#000", "#e5e6e7"
nodeStyle.radiusnumber30The radius of nodes.
nodeStyle.borderWidthnumber0The width of the nodes borders.
nodeStyle.borderColorstringblackThe color of the nodes border.
nodeStyle.backgroundstringblackThe color of the nodes background.
nameStyle.sizenumber20The size of the nodes name.
nameStyle.colorstringblackThe nodes name color
nameStyle.xstringcenterThe horizontal position of the nodes name: left, right, center.
nameStyle.ystringbottomThe vertical position of the nodes name: bottom, top.
labelStyle.showbooleanfalseShow or hide labels.
labelStyle.sizenumber10The size of the labels.
labelStyle.colorstringblackThe color of the labels

Contribution

  1. npm install
  2. cd example && npm install
  3. npm start
  4. cd example && npm startin a diffrent terminal.

License

MIT © NadirTellai

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.1

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago