Script pour obtenir une animation de la toile de confiance duniter. [dépôt archivé] le code a été intégré à DataJune (
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

66 lines
2.6 KiB

# functions printing graph to image files
module GraphPrinter
using LightGraphs
using Dates
using GraphPlot, Compose
import Cairo, Fontconfig
using Plots, Colors
using ProgressMeter
using CustomLayout
using WotUtils
using Community
# compose graph with precomputed layout
function composegraph(legend, g, x, y, pseudo, sizes, colors)
N = nv(g) # number of node
graph = gplot(g, x, y, # graph
nodesize=sizes, nodelabel=pseudo, nodelabelsize=sizes, NODESIZE=3/sqrt(N+1500), # node shape
nodefillc=colors, edgestrokec=colorant"#77777744", # colors
arrowlengthfrac=0) # do not display arrow end
overlay = compose(context(), Compose.text(30pt, 60pt, legend), fontsize(30pt)) # legend
background = compose(context(), rectangle(), fill("white")) # background
return compose(context(), overlay, graph, background) # compose
# left pad with zeros
zeropad(n::Int, l::Int) = lpad(string(n),l,"0")
# print graph to file
function printgraph(folder::String, state::WotUtils.WotState)
FORMAT = ".png"
b = state.intervals[state.interval]
filename = joinpath(folder, "img", lpad(string(state.interval),4,'0') * FORMAT)
date = Date(unix2datetime(b))
legend = "$date N=" * zeropad(state.n,4) * " E=" * zeropad(ne(state.g),5)
img = composegraph(legend,, state.locs[1,:], state.locs[2,:], state.pseudo, state.indegrees, state.colors)
if FORMAT == ".png"
draw(PNG(filename, 30cm, 30cm, dpi=120), img) # save plot to PNG
elseif FORMAT == ".svg"
draw(SVG(filename, 30cm, 30cm), img) # save plot to SVG
# iterate over graphs while keeping layout from one to next
function animate_wotmap(folder::String)
mkpath(joinpath(folder, "img")) # create img directory
wotstate = WotUtils.WotState(folder) # initialize wotstate
wotstate.locs[:,:] .= CustomLayout.random_layout(wotstate.g) # initialize with random layout
# perform first iteration separately
counter = Community.NeighComm(wotstate.N) # initialize counter
CustomLayout.custom_layout!(wotstate, ITER=50) # First layout
Community.label_propagation!(wotstate.g, wotstate.communities, counter) # detect communities
printgraph(folder, wotstate)
# perform the rest of iterations
@showprogress "Printing images..." for i in 2:size(wotstate.intervals, 1)
WotUtils.set_current_interval!(wotstate, i) # load next graph
CustomLayout.custom_layout!(wotstate, ITER=1) # iter once
Community.label_propagation!(wotstate.g, wotstate.communities, counter) # update communities
printgraph(folder, wotstate)