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

Customizable links/paths between nodes #80

Open
aroraank opened this issue Aug 21, 2018 · 5 comments
Open

Customizable links/paths between nodes #80

aroraank opened this issue Aug 21, 2018 · 5 comments

Comments

@aroraank
Copy link

How i can show conditional custom paths styles for different spouses like example: green path for current spouse & red path for ex-spouse?

@ucay
Copy link

ucay commented Aug 23, 2018

You can add your custom styles.

/* Data object */
[{
    /* ... */
    marriages: [{
        /* ... */
        class: "node spouse",
        /* ... */
    },{
        /* ... */
        class: "node spouse spouse_current",
        /* ... */
    }]
}]
/* stylesheets */ 
.spouse{
    background-color: red;
}
.spouse_current{
    background-color: green;
}

@aroraank
Copy link
Author

aroraank commented Aug 23, 2018

Hi @ucay , thanks for the solution
It is changing the color of node only. Is there any way to change the paths color also, for spouse and ex-spouse?

@ucay
Copy link

ucay commented Aug 24, 2018

Sorry @aroraank , missing the "path" word 😄
I like your idea for custom path's color.
For example, different color for current and ex-spouse, 1st and 2nd generation, or each descendant.

https://github.com/ErikGartner/dTree/blob/master/src/builder.js#L93
Can we add a class attribute to spouse ?
Or can we add it as a callback?

WDYT, @ErikGartner ?

@ErikGartner
Copy link
Owner

Good question @aroraank and thanks for helping out @ucay! 🙂 Currently there is no way to do this. Though I would be open to merging a pull-request adding this feature as it is a good suggestion.

A simpler class based solution makes if we can come up with a good and consistent way of addressing the path and everything that we want to do in terms of customize can be done in CSS (which I think is the case). We could add a class linkClass to spouses and children (of marriages and directly to a node).

A callback based solution would make sense if we would want more powerful customization beyond what CSS allows for. The only problem is designing the callback with "enough" information to be able to determine the color of the path. It would need something like function linkRendeder(fromNode, toNode, isChild, isSibling) and then execute the relevant d3 SVG commands. However this would force the user to write d3 code themselves, though on the other hand if the user wants to change the lines they probably are be an advanced user.

In general I'm open for merging any/both of these solutions as long as the solution is backwards compatible with the current format (i.e. adding an optional field or callback is fine).

I think the class based solution probably is favorable and considerably simpler (here and here dTree currently sets the path class). Some code to propagate the class attribute in a similar manner as with textClass and nodeClass and then setting it for each link should be all that is required.

/Erik

@ErikGartner ErikGartner changed the title Conditional custom paths Customizable links/paths between nodes Aug 25, 2018
@meganathan-codenatives
Copy link

meganathan-codenatives commented Jul 22, 2021

// Draw siblings (marriage)
this.g.selectAll('.sibling').data(this.siblings).enter().append('path').attr('class', opts.styles.marriage).attr('d', _.bind(this._siblingLine, this)).attr('style', _.bind(this._siblingStroke, this));

{
key: '_siblingStroke',
value: function _siblingStroke(d, i) {
var marriageStyle = "fill: none;stroke: #23883D;stroke-width: 5;";
// Not first marriage
if (d.number > 0) {
marriageStyle = "fill: none;stroke: #90EE90;stroke-width: 5;stroke-dasharray:4 3"
}
return marriageStyle;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants