phart

Style Rules Specification

Status: Implemented in PHART v1.5.x (current branch behavior documented below).

Canonical Rule Model

Rules normalize into an internal structure such as:

id: spouse-male
priority: 100 # optional integer; higher runs first
target: edge # edge | node | connector | panel_header
when: role == "spouse" and v.sex == "M"
set:
  color: blue # required field for color behavior

Notes:

Supported targets:

Supported set keys:

Expression Language (v1.5)

Operators

Literals

Attribute references

Resolution rules:

String comparison semantics

Default string comparisons are case-insensitive in v1.5 for compatibility with existing edge color rule normalization.

Rule Sources

CLI (simple)

Keep existing:

--colors attr --edge-color-rule parenttype:father=bright_blue,mother=bright_magenta

This is compiled into equivalent advanced rules at parse time.

CLI (advanced)

CLI supports repeated option:

--style-rule 'edge: role=="spouse" and v.sex=="M" -> color=blue'
--style-rule 'edge: role=="spouse" and v.sex=="F" -> color=green'

Optional file input for complex sets:

--style-rules-file rules.yaml

File format: YAML or JSON containing a rules array using canonical model.

Programmatic

LayoutOptions accepts raw canonical rule dicts via style_rules:

style_rules=[
    {
        "target": "edge",
        "when": 'role == "spouse" and v.sex == "M"',
        "set": {"color": "blue"},
    }
]

Implementation note:

Evaluation Semantics

  1. Build evaluation context for each element.
  2. Sort rules by:
    1. priority descending
    2. declaration order ascending
  3. Evaluate when for matching target.
  4. On match, apply keys in set not yet assigned.
  5. Continue until all rules checked (or short-circuit if all requested fields set).

v1.5 color behavior:

Fallbacks:

Backward Compatibility

Legacy mapping example:

--edge-color-rule role:spouse=blue

normalizes to:

- target: edge
  when: edge.role == "spouse"
  set: { color: blue }

Error Handling

Security and Safety

Performance Expectations

Implementation Status (Phased)

Phase 1 completed:

Phase 2 completed:

Phase 3 completed for current scope:

Phase 3 Expansion: Legacy Feature Convergence

Background

PHART has two historical styling tracks:

The style-rule system should become the canonical per-element styling mechanism, while preserving backward compatibility for existing global options.

Implemented rule-settable fields (v1.5)

Node-target fields:

Edge-target fields:

Precedence model (implemented)

  1. Engine defaults
  2. LayoutOptions explicit global values
  3. Style rules (priority + declaration order)

Style rules are last-write authority for the fields they set.

Compatibility strategy (implemented)

Constraints

Examples

Simple edge attr:

rules:
  - target: edge
    when: role == "parent" and parenttype == "mother"
    set: { color: bright_magenta }

Edge + endpoint attr:

rules:
  - target: edge
    when: role == "spouse" and v.sex == "M"
    set: { color: blue }
  - target: edge
    when: role == "spouse" and v.sex == "F"
    set: { color: green }

Node rule:

rules:
  - target: node
    when: sex == "F"
    set: { color: bright_magenta }