-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
193 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"composite_marks", | ||
"multi_view_plots", | ||
"layered_plots", | ||
"interactive" | ||
"interactive", | ||
"graphs", | ||
] | ||
} |
This file contains 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,14 @@ | ||
# --- | ||
# cover: assets/graph_chart.png | ||
# author: bruno | ||
# description: Simple Graph Chart | ||
# --- | ||
|
||
using Deneb, Graphs, NetworkLayout | ||
|
||
g = wheel_graph(10) | ||
|
||
chart = plotgraph(g) | ||
|
||
# save cover #src | ||
save("assets/graph_chart.png", chart) #src |
This file contains 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,14 @@ | ||
# --- | ||
# cover: assets/graph_chart_labels.png | ||
# author: bruno | ||
# description: Graph Chart wih Custom Labels | ||
# --- | ||
|
||
using Deneb, Graphs, NetworkLayout | ||
|
||
g = smallgraph(:cubical) | ||
|
||
chart = plotgraph(g, node_labels='a':'h') | ||
|
||
# save cover #src | ||
save("assets/graph_chart_labels.png", chart) #src |
This file contains 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,14 @@ | ||
# --- | ||
# cover: assets/graph_chart_layout.png | ||
# author: bruno | ||
# description: Graph Chart wih Custom Layout | ||
# --- | ||
|
||
using Deneb, Graphs, NetworkLayout | ||
|
||
g = smallgraph(:petersen) | ||
|
||
chart = plotgraph(g, layout=Shell(nlist=[6:10, ])) | ||
|
||
# save cover #src | ||
save("assets/graph_chart_layout.png", chart) #src |
This file contains 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 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,76 @@ | ||
module GraphsExt | ||
|
||
using Deneb, Graphs, NetworkLayout | ||
|
||
function node_data(g::AbstractGraph, pos; labels::Union{Nothing, AbstractVector}=nothing) | ||
isnothing(labels) && return [(id=v, x=pos[v][1], y=pos[v][2]) for v in vertices(g)] | ||
length(labels) == nv(g) || error("labels length must be equal to number of vertices") | ||
return [ | ||
(id=v, x=pos[v][1], y=pos[v][2], label=l) | ||
for (v, l) in zip(vertices(g), labels) | ||
] | ||
end | ||
|
||
function edge_data(g::AbstractGraph, pos; labels::Union{Nothing, AbstractVector}= nothing) | ||
isnothing(labels) && return [ | ||
(src=src(e), dst=dst(e), x=pos[src(e)][1], y=pos[src(e)][2], x2=pos[dst(e)][1], y2=pos[dst(e)][2], label=repr(e)) | ||
for e in edges(g) | ||
] | ||
length(labels) == ne(g) || error("labels length must be equal to number of edges") | ||
return [ | ||
(src=src(e), dst=dst(e), x=pos[src(e)][1], y=pos[src(e)][2], x2=pos[dst(e)][1], y2=pos[dst(e)][2], label=l) | ||
for (e, l) in zip(edges(g), labels) | ||
] | ||
end | ||
|
||
function Deneb.graph_data( | ||
g::AbstractGraph; | ||
layout::NetworkLayout.AbstractLayout=Spring(), | ||
node_labels::Union{Nothing, AbstractVector}=nothing, | ||
edge_labels::Union{Nothing, AbstractVector}=nothing, | ||
) | ||
pos = layout(g) | ||
nodes = node_data(g, pos; labels=node_labels) | ||
edges = edge_data(g, pos; labels=edge_labels) | ||
return nodes, edges | ||
end | ||
|
||
function Deneb.Datasets( | ||
g::AbstractGraph; | ||
layout::NetworkLayout.AbstractLayout=Spring(), | ||
node_labels::Union{Nothing, AbstractVector}=nothing, | ||
edge_labels::Union{Nothing, AbstractVector}=nothing, | ||
) | ||
nodes, edges = graph_data(g; layout, node_labels, edge_labels) | ||
return Datasets(; nodes, edges) | ||
end | ||
|
||
function Deneb.plotgraph( | ||
g::AbstractGraph; | ||
layout::NetworkLayout.AbstractLayout=Spring(), | ||
node_labels::Union{Nothing, AbstractVector}=nothing, | ||
edge_labels::Union{Nothing, AbstractVector}=nothing, | ||
) | ||
base = Datasets(g; layout, node_labels, edge_labels) * Encoding( | ||
x=field("x:q", axis=nothing), | ||
y=field("y:q", axis=nothing), | ||
) | ||
|
||
ntooltip = isnothing(node_labels) ? :id : [field(:id), field(:label)] | ||
points = Mark( | ||
:point, size=400, fill=:lightblue, opacity=1, | ||
) * Encoding(tooltip=ntooltip) | ||
labels = Mark(:text) * Encoding( | ||
text=isnothing(node_labels) ? :id : :label, | ||
tooltip=ntooltip, | ||
) | ||
|
||
lines = Mark(:rule, size=3) * Encoding(x2=:x2, y2=:y2, tooltip=:label) | ||
|
||
return base * ( | ||
Data(:name, :edges) * lines + | ||
Data(:name, :nodes) * (points + labels) | ||
) | ||
end | ||
|
||
end |
This file contains 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 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 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