forked from JuliaAnimators/Javis.jl
-
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
Draft
codejaeger
wants to merge
13
commits into
api-demos
Choose a base branch
from
signatures_and_docstrings
base: api-demos
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8709707
Update with docstrings
codejaeger 545469b
Fill in implementation details for GraphAnimation
codejaeger ee3bd3d
Refactor syntax for using graph animations
codejaeger b325b0e
Update
codejaeger b0c7f93
Update with GraphVertex creation
codejaeger 692508a
Fix macro @Graph
codejaeger 907daa8
Update with demo
codejaeger be61303
Add node styling options
codejaeger 8e584a3
Add edge drawing functions
codejaeger 58e60b4
Update with custom node positions
codejaeger f96c53f
Add self loops
codejaeger 887fb1e
Add edge style and arrows
codejaeger b64d014
Add some basic edge labelling
codejaeger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
```julia | ||
using Javis, LaTeXStrings | ||
|
||
function edge(; p1, p2, kwargs...) | ||
# sethue("black") | ||
# ob = blend(p1, p2, "orange", "blue") | ||
# setblend(ob) | ||
line(p1, p2, :clip) | ||
rect(p1, (p2-p1)..., :fill) | ||
# rect(p1, p2, :fill) | ||
clipreset() | ||
end | ||
|
||
function node(p=O, color="black") | ||
sethue(color) | ||
circle(p, 10, :fill) | ||
return p | ||
end | ||
|
||
function ground(args...) | ||
background("white") | ||
sethue("black") | ||
end | ||
|
||
video = Video(400, 400) | ||
Background(1:150, ground) | ||
|
||
g = @Object 1:150 JGraph(true, 100, 100) O | ||
|
||
adjacency_list = [[2, 3, 4, 5, 6], | ||
[7, 8], | ||
[7, 8], | ||
[],[],[],[],[]] | ||
for i in 1:length(adjacency_list) | ||
if i%2 == 0 | ||
@Graph g i*10:150 GraphVertex(i, [node_shape(:circle, true, radius=12), node_fill(:image, "football.png")]) O | ||
else | ||
@Graph g i*10:150 GraphVertex(i, [node_shape(:rectangle, true, width=20, height=20), node_fill(:color, "yellow"), node_text(L"""%$i""", :inside), node_border("green", 2)]) O | ||
end | ||
end | ||
# , node_text("$(i)", :top) | ||
global count = 0 | ||
for i in 1:length(adjacency_list) | ||
for j in adjacency_list[i] | ||
@Graph g 15+count*10:150 GraphEdge(i, j, [edge_shape(:curved, false; center_offset=5, end_offsets=(15, 15))]) O | ||
count+=1 | ||
end | ||
end | ||
|
||
# c = 5 | ||
# i = 1 | ||
# j = 2 | ||
# g2 = @Object 1:150 JGraph(true, 100, 100) O | ||
# @Graph g2 c*10:150 GraphVertex(i, (args...; kw...)->node()) O | ||
# @Graph g2 c*10:150 GraphVertex(j, (args...; kw...)->node()) O | ||
# @Graph g2 c*10:150 GraphEdge(i, j, (args...; kw...)->edge(; kw...)) O | ||
|
||
render(video; pathname="demo.gif") | ||
``` | ||
|
||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
```julia | ||
using Javis, LaTeXStrings | ||
|
||
function edge(; p1, p2, kwargs...) | ||
sethue("black") | ||
line(p1, p2, :stroke) | ||
end | ||
|
||
function node(position) | ||
# Just return the node position | ||
return Dict(:position=>position), (args...; kwargs...) -> nothing | ||
end | ||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this notation seems a bit weird. What are the two return arguments? |
||
|
||
function ground(args...) | ||
background("white") | ||
sethue("black") | ||
end | ||
|
||
video = Video(400, 400) | ||
Background(1:150, ground) | ||
|
||
g = @Object 1:150 JGraph(true, 100, 100, :none) Point(60, 60) | ||
|
||
adjacency_list = [[2, 3, 4, 5, 6], | ||
[7, 8], | ||
[7, 8], | ||
[],[],[],[],[]] | ||
coords = [] | ||
for i in 1:length(adjacency_list) | ||
if i%2 == 0 | ||
@Graph g i*10:150 GraphVertex(i, [node(Point(-(9-i)*10, -(i+5)*(i+5))), node_shape(:circle, true, radius=12), node_fill(:image, "football.png")]) O | ||
else | ||
@Graph g i*10:150 GraphVertex(i, [node(Point((9-i)*10, (i+5)*(i+5))), node_shape(:rectangle, true, width=20, height=20), node_fill(:color, "yellow"), node_text(L"""%$i""", :inside), node_border("green", 2)]) O | ||
end | ||
end | ||
count = 0 | ||
for i in 1:length(adjacency_list) | ||
for j in adjacency_list[i] | ||
@Graph g 15+count*10:150 GraphEdge(i, j, [edge_shape(:curved, false; center_offset=7)]) O | ||
count+=1 | ||
end | ||
end | ||
|
||
render(video; pathname="demo2.gif") | ||
``` | ||
|
||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
```julia | ||
using Javis, LaTeXStrings | ||
|
||
function edge(; p1, p2, kwargs...) | ||
sethue("black") | ||
line(p1, p2, :stroke) | ||
end | ||
|
||
function node(position) | ||
# Just return the node position | ||
return Dict(:position=>position), (args...; kwargs...) -> nothing | ||
end | ||
|
||
function ground(args...) | ||
background("white") | ||
sethue("black") | ||
end | ||
|
||
video = Video(400, 400) | ||
Background(1:150, ground) | ||
|
||
g = @Object 1:150 JGraph(true, 100, 100, :spring) Point(60, 60) | ||
|
||
adjacency_list = [[1, 2, 3, 4, 5, 6], | ||
[7, 8], | ||
[7, 8], | ||
[],[],[],[],[]] | ||
coords = [] | ||
for i in 1:length(adjacency_list) | ||
if i%2 == 0 | ||
@Graph g i*10:150 GraphVertex(i, [node(Point(-(9-i)*10, -(i+5)*(i+5))), node_shape(:circle, true, radius=12), node_fill(:color, "red"), node_text("1", :top)]) O | ||
else | ||
@Graph g i*10:150 GraphVertex(i, [node(Point((9-i)*10, (i+5)*(i+5))), node_shape(:rectangle, true, width=20, height=20), node_fill(:color, "yellow"), node_text(L"""%$i""", :inside), node_border("green", 2)]) O | ||
end | ||
end | ||
count = 0 | ||
for i in 1:length(adjacency_list) | ||
for j in adjacency_list[i] | ||
@Graph g 15+count*10:150 GraphEdge(i, j, [edge_shape(:line, center_offset=16, end_offsets=(2, 2)), edge_style(color="blue", linewidth=2), edge_arrow(), edge_label("$(i)->$(j)")]) O | ||
count+=1 | ||
end | ||
end | ||
|
||
render(video; pathname="demo3.gif") | ||
``` | ||
|
||
 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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