Render Stage¶
The render stage transforms compiled boards 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 dashboards:
render
¶
render(board: CompiledBoard, executor: Executor, format: str = 'svg', variables: Optional[VariableValues] = None, **options: Any) -> Union[str, bytes]
Render a compiled dashboard.
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 |
|---|---|
board
|
Compiled dashboard 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)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[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/render/renderer.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
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/render/renderer.py
Layout Functions¶
The layout module provides functions for rendering different layout types.
Rows Layout¶
render_rows_layout_svg
¶
render_rows_layout_svg(items: List[LayoutItem], executor: Executor, variables: VariableValues, available_width: float, available_height: float, gap: float, background: Optional[str] = None, theme: Optional[str] = None) -> str
Render items in vertical stack as SVG.
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 |
|---|---|
str
|
SVG string for rows layout |
Source code in dataface/render/layouts.py
Columns Layout¶
render_cols_layout_svg
¶
render_cols_layout_svg(items: List[LayoutItem], executor: Executor, variables: VariableValues, available_width: float, available_height: float, gap: float, background: Optional[str] = None, theme: Optional[str] = None) -> str
Render items in horizontal distribution as SVG.
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 |
|---|---|
str
|
SVG string for cols layout |
Source code in dataface/render/layouts.py
Grid Layout¶
render_grid_layout_svg
¶
render_grid_layout_svg(items: List[LayoutItem], executor: Executor, variables: VariableValues, available_width: float, available_height: float, columns: int, gap: float, background: Optional[str] = None, theme: Optional[str] = None) -> str
Render items in positioned grid as SVG.
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 |
|---|---|
str
|
SVG string for grid layout |
Source code in dataface/render/layouts.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 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 | |
Tabs Layout¶
render_tabs_layout_svg
¶
render_tabs_layout_svg(items: List[LayoutItem], executor: Executor, variables: VariableValues, available_width: float, available_height: float, tab_titles: Optional[List[str]] = None, active_tab: int = 0, tab_position: str = 'top', background: Optional[str] = None, theme: Optional[str] = None) -> str
Render tabbed container as SVG (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 |
|---|---|
str
|
SVG string for tabs layout (showing only active tab) |
Source code in dataface/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 359 360 361 | |
Vega-Lite Integration¶
Charts are rendered using Vega-Lite specifications.
generate_vega_lite_spec¶
generate_vega_lite_spec
¶
generate_vega_lite_spec(chart: Union[CompiledChart, Any], data: List[Dict[str, Any]], width: Optional[float] = None, height: Optional[float] = None, theme: Optional[str] = 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/render/vega_lite.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 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 | |
render_chart¶
render_chart
¶
render_chart(chart: Union[CompiledChart, Any], data: List[Dict[str, Any]], format: str = 'json', width: Optional[float] = None, height: Optional[float] = None, theme: Optional[str] = None) -> 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:
|
| 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/render/vega_lite.py
2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 | |
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 dashboard with proper styling.
The SVG content includes all interactivity via embedded JavaScript and foreignObject elements for variable controls.
Configuration¶
RenderConfig¶
RenderConfig
dataclass
¶
RenderConfig(background: Optional[str] = None, backgrounds: Dict[str, Optional[str]] = dict(), scale: float = 1.0, quality: int = 90)
Rendering configuration.
| ATTRIBUTE | DESCRIPTION |
|---|---|
background |
Default background color
TYPE:
|
backgrounds |
Format-specific backgrounds
TYPE:
|
scale |
Scale factor for PNG output
TYPE:
|
quality |
Quality setting for image output
TYPE:
|
get_background_for_format¶
get_background_for_format
¶
get_background_for_format(format: str, style: Optional[Any] = None, override: Optional[str] = None) -> Optional[str]
Get the appropriate background color for a format.
Priority: 1. Override parameter 2. Style format-specific background 3. Style general background 4. Default for format
| PARAMETER | DESCRIPTION |
|---|---|
format
|
Output format (svg, html, png, pdf, terminal)
TYPE:
|
style
|
Board style (BoardStyle object or dict for backwards compat)
TYPE:
|
override
|
Explicit override value
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[str]
|
Background color or None for transparent |
Source code in dataface/render/config.py
Errors¶
errors
¶
Rendering error types.
Stage: RENDER Purpose: Define error types for rendering failures.
These errors are raised during: - Chart rendering (ChartError) - Layout rendering (LayoutError) - 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 dashboard.
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/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(board, executor, format="unknown") ... except FormatError as e: ... print(f"Format error: {e}")
Source code in dataface/render/errors.py
ChartError
¶
Bases: RenderError
Error during chart rendering.
Raised when: - Chart type not supported - Data doesn't match chart requirements - Vega-Lite spec generation fails
Example
try: ... render_chart(chart, data) ... except ChartError as e: ... print(f"Chart failed: {e}")