Skip to content

fix(graph): make the entity type legend collapsible - #109

Open
Ravi chandu Edru (RaviChanduEdru) wants to merge 1 commit into
microsoft:mainfrom
RaviChanduEdru:fix/collapsible-graph-legend
Open

Ravi chandu Edru (RaviChanduEdru) wants to merge 1 commit into
microsoft:mainfrom
RaviChanduEdru:fix/collapsible-graph-legend

Conversation

@RaviChanduEdru

Copy link
Copy Markdown
Contributor

Fixes the first item of #87 — "a popup or overlay appears over the graph and obscures the nodes. I could not find an option to close, minimize, or move it."

The problem

The entity-type legend is absolutely positioned over the graph canvas and renders one row per entity type with no bound:

<div className="graph-legend">
  <div className="legend-title">Entity Types</div>
  {currentOntology.entityTypes.map(entity => ( ... ))}
</div>

There is no close, collapse, or move affordance anywhere — the only place it gets hidden is the mobile breakpoint, which drops it with display: none. On a large ontology it grows until it blankets the nodes it exists to annotate, which is what the reporter's screenshot shows.

The change

  • Collapsible. A header button collapses the legend to a single pill showing the title and the entity-type count. The choice persists to localStorage, so it survives a reload.
  • Sensible default for big ontologies. With no stored preference, the legend opens collapsed above LEGEND_AUTO_COLLAPSE_THRESHOLD (12) entity types, and re-applies that heuristic when a much larger ontology is loaded into an already-open session — so importing a big taxonomy doesn't bury the graph. An explicit toggle always wins over the heuristic.
  • Bounded. The expanded body is capped at 45% of canvas height with internal scrolling, so even an unbounded entity list can't cover the graph.

Extracted into GraphLegend.tsx — it now owns state, and OntologyGraph is already ~590 lines and mounts cytoscape on render, which makes it impractical to reach in jsdom. OntologyGraph's diff is a one-line swap.

Accessibility: the toggle carries aria-expanded / aria-controls, plus an aria-label that keeps the visible "Entity Types" text inside the accessible name (WCAG 2.5.3) — without it the button announced as "Entity Types3". Only existing theme tokens are used, so the contrast suite is unaffected.

Verification

10 new unit tests in GraphLegend.test.tsx cover expand/collapse, persistence, the size heuristic, explicit-choice precedence, mid-session ontology growth, and localStorage being unavailable.

Also driven against the running app with Playwright:

Scenario Result
Default ontology (6 types) opens expanded, all 6 rows
Click toggle collapses to the pill, 0 rows, persisted
Reload still collapsed
community/1010yab/university-class-search (19 types) opens collapsed
Expanding it 376px tall inside an 836px canvas, all 19 rows scrollable

No console errors in any state.

Notes

The legend is absolutely positioned over the graph canvas with no way to
close, minimize, or move it, and it renders one row per entity type with no
bound. On a large ontology it grows until it blankets the nodes it is meant
to annotate - the overlay complaint in microsoft#87, where the reporter could not find
any way to dismiss it. Outside the mobile breakpoint, which hides the legend
entirely, there was no escape.

Give the legend a header button that collapses it to a single pill showing
the title and the entity type count, persisted to localStorage so the choice
survives a reload. When the user has expressed no preference, the legend
opens collapsed for ontologies above LEGEND_AUTO_COLLAPSE_THRESHOLD entity
types, and re-applies that heuristic when a much larger ontology is loaded
into an open session - so importing a big taxonomy no longer buries the
graph. An explicit toggle always wins over the heuristic.

Cap the expanded body at 45% of the canvas height with internal scrolling, so
even an unbounded entity list cannot cover the graph.

Extracted to GraphLegend.tsx: it now owns state, and OntologyGraph is already
590 lines and mounts cytoscape on render, which makes it impractical to reach
in jsdom.

The toggle carries aria-expanded and aria-controls, plus an aria-label that
keeps the visible "Entity Types" text inside the accessible name (WCAG 2.5.3)
- without it the button announced as "Entity Types3".

Verified against the running app with Playwright: default ontology expands
with all 6 rows, collapses to the pill, and stays collapsed across a reload;
a 19-entity catalogue ontology opens collapsed, and expanding it stays inside
the canvas (376px of 836px) with all 19 rows scrollable. No console errors.
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.

1 participant