disposition_input_model/
input_diagram.rs

1use disposition_model_common::theme::Css;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5    entity::{EntityDescs, EntityTypes},
6    process::Processes,
7    tag::{TagNames, TagThings},
8    theme::{ThemeDefault, ThemeTagThingsFocus, ThemeThingDependenciesStyles, ThemeTypesStyles},
9    thing::{ThingCopyText, ThingDependencies, ThingHierarchy, ThingInteractions, ThingNames},
10};
11
12/// The kinds of diagrams that can be generated.
13///
14/// This is the root data structure for diagram input, containing all
15/// configuration for things, their relationships, processes, tags, styling,
16/// and themes.
17#[cfg_attr(
18    all(feature = "openapi", not(feature = "test")),
19    derive(utoipa::ToSchema)
20)]
21#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
22pub struct InputDiagram {
23    /// Things in the diagram and their display labels.
24    #[serde(default, skip_serializing_if = "ThingNames::is_empty")]
25    pub things: ThingNames,
26
27    /// Text to copy to clipboard when a thing's copy button is clicked.
28    ///
29    /// This allows things to have different copy text than their display label.
30    #[serde(default, skip_serializing_if = "ThingCopyText::is_empty")]
31    pub thing_copy_text: ThingCopyText,
32
33    /// Hierarchy of `thing`s as a recursive tree structure.
34    ///
35    /// This defines the nesting of things, which affects visual containment
36    /// in the diagram.
37    #[serde(default, skip_serializing_if = "ThingHierarchy::is_empty")]
38    pub thing_hierarchy: ThingHierarchy,
39
40    /// Dependencies between things (static relationships).
41    ///
42    /// When B depends on A, it means A must exist before B.
43    /// Changes to A means B is out of date.
44    #[serde(default, skip_serializing_if = "ThingDependencies::is_empty")]
45    pub thing_dependencies: ThingDependencies,
46
47    /// Interactions between things (communication between applications).
48    ///
49    /// Has the same structure as dependencies but represents runtime
50    /// communication rather than static dependencies.
51    #[serde(default, skip_serializing_if = "ThingInteractions::is_empty")]
52    pub thing_interactions: ThingInteractions,
53
54    /// Processes are groupings of interactions between things sequenced over
55    /// time.
56    #[serde(default, skip_serializing_if = "Processes::is_empty")]
57    pub processes: Processes,
58
59    /// Tags are labels that can be associated with things, so that the things
60    /// can be highlighted when the tag is focused.
61    #[serde(default, skip_serializing_if = "TagNames::is_empty")]
62    pub tags: TagNames,
63
64    /// Things associated with each tag.
65    #[serde(default, skip_serializing_if = "TagThings::is_empty")]
66    pub tag_things: TagThings,
67
68    /// Descriptions to render next to entities (things, edges, edge groups).
69    #[serde(default, skip_serializing_if = "EntityDescs::is_empty")]
70    pub entity_descs: EntityDescs,
71
72    /// Additional `type`s attached to entities for common styling.
73    ///
74    /// Each entity can have multiple types, allowing styles to be stacked.
75    /// These types are appended to the entity's computed default type.
76    #[serde(default, skip_serializing_if = "EntityTypes::is_empty")]
77    pub entity_types: EntityTypes,
78
79    /// Default theme styles when the diagram has no user interaction.
80    #[serde(default, skip_serializing_if = "ThemeDefault::is_empty")]
81    pub theme_default: ThemeDefault,
82
83    /// Styles applied to things / edges of a particular `type`.
84    #[serde(default, skip_serializing_if = "ThemeTypesStyles::is_empty")]
85    pub theme_types_styles: ThemeTypesStyles,
86
87    /// Styles when a `thing` is focused to show its dependencies.
88    #[serde(
89        default,
90        skip_serializing_if = "ThemeThingDependenciesStyles::is_empty"
91    )]
92    pub theme_thing_dependencies_styles: ThemeThingDependenciesStyles,
93
94    /// Styles when a tag is focused.
95    ///
96    /// The `tag_defaults` key applies styles to all tags uniformly.
97    /// Specific tag IDs can be used to override defaults for particular tags.
98    #[serde(default, skip_serializing_if = "ThemeTagThingsFocus::is_empty")]
99    pub theme_tag_things_focus: ThemeTagThingsFocus,
100
101    /// Additional CSS to place in the SVG's inline `<styles>` section.
102    #[serde(default, skip_serializing_if = "Css::is_empty")]
103    pub css: Css,
104}
105
106impl InputDiagram {
107    /// Returns a new `InputDiagram` with default values.
108    pub fn new() -> Self {
109        Self::default()
110    }
111}