feat: add configurable hover settings for wiki graph

- Fix hover exit behavior to restore original node size (not minimum)
- Add configurable hover settings in fiona-settings.json:
  - hover.color: node highlight color (default: #add8e6)
  - hover.edge_color: edge highlight color (default: #0000ff)
  - hover.size_multiplier: hover size multiplier (default: 1.3)
- Cap hover size at max_radius to prevent nodes from growing too large
- Update SPEC.md with new configuration options and acceptance criteria
- Update llm-wiki fiona-settings.json with hover configuration

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
nvaldez
2026-09-28 20:32:59 +02:00
parent 4697c5323f
commit f1a12ae1f6
4 changed files with 143 additions and 71 deletions
+21 -6
View File
@@ -449,10 +449,11 @@ relationships and navigate their wiki structure.
- *3.1.4.3.9.* Clicking on another node switches the highlight to that node.
- *3.1.4.3.10.* Clicking on empty space or any non-node area removes the highlight.
- *3.1.4.3.11.* Double click on node opens the markdown file in default editor or browser.
- *3.1.4.3.12.* Color coding: nodes use a spectrum from green (no links/gray) to yellow to
red (high connectivity) based on in-degree.
- *3.1.4.3.12.* Color coding: nodes use a spectrum from gray (no links) to orange to
red (high connectivity) based on in-degree, relative to the maximum in-degree in the graph.
- *3.1.4.3.13.* Node sizing: circle radius scales proportionally to the node's in-degree
(number of incoming links). Higher in-degree = larger circle.
(number of incoming links) relative to the maximum in-degree in the graph, with
minimum radius 5 and maximum radius 25.
- *3.1.4.3.14.* Edge coloring: use a spectrum from gray (single link) to yellow to red
(many links) based on link count, rather than increasing line thickness.
- *3.1.4.3.15.* Gravity force: mass-based physics system with continuous fluid movement.
@@ -557,9 +558,18 @@ relationships and navigate their wiki structure.
"default_layout": "force-directed",
"max_files": 5000,
"node_colors": {
"high_connectivity": "#ff0000",
"medium_connectivity": "#ffff00",
"low_connectivity": "#00ff00"
"low": "#808080",
"mid": "#ffa500",
"high": "#ff0000"
},
"node_radius": {
"min": 5,
"max": 25
},
"hover": {
"color": "#add8e6",
"edge_color": "#0000ff",
"size_multiplier": 1.3
}
}
}
@@ -568,6 +578,11 @@ relationships and navigate their wiki structure.
```
- *acceptance*: Settings override defaults when present.
- *acceptance*: `node_colors` configures the color spectrum (low, mid, high).
- *acceptance*: `node_radius` configures the radius range (min, max).
- *acceptance*: `hover` configures hover behavior (color, edge_color, size_multiplier).
- *acceptance*: Hover size is capped at max_radius to prevent nodes from growing too large.
- *acceptance*: On hover exit, nodes restore to their original size (not minimum size).
- *3.1.4.10.* Module Structure
- *3.1.4.10.1.* **MarkdownLinkParser**: Parses markdown files to extract internal
links. Handles standard markdown links and optional wikilinks. Resolves
+18
View File
@@ -55,6 +55,24 @@
"file_log_location": "fiona.log",
"llm-wiki": {
"ignore_files": []
},
"wiki": {
"graph": {
"node_colors": {
"low": "#808080",
"mid": "#ffa500",
"high": "#FF0000"
},
"node_radius": {
"min": 5,
"max": 40
},
"hover": {
"color": "#add8e6",
"edge_color": "#0000ff",
"size_multiplier": 1.3
}
}
}
}
}
+29 -2
View File
@@ -488,13 +488,15 @@ class HTMLGraphRenderer:
D3JS_CDN = "https://d3js.org/d3.v7.min.js"
def __init__(self, graph: WikiGraph):
def __init__(self, graph: WikiGraph, settings: dict | None = None):
"""Initialize the HTMLGraphRenderer.
Args:
graph: The WikiGraph instance to render.
settings: Optional dictionary with graph settings (e.g., color spectrum).
"""
self.graph = graph
self.settings = settings or {}
def _generate_node_data(self) -> list[dict]:
"""Generate node data for JSON output.
@@ -569,6 +571,23 @@ class HTMLGraphRenderer:
# Determine connectivity levels for color coding
max_in_degree = max((node["in_degree"] for node in node_data), default=0)
# Get color spectrum settings with defaults
color_settings = self.settings.get("node_colors", {})
color_low = color_settings.get("low", "#808080") # gray
color_mid = color_settings.get("mid", "#ffa500") # orange
color_high = color_settings.get("high", "#ff0000") # red
# Get radius settings with defaults
radius_settings = self.settings.get("node_radius", {})
min_radius = radius_settings.get("min", 5)
max_radius = radius_settings.get("max", 25)
# Get hover settings with defaults
hover_settings = self.settings.get("hover", {})
hover_color = hover_settings.get("color", "#add8e6") # light blue
hover_edge_color = hover_settings.get("edge_color", "#0000ff") # blue
hover_size_multiplier = hover_settings.get("size_multiplier", 1.3)
# Load the template
template_path = os.path.join(os.path.dirname(__file__), 'templates', 'graph_template.html')
with open(template_path, 'r', encoding='utf-8') as f:
@@ -580,6 +599,14 @@ class HTMLGraphRenderer:
html = html.replace('{{max_in_degree}}', str(max_in_degree))
html = html.replace('{{node_data_json}}', json.dumps(node_data))
html = html.replace('{{edge_data_json}}', json.dumps(edge_data))
html = html.replace('{{color_low}}', color_low)
html = html.replace('{{color_mid}}', color_mid)
html = html.replace('{{color_high}}', color_high)
html = html.replace('{{min_radius}}', str(min_radius))
html = html.replace('{{max_radius}}', str(max_radius))
html = html.replace('{{hover_color}}', hover_color)
html = html.replace('{{hover_edge_color}}', hover_edge_color)
html = html.replace('{{hover_size_multiplier}}', str(hover_size_multiplier))
return html
@@ -713,7 +740,7 @@ def wiki_graph_main(
logger.info(f"Graph: {len(graph.nodes)} nodes, {len(graph.edges)} edges")
# Generate output
renderer = HTMLGraphRenderer(graph)
renderer = HTMLGraphRenderer(graph, graph_settings)
if format_type == "json":
output_content = renderer.generate_json(directory)
+75 -63
View File
@@ -70,15 +70,15 @@
background-color: #6c757d;
cursor: not-allowed;
}
.toggle-btn {
background-color: #6c757d;
}
.toggle-btn.active {
background-color: #007bff;
}
.node-info {
position: absolute;
background: white;
@@ -222,7 +222,7 @@
// Higher = more space between edges, fewer crossings
// Simulation damping: controls motion fluidity
const ALPHA_DECAY = 0.009; // Faster settling for responsive following
const ALPHA_DECAY = 0.005; // Faster settling for responsive following
const ALPHA_MIN = 0.0005; // Very low minimum for continuous correction
const VELOCITY_DECAY = 0.4; // Lower damping for responsive motion
@@ -272,16 +272,17 @@
return `rgb(${r}, ${g}, ${b})`;
}
// Get node color based on in_degree: gray (0) -> green -> yellow -> red (high)
// Get node color based on in_degree using configurable spectrum
function getNodeColor(d) {
if (d.in_degree === 0) return '#808080'; // gray for no links
const factor = d.in_degree / Math.max(maxInDegree, 1);
if (maxInDegree === 0) return '{{color_low}}'; // all low color if no references
const factor = d.in_degree / maxInDegree;
if (factor === 0) return '{{color_low}}'; // low color for no references
if (factor < 0.5) {
// green to yellow (0.5 is midpoint)
return interpolateColor('#00ff00', '#ffff00', factor * 2);
// low to mid color (0.5 is midpoint)
return interpolateColor('{{color_low}}', '{{color_mid}}', factor * 2);
} else {
// yellow to red
return interpolateColor('#ffff00', '#ff0000', (factor - 0.5) * 2);
// mid to high color
return interpolateColor('{{color_mid}}', '{{color_high}}', (factor - 0.5) * 2);
}
}
@@ -426,9 +427,10 @@
// Collision detection - radius accounts for node size AND edge count
.force('collide', d3.forceCollide()
.radius(d => {
const nodeRadius = Math.max(BASE_COLLIDE_RADIUS, d.in_degree * COLLIDE_PER_DEGREE);
const radiusRange = {{max_radius}} - {{min_radius}};
const visualRadius = maxInDegree === 0 ? {{min_radius}} : ({{min_radius}} + radiusRange * (d.in_degree / maxInDegree));
const edgePadding = (d.in_degree + d.out_degree) * EDGE_PADDING_MULTIPLIER;
return nodeRadius + edgePadding;
return visualRadius + edgePadding;
})
.strength(COLLIDE_STRENGTH)
.iterations(2))
@@ -474,7 +476,11 @@
.selectAll('circle')
.data(nodeData)
.enter().append('circle')
.attr('r', d => Math.max(5, d.in_degree * 3))
.attr('r', d => {
if (maxInDegree === 0) return {{min_radius}};
const radiusRange = {{max_radius}} - {{min_radius}};
return {{min_radius}} + radiusRange * (d.in_degree / maxInDegree);
})
.attr('fill', d => getNodeColor(d))
.attr('opacity', 0) // Start invisible
.attr('cx', width / 2) // Start at center
@@ -492,18 +498,21 @@
// Store current state of this node
const currentFill = d3.select(this).attr('fill');
const currentRadius = parseFloat(d3.select(this).attr('r'));
// Calculate hover radius, ensuring it doesn't exceed max
const hoverRadius = Math.min(currentRadius * {{hover_size_multiplier}}, {{max_radius}});
// Highlight the hovered node
d3.select(this)
.attr('fill', '#add8e6') // Light blue
.attr('r', currentRadius * 1.3); // Slightly larger
.attr('fill', '{{hover_color}}') // Hover color
.attr('r', hoverRadius); // Larger, but capped at max_radius
// Highlight all edges connected to this node
link
.attr('stroke', function(linkD) {
// Check if this edge is connected to the hovered node
if (linkD.source.id === d.id || linkD.target.id === d.id) {
return '#0000ff'; // Blue for connected edges
return '{{hover_edge_color}}'; // Highlight color for connected edges
}
return getEdgeColor(linkD.weight); // Original color for others
})
@@ -534,7 +543,7 @@
.attr('fill', function(d) {
if (searchActive && filteredNodeIds !== null && lastSearchDistances) {
const dist = lastSearchDistances[d.id];
if (dist === 0) return '#add8e6'; // Matching nodes in search
if (dist === 0) return '{{hover_color}}'; // Matching nodes in search
if (dist !== undefined) return '#808080'; // Neighbors in search
return originalColors.get(d.id);
}
@@ -543,7 +552,7 @@
.attr('r', function(d) {
if (searchActive && filteredNodeIds !== null && lastSearchDistances) {
const dist = lastSearchDistances[d.id];
if (dist === 0) return originalRadii.get(d.id) * 1.5; // Matching nodes in search
if (dist === 0) return Math.min(originalRadii.get(d.id) * 1.5, {{max_radius}}); // Matching nodes in search
return originalRadii.get(d.id);
}
return originalRadii.get(d.id);
@@ -559,7 +568,7 @@
const now = Date.now();
const isDoubleClick = (now - lastClickTime) < DOUBLE_CLICK_THRESHOLD;
lastClickTime = now;
if (isDoubleClick) {
// Double click - open the file
// Try to open in default editor
@@ -572,7 +581,7 @@
window.open('file://' + d.id, '_blank');
return;
}
// Single click - toggle highlight on this node
if (highlightedNode === d.id) {
// Clicking the same node again - remove highlight
@@ -786,12 +795,12 @@
let originalRadii = new Map();
let searchActive = false;
let lastSearchDistances = null;
// Node selection functionality
let highlightedNode = null;
let lastClickTime = 0;
const DOUBLE_CLICK_THRESHOLD = 300; // ms
// Create frontmatter card element
const frontmatterCard = d3.select('body').append('div')
.attr('class', 'frontmatter-card')
@@ -806,24 +815,25 @@
.style('z-index', '1001')
.style('box-shadow', '0 2px 4px rgba(0,0,0,0.2)')
.style('display', 'none');
// Helper function to highlight a node
function highlightNode(nodeId) {
// Remove any existing highlight
removeNodeHighlight();
// Set the highlighted node
highlightedNode = nodeId;
// Find the node element and highlight it
d3.selectAll('circle')
.filter(function(d) { return d.id === nodeId; })
.attr('fill', '#add8e6')
.attr('fill', '{{hover_color}}')
.attr('r', function(d) {
const originalRadius = originalRadii.get(d.id);
return originalRadius * 1.3;
// Ensure highlighted size doesn't exceed max
return Math.min(originalRadius * {{hover_size_multiplier}}, {{max_radius}});
});
// Load and display the frontmatter in upper left of SVG
const svgRect = document.getElementById('graph-container').getBoundingClientRect();
frontmatterCard
@@ -833,19 +843,19 @@
.style('left', (svgRect.left + 20) + 'px')
.style('top', (svgRect.top + 20) + 'px')
.style('display', 'block');
// Highlight connected edges
link
.attr('stroke', function(linkD) {
// Check if this edge is connected to the highlighted node
if (linkD.source.id === nodeId || linkD.target.id === nodeId) {
return '#0000ff'; // Blue for connected edges
return '{{hover_edge_color}}'; // Highlight color for connected edges
}
// Check if search is active and edge is gray
if (searchActive && filteredNodeIds !== null && lastSearchDistances) {
const sourceDist = lastSearchDistances[linkD.source.id];
const targetDist = lastSearchDistances[linkD.target.id];
if ((sourceDist !== undefined && sourceDist > 0) ||
if ((sourceDist !== undefined && sourceDist > 0) ||
(targetDist !== undefined && targetDist > 0)) {
return '#808080'; // Keep gray for search neighbors
}
@@ -853,18 +863,18 @@
return getEdgeColor(linkD.weight);
});
}
// Helper function to remove node highlight
function removeNodeHighlight() {
if (highlightedNode === null) return;
// Restore node appearance
d3.selectAll('circle')
.filter(function(d) { return d.id === highlightedNode; })
.attr('fill', function(d) {
if (searchActive && filteredNodeIds !== null && lastSearchDistances) {
const dist = lastSearchDistances[d.id];
if (dist === 0) return '#add8e6'; // Matching nodes in search
if (dist === 0) return '{{hover_color}}'; // Matching nodes in search
if (dist !== undefined) return '#808080'; // Neighbors in search
}
return originalColors.get(d.id);
@@ -872,32 +882,32 @@
.attr('r', function(d) {
if (searchActive && filteredNodeIds !== null && lastSearchDistances) {
const dist = lastSearchDistances[d.id];
if (dist === 0) return originalRadii.get(d.id) * 1.5; // Matching nodes in search
if (dist === 0) return Math.min(originalRadii.get(d.id) * 1.5, {{max_radius}}); // Matching nodes in search
}
return originalRadii.get(d.id);
});
// Restore edge colors
link
.attr('stroke', function(linkD) {
if (searchActive && filteredNodeIds !== null && lastSearchDistances) {
const sourceDist = lastSearchDistances[linkD.source.id];
const targetDist = lastSearchDistances[linkD.target.id];
if ((sourceDist !== undefined && sourceDist > 0) ||
if ((sourceDist !== undefined && sourceDist > 0) ||
(targetDist !== undefined && targetDist > 0)) {
return '#808080'; // Keep gray for search neighbors
}
}
return getEdgeColor(linkD.weight);
});
// Hide frontmatter card
frontmatterCard.style('display', 'none');
// Clear highlighted node
highlightedNode = null;
}
// Click on SVG background to remove highlight
svg.on('click', function(event) {
// Only remove highlight if we didn't click on a node
@@ -906,16 +916,18 @@
removeNodeHighlight();
}
});
// Store original colors and radii for all nodes
nodeData.forEach(n => {
originalColors.set(n.id, getNodeColor(n));
originalRadii.set(n.id, Math.max(5, n.in_degree * 3));
// Calculate the actual rendered radius for this node
const nodeRadius = maxInDegree === 0 ? {{min_radius}} : ({{min_radius}} + ({{max_radius}} - {{min_radius}}) * (n.in_degree / maxInDegree));
originalRadii.set(n.id, nodeRadius);
});
document.getElementById('search-input').addEventListener('input', function(e) {
const searchTerm = e.target.value.toLowerCase();
if (searchTerm === '') {
// Clear search - restore all
filteredNodeIds = null;
@@ -936,7 +948,7 @@
});
return;
}
// Find matching nodes
const matchingNodeIds = new Set();
nodeData.forEach(n => {
@@ -944,7 +956,7 @@
matchingNodeIds.add(n.id);
}
});
if (matchingNodeIds.size === 0) {
// No matches - hide all
filteredNodeIds = new Set();
@@ -953,10 +965,10 @@
link.style('opacity', 0);
return;
}
filteredNodeIds = matchingNodeIds;
searchActive = true;
// Build adjacency map for degree calculation
const adjacency = {};
edgeData.forEach(edge => {
@@ -965,26 +977,26 @@
adjacency[edge.source].add(edge.target);
adjacency[edge.target].add(edge.source);
});
// Calculate distances from matching nodes using BFS
lastSearchDistances = {};
const queue = [];
// Initialize: all matching nodes have distance 0
matchingNodeIds.forEach(nodeId => {
lastSearchDistances[nodeId] = 0;
queue.push(nodeId);
});
// BFS to calculate distances
let idx = 0;
while (idx < queue.length) {
const currentId = queue[idx++];
const currentDistance = lastSearchDistances[currentId];
// Stop at 3rd degree (distance 3)
if (currentDistance >= 3) continue;
// Visit neighbors
const neighbors = adjacency[currentId] || new Set();
neighbors.forEach(neighborId => {
@@ -994,7 +1006,7 @@
}
});
}
// Update node and link visibility based on distance
node
.style('opacity', function(d) {
@@ -1007,17 +1019,17 @@
if (!visibleNodes.has(d.id)) return originalColors.get(d.id);
const dist = lastSearchDistances[d.id];
if (dist === undefined) return '#ffffff'; // Not reachable - white (hidden)
if (dist === 0) return '#add8e6'; // Matching nodes - light blue highlight
if (dist === 0) return '{{hover_color}}'; // Matching nodes - highlight color
return '#808080'; // All neighbors - gray
})
.attr('r', function(d) {
if (!visibleNodes.has(d.id)) return originalRadii.get(d.id);
const dist = lastSearchDistances[d.id];
if (dist === undefined) return originalRadii.get(d.id);
if (dist === 0) return originalRadii.get(d.id) * 1.5; // Matching nodes - 1.5x bigger
if (dist === 0) return Math.min(originalRadii.get(d.id) * 1.5, {{max_radius}}); // Matching nodes - 1.5x bigger, capped at max
return originalRadii.get(d.id); // All neighbors - normal size
});
link.style('opacity', function(d) {
if (!visibleEdges.has(d.index)) return 0;
// Show edge if both ends are visible
@@ -1029,14 +1041,14 @@
return 0;
});
});
// Orphan nodes toggle
document.getElementById('orphan-toggle').addEventListener('click', function() {
const btn = d3.select(this);
showOrphans = !showOrphans;
btn.classed('active', showOrphans);
btn.text(showOrphans ? 'Hide Orphan Nodes' : 'Show Orphan Nodes');
// Get orphan nodes (nodes with no connections)
const orphanNodeIds = new Set();
nodeData.forEach(n => {
@@ -1044,7 +1056,7 @@
orphanNodeIds.add(n.id);
}
});
// Update visibility
node.style('opacity', function(d) {
if (!visibleNodes.has(d.id)) return 0;
@@ -1060,7 +1072,7 @@
}
return 1;
});
// Hide edges connected to hidden orphans
link.style('opacity', function(d) {
if (!visibleEdges.has(d.index)) return 0;