Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-d3-graph

danielcaldas53.5kMIT2.6.0TypeScript support: definitely-typed

React component to build interactive and configurable graphs with d3 effortlessly

d3-visualization, d3js, graphs, javascript, networks, react, social-network-analysis, social-network-graph, visualization

readme

react-d3-graph · Build Status

npm version npm npm probot enabled code style: prettier

:book: Documentation

Interactive and configurable graphs with react and d3 effortlessly

react-d3-graph gif sample

Playground

Here a live playground page where you can interactively config your own graph, and generate a ready to use configuration! :sunglasses:

You can also load different data sets and configurations via URL query parameter. Below is a table with all the data sets available in the live sandbox for you to interactively explore different kinds of integrations with the library.

Name Link Source Description
small demo sandbox/data/small This is a good example to get you started. It has only 4 nodes. It's good to discuss over integration details and it's also good to report issues that you might found in the library. It's much easier to debug over a tiny graph.
custom demo sandbox/data/custom-node In this example you'll be able to see the power of the feature node.viewGenerator to create highly customizable nodes for you graph that go beyond the simple shapes that come out of the box with the library.
marvel demo sandbox/data/marvel In this thematic example you can see how several features such as: nodeHighlightBehavior, custom SVGs for nodes, collapsible etc. come together on top of a directed graph that displays some characters from the Marvel Universe.
static demo sandbox/data/static If your goal is not to have nodes dancing around with the default d3 forces that the library provides, you can opt by making your nodes static and positioned them always in the same (x, y) coordinates. To achieve this you can make use of staticGraphWithDragAndDrop or staticGraph

Do you want to visualize your own data set on the live sandbox? Just submit a PR! You're welcome 😁.

Documentation :book:

Full documentation here.

Install

https://nodei.co/npm/YOUR-MODULE-NAME.png?downloads=true&downloadRank=true&stars=true

npm install d3@^5.5.0      # if you don't have d3 already
npm install react@^16.4.1  # if you don't have react already

npm install react-d3-graph

About react and d3 peer dependencies

Note that react and d3 are peer-dependencies, this means that the responsibility to install them is delegated to the client. This will give you more flexibility on what versions of d3 and react you want to consume, you just need to make sure that you are compliant with the range of versions that react-d3-graph is compatible with. If you install react-d3-graph without first installing d3 and react you might see the following warnings:

npm WARN react-d3-graph@2.0.1 requires a peer of d3@^5.5.0 but none is installed. You must install peer dependencies yourself. npm WARN react-d3-graph@2.0.1 requires a peer of react@^16.4.1 but none is installed. You must install peer dependencies yourself.

Minimal usage example

Graph component is the main component for react-d3-graph components, its interface allows its user to build the graph once the user provides the data, configuration (optional) and callback interactions (also optional). The code for the live example can be consulted here.

import { Graph } from "react-d3-graph";

// graph payload (with minimalist structure)
const data = {
  nodes: [{ id: "Harry" }, { id: "Sally" }, { id: "Alice" }],
  links: [
    { source: "Harry", target: "Sally" },
    { source: "Harry", target: "Alice" },
  ],
};

// the graph configuration, just override the ones you need
const myConfig = {
  nodeHighlightBehavior: true,
  node: {
    color: "lightgreen",
    size: 120,
    highlightStrokeColor: "blue",
  },
  link: {
    highlightColor: "lightblue",
  },
};

const onClickNode = function(nodeId) {
  window.alert(`Clicked node ${nodeId}`);
};

const onClickLink = function(source, target) {
  window.alert(`Clicked link between ${source} and ${target}`);
};

<Graph
  id="graph-id" // id is mandatory
  data={data}
  config={myConfig}
  onClickNode={onClickNode}
  onClickLink={onClickLink}
/>;

For more advanced use cases check the official documentation.

Core Team

The group of maintainers driving the project.

Daniel Caldas Sara Hernández Terahn Harrison Antonin Klopp-Tosser
danielcaldas LonelyPrincess terahn antonin
@_danielcaldas |

Contributions

Contributions are welcome, feel free to submit new ideas/features, just go ahead and open an issue. If you are more a hands on person, just submit a pull request. Before jumping into coding, please take a look at the contribution guidelines CONTRIBUTING.md.

To run react-d3-graph in development mode you just need to run npm run dev and the interactive sandbox will reload with the changes to the library code, that way you can test your changes not only through unit test but also through a real life example. It's that simple. The development workflow usually should follow the steps:

  • Create a branch prefixed with fix/ for bug fixes, feature/ for new features, chore/ or refactor/ for refactoring or tooling and CI/CD related tasks.
  • Make sure you are up to date running npm install.
  • Run npm run dev.
  • Make you changes inside the folder src and the interactive sandbox consumes your changes in real time with webpack-dev-server.
  • You can run tests locally with npm run test (for unit tests) or npm run functional:local for e2e tests.
  • After you're done, open the Pull Request and describe the changes you've made.

Alternatives (Not what you where looking for?)

Well if you scrolled this far maybe react-d3-graph does not fulfill all your requirements 😭, but don't worry I got you covered! There are a lot of different and good alternatives out there, here is a list with a few alternatives.

changelog

Changelog

2.6.0 (2020-12-18)

Full Changelog

Implemented enhancements:

  • Arrow color go out of sync with link color when link.color or link.highlightColor is updated #360
  • Error: react-d3-graph :: Graph :: you have not provided enough data for react-d3-graph to render something. You need to provide at least one node #347
  • get x, y and other node informations with event onMouseOverNode() #306
  • Arrows don't point to nodes as expected #265
  • feature: expose node information to node related callbacks #385 (LonelyPrincess)
  • Don't throw error when there are no nodes #381 (LonelyPrincess)

Fixed bugs:

  • Some properties make the graph becomes unresetable #372
  • Node does not move/update when given coordinates or new coordinates #295

Closed issues:

  • Bendable links #373
  • High res pdf #356
  • Rendering graph with initial node positions doesn't properly place nodes without links #350
  • Enhance control on links appearance - support dashed links #343
  • Error when attempting to drag custom nodes #338
  • fontSize parameter should be working for single node #330
  • Adding the ability to completely freeze the graph #308

Merged pull requests:

2.5.0

Full Changelog

Implemented enhancements:

  • make node.size accept both height and width #336

Fixed bugs:

  • Passing an empty data.links array throws a warning #323
  • renderLabel params are not working for single node #322
  • The release version does not contain some fixes #314

Closed issues:

  • Docs missing collapsible sandbox example #337
  • Multiple Edges between 2 nodes #335
  • Ability to display node labels in different positions relative to the node center #299

Merged pull requests:

2.4.1

Full Changelog

Special announcement:

Implemented enhancements:

  • Make link end marker's width and height configurable #238
  • Avoid flashing graph when drag&drop node #237
  • Make node.renderLabel available at node level #192

Sandbox & Documentation

  • Anchored links per each configuration property starting on version 2.4.0
  • Deleting node is sandbox breaks the demo if the number of nodes reaches 0 #287

Fixed bugs:

  • Collapsible node with no links errors out on click #292
  • Deleting node is sandbox breaks the demo if the number of nodes reaches 0 #287
  • onNodePositionChange doesn't always trigger #264
  • Custom node example is not loading on the sandbox #252
  • Not passing data.links breaks the library while it should throw a custom error #211

Closed issues:

  • automaticRearrangeAfterDropNode - play button from live demo #261
  • Improve live example by replacing all window.alerts by toasts or other non blocking alerts #241
  • Add tooltips to sandbox playground configs #239
  • Make use of jest .toMatchSnapshot in library unit tests #236
  • link.type only can make effect in global #234
  • Node drag and drop methods #204

Merged pull requests:

2.4.0

⚠️ This distribution is not valid, it not up to date with the changes described in its previous CHANGELOG.md. Please use version 2.4.1 of this library instead. Issue reported in The release version does not contain some fixes #314.

2.3.0

Full Changelog

Merged pull requests:

2.2.0

Full Changelog

Fixed bugs:

  • Drag&Drop does not work for leaf nodes after collapsing and "uncollapsing" #223
  • [Sandbox] Fail to remove links / nodes in the live demo example #212
  • Error clicking nodes composed of mdi-react icons #201

Closed issues:

  • link.renderLabel is not true by default #210
  • onDoubleClickNode #194

Merged pull requests:

Chore:

2.1.0

Full Changelog

Fixed bugs:

  • When using an icon from mdi-react in a node, clicking the node throws an error. #201

New features:

  • onDoubleClickNode #194

2.0.2

Full Changelog

Fixed bugs:

  • Delete (remove) nodes and links from graph #183

Closed issues:

  • Is there a way to make the graph render consistently? #193
  • Addition to readme #190

Merged pull requests:

2.0.1

Full Changelog

Fixed bugs:

2.0.0

Full Changelog

Fixed bugs:

  • Link Colors not used when adding to graph #169
  • Node id 0 not set properly #160
  • Nodes added or deleted from a graph with nodes in fixed positions will cause issues #151
  • Collapsible config option can cause orphaned nodes to not be displayed #129

Closed issues:

  • Reverse the direction of arrows for "directed" property #153
  • viewGenerator key being dropped in config merge #142
  • Links labeling #47

Merged pull requests:

2.0.0-rc2

Full Changelog

Implemented enhancements:

  • Allow nodes to override strokeColor #122

Fixed bugs:

  • Custom onNodeClick handler not triggering on collapsible nodes #136
  • 🐛 Global viewGenerator not been applied to the nodes #130

Closed issues:

  • graph constantly re-rendering even when app is idle? #145
  • Allow users to pass in a function in node.labelProperty #133
  • Drop yarn support for development (stick to npm only) #127
  • Link mouse cursor property #119
  • Center graph on a specific node #102
  • Links with directional arrow #88

Merged pull requests:

2.0.0-rc1

Full Changelog

Closed issues:

  • i want to customise node. is it possible ? #90

Merged pull requests:

2.0.0-rc0

Full Changelog

Implemented enhancements:

  • Directional links are placed on top of each other #89

Fixed bugs:

  • Error re-rendering Graph when no config prop is set #81

Merged pull requests:

1.3.0 (2018-06-25)

NOTE: This release contains only PR #79 cherry picked from master.

Full Changelog

Merged pull requests:

  • Customize color for a link #79

1.2.2 (2018-05-14)

NOTE: This release contains only some minor fixes picked from master. Out of scope of this relase is PR Fix/peer dependencies #70 where react and d3 will pass to the peerDependencies block breaking installs that do not meet the restrictions of react and d3 versions.

Full Changelog

Fixed bugs:

  • BUG: NO LINK GETS HIGHLIGHTED WHEN NODE ID IS NON-STIRNG #73 props to @iamhosseindhv for reporting

Closed issues:

  • can the graph nodes and line not stacked #58
  • custom add node button #57
  • labelProperty not implemented? #54
  • BUG: NO LINK GETS HIGHLIGHTED WHEN NODE ID IS NON-STIRNG #73

Merged pull requests:

  • Fix/mouse over link highlight #75
  • Fix/link highlight id number #74
  • Feature/move to node 8.11.0 #72
  • Refactor/links build #69

1.2.1 (2018-04-22)

Full Changelog

Closed issues:

  • 100% Width/Height of parent element #63
  • SVG image for node #36

Merged pull requests:

  • Move logic from graph component (highlight updates) #66 (danielcaldas)
  • Feature/update dependencies #65 (danielcaldas)
  • Add fontColor as a configuration option for node's <text> fill property #64 (dmmulroy)

1.2.0 (2018-04-01)

Full Changelog

Implemented enhancements:

  • Graph Rerendering #51

Fixed bugs:

  • Graph Rerendering #51

Merged pull requests:

1.0.1 (2018-02-18)

Full Changelog

Fixed bugs:

  • Click one node but another one moves #41

Merged pull requests:

1.0.0 (2017-12-02)

Full Changelog

Closed issues:

  • How can I get onMouseOverLink event? #25

Merged pull requests:

0.4.0 (2017-11-11)

Full Changelog

Implemented enhancements:

  • Node version #29

Merged pull requests:

0.3.0 (2017-10-21)

Full Changelog

Implemented enhancements:

  • Squeezing if "staticGraph": true #24

Fixed bugs:

  • Squeezing if "staticGraph": true #24

Merged pull requests:

0.2.1 (2017-09-17)

Full Changelog

Merged pull requests:

0.2.0 (2017-09-16)

Full Changelog

Merged pull requests:

0.1.0 (2017-08-05)

Full Changelog

Implemented enhancements:

  • Adding nodes? #7

Merged pull requests:

0.0.2 (2017-04-25)

Full Changelog

0.0.1 (2017-04-25)

Merged pull requests:

* This Change Log was automatically generated by [githubchangelog_generator](https://github.com/skywinder/Github-Changelog-Generator)_

* This Changelog was automatically generated by [githubchangelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)_