use orrery_core::{
draw::{Drawable, Fragment, LayeredOutput, Note, PositionedArrowWithText, PositionedDrawable},
geometry::{Bounds, Point},
};
use super::Svg;
use crate::layout::{layer::ContentStack, sequence};
impl Svg {
pub fn render_participant(&self, participant: &sequence::Participant) -> LayeredOutput {
let mut output = LayeredOutput::new();
let component = participant.component();
let shape_output = component.drawable().render_to_layers();
output.merge(shape_output);
let lifeline_output = participant.lifeline().render_to_layers();
output.merge(lifeline_output);
output
}
pub fn render_message(&mut self, message: &PositionedArrowWithText) -> LayeredOutput {
message.render_to_layers(&mut self.arrow_with_text_drawer)
}
pub fn render_fragment(&self, fragment: &PositionedDrawable<Fragment>) -> LayeredOutput {
fragment.render_to_layers()
}
pub fn render_note(&self, note: &PositionedDrawable<Note>) -> LayeredOutput {
note.render_to_layers()
}
pub fn render_activation_box(&self, activation_box: &sequence::ActivationBox) -> LayeredOutput {
let position = Point::new(activation_box.participant_x(), activation_box.center_y());
activation_box.drawable().render_to_layers(position)
}
pub fn calculate_sequence_diagram_bounds(
&self,
content_stack: &ContentStack<sequence::Layout>,
) -> Bounds {
let last_positioned_content = content_stack.iter().last();
last_positioned_content
.map(|positioned_content| {
let layout = &positioned_content.content();
if layout.participants().is_empty() {
return Bounds::default();
}
let mut content_bounds = layout
.participants()
.values()
.map(|p| p.component().bounds())
.reduce(|acc, bounds| acc.merge(&bounds))
.unwrap_or_default();
for note in layout.notes() {
let note_bounds = note.position().to_bounds(note.size());
content_bounds = content_bounds.merge(¬e_bounds);
}
content_bounds.with_max_y(layout.max_lifeline_end())
})
.unwrap_or_default()
}
}