Git Product home page Git Product logo

react-graph-network's Introduction

React component for rendering svg graph based on d3-force with zoom, node dragging and other preferences.

Usage

Simple case

simple-case

import React from 'react';
import Graph from 'react-graph-network';

const data = {
  nodes: [
    {id: "HkqEDLvxE"},
    {id: "011jVS4rb"},
    {id: "PXACjDxmR"},
    {id: "kuVISwh7w"},
    {id: "UIEjvLJMd"},
    {id: "ZVi8fWDBx"},
    {id: "H-06WvsfJ"},
    {id: "Fbc9iwnJl"},
  ],
  links: [
    {"source": "HkqEDLvxE", "target": "011jVS4rb"},
    {"source": "011jVS4rb", "target": "PXACjDxmR"},
    {"source": "PXACjDxmR", "target": "kuVISwh7w"},
    {"source": "PXACjDxmR", "target": "Fbc9iwnJl"},
    {"source": "PXACjDxmR", "target": "UIEjvLJMd"},
    {"source": "kuVISwh7w", "target": "UIEjvLJMd"},
    {"source": "UIEjvLJMd", "target": "ZVi8fWDBx"},
    {"source": "ZVi8fWDBx", "target": "H-06WvsfJ"},
    {"source": "H-06WvsfJ", "target": "Fbc9iwnJl"}
  ]
};

const App = () => (
  <div style={{ height: '100vh' }}>
    <Graph data={data} id="graph" />
  </div>
);

export default App;

Advanced case

Try different preferences on demo page with Leo Tolstoy family tree data.

Props

Name Type Default Description
data object Must have links and nodes props. Each node must have id prop. Each link must have source and target props with id as values.
id string GraphTree_container Provide id if you need more than 1 graph.
nodeDistance number 100 The more value is, the more is distance between nodes.
NodeComponent node Has to be svg element. Will receive concrete node prop from your data.
LineComponent node Has to be <line /> tag. Will receive concrete link prop from your data as id and as object it point to.
enableDrag bool false Enable nodes dragging.
pullIn bool false When enableDrag, stretch nodes back.
zoomDepth number 0 Zooming on scroll wheel. 1 will just enable dragging graph area.
hoverOpacity number 1 When hover on node all other nodes will have this value as opacity. Needs to be from 0 to 1.

LineComponent

You need to apply all rest props on your <line> tag. If you have specific logic in your Line component be sure to handle link prop both as id and object. See details and example on demo project.

data example

const data = {
    nodes: [
        {id: "HkqEDLvxE"},
        {id: "011jVS4rb"},
        {id: "PXACjDxmR"},
        {id: "kuVISwh7w"},
    ],
    links: [
        {"source": "HkqEDLvxE", "target": "011jVS4rb"},
        {"source": "HkqEDLvxE", "target": "PXACjDxmR"},
        {"source": "kuVISwh7w", "target": "011jVS4rb"},
        {"source": "kuVISwh7w", "target": "PXACjDxmR"},
        {"source": "011jVS4rb", "target": "PXACjDxmR"}
    ]
};

react-graph-network's People

Contributors

alyonashadrina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-graph-network's Issues

Resizing Problem

After feeding in data, the result is in the form of an svg file which cannot be resized. So even if I increase/decrease the outer box, the graph doesnt resize. Doesnt even change its position. It overflows and becomes invisible after decreasing the outer div beyond a point. I tried using custom css also but its not working. I have given width and height both as 100% but still its not working. On inspecting I saw that the svg is taking 100% width and height but inside is overflowing out of the div. The svg file is buggy. Ideally all contents should be INSIDE the but here its not.

Several graph

Hello, i want to ask about how i can to display several graph? When i display one graph everything work correct, but when i display tow graph and more it displaying one graph. I think it connected with id graph , how i can resolve this problem?

<Graph data={dataFromDB} LineComponent={LineGraph} NodeComponent={Node} style={{height: '100%', width: '100%'}} nodeDistance={getNodeDistance()} zoomDepth={3} hoverOpacity={0.3} enableDrag={false} pullIn={false} />

Move node of the graph

Hello. I want to ask how i can to control move the graph. I mean i want the graph not went beyond the borders. I want to know coordinates the moving node. How can i do it? Thank you

onClick event

Is there any way to add some kind of event listener on nodes?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.