dendryform_layout/geometry.rs
1//! Layout geometry types — the positioned output of layout computation.
2
3use dendryform_core::{
4 Color, ConnectorStyle, ContainerBorder, LegendEntry, Node, NodeId, TierLayout,
5};
6
7/// Preferred viewport configuration for rendering.
8#[derive(Debug, Clone, PartialEq)]
9pub struct ViewportHint {
10 /// Reference width in pixels (default 1100).
11 pub width: f32,
12 /// Horizontal padding in pixels.
13 pub padding_x: f32,
14 /// Top padding in pixels.
15 pub padding_top: f32,
16 /// Bottom padding in pixels.
17 pub padding_bottom: f32,
18}
19
20impl Default for ViewportHint {
21 fn default() -> Self {
22 Self {
23 width: 1100.0,
24 padding_x: 32.0,
25 padding_top: 48.0,
26 padding_bottom: 64.0,
27 }
28 }
29}
30
31/// Header geometry — title and subtitle positioning.
32#[derive(Debug, Clone, PartialEq)]
33pub struct HeaderGeometry {
34 /// The main title text.
35 pub title_text: String,
36 /// The accent word in the title.
37 pub title_accent: String,
38 /// The subtitle text.
39 pub subtitle: String,
40}
41
42/// A positioned node within a tier grid.
43#[derive(Debug, Clone, PartialEq)]
44pub struct NodeGeometry<'a> {
45 /// Reference to the source node data.
46 pub node: &'a Node,
47 /// Grid column index (0-based).
48 pub grid_column: usize,
49 /// Grid row index (0-based).
50 pub grid_row: usize,
51}
52
53/// Layout of a connector between tiers.
54#[derive(Debug, Clone, PartialEq)]
55pub struct ConnectorGeometry {
56 /// Visual style (line or dots).
57 pub style: ConnectorStyle,
58 /// Optional protocol/description label.
59 pub label: Option<String>,
60 /// Whether this connector is inside a container.
61 pub is_internal: bool,
62}
63
64/// Layout of flow labels between tiers.
65#[derive(Debug, Clone, PartialEq)]
66pub struct FlowLabelsGeometry {
67 /// The label texts.
68 pub items: Vec<String>,
69}
70
71/// Layout of a container wrapping nested tiers.
72#[derive(Debug, Clone, PartialEq)]
73pub struct ContainerGeometry<'a> {
74 /// Container label text.
75 pub label: String,
76 /// Container border style.
77 pub border: ContainerBorder,
78 /// Container label color.
79 pub label_color: Color,
80 /// Nested layer geometries.
81 pub layers: Vec<LayerGeometry<'a>>,
82}
83
84/// Layout of a tier (horizontal band of nodes).
85#[derive(Debug, Clone, PartialEq)]
86pub struct TierGeometry<'a> {
87 /// Tier identifier.
88 pub id: NodeId,
89 /// Optional heading label.
90 pub label: Option<String>,
91 /// The layout mode for this tier.
92 pub layout: TierLayout,
93 /// Number of grid columns.
94 pub columns: usize,
95 /// Positioned nodes in grid order.
96 pub nodes: Vec<NodeGeometry<'a>>,
97 /// Optional container wrapping nested tiers.
98 pub container: Option<ContainerGeometry<'a>>,
99}
100
101/// A single positioned layer in the layout.
102#[derive(Debug, Clone, PartialEq)]
103pub enum LayerGeometry<'a> {
104 /// A positioned tier.
105 Tier(TierGeometry<'a>),
106 /// A positioned connector.
107 Connector(ConnectorGeometry),
108 /// Positioned flow labels.
109 FlowLabels(FlowLabelsGeometry),
110}
111
112/// Layout of the legend.
113#[derive(Debug, Clone, PartialEq)]
114pub struct LegendGeometry {
115 /// Legend entries with color swatches.
116 pub entries: Vec<LegendEntry>,
117}
118
119/// The complete layout plan for a diagram.
120///
121/// Contains all the geometry needed for rendering. Format-specific renderers
122/// (HTML, SVG) consume this plan to produce output.
123#[derive(Debug, Clone, PartialEq)]
124pub struct LayoutPlan<'a> {
125 /// Viewport configuration.
126 pub viewport: ViewportHint,
127 /// Header geometry.
128 pub header: HeaderGeometry,
129 /// Ordered layer geometries (tiers, connectors, flow labels).
130 pub layers: Vec<LayerGeometry<'a>>,
131 /// Legend geometry.
132 pub legend: LegendGeometry,
133}