Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix(explorer): address PR #513 review blockers

KaifAhmad17b581d596031
diff --git a/explorer/src/workspaces/GraphWorkspace/GraphInspectorPanel.tsx b/explorer/src/workspaces/GraphWorkspace/GraphInspectorPanel.tsx
index 5a68bb71..d2720756 100644
--- a/explorer/src/workspaces/GraphWorkspace/GraphInspectorPanel.tsx
+++ b/explorer/src/workspaces/GraphWorkspace/GraphInspectorPanel.tsx
@@ -64,6 +64,11 @@ const BAND_COLORS: Record<string, string> = {
function PathDistanceIntelPanel({ result }: { result: PathResponse }) {
const bandColor = BAND_COLORS[result.distance_band] ?? "#8b949e";
+ const hasMetrics =
+ result.confidence_decay != null ||
+ result.semantic_similarity != null ||
+ result.path_coherence_score != null ||
+ result.bottleneck_node != null;
return (
<div style={{ display: "flex", flexDirection: "column", gap: 8, marginTop: 8 }}>
@@ -88,7 +93,7 @@ function PathDistanceIntelPanel({ result }: { result: PathResponse }) {
</div>
{/* metric grid */}
- <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 8 }}>
+ {hasMetrics && <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 8 }}>
{result.confidence_decay != null && (
<div style={metricCardStyle}>
<div style={metricLabelStyle}>Confidence Decay</div>
@@ -149,7 +154,7 @@ function PathDistanceIntelPanel({ result }: { result: PathResponse }) {
</div>
</div>
)}
- </div>
+ </div>}
{/* interpretation */}
{result.interpretation && (
diff --git a/explorer/src/workspaces/GraphWorkspace/GraphWorkspace.tsx b/explorer/src/workspaces/GraphWorkspace/GraphWorkspace.tsx
index 4cd12cdf..1532eb94 100644
--- a/explorer/src/workspaces/GraphWorkspace/GraphWorkspace.tsx
+++ b/explorer/src/workspaces/GraphWorkspace/GraphWorkspace.tsx
@@ -2589,7 +2589,7 @@ export function GraphWorkspace() {
`${visibleDistanceCounts.anchor.toLocaleString()} anchor`,
`${formatRenderedCount(visibleDistanceCounts.oneHop, renderedHeatmapCounts?.oneHop)} 1-hop`,
`${formatRenderedCount(visibleDistanceCounts.twoHop, renderedHeatmapCounts?.twoHop)} 2-hop`,
- `${formatRenderedCount(visibleDistanceCounts.threeHop, renderedHeatmapCounts?.threeHop)} 3-hop`,
+ `${formatRenderedCount(visibleDistanceCounts.threeHopPlus, renderedHeatmapCounts?.threeHopPlus)} 3+ hop`,
`${visibleDistanceCounts.outside.toLocaleString()} outside`,
distanceVisualState.heatmapSaturationMode === "sampled" ? "Sampled for readability" : "",
].filter(Boolean).join(" · ")
@@ -2599,7 +2599,7 @@ export function GraphWorkspace() {
`${renderedHeatmapCounts.anchor.toLocaleString()} anchor shown`,
`${renderedHeatmapCounts.oneHop.toLocaleString()} 1-hop shown`,
`${renderedHeatmapCounts.twoHop.toLocaleString()} 2-hop shown`,
- `${renderedHeatmapCounts.threeHop.toLocaleString()} 3-hop shown`,
+ `${renderedHeatmapCounts.threeHopPlus.toLocaleString()} 3+ hop shown`,
].join(" · ")
: null;
const distanceLegendItems = distanceVisualState.mode === "heatmap"
diff --git a/explorer/src/workspaces/GraphWorkspace/graphSceneState.ts b/explorer/src/workspaces/GraphWorkspace/graphSceneState.ts
index 48f81660..a6ae7b7c 100644
--- a/explorer/src/workspaces/GraphWorkspace/graphSceneState.ts
+++ b/explorer/src/workspaces/GraphWorkspace/graphSceneState.ts
@@ -46,6 +46,16 @@ const HEATMAP_ONE_HOP_CAP = 120;
const HEATMAP_TWO_HOP_CAP = 650;
const HEATMAP_THREE_HOP_CAP = 900;
+const _heatmapVisibleSetCache = new WeakMap<GraphDistanceVisualState, Set<string>>();
+function getHeatmapVisibleSet(state: GraphDistanceVisualState): Set<string> {
+ let cached = _heatmapVisibleSetCache.get(state);
+ if (!cached) {
+ cached = new Set(state.heatmapVisibleNodeIds ?? []);
+ _heatmapVisibleSetCache.set(state, cached);
+ }
+ return cached;
+}
+
type GraphRef = typeof graph | Graph<NodeAttributes, EdgeAttributes>;
export type GraphDisplayResult = {
@@ -174,7 +184,7 @@ export function summarizeDistanceBuckets(
anchor: 0,
oneHop: 0,
twoHop: 0,
- threeHop: 0,
+ threeHopPlus: 0,
outside: 0,
};
@@ -186,11 +196,11 @@ export function summarizeDistanceBuckets(
} else if (distance === 2) {
counts.twoHop += 1;
} else {
- counts.threeHop += 1;
+ counts.threeHopPlus += 1;
}
});
- const reachedCount = counts.anchor + counts.oneHop + counts.twoHop + counts.threeHop;
+ const reachedCount = counts.anchor + counts.oneHop + counts.twoHop + counts.threeHopPlus;
counts.outside = Math.max(0, totalNodeCount - reachedCount);
return counts;
}
@@ -200,7 +210,7 @@ function createEmptyDistanceCounts(): GraphDistanceBucketCounts {
anchor: 0,
oneHop: 0,
twoHop: 0,
- threeHop: 0,
+ threeHopPlus: 0,
outside: 0,
};
}
@@ -296,17 +306,15 @@ export function buildHeatmapRenderSnapshot(
if (ring === 0) renderedRingCounts.anchor = candidates.length;
if (ring === 1) renderedRingCounts.oneHop = candidates.length;
if (ring === 2) renderedRingCounts.twoHop = candidates.length;
- if (ring === 3) renderedRingCounts.threeHop = candidates.length;
+ if (ring === 3) renderedRingCounts.threeHopPlus = candidates.length;
});
- if (anchorNodeId) {
- visibleNodeIds.add(anchorNodeId);
- renderedRingCounts.anchor = Math.max(1, renderedRingCounts.anchor);
- }
+ visibleNodeIds.add(anchorNodeId);
+ renderedRingCounts.anchor = Math.max(1, renderedRingCounts.anchor);
const isSampled = renderedRingCounts.oneHop < ringCounts.oneHop
|| renderedRingCounts.twoHop < ringCounts.twoHop
- || renderedRingCounts.threeHop < ringCounts.threeHop;
+ || renderedRingCounts.threeHopPlus < ringCounts.threeHopPlus;
return {
visibleNodeIds: [...visibleNodeIds],
@@ -321,13 +329,13 @@ function isHeatmapSaturated(counts: GraphDistanceBucketCounts | undefined): bool
return false;
}
- const total = counts.anchor + counts.oneHop + counts.twoHop + counts.threeHop + counts.outside;
+ const total = counts.anchor + counts.oneHop + counts.twoHop + counts.threeHopPlus + counts.outside;
if (total <= 0) {
return false;
}
- const broadRings = counts.twoHop + counts.threeHop;
- return counts.threeHop > 1_500 || broadRings / total > 0.35;
+ const broadRings = counts.twoHop + counts.threeHopPlus;
+ return counts.threeHopPlus > 1_500 || broadRings / total > 0.35;
}
function resolveHeatmapRingStyle(distance: number, isSaturated: boolean) {
@@ -417,8 +425,8 @@ export function resolveDistanceNodeStyle(
}
if (distanceVisualState.mode === "heatmap") {
- const visibleNodeIds = distanceVisualState.heatmapVisibleNodeIds;
- const isRenderedHeatmapNode = isAnchor || !visibleNodeIds || visibleNodeIds.includes(nodeId);
+ const visibleSet = getHeatmapVisibleSet(distanceVisualState);
+ const isRenderedHeatmapNode = isAnchor || visibleSet.size === 0 || visibleSet.has(nodeId);
if (distance == null || !isRenderedHeatmapNode) {
return {
diff --git a/explorer/src/workspaces/GraphWorkspace/types.ts b/explorer/src/workspaces/GraphWorkspace/types.ts
index a2408f80..01164899 100644
--- a/explorer/src/workspaces/GraphWorkspace/types.ts
+++ b/explorer/src/workspaces/GraphWorkspace/types.ts
@@ -21,7 +21,7 @@ export interface GraphDistanceBucketCounts {
anchor: number;
oneHop: number;
twoHop: number;
- threeHop: number;
+ threeHopPlus: number;
outside: number;
}