-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add option for custom node shapes #27
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks @BoZenKhaa !
This is awesome! I would like to fix the Dict
/String
inconsistency that you mention if possible. What is the relationship between style
and shape
? Can we merge the two? It would probably be more appropriate to have style
and link_style
be Dict
s anyways.
Hopefully it would not be too hard to maintain backwards compatibility by still having a constructor that takes strings.
Let me know what you think.
Another option for an easyish fix would be to only have an element
keyword argument which could be circle
, rect
, etc. and then everything else like r
, width
, etc. could be controlled with the style
keyword.
One problem is that different types of shapes require different styling parameters ( So another option would be to merge the Do you have a preference or a better idea of how to address this? Anyway, I like the idea of converting |
How about keeping the style=[Dict(SVG_CIRCLE..., "opacity"=>"0.7"), etc.] to guide users in how to use different shapes? |
OK, I looked a bit more into how svgs work (https://editsvgcode.com/ is useful). Here are my conclusions:
(I am not sure what the tradeoffs for using What do you think? |
That sounds reasonable, I will try to rewrite it this way. |
I tried looking at the SVGs myself, I think it might be better actually to combine the element and its attributes in a single object. The reason is that as I understand it, svgs can contain nested elements. In the future, this would make stuff like this possible as valid node symbols: <g id="group1" fill="red">
<rect x="1cm" y="1cm" width="1cm" height="1cm"/>
<rect x="3cm" y="1cm" width="1cm" height="1cm"/>
</g> So now, I would either go with node_svg::Vector{String} that would just allow any SVG string such as the one above, or use some simple SVG struct: struct SVG
element::Symbol // or String
attributes::NamedTuple
// children::Vector{SVG} // as future extension
end
node_svg::Vector{SVG} The strings can apparently be added with something like d3.select('#svgtmp').append('div').html('<svg...') d3.select('.container').appendHTML('<div><svg><g><rect width="50" height="50" /></g></svg></div>'); which seems clean, but everything is up to the user then. Using struct would let us unpack and maybe check the contents of the SVG, but I am not sure that we want to maintain that. Maybe integrating https://github.com/BenLauwens/NativeSVG.jl could then be an option. I think I prefer the I tried to find some good SVG reference to include in the docs, the best I found is https://www.w3.org/TR/SVG/, specifically https://www.w3.org/TR/SVG/struct.html#NewDocument, but that's a bit wordy, do you know of anything better? |
The |
Ideally there would be a nice Julian svg interface like NativeSVG, but that package is not registered. So, I think the string approach is OK. I suggest trying to implement it and seeing if it comes out clean. |
Ok, I will give it a try and we will see what comes out of it. |
The shapes are now entered as SVG strings into At the same time, styling through the existing methods ( I now think it might make sense to keep both methods of styling, at least for With the
Currently, I am inclined to remove See the jupyter notebook for how things work in the current version. |
Also, instead of constants These methods could take arguments from |
Here is the attempt at providing backward compatibility while allowing custom SVGs. @zsunberg unless you object to this approach, I will clean up, update docs and add tests. |
Thanks for the additional work! Conceptually, this seems good to me. I will take another look once the README is updated.
I think we should only document one way to do it - it is too hard to maintain multiple ways, and it is easy enough for users to construct an svg string. We should only keep the old way for backwards compatibility.
Yes, I agree this is a much better idea than constants! but I agree that this may not be strictly necessary. |
Would it make sense just to construct svg strings in julia rather than employing other d3 functions? |
Adds support for custom node shapes, through new
shape
parameters. Seehello.ipynb
for examples:This adds an inconsistency where the shape parameter uses
Dict
instead of strings in other styling functions. This is because theshape
part of the dict is used differently by the javascript than the rest of the parameters. The shapes could be made to work with just strings, but that would require parsing them in javascript. I think it might be better long-term to have all the parameters as Dicts, but that's a breaking change that might be not worth it?