Giter Site home page Giter Site logo

Comments (2)

kelemeno avatar kelemeno commented on July 17, 2024 1

Thanks this is great!

I will use the depthLayering method you provided, I have the height stored. (I don't think the first one will work, as I will not draw every edge of the tree, only a section of the tree. But I do want to keep the tree's layering. I also don't think it is compact).

And fortunately not a multigraph.

from d3-dag.

erikbrinkman avatar erikbrinkman commented on July 17, 2024

@kelemeno sorry for the late response!

  • If your tree is compact, e.g. all children are one height below their parents, then simplex should just do the right thing, and so should longestPath (the later being a little faster).
  • If it's not compact, you should be able to get away with just specifying ranks. It's still more computationally expensive than necessary, but it's the next easiest for your effort.
  • The fastest for large trees will be writing it yourself. If you look at the documentation for LayeringOperators it has a pretty simple requirement

    After calling a layering operator on a dag, every node's value should be set to a non-negative integer layer, starting at 0. Additionally children should have a strictly larger layer than their parents, and if a node has multiple links to the same child, it's layer should be at least two greater than its parent.
    If you had the depth stored in the node data you could use that with something like:

    function depthLayering(dag: Dag<{ myDepth: number }, unknown>): void {
        for (const node of dag) {
            node.value = node.data.myDepth;
        }
    }
    However, if you don't have the height stored, and want it purely in graph terms, then you should also be able to use height because that does exactly what you want.
    function depthLayering(dag: Dag<unknown, unknown>): void {
        dag.height();
    }
    Do note, that both of these implementation assume that you don't have a muultigraph, e.g. you can't have two edges between the same two nodes. Due to the way we layout multi-edges, we have to insert dummy layers, and these implementations don't do that.

from d3-dag.

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.