A Julia package for transalting Neo4j graphs to MetaGraph.jl. Also adds an intuitive
plot
method via GraphPlot.jl to plot graphs with more configuration that Neo4j Bloom allows to.
pkg> add "https://github.com/valcarce01/Neo4j2Julia.jl"
There are two methods implemented in this package: create_graph
and plot
. The first one is the one that translates the Neo4j Graph to the MetaGraph and the second one is a simple function to plot it using configuration not available in the Neo4j Bloom.
The create_graph
includes the following arguments:
usr
: the user to be used to log-in the databasepassw
: the password of the given userURI
: to access the database (it is not really the URI, but the domain). Exmple: "http://localhost:7474" should beURI=localhost
(default).port
: in which the database is accessible.query
: the query (cypher) to return the data you want to work with (defualt is all the database)
create_graph( usr::String = "neo4j", passw::String = "neo4j", URI::String = "localhost", port::String = "7474", query::String = "MATCH (n) OPTIONAL MATCH (n)-[r]-() RETURN n, r;")
The plot
method includes the following arguments:
g
: the MetaGraph object to be plotted.nodeLabel
: the symbol (:name
) that stores the information about the node label.nodeLabelColor
: the symbol that you want to color the labels fromnodeLabelOffsetDist
: how far the labels should be from the nodenodeLabelOffsetAngle
: angle the labels should be in the nodenodeSize
: the symbol that stores the size of themnodeColor
: the symbol that should be used to apply color to the plotedgeLabel
: the symbol that stores the edge labelsedgeLabelColor
: the symbol that you want to color the edge labels fromedgeColor
: the symbol that should be used to apply color to the edges plotedgeWidth
: the width of the edgespallete
: a vector of RGB. This can be done via:[colorant"green", ...]
layout
: the layout that should be applied when placing the nodes. Options:- random_layout
- circular_layout
- spectral_layout
- shell_layout
filename
: the exporting path (include extension). Supported extensions:.svg
,.png
and.pdf
. The file would be exported as a 16cm x 16cm
plot(
g::MetaDiGraph;
# Node configuration:
nodeLabel::Union{Nothing, Symbol} = nothing,
nodeLabelColor::Union{RGB, Symbol} = colorant"black",
nodeLabelOffsetDist::Real = 0,
nodeLabelOffsetAngle::Real = π / 4.0,
nodeSize::Union{Real, Symbol} = 1,
nodeColor::Union{RGB, Symbol} = colorant"turquoise",
# Edge configuration:
edgeLabel::Union{Vector, Symbol} = [],
edgeLabelColor::Union{RGB, Symbol} = colorant"black",
edgeColor::Union{RGB, Symbol} = colorant"lightgray",
edgeWidth::Real = 1,
# Color pallete
pallete::AbstractVector=distinguishable_colors(1),
# Layout configuration
layout=random_layout,
#save config
filename = nothing,
)
# firstly we create the graph
G = create_graph("neo4j", "neo4j", "localhost", "7474")
# and then we plot it
plot(G)
# if we want to colorize it by a given property of the Neo4j Database:
plot(G; nodeColor = :type)
This package has been built for a personal project and only tested in one database, so I am not sure this is generalizable.
Feel free to report any issue or add new functionalities/correct them through a pull request.