Skip to content

Viz.Pill

Renders a pill-shaped badge as an SVG data URI with centered text

DaxLib

DaxLib.SVG.Viz.Pill( txt, color, width, height )
Parameter Type Required Description
txt STRING The text to display
color STRING Optional pill color. Defaults to Power BI theme color
width INT64 Optional: SVG width. Defaults to 120
height INT64 Optional: SVG height. Defaults to 48

STRING SVG Pill

DaxLib.SVG.Viz.Pill(
    "Active",           // txt
    "#EC008C",          // color
    120,                // width
    28                  // height
)
// Returns an SVG data URI with a pill-shaped badge
// Set as a measure with DataCategory = "ImageUrl"
function 'DaxLib.SVG.Viz.Pill' =
        (
            txt: STRING,
            color: STRING,
            width: INT64,
            height: INT64
        ) =>

            VAR _W = IF( ISBLANK( width ), 120, width )
            VAR _H = IF( ISBLANK( height ), 48, height )
            VAR _Color = IF( NOT ISBLANK( color ), color, DaxLib.SVG.Color.Theme( "Power BI", 1 ) )
            VAR _Marks =
                DaxLib.SVG.Compound.Pill(
                    0, 0, _W, _H, 0, 0, txt, _Color
                )

            RETURN
                IF( NOT ISBLANK( _Marks ), DaxLib.SVG.SVG( "100%", "100%", "0 0 " & _W & " " & _H, _Marks, BLANK() ) )