use abstracttui::base::Size;
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
pub enum Direction {
#[default]
TopDown,
LeftRight,
BottomTop,
RightLeft,
}
impl Direction {
pub const fn is_vertical(self) -> bool {
matches!(self, Direction::TopDown | Direction::BottomTop)
}
pub const fn is_reversed(self) -> bool {
matches!(self, Direction::BottomTop | Direction::RightLeft)
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct NodeDesc {
pub id: String,
pub size: Size,
pub kind: Option<String>,
pub label: Option<String>,
}
impl NodeDesc {
pub fn new(id: impl Into<String>, w: i32, h: i32) -> Self {
NodeDesc {
id: id.into(),
size: Size::new(w, h),
..Default::default()
}
}
pub fn kind(mut self, kind: impl Into<String>) -> Self {
self.kind = Some(kind.into());
self
}
pub fn label(mut self, label: impl Into<String>) -> Self {
self.label = Some(label.into());
self
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct EdgeDesc {
pub from: String,
pub to: String,
pub label: Option<String>,
pub style: Option<String>,
}
impl EdgeDesc {
pub fn new(from: impl Into<String>, to: impl Into<String>) -> Self {
EdgeDesc {
from: from.into(),
to: to.into(),
..Default::default()
}
}
pub fn label(mut self, label: impl Into<String>) -> Self {
self.label = Some(label.into());
self
}
pub fn style(mut self, style: impl Into<String>) -> Self {
self.style = Some(style.into());
self
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct GraphDesc {
pub nodes: Vec<NodeDesc>,
pub edges: Vec<EdgeDesc>,
}
impl GraphDesc {
pub fn new() -> Self {
GraphDesc::default()
}
pub fn node(mut self, id: impl Into<String>, w: i32, h: i32) -> Self {
self.nodes.push(NodeDesc::new(id, w, h));
self
}
pub fn with_node(mut self, node: NodeDesc) -> Self {
self.nodes.push(node);
self
}
pub fn edge(mut self, from: impl Into<String>, to: impl Into<String>) -> Self {
self.edges.push(EdgeDesc::new(from, to));
self
}
pub fn with_edge(mut self, edge: EdgeDesc) -> Self {
self.edges.push(edge);
self
}
}