pub(crate) const SEQUENCE_NOTE_WRAP_SLACK_PX: f64 = 12.0;
pub(crate) const SEQUENCE_LEFT_OF_NOTE_WIDTH_OVERFLOW_PX: f64 = 3.0;
pub(crate) const SEQUENCE_LEFT_OF_NOTE_FINAL_WRAP_SLACK_PX: f64 = 16.0;
pub(crate) const SEQUENCE_WRAPPED_MESSAGE_WIDTH_EPS_PX: f64 = 4.0;
pub(crate) const SEQUENCE_MESSAGE_WRAP_SLACK_FACTOR: f64 = 4.5;
pub(crate) const SEQUENCE_SELF_MESSAGE_FRAME_EXTRA_Y_PX: f64 = 60.0;
pub(crate) const SEQUENCE_FRAME_SIDE_PAD_PX: f64 = 11.0;
pub(crate) const SEQUENCE_FRAME_GEOM_PAD_PX: f64 = 10.0;
pub(crate) const SEQUENCE_ACTOR_POPUP_PANEL_BASE_HEIGHT: f64 = 20.0;
pub(crate) const SEQUENCE_ACTOR_POPUP_ROW_HEIGHT: f64 = 30.0;
pub(crate) fn sequence_text_dimensions_height_px(font_size_px: f64) -> f64 {
(font_size_px.max(1.0) * (17.0 / 16.0)).round().max(1.0)
}
pub(crate) fn sequence_text_line_step_px(font_size_px: f64) -> f64 {
font_size_px.max(1.0) * 1.1875
}
pub(crate) fn sequence_actor_popup_panel_height(link_count: usize) -> f64 {
SEQUENCE_ACTOR_POPUP_PANEL_BASE_HEIGHT + (link_count as f64) * SEQUENCE_ACTOR_POPUP_ROW_HEIGHT
}
pub(super) fn sequence_actor_visual_height(
actor_type: &str,
base_width: f64,
base_height: f64,
label_box_height: f64,
) -> f64 {
match actor_type {
"boundary" => (60.0 + label_box_height).max(1.0),
"database" => ((base_width / 4.0) + label_box_height).max(1.0),
"entity" => (36.0 + label_box_height).max(1.0),
"control" => (36.0 + 2.0 * label_box_height).max(1.0),
_ => base_height.max(1.0),
}
}
pub(super) fn sequence_actor_lifeline_start_y(
actor_type: &str,
base_height: f64,
box_text_margin: f64,
) -> f64 {
match actor_type {
"actor" | "boundary" => 80.0,
"control" | "entity" => 75.0,
"database" => base_height + 2.0 * box_text_margin,
_ => base_height,
}
}
#[cfg(test)]
mod tests {
#[test]
fn sequence_text_and_frame_constants_match_mermaid() {
assert_eq!(super::SEQUENCE_NOTE_WRAP_SLACK_PX, 12.0);
assert_eq!(super::SEQUENCE_LEFT_OF_NOTE_WIDTH_OVERFLOW_PX, 3.0);
assert_eq!(super::SEQUENCE_LEFT_OF_NOTE_FINAL_WRAP_SLACK_PX, 16.0);
assert_eq!(super::SEQUENCE_WRAPPED_MESSAGE_WIDTH_EPS_PX, 4.0);
assert_eq!(super::SEQUENCE_MESSAGE_WRAP_SLACK_FACTOR, 4.5);
assert_eq!(super::SEQUENCE_ACTOR_POPUP_PANEL_BASE_HEIGHT, 20.0);
assert_eq!(super::SEQUENCE_ACTOR_POPUP_ROW_HEIGHT, 30.0);
assert_eq!(super::sequence_actor_popup_panel_height(0), 20.0);
assert_eq!(super::sequence_actor_popup_panel_height(4), 140.0);
assert_eq!(super::sequence_text_dimensions_height_px(16.0), 17.0);
assert_eq!(super::sequence_text_dimensions_height_px(10.0), 11.0);
assert_eq!(super::sequence_text_line_step_px(16.0), 19.0);
assert_eq!(super::SEQUENCE_SELF_MESSAGE_FRAME_EXTRA_Y_PX, 60.0);
assert_eq!(super::SEQUENCE_FRAME_SIDE_PAD_PX, 11.0);
assert_eq!(super::SEQUENCE_FRAME_GEOM_PAD_PX, 10.0);
}
}