Skip to content

common_reports.builders.plots

Plot families — Plotly figures for report Figure components (optional).

The finance plot families ported from AlgoReports (Processor / OriginStats): all 10 PlotType families, honouring [G1] MAX dual-axis ratio yranges, [G2] trading-gate vs calendar-lookback, [G3] live-start default-visible, [G5] 12 rolling metrics, [G6] canonical H legend, [G7] portfolio empty-y2 quirk and [G8] coloured heatmap — plus figure_to_assets (go.Figure -> interactive HTML via CDN + static PNG; [G16] order = interactive, static, url).

Independent of any statistics pipeline: families take the DataFrame already on the Figure component. Plotly / pandas / numpy load LAZILY inside the functions and need the [builders] extra; importing this module stays light.

Functions

build_plotly_figure

def build_plotly_figure(figure: Figure, theme: Theme) -> Any

Build a go.Figure for a :class:Figure component: the 10 AlgoReports families plus the finance families (builders/charts.py), with fmt.hover / fmt.zoom applied. Plotly/pandas/numpy load lazily.

figure_png

def figure_png(fig: Any, *, width: int | None = None, height: int | None = None, scale: float | None = None) -> bytes | None

Static PNG bytes of a figure (kaleido), or None when export is unavailable.

width/height are CSS pixels; scale multiplies them (2 = retina).

figure_to_assets

def figure_to_assets(fig: Any, output: PlotOutput, *, image_template: str = '<img src="data:image/png;base64,{encoded_image}" style="width: 100%; height: auto;">', uploader: Any = None) -> FigureAsset

Render a go.Figure into its target forms.

[G16] order = (interactive, static, url).

  • interactive: pio.to_html(full_html=False, include_plotlyjs='cdn', config={'responsive': True})
  • static: pio.to_image(format='png') -> base64 -> image_template
  • url: if uploader supplied, write PNG bytes and host -> hosted URL.

PNG / kaleido failures degrade gracefully (static left empty) so an interactive-only render never hard-fails.

Types and values

PNG_TIMEOUT_SECONDS

PNG_TIMEOUT_SECONDS = 120.0