-
Notifications
You must be signed in to change notification settings - Fork 0
Implement graph, nodes and edge creation #3
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
base: api-demos
Are you sure you want to change the base?
Conversation
f01d09b
to
b13adfa
Compare
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.
Just some comments ;)
b13adfa
to
1b2e7fa
Compare
* GraphAnimation * GraphNode * GraphEdge
1b2e7fa
to
8709707
Compare
a3f0f79
to
b0c7f93
Compare
bd37517
to
907daa8
Compare
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.
Looks good. Just some questions before I go deeper 😉
Maybe you can add some flow diagram/description of how everything is connected and give some details/docstrings to some more functions. Mostly describing what they are used for/doing.
@warn "Edge $(from_node)=>$(to_node) is already created on canvas. Recreating it will leave orphan edges in the animation. To undo, call `rem_edge!`" | ||
end | ||
add_edge!(g.adjacency_list.graph, from_node, to_node) | ||
set_prop!(g.adjacency_list, from_node, to_node, length(g.ordering)+1) |
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.
what is set here? What does the prop
represent, is it the id of the edge?
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.
set_prop!
sets the property of the node/edge (edge in this case). Since the WeightedGraph
type can only have one property for each node and edge there is no name given to that property.
property_style_map::Dict{Any,Symbol} = Dict{Any,Symbol}(), | ||
) | ||
g = graph.meta | ||
if !(typeof(g) <: JGraph) |
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.
Maybe we can do a parameterized AbstractObject
instead of checking the type of the meta
field here.
draw_fn = draw | ||
end | ||
add_vertex!(g.adjacency_list.graph) | ||
set_prop!(g.adjacency_list, nv(g.adjacency_list), length(g.ordering)+1) |
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'm a bit confused by the set_prop
functionality in general I think. I thought we can set different properties for a node, edge but it seems like we can only store one thing? Which in this case is the length(g.ordering)+1
?
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.
Yes, to store more than one property for nodes and edges there is already the MetaGraph
package. In many graph algorithms, only a single weight is associated with the nodes and edges hence this would be a useful structure to have.
src/structs/JGraph.jl
Outdated
end | ||
# Now assign positions back to all nodes | ||
for (idx, p) in enumerate(node_props(g.adjacency_list)) | ||
g.ordering[p].meta.opts[:position] = object.opts[:layout][idx] |
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.
is this used to give the position to each node later in rendering?
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.
Yes.
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.
Additionally to the specific comments in the code:
You often restrict the types of arguments in your functions where it isn't necessary and sometimes is restricting the user.
Furthermore you can restructure parts of your functions to call helper functions to limit code copy pasting.
examples/graph_animations/demo.md
Outdated
count = 0 | ||
for i in 1:length(adjacency_list) | ||
for j in adjacency_list[i] | ||
@Graph g 15+count*10:150 GraphEdge(i, j, (args...; kwargs...)->edge(; kwargs...)) O |
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.
doesn't work with count
as it's not known when you write this in global scope
opts = Dict{Symbol, Any}() | ||
opts[:shape] = shape | ||
opts[:clip] = clip | ||
if shape == :rectangle |
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.
currently there is no error message when one writes:
node_shape(:rectangle, true, radius=12)
Maybe have a look at: https://docs.julialang.org/en/v1/manual/types/#%22Value-types%22 to dispatch on the Symbol
src/node_shapes.jl
Outdated
|
||
# Arguments | ||
- `fill::Symbol`: Can be `image` or `color`. | ||
- `arg::String`: Can be a color like "red" or a image path in the same directory like "image.png". |
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.
In Luxor one normally sets colors with symbols so :red
instead of "red"
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.
Hey, I was using sethue
to switch between colors. I checked the methods available for sethue
and could not find one using Symbol
s. Is there something else you are referring to here?
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.
Oh sorry I think I got confused 😁 but I think other color packages are also supported. Let me check though
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.
src/node_shapes.jl
Outdated
- `color`: The color of the text. Default is "black". | ||
- `offset`: Used only when `align` is not `:inside`. Specifies an offset in the direction of `align`. | ||
""" | ||
function node_text(text::AbstractString, align::Symbol, color::String="black", offset::Real=1) |
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 think we want to have an option to specify the font size?
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.
To specify font and size, it is possible to add a (args...; kwargs...) -> setfont(font, size) anywhere in the list before a node_text
is created. Since these functions are supposed to be backup options if the user wants to skip some drawing properties I skipped that option. Do you think it is still needed?
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 think font size is something so standard that we want to include it in node_text
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.
Okay sure will do that.
2abb72d
to
b3c4846
Compare
b3c4846
to
be61303
Compare
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.
Just some minor things
src/edge_shapes.jl
Outdated
return | ||
end | ||
if self_loop | ||
# Need to find out where to draw the edge without clutter |
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.
Set a Todo:
in those cases to find them later
src/edge_shapes.jl
Outdated
@@ -0,0 +1,44 @@ | |||
function edge_shape(shape::Symbol=:line, clip::Bool = false; center_offset::Real = 3, end_offsets::Tuple{Real, Real} = (0, 0), width::Real = 2, dash::String = "solid") |
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.
please add a docstring here
# Check available layouts | ||
if !(layout in [:none, :spring, :spectral]) | ||
layout = :spring | ||
@warn "Unknown layout '$(layout)'. Defaulting to static layout" |
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.
do you mean: Defaulting to :spring
layout?
video = Video(400, 400) | ||
Background(1:150, ground) | ||
|
||
g = @Object 1:150 JGraph(true, 100, 100) O |
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.
Seems like the O
doesn't have any effect?
For example replacing it by Point(-100,0)
does not shift it 100px to the left
|
||
Create an empty graph on the canvas. | ||
""" | ||
JGraph(directed::Bool, width::Int, height::Int) = |
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.
this should allow the keywords mode, layout, get_node_attribute, get_edge_attribute
, right?
@@ -53,6 +53,10 @@ JGraph(directed::Bool, width::Int, height::Int) = | |||
directed ? JGraph(WeightedGraph(LightGraphs.SimpleDiGraph()), width, height) : | |||
JGraph(WeightedGraph(LightGraphs.SimpleGraph()), width, height) | |||
|
|||
JGraph(directed::Bool, width::Int, height::Int, layout::Symbol=:none) = |
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.
mode is still missing, right?
e960aa5
to
5129cf8
Compare
return Dict(:position=>position), (args...; kwargs...) -> nothing | ||
end |
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.
this notation seems a bit weird. What are the two return arguments?
de1ba34
to
84062b4
Compare
84062b4
to
58e60b4
Compare
* TODO: Label position for bezier curves
3c8cfec
to
b64d014
Compare
PR Checklist
If you are contributing to
Javis.jl
, please make sure you are able to check off each item on this list:CHANGELOG.md
with whatever changes/features I added with this PR?Project.toml
+ set an upper bound of the dependency (if applicable)?test
directory (if applicable)?Link to relevant issue(s)
Closes #
How did you address these issues with this PR? What methods did you use?