API manual
Luxor.midpoint
— Methodmidpoint(a::Node, b::Node)
Get the midpoint of two nodes. Returns a Node
of shape :dot
.
LuxorGraphPlot.bottom
— Methodbottom(n::Node)
Get the bottom boundary point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.bottomleft
— Methodbottomleft(n::Node)
Get the bottomleft boundary point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.bottomright
— Methodbottomright(n::Node)
Get the bottomright boundary point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.boundary
— Methodboundary(n::Node, s::String)
boundary(n::Node, angle::Real)
Get the boundary point of a node in a direction. The direction can be specified by a string or an angle. Possible strings are: "left", "right", "top", "bottom", "topright", "topleft", "bottomleft", "bottomright".
LuxorGraphPlot.box!
— Methodbox!([nodestore, ]args...; kwargs...) = push!(nodestore, boxnode(args...; kwargs...))
Add a box shaped node to the nodestore. Please refer to boxnode
for more information. If nodestore
is not provided, the current nodestore is used.
LuxorGraphPlot.boxnode
— Methodbox(loc, width, height; props...) = Node(:box, loc; width, height, props...)
LuxorGraphPlot.center
— Methodcenter(n::Node)
Get the center point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.circle!
— Methodcircle!([nodestore, ]args...; kwargs...) = push!(nodestore, circlenode(args...; kwargs...))
Add a circle shaped node to the nodestore. Please refer to circlenode
for more information. If nodestore
is not provided, the current nodestore is used.
LuxorGraphPlot.circlenode
— Methodcircle(loc, radius; props...) = Node(:circle, loc; radius, props...)
LuxorGraphPlot.darktheme!
— Methoddarktheme!(config::GraphDisplayConfig)
Set the dark theme for the graph display.
LuxorGraphPlot.dot!
— Methoddot!([nodestore, ]args...; kwargs...) = push!(nodestore, dotnode(args...; kwargs...))
Add a dot shaped node to the nodestore. Please refer to dotnode
for more information. If nodestore
is not provided, the current nodestore is used.
LuxorGraphPlot.dotnode
— Methoddotnode(x, y)
dotnode(p::Point)
Create a node with a shape :dot
and a location.
LuxorGraphPlot.ellipse!
— Methodellipse!([nodestore, ]args...; kwargs...) = push!(nodestore, ellipsenode(args...; kwargs...))
Add a ellipse shaped node to the nodestore. Please refer to ellipsenode
for more information. If nodestore
is not provided, the current nodestore is used.
LuxorGraphPlot.ellipsenode
— Methodellipse(loc, width, height; props...) = Node(:ellipse, loc; width, height, props...)
LuxorGraphPlot.left
— Methodleft(n::Node)
Get the left boundary point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.lighttheme!
— Methodlighttheme!(config::GraphDisplayConfig)
Set the light theme for the graph display.
LuxorGraphPlot.line!
— Methodline!([nodestore, ]args...; kwargs...) = push!(nodestore, linenode(args...; kwargs...))
Add a line shaped node to the nodestore. Please refer to linenode
for more information. If nodestore
is not provided, the current nodestore is used.
LuxorGraphPlot.linenode
— Methodline(args...; props...) = Node(:line, mid; relpath, props...)
LuxorGraphPlot.nodestore
— Methodnodestore(f)
Create a NodeStore
context, such that box!
, circle!
, polygon!
, dot!
and line!
will add nodes to the nodestore. The nodestore is passed to the function f
as an argument.
Example
julia> using LuxorGraphPlot, LuxorGraphPlot.Luxor
julia> nodestore() do ns
box = box!(ns, (100, 100), 100, 100)
circle = circle!(ns, (200, 200), 50)
with_nodes(ns) do
stroke(box)
stroke(circle)
Luxor.line(topright(box), circle)
end
end
LuxorGraphPlot.offset
— Methodoffset(n::Node, p::Union{Tuple,Point})
offset(n::Node, direction, distance)
offset(n::Node, direction::Node, distance)
Offset a node towards a direction or another node. The direction can be specified by a tuple, a Point
or a Node
.
LuxorGraphPlot.polygon!
— Methodpolygon!([nodestore, ]args...; kwargs...) = push!(nodestore, polygonnode(args...; kwargs...))
Add a polygon shaped node to the nodestore. Please refer to polygonnode
for more information. If nodestore
is not provided, the current nodestore is used.
LuxorGraphPlot.polygonnode
— Methodpolygon([loc, ]relpath::AbstractVector; props...) = Node(:polygon, loc; relpath, props...)
LuxorGraphPlot.right
— Methodright(n::Node)
Get the right boundary point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.show_gallery
— Methodshow_gallery([f, ]stores::AbstractMatrix{GraphViz};
kwargs...
)
Show a gallery of graphs in VSCode, Pluto or Jupyter notebook, or save it to a file.
Positional arguments
f
is a function that returns extraLuxor
plotting statements.stores
is a matrix ofGraphViz
instances.
Keyword arguments
config
is aGraphDisplayConfig
instance.padding_left::Int = 10
, the padding on the left side of the drawingpadding_right::Int = 10
, the padding on the right side of the drawingpadding_top::Int = 10
, the padding on the top side of the drawingpadding_bottom::Int = 10
, the padding on the bottom side of the drawingformat
is the output format, which can be:svg
,:png
or:pdf
.filename
is a string as the output filename.
LuxorGraphPlot.show_graph
— Methodshow_graph([f, ]graph::AbstractGraph;
kwargs...
)
Show a graph in VSCode, Pluto or Jupyter notebook, or save it to a file.
Positional arguments
f
is a function that returns extraLuxor
plotting statements.graph
is a graph instance.locs
is a vector of tuples for specifying the vertex locations, or aAbstractLayout
instance.
Keyword arguments
config
is aGraphDisplayConfig
instance.vertex_colors
is a vector of color strings for specifying vertex fill colors.vertex_sizes
is a vector of real numbers for specifying vertex sizes.vertex_shapes
is a vector of strings for specifying vertex shapes, the string should be "circle" or "box".vertex_stroke_colors
is a vector of color strings for specifying vertex stroke colors.vertex_text_colors
is a vector of color strings for specifying vertex text colors.edge_colors
is a vector of color strings for specifying edge colors.texts
is a vector of strings for labeling vertices.
padding_left::Int = 10
, the padding on the left side of the drawingpadding_right::Int = 10
, the padding on the right side of the drawingpadding_top::Int = 10
, the padding on the top side of the drawingpadding_bottom::Int = 10
, the padding on the bottom side of the drawingformat
is the output format, which can be:svg
,:png
or:pdf
.filename
is a string as the output filename.
Example
julia> using Graphs, LuxorGraphPlot
julia> show_graph(smallgraph(:petersen); format=:png, vertex_colors=rand(["blue", "red"], 10));
LuxorGraphPlot.stroke
— Methodcircle(n::Node, action=:stroke)
Stroke a node with line.
LuxorGraphPlot.top
— Methodtop(n::Node)
Get the top boundary point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.topleft
— Methodtopleft(n::Node)
Get the topleft boundary point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.topright
— Methodtopright(n::Node)
Get the topright boundary point of a node. Returns a Node
of shape :dot
.
LuxorGraphPlot.with_nodes
— Methodwith_nodes(f[, nodestore]; kwargs...)
Create a drawing with the nodes in the nodestore. The bounding box of the drawing is determined by the bounding box of the nodes in the nodestore. If nodestore
is not provided, the current nodestore is used.
Keyword arguments
padding_left::Int=10
: Padding on the left side of the drawing.padding_right::Int=10
: Padding on the right side of the drawing.padding_top::Int=10
: Padding on the top side of the drawing.padding_bottom::Int=10
: Padding on the bottom side of the drawing.format::Symbol=:svg
: The format of the drawing. Available formats are:png
,:pdf
,:svg
...filename::String=nothing
: The filename of the drawing. Ifnothing
, a temporary file is created.background::String="white"
: The background color of the drawing.
LuxorGraphPlot.Connection
— TypeConnection(start, stop; isarrow=false, mode=:exact, arrowprops=Dict{Symbol, Any}(), control_points=Point[], smoothprops=Dict{Symbol, Any}())
Create a connection between two nodes. The connection can be a line, a curve, a bezier curve, a smooth curve or a zig-zag line.
Required Arguments
start::Node
: the start nodestop::Node
: the stop node
Optional Keyword Arguments
isarrow=false
: whether to draw an arrow at the end of the connectionmode=:exact
: the mode to get the connection point, can be:exact
or:natural
arrowprops=Dict{Symbol, Any}()
: the properties of the arrowcontrol_points=Point[]
: the control points for the connectionsmoothprops=Dict{Symbol, Any}()
: the properties of the smooth curve
LuxorGraphPlot.GraphDisplayConfig
— TypeGraphDisplayConfig
The configuration for graph display.
Keyword arguments
locs
is a vector of tuples for specifying the vertex locations.edges
is a vector of tuples for specifying the edges.fontsize::Float64 = 12.0
, the font sizefontface::String = ""
, the font face, leave empty to follow systemvertex_text_color = "black"
, the default text colorvertex_stroke_color = "black"
, the default stroke color for verticesvertex_color = "transparent"
, the default default fill color for verticesvertex_size::Float64 = 10.0
, the default vertex sizevertex_shape::Symbol = :circle
, the default vertex shape, which can be :circle, :box or :dotvertex_line_width::Float64 = 1
, the default vertex stroke line widthvertex_line_style::String = "solid"
, the line style of vertex stroke, which can be one of ["solid", "dotted", "dot", "dotdashed", "longdashed", "shortdashed", "dash", "dashed", "dotdotdashed", "dotdotdotdashed"]edge_color = "black"
, the default edge coloredge_line_width::Float64 = 1
, the default line widthedge_style::String = "solid"
, the line style of edges, which can be one of ["solid", "dotted", "dot", "dotdashed", "longdashed", "shortdashed", "dash", "dashed", "dotdotdashed", "dotdotdotdashed"]
LuxorGraphPlot.GraphViz
— TypeGraphViz
The struct for storing graph visualization information.
Keyword arguments
vertex_colors
is a vector of color strings for specifying vertex fill colors.vertex_sizes
is a vector of real numbers for specifying vertex sizes.vertex_shapes
is a vector of strings for specifying vertex shapes, the string should be "circle" or "box".vertex_stroke_colors
is a vector of color strings for specifying vertex stroke colors.vertex_text_colors
is a vector of color strings for specifying vertex text colors.edge_colors
is a vector of color strings for specifying edge colors.texts
is a vector of strings for labeling vertices.
LuxorGraphPlot.Node
— TypeNode(shape::Symbol, loc; props...)
Create a node with a shape and a location. The shape can be :circle
, :ellipse
, :box
, :polygon
, :line
or :dot
.
Required Keyword Arguments
ellipse
: [:width, :height]circle
: [:radius]line
: [:relpath]dot
: Symbol[]polygon
: [:relpath]box
: [:width, :height]
Optional Keyword Arguments
ellipse
: Dict{Symbol, Any}()circle
: Dict{Symbol, Any}()line
: Dict{Symbol, Any}(:arrowstyle => "-")dot
: Dict{Symbol, Any}()polygon
: Dict{Symbol, Any}(:smooth => 0, :close => true)box
: Dict{Symbol, Any}(:smooth => 0)
LuxorGraphPlot.NodeStore
— TypeNodeStore <: AbstractNodeStore
A collection of nodes, which is used to infer the bounding box of a drawing.
LuxorGraphPlot.Layouts.LayeredSpringLayout
— MethodLayeredSpringLayout(; zlocs, optimal_distance, aspect_ration=0.2)
Create a layered spring layout.
Keyword Arguments
zlocs
: the z-axis locationsoptimal_distance::Float64
: the optimal distance between verticesaspect_ration::Float64
: the aspect ratio of the z-axisα0::Float64
: the initial moving speedmaxiter::Int
: the maximum number of iterations
LuxorGraphPlot.Layouts.LayeredStressLayout
— MethodLayeredStressLayout(; zlocs, optimal_distance, aspect_ration=0.2)
Create a layered stress layout.
Keyword Arguments
zlocs
: the z-axis locationsoptimal_distance::Float64
: the optimal distance between verticesaspect_ration::Float64
: the aspect ratio of the z-axismaxiter::Int
: the maximum number of iterationsrtol::Float64
: the absolute tolerance
LuxorGraphPlot.Layouts.render_locs
— Methodrender_locs(graph, layout::Layout)
Render the vertex locations for a graph from an AbstractLayout
instance.
Arguments
graph::AbstractGraph
: the graph to renderlayout::AbstractLayout
: the layout algorithm
LuxorGraphPlot.Layouts.spectral_layout
— Functionspectral_layout(g::AbstractGraph, weight=nothing; optimal_distance=50.0)
Spectral layout for graph plotting, returns a vector of vertex locations.
LuxorGraphPlot.Layouts.spring_layout
— Methodspring_layout(g::AbstractGraph;
locs=nothing,
optimal_distance=50.0, # the optimal vertex distance
maxiter=100,
α0=2*optimal_distance, # initial moving speed
mask::AbstractVector{Bool}=trues(nv(g)) # mask for which to relocate
)
Spring layout for graph plotting, returns a vector of vertex locations.
This function is copied from GraphPlot.jl
, where you can find more information about his function.
LuxorGraphPlot.Layouts.stressmajorize_layout
— Methodstressmajorize_layout(g::AbstractGraph;
locs=rand_points_2d(nv(g)),
w=nothing,
optimal_distance=50.0, # the optimal vertex distance
maxiter = 400 * nv(g)^2,
rtol=1e-2,
)
Stress majorization layout for graph plotting, returns a vector of vertex locations.
References
- https://github.com/JuliaGraphs/GraphPlot.jl/blob/e97063729fd9047c4482070870e17ed1d95a3211/src/stress.jl
LuxorGraphPlot.Layouts.AbstractLayout
— TypeAbstractLayout
Abstract type for layout algorithms.
LuxorGraphPlot.Layouts.Layered
— TypeLayered <: AbstractLayout
Layered version of a parent layout algorithm.
Fields
parent::LT
: the parent layout algorithmzlocs::Vector{T}
: the z-axis locationsaspect_ratio::Float64
: the aspect ratio of the z-axis
LuxorGraphPlot.Layouts.Point
— TypePoint{D, T}
A point in D-dimensional space, with coordinates of type T.
LuxorGraphPlot.Layouts.SpectralLayout
— TypeSpectralLayout <: AbstractLayout
A layout algorithm based on spectral graph theory.
Fields
optimal_distance::Float64
: the optimal distance between verticesdimension::Int
: the number of dimensions
LuxorGraphPlot.Layouts.SpringLayout
— TypeSpringLayout <: AbstractLayout
A layout algorithm based on a spring model.
Fields
optimal_distance::Float64
: the optimal distance between verticesmaxiter::Int
: the maximum number of iterationsα0::Float64
: the initial moving speedmeta::Dict{Symbol, Any}
: graph dependent meta information, includinginitial_locs
: initial vertex locationsmask
: boolean mask for which vertices to relocate
LuxorGraphPlot.Layouts.StressLayout
— TypeStressLayout <: AbstractLayout
A layout algorithm based on stress majorization.
Fields
optimal_distance::Float64
: the optimal distance between verticesmaxiter::Int
: the maximum number of iterationsrtol::Float64
: the absolute toleranceinitial_locs
: initial vertex locationsmask
: boolean mask for which vertices to relocatemeta::Dict{Symbol, Any}
: graph dependent meta information, includinginitial_locs
: initial vertex locationsmask
: boolean mask for which vertices to relocate