Giter Club home page Giter Club logo

Comments (3)

davelandry avatar davelandry commented on July 4, 2024

@AlmahaAlmalki thank you for the kind words! glad you're enjoying using d3plus 😄

This is actually intended behavior, because internally there's no way to know if the integer passed as the source/target is an index or an actual ids (because ids can be integers). The value for source and target need to either be the index of the node in the nodes array, or the actual node itself! For example, you could transform your links array like this:

const methods = {
  links:  [
    {source: 'alpha', target: 'beta'},
    {source: 'alpha', target: 'gamma'},
    {source: 'epsilon', target: 'zeta'},
    {source: 'epsilon', target: 'theta'},
    {source: 'theta', target: 'alpha'}
  ] ,
  nodes:  [
    {id: 'alpha',   x: 1,   y: 1},
    {id: 'beta',    x: 2,   y: 1},
    {id: 'gamma',   x: 1,   y: 2},
    {id: 'epsilon', x: 3,   y: 2},
    {id: 'zeta',    x: 2.5, y: 1.5},
    {id: 'theta',   x: 2,   y: 2}
  ],
}

methods.links.forEach(function(link) {
  link.source = methods.nodes.filter(function(node) {
    return node.id === link.source;
  })[0];
  link.target = methods.nodes.filter(function(node) {
    return node.id === link.target;
  })[0];
});

Let me know if that doesn't work for you!

from d3plus-react.

AlmahaAlmalki avatar AlmahaAlmalki commented on July 4, 2024

Hi @davelandry

Thanks that makes a lot of sense, there's another issue with dynamic nodes position. However, I used d3 force layout to generate the positions dynamically. But, I was wondering if there's another way to set the x and y using d3plus only?

from d3plus-react.

davelandry avatar davelandry commented on July 4, 2024

@AlmahaAlmalki force-directed layouts have not been implemented in 2.0 yet: d3plus/d3plus-network#28

from d3plus-react.

Related Issues (20)

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.