Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering graph with initial node positions doesn't properly place nodes without links #350

Closed
TranquilMarmot opened this issue Jul 18, 2020 · 0 comments · Fixed by #353
Closed

Comments

@TranquilMarmot
Copy link
Contributor

TranquilMarmot commented Jul 18, 2020

Describe the bug
When rendering the graph and giving nodes initial positions via x/y, if a node does not have any links it will not be properly placed in the graph.

To Reproduce

Here's a minimal repo:

import React, { Component } from "react";
import { Graph } from "react-d3-graph";
import "./App.css";

class App extends Component {
  render() {
    const data = {
      nodes: [
        {
          id: "node-1",
          fx: 100,
          fy: 100
        },
        {
          id: "node-2",
          fx: 200,
          fy: 200
        },
        {
          id: "node-3",
          fx: 300,
          fy: 300
        }
      ],
      links: [
        {
          source: "node-1",
          target: "node-2"
        }
      ]
    };

    const config = {
      width: 2000,
      height: 2000
    };

    return (
      <div className="App">
        <Graph id="my-graph" data={data} config={config} />
      </div>
    );
  }
}

export default App;

I also have this in a code sandbox: https://codesandbox.io/s/create-react-app-7ozk6?file=/src/App.js

You'll notice that node-1 and node-2 are placed properly, but node-3 is placed at 0,0.

Adding i.e. { source: "node-2", target: "node-3" } to the links array will cause node-3 to be properly placed.

Expected behavior
Nodes that have x/y coordinates should always be placed in the right spot when rendering even if they don't have links.

Screenshots

Without links:
image

With links:
image

Environment:

  • OS: Windows, Ubuntu
  • Browser: Chrome, Firefox
  • Version: Chrome 78, Firefox 79
  • Node version: v12.13.0
  • react-d3-graph version: 2.5.0
  • d3 version: Whatever comes along with react-d3-graph
  • react version: 16.13.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant