GithubHelp home page GithubHelp logo

klortho / d3-flextree Goto Github PK

View Code? Open in Web Editor NEW
312.0 312.0 46.0 3.94 MB

Flexible tree layout algorithm that allows for variable node sizes

Home Page: https://klortho.github.io/d3-flextree/

License: Do What The F*ck You Want To Public License

HTML 0.73% JavaScript 98.49% CSS 0.78%

d3-flextree's People

Contributors

avs-doom avatar klortho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

d3-flextree's Issues

How to use with React

Trying to figure out how to use this in my React app. I've got D3 imported without problems, but can't figure out how to import/load the generated JS files with my component.

Any help would be appreciated!

Importing d3-flextree in an Ecmascript6 polymer 3 element

I have this so far:

import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import * as d3 from 'd3';
/**
 * `emh-d3-flextree`
 * 
 *
 * @customElement
 * @polymer
 * @demo demo/index.html
 */
class EmhD3Flextree extends PolymerElement {
  static get template() {
    return html`
      <style>
        :host {
          display: block;
        }
      </style>
      <h2>Hello [[prop1]]!</h2>
    `;
  }
  static get properties() {
    return {
      prop1: {
        type: String,
        value: 'emh-d3-flextree',
      },
    };
  }
}

window.customElements.define('emh-d3-flextree', EmhD3Flextree);

I try:

import 'd3-flextree/build/d3-flextree.js';

and get

d3-flextree.js:2 Uncaught TypeError: Cannot read property 'd3' of undefined
    at d3-flextree.js:2
    at d3-flextree.js:3
(anonymous) @ d3-flextree.js:2
(anonymous) @ d3-flextree.js:3

How do I import the d3-flextree into an Ecmascript6 module?

Using d3.stratify together with the flextree hierarchy

My tree-data lies as a plain array at the beginning, so converting to a nested structure is necessary before processing with flextree.

If I use the d3.stratify function it creates a nested structure with the data property containing all the original properties of every node. If I then call the layout.hierarchy on this data it crates a new hierarchy containing the data property containing the data property containing all the original properties 😞

If I call layout directly on the stratified data the resulting layout does not have the right properties.

So shat I was forced to do instead was using different function to create the nested structure (see list-to-tree-lite) to create the flextree hierarchy to compute the layout.

It would be great if the flextree would be able to implement the d3.stratify function as well or at least operate on the stratified data with an option to re-use the data property.

Possible dynamic tree?

Hi, I'm totally new to D3 and to this library. Thank you so much for sharing your code.
I would like to add data for nodes dynamicaly and I wonder if this is possible with d3-flextree - to recalculate/redraw tree after adding new child nodes?
Something like https://github.com/fhightower/d3-dynamic-tree
Thanks for any reply!

layout bug

Discovered a bug in the layout algorithm -- see this issue. I added test trees grandkids1.json and grandkids2.json to illustrate it.

Custom spacing does not work

I found that custom spacing does not work (an example layout dump is pasted at the end). I can confirm that spacing accessor is called every time but somehow does not affect the 'y' coordinates. For example, with custom spacing 10, I expect 'y' in the following (the right most leaf in the paste below would be (320, 410) instead of (320, 400) -- and this recurses of course:

                     { size: [1260, 80],
                      x: 530, y: 320,
                      children: [
                        { size: [380, 80],
                          x: 530, y: 400 },
                      ],

I can work around the problem by including the spacing (I only need fixed spacing for now) in the size but it would be nice if this is something that you can quickly fix since you have much better knowledge on this. :-)

{ size: [620, 60], x: 0, y: 0, children: [ { size: [10, 40], x: 0, y: 60, children: [ { size: [620, 60], x: -570, y: 100, children: [ { size: [340, 60], x: -570, y: 160, children: [ { size: [10, 40], x: -570, y: 220, children: [ { size: [480, 60], x: -570, y: 260, children: [ { size: [740, 60], x: -570, y: 320, children: [ { size: [340, 80], x: -570, y: 380 }, ], }, ], }, ], }, ], }, ], }, { size: [700, 60], x: 530, y: 100, children: [ { size: [1200, 60], x: 530, y: 160, children: [ { size: [560, 60], x: 530, y: 220, children: [ { size: [10, 40], x: 530, y: 280, children: [ { size: [1260, 80], x: 530, y: 320, children: [ { size: [380, 80], x: 530, y: 400 }, ], }, ], }, ], }, ], }, ], }, ], }, ], },

Top to Bottom

Hi,

Is it possible to flip tree top to bottom?

Thanks a lot.

Node positions too far away on different sizes

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

overlapping in tree nodes with different sizes

This tree with different node sizes like below makes overlapping!

const flextree = require('d3-flextree').flextree;
const layout = flextree();
const tree = layout.hierarchy({
id:1,
size: [1, 1],
children: [
{id:2, size: [2, 1], children: [ ]},
{id:3, size: [4, 1], children: [ ]},
{id:4, size: [1, 1], children: [ ]}
]
});
layout(tree);
tree.each(node => console.log((${node.x}, ${node.y})));

when we run this code, you can see calculate wrong X for nodes with id 2 and 3!
the result:

"(0, 0)"
"(-2.5, 1)"
"(0.5, 1)"
"(3, 1)"

the excepted result:

"(0, 0)"
"(-3, 1)"
"(-1, 1)"
"(3, 1)"

Licensing change

Is it possible to change the license of this software to an OSI approved license like the "Unlicense"? https://choosealicense.com/licenses/unlicense/ https://unlicense.org/

The current WTFPL license is very vague does not include mentions regarding liability, warranty and public domain and isn't court tested, which is why my company is hesitant to actually use code licensed under it and it could also potentially be problematic for you as author. The Unlicense has all of the same freedoms that you seem to want from the WTFPL, but fixes the problems I mentioned above.

problem of using the d3-flextree in webpack

I love the concept of variable size in the d3 tree layout, I'm trying to use it in a webpack environment. First I'm not sure if there is d3-flextree npm package and it seems like I couldn't run the npm install d3-flextree, then I tried to import the file directly, my first attempt is to import the dist/d3-flextree and I got d3 couldn't be found error, then I tried to import the /d3/d3.min.js, and I got another error: Uncaught TypeError: Cannot read property 'document' of undefined. Is there any way to use it in the webpack?

Thanks!

The spacing argument is for extra space between siblings or the tree-levels ?

Hello,

I am trying to implement an "horizontal" flextree layout. So far so good, after I switched some x and y coordinates. I would like to add some extra separation between the parent nodes and the children nodes. So I introduced the spacing parameter. It looks to me, that this adds only spacing between the siblings, not between the tree levels.

This is how my chart looks like with spacing 0.
bildschirmfoto 2018-08-27 um 15 46 13
This is how my chart looks like with spacing 50.
bildschirmfoto 2018-08-27 um 15 47 05

In the flextree example it looks like the spacing is only between the "sibling" nodes. How can I achieve extra tree-level spacing without introducing some opaque container workaround ?

Horizontal tree

Hello,

thanks for providing this package!

Is it also possible to create a horizontal tree?

Best

[React] Cannot minify package.

When utilise CRA / Webpack in my project I am not able to compile it properly.

Everything works fine with my React build and this package is amazing, but I am forced now to utilise d3-flextree-v4 because that package has been exported as an es5 module

Documentation about CRA error.
https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify

@Klortho By the way I cannot express how grateful I am for this javascript port this opens so much UX/UI possibilities.

Different layout for children count greater than X

Not sure if anyone is actively managing this but is there any known reference for having the layout change for any nodes that have a certain number of children?

I have all my nodes in a tree structure but for visual purposes, I want to have children nodes be displayed in columns of two as opposed to one long row. Not sure if anyone using this library has had similar interests/issues like this.

Return coordinates starting from 0,0

As it stands, flextree seems to return centered coordinates. It would be more keeping with the other d3-hierarchy style layouts if it instead returned coordinates that started from 0,0 (including the width and height of the calculated nodes). If this is an option or I shouldn't be seeing negative x values, let me know.

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.