Skip to content

Conversation

@JrmyDev
Copy link

@JrmyDev JrmyDev commented Sep 3, 2025

This PR implements the trace hover highlighting feature that allows users to visualize electrical connectivity in schematic diagrams. When hovering over any trace, all electrically connected traces in the same net are highlighted, making it easier to understand circuit topology and debug routing issues.

✨ Features Implemented

Core Functionality
✅ Hover Detection: Automatically detects when user hovers over schematic traces
✅ Connectivity Analysis: Uses circuit JSON metadata to find electrically connected traces
✅ Visual Highlighting: Applies CSS-based highlighting with filter: invert(1) to match existing hover behavior
✅ Performance Optimized: CSS-only approach with no SVG manipulation
✅ Clean Integration: Minimal changes to existing codebase

Technical Highlights
✅ MutationObserver: Reliable detection of SVG loading for proper timing
✅ Electrical Accuracy: Uses subcircuit_connectivity_map_key for precise connectivity detection
✅ Graceful Fallbacks: Handles edge cases and ID mismatches robustly
✅ Memory Management: Proper cleanup of event listeners and timeouts

New Files Created:

  • useSubTraceHover.ts Main React hook for trace hover functionality
  • trace-connectivity.ts Electrical connectivity detection logic
  • trace-highlighting-styles.ts CSS injection for highlighting styles
  • example13-trace-hover-highlighting-demo.fixture.tsx Demo circuit showcasing the feature

Files Modified
Minimal Changes Made:
SchematicViewer.tsx Added 2 lines:

  • Import: import { useSubTraceHover } from "lib/hooks/useSubTraceHover"
  • Hook call: [useSubTraceHover({ svgDivRef, circuitJson, enabled: true })]

🏗️ Architecture
Clean Separation of Concerns:

Key Design Decisions:

  • CSS-only highlighting - No SVG DOM manipulation for performance
  • Circuit JSON metadata - Uses existing connectivity data from circuit-to-svg
  • Event delegation - Efficient event handling with MutationObserver
  • Minimal footprint - Only 2 lines added to main component

/claim #117

Enregistrement.de.l.ecran.2025-09-03.a.14.58.13.mov

@vercel
Copy link

vercel bot commented Sep 3, 2025

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

Project Deployment Preview Comments Updated (UTC)
schematic-viewer Ready Ready Preview Comment Sep 3, 2025 8:14pm

/**
* Optimized trace highlighting using CSS classes and circuit-to-svg metadata
*/
export const useSubTraceHover = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const useSubTraceHover = ({
export const useConnectedTracesHoverHighlighting = ({

Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

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

Good, only minor comments

@JrmyDev
Copy link
Author

JrmyDev commented Sep 3, 2025

Good, only minor comments

Thanks ! Modifications done

@seveibar
Copy link
Contributor

seveibar commented Sep 3, 2025

@JrmyDev seems now there's a formatting issue (should be caught in CI, but that's a different issue)

@JrmyDev
Copy link
Author

JrmyDev commented Sep 3, 2025

Hmm seems my vscode auto applied on save... will rollback and apply modification only

@ShiboSoftwareDev
Copy link
Contributor

@seveibar this implementation doesn't work, I'm diving into the connectivity issue which has to be fixed first

@JrmyDev JrmyDev force-pushed the feature/117-highlight-connected-traces branch from dbf2264 to 70b8eb8 Compare September 3, 2025 20:05
@seveibar
Copy link
Contributor

seveibar commented Sep 3, 2025

@ShiboSoftwareDev it seems he's just using subcircuit_connectivity_key to determine if traces are connected. AFAIK that is a stable approach, even as we fix other bugs. It could even help fix other bugs

image

@ShiboSoftwareDev
Copy link
Contributor

@seveibar check the deployment

@seveibar
Copy link
Contributor

seveibar commented Sep 3, 2025

Kapture.2025-09-03.at.13.08.29.mp4

ahh yea you're right, this doesn't work, must be a flaw in the logic

Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

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

some kind of flaw in the logic, see video in comment

@JrmyDev
Copy link
Author

JrmyDev commented Sep 3, 2025

ahh yea you're right, this doesn't work, must be a flaw in the logic

correct, might be an hovering issue... will dive

Copy link
Member

@techmannih techmannih left a comment

Choose a reason for hiding this comment

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

its completed in circuit-to-svg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants