rs_graph/
draw.rs

1// Copyright (c) 2016, 2017, 2018, 2021 Frank Fischer <frank-fischer@shadow-soft.de>
2//
3// This program is free software: you can redistribute it and/or
4// modify it under the terms of the GNU General Public License as
5// published by the Free Software Foundation, either version 3 of the
6// License, or (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful, but
9// WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11// General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program.  If not, see  <http://www.gnu.org/licenses/>
15
16//! Visualizing graphs.
17
18use crate::traits::GraphType;
19
20/// Trait for node attributes.
21pub trait NodeAttr {
22    fn set_name(&mut self, name: Option<&str>);
23
24    fn set_label(&mut self, label: Option<usize>);
25}
26
27/// Trait for edge attributes.
28pub trait EdgeAttr {
29    fn set_name(&mut self, name: Option<&str>);
30
31    fn set_label(&mut self, label: Option<usize>);
32}
33
34/// Trait for drawing sequences of graphs.
35pub trait GraphDrawer<'a, G>
36where
37    G: GraphType,
38{
39    type NodeAttr: NodeAttr;
40
41    type EdgeAttr: EdgeAttr;
42
43    /// Return the default node attribute.
44    fn node_default(&self) -> &Self::NodeAttr;
45
46    /// Return the default node attribute.
47    fn node_default_mut(&mut self) -> &mut Self::NodeAttr;
48
49    /// Return the attributes of a node.
50    fn node(&self, u: G::Node<'_>) -> &Self::NodeAttr;
51
52    /// Return the attributes of a node.
53    fn node_mut(&mut self, u: G::Node<'_>) -> &mut Self::NodeAttr;
54
55    /// Return the default edge attribute.
56    fn edge_default(&self) -> &Self::EdgeAttr;
57
58    /// Return the default edge attribute.
59    fn edge_default_mut(&mut self) -> &mut Self::EdgeAttr;
60
61    /// Return the attributes of an edge.
62    fn edge(&self, e: G::Edge<'_>) -> &Self::EdgeAttr;
63
64    /// Return the attributes of an edge.
65    fn edge_mut(&mut self, e: G::Edge<'_>) -> &mut Self::EdgeAttr;
66
67    /// Add drawing with current attributes.
68    fn add_drawing(&mut self);
69}