colored obsidian graph

Signpost11 Signposts
Sapling5 Saplings
Chest5 Chests
Seedling4 Seedlings
Tree2 Trees
Withered1 Withered
Stone1 Stone
Success

The graph nodes are now colored by their location relative to the swamp.

Graph Node and Link Coloring by Folder Update

Overview

Updated the digital garden's graph visualization to color both nodes and links based on their folder location, providing better visual organization and navigation of content areas. Implemented a shared color configuration system for consistency across build-time and runtime processes.

Problem Solved

Previously, all nodes and links in the graph were colored with the same theme color, making it difficult to visually distinguish between different content areas (Maps, Swamp, Updates, and root-level notes). Additionally, there was no centralized color management system.

Changes Made

Before:

let group = "none";
if (parts.length >= 3) {
  group = parts[parts.length - 2];
}

After:

let group = "root";
if (parts.length >= 2) {
  group = parts[0]; // First folder is the group (Maps, Swamp, Updates, etc.)
}

Why: The original logic was looking for files nested 3+ levels deep, but our folder structure is only 2 levels deep (/notes/Maps/Career.md). This meant all nodes were getting group: "none" instead of their actual folder names.

2. Created Shared Color Configuration (src/helpers/folderColors.js)

Added a centralized color configuration file that both build-time and runtime processes can use:

const folderColors = {
    'Maps': '#8A784E',      // Brown
    'Swamp': '#4CAF50',     // Green  
    'Updates': '#9C27B0',   // Purple
    'root': '#648DB3',      // Blue for root-level notes
    'default': '#666666'    // Fallback gray color
};

function getFolderColor(folderName) {
    if (!folderName || folderName === '' || folderName === 'root') {
        return folderColors['root'];
    }
    return folderColors[folderName] || folderColors['default'];
}

module.exports = { folderColors, getFolderColor };

Added color information to node data during build time:

const { folderColors, getFolderColor } = require('./folderColors');

nodes[v.url] = {
    // ...existing properties...
    group,
    color: getFolderColor(group), // Add color based on folder
    // ...existing properties...
};

Modified both node and link rendering to use folder-based colors:

Node Coloring:

.nodeCanvasObject((node, ctx) => {
    // ...existing code...
    const nodeColor = node.color || getCssVar("--graph-main");
    
    // Apply folder color to node fill and stroke
    ctx.fillStyle = nodeColor;
    ctx.strokeStyle = nodeColor;
    // ...existing code...
})

Link Coloring:

.linkColor((link) => {
    const sourceNodeColor = link.source.color || getCssVar("--graph-main");
    
    if (hoverNode == null) {
        return sourceNodeColor;
    }
    if (link.source.id == hoverNode.id || link.target.id == hoverNode.id) {
        return sourceNodeColor;
    } else {
        return mutedColor;
    }
})

Color Scheme

Folder Color Hex Code Purpose
Maps Brown #8A784E MOCs (Maps of Content) and index pages
Swamp Green #4CAF50 Work-in-progress notes and raw thoughts
Updates Purple #9C27B0 Changelog and update entries
Root Blue #648DB3 Main pages (about, contact, home, etc.)

Benefits

  1. Visual Organization: Easy to identify content areas at a glance in both nodes and links
  2. Better Navigation: Users can quickly locate different types of content and their connections
  3. Semantic Meaning: Colors reflect the purpose of each content area
  4. Link Flow Visualization: Links are colored by their source folder, showing content flow between areas
  5. Centralized Color Management: Single source of truth for all colors
  6. Build-time Optimization: Colors are pre-calculated and included in graph data
  7. Maintains Functionality: All existing graph features (hover, zoom, click) work unchanged

Technical Notes

Files Modified

  1. src/helpers/folderColors.js - New: Centralized color configuration
  2. src/helpers/linkUtils.js - Fixed group detection logic and added color property to nodes
  3. src/site/_includes/components/graphScript.njk - Updated node and link rendering to use folder colors

Architecture

Build Time (Node.js)

Runtime (Browser)

Future Enhancements