Skip to content

feat: highlight traces and same-net traces on hover#164

Open
aifunmobi wants to merge 3 commits intotscircuit:mainfrom
aifunmobi:fix/trace-hover-highlight
Open

feat: highlight traces and same-net traces on hover#164
aifunmobi wants to merge 3 commits intotscircuit:mainfrom
aifunmobi:fix/trace-hover-highlight

Conversation

@aifunmobi
Copy link

Summary

  • Adds hover highlighting for schematic traces: when hovering over a trace, it and all traces on the same net change color (#60a5fa)
  • Precomputes net groups from circuit-json relationships (source_trace → connected_source_port_ids) for efficient pointermove handling
  • New useTraceHoverHighlight hook follows the same pattern as existing useChangeSchematicTracesForMovedComponents

Closes tscircuit/tscircuit#1130

/claim #1130

How it works

  1. On mount, builds lookup maps from circuitJson: schematic traces → source traces → connected ports
  2. Groups traces into nets using BFS over shared port connections
  3. On pointermove, detects which trace group the pointer is over via Element.closest("[data-schematic-trace-id]")
  4. Highlights all traces in that net by swapping their stroke color; restores originals on pointer leave

Test plan

  • Hover over a trace → it turns blue (#60a5fa)
  • Other traces on the same net also highlight
  • Moving pointer off the trace restores original colors
  • Moving between traces on the same net doesn't flicker
  • No interference with existing component drag dash animation

When hovering over a schematic trace, the trace and all other traces
connected to the same net change color to indicate interactivity.
Net groups are precomputed from circuit-json relationships for efficient
pointer event handling.

Closes tscircuit/tscircuit#1130
@vercel
Copy link

vercel bot commented Feb 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
schematic-viewer Ready Ready Preview, Comment Feb 8, 2026 1:36pm

Request Review

The previous approach using BFS over circuit-json source_trace relationships
missed connections. The SVG already encodes correct net grouping via
data-subcircuit-connectivity-map-key attributes set by circuit-to-svg.
This is simpler and handles all edge cases including traces without net keys.
@aifunmobi
Copy link
Author

Demo — Trace Hover Highlighting (example9)

Preview: https://schematic-viewer-git-fork-aifunmobi-fix-trace-0f983c-tscircuit.vercel.app/?fixtureId=%7B%22path%22%3A%22examples%2Fexample9-spice-rc-charging-voltage-divider.fixture.tsx%22%7D

How to test

  1. Open the preview link above
  2. Hover over any trace in the schematic
  3. The hovered trace and all same-net traces change color to blue (#60a5fa)
  4. Moving off the trace restores original colors

Same-net grouping verification

In example9, traces are grouped by net using the data-subcircuit-connectivity-map-key SVG attribute:

  • schematic_trace_0 (R1→junction) + schematic_trace_1 (junction→R2) share net2 → both highlight together
  • schematic_trace_2 is on net3 → highlights independently
  • schematic_trace_3 has no net key → highlights as a single trace

Verified via browser console:

// Hovering trace_0 → both net2 traces turn blue
trace_0: stroke="#60a5fa"  // ✅ highlighted
trace_1: stroke="#60a5fa"  // ✅ same-net highlighted
trace_2: stroke="rgb(0, 150, 0)"  // unchanged (different net)
trace_3: stroke="rgb(0, 150, 0)"  // unchanged (no net)

This is the exact issue that caused PRs #142, #149, and #157 to be rejected — incomplete net grouping where only the directly hovered trace highlighted but not all same-net traces.

@aifunmobi
Copy link
Author

Demo Video

trace-hover-highlight-demo

Example 9 (RC charging voltage divider): Hovering over a trace highlights it and all same-net traces in blue (#60a5fa). Moving off restores original colors. Traces on different nets are unaffected.

Preview: https://schematic-viewer-git-fork-aifunmobi-fix-trace-0f983c-tscircuit.vercel.app/?fixtureId=%7B%22path%22%3A%22examples%2Fexample9-spice-rc-charging-voltage-divider.fixture.tsx%22%7D

Copy link
Contributor

@rushabhcodes rushabhcodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the repro give https://tscircuit.com/MrPicklePinosaur/tscircuit_demo#schematic to demonstrate your fix

Loads MrPicklePinosaur/tscircuit_demo circuit from tscircuit registry
to demonstrate trace hover highlighting on a complex real-world schematic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aifunmobi
Copy link
Author

Demo on MrPicklePinosaur/tscircuit_demo

Added a new fixture (example19-tscircuit-demo) that loads the full MrPicklePinosaur/tscircuit_demo circuit (FT232H USB board — 49 schematic traces, 37 components) directly from the tscircuit registry.

Preview: https://schematic-viewer-git-fork-aifunmobi-fix-trace-0f983c-tscircuit.vercel.app/?fixtureId=%7B%22path%22%3A%22examples%2Fexample19-tscircuit-demo.fixture.tsx%22%7D

How to test

  1. Open the preview link above (circuit loads from tscircuit registry API)
  2. Hover over any trace in the schematic
  3. The hovered trace and all same-net traces highlight in blue (#60a5fa)
  4. Moving off restores original colors

This is the exact repro from https://tscircuit.com/MrPicklePinosaur/tscircuit_demo#schematic rendered with our PR's hover highlight hook.

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.

Change of color on hover for traces are missing

2 participants