Giter Club home page Giter Club logo

Comments (8)

erikbrinkman avatar erikbrinkman commented on May 22, 2024 1

Okay, without padding, the nodeSize you define will be exactly how much space there is between things. i.e. if nodeSize = your actual node size, then everything will be touching instead of having space. This is apparently what d3-hierarchy does, and I guess that's a simpler api than also having padding, but it also seems unintuitive.

It shouldn't be too difficult to add this functionality in. Not sure when I'll get around to it.

from d3-dag.

erikbrinkman avatar erikbrinkman commented on May 22, 2024

I'm not sure entirely what you mean. Can you give an example of the overcrowding, or how you want the nodes to change?

The sugiyama layout is stacked, so every node that gets assigned to a layer must stay in the layer. If you want nodes to have more vertical room, you just need to space each layer out more. There's currently no way to offset nodes within a layer if they have different heights, although the Arquint layout does something like this if that's what you're interested in. If instead you're concerned about horizontal spacing, there is an option to adjust the spacing that nodes get via the separation function. This should allow you to gives nodes proportionally more or less space between them to account for their size. If too many nodes are getting put on the same layer causing that layer to get squished, then you could use the CoffmanGraham layout to limit the number of nodes on each layer. However, that doesn't account for the size of each node. Potentially the CoffmanGraham layering could be tweaked to take node "size" into account. If that's the route you want to go, I can advise on how to add the functionality and potentially submit a PR.

from d3-dag.

djknight1 avatar djknight1 commented on May 22, 2024

@erikbrinkman Thanks for answering! Actually, the node size I mean is more like 'layer size'.
I set sugiyama size to 1000 * 1000

private layout() {
    this.dagStratifyConstructor = dagStratify()(this.data);
    this.sugiyamaRoot = sugiyama()
      .coord(coordVert())
      .size([1000, 1000])

And then I use descendants() to create nodes, and append rect to each node.Setting the height to 50, alos drawing lines between them.
It works while node's count are not to large.However, if it increases to 10 - 11, the line and space between layer become tight.
So, I dont know it there a way to fix it. And it seems that separation doesn't solve this problem
My DAG is a simple one, it 's like two tree share one root from top to bottom.

Thanks again for your answer!

from d3-dag.

djknight1 avatar djknight1 commented on May 22, 2024

@erikbrinkman And in d3 there is a API called nodeSize, it solves this problem, that i dont need to fix the size of layout

from d3-dag.

erikbrinkman avatar erikbrinkman commented on May 22, 2024

Sorry for my lack of understanding. I'm not sure what you want. I'm guessing something like you set nodeSize and they layout is such that the nodes are always spaced apart? As I mentioned, this isn't really supported, but you can pretty easily mimic it.

The parameters specified in size are just multiplied by the values returned by the layout algorithm. If you want to change the height to always give appropriate spacing, then first compute the maximum layer after the layout, and then multiply the y coordinates by maxLayer * nodeHeight * 2 (the 2 sets the space between the nodes equal to the height of each node). separation would allow you to tweak the layout for nodes with different widths. You'd have to do a similar thing of setting the ratio relative to node width, then computing the effective spacing and using that to scale the width.

enough people have asked about this that I'm open to implementing something like it, but since I don't really have a use case, the api is unclear. If you can put together a proposal for what the appropriate api would look like, I'd be open to working on it.

from d3-dag.

djknight1 avatar djknight1 commented on May 22, 2024

@erikbrinkman Thank u! I do want that the nodes in the layout always spaced apart..
And thank u for your solution, I will try.
And I'd like to show u what a nodeSize api should like in my mind.

function nodeSize(x: [number, number]) {
    return arguments.length ? (nodeSize = true, [width, height] = x, sugiyama) : (nodeSize ? [width, height] : null);
};

function sizeNode(node) {
    node.x *= width;
    node.y = node.depth * height;
}
function sugiyama() {
 // ***
 if (nodeSize) dag.every(sizeNode)
// ***
}

from d3-dag.

erikbrinkman avatar erikbrinkman commented on May 22, 2024

I'm a little confused by this. In this api do all nodes have the same size? So the layout is really just height = depth * nodeHeight and width = maxNodesPerLine * nodeWidth? Should there be padding on those numbers? Proportional or absolute? Should instead it be a per node nodeSize with the option of making it all constant easily? maybe as an accessor function that could just return a constant value?

from d3-dag.

djknight1 avatar djknight1 commented on May 22, 2024

Yes, all nodes have same size.And your calculation is right.Actually I dont think there will be padding around these numbers.
In my mind, when you set size, you set a fixed tree, while use nodeSize, you set a dynamic tree. And a accessor function is great!

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.