Compile Stage¶
The compile stage transforms YAML dataface definitions into normalized, validated CompiledFace objects ready for execution and rendering.
Entry Points¶
compile¶
The main entry point for compiling YAML content:
compile
¶
compile(yaml_content: str, options: dict[str, Any] | None = None, base_dir: Path | None = None, project_dir: Path | None = None) -> CompileResult
Compile YAML content to a CompiledFace.
Stage: COMPILE (Full Pipeline)
This is the main entry point for compilation. It orchestrates: 1. PARSE: YAML string → Face object 2. VALIDATE: Check structure and references 3. NORMALIZE: Resolve references, add metadata
Layout sizing happens later in the render pipeline (data-aware).
| PARAMETER | DESCRIPTION |
|---|---|
yaml_content
|
YAML string to compile
TYPE:
|
options
|
Optional compilation options
TYPE:
|
base_dir
|
Base directory for resolving file references
TYPE:
|
project_dir
|
Project directory for resolving project-level sources
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompileResult
|
CompileResult with compiled face or errors |
Example
yaml_content = ''' ... title: My Dataface ... queries: ... users: SELECT * FROM users ... charts: ... user_count: ... query: users ... type: kpi ... value: count ... rows: ... - user_count ... ''' result = compile(yaml_content) if result.success: ... face = result.face ... print(face.title) # "My Dataface"
Source code in dataface/core/compile/compiler.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 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 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 | |
compile_file¶
Compile from a file path:
compile_file
¶
compile_file(file_path: Path, options: dict[str, Any] | None = None, apply_meta: bool = True, root_path: Path | None = None) -> CompileResult
Compile a YAML file to a CompiledFace.
Convenience function that reads a file and compiles it. Optionally applies meta.yaml cascading configuration from parent directories.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Path to YAML file
TYPE:
|
options
|
Optional compilation options
TYPE:
|
apply_meta
|
If True, resolve and apply meta.yaml chain (default: True)
TYPE:
|
root_path
|
Project root for meta resolution (default: auto-detect)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompileResult
|
CompileResult with compiled face or errors |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If file doesn't exist |
Example
result = compile_file(Path("face.yml")) if result.success: ... print(result.face.title)
Source code in dataface/core/compile/compiler.py
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 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 | |
CompileResult¶
The result object returned by compilation:
CompileResult
dataclass
¶
CompileResult(face: CompiledFace | None = None, errors: list[CompilationError] = list(), warnings: list[str] = list(), suppressed_warnings: list[str] = list(), diagnostics: list[QueryDiagnostic] = list(), query_registry: dict[str, CompiledQuery] = dict(), meta_config: Any = None)
Result of compilation.
Contains the compiled face (if successful), any errors encountered, and warnings that don't prevent compilation.
| ATTRIBUTE | DESCRIPTION |
|---|---|
face |
Compiled face (None if errors occurred)
TYPE:
|
errors |
List of compilation errors
TYPE:
|
warnings |
List of non-fatal warnings (human-readable strings)
TYPE:
|
diagnostics |
Structured query diagnostics from validate_compiled_queries.
Includes all severity levels;
TYPE:
|
query_registry |
All normalized queries (for executor)
TYPE:
|
sources |
Source configurations (for resolving named source references)
TYPE:
|
Example
result = compile(yaml_content) if result.success: ... print(f"Compiled: {result.face.title}") ... else: ... for error in result.errors: ... print(f"Error: {error}")
Compiled Types¶
These types represent the output of compilation, with all fields guaranteed to be present.
CompiledFace¶
CompiledFace
¶
Bases: BaseModel
Compiled face ready for execution and rendering.
Stage: COMPILE output / EXECUTE and RENDER input
This is the main output of compilation. It contains: - Resolved definitions (variables, queries, charts) - Unified layout structure - Calculated dimensions - Applied defaults and metadata
Guarantees
- id: Always set
- title: Always set (empty string if not provided)
- layout: Always present (unified structure)
- All charts resolved to CompiledChart objects
- All queries resolved to query objects
| ATTRIBUTE | DESCRIPTION |
|---|---|
id |
Unique identifier for this face
TYPE:
|
title |
Display title
TYPE:
|
description |
Description text
TYPE:
|
variables |
Variable definitions (Dict[str, Variable])
TYPE:
|
queries |
Compiled queries (Dict[str, CompiledQuery])
TYPE:
|
charts |
Compiled charts (Dict[str, CompiledChart])
TYPE:
|
layout |
Unified layout structure
TYPE:
|
variable_defaults |
Resolved default values for variables
TYPE:
|
style |
Face styling
TYPE:
|
Example: >>> result = compile(yaml_content) >>> face = result.face >>> print(face.id) # "sales-dataface" >>> print(face.title) # "Sales Dataface" >>> print(face.layout.type) # "rows" >>> for item in face.layout.items: ... chart = item.chart ... print(f"Chart: {chart.id}, Query: {chart.query_name}")
CompiledChart¶
CompiledChart
¶
Bases: ChartFields
Compiled chart ready for execution and rendering.
Stage: COMPILE output / EXECUTE and RENDER input
Inherits shared data-mapping, geo, and interaction fields from ChartFields. Adds compiled-specific fields (id, resolved query, variable_dependencies, etc.) with guaranteed structure.
Guarantees vs ChartPatch (input type): | Field | ChartPatch (input) | CompiledChart (compiled) | |-------------|-----------------------|----------------------------| | id | Optional[str] | str (always present) | | title | Optional[str] | str (empty string default) | | subtitle | Optional[str] | str (empty string default) | | description | Optional[str] | str (empty string default) | | query | str (reference) | Query object (resolved) |
Downstream code can access fields directly without checking for None.
| ATTRIBUTE | DESCRIPTION |
|---|---|
id |
Unique identifier within the dashboard.
TYPE:
|
query |
Resolved query object (SqlQuery, CsvQuery, etc.)
TYPE:
|
query_name |
String name for executor lookup.
TYPE:
|
type |
Chart type (line, bar, table, etc.)
TYPE:
|
title |
Display title. Empty string if not provided.
TYPE:
|
subtitle |
Secondary title line. Empty string if not provided.
TYPE:
|
description |
Description. Empty string if not provided.
TYPE:
|
convert_dicts_to_typed
classmethod
¶
Auto-convert dict to typed models for style field.
Compiled charts are expected to come from normalized Chart input,
which already validates the Vega-Lite passthrough contract. Keep this
hook limited to internal wrapper conversions needed by downstream code.
Source code in dataface/core/compile/compiled_types.py
validate_kpi
¶
Validate KPI charts have a value (column reference or literal).
Note: This only validates when type is explicitly "kpi". When type is "auto", validation is deferred to render time.
Source code in dataface/core/compile/compiled_types.py
validate_error
¶
Validate error charts have message field.
Source code in dataface/core/compile/compiled_types.py
validate_explicit_chart_surface
¶
Validate line and pie charts against explicit allowed terms.
Source code in dataface/core/compile/compiled_types.py
to_dict
¶
Convert chart to YAML-compatible dict.
Returns a minimal dict suitable for YAML serialization, excluding internal/computed fields like variable_dependencies.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dict representation suitable for YAML export |
Source code in dataface/core/compile/compiled_types.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |
get_dependencies
¶
Get all dependencies required to render this chart.
Collects sources, variables, and queries that this chart needs. Use this to extract minimal preview dashboards.
| RETURNS | DESCRIPTION |
|---|---|
ChartDependencies
|
ChartDependencies with sources, variables, and queries needed |
Source code in dataface/core/compile/compiled_types.py
LayoutItem¶
LayoutItem
¶
Bases: BaseModel
A single item in a layout.
Represents either a chart or a nested face in the layout. The unified structure makes iteration simple:
for item in layout.items:
if item.type == "chart":
render_chart(item.chart)
else:
render_face(item.face)
| ATTRIBUTE | DESCRIPTION |
|---|---|
type |
Either "chart" or "face"
TYPE:
|
chart |
CompiledChart if type == "chart"
TYPE:
|
face |
CompiledFace if type == "face"
TYPE:
|
Grid-specific (optional): row, col: Grid position (0-based) row_span, col_span: Grid span (in grid units)
Calculated dimensions (set by sizing module): width_fraction: What fraction of parent width (0.0-1.0) width: Pixel width height: Pixel height x: X position in pixels y: Y position in pixels
Query Types¶
Dataface supports multiple query types through a unified interface.
SqlQuery¶
SqlQuery
¶
Bases: Query
SQL query against a database.
Executes raw SQL against the configured database connection. Supports Jinja templating for variable substitution.
Required Fields
sql: SQL query string (may contain Jinja templates)
Connection Fields (one required): source: Source name or inline config
Optional Fields
target: dbt target name (defaults to 'dev' if not specified)
Example
query = SqlQuery( ... sql="SELECT * FROM users WHERE id = {{ user_id }}", ... source="my_postgres" ... ) query.query_type # "sql" query.source_description # "SQL: SELECT * FROM users WHERE id = {{ user_..."
CsvQuery¶
CsvQuery
¶
Bases: Query
Query data from a CSV file.
Loads and queries data from CSV files. Supports column selection, filtering, and limiting results.
Fields (one required): file: Path to CSV file (relative to project root or absolute) source: Source reference or inline CSV source config
Optional Fields
columns: List of columns to select (default: all) filter: Dict of column->value for exact match filtering
Example
query = CsvQuery(file="data/sales.csv", columns=["date", "amount"]) query.query_type # "csv" query.source_description # "CSV: data/sales.csv"
HttpQuery¶
HttpQuery
¶
Bases: Query
Query data from an HTTP API.
Fetches data from REST API endpoints. Supports various HTTP methods, headers, query parameters, and request bodies.
Fields
url: Full URL of the API endpoint (legacy) source: Source reference or inline HTTP source config (new) path: API path (appended to base URL from source)
Optional Fields
method: HTTP method (default: GET) headers: Request headers (merged with source headers) params: Query parameters body: Request body (for POST/PUT/PATCH) json_path: JSONPath expression to extract data from response
Example
query = HttpQuery( ... source="model_api", ... path="/predict", ... method="POST", ... body={"input": "data"} ... ) query.query_type # "http" query.source_description # "HTTP: POST model_api/predict"
MetricFlowQuery¶
MetricFlowQuery
¶
Bases: Query
Query the dbt Semantic Layer.
Executes queries against dbt's Semantic Layer using MetricFlow. Supports metrics, dimensions, filters, and time grains.
Required Fields
metrics: List of metric names to query
Optional Fields
dimensions: List of dimension names to group by time_grain: Time grain for time-based dimensions (day, week, month, etc.)
Example
query = MetricFlowQuery( ... metrics=["revenue", "orders"], ... dimensions=["date_day", "region"] ... ) query.query_type # "metricflow" query.source_description # "MetricFlow: revenue, orders"
Input Types¶
These types represent the raw YAML structure before normalization.
Face¶
Face
¶
Bases: BaseModel
Face (dataface) definition from YAML.
This is the top-level input type representing a complete dataface. A face contains definitions (variables, queries, charts) and a layout.
Example YAML
title: Sales Dataface description: Overview of sales metrics
sources: default: my_postgres # Default source for all queries
variables: date_range: input: daterange default: ["2024-01-01", "2024-12-31"]
queries: sales: SELECT * FROM sales WHERE date BETWEEN ...
charts: revenue: query: sales type: line x: date y: amount
rows: - revenue
Layout
Exactly one layout type should be present (rows, cols, grid, or tabs). Layout items can be: - Chart name (string reference) - Inline chart definition (dict with query and type) - Nested face (dict with layout keys)
Sources
Optional sources section with: - default: Default source name for all queries in this face - Inline source definitions (source_name: {...config...})
reject_face_key
classmethod
¶
Reject 'face' as a top-level key.
Source code in dataface/core/compile/types.py
validate_layout
¶
Ensure at least one layout type or content is defined.
Source code in dataface/core/compile/types.py
get_default_source
¶
Get the default source for this face.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Default source name, or None if not set |
Source code in dataface/core/compile/types.py
Chart¶
Chart
¶
Bases: ChartFields
Sparse authored chart input from board YAML.
All fields optional. Validated during YAML parsing, then normalized into CompiledChart during compilation.
ChartPatch → CompiledChart
Chart-local style uses ChartStylePatch for typed, closed-contract
overlay.
Example YAML::
charts:
revenue_trend:
query: sales_by_date
type: line
title: "Revenue Trend"
x: date
y: amount
color: category
style:
background: "#f8f8f8"
reject_removed_vl_passthrough_fields
classmethod
¶
Reject removed chart-level VL passthrough fields with a clear error.
The normalizer rejects these first for standard compilation paths; this validator is a fallback for direct ChartPatch construction.
Source code in dataface/core/compile/chart.py
validate_kpi
¶
KPI charts must specify a value (column reference or literal).
Source code in dataface/core/compile/chart.py
validate_error
¶
Error charts must specify a message.
Source code in dataface/core/compile/chart.py
validate_layered
¶
Layered charts require non-empty layers; layers require type: layered.
Source code in dataface/core/compile/chart.py
validate_explicit_chart_surface
¶
Validate line and pie charts against explicit allowed terms.
validate_data_table
¶
Validate the data_table block at the ChartPatch layer.
Covers the data-free portion of spec §3: - Chart-type eligibility (bar, line, area; everything else rejects with a single unified error per ADR-006). - Multi-y / layered rejection (spec §1 single-unambiguous-x). - Duplicate-entry rejection (spec §3.2).
Data-aware checks (source-column existence, multi-row-per-x ambiguity, x-axis cardinality > 40) live in the render pipeline where query output is known.
Source code in dataface/core/compile/chart.py
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | |
Query¶
Query
¶
Bases: BaseModel
Query definition from YAML.
Queries fetch data from various sources. The type field determines which adapter handles execution.
Supported types: - sql: Raw SQL query (default) - metricflow: dbt Semantic Layer query - dbt_model: Query against a dbt model - http: REST API query - csv: CSV file query
Example YAML
queries: sales_by_date: sql: SELECT date, SUM(amount) FROM sales GROUP BY date source: my_postgres # Source reference
metrics_query: type: metricflow metrics: [revenue, orders] dimensions: [date_day]
api_data: type: http url: https://api.example.com/data
Errors¶
errors
¶
Compilation error types.
Stage: COMPILE Purpose: Define error types for all compilation failures.
These errors are raised during: - YAML parsing (ParseError, YAMLError) - Schema validation (ValidationError) - Reference resolution (ReferenceError) - Jinja template rendering (JinjaError)
All errors inherit from CompilationError for easy catching.
Enhanced error messages include: - Line numbers where errors occur - YAML context showing the problematic snippet - Helpful suggestions ("Did you mean 'bar'?")
Refs #94
CompilationError
¶
CompilationError(message: str, location: str | None = None, line: int | None = None, column: int | None = None, context: str | None = None, suggestion: str | None = None)
Bases: DatafaceError
Base error for all compilation failures.
This is the parent class for all compilation-related errors. Catch this to handle any compilation error.
| ATTRIBUTE | DESCRIPTION |
|---|---|
message |
Human-readable error description
|
location |
Optional location in source (line number, path, etc.)
TYPE:
|
line |
Optional line number in the YAML file
TYPE:
|
column |
Optional column number in the YAML file
TYPE:
|
context |
Optional YAML snippet showing the error location
TYPE:
|
suggestion |
Optional helpful suggestion for fixing the error
TYPE:
|
Source code in dataface/core/compile/errors.py
ParseError
¶
ParseError(message: str, line: int | None = None, context: str | None = None, suggestion: str | None = None)
Bases: CompilationError
Error during YAML parsing.
Raised when: - YAML syntax is invalid - YAML structure cannot be parsed
| ATTRIBUTE | DESCRIPTION |
|---|---|
line |
Line number where the error occurred
TYPE:
|
context |
YAML snippet showing the error location
TYPE:
|
suggestion |
Helpful fix suggestion
TYPE:
|
Example
try: ... compile("invalid: yaml: content") ... except ParseError as e: ... print(f"Parse failed at line {e.line}: {e}")
Source code in dataface/core/compile/errors.py
ValidationError
¶
ValidationError(message: str, location: str | None = None, line: int | None = None, context: str | None = None, suggestion: str | None = None, field_path: str | None = None, invalid_value: str | None = None, valid_values: list | None = None)
Bases: CompilationError
Error during schema validation.
Raised when: - Required fields are missing - Field values are invalid type - Enum values are not recognized - Schema constraints are violated
| ATTRIBUTE | DESCRIPTION |
|---|---|
field_path |
Path to the field that failed validation
TYPE:
|
invalid_value |
The value that caused the error
TYPE:
|
valid_values |
List of valid values (if applicable)
TYPE:
|
line |
Line number where the error occurred
TYPE:
|
context |
YAML snippet showing the error location
TYPE:
|
suggestion |
Helpful fix suggestion
TYPE:
|
Example
try: ... compile("charts:\n my_chart:\n type: invalid_type") ... except ValidationError as e: ... print(f"Validation failed at line {e.line}: {e}")
Source code in dataface/core/compile/errors.py
ReferenceError
¶
Bases: CompilationError
Error resolving a reference.
Raised when: - Chart references unknown query - Layout references unknown chart - Remote reference cannot be resolved - Partial file not found
| ATTRIBUTE | DESCRIPTION |
|---|---|
ref |
The reference that could not be resolved
TYPE:
|
context |
Where the reference was used
TYPE:
|
Example
try: ... compile("charts:\n my_chart:\n query: unknown_query") ... except ReferenceError as e: ... print(f"Reference '{e.ref}' not found")
Source code in dataface/core/compile/errors.py
JinjaError
¶
Bases: CompilationError
Error during Jinja template resolution.
Raised when: - Jinja syntax is invalid - Variable not found in template context - Filter not found
| ATTRIBUTE | DESCRIPTION |
|---|---|
template |
The template that caused the error (if available)
TYPE:
|
Example
try: ... compile("queries:\n q: SELECT * FROM {{ undefined_var }}") ... except JinjaError as e: ... print(f"Template error: {e}")
Source code in dataface/core/compile/errors.py
Internal Modules¶
These are used internally by the compiler. Most users won't need to use them directly.
Parser¶
parse_yaml
¶
Parse YAML content into a Face object.
Stage: COMPILE (Step 1 of 4: Parsing)
This is the first step of compilation. It converts a raw YAML string into a structured Face object. Only basic syntax validation happens here - schema validation is the next step.
Enhanced error messages include: - Line numbers where errors occur - YAML context showing the problematic snippet - Helpful suggestions ("Did you mean?")
| PARAMETER | DESCRIPTION |
|---|---|
content
|
Raw YAML string to parse
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Face
|
Face object with parsed structure |
| RAISES | DESCRIPTION |
|---|---|
ParseError
|
If YAML syntax is invalid or parsing fails |
Example
yaml_content = ''' ... title: My Dataface ... queries: ... sales: SELECT * FROM sales ... charts: ... revenue: ... query: sales ... type: line ... rows: ... - revenue ... ''' face = parse_yaml(yaml_content) face.title 'My Dataface'
Source code in dataface/core/compile/parser.py
Validator¶
validate_face
¶
Validate a Face structure and cross-references.
Stage: COMPILE (Step 2 of 4: Validation)
Performs semantic validation beyond what Pydantic provides: - Chart → Query references exist - Layout items reference existing charts
Note: Pydantic already validates types, required fields, and nested structures during parsing. This function adds cross-reference validation.
| PARAMETER | DESCRIPTION |
|---|---|
face
|
Parsed Face to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[ValidationError]
|
List of ValidationError objects (empty if valid) |
Example
face = parse_yaml(yaml_content) errors = validate_face(face) if errors: ... for e in errors: ... print(f"Error: {e}")
Source code in dataface/core/compile/validator.py
Normalizer¶
normalize_face
¶
normalize_face(face: Face, face_id: str | None = None, parent_context: dict[str, Any] | None = None, query_registry: dict[str, CompiledQuery] | None = None, chart_registry: dict[str, Any] | None = None, depth: int = 0, base_path: Path | None = None) -> CompiledFace
Normalize a Face into a CompiledFace with guaranteed structure.
Stage: COMPILE (Step 3 of 4: Normalization)
This is the core transformation from user-provided YAML structure to the internal compiled representation. After this step, all references are resolved, IDs are assigned, and downstream code can rely on guaranteed field presence.
Normalization performs: - Resolve all chart references (queries, extends, partials) - Generate unique IDs for all entities - Apply defaults (title from ID, empty description) - Transform input types to compiled types - Create unified Layout structure - Propagate default source to queries without explicit source
| PARAMETER | DESCRIPTION |
|---|---|
face
|
Input Face from parsing/validation step.
TYPE:
|
face_id
|
Optional explicit ID for this face
TYPE:
|
parent_context
|
Context from parent face (for nested faces)
TYPE:
|
query_registry
|
Complete query registry for reference resolution
TYPE:
|
chart_registry
|
Complete chart registry for reference resolution
TYPE:
|
depth
|
Current nesting depth (for cycle detection)
TYPE:
|
base_path
|
Base path for resolving external file references
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompiledFace
|
CompiledFace with guarantees: - All fields required by compiled types are present - All references resolved to actual objects - All IDs are unique and deterministic - Layout is unified (rows/cols/grid/tabs → Layout type) |
| RAISES | DESCRIPTION |
|---|---|
ReferenceError
|
When a chart references an undefined query |
CompilationError
|
When normalization fails |
Example
face = parse_yaml(yaml_content) errors = validate_face(face) if not errors: ... compiled = normalize_face(face) ... print(compiled.charts['revenue'].id) # Guaranteed to exist 'revenue'
Source code in dataface/core/compile/normalizer.py
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 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 | |
Sizing¶
calculate_layout
¶
Calculate dimensions for all layout items.
Stage: COMPILE (Step 4 of 4: Layout Calculation)
This is the final compilation step. It calculates pixel dimensions for all charts and nested faces based on layout type and nesting.
The sizing is content-aware: - KPIs get smaller heights (~100px) - Charts get standard heights (~300px) - Titles are measured for text wrapping - Nested faces accumulate their content heights
| PARAMETER | DESCRIPTION |
|---|---|
face
|
CompiledFace with layout structure
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompiledFace
|
CompiledFace with calculated dimensions on layout items |
Example
face = normalize_face(parsed_face) face = calculate_layout(face) print(face.layout.width, face.layout.height) 1200.0 800.0
Source code in dataface/core/compile/sizing.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |