### Install GraphMakie Source: https://github.com/makieorg/graphmakie.jl/blob/master/README.md Use the Julia package manager to add the GraphMakie package. ```julia pkg> add GraphMakie ``` -------------------------------- ### EdgeClickHandler Example Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-interactions.md Creates a click handler for edges that invokes a callback on left-click. The callback function receives the edge index, event, and axis. This example demonstrates changing an edge's color on click. ```julia using Makie.Colors g = wheel_digraph(10) f, ax, p = graphplot(g, edge_width=4, edge_color=[colorant"black" for i in 1:ne(g)]) function action(idx, event, axis) p.edge_color[][idx] = rand(RGB) p.edge_color[] = p.edge_color[] end register_interaction!(ax, :edgeclick, EdgeClickHandler(action)) ``` -------------------------------- ### NodeClickHandler Example Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-interactions.md Creates a click handler for nodes that invokes a callback on left-click. The callback function receives the node index, event, and axis. This example demonstrates changing a node's color on click. ```julia using Makie.Colors g = wheel_digraph(10) f, ax, p = graphplot(g, node_size=30, node_color=[colorant"red" for i in 1:nv(g)]) function action(idx, event, axis) p.node_color[][idx] = rand(RGB) p.node_color[] = p.node_color[] end register_interaction!(ax, :nodeclick, NodeClickHandler(action)) ``` -------------------------------- ### Curved Edges for Bidirectional Graphs Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/configuration.md Configures curved edges with a specified distance and usage. This example curves all edges, suitable for visualizing bidirectional relationships clearly. ```julia graphplot(g, curve_distance = 0.15, curve_distance_usage = true, # curve all edge_width = 2 ) ``` -------------------------------- ### straighten Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Convert any path to a straight line by taking start and end points. Returns a Line object representing the path from its start to its end. ```APIDOC ## straighten ### Description Convert any path to a straight line by taking start and end points. ### Parameters - **path** (AbstractPath) - Yes - Path to straighten ### Returns `Line` - Line from path start to path end ``` -------------------------------- ### Convert Path to Straight Line Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Transforms any AbstractPath into a Line by using only its start and end points. ```julia straighten(path::AbstractPath) ``` -------------------------------- ### Get Bezier Path Waypoints Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Extracts all characteristic points, including control points and endpoints, from a BezierPath. This is useful for debugging. ```julia waypoints(p::BezierPath) ``` -------------------------------- ### Interpolate Point on Path Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Calculates the position along a path at a given parameter t. t=0 is the start, and t=1 is the end. This function supports linear interpolation for lines and cubic Bezier curves for BezierPaths. ```julia path = Path(Point2f(0,0), Point2f(1,1), Point2f(2,0)) p_start = interpolate(path, 0.0) # start point p_mid = interpolate(path, 0.5) # middle p_end = interpolate(path, 1.0) # end point ``` -------------------------------- ### Registering Interactions Source: https://github.com/makieorg/graphmakie.jl/blob/master/docs/src/index.md Demonstrates how to register predefined interactions like node/edge highlighting and dragging. ```APIDOC ## Predefined Interactions `GraphMakie.jl` provides some pre-built interactions to enable drag&drop of nodes and edges as well as highlight on hover. ### Description This example shows how to register various interactions to a graph plot. ### Method `register_interaction!` ### Endpoint N/A (Julia function) ### Parameters - `ax` (Axis): The Makie axis object to register the interaction with. - `interaction_name` (Symbol): A symbolic name for the interaction (e.g., `:nhover`). - `interaction_handler` (Interaction): An instance of an interaction handler (e.g., `NodeHoverHighlight(p)`). ### Request Example ```julia using GLMakie using GraphMakie using Graphs g = wheel_graph(10) f, ax, p = graphplot(g, edge_width=[3 for i in 1:ne(g)], node_size=[10 for i in 1:nv(g)]) deregister_interaction!(ax, :rectanglezoom) register_interaction!(ax, :nhover, NodeHoverHighlight(p)) register_interaction!(ax, :ehover, EdgeHoverHighlight(p)) register_interaction!(ax, :ndrag, NodeDrag(p)) register_interaction!(ax, :edrag, EdgeDrag(p)) ``` ### Response This function modifies the axis to include the specified interaction. No explicit return value is documented for success. ``` -------------------------------- ### Line Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md Represents a straight line segment defined by a start point and an end point. ```APIDOC ## Line ```julia struct Line{PT} <: AbstractPath{PT} p0::PT p::PT end ``` Straight line segment from `p0` to `p`. ### Type Parameters - `PT` - Point type (Point2, Point3, etc.) ### Fields | Field | Type | Description | |-------|------|-------------| | p0 | PT | Start point | | p | PT | End point | ``` -------------------------------- ### Geometry and Visualization Utilities Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md Visualize Bezier control points with `plot_controlpoints!`. Other utilities include calculating marker scaling factors, distances between markers, and finding points on a path near a destination. ```julia plot_controlpoints!(ax, gp) ``` ```julia scale_factor(marker) ``` ```julia distance_between_markers(m1, s1, m2, s2) ``` ```julia point_near_dst(path, p0, d, to_px) ``` -------------------------------- ### Create NodeHoverHighlight Handler Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-interactions.md Creates a pre-built handler to magnify node sizes on hover. It requires the `node_size` attribute to be a Vector of real numbers. ```julia NodeHoverHighlight(p::GraphPlot, factor=2) ``` ```julia g = wheel_graph(10) f, ax, p = graphplot(g, node_size = [20 for i in 1:nv(g)]) register_interaction!(ax, :nodehover, NodeHoverHighlight(p)) ``` -------------------------------- ### Path Constructor (Spline Interpolation) Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Creates a Bezier path through multiple points using natural cubic spline interpolation. It supports custom tangent directions and a factor to control curve radius. For two points without tangents, it returns a straight line. ```APIDOC ## Path(P::Vararg{PT, N}; tangents=nothing, tfactor=.5) ### Description Create a Bezier path through multiple points using natural cubic spline interpolation. Supports optional tangent vectors for start and end points, and a factor controlling curve radius. ### Parameters #### Path Parameters - **P** (Point arguments) - Required - 2 or more points to interpolate through - **tangents** (Tuple{Point, Point} or nothing) - Optional - Optional tangent vectors for start and end points. If provided, bezier curve is adjusted to start/end with given direction. - **tfactor** (Number or Tuple{Number, Number}) - Optional - Factor controlling curve radius from tangents (0-1). Separate values can be given for start and end. Default: 0.5 ### Returns - `Line{PT}` - If N=2 and tangents=nothing - `BezierPath{PT}` - If N>2 or tangents provided ### Behavior - For 2 points without tangents: returns a straight line - For 2+ points: uses natural cubic spline interpolation - Tangents override the spline-computed directions at endpoints - tfactor scales the tangent vectors (higher = bigger radius) ### Example ```julia p1 = Point2f(0, 0) p2 = Point2f(2, 1) p3 = Point2f(4, 0) # Simple spline through 3 points path1 = Path(p1, p2, p3) # Spline with custom tangent directions path2 = Path(p1, p2, p3; tangents=(Point2f(1, 0), Point2f(1, 0)), tfactor=0.8) # Just two points - returns straight line path3 = Path(p1, p2) # Two points with tangents - returns bezier curve t1 = Point2f(1, 1) t2 = Point2f(-1, 0) path4 = Path(p1, p2; tangents=(t1, t2)) ``` ``` -------------------------------- ### waypoints Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Get all characteristic points of a Bezier path for debugging. Extracts control points and endpoints from all CurveTo commands. ```APIDOC ## waypoints ### Description Get all characteristic points of a Bezier path for debugging. ### Parameters - **p** (BezierPath) - Yes - Path to extract waypoints from ### Returns `Vector{PT}` - Control points and endpoints from all CurveTo commands ``` -------------------------------- ### Basic Graph Plot Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/README.md Demonstrates how to create a basic plot of a complete graph using GraphMakie.jl. Ensure Graphs.jl and GLMakie.jl are imported. ```julia using GraphMakie, Graphs, GLMakie g = complete_graph(5) graphplot(g) ``` -------------------------------- ### Extract EdgePlot from GraphPlot Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-utilities.md Use this function to get the internal EdgePlot object from a GraphPlot. This object is responsible for rendering all edges. ```julia g = complete_graph(5) f, ax, p = graphplot(g) edge_plot = get_edge_plot(p) ``` -------------------------------- ### GraphPlot with Edge Styling Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-edgeplot.md Demonstrates how to use `graphplot` to render a graph with custom edge styling. It shows how to set per-edge width, color, and linestyle, and how to access the internal EdgePlot object. ```julia g = complete_graph(5) f, ax, p = graphplot(g, edge_width = [1, 2, 3, 4, 5], edge_color = [:red, :blue, :green, :gray, :black], edge_linestyle = [:solid, :dash, :dot, :solid, :dash] ) # Access internal EdgePlot edge_plot = get_edge_plot(p) ``` -------------------------------- ### Get Tangent Vector on Path Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Retrieves the normalized tangent vector at a specific parameter t along the path. This indicates the direction of the path at that point. ```julia path = Path(Point2f(0,0), Point2f(1,1), Point2f(2,0)) dir = tangent(path, 0.5) # direction at midpoint ``` -------------------------------- ### Path Constructor (Rounded Corners) Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Creates a path through points with straight line segments and smooth rounded corners. The radius parameter determines the roundness of the corners. ```APIDOC ## Path(radius::Real, p::Vararg{PT, N}) ### Description Create a path through points with straight line segments and smooth rounded corners. ### Parameters #### Path Parameters - **radius** (Real) - Required - Corner radius. 0 for sharp corners, positive for rounded. - **p** (Point arguments) - Required - 2 or more points to connect ### Returns - `BezierPath{PT}` - Path with straight segments and smooth corners ``` -------------------------------- ### GraphMakie Module Structure Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md Overview of the GraphMakie.jl module structure, showing the organization of source files for the main module, recipes, interaction handlers, Bezier curves, and utility functions. ```bash GraphMakie/ ├── src/ │ ├── GraphMakie.jl # Main module │ ├── recipes.jl # GraphPlot and EdgePlot recipes │ ├── interaction.jl # Interactive handlers │ ├── beziercurves.jl # Path types and operations │ └── utils.jl # Utility functions ``` -------------------------------- ### Create EdgeHoverHighlight Handler Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-interactions.md Creates a pre-built handler to magnify edge widths on hover. It can also scale arrow sizes if they are represented as a Vector of real numbers. ```julia EdgeHoverHighlight(p::GraphPlot, factor=2) ``` -------------------------------- ### Get Attribute from Observable or Collection Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-utilities.md Safely extract a value from an observable, vector, or dictionary using an index or key. Provides a default value if the index/key is not found. ```julia edge_colors = [:red, :blue, :green] getattr(edge_colors, 2) # returns :blue edge_dict = Dict(1 => :red, 2 => :blue) getattr(edge_dict, 1) # returns :red getattr(edge_dict, 3, :gray) # returns :gray (default) ``` -------------------------------- ### Extract Node Label Plot from GraphPlot Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-utilities.md Get the internal text plot for node labels from a GraphPlot. This function returns nothing if no node labels were provided. ```julia f, ax, p = graphplot(g, nlabels=string.(1:nv(g))) label_plot = get_nlabel_plot(p) ``` -------------------------------- ### Path Constructor for Spline Interpolation Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Creates a Bezier path through multiple points using natural cubic spline interpolation. Can optionally use custom tangents and a tangent factor. ```julia Path(P::Vararg{PT, N}; tangents=nothing, tfactor=.5) where {PT<:AbstractPoint, N} ``` ```julia p1 = Point2f(0, 0) p2 = Point2f(2, 1) p3 = Point2f(4, 0) # Simple spline through 3 points path1 = Path(p1, p2, p3) # Spline with custom tangent directions path2 = Path(p1, p2, p3; tangents=(Point2f(1, 0), Point2f(1, 0)), tfactor=0.8) # Just two points - returns straight line path3 = Path(p1, p2) # Two points with tangents - returns bezier curve t1 = Point2f(1, 1) t2 = Point2f(-1, 0) path4 = Path(p1, p2; tangents=(t1, t2)) ``` -------------------------------- ### MoveTo Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md Path command to move the current point to a specified location without drawing a line. ```APIDOC ## MoveTo ```julia struct MoveTo{PT} <: PathCommand{PT} p::PT end ``` Path command to move to a point without drawing. ### Type Parameters - `PT` - Point type ### Fields | Field | Type | Description | |-------|------|-------------| | p | PT | Target point | ``` -------------------------------- ### tangent Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Get tangent vector at parameter t along path. For Line, returns normalized direction vector. For BezierPath, evaluates the derivative of the cubic Bezier at t. ```APIDOC ## tangent ### Description Get tangent vector at parameter t along path. ### Parameters - **p** (AbstractPath) - Yes - Path to sample - **t** (Number) - Yes - Parameter 0=start, 1=end ### Returns Point - Normalized tangent vector at parameter t ### Behavior - For Line: returns normalized direction vector - For BezierPath: evaluates derivative of cubic Bezier at t ### Example ```julia path = Path(Point2f(0,0), Point2f(1,1), Point2f(2,0)) dir = tangent(path, 0.5) # direction at midpoint ``` ``` -------------------------------- ### Basic Graph Plotting Source: https://github.com/makieorg/graphmakie.jl/blob/master/README.md Create a complete graph with 10 nodes and visualize it using the graphplot function. ```julia using GLMakie using GraphMakie using Graphs g = complete_graph(10) graphplot(g) ``` -------------------------------- ### Get Marker Scale Factor Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-utilities.md Retrieves the base size scaling factor for a given marker in pixels. The factor is used to determine the marker's size relative to a standard. Handles default, character, and symbol markers. ```julia scale_factor(marker) ``` -------------------------------- ### LineTo Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md Path command to draw a straight line from the current point to a specified target point. ```APIDOC ## LineTo ```julia struct LineTo{PT} <: PathCommand{PT} p::PT end ``` Path command to draw a line to a point. ### Type Parameters - `PT` - Point type ### Fields | Field | Type | Description | |-------|------|-------------| | p | PT | Target point | ``` -------------------------------- ### Custom Network Layouts Source: https://github.com/makieorg/graphmakie.jl/blob/master/docs/src/index.md Explains how to use custom layout functions with GraphMakie, including integration with NetworkLayout.jl and LayeredLayouts.jl. ```APIDOC ## Network Layouts The layout algorithms are provided by [`NetworkLayout.jl`](https://juliagraphs.org/NetworkLayout.jl/stable/). ### Description Defines and uses a custom network layout function. ### Method Custom function definition and usage within `graphplot`. ### Endpoint N/A (Julia function) ### Parameters A layout function must have the signature `f(g::AbstractGraph) -> pos::Vector{Point}`. ### Request Example ```julia using LayeredLayouts function mylayout(g::SimpleGraph) xs, ys, _ = solve_positions(Zarate(), g) return Point.(zip(xs, ys)) end # Usage within graphplot (example): # f, ax, p = graphplot(g, layout=mylayout) ``` ### Response The layout function returns a `Vector{Point}` representing the positions of the nodes. ``` -------------------------------- ### Create a Path with Bending Radius Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Defines a path with specified intermediate points and a bending radius for smooth curves. A radius of 0 results in sharp corners. ```julia points = Point2f[(0, 0), (2, 0), (2, 2), (0, 2)] path = Path(0.3, points...) ``` -------------------------------- ### Path Constructor for Rounded Corners Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Creates a path connecting multiple points with straight line segments and smooth rounded corners. The radius parameter controls the roundness. ```julia Path(radius::Real, p::Vararg{PT, N}) where {PT<:AbstractPoint, N} ``` -------------------------------- ### Managing Graph Attributes Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md Functions for managing vertex and edge attributes. `prep_vertex_attributes` and `prep_edge_attributes` prepare attributes for recipes, while `getattr` retrieves values and `issingleattribute` checks if a value is a single attribute. ```julia getattr(x, idx, default) ``` ```julia prep_vertex_attributes(attr, g, default) ``` ```julia prep_edge_attributes(attr, g, default) ``` ```julia issingleattribute(x) ``` -------------------------------- ### graphplot! Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-graphplot.md Creates a plot of the network graph with nodes and edges on a given Makie axis. It handles layout computation, edge rendering, arrow head rendering, and label rendering. ```APIDOC ## graphplot! ### Description Creates a plot of the network `graph` with nodes represented as scatter points and edges as line segments on a given Makie axis `ax`. The function performs layout computation, edge rendering, arrow head rendering, and label rendering in a single recipe. ### Method `graphplot!(ax, graph::AbstractGraph)` ### Parameters #### Path Parameters - **ax** (Makie.Axis) - Yes - Description: The Makie axis to plot on. - **graph** (AbstractGraph) - Yes - Description: Graph object from Graphs.jl with nodes and edges ### Returns `GraphPlot` - A Makie recipe object containing all plot data and attributes. The node positions are accessible via the `:node_pos` attribute observable. ### Main Attributes #### Layout - **layout** (AbstractLayout or Vector{Point}) - Default: Spring() - Description: Function to compute node positions or pre-computed position vector. Can be any NetworkLayout.jl layout (Spring, Stress, Spectral, etc.). If a vector is provided, length must match number of nodes. #### Node Styling - **node_color** (Color or Vector) - Default: automatic - Description: Color for nodes. Defaults to scatter theme color or gray80 with inner labels. Can be per-node. - **node_size** (Number or Vector) - Default: automatic - Description: Size of node markers. Defaults to scatter theme markersize. When ilabels provided, auto-sized based on label dimensions. Can be per-node. - **node_marker** (Symbol or Char) - Default: automatic - Description: Marker shape for nodes. Defaults to scatter theme marker (Circle). Can be per-node. - **node_strokewidth** (Number or Vector) - Default: automatic - Description: Stroke width for node borders. Defaults to scatter theme strokewidth. Can be per-node. - **node_attr** (NamedTuple) - Default: (;) - Description: Additional keyword arguments passed to scatter plot. #### Edge Styling - **edge_color** (Color or Vector) - Default: lineseg_theme.color - Description: Color for edges. Can be per-edge. - **edge_width** (Number or Vector or Dict) - Default: lineseg_theme.linewidth - Description: Width of edges. Can specify 2 widths per edge for tapering. Can be per-edge. - **edge_linestyle** (Symbol or Vector) - Default: :solid - Description: Line style for edges (:solid, :dash, :dot). Can be per-edge. - **edge_attr** (NamedTuple) - Default: (;) - Description: Additional keyword arguments passed to line plot. - **force_straight_edges** (Bool) - Default: false - Description: If true, draw all edges as straight lines ignoring curve attributes. #### Arrow Styling (Directed Graphs) - **arrow_show** (Bool or automatic) - Default: automatic - Description: Whether to show arrowheads. Defaults to true for directed graphs. - **arrow_marker** (Char or Symbol) - Default: '➤' - Description: Marker character/symbol for arrowheads. Can be per-edge. - **arrow_size** (Number or Vector) - Default: scatter_theme.markersize - Description: Size of arrowhead markers. Can be per-edge. - **arrow_shift** (Number or :end or Vector) - Default: 0.5 - Description: Position of arrowhead along edge (0=source, 1=destination). Use :end to place on destination node surface. Can be per-edge. - **arrow_attr** (NamedTuple) - Default: (;) - Description: Additional keyword arguments passed to scatter plot. #### Node Labels - **nlabels** (Vector{String} or nothing) - Default: nothing - Description: Text label for each node. - **nlabels_align** (Tuple{Symbol, Symbol} or Vector) - Default: (:left, :bottom) - Description: Text alignment (horizontal: :left/:center/:right, vertical: :top/:center/:bottom). Can be per-node. - **nlabels_distance** (Number or Vector) - Default: 0.0 - Description: Pixel distance from node in direction of alignment. Can be per-node. - **nlabels_offset** (Point or Vector{Point} or nothing) - Default: nothing - Description: Offset in data space for each label. Can be per-node. - **nlabels_color** (Color or Vector) - Default: labels_theme.color - Description: Color for node labels. Can be per-node. - **nlabels_fontsize** (Number or Vector) - Default: labels_theme.fontsize - Description: Font size for node labels. Can be per-node. - **nlabels_attr** (NamedTuple) - Default: (;) - Description: Additional keyword arguments passed to text plot. #### Inner Node Labels - **ilabels** (Vector or nothing) - Default: nothing - Description: Labels to place inside node markers. When provided, overrides default node styling. - **ilabels_color** (Color or Vector) - Default: labels_theme.color - Description: Color for inner labels. Can be per-node. - **ilabels_fontsize** (Number or Vector) - Default: labels_theme.fontsize - Description: Font size for inner labels. Can be per-node. - **ilabels_attr** (NamedTuple) - Default: (;) - Description: Additional keyword arguments passed to text plot. ``` -------------------------------- ### EdgePlot Recipe Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-edgeplot.md The EdgePlot recipe is an internal Makie component used for rendering a collection of edge paths. It supports styling attributes inherited from `Lines` and handles the discretization of paths into points for rendering. ```APIDOC ## EdgePlot ### Description Internal recipe that renders a collection of edge paths as continuous line segments with support for multiple linestyles and varying widths. ### Parameters #### Path Data - **paths** (Vector{AbstractPath}) - Required - Edge paths to render (Line or BezierPath objects) ### Attributes #### Path Data - **paths** (Vector{AbstractPath{PT}}) - Edge paths to discretize and render - **split_edgeplots** (Bool) - Internal flag: whether paths have different linestyles requiring separate plots - **points** (Vector{Point{N, Float32}}) - Discretized points from all edge paths - **ranges** (Vector{UnitRange{Int}}) - Point indices for each edge path #### Styling (inherited from Lines) - **color** (Color or Vector) - Line color. Can be per-edge. - **linewidth** (Number or Vector) - Line width. Can be per-edge. - **linestyle** (Symbol or Vector) - Line style (:solid, :dash, :dot, etc). Per-edge specification creates multiple plots. - **colorrange** (Tuple or automatic) - Color value range for colormap. - **colormap** (Symbol) - Colormap for numeric color values. - **alpha** (Number) - Transparency (0-1). - **overdraw** (Bool) - Whether to overdraw on top of existing plots. ``` -------------------------------- ### Interaction Types and Constructors Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md Defines types for interactive handlers like hover, drag, and click, and provides constructors for creating specific interaction behaviors. ```APIDOC ## Interaction Types and Constructors ### Description This section covers the types for interactive handlers (`GraphInteraction`, `HoverHandler`, `DragHandler`, `ClickHandler`) and the functions used to construct these handlers for nodes and edges. ### Interaction Types - `GraphInteraction`: Base type for interaction handlers. - `HoverHandler`: Generic hover event handler. - `DragHandler`: Generic drag event handler. - `ClickHandler`: Generic click event handler. ### Interaction Constructors - `NodeHoverHandler(fun)`: Creates a node hover handler. - `NodeHoverHighlight(p, factor)`: Pre-built node hover magnification. - `EdgeHoverHandler(fun)`: Creates an edge hover handler. - `EdgeHoverHighlight(p, factor)`: Pre-built edge hover magnification. - `NodeDragHandler(fun)`: Creates a node drag handler. - `NodeDrag(p)`: Pre-built node drag-and-drop. - `EdgeDragHandler(fun)`: Creates an edge drag handler. - `EdgeDrag(p)`: Pre-built edge drag-and-drop. - `NodeClickHandler(fun)`: Creates a node click handler. - `EdgeClickHandler(fun)`: Creates an edge click handler. ``` -------------------------------- ### Discretize Path to Points Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Converts an AbstractPath into a vector of points. For BezierPaths, this involves evaluating segments with a default of 60 points. ```julia path = Path(Point2f(0,0), Point2f(1,1), Point2f(2,0)) points = discretize(path) ``` -------------------------------- ### graphplot() and graphplot!() Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md Functions to create and update graph visualizations. `graphplot()` creates a new visualization, while `graphplot!()` plots into an existing axis. ```APIDOC ## `graphplot()` and `graphplot!()` ### Description Creates a new graph visualization or plots a graph into an existing axis. ### Functions - `graphplot(graph, ...)`: Creates a new graph visualization. - `graphplot!(axis, graph, ...)`: Plots a graph into the specified existing axis. ### Purpose These are the main functions for initiating graph visualizations in GraphMakie.jl. ``` -------------------------------- ### Graph Plot with Labels and Colors Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/README.md Shows how to add node labels, distinguish nodes by color, and set node sizes in a GraphMakie plot. Uses the `distinguishers` function for coloring. ```julia f, ax, p = graphplot(g, nlabels = string.(1:nv(g)) , node_color = distinguishers(g), node_size = 20 ) ``` -------------------------------- ### Path Functions Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md Functions for creating and manipulating paths. ```APIDOC ## Path(points...; tangents=nothing, tfactor=0.5) ### Description Create a path from a series of points. ### Function Signature `Path(points...; tangents=nothing, tfactor=0.5)` ### Parameters - **points**: A variable number of points defining the path. - **tangents**: Optional tangents for the path. - **tfactor**: Tangent factor (default: 0.5). ## Path(radius, points...) ### Description Create a path with a specified radius from a series of points. ### Function Signature `Path(radius, points...)` ### Parameters - **radius**: The radius of the path. - **points**: A variable number of points defining the path. ## interpolate(path, t) ### Description Interpolate a point on the path at a given parameter `t`. ### Function Signature `interpolate(path, t)` ### Parameters - **path**: The path object. - **t**: The interpolation parameter (0 to 1). ## inverse_interpolate(path, pt) ### Description Find the parameter `t` for a given point on the path. ### Function Signature `inverse_interpolate(path, pt)` ### Parameters - **path**: The path object. - **pt**: The point on the path. ## tangent(path, t) ### Description Get the tangent vector at a given parameter `t` on the path. ### Function Signature `tangent(path, t)` ### Parameters - **path**: The path object. - **t**: The parameter value. ## discretize(path) ### Description Discretize the path into a series of line segments. ### Function Signature `discretize(path)` ### Parameters - **path**: The path object. ## isline(path) ### Description Check if the path is a straight line. ### Function Signature `isline(path)` ### Parameters - **path**: The path object. ## straighten(path) ### Description Convert a curved path into a straight line. ### Function Signature `straighten(path)` ### Parameters - **path**: The path object. ## adjust_endpoint(path, p) ### Description Adjust the endpoint of a path to a new point. ### Function Signature `adjust_endpoint(path, p)` ### Parameters - **path**: The path object. - **p**: The new endpoint. ``` -------------------------------- ### NodeHoverHighlight Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-interactions.md A pre-built handler designed to visually highlight nodes on hover by magnifying their size. It simplifies the process of adding hover effects without manual callback implementation. ```APIDOC ## NodeHoverHighlight Pre-built handler that magnifies the node_size when hovering. Requires `node_size` to be a `Vector{<:Real}`. ### Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | p | GraphPlot | Yes | — | The graph plot to modify on hover | | factor | Real | No | 2 | Magnification factor (node_size * factor on hover) | ### Returns `HoverHandler{Scatter, Function}` - Preconfigured handler ### Throws `AssertionError` - If `node_size` is not a `Vector{<:Real}` ### Example ```julia g = wheel_graph(10) f, ax, p = graphplot(g, node_size = [20 for i in 1:nv(g)]) register_interaction!(ax, :nodehover, NodeHoverHighlight(p)) ``` ``` -------------------------------- ### CurveTo Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md Path command to draw a cubic Bezier curve to a specified end point, using two control points. ```APIDOC ## CurveTo ```julia struct CurveTo{PT} <: PathCommand{PT} c1::PT c2::PT p::PT end ``` Path command to draw a cubic Bezier curve to a point with two control points. ### Type Parameters - `PT` - Point type ### Fields | Field | Type | Description | |-------|------|-------------| | c1 | PT | First control point | | c2 | PT | Second control point | | p | PT | End point | ``` -------------------------------- ### Per-Element Customization with Vectors Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/configuration.md Styles individual nodes and edges using vectors of attributes. Allows for fine-grained control over each element's appearance. ```julia graphplot(g, node_color = [:red, :blue, :green, :yellow, :purple], node_size = [10, 20, 15, 25, 20], edge_color = [i % 2 == 0 ? :solid : :dash for i in 1:ne(g)], edge_width = [rand()*3 for i in 1:ne(g)] ) ``` -------------------------------- ### discretize Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-paths.md Return vector of points representing the path. For Line, returns [p0, p]. For BezierPath, evaluates each CurveTo with 60 points, merging with MoveTo/LineTo points. ```APIDOC ## discretize ### Description Return vector of points representing the path. ### Parameters - **path** (AbstractPath) - Yes - Path to discretize ### Returns `Vector{PT}` - Sequence of points along the path ### Behavior - For Line: returns [p0, p] - For BezierPath: evaluates each CurveTo with 60 points, merges with MoveTo/LineTo points ### Example ```julia path = Path(Point2f(0,0), Point2f(1,1), Point2f(2,0)) points = discretize(path) ``` ``` -------------------------------- ### Define Custom Network Layout Source: https://github.com/makieorg/graphmakie.jl/blob/master/docs/src/index.md Create a custom network layout function using external packages like LayeredLayouts.jl. Ensure the function accepts an AbstractGraph and returns a Vector of Points. ```julia using LayeredLayouts function mylayout(g::SimpleGraph) xs, ys, _ = solve_positions(Zarate(), g) return Point.(zip(xs, ys)) end ``` -------------------------------- ### Graph Plotting Recipe Source: https://github.com/makieorg/graphmakie.jl/blob/master/docs/src/index.md The `graphplot` recipe is the main function for plotting graphs in GraphMakie.jl. It accepts various arguments for customization. ```APIDOC ## The `graphplot` Recipe This is the main plotting recipe for graphs. ### Description Plots a graph using the `graphplot` function. ### Method `graphplot` ### Endpoint N/A (Julia function) ### Parameters This function accepts various keyword arguments for customization, including: - `edge_width` (Vector): Specifies the width of edges. - `node_size` (Vector): Specifies the size of nodes. ### Request Example ```julia using GLMakie using GraphMakie using Graphs g = wheel_graph(10) f, ax, p = graphplot(g, edge_width=[3 for i in 1:ne(g)], node_size=[10 for i in 1:nv(g)]) ``` ### Response Returns a tuple containing the figure, axis, and plot object. #### Success Response (200) - `f` (Figure): The Makie figure object. - `ax` (Axis): The Makie axis object. - `p` (Plot): The graph plot object. #### Response Example ```julia (f, ax, p) ``` ``` -------------------------------- ### Minimal Graph Plot Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/configuration.md Generates a complete graph with 5 nodes using default styling. This is the most basic way to visualize a graph. ```julia g = complete_graph(5) graphplot(g) # Uses all defaults ``` -------------------------------- ### Point and Alignment Conversion Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md Convert coordinates to `Point{N, Float32}` using `to_pointf32`. Convert text alignment to a direction vector using `align_to_dir`. ```julia to_pointf32(p) ``` ```julia align_to_dir(align) ``` -------------------------------- ### Interaction Handlers Source: https://github.com/makieorg/graphmakie.jl/blob/master/docs/src/index.md Details on the available interaction handler types for nodes and edges, including click, hover, and drag. ```APIDOC ## Interaction Interface `GraphMakie.jl` provides helper functions to register interactions. ### Description This section documents the various interaction handler types available for nodes and edges. ### Method Interaction handler types (e.g., `NodeClickHandler`, `EdgeHoverHandler`). ### Endpoint N/A (Julia types) ### Available Interaction Handlers: #### Click Interactions - `NodeClickHandler`: Handles click events on nodes. - `EdgeClickHandler`: Handles click events on edges. #### Hover Interactions - `NodeHoverHandler`: Handles hover events on nodes. - `EdgeHoverHandler`: Handles hover events on edges. #### Drag Interactions - `NodeDragHandler`: Handles drag events for nodes. - `EdgeDragHandler`: Handles drag events for edges. ### Usage These handlers are typically instantiated and then registered with an axis using `register_interaction!`. ``` -------------------------------- ### Create NodeHoverHandler Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-interactions.md Creates a hover handler specifically for nodes. It takes a callback function that is invoked when the mouse enters or leaves a node. ```julia NodeHoverHandler(fun::F) where {F} ``` ``` ```julia g = wheel_digraph(10) f, ax, p = graphplot(g, node_size = [20 for i in 1:nv(g)]) function action(state, idx, event, axis) p.node_size[][idx] = state ? 40 : 20 p.node_size[] = p.node_size[] # trigger observable end register_interaction!(ax, :nodehover, NodeHoverHandler(action)) ``` -------------------------------- ### Create EdgeHoverHandler Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-interactions.md Creates a hover handler for edges, invoking a callback function when the mouse enters or leaves an edge. ```julia EdgeHoverHandler(fun::F) where {F} ``` ``` ```julia g = wheel_digraph(10) f, ax, p = graphplot(g, edge_width = [3.0 for i in 1:ne(g)]) function action(state, idx, event, axis) p.edge_width[][idx] = state ? 6.0 : 3.0 p.edge_width[] = p.edge_width[] # trigger observable end register_interaction!(ax, :edgehover, EdgeHoverHandler(action)) ``` -------------------------------- ### plot_controlpoints! Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-utilities.md Visualizes Bezier control points and tangent lines for debugging curved edges in graph plots. ```APIDOC ## plot_controlpoints! ### Description Visualize Bezier control points for debugging curved edges. ### Parameters - **ax** (Axis) - Required - Axis to plot into - **gp or p** (GraphPlot or BezierPath) - Required - Graph plot or path to debug - **color** (Symbol or Color) - Optional - Default is :black. Color for control point visualization ### Behavior - For GraphPlot: plots all control points from all edges - For BezierPath: plots control points as dots and tangent lines as dashed segments ### Example ```julia f, ax, p = graphplot(g, waypoints=Dict(...)) plot_controlpoints!(ax, p) # visualize control points ``` ``` -------------------------------- ### MoveTo Struct Definition Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md A path command to move to a specified point without drawing a line. ```julia struct MoveTo{PT} <: PathCommand{PT} p::PT end ``` -------------------------------- ### Path Types and Construction Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md Defines the types for representing paths, including straight lines and Bezier curves, and provides functions for path construction and manipulation. ```APIDOC ## Path Types and Construction ### Description This section details the types used for path abstractions, such as `Line` and `BezierPath`, and the functions available for creating and manipulating these paths. ### Path Types - `AbstractPath`: Base type for all path representations. - `Line`: Represents a straight line segment. - `BezierPath`: Represents piecewise cubic Bezier curves. - `PathCommand`: Base for path drawing commands (`MoveTo`, `LineTo`, `CurveTo`). ### Path Construction Functions - `Path(points...)`: Creates a path via cubic spline interpolation. - `Path(radius, points...)`: Creates a path with rounded corners. ``` -------------------------------- ### to_pointf32 Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-utilities.md Converts various input types (Points, tuples, vectors, or arguments) into a Point{N, Float32} format. ```APIDOC ## to_pointf32 ### Description Convert point or coordinates to Point{N, Float32}. ### Parameters - **p** (Point{N,T}, NTuple{N,T}, StaticVector{N,T}, Vararg{T,N}, Vector{T}) - Required - Coordinates to convert ### Returns `Point{N, Float32}` - Converted point ### Example ```julia p1 = to_pointf32((1.0, 2.0)) # Point2f(1.0, 2.0) p2 = to_pointf32([1, 2, 3]) # Point3f(1.0, 2.0, 3.0) p3 = to_pointf32(1.0, 2.0) # Point2f(1.0, 2.0) ``` ``` -------------------------------- ### Define EdgePlot Recipe Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-edgeplot.md Defines the internal EdgePlot recipe, inheriting attributes from Makie's Lines. This sets up the basic structure for rendering edge paths. ```julia @recipe EdgePlot (paths,) begin Makie.documented_attributes(Lines)... end ``` -------------------------------- ### Directed Graph with Custom Arrow Styling Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-graphplot.md Creates a directed graph plot with custom arrow styles, including marker, size, and shift. Requires GraphMakie, Graphs, and GLMakie libraries. ```julia g = SimpleDiGraph(10) for i in 1:9 add_edge!(g, i, i+1) end f, ax, p = graphplot( g, arrow_show = true, arrow_marker = '➤', arrow_size = 20, arrow_shift = 0.8 ) ``` -------------------------------- ### Define GraphPlot Recipe Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md Defines the main recipe type for graph visualization, parametrized by the graph object. It serves as the base for graph plotting functions and interaction handlers. ```julia ```julia @recipe(GraphPlot, graph) do scene # ... attributes definition end ``` ``` -------------------------------- ### PathCommand Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md Base type for path drawing commands used within BezierPath. It has subtypes for moving, drawing lines, and drawing curves. ```APIDOC ## PathCommand ```julia abstract type PathCommand{PT<:AbstractPoint} end ``` Base type for path drawing commands within BezierPath. ### Type Parameters - `PT<:AbstractPoint` - Point type ### Subtypes - `MoveTo{PT}` - Move to point without drawing - `LineTo{PT}` - Draw line to point - `CurveTo{PT}` - Draw cubic Bezier curve to point with control points ``` -------------------------------- ### GraphMakie Public Exports Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/INDEX.md List of all public exports from the main GraphMakie module, including types, functions for plotting, interaction handlers, and utility functions. ```julia GraphPlot, graphplot, graphplot!, Arrow NodeHoverHandler, EdgeHoverHandler NodeHoverHighlight, EdgeHoverHighlight NodeClickHandler, EdgeClickHandler NodeDragHandler, EdgeDragHandler NodeDrag, EdgeDrag get_edge_plot, get_arrow_plot, get_node_plot get_nlabel_plot, get_elabel_plot ``` -------------------------------- ### LineTo Struct Definition Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md A path command to draw a straight line to a specified point. ```julia struct LineTo{PT} <: PathCommand{PT} p::PT end ``` -------------------------------- ### NodeHoverHandler Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/api-reference-interactions.md Creates a hover handler specifically for nodes. It allows you to register a callback function that will be invoked whenever the mouse pointer enters or leaves a node, enabling dynamic visual feedback. ```APIDOC ## NodeHoverHandler Creates a hover handler for nodes. Invokes callback on hover state changes. ### Parameters | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | fun | Function | Yes | Callback function signature: `fun(hoverstate, idx, event, axis)` where hoverstate is Bool, idx is the node index ### Returns `HoverHandler{Scatter, F}` - Configured handler for node hover events ### Behavior The callback is called with: - `hoverstate=true` when mouse enters a node - `hoverstate=false` when mouse leaves the node - `idx` - the node index (1-based) - `event` - MouseEvent object - `axis` - the axis where the event occurred ### Example ```julia g = wheel_digraph(10) f, ax, p = graphplot(g, node_size = [20 for i in 1:nv(g)]) function action(state, idx, event, axis) p.node_size[][idx] = state ? 40 : 20 p.node_size[] = p.node_size[] # trigger observable end register_interaction!(ax, :nodehover, NodeHoverHandler(action)) ``` ``` -------------------------------- ### AbstractPath Source: https://github.com/makieorg/graphmakie.jl/blob/master/_autodocs/types.md Base type for all path representations, parametrized by point type. Paths can be interpolated, discretized, and manipulated. ```APIDOC ## AbstractPath ```julia abstract type AbstractPath{PT<:AbstractPoint} end ``` Base type for all path representations parametrized by point type. ### Type Parameters - `PT<:AbstractPoint` - Point type (Point2, Point3, etc.) ### Subtypes - `Line{PT}` - Straight line segment - `BezierPath{PT}` - Piecewise cubic Bezier curve ### Behavior Paths can be interpolated, discretized, and manipulated to represent edge curves and shapes. ```