Comments (8)
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.
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.
@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.
@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.
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.
@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.
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.
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)
- Basic TypeScript type check error HOT 6
- Tips for writing my own layering HOT 2
- General question about node ordering HOT 2
- Specific key order appears to cause decrossOpt to hang HOT 4
- TS: Errors with typescript version 4.9.4 HOT 3
- example code not runable HOT 4
- How to plot a horizonal sugiyama graph HOT 1
- Guidance on Implementing Radial Drawing with d3-dag's Sugiyama Algorithm HOT 3
- Implement Brandes/Kรถpf Coordinate Assignment
- Expand d3-dag to handle multiple paths from parent->child HOT 4
- Dynamic nodeSize? HOT 1
- TS, export SugiNode<NodeDatum = unknown, LinkDatum = unknown> ? HOT 3
- TS Sugestion(?) HOT 4
- Possible linking bug in docs HOT 3
- elkjs, external layout algorithms? HOT 1
- is it possible to establish node order explicitly in grid? HOT 8
- Support for TypeScript <4.5
- How to extend DagNode in vanilla js? HOT 6
- Error: size of dag to decrossOpt is too large and will likely crash instead of complete, enable "large" grahps to run anyway HOT 9
- Layout direction HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-dag.