Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions docs/output-formats-and-report-specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,37 @@ Column(name='Zone Profile All', key='zoneProfileAllMermaidPieChart'),
Column(name='Zone Profiles', key='zone_profile_mermaid_pie_chart'),
```

The `name` field has no effect on detection for pie chart or custom graph columns — only the `key` matters. For the generic flowchart case (`key='mermaidGraph'`, `name='Mermaid Graph'`) both routes happen to match, which is why it appears to work with either case.
Detection goes by the `key` first. A `name` also counts when its title ends in "Mermaid Graph", "Mermaid Mind Map", "Mermaid Pie Chart" or "Lineage Graph" (or is "Mermaid Graph" or "Mermaid"). For the generic flowchart case (`key='mermaidGraph'`, `name='Mermaid Graph'`) both routes match, which is why it appears to work with either case.

#### Recognised camelCase mermaid keys (`MERMAID_ATTRIBUTE_KEYS`)
#### Any graph key Egeria returns is recognised (6.2.29)

`is_mermaid_graph_key()` in `pyegeria/view/output_formatter.py` treats a key as a Mermaid graph when it ends in `MermaidGraph`, `MermaidMindMap`, `MermaidPieChart` or `LineageGraph` (the ending's case is ignored). The last covers `fieldLevelLineageGraph` and `localLineageGraph`, which carry no "Mermaid". So a new kind of graph from Egeria renders as Mermaid in a REPORT, HTML or MERMAID output with no code change; the table below lists the keys known so far. Vega-Lite keys (`...BarGraph`, `...PieGraph` and so on) are not matched and are checked first.

#### The action and activity graphs follow the context graph (6.2.29)

From Egeria 6.2.29 the context graph, `mermaidGraph`, leaves out relationships whose purpose is Action or Activity; `actionMermaidGraph` and `activityMermaidGraph` show them. So wherever a report offers the context graph (a column keyed `mermaidGraph`, or the `mermaid` column filled from it), pyegeria shows each of these two right after it, when the element carries it:

| Output | What is added |
| :--- | :--- |
| MERMAID | A Mermaid block per companion graph, after the context graph |
| REPORT, and HTML (rendered from the REPORT) | `### Action Mermaid Graph` and `### Activity Mermaid Graph` sections, after the context graph |
| DICT | `Action Mermaid Graph` and `Activity Mermaid Graph` entries, after the context graph's entry |
| TABLE, LIST, MD, FORM | Nothing: every row of a table has the same columns, and MD/FORM show no graphs |

A companion the spec already selects (for example `Asset-Graph`'s own `Action Graph` column) is not repeated, and an element that carries neither key gives exactly the output it gave before. Egeria already returns `actionMermaidGraph` (for Assets, for example), so this changes output today: `Asset-Graph`'s MERMAID shows the context graph, then the action graph.

**Key on every row.** In a DICT result of several rows, when any row carries a companion, every row gets that key right after its context graph, with `""` where the element has none, so a table renderer sees one row shape. A single row, or rows none of which carries a companion, are left as they are.

#### Mermaid keys named so far (`MERMAID_ATTRIBUTE_KEYS`)

| Key | Typical content |
| :--- | :--- |
| `mermaidGraph` | General-purpose flowchart |
| `anchorMermaidGraph` | Anchor graph |
| `informationSupplyChainMermaidGraph` | Information supply chain |
| `fieldLevelLineageGraph` | Field-level lineage |
| `actionMermaidGraph` | Governance action graph |
| `actionMermaidGraph` | Relationships whose purpose is Action (left out of `mermaidGraph` from Egeria 6.2.29) |
| `activityMermaidGraph` | Relationships whose purpose is Activity (left out of `mermaidGraph` from Egeria 6.2.29) |
| `localLineageGraph` | Local lineage |
| `edgeMermaidGraph` | Edge graph |
| `iscImplementationMermaidGraph` | ISC implementation graph (context, solution-component design, implementation status). Servers before Egeria 6.3 sent `iscimplementationMermaidGraph`; it is matched case-insensitively |
Expand All @@ -458,8 +478,13 @@ The `name` field has no effect on detection for pie chart or custom graph column
| `zoneProfileMermaidPieChart` | Zone membership profile |
| `zoneProfileAnchoredMermaidPieChart` | Zone anchored-elements profile |
| `zoneProfileAllMermaidPieChart` | Zone all-elements profile |
| `userAccountTypeProfileMermaidPieChart` | Secrets collection: user accounts by type |
| `userAccountStatusProfileMermaidPieChart` | Secrets collection: user accounts by status |
| `organizationTreeMermaidGraph` | Organization tree |
| `rootHierarchyMermaidGraph` | Root hierarchy |
| `fullLineageMermaidGraph` | Full lineage |

If you add a new mermaid attribute not in this table, add its camelCase key to `MERMAID_ATTRIBUTE_KEYS` in `pyegeria/view/output_formatter.py`.
A key with one of the endings above needs no entry here. Add a key to `MERMAID_ATTRIBUTE_KEYS` only if Egeria ever names a graph without one of those endings.

### Syntax Compatibility
Egeria often produces Mermaid output using newer syntax features (like `@ { shape: ... }`) or YAML frontmatter that some Markdown renderers (e.g., Obsidian, PyCharm) do not yet support.
Expand Down
26 changes: 26 additions & 0 deletions docs/release-notes/6.2.29.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,29 @@
it still scans every `SemanticAssignment` relationship. Its viewer term count (13.5 s live) now
runs on its own thread while the scan pages: 22.6 s became 16.8 s live, with the same answer (984
orphans of 1,061 terms).
- **A report that offers the context graph (`mermaidGraph`) now also shows the action and activity graphs
when Egeria returns them.** This changes output today: Egeria already returns `actionMermaidGraph`, for example
for Assets.
- From Egeria 6.2.29 `mermaidGraph` leaves out relationships whose purpose is Action or Activity. Two graphs
show them instead: `actionMermaidGraph` (already returned, for Assets and others) and `activityMermaidGraph`
(new).
- "Offers the context graph" means a `mermaidGraph` column, or the `mermaid` column filled from it. Each of the
two graphs follows the context graph, when the element carries it:
- as a Mermaid block in MERMAID;
- as a section in REPORT and HTML;
- as an entry in DICT.
- **For example, `Asset-Graph`'s MERMAID output now has two blocks for an asset with an action graph: the context
graph, then the action graph.**
- A graph the spec already selects is not repeated (`Asset-Graph`'s REPORT shows its own `Action Graph` once).
TABLE, LIST, MD and FORM are unchanged.
- **Key on every row.** In a DICT result of several rows, if any row carries `Action Mermaid Graph` or `Activity
Mermaid Graph`, every row gets that key, after its context graph, empty (`""`) where the element has none. So
the rows keep one shape for table renderers. A single row, or rows none of which carries one, are unchanged.
- An element that carries neither graph gives the output it gave in 6.2.28. Checked by rendering every spec in
every declared format (674 renders) before and after; the seed is unchanged.
- **Any graph Egeria returns renders as Mermaid.** `is_mermaid_graph_key()` recognises a key ending in
`MermaidGraph`, `MermaidMindMap`, `MermaidPieChart` or `LineageGraph`, so a new kind of graph needs no code change.
- That covers the keys pyegeria did not name before: `activityMermaidGraph`, the `userAccountTypeProfile` and
`userAccountStatusProfile` pie charts, and others.
- Vega-Lite keys (`...BarGraph`, `...PieGraph`) are not matched.
- A column title ending in "Mermaid Graph", "Mermaid Mind Map", "Mermaid Pie Chart" or "Lineage Graph" also counts.
129 changes: 127 additions & 2 deletions pyegeria/view/output_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,65 @@ def _resolve_normalize_mermaid_flag(default: bool = True) -> bool:
"zoneProfileAllMermaidPieChart",
"userAccountTypeProfileMermaidPieChart",
"userAccountStatusProfileMermaidPieChart",
"activityMermaidGraph",
}

#: Egeria names every graph it returns with one of these endings (6.2.29). Two lineage keys,
#: fieldLevelLineageGraph and localLineageGraph, carry no "Mermaid", hence "LineageGraph".
#: A key with one of these endings is a Mermaid graph, so a new kind of graph from Egeria is
#: recognised without a code change. MERMAID_ATTRIBUTE_KEYS stays for the keys named so far.
MERMAID_KEY_SUFFIXES = ("MermaidGraph", "MermaidMindMap", "MermaidPieChart", "LineageGraph")
_MERMAID_KEY_SUFFIXES_LOWER = tuple(s.lower() for s in MERMAID_KEY_SUFFIXES)
_MERMAID_TITLE_SUFFIXES = ("Mermaid Graph", "Mermaid Mind Map", "Mermaid Pie Chart", "Lineage Graph")

#: From Egeria 6.2.29 the context graph (mermaidGraph) leaves out relationships whose purpose is
#: Action or Activity; these two graphs show them. Wherever a report offers mermaidGraph, these
#: follow it when the element carries them, so those relationships do not vanish from the report.
MERMAID_COMPANION_GRAPHS = (
("actionMermaidGraph", "Action Mermaid Graph"),
("activityMermaidGraph", "Activity Mermaid Graph"),
)
#: Column keys that carry the context graph: the response key itself, and the 'mermaid' column
#: that populate_common_columns fills from mermaidGraph.
_CONTEXT_GRAPH_KEYS = ("mermaidGraph", "mermaid")


def is_mermaid_graph_key(key: str | None) -> bool:
"""True when `key` names a Mermaid graph in an Egeria response (case of the ending ignored)."""
if not isinstance(key, str) or not key:
return False
return key in MERMAID_ATTRIBUTE_KEYS or key.lower().endswith(_MERMAID_KEY_SUFFIXES_LOWER)


def _is_mermaid_attribute(attribute_name: str | None = None, attribute_key: str | None = None) -> bool:
"""Return True when a selected report attribute should be rendered as Mermaid."""
if attribute_key in MERMAID_ATTRIBUTE_KEYS:
if is_mermaid_graph_key(attribute_key):
return True

attribute_title = camel_to_title_case(attribute_name or "")
return attribute_title in MERMAID_GRAPH_TITLES + ["Mermaid Graph", "Mermaid"]
return (attribute_title in MERMAID_GRAPH_TITLES + ["Mermaid Graph", "Mermaid"]
or attribute_title.endswith(_MERMAID_TITLE_SUFFIXES))


def _companion_mermaid_columns(element: Any, column_keys) -> list[dict]:
"""The action/activity graphs to show after the context graph, as columns.

Only when the report offers the context graph (a column keyed mermaidGraph or 'mermaid'),
only for a companion the report does not already select, and only when the element carries
it with a value. An element with neither key gets nothing, so its output is unchanged.
"""
keys = set(k for k in column_keys if k)
if not isinstance(element, dict) or not keys.intersection(_CONTEXT_GRAPH_KEYS):
return []
lower = {k.lower() for k in keys if isinstance(k, str)}
result = []
for key, name in MERMAID_COMPANION_GRAPHS:
if key.lower() in lower:
continue
value = _get_mermaid_graph_value(element, key)
if value not in (None, ""):
result.append({"name": name, "key": key, "value": value})
return result


_VEGA_KEY_SUFFIXES = ("BarGraph", "PieGraph", "VegaGraph", "LineGraph", "AreaGraph", "ScatterGraph", "FunnelGraph")
Expand Down Expand Up @@ -254,6 +303,9 @@ def _extract_selected_mermaid_fields(element: dict, columns_struct: Optional[dic
# Legacy compatibility: if no explicit Mermaid fields were selected, use mermaidGraph.
if not selected_fields:
selected_fields = [{"name": "Mermaid Graph", "key": "mermaidGraph"}]
# The action and activity graphs follow the context graph when the element carries them.
selected_fields = selected_fields + _companion_mermaid_columns(
element, [attribute.get("key") for attribute in selected_fields])

result = []
for attribute in selected_fields:
Expand Down Expand Up @@ -1184,6 +1236,9 @@ def generate_entity_md(elements: List[Dict],
# Add attributes based on column spec if available, otherwise, add all (legacy)
if returned_struct is not None:
cols = returned_struct.get('formats', {}).get('attributes', [])
# The action and activity graphs follow the context graph in a REPORT (and so in HTML).
companions = (_companion_mermaid_columns(element, [c.get('key') for c in cols if isinstance(c, dict)])
if output_format == 'REPORT' else [])
for column in cols:
name = column.get('name')
key = column.get('key')
Expand All @@ -1196,6 +1251,11 @@ def generate_entity_md(elements: List[Dict],
value = format_for_markdown_table(value, guid)

elements_md += make_md_attribute(name, value, output_format, attribute_key=key)
if companions and key in _CONTEXT_GRAPH_KEYS:
for companion in companions:
elements_md += make_md_attribute(companion["name"], companion["value"], output_format,
attribute_key=companion["key"])
companions = []

# Master-Detail support for REPORT, MD, and FORM formats
if detail_spec and value and output_format in ['REPORT', 'MD', 'FORM']:
Expand Down Expand Up @@ -1224,6 +1284,8 @@ def generate_entity_md(elements: List[Dict],
elements_md += ", ".join(wk)
elif base_columns:
# If we have columns but extractor didn't return struct, use legacy props lookup
companions = (_companion_mermaid_columns(element, [c.get('key') for c in base_columns])
if output_format == 'REPORT' else [])
for column in base_columns:
key = column['key']
name = column['name']
Expand All @@ -1235,6 +1297,11 @@ def generate_entity_md(elements: List[Dict],
if column.get('format'):
value = format_for_markdown_table(value, guid or props.get('GUID'))
elements_md += make_md_attribute(name, value, output_format, attribute_key=key)
if companions and key in _CONTEXT_GRAPH_KEYS:
for companion in companions:
elements_md += make_md_attribute(companion["name"], companion["value"], output_format,
attribute_key=companion["key"])
companions = []
if output_format in ('REPORT', 'MD', 'FORM') and (wk := columns_struct.get("annotations", {}).get("wikilinks", None)):
elements_md += ", ".join(wk)
else:
Expand Down Expand Up @@ -1456,6 +1523,33 @@ def generate_entity_md_table(elements: List[Dict],
return elements_md


def _uniform_companion_keys(rows: List[Dict], row_context_keys: List[Optional[str]]) -> None:
"""Key on every row (owner, 2026-11-09): when any DICT row carries a companion graph, every row
gets that key, empty ("") where its element has none, right after the row's context graph, so
table renderers see one row shape. A single row, or rows with no companion, are left as they are.
"""
names = [name for _, name in MERMAID_COMPANION_GRAPHS if any(name in row for row in rows)]
if not names or len(rows) < 2:
return
for row, context_key in zip(rows, row_context_keys):
if all(name in row for name in names):
continue
values = {name: row.get(name, "") for name in names}
if context_key not in row:
for name in names:
row.setdefault(name, "")
continue
rebuilt = {}
for key, value in row.items():
if key in values:
continue
rebuilt[key] = value
if key == context_key:
rebuilt.update(values)
row.clear()
row.update(rebuilt)


def generate_entity_dict(elements: List[Dict],
extract_properties_func: Callable,
get_additional_props_func: Optional[Callable] = None,
Expand All @@ -1479,6 +1573,7 @@ def generate_entity_dict(elements: List[Dict],
list: List of entity dictionaries
"""
result = []
row_context_keys = []

#####
# Add attributes based on column spec if available, otherwise, add all
Expand Down Expand Up @@ -1515,8 +1610,15 @@ def generate_entity_dict(elements: List[Dict],

# Create entity dictionary
entity_dict = {}
context_dict_key = None # the DICT key of the context graph's column, if the row has one

cols = local_columns_struct['formats'].get('attributes', None) if local_columns_struct else None
# The action and activity graphs follow the context graph in a DICT (not in a TABLE, whose
# rows must all have the same columns).
companion_source = (returned_struct.get('formats', {}).get('attributes', []) if returned_struct is not None
else cols or [])
companions = (_companion_mermaid_columns(element, [c.get('key') for c in companion_source if isinstance(c, dict)])
if output_format == 'DICT' else [])
if returned_struct is not None:
for column in returned_struct.get('formats', {}).get('attributes', []):
key = column.get('key')
Expand Down Expand Up @@ -1558,6 +1660,12 @@ def generate_entity_dict(elements: List[Dict],
tmp_key = f"{dict_key}_{suffix_idx}"
dict_key = tmp_key
entity_dict[dict_key] = value
if key in _CONTEXT_GRAPH_KEYS and context_dict_key is None:
context_dict_key = dict_key
if companions and key in _CONTEXT_GRAPH_KEYS:
for companion in companions:
entity_dict.setdefault(companion["name"], companion["value"])
companions = []
elif cols:
for column in cols:
key = column['key']
Expand All @@ -1580,6 +1688,12 @@ def generate_entity_dict(elements: List[Dict],
tmp_key = f"{dict_key}_{suffix_idx}"
dict_key = tmp_key
entity_dict[dict_key] = value
if key in _CONTEXT_GRAPH_KEYS and context_dict_key is None:
context_dict_key = dict_key
if companions and key in _CONTEXT_GRAPH_KEYS:
for companion in companions:
entity_dict.setdefault(companion["name"], companion["value"])
companions = []
else:
props = extract_properties_func(element, local_columns_struct)
# Add properties based on include/exclude lists
Expand All @@ -1595,6 +1709,10 @@ def generate_entity_dict(elements: List[Dict],
entity_dict[key] = value

result.append(entity_dict)
row_context_keys.append(context_dict_key)

if output_format == 'DICT':
_uniform_companion_keys(result, row_context_keys)
#####
# for element in elements:
# if element is None:
Expand Down Expand Up @@ -1848,6 +1966,13 @@ def populate_common_columns(
if key in MERMAID_GRAPHS and mermaid_dest_key not in MERMAID_GRAPHS:
column['value'] = _get_mermaid_graph_value(element, key) or ''
continue
# Any other graph key (the generic endings): fill it only when the element carries it,
# so a column the element lacks keeps the value it had before.
if is_mermaid_graph_key(key) and mermaid_dest_key not in MERMAID_GRAPHS:
graph_value = _get_mermaid_graph_value(element, key)
if graph_value is not None:
column['value'] = graph_value
continue

# --- Auto-generate Vega graphs for categorical counts if requested by the columns_struct ---
# Only do the heavy recursive scan if the report spec actually asks for a BarGraph or PieGraph
Expand Down
Loading
Loading