cottax.consumers.visualization.svg module¶
The SVG every picture draws with: a label’s runs and width, the shapes, escaping.
- class SvgDoc[source]¶
Bases:
strSVG markup as a str, which a notebook also renders inline (_repr_svg_). path is the .svg file it was written to, or None; cell (the widest step column and tallest row) and size (width, height) are in px, for another drawing’s cell and canvas.
- path: str | None = None¶
- cell: tuple[float, float] | None = None¶
- size: tuple[float, float] | None = None¶
- BASE_FONT_SIZE = 13.0¶
The size a diagonal label is set at, and the unit every distance here is a multiple of.
- markup_runs(s: str)[source]¶
s as (text, italic, bold, shift, face) runs, shift -1 for a subscript and +1 for a superscript. Text outside a marked run is escaped here, since it is a name; text inside one was written as markup and is already escaped.
- Return type:
list[tuple[str,bool,bool,int,str|None]]
- weight(run_bold: bool, face: str | None, bold: bool)[source]¶
Whether one run is drawn bold, as label sets it: bold is the surrounding <text>’s weight, run_bold the run’s own markup’s. A run naming a face takes only its own: the named face may carry no bold.
- Return type:
bool
- tw(s: str, size: float = BASE_FONT_SIZE, *, bold: bool = False)[source]¶
The estimated width of s drawn at size, its markup counted as it is set; bold for a label set bold.
- Return type:
float
- label(s: str, size: float)[source]¶
s as the content of a <text>: a tspan per marked run, plain text where there is no markup. A sub- or superscript is a dy off the running offset (converters drop baseline-shift).
- Return type:
str
- hexagon(cx: float, cy: float, w: float, h: float, scale: float = 1.0, cap: float | None = None)[source]¶
The points of a w by h box with chevron sides, centred on (cx, cy): the chevron is 12% of the width, at most 11 * scale px (scale: the type’s size over BASE_FONT_SIZE), or cap px when given.
- Return type:
str
- cut_hexagon(points: str, head: float, half: float)[source]¶
The contour of hexagon’s points as two open paths, the left chevron and the right, stopping half either side of head (the middle of the shape’s own column) on the top and bottom edges.
- Return type:
tuple[str,str]
- cut_rect(x: float, y: float, w: float, h: float, r: float, half: float)[source]¶
A rounded rect’s contour as two open halves, stopping half either side of the middle of its top and bottom edges.
- Return type:
tuple[str,str]
- type Measure = Callable[[str, float, bool], tuple[float, float]]¶
What render_xdsm_svg’s measure is: (label, size, bold) -> (ink_left, ink_width), in px and relative to the pen origin, for a label already carrying its MARKUP runs.