#![allow(clippy::derive_partial_eq_without_eq)]
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq)]
pub enum GraphEvent {
AddNode {
id: String,
label: Option<String>,
node_type: NodeType,
properties: Properties,
},
UpdateNode {
id: String,
label: Option<String>,
properties: Properties,
},
RemoveNode { id: String },
AddEdge {
id: String,
from: String,
to: String,
edge_type: EdgeType,
label: Option<String>,
properties: Properties,
},
UpdateEdge {
id: String,
label: Option<String>,
properties: Properties,
},
RemoveEdge { id: String },
AddGroup {
id: String,
label: Option<String>,
members: Vec<String>,
group_type: GroupType,
properties: Properties,
},
UpdateGroup { id: String, members: Vec<String> },
RemoveGroup { id: String },
SetLayout {
layout_type: LayoutType,
properties: Properties,
},
Clear,
BatchStart,
BatchEnd,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NodeType {
Node,
Actor { actor_type: String },
State { state_type: StateType },
Process,
DataStore,
External,
Custom(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StateType {
Initial,
Final,
Normal,
Composite,
History,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EdgeType {
Directed,
Undirected,
Bidirectional,
Message {
message_type: MessageType,
sequence: Option<u32>,
},
Transition {
trigger: Option<String>,
guard: Option<String>,
action: Option<String>,
},
Association { association_type: String },
Custom(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MessageType {
Synchronous,
Asynchronous,
Return,
Create,
Destroy,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GroupType {
Cluster,
Sequential { sequence_type: String },
Parallel,
Container,
Custom(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LayoutType {
Hierarchical { direction: Direction },
Force,
Circular,
Grid { columns: Option<u32> },
Sequential { direction: Direction },
Layered { direction: Direction },
Custom(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Direction {
TopToBottom,
BottomToTop,
LeftToRight,
RightToLeft,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Properties {
pub style: Option<Style>,
pub position: Option<Position>,
pub custom: HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Style {
pub color: Option<String>,
pub background_color: Option<String>,
pub border_style: Option<String>,
pub border_color: Option<String>,
pub border_width: Option<f32>,
pub shape: Option<String>,
pub size: Option<f32>,
pub font_size: Option<f32>,
pub font_family: Option<String>,
pub opacity: Option<f32>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Position {
Absolute { x: f32, y: f32, z: Option<f32> },
Relative {
anchor: String,
offset_x: f32,
offset_y: f32,
offset_z: Option<f32>,
},
Grid { row: u32, column: u32 },
Sequential { order: u32 },
Layer { level: u32 },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EventResult {
Success,
NodeExists(String),
NodeNotFound(String),
EdgeExists(String),
EdgeNotFound(String),
Invalid(String),
}
impl GraphEvent {
pub fn simple_node(id: impl Into<String>, label: impl Into<String>) -> Self {
Self::AddNode {
id: id.into(),
label: Some(label.into()),
node_type: NodeType::Node,
properties: Properties::default(),
}
}
pub fn simple_edge(from: impl Into<String>, to: impl Into<String>) -> Self {
let from = from.into();
let to = to.into();
Self::AddEdge {
id: format!("{from}->{to}"),
from,
to,
edge_type: EdgeType::Directed,
label: None,
properties: Properties::default(),
}
}
}