Skip to content

Element.Txt

Creates a text SVG element

DaxLib

DaxLib.SVG.Element.Txt( x, y, txt, dx, dy, attributes, transforms, escape )
Parameter Type Required Default Description
x STRING The x position of the text
y STRING The y position of the text
txt STRING The text content
dx STRING BLANK() Optional: x offset from position
dy STRING BLANK() Optional: y offset from position
attributes STRING BLANK() Optional: Direct SVG attributes to apply (e.g., "text-anchor='middle' dominant-baseline='middle'"), can generate with DaxLib.SVG.Attr.* or manually
transforms STRING BLANK() Optional: Additional transforms (e.g. "scale(1.2) translate(10,10)") (can be generated with DaxLib.SVG.Transforms)
escape BOOLEAN TRUE() Optional: When TRUE or BLANK (default), XML-escapes txt (replaces &, <, >, ", ') so characters like & and < render correctly. Pass FALSE to insert txt verbatim (e.g. when it already contains raw SVG markup).

STRING element

DaxLib.SVG.SVG( 
    500,                // width
    100,                // height
    DaxLib.SVG.Element.Txt(
        10,             // x
        10,             // y
        "DaxLib",       // txt
        0,              // dx
        0,              // dy
        DaxLib.SVG.Attr.Txt(
            "Arial",    // fontFamily
            12,         // fontSize
            BLANK(),    // fontWeight
            BLANK(),    // fontStyle
            BLANK(),    // textAnchor
            BLANK(),    // baseline
            BLANK(),    // textDecoration
            BLANK(),    // letterSpacing
            BLANK()     // wordSpacing
        ),              // attributes
        BLANK()         // transforms
    ),                  // contents
    "0 0 100 20",       // viewbox
    BLANK()             // sortValue
)
function 'DaxLib.SVG.Element.Txt' =
        (
            x: STRING,
            y: STRING,
            txt: STRING,
            dx: STRING = BLANK(),
            dy: STRING = BLANK(),
            attributes: STRING = BLANK(),
            transforms: STRING = BLANK(),
            escape: BOOLEAN = TRUE()
        ) =>

            VAR _Escape = COALESCE( escape, TRUE() )
            VAR _s0 = COALESCE( txt, "" )
            VAR _s1 = SUBSTITUTE( _s0, "&",  "&amp;"  )
            VAR _s2 = SUBSTITUTE( _s1, "<",  "&lt;"   )
            VAR _s3 = SUBSTITUTE( _s2, ">",  "&gt;"   )
            VAR _s4 = SUBSTITUTE( _s3, """", "&quot;" )
            VAR _s5 = SUBSTITUTE( _s4, "'",  "&apos;" )
            VAR _Txt = IF( _Escape, _s5, txt )
            RETURN
                "<text" &
                " x='" & x & "'" &
                " y='" & y & "'" &
                IF(NOT ISBLANK( dx ), " dx='" & dx & "'" ) & 
                IF(NOT ISBLANK( dy ), " dy='" & dy & "'" ) &
                IF( NOT ISBLANK( attributes ), " " & attributes & " " ) &
                IF( NOT ISBLANK( transforms ), " transform='" & transforms & "'" ) &
                ">" & _Txt & 
                "</text>"