use std::sync::Arc;
use crate::style::Color;
use crate::style::Style;
use crate::widgets::gantt_diagram::GanttSpec;
#[derive(Clone, Debug, PartialEq)]
pub enum ParsedDiagram {
Flowchart(FlowchartSpec),
Sequence(SequenceSpec),
Class(ClassSpec),
State(StateSpec),
Er(ErSpec),
Pie(PieSpec),
Gantt(GanttSpec),
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum DiagramDirection {
#[default]
TopDown,
BottomUp,
LeftRight,
RightLeft,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum FlowNodeShape {
#[default]
Rect,
Round,
Diamond,
Circle,
Cylinder,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FlowNodeSpec {
pub id: Arc<str>,
pub label: Arc<str>,
pub shape: FlowNodeShape,
pub style: NodeStyle,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct NodeStyle {
pub fill: Option<Color>,
pub label_fg: Option<Color>,
pub border_fg: Option<Color>,
}
impl NodeStyle {
#[cfg(feature = "markdown")]
pub(crate) fn merge(&mut self, other: Self) {
self.fill = other.fill.or(self.fill);
self.label_fg = other.label_fg.or(self.label_fg);
self.border_fg = other.border_fg.or(self.border_fg);
}
pub(super) fn fill_style(self) -> Style {
Style {
bg: self.fill.map(Into::into),
..Style::default()
}
}
pub(super) fn label_style(self) -> Style {
Style {
fg: self.label_fg.map(Into::into),
..Style::default()
}
}
pub(super) fn border_style(self) -> Style {
Style {
fg: self.border_fg.map(Into::into),
..Style::default()
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FlowEdgeSpec {
pub from: Arc<str>,
pub to: Arc<str>,
pub label: Option<Arc<str>>,
pub dashed: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FlowchartSpec {
pub direction: DiagramDirection,
pub nodes: Vec<FlowNodeSpec>,
pub edges: Vec<FlowEdgeSpec>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SequenceParticipantSpec {
pub id: Arc<str>,
pub label: Arc<str>,
pub actor: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SequenceMessageSpec {
pub from: Arc<str>,
pub to: Arc<str>,
pub label: Arc<str>,
pub dashed: bool,
pub open_arrow: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SequenceSpec {
pub participants: Vec<SequenceParticipantSpec>,
pub messages: Vec<SequenceMessageSpec>,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ClassVisibilitySpec {
#[default]
Public,
Private,
Protected,
Package,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClassMemberSpec {
pub visibility: ClassVisibilitySpec,
pub name: Arc<str>,
pub ty: Option<Arc<str>>,
pub method: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClassNodeSpec {
pub name: Arc<str>,
pub members: Vec<ClassMemberSpec>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClassRelationSpec {
pub from: Arc<str>,
pub to: Arc<str>,
pub arrow: Arc<str>,
pub from_cardinality: Option<Arc<str>>,
pub to_cardinality: Option<Arc<str>>,
pub label: Option<Arc<str>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ClassSpec {
pub classes: Vec<ClassNodeSpec>,
pub relations: Vec<ClassRelationSpec>,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum StateKindSpec {
#[default]
State,
Start,
End,
Choice,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StateNodeSpec {
pub id: Arc<str>,
pub label: Arc<str>,
pub kind: StateKindSpec,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StateTransitionSpec {
pub from: Arc<str>,
pub to: Arc<str>,
pub label: Option<Arc<str>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StateSpec {
pub states: Vec<StateNodeSpec>,
pub transitions: Vec<StateTransitionSpec>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ErAttributeSpec {
pub ty: Arc<str>,
pub name: Arc<str>,
pub keys: Vec<Arc<str>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ErEntitySpec {
pub name: Arc<str>,
pub attributes: Vec<ErAttributeSpec>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ErRelationSpec {
pub left: Arc<str>,
pub right: Arc<str>,
pub left_cardinality: Arc<str>,
pub right_cardinality: Arc<str>,
pub label: Option<Arc<str>>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ErSpec {
pub entities: Vec<ErEntitySpec>,
pub relations: Vec<ErRelationSpec>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct PieSliceSpec {
pub label: Arc<str>,
pub value: f64,
}
#[derive(Clone, Debug, PartialEq)]
pub struct PieSpec {
pub title: Option<Arc<str>>,
pub slices: Vec<PieSliceSpec>,
}