Skip to content

Support readable node labels in interactive graph viewer#78

Merged
marota merged 2 commits into
masterfrom
claude/pypsa-voltage-level-labels-3oqwbn
Jun 17, 2026
Merged

Support readable node labels in interactive graph viewer#78
marota merged 2 commits into
masterfrom
claude/pypsa-voltage-level-labels-3oqwbn

Conversation

@marota

@marota marota commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Enhance the interactive HTML graph viewer to display readable node labels (e.g., voltage-level names like "Saucats 400kV") while preserving the stable node identity for selection, adjacency, and resolution logic. This improves operator experience by showing human-friendly names without breaking the underlying graph mechanics.

Key Changes

  • Search placeholder update: Changed from "filter nodes by name…" to "filter nodes by name or id…" to reflect new dual-matching behavior
  • Node display helpers: Added two new JavaScript functions:
    • nodeDisplayName(el): Returns the readable label if present, otherwise falls back to the stable node id
    • nodeHeaderHtml(el): Generates a formatted header showing the readable name in bold, with the raw id shown underneath only when it differs
  • Enhanced search: Modified the search filter to match against both data-name (stable id) and data-attr-label (readable label), allowing operators to find nodes by either spelling
  • Tooltip and info panel: Updated to use the new header functions, excluding the label attribute from the attribute list display (since it's now shown in the header)
  • Test coverage: Added two new tests:
    • test_readable_node_label_surfaces_without_losing_id: Verifies that readable labels are exposed and rendered while node identity is preserved
    • test_search_matches_readable_label_and_id: Confirms search functionality works with both label and id attributes

Implementation Details

  • The fmtAttrs() function now accepts an optional skip parameter to exclude specific attributes from the formatted output (used to hide label from the attribute list since it's displayed in the header)
  • Node identity (data-name) remains the canonical identifier for all graph operations; data-attr-label is purely for display
  • Backward compatible: nodes without a label attribute continue to work as before, displaying only their id

https://claude.ai/code/session_01SxDmpV5a1RZBgPd8gAuSvy

claude added 2 commits June 17, 2026 17:08
Node display labels (e.g. readable voltage-level names like "Saucats
400kV") are now usable in the interactive HTML viewer beyond just the
rendered text:

- Search matches both the stable id (data-name) and the readable
  label (data-attr-label), so a node can be found by either spelling.
- Hover tooltip and selection panel show the readable name as the
  header, with the raw id underneath only when it differs.
- fmtAttrs gains an optional skip list to avoid duplicating the label
  in the node attribute list.

Node identity (SVG <title> / data-name) is unchanged, so selection,
adjacency highlight and double-click SLD resolution keep using the id.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxDmpV5a1RZBgPd8gAuSvy
- Fix: label-less nodes carry the Graphviz "\N" placeholder in their
  label attribute; nodeDisplayName now ignores any backslash escape and
  falls back to the stable id, so tooltips/search never surface a
  literal "\N". Search uses the resolved display name.
- More tests: search consults id + resolved display name; tooltip/
  selection skip the duplicated label attribute; label-less nodes fall
  back to the id (no \N leak); readable label surfaces without losing id.
- Bump version to 0.3.2.post4 (setup.py + download_url).
- CHANGELOG: document the readable-node-name viewer feature, the \N fix
  and the tests under [0.3.2.post4].

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxDmpV5a1RZBgPd8gAuSvy
@marota marota merged commit bfc3b61 into master Jun 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants