ErikGartner / dTree

A library for visualizing data trees with multiple parents, such as family trees. Built on top of D3.
https://treehouse.gartner.io/ErikGartner/58e58be650453b6d49d7
MIT License
521 stars 139 forks source link

Add support for a custom renderer for marriages #65

Closed ErikGartner closed 4 years ago

ErikGartner commented 6 years ago

From an email, describing how to implement this:

Marriages are already represented by hidden nodes in the underlying tree structure, and support the extra property in the json format. So there is already some support for passing this type of data. See: https://github.com/ErikGartner/dTree/blob/e2d794c2b2320f2ef23c71604e0048963ad29118/src/dtree.js#L114

The best way to manage this in a general and PR friendly way would be to:

Add support for a custom marriageRenderer callback, this would take a "marriage node” along with the extra property and then do some printing of text or drawing. I would be fine with having a “default callback” that looks in the extra property and if it exists and is just a string, then it will be printed along the marriage line.

For inspiration on how to make a callback see: https://github.com/ErikGartner/dTree/blob/e2d794c2b2320f2ef23c71604e0048963ad29118/src/builder.js#L282

and set the default callback here: https://github.com/ErikGartner/dTree/blob/e2d794c2b2320f2ef23c71604e0048963ad29118/src/dtree.js#L17

If might be a good idea to add some property in the marriage nodes when they are created that let you identify them in builder.js. That way you don’t have guess which nodes are “real” nodes, marriage nodes or other types of hidden nodes.