Skip to content

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

Draft
wants to merge 13 commits into
base: api-demos
Choose a base branch
from

Conversation

codejaeger
Copy link
Owner

  • GraphAnimation

PR Checklist

If you are contributing to Javis.jl, please make sure you are able to check off each item on this list:

  • Did I update CHANGELOG.md with whatever changes/features I added with this PR?
  • Did I make sure to only change the part of the file where I introduced a new change/feature?
  • Did I cover all corner cases to be close to 100% test coverage (if applicable)?
  • Did I properly add Javis dependencies to the Project.toml + set an upper bound of the dependency (if applicable)?
  • Did I properly add test dependencies to the test directory (if applicable)?
  • Did I check relevant tutorials that may be affected by changes in this PR?
  • Did I clearly articulate why this PR was made the way it was and how it was made?

Link to relevant issue(s)
Closes #

How did you address these issues with this PR? What methods did you use?

@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from f01d09b to b13adfa Compare June 14, 2021 18:41
Copy link

@Wikunia Wikunia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some comments ;)

@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from b13adfa to 1b2e7fa Compare June 15, 2021 11:26
* GraphAnimation
* GraphNode
* GraphEdge
@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from 1b2e7fa to 8709707 Compare June 15, 2021 21:05
* Add macro syntax @object as temporary sol. for predefined objects
* Update graph creation workflow
* Add utility graph type WeightedGraph
@codejaeger codejaeger changed the title Update with docstrings Implement graph, nodes and edge creation Jun 21, 2021
@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from a3f0f79 to b0c7f93 Compare June 22, 2021 20:17
@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from bd37517 to 907daa8 Compare June 26, 2021 12:49
Copy link

@Wikunia Wikunia left a 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)
Copy link

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?

Copy link
Owner Author

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)
Copy link

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)
Copy link

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 ?

Copy link
Owner Author

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.

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]
Copy link

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?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link

@Wikunia Wikunia left a 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.

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
Copy link

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
Copy link

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


# 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".
Copy link

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"

Copy link
Owner Author

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 Symbols. Is there something else you are referring to here?

Copy link

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- `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)
Copy link

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?

Copy link
Owner Author

@codejaeger codejaeger Jul 5, 2021

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?

Copy link

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

Copy link
Owner Author

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.

@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from 2abb72d to b3c4846 Compare July 5, 2021 14:06
@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from b3c4846 to be61303 Compare July 5, 2021 14:11
Copy link

@Wikunia Wikunia left a 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

return
end
if self_loop
# Need to find out where to draw the edge without clutter
Copy link

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

@@ -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")
Copy link

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"
Copy link

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
Copy link

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) =
Copy link

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) =
Copy link

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?

@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from e960aa5 to 5129cf8 Compare July 7, 2021 15:45
Comment on lines +11 to +12
return Dict(:position=>position), (args...; kwargs...) -> nothing
end
Copy link

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?

@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from de1ba34 to 84062b4 Compare July 7, 2021 16:12
@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from 84062b4 to 58e60b4 Compare July 10, 2021 15:40
@codejaeger codejaeger marked this pull request as draft July 16, 2021 16:24
* TODO: Label position for bezier curves
@codejaeger codejaeger force-pushed the signatures_and_docstrings branch from 3c8cfec to b64d014 Compare July 16, 2021 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants