Skip to content

fix: d3.select("svg") selects legend inline SVG instead of main canvas#451

Open
wangpi26 wants to merge 1 commit into
tirth8205:mainfrom
wangpi26:fix/d3-svg-selector
Open

fix: d3.select("svg") selects legend inline SVG instead of main canvas#451
wangpi26 wants to merge 1 commit into
tirth8205:mainfrom
wangpi26:fix/d3-svg-selector

Conversation

@wangpi26
Copy link
Copy Markdown

@wangpi26 wangpi26 commented May 8, 2026

Problem

In the generated graph.html, the <nav id="legend"> section uses inline <svg> elements (16×16 icons) for node type legends. The main canvas <svg id="graph-svg"> appears later in the DOM. The JavaScript code uses d3.select("svg") which selects the first <svg> element in the DOM — the small legend icon — causing the entire graph to be rendered inside that tiny icon.

Fix

Replace d3.select("svg") with d3.select("#graph-svg") at both occurrences in code_review_graph/visualization.py:

  • Line 859
  • Line 1759

The main canvas SVG already has id="graph-svg" defined, so this is a minimal, safe change.

Testing

  1. Run code-review-graph visualize to generate graph.html
  2. Open graph.html in a browser
  3. Graph now renders correctly in the main canvas area

Closes #450

The legend section uses inline <svg> elements for node type icons which
appear before the main <svg id="graph-svg"> in the DOM. d3.select("svg")
matched the first inline SVG (16x16 icon) instead of the main canvas,
causing the graph to render inside the tiny legend icon.

Replace d3.select("svg") with d3.select("#graph-svg") at both
occurrences (lines 859 and 1759) to target the correct element.

Closes tirth8205#450
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.

Bug: d3.select("svg") selects legend inline SVG instead of main canvas (#graph-svg)

1 participant