Render Stage¶
The render stage transforms compiled faces with data into visual output formats.
Supported Formats¶
The renderer supports the following output formats:
- SVG: Scalable vector graphics (default)
- HTML: Interactive HTML pages with embedded charts
- PNG: Raster image format
- PDF: PDF documents
- Terminal: Terminal output with ASCII/Unicode charts (prints to stdout)
Entry Points¶
render¶
The main entry point for rendering datafaces:
render
¶
render(face: CompiledFace, executor: Executor, format: str = 'svg', variables: VariableValues | None = None, **options: Any) -> str | bytes
Render a compiled dataface.
Stage: RENDER (Main Entry Point)
This is the main rendering function. It walks the layout structure, renders each chart (triggering lazy query execution), and produces output in the requested format.
| PARAMETER | DESCRIPTION |
|---|---|
face
|
Compiled dataface to render
TYPE:
|
executor
|
Executor for query execution
TYPE:
|
format
|
Output format (svg, html, png, pdf, terminal)
TYPE:
|
variables
|
Variable values for queries
TYPE:
|
**options
|
Format-specific options - background: Background color - scale: Scale factor (for png) - grid: Show grid overlay (for debugging)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | bytes
|
Rendered output: - str for svg, html, terminal - bytes for png, pdf |
| RAISES | DESCRIPTION |
|---|---|
RenderError
|
If rendering fails |
FormatError
|
If format is unknown |
Source code in dataface/core/render/renderer.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
render_chart¶
Render a single chart:
render_chart
¶
Render a single chart to SVG.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
CompiledChart to render
TYPE:
|
data
|
Query results for the chart
TYPE:
|
**options
|
Rendering options
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
SVG string for the chart |
Source code in dataface/core/render/renderer.py
Layout Functions¶
The layout module provides functions for rendering different layout types.
Rows Layout¶
render_rows_layout
¶
render_rows_layout(items: list[LayoutItem], executor: Executor, variables: VariableValues, available_width: float, available_height: float, gap: float, background: str | None = None, theme: str | None = None) -> LayoutResult
Render items in vertical stack.
In a rows layout, items stack vertically. Heights are determined by: 1. Pre-calculated dimensions from sizing module (preferred) 2. Content-aware fallback if not pre-calculated
| PARAMETER | DESCRIPTION |
|---|---|
items
|
Layout items to render
TYPE:
|
executor
|
Executor for query execution
TYPE:
|
variables
|
Variable values for queries
TYPE:
|
available_width
|
Available container width
TYPE:
|
available_height
|
Available container height
TYPE:
|
gap
|
Gap between items
TYPE:
|
background
|
Optional background color
TYPE:
|
theme
|
Optional theme name to apply
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LayoutResult
|
LayoutResult with SVG content and dimensions |
Source code in dataface/core/render/layouts.py
Columns Layout¶
render_cols_layout
¶
render_cols_layout(items: list[LayoutItem], executor: Executor, variables: VariableValues, available_width: float, available_height: float, gap: float, background: str | None = None, theme: str | None = None) -> LayoutResult
Render items in horizontal distribution.
Trusts the normalizer for all sizing. Uses pre-calculated item.x, item.width, and item.height values.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
Layout items to render (with pre-calculated dimensions from normalizer)
TYPE:
|
executor
|
Executor for query execution
TYPE:
|
variables
|
Variable values for queries
TYPE:
|
available_width
|
Available container width
TYPE:
|
available_height
|
Available container height (upper bound)
TYPE:
|
gap
|
Gap between items (unused - normalizer already applied it)
TYPE:
|
background
|
Optional background color
TYPE:
|
theme
|
Optional theme name to apply
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LayoutResult
|
LayoutResult with SVG content and dimensions |
Source code in dataface/core/render/layouts.py
Grid Layout¶
render_grid_layout
¶
render_grid_layout(items: list[LayoutItem], executor: Executor, variables: VariableValues, available_width: float, available_height: float, columns: int, gap: float, background: str | None = None, theme: str | None = None) -> LayoutResult
Render items in positioned grid.
Grid items have explicit x, y positions and width, height spans. Each item's dimensions are calculated based on the grid columns/rows.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
Layout items with grid positions (x, y, width, height)
TYPE:
|
executor
|
Executor for query execution
TYPE:
|
variables
|
Variable values for queries
TYPE:
|
available_width
|
Available container width
TYPE:
|
available_height
|
Available container height
TYPE:
|
columns
|
Number of grid columns
TYPE:
|
gap
|
Gap between grid cells
TYPE:
|
background
|
Optional background color
TYPE:
|
theme
|
Optional theme name to apply
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LayoutResult
|
LayoutResult with SVG content and dimensions |
Source code in dataface/core/render/layouts.py
Tabs Layout¶
render_tabs_layout
¶
render_tabs_layout(items: list[LayoutItem], executor: Executor, variables: VariableValues, available_width: float, available_height: float, tab_titles: list[str] | None = None, active_tab: int = 0, tab_position: str = 'top', background: str | None = None, theme: str | None = None) -> LayoutResult
Render tabbed container (active tab only).
In a tabs layout, each tab gets the full container size minus the tab bar. Only the active tab is rendered in SVG output.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
Layout items (one per tab)
TYPE:
|
executor
|
Executor for query execution
TYPE:
|
variables
|
Variable values for queries
TYPE:
|
available_width
|
Available container width
TYPE:
|
available_height
|
Available container height
TYPE:
|
tab_titles
|
Optional titles for tabs
TYPE:
|
active_tab
|
Index of active tab (0-based)
TYPE:
|
tab_position
|
Position of tabs ("top" or "left")
TYPE:
|
background
|
Optional background color
TYPE:
|
theme
|
Optional theme name to apply
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LayoutResult
|
LayoutResult with SVG content and dimensions |
Source code in dataface/core/render/layouts.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
Vega-Lite Integration¶
Charts are rendered using Vega-Lite specifications.
generate_vega_lite_spec¶
generate_vega_lite_spec
¶
generate_vega_lite_spec(chart: CompiledChart | Any, data: list[dict[str, Any]], width: float | None = None, height: float | None = None, theme: str | None = None) -> dict[str, Any]
Generate a Vega-Lite specification from a chart definition and data.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
CompiledChart definition (or legacy Chart type)
TYPE:
|
data
|
List of dicts containing chart data
TYPE:
|
width
|
Optional explicit width in pixels
TYPE:
|
height
|
Optional explicit height in pixels
TYPE:
|
theme
|
Optional Vega-Lite theme name to apply
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Vega-Lite specification dictionary |
Source code in dataface/core/render/vega_lite.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
render_chart¶
render_chart
¶
render_chart(chart: CompiledChart | Any, data: list[dict[str, Any]], format: str = 'json', width: float | None = None, height: float | None = None, theme: str | None = None, is_placeholder: bool = False) -> str
Render a chart to the specified format.
| PARAMETER | DESCRIPTION |
|---|---|
chart
|
CompiledChart definition
TYPE:
|
data
|
List of dicts containing chart data
TYPE:
|
format
|
Output format ('json', 'svg', 'png', 'pdf')
TYPE:
|
width
|
Optional explicit width in pixels
TYPE:
|
height
|
Optional explicit height in pixels
TYPE:
|
theme
|
Optional theme name to apply (e.g., 'dark', 'light')
TYPE:
|
is_placeholder
|
If True, render with placeholder styling (reduced opacity, "add data" overlay). Used when chart has no query/data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Rendered chart as string |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If format is not supported |
ImportError
|
If vl-convert-python is not installed for non-JSON formats |
Source code in dataface/core/render/vega_lite.py
3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 | |
HTML Output¶
HTML output is now a minimal wrapper around SVG output. Use format='html' to get
a complete HTML document that embeds the SVG dataface with proper styling.
The SVG content includes all interactivity via embedded JavaScript and foreignObject elements for variable controls.
Errors¶
errors
¶
Rendering error types.
Stage: RENDER Purpose: Define error types for rendering failures.
These errors are raised during: - General rendering failures (RenderError) - Format conversion (FormatError)
All errors inherit from RenderError for easy catching.
Note: Many render errors are displayed IN the output rather than thrown, so users see helpful error messages in the rendered dataface.
RenderError
¶
Bases: Exception
Base error for all rendering failures.
This is the parent class for all rendering-related errors. Catch this to handle any rendering error.
| ATTRIBUTE | DESCRIPTION |
|---|---|
message |
Human-readable error description
|
element |
Element that failed to render (if applicable)
|
Source code in dataface/core/render/errors.py
FormatError
¶
Bases: RenderError
Error during format conversion.
Raised when: - Unknown format requested - SVG to PNG/PDF conversion fails - HTML template error
Example
try: ... render(face, executor, format="unknown") ... except FormatError as e: ... print(f"Format error: {e}")