pub struct Mermaid {
diagram: String,
scale: f32,
auto_scale: bool,
max_ratio: f32,
alignment: Alignment,
position: Option<Position>,
link: Option<String>,
}Expand description
Element that renders a Mermaid diagram into the PDF as an SVG image.
This element is only available when the mermaid feature is enabled.
Rendering requires headless Chrome at runtime; the following example demonstrates
creating and configuring a Mermaid element but does not attempt to render it.
§Examples
use genpdfi_extended::elements::Mermaid;
use genpdfi_extended::Alignment;
let m = Mermaid::new("graph TB\na-->b")
.with_alignment(Alignment::Center)
.with_scale(1.5);
// Example verifies the API compiles and can be debug-formatted without invoking Chrome.
let s = format!("{:?}", m);
assert!(s.contains("Mermaid"));Fields§
§diagram: String§scale: f32Scaling factor applied directly to the generated SVG. A value of 1.0 means no scaling.
auto_scale: boolIf true, automatically reduce the scale so the rendered diagram fits within
90% of the page width or height (whichever constrains first). When enabled
the scale is initially set to 2.0 by with_auto_scale() and then adjusted
at render time based on the available area.
max_ratio: f32Maximum ratio of page size to use when auto-scaling (e.g. 0.9 for 90% of page)
alignment: AlignmentPositioning and presentation helpers mirrored from Image.
position: Option<Position>§link: Option<String>Implementations§
Source§impl Mermaid
impl Mermaid
Sourcepub fn new<S: Into<String>>(diagram: S) -> Self
pub fn new<S: Into<String>>(diagram: S) -> Self
Create a new Mermaid element from the source string.
§Examples
use genpdfi_extended::elements::Mermaid;
let m = Mermaid::new("graph TB\na-->b");
let s = format!("{:?}", m);
assert!(s.contains("Mermaid"));Sourcepub fn ensure_browser() -> Result<(), Error>
pub fn ensure_browser() -> Result<(), Error>
Ensure the global headless Chrome instance is up and running.
Useful for examples that want to pre-check the environment before building the full PDF.
Sourcepub fn get_browser() -> Result<&'static Browser, Error>
pub fn get_browser() -> Result<&'static Browser, Error>
Returns a reference to the shared headless Chrome Browser instance, initializing
it if necessary. Use this if you need to open tabs or interact directly with the
browser in integration tests or examples.
Sourcepub fn with_alignment(self, a: Alignment) -> Self
pub fn with_alignment(self, a: Alignment) -> Self
Set alignment used when no absolute position is given.
Sourcepub fn with_position(self, p: Position) -> Self
pub fn with_position(self, p: Position) -> Self
Set an absolute position for the element.
Sourcepub fn with_link<S: Into<String>>(self, link: S) -> Self
pub fn with_link<S: Into<String>>(self, link: S) -> Self
Attach a hyperlink to the rendered SVG.
Sourcepub fn with_scale(self, s: f32) -> Self
pub fn with_scale(self, s: f32) -> Self
Set the scale to apply directly to the generated SVG.
The scaling is applied to the SVG markup (a wrapper <g transform="scale(...)">
is inserted) and numeric width/height attributes are multiplied accordingly.
§Examples
use genpdfi_extended::elements::Mermaid;
let m = Mermaid::new("graph TB\na-->b").with_scale(2.0);
let s = format!("{:?}", m);
assert!(s.contains("Mermaid"));Sourcepub fn with_auto_scale(self, s: f32, max_ratio: f32) -> Self
pub fn with_auto_scale(self, s: f32, max_ratio: f32) -> Self
Enable automatic scaling with a sensible default.
This sets the scale and enables automatic adjustment at render time so that the final rendered diagram does not exceed 90% of the available page width or height. The computed scale will never be larger than the initial value.
§Examples
use genpdfi_extended::elements::Mermaid;
let m = Mermaid::new("graph TB\na-->b").with_auto_scale(2.0, 0.9);
let s = format!("{:?}", m);
assert!(s.contains("Mermaid"));Trait Implementations§
Source§impl Element for Mermaid
impl Element for Mermaid
Source§fn render(
&mut self,
context: &Context,
area: Area<'_>,
style: Style,
) -> Result<RenderResult, Error>
fn render( &mut self, context: &Context, area: Area<'_>, style: Style, ) -> Result<RenderResult, Error>
Source§fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>where
Self: Sized,
fn framed(self, line_style: impl Into<LineStyle>) -> FramedElement<Self>where
Self: Sized,
Auto Trait Implementations§
impl Freeze for Mermaid
impl RefUnwindSafe for Mermaid
impl Send for Mermaid
impl Sync for Mermaid
impl Unpin for Mermaid
impl UnwindSafe for Mermaid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<E> IntoBoxedElement for Ewhere
E: Element + 'static,
impl<E> IntoBoxedElement for Ewhere
E: Element + 'static,
Source§fn into_boxed_element(self) -> Box<dyn Element>
fn into_boxed_element(self) -> Box<dyn Element>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.