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

Node positions too far away on different sizes #36

Open
vco-80 opened this issue May 7, 2023 · 1 comment
Open

Node positions too far away on different sizes #36

vco-80 opened this issue May 7, 2023 · 1 comment

Comments

@vco-80
Copy link

vco-80 commented May 7, 2023

Hi

Seems that when having children with different width, the calculated x positions are too far away. Or i don't get what i'm making wrong.

Here is a simple example. You can just copy&paste it in the npm runkit (https://npm.runkit.com/d3-flextree):

var d3Flextree = require("d3-flextree")
const flextree = d3Flextree.flextree;

const data = {
    "id": "26d536a3-879f-493c-af2e-3785a3e7bd5c",
    "size": [
        360,
        409
    ],
    "children": [
        {
            "id": "e7e369db-ffd7-4b1a-a7d4-42a6d157c35c",
            "size": [
                460,
                609
            ],
            "children": []
        },
        {
            "id": "6a91d13d-dc13-45b9-8697-d105a443ac03",
            "size": [
                1103,
                1298
            ],
            "children": []
        }
    ]
};


const layout = flextree();
const tree = layout.hierarchy(data);
layout(tree);
tree.each(node => console.log(`(${node.x}, ${node.y})`));

These are the computed x/y positions of each node (printed from the console.log):

"(0, 0)"
"(-551.5, 409)"
"(230, 409)"

The calculated distance between the 2 children is 321.5 ((-551.5 + 460 - 230) * -1), but should be almost 0 because i don't have defined any spacings.

Or am I wrong?

Thanks for your help

@vco-80
Copy link
Author

vco-80 commented May 9, 2023

Ok, i get it. I think it's because the x position is the center of the element not the left position.

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

No branches or pull requests

1 participant