fix(explorer): make distance intelligence visible#513
Open
ZohaibHassan16 wants to merge 3 commits intomainfrom
Open
fix(explorer): make distance intelligence visible#513ZohaibHassan16 wants to merge 3 commits intomainfrom
ZohaibHassan16 wants to merge 3 commits intomainfrom
Conversation
- Fix dead `if (anchorNodeId)` conditional in buildHeatmapRenderSnapshot (anchor is always truthy past the early-return guard on line 263) - Replace O(n) array .includes() with WeakMap-cached Set.has() in resolveDistanceNodeStyle heatmap path β prevents per-node O(n) scan during every Sigma reducer pass on large graphs - Rename GraphDistanceBucketCounts.threeHop β threeHopPlus across types.ts, graphSceneState.ts, and GraphWorkspace.tsx so the field name reflects that it accumulates distance β₯ 3, not exactly 3; update status-strip labels to "3+ hop" accordingly - Restore hasMetrics guard in PathDistanceIntelPanel to suppress the empty metric grid <div> when a path result carries no optional metrics Co-Authored-By: ZohaibHassan16 <zohaib@hawksight.ai> Co-Authored-By: KaifAhmad1 <mohammadk78600@gmail.com>
Co-Authored-By: ZohaibHassan16 <zohaib@hawksight.ai> Co-Authored-By: KaifAhmad1 <mohammadk78600@gmail.com>
KaifAhmad1
approved these changes
Apr 29, 2026
Contributor
KaifAhmad1
left a comment
There was a problem hiding this comment.
PR Review β #513: fix(explorer): make distance intelligence visible
- Author: @ZohaibHassan16
- Reviewer: @KaifAhmad1
Summary
This PR refactors Distance Intelligence in the Explorer UI from imperative graph-attribute mutation into a typed visual state that flows through the standard Sigma reducer/theme pipeline. All four distance modes (Ego, Heatmap, Structural, Semantic) now render as first-class visual states rather than side-effects.
What Was Reviewed
Architecture
- Shift from raw
graph.setNodeAttribute()mutation to a typedGraphDistanceVisualStatepassed throughbuildReducerSceneStateβ Sigma reducers is the right design. - The renderer can now be fully described from props with no hidden side-effects on graph attributes.
New Types β types.ts
GraphDistanceVisualMode,GraphDistanceVisualStatus,GraphDistanceBucketCounts,GraphHeatmapRenderSnapshot, andGraphDistanceVisualStateare well-scoped.- Integrate cleanly with the existing diagnostics snapshot interfaces.
Core Logic β graphSceneState.ts
buildStructuralDistanceSnapshotβ bounded BFS, correct early-return guard,maxHopscap prevents runaway on dense graphs.buildHeatmapRenderSnapshotβ ring caps (120 / 650 / 900), deterministic sampling viahashStringtiebreaker (no render flicker), saturation detection with dual-condition heuristic.resolveDistanceNodeStyle/resolveDistanceEdgeStyleβ clean per-mode dispatch, correct fallback to{}when mode is"off"or status is not"ready".
GraphCanvas β GraphCanvas.tsx
distanceVisualStateChangedref tracking correctly invalidates the full reducer pass on state change.- Dependency arrays are accurate.
Inspector Panel β GraphInspectorPanel.tsx
- Band chip, metric cards, and interpretation section are all conditionally rendered β no layout noise when fields are absent.
Test Coverage
- 281 lines added to
graphSceneState.display.test.tscovering BFS snapshots, ring capping, deterministic sampling, node style resolution, and edge suppression. - Adequate for the surface area changed.
Blockers Fixed β Follow-up Commit by @KaifAhmad1
- Dead conditional (
graphSceneState.ts:305) βif (anchorNodeId)is always true past the early-return guard at line 263. Removed the wrapper; statements made unconditional. - O(n) hot-path lookup (
graphSceneState.ts:424) β.includes()was called per-node per Sigma render frame, up to ~8M comparisons/frame on large graphs. Added aWeakMap-backedgetHeatmapVisibleSet()helper; replaced with O(1)Set.has(). - Bucket semantic mismatch (
types.ts+ all callsites) βGraphDistanceBucketCounts.threeHopaccumulated distance β₯ 3, not exactly 3. Renamed tothreeHopPlusacrosstypes.ts,graphSceneState.ts, andGraphWorkspace.tsx; status strip now reads"3+ hop". - Empty metric grid (
GraphInspectorPanel.tsx:91) β empty<div>rendered when all optional path metric fields are null, causing orphaned whitespace. RestoredhasMetricsguard wrapping the grid.
Minor Notes (Non-blocking)
getDistanceBandColor:distance <= 3anddistance <= 6both return"#B0883A"β the two branches can be collapsed intodistance <= 6. Low risk, cosmetic.void edgeIdinbuildPreviousRingEdgeScores: use_edgeIdparameter name instead β idiomatic TS convention.SemanticNeighborhoodResponsetype is declared inline inGraphWorkspace.tsxβ belongs intypes.tsfor discoverability.- Heatmap hard-caps at 3 hops regardless of
maxHops(line 272). Intentional for perf but undocumented; worth a comment.
Verdict
Approved. Core architecture is solid. All four blocking issues have been resolved in the follow-up commit. Minor notes above are recommended for a future cleanup pass but do not block merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes Distance Intelligence in the Explorer UI so distance modes render through the normal Sigma reducer/theme pipeline instead of mutating raw graph attributes.
Distance Intelligence now behaves as a first-class visual state in Full Graph:
What Changed
Testing
npx tsc -bnpm run test:graph-workspace