Create clld icons as SVG

Provides functionality to create simple SVG icons or pie charts which can be used as map markers e.g. with leaflet.

clldutils.svg.svg(content, height=None, width=None)[source]

Wrap content (some SVG XML) into a svg element with optional dimension attributes.

Return type:

str

Returns:

The full SVG XML as string.

Parameters:
  • content (str) –

  • height (typing.Optional[int]) –

  • width (typing.Optional[int]) –

clldutils.svg.data_url(svgxml)[source]

Turn SVG XML into a data URL suitable for inlining in HTML.

Parameters:

svgxml (str) –

Return type:

str

clldutils.svg.icon(spec, opacity=None)[source]

Creates a SVG graphic according to a spec as used for map icons in clld apps.

Parameters:

spec (str) – Icon spec of the form “(s|d|c|f|t)rrggbb” where the first character defines a shape (s=square, d=diamond, c=circle, f=upside-down triangle, t=triangle) and “rrggbb” specifies a color as hex triple.

Return type:

str

Returns:

SVG XML

clldutils.svg.pie(data, colors=None, titles=None, width=34, stroke_circle=False)[source]

An SVG pie chart.

Parameters:
  • data (typing.List[typing.Union[float, int]]) – list of numbers specifying the proportional sizes of the slices.

  • colors (typing.Optional[typing.List[str]]) – list of RGB colors as hex triplets, specifying the respective colors of the slices.

  • titles (typing.Optional[typing.List[str]]) – list of strings to use as titles for the respective slices.

  • width (int) – Width of the SVG object.

  • stroke_circle (bool) – Whether to stroke (aka outline) theboundary of the pie.

Return type:

str

Returns:

SVG XML representation of the data as pie chart.