plesty.lib.report.svg ===================== .. py:module:: plesty.lib.report.svg .. autoapi-nested-parse:: A figure's drawables as one self-contained SVG. Series take their colours from the packaged palette (the same tokens a live view resolves), and everything else — axes, ticks, labels — is drawn in ``currentColor``, so the figure reads on the page it is set in, light or dark. An :class:`~plesty.lib.monitor.plots.Image` is embedded as a PNG in the palette's colour map; nothing outside the standard library and numpy is needed to draw any of it. Attributes ---------- .. autoapisummary:: plesty.lib.report.svg.MARGIN plesty.lib.report.svg.Trace plesty.lib.report.svg._CORNERS Functions --------- .. autoapisummary:: plesty.lib.report.svg.figure_svg plesty.lib.report.svg._finite plesty.lib.report.svg._span plesty.lib.report.svg._ranges plesty.lib.report.svg._ticks plesty.lib.report.svg._tick_label plesty.lib.report.svg._mapper plesty.lib.report.svg._axes plesty.lib.report.svg._trace plesty.lib.report.svg._polyline plesty.lib.report.svg._legend_entries plesty.lib.report.svg._legend_box plesty.lib.report.svg._legend_corner plesty.lib.report.svg._legend plesty.lib.report.svg._marks plesty.lib.report.svg._levels plesty.lib.report.svg._colour plesty.lib.report.svg._png plesty.lib.report.svg._data_uri plesty.lib.report.svg._image plesty.lib.report.svg._colour_bar Module Contents --------------- .. py:data:: MARGIN :value: (64, 20, 16, 48) .. py:data:: Trace .. py:function:: figure_svg(drawables: Sequence[plesty.lib.monitor.plots.Drawable], theme: Optional[plesty.lib.ui.theme.Theme] = None) -> str Draw *drawables* on one pair of axes. :param drawables: What to draw, in the order it is layered. :param theme: Where colour tokens resolve; the packaged palette by default. :returns: An ```` element. .. py:function:: _finite(values: Any) -> numpy.ndarray Return the finite entries of *values* as a flat float array. .. py:function:: _span(values: Sequence[numpy.ndarray]) -> tuple[float, float] Return the range covering every array, widened when it is a point. .. py:function:: _ranges(images: Sequence[plesty.lib.monitor.plots.Image], traces: Sequence[Trace]) -> tuple[tuple[float, float], tuple[float, float]] Return the x and y ranges the axes show. .. py:function:: _ticks(low: float, high: float, count: int = 6) -> list[float] Return round tick positions inside ``[low, high]``: steps of 1, 2 or 5. .. py:function:: _tick_label(value: float, ticks: Sequence[float]) -> str Return a tick value with just the decimals its step needs. .. py:function:: _mapper(area: tuple[float, float, float, float], x_range: tuple[float, float], y_range: tuple[float, float]) -> Any Return a function from data coordinates to SVG coordinates. .. py:function:: _axes(area: tuple[float, float, float, float], x_range: tuple[float, float], y_range: tuple[float, float], drawables: Sequence[plesty.lib.monitor.plots.Drawable]) -> str Draw the frame, the ticks with their values, and the axis labels. .. py:function:: _trace(item: Trace, area: tuple[float, float, float, float], x_range: tuple[float, float], y_range: tuple[float, float], theme: plesty.lib.ui.theme.Theme) -> str Draw a line (broken where a value is missing) or a set of points. .. py:function:: _polyline(points: list[str], colour: str, width: float) -> str Return one unbroken run of a line. .. py:data:: _CORNERS :value: ('top-right', 'bottom-right', 'top-left', 'bottom-left') .. py:function:: _legend_entries(traces: Sequence[Trace]) -> list[Trace] Return the traces a legend lists: labelled, and not hidden by a ``_`` label. .. py:function:: _legend_box(corner: str, area: tuple[float, float, float, float], rows: int, longest: int) -> tuple[float, float, float, float] Return the box ``(x0, y0, x1, y1)`` a legend of *rows* entries takes in *corner*. .. py:function:: _legend_corner(drawables: Sequence[plesty.lib.monitor.plots.Drawable]) -> str Choose the corner where the legend covers the fewest trace points. A legend fixed top-right sat on every series that rises to the right — in a log–log power dependence, on the ends of all six lines and their fits. A line is sampled along its segments, not only at its points, so a sparse line crossing a corner counts too. The top-left corner holds the scalars and text marks, so a figure with any never puts its legend there. The LaTeX renderer asks the same question, so both outputs agree. :param drawables: The figure's drawables, as :func:`figure_svg` receives them. :returns: One of :data:`_CORNERS`. .. py:function:: _legend(traces: Sequence[Trace], area: tuple[float, float, float, float], theme: plesty.lib.ui.theme.Theme, corner: str = 'top-right') -> str List every labelled trace in *corner* of the plot. .. py:function:: _marks(marks: Sequence[plesty.lib.monitor.plots.Scalar | plesty.lib.monitor.plots.Text], area: tuple[float, float, float, float]) -> str Set scalars and text marks in the top-left corner, one line each. .. py:function:: _levels(image: plesty.lib.monitor.plots.Image) -> tuple[numpy.ndarray, float, float] Return the image scaled to ``[0, 1]`` (``nan`` where missing), and its range. .. py:function:: _colour(level: numpy.ndarray, stops: Sequence[str]) -> numpy.ndarray Map levels in ``[0, 1]`` onto the colour map, as RGBA bytes. .. py:function:: _png(rgba: numpy.ndarray) -> bytes Encode an ``(rows, columns, 4)`` byte array as a PNG. .. py:function:: _data_uri(rgba: numpy.ndarray) -> str Return a PNG as a ``data:`` URI. .. py:function:: _image(image: plesty.lib.monitor.plots.Image, area: tuple[float, float, float, float], x_range: tuple[float, float], y_range: tuple[float, float], theme: plesty.lib.ui.theme.Theme) -> str Embed the image, first row at the bottom, stretched over its extent. .. py:function:: _colour_bar(image: plesty.lib.monitor.plots.Image, area: tuple[float, float, float, float], theme: plesty.lib.ui.theme.Theme) -> str Draw the colour map beside the plot, labelled with the image's range.