-
Notifications
You must be signed in to change notification settings - Fork 594
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
Implemented "arbitrary" node shapes #69
Conversation
Not yet done: looks perfect when rendered with Rascal, but not so perfect when pasted in an HTML page.
shapes The basic idea is that instead of the standard rectangle that is now drawn for each node, a separate shape can be defined per node. This is achieved by adding an extra "use" field that holds the name of an SVG def element. Whenever a node is rendered and the use element is present, the defined element will be drawn. An extra complication is how to determine the intersection between edges and user-defined node shapes. The approach is as follows: - circle, ellipse and polygon are supported and separate boundary intersection algorithms have been implemented - for all other cases we fall back to rectangular boundary. Caveats: - When the user defined shape is much larger than the height of each layer (rank), the end point of the edge may actually be inside the user-defined node shape and no intersection can be found. Solutions: (a) make shape smaller; (b) increase nodeSep. - When using donut-like shapes (with a hollow interior) and fill-rule "evenodd" the interior will not be filled and outgoing edges will become visible (since they are drawn from the shapes center below the shape itself). Solutions: (a) don't use shapes with interior holes as shape; (b) may get fixed in later versions.
@PaulKlint: love the new shapes. This will interest a lot of users, especially because it is more portable than the foreignObject label. In intersectNode is there any reason we can't use the "use" attribute? I think this would definitely be preferable if possible. Minor: code style is inconsistent around spaces, but I can clean those up once we've resolved on the above question. Thanks again! |
@cpettitt I will check the use issue you mention. Regarding coding style: I tried to follow your coding style as much as possible. Which exceptions did you spot? (My style is different, so I have undoubtedly introduced some inconsistencies) |
@cpettitt The preferred way to write
However, it seems that the meta information is lost somewhere during the copying/handling of nodes and |
@PaulKlint thanks for the details. Your preferred code looks good to me. I didn't get time to look at this today, but should have some time tomorrow to figure out what it will take to get this working. |
@PaulKlint I got it working with your preferred code above. I made a slight tweak: I change the attribute from 'use' to 'useDef' to make it a bit more specific. If everything looks good to you, I will publish a new release with this code. Thanks again; this is an awesome enhancement! |
The code looks good to me and the merged version works fine in my context as well. Glad that you like this addition. There are some more things on my wish list (but don't know whether I have time to work on this soon):
|
return r1 * r2 > 0; | ||
} | ||
|
||
// Add point to the found interesctions, but check first that it is unique. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a typo here: interesctions => intersections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Your code is now available in dagre v0.2.6. Thanks again!
Added optional "use" element in node meta-data for user-defined node shapes
The basic idea is that instead of the standard rectangle that is now drawn for each node, a separate shape can be defined per node.
This is achieved by adding an extra
use
field that holds the name of an SVGdef
element. Whenever a node is rendered and the use element is present, the defined element will be drawn. Seedemos/user-defined-nodes.html
for an example.The defined node shape element should satisfy the following requirements:
defs
section that is part of the svg in which the graph is being rendered.id
as occurs in theuse
element in the node's meta-data.A typical (good) example of a defined node shape is:
Caveats: