Utilitaire pour indexer des informations de la blockchain et dessiner des Plots. Focalisé sur la toile de confiance. http://datajune.coinduf.eu/
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.

39 lines
1.6 KiB

module GraphPrinter
"""allow to print a graph with given layout"""
using ..Config
using LightGraphs
using GraphPlot, Compose, Colors, Cairo, Fontconfig, Dates
"compose graph with precomputed layout"
function composegraph(g::AbstractGraph, x::AbstractVector, y::AbstractVector,
pseudo::AbstractVector, sizes::AbstractVector, colors::AbstractVector, legend::String)
N = nv(g) # number of nodes
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(), Compose.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 frame cache for animwotmap movie"
function printframe(g::SimpleDiGraph, ug::SimpleGraph, locs, pseudo, sizes, colors, date::Date, number::Int)
FORMAT = ".png"
filename = joinpath(IMAGE_CACHE_PATH, zeropad(number,4) * FORMAT)
legend = "$date N=" * zeropad(nv(g),4) * " E=" * zeropad(ne(g),5)
img = composegraph(ug, locs[1,:], locs[2,:], pseudo, sizes, colors, legend)
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