layout icon indicating copy to clipboard operation
layout copied to clipboard

Feature request: add geometry methods to support edge rendering edge case

Open NathanWEdwards opened this issue 1 year ago • 0 comments

Given more than one edge between two nodes exists, all sibling edges should be spaced appropriately to minimize intersections and overlapping between siblings.

In this example, the dashed and normal edges between Node 1 and Node 2 follow along the same path between nodes.

use layout::adt::dag::NodeHandle;
use layout::core::base::Orientation;
use layout::core::style::LineStyleKind;
use layout::core::style::StyleAttr;
use layout::std_shapes::shapes::Element;
use layout::std_shapes::shapes::LineEndKind;
use layout::std_shapes::shapes::ShapeKind;

let mut svg_writer: layout::backends::svg::SVGWriter = layout::backends::svg::SVGWriter::new();
let mut graph: layout::topo::layout::VisualGraph = layout::topo::layout::VisualGraph::new(layout::core::base::Orientation::LeftToRight);

let node_1: Element = Element::create(
    ShapeKind::new_circle(&"Node 1"),
    StyleAttr::simple(),
    Orientation::LeftToRight,
    layout::core::geometry::Point::new(100., 100.));
let node_2: Element = Element::create(
    ShapeKind::new_circle(&"Node 2"),
    StyleAttr::simple(),
    Orientation::LeftToRight,
    layout::core::geometry::Point::new(100., 100.));
let handle_1: NodeHandle = graph.add_node(node_1);
let handle_2: NodeHandle = graph.add_node(node_2);
// Dashed edge.
graph.add_edge(layout::std_shapes::shapes::Arrow::new(
    LineEndKind::Arrow,
    LineEndKind::None,
    LineStyleKind::Dashed,
    &"",
    &StyleAttr::simple(),
    &None,
    &None),
    handle_2,
    handle_1);
// Normal edge
graph.add_edge(layout::std_shapes::shapes::Arrow::new(
    LineEndKind::Arrow,
    LineEndKind::None,
    LineStyleKind::Normal,
    &"",
    &StyleAttr::simple(),
    &None,
    &None),
    handle_1,
    handle_2);

graph.do_it(false, false, false, &mut svg_writer);
std::fs::write(path, &svg_writer.finalize());

edges

NathanWEdwards avatar Jul 06 '23 16:07 NathanWEdwards