use ratatui::style::Color;
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum NodeStatus {
#[default]
Healthy,
Degraded,
Down,
Unknown,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum NodeShape {
#[default]
Rectangle,
RoundedRectangle,
Diamond,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum EdgeStyle {
#[default]
Solid,
Dashed,
Dotted,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum LayoutMode {
#[default]
Hierarchical,
ForceDirected,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum RenderMode {
#[default]
BoxDrawing,
Braille,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub enum Orientation {
#[default]
LeftToRight,
TopToBottom,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct DiagramNode {
id: String,
label: String,
status: NodeStatus,
color: Option<Color>,
shape: NodeShape,
metadata: Vec<(String, String)>,
cluster_id: Option<String>,
}
impl DiagramNode {
pub fn new(id: impl Into<String>, label: impl Into<String>) -> Self {
Self {
id: id.into(),
label: label.into(),
status: NodeStatus::default(),
color: None,
shape: NodeShape::default(),
metadata: Vec::new(),
cluster_id: None,
}
}
pub fn with_status(mut self, status: NodeStatus) -> Self {
self.status = status;
self
}
pub fn with_color(mut self, color: Color) -> Self {
self.color = Some(color);
self
}
pub fn with_shape(mut self, shape: NodeShape) -> Self {
self.shape = shape;
self
}
pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.metadata.push((key.into(), value.into()));
self
}
pub fn with_cluster(mut self, cluster_id: impl Into<String>) -> Self {
self.cluster_id = Some(cluster_id.into());
self
}
pub fn id(&self) -> &str {
&self.id
}
pub fn label(&self) -> &str {
&self.label
}
pub fn status(&self) -> &NodeStatus {
&self.status
}
pub fn set_status(&mut self, status: NodeStatus) {
self.status = status;
}
pub fn color(&self) -> Option<Color> {
self.color
}
pub fn set_color(&mut self, color: Option<Color>) {
self.color = color;
}
pub fn shape(&self) -> &NodeShape {
&self.shape
}
pub fn metadata(&self) -> &[(String, String)] {
&self.metadata
}
pub fn cluster_id(&self) -> Option<&str> {
self.cluster_id.as_deref()
}
pub fn set_label(&mut self, label: impl Into<String>) {
self.label = label.into();
}
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct DiagramEdge {
from: String,
to: String,
label: Option<String>,
color: Option<Color>,
style: EdgeStyle,
bidirectional: bool,
}
impl DiagramEdge {
pub fn new(from: impl Into<String>, to: impl Into<String>) -> Self {
Self {
from: from.into(),
to: to.into(),
label: None,
color: None,
style: EdgeStyle::default(),
bidirectional: false,
}
}
pub fn with_label(mut self, label: impl Into<String>) -> Self {
self.label = Some(label.into());
self
}
pub fn with_color(mut self, color: Color) -> Self {
self.color = Some(color);
self
}
pub fn with_style(mut self, style: EdgeStyle) -> Self {
self.style = style;
self
}
pub fn with_bidirectional(mut self, bidirectional: bool) -> Self {
self.bidirectional = bidirectional;
self
}
pub fn from(&self) -> &str {
&self.from
}
pub fn to(&self) -> &str {
&self.to
}
pub fn label(&self) -> Option<&str> {
self.label.as_deref()
}
pub fn color(&self) -> Option<Color> {
self.color
}
pub fn set_color(&mut self, color: Option<Color>) {
self.color = color;
}
pub fn style(&self) -> &EdgeStyle {
&self.style
}
pub fn bidirectional(&self) -> bool {
self.bidirectional
}
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serialization",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct DiagramCluster {
id: String,
label: String,
color: Option<Color>,
}
impl DiagramCluster {
pub fn new(id: impl Into<String>, label: impl Into<String>) -> Self {
Self {
id: id.into(),
label: label.into(),
color: None,
}
}
pub fn with_color(mut self, color: Color) -> Self {
self.color = Some(color);
self
}
pub fn id(&self) -> &str {
&self.id
}
pub fn label(&self) -> &str {
&self.label
}
pub fn color(&self) -> Option<Color> {
self.color
}
pub fn set_color(&mut self, color: Option<Color>) {
self.color = color;
}
pub fn set_label(&mut self, label: impl Into<String>) {
self.label = label.into();
}
}