Skip to content

Svg

subsurfaceio.logplot.render.svg

Small SVG fragment helpers for logplot rendering.

Functions:

Name Description
escape_attr

Escape a value for use inside a double-quoted SVG attribute.

escape_text

Escape text for safe inclusion in SVG/XML content.

hline

Return a horizontal <line> SVG element.

tspan

Return a <tspan> with escaped text content.

vline

Return a vertical <line> SVG element.

Attributes:

Name Type Description
SvgValue TypeAlias

SvgValue module-attribute

SvgValue: TypeAlias = str | float | int | bool | None

escape_attr

escape_attr(value: SvgValue) -> str

Escape a value for use inside a double-quoted SVG attribute.

Parameters:

Name Type Description Default
value SvgValue

Attribute value; None becomes an empty string.

required

Returns:

Type Description
str

XML-escaped attribute text.

escape_text

escape_text(value: SvgValue) -> str

Escape text for safe inclusion in SVG/XML content.

Parameters:

Name Type Description Default
value SvgValue

Text or numeric value; None becomes an empty string.

required

Returns:

Type Description
str

XML-escaped text.

hline

hline(
    y: float,
    *,
    x1: float | str = 0,
    x2: float | str = "100%",
    stroke: str = "#000"
) -> str

Return a horizontal <line> SVG element.

Parameters:

Name Type Description Default
y float

Vertical position in pixels.

required
x1 float | str

Left x, numeric or CSS length.

0
x2 float | str

Right x, numeric or CSS length.

'100%'
stroke str

Stroke color.

'#000'

Returns:

Type Description
str

SVG <line> markup including a trailing newline.

tspan

tspan(
    text: str,
    *,
    x: float | str,
    dy_pt: float = 0.0,
    y: float | str | None = None
) -> str

Return a <tspan> with escaped text content.

Parameters:

Name Type Description Default
text str

Unescaped text.

required
x float | str

Horizontal position.

required
dy_pt float

Vertical offset in points.

0.0
y float | str | None

Optional absolute y.

None

Returns:

Type Description
str

SVG <tspan> markup.

vline

vline(
    x: float,
    *,
    y1: float | str = 0,
    y2: float | str = "100%",
    stroke: str = "#000",
    class_name: str | None = None
) -> str

Return a vertical <line> SVG element.

Parameters:

Name Type Description Default
x float

Horizontal position in pixels.

required
y1 float | str

Top y, numeric or CSS length.

0
y2 float | str

Bottom y, numeric or CSS length.

'100%'
stroke str

Stroke color.

'#000'
class_name str | None

Optional CSS class.

None

Returns:

Type Description
str

SVG <line> markup including a trailing newline.