Sign in

    moonbit-community/mermaid/diagram does not have a README file

    Context

    pub struct Context {
    id : String
    config :
    Config

    svg :
    Element

    now : Double
    page : Page
    image_loader : (String) -> Bytes??
    }

    What a diagram renderer works with: the <svg> element to draw into and the configuration in effect.

    Context::container_width

    fn Context::container_width(self : Context) -> Double

    The width of the element the diagram is rendered into, before the diagram has a size (parentElement.offsetWidth at the start of drawing).

    Context::font

    fn Context::font(self : Context, bold? : Bool, italic? : Bool) ->
    Stack

    The font stack text in this diagram is measured with.

    Context::new

    fn Context::new(id : String, config :
    Config
    , svg :
    Element
    , now~ : Double, page~ : Page, image_loader? : (String) -> Bytes?) -> Context

    Context::placement

    fn Context::placement(self : Context, width : Double, height : Double, max_width~ : Double) -> Placement

    The placement of a diagram whose <svg> has width="100%", the view box 0 0 width height and a max-width style (in pixels), fitted the way preserveAspectRatio does by default: scaled uniformly and centred.

    The element is as wide as its container allows, at most max_width, and as tall as the view box's proportions make it, in whole layout units. When that is taller than the viewport has room for, the page gets a scrollbar and the container narrows.

    Context::theme

    The theme variables in effect.

    Context::view_box_scale

    fn Context::view_box_scale(self : Context, width : Double, height : Double, max_width? : Double, fixed? : Bool) -> Double

    The factor the browser draws the diagram's user units at once the <svg> (still width="100%", no height) has the view box 0 0 width height, the way the view box is fitted into the element (preserveAspectRatio at its default).

    The element is as wide as its container, or as max_width when its style limits it to less, and as tall as the view box's proportions make it; when that is taller than the viewport has room for, the page gets a scrollbar, the container narrows and the diagram shrinks with it. A diagram that measures text after setting its view box gets its measurements at this scale.

    With fixed, the element has width and height attributes of the size of the view box instead, and the page does not matter.

    Page

    pub struct Page {
    viewport_width : Double
    viewport_height : Double
    margin : Double
    scrollbar : Double
    screen_width : Double
    }

    The page a diagram is rendered in, for the diagrams whose geometry depends on it.

    mermaid renders into a block element appended to the body, holding an <svg width="100%">. A Gantt chart takes the width of that element as its own, and measures its labels while the browser has the <svg> laid out at whatever size the page gives it — scrollbar included.

    Page::new

    fn Page::new(viewport_width? : Double, viewport_height? : Double, margin? : Double, scrollbar? : Double, screen_width? : Double) -> Page

    A page; the defaults describe the one the reference renderings are made in: headless Chrome's default window on macOS, with the default body margin and classic scrollbars.

    Placement

    pub struct Placement {
    scale : Double
    dx : Double
    dy : Double
    left : Double
    top : Double
    }

    How the browser fits a diagram's user space into the page. A point in user units is scaled by scale and moved by dx and dy to its place inside the <svg> element, whose top left corner is at left and top in the viewport; together they are getScreenCTM().

    configure_svg_size

    fn configure_svg_size(svg :
    Element
    , height : Double, width : Double, use_max_width : Bool) -> Unit

    Size the <svg> element, like mermaid's configureSvgSize: either responsive with a maximum width, or fixed.

    css_font_size

    fn css_font_size(value : Json, parent : Double) -> Double?

    The font size the browser computes for value, a theme variable a stylesheet writes after font-size:. parent is the size inherited when the declaration is invalid, as a bare number is, and the size relative units refer to. None for a value the port does not measure (other units, keywords, sizes not above zero).

    is_js_space

    fn is_js_space(c : Char) -> Bool

    Whether JavaScript's \s (and String.prototype.trim) takes c for white space.

    parse_float

    fn parse_float(text : String) -> Double

    JavaScript's parseFloat: the number the longest numeric prefix of the text stands for, NaN without one.

    parse_font_size

    fn parse_font_size(size : String) -> Double?

    mermaid's parseFontSize: the leading integer of a size such as "17px", like JavaScript's parseInt.

    to_fixed0

    fn to_fixed0(value : Double) -> String

    Number.prototype.toFixed(0): round to an integer, halves away from zero.

    to_number

    fn to_number(value : Json) -> Double

    JavaScript's Number(value) for a value read from configuration or metadata: a number as it is, a string as a numeric literal ("20" is 20, "" is 0, "20px" is NaN), true and false as 1 and 0, null as 0. An array goes through its text, its elements joined by commas ([5] is 5, [] is 0); an object is NaN.