1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
mod configuration;
mod geometry;
mod patterns;
mod renderer;
mod shapes;
mod smart_positioning;
mod stage_type;
mod utils;
// Re-export parser types
pub use wmap_parser::{
Component, Dependency, Evolution, Group, Inertia, Map, Note, Shape, Stage, StageData,
};
// Re-export our types
pub use configuration::{
Colors, Configuration, Fonts, LineHeights, Opacity, Options, Sizes, Theme,
};
pub use stage_type::StageType;
use thiserror::Error;
/// Error types for rendering
#[derive(Debug, Error)]
pub enum RenderError {
#[error("Cairo rendering error: {0}")]
Cairo(String),
#[error("Invalid configuration: {0}")]
InvalidConfig(String),
#[error("Concave hull calculation failed")]
GeometryError,
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
impl From<cairo::Error> for RenderError {
fn from(err: cairo::Error) -> Self {
RenderError::Cairo(err.to_string())
}
}
impl From<cairo::IoError> for RenderError {
fn from(err: cairo::IoError) -> Self {
RenderError::Cairo(err.to_string())
}
}
/// Renders a Wardley map to PNG format
///
/// # Arguments
///
/// * `map` - The parsed Wardley map
/// * `stage_type` - The stage type to use for axis labels
/// * `config` - Configuration options
///
/// # Returns
///
/// A vector of bytes containing the PNG image data
pub fn render_to_png(
map: &Map,
stage_type: StageType,
config: &Configuration,
) -> Result<Vec<u8>, RenderError> {
renderer::render_to_png(map, stage_type, config)
}
/// Renders a Wardley map to SVG format
///
/// # Arguments
///
/// * `map` - The parsed Wardley map
/// * `stage_type` - The stage type to use for axis labels
/// * `config` - Configuration options
///
/// # Returns
///
/// A string containing the SVG data
pub fn render_to_svg(
map: &Map,
stage_type: StageType,
config: &Configuration,
) -> Result<String, RenderError> {
renderer::render_to_svg(map, stage_type, config)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_configuration() {
let config = Configuration::default();
assert!(config.options.show_background);
assert!(config.options.smart_label_positioning);
}
#[test]
fn test_default_stage_type() {
let stage = StageType::default();
assert_eq!(stage, StageType::Activities);
}
}
|