gws.lib.svg.draw

SVG builders.

Source code: gws.lib.svg.draw

Module Contents

gws.lib.svg.draw.DEFAULT_FONT_SIZE = 10
gws.lib.svg.draw.DEFAULT_MARKER_SIZE = 10
gws.lib.svg.draw.DEFAULT_POINT_SIZE = 10
gws.lib.svg.draw.shape_to_fragment(shape: gws.Shape, view: gws.MapView, label: str = None, style: gws.Style = None) list[gws.XmlElement]

Convert a shape to a list of XmlElements (a “fragment”).

gws.lib.svg.draw.soup_to_fragment(view: gws.MapView, points: list[gws.Point], tags: list) list[gws.XmlElement]

Convert an svg “soup” to a list of XmlElements (a “fragment”).

A soup has two components:

  • a list of points, in the map coordinate system

  • a list of tuples suitable for xmlx.tag input (tag-name, {atts}, child1, child2….)

The idea is to represent client-side svg drawings (e.g. dimensions) in a resolution-independent way

First, points are converted to pixels using the view’s transform. Then, each tag’s attributes are iterated. If any attribute value is an array, it’s assumed to be a ‘function’. The first element is a function name, the rest are arguments. Attribute ‘functions’ are

  • [‘x’, n] - returns points[n][0]

  • [‘y’, n] - returns points[n][1]

  • [‘r’, p1, p2, r] - computes a slope between points[p1] points[p2] and returns a string

    rotate(slope, points[r].x, points[r].y)