Skip to main content
Rust4PM

LayoutRequest

A layered-layout request: the graph, the preset its options start from, and the fields of that preset to change.

Every part defaults, so {} is a valid request (an empty graph, the layered preset).

use graphlay::json::LayoutRequest;
use graphlay::{Direction, RoutingStyle};

let request: LayoutRequest = serde_json::from_str(r#"{
    "graph": {"nodes": [{"size": {"width": 80, "height": 40}},
                        {"size": {"width": 80, "height": 40}}],
              "edges": [{"source": 0, "target": 1}]},
    "preset": "process_map",
    "options": {"routing": {"style": "diagonal"}}
}"#)?;
let (graph, options) = request.split()?;
assert_eq!(options.routing.style, RoutingStyle::Diagonal); // from the patch
assert_eq!(options.direction, Direction::TopBottom); // from the preset
let l = graphlay::layout(&graph, &options)?;
assert!(l.nodes[0].center.y < l.nodes[1].center.y);

// A bad patch is an error that names the field.
let bad: LayoutRequest =
    serde_json::from_str(r#"{"options": {"routing": {"style": "curvy"}}}"#)?;
assert!(bad.split().unwrap_err().starts_with("options.routing.style:"));
# Ok::<(), Box<dyn std::error::Error>>(())
Used as Input

2

functions accept this type

Used as Output

0

functions return this type(+7 nested)

Type Definition

262 nested items
struct— A layered-layout request: the graph, the preset its options start from, and the fields of
graph:Graph= {...}— The graph to lay out: nodes addressed by index, edges referring to those indices.
options:LayoutOptions= null— Everything that steers one layout run.
seed:u32= 0— Seed for the crossing minimisation's restarts and kicks. The same seed gives the same
preset:Preset= "layered"— A named starting point for LayoutOptions, so a caller or a JSON request
variant 1:"layered"— LayoutOptions::layered_default, for Petri nets.
variant 2:"process_map"— LayoutOptions::process_map, for directly-follows graphs.
variant 3:"hub_and_spoke"— LayoutOptions::hub_and_spoke, for dense relationship graphs.
variant 4:"hub_and_spoke_flow"— LayoutOptions::hub_and_spoke_flow, for dense graphs with a direction of flow.

Example JSON Value

{}

Functions Accepting This Type(2)