Obsidian 3D Graph
repository·master·Indexed 18 days ago
https://github.com/alexw00/obsidian-3d-graphA community plugin for Obsidian (version 1.0.5) that provides a three-dimensional visualization of a user's vault graph. Built with TypeScript and powered by D3.js, it allows users to render global and local graphs, configure visual parameters via DisplaySettings, manage visibility filters, and categorize nodes using GroupSettings with tag or path-based queries.
What's inside Obsidian 3D Graph
- Obsidian 3D Graph provides a 3D visualization of your Obsidian vault's graph. The plugin is built using TypeScript and utilizes D3.js for the rendering engine.
Understand the project structure
masterThe project is organized into several functional directories within
src/:src/graph/: Contains the core graph data structures and algorithms.src/settings/: Manages settings data structures.src/utils/: Contains shared utility functions.src/views/: Contains the UI layer, further subdivided into:atomics/: Small, atomic UI components.graph/: Components specifically for rendering the graph.settings/: Components for the settings interface.
src/main.ts: The main entry point for the Obsidian plugin.
Install the Obsidian 3D Graph plugin
master3D-Graph is an official community plugin for Obsidian. You can install it using one of two methods:
- Obsidian Plugin Browser: Open Obsidian, go to the Community Plugins tab, and search for "3D Graph".
- Direct Download: Download it directly from the Obsidian Plugin Marketplace.
How NodeGroup queries match nodes
masterThe
NodeGroup.matches(query, node)method determines if a specific node belongs to a group based on the providedquerystring. The matching logic follows two patterns:- Tag Matching: If the query starts with
tag:ortag:#, the system checks if the node's tags include the string following that prefix. For example,tag:#projectmatches a node with the tag#project. - Path Matching: If the query does not match the tag pattern, it is treated as a path prefix. The query is passed through
sanitizeQuery(which removes leading./if present) and checked against the node's file path usingstartsWith.
Query Sanitization Rules:
- Leading
./is stripped from the query before path matching occurs.
// Example of tag matching logic NodeGroup.matches("tag:#important", node); // Example of path matching logic NodeGroup.matches("./notes/daily", node); // matches nodes in 'notes/daily'"- Tag Matching: If the query starts with
Access the underlying ForceGraph3DInstance
masterIf you need to interact directly with the underlying
3d-force-graphengine (to access low-level D3-force properties or specific3d-force-graphmethods), you can retrieve the raw instance usinggetInstance().const rawInstance = forceGraph.getInstance(); // rawInstance is of type ForceGraph3DInstanceConfigure FilterSettings for the 3D Graph
masterThe
FilterSettingsclass manages visibility filters for the 3D graph. It controls whether orphan nodes (nodes without connections) and attachment files are rendered in the visualization.Properties:
doShowOrphans(boolean): Determines if nodes with no incoming or outgoing links are displayed. Defaults totrue.doShowAttachments(boolean): Determines if attachment files are displayed in the graph. Defaults tofalse.
You can instantiate this class directly via the constructor or reconstruct it from a stored configuration object using
fromStore().// Direct instantiation const settings = new FilterSettings(true, true); // Reconstructing from a stored object (e.g., from Obsidian settings storage) const storedData = { doShowOrphans: false, doShowAttachments: true }; const settingsFromStore = FilterSettings.fromStore(storedData); // Exporting settings back to a plain object for storage const configObject = settings.toObject();Serialize GroupSettings to a plain object
masterTo save or export the current grouping configuration, use the
toObject()method on aGroupSettingsinstance. This returns a plain JavaScript object containing thegroupsarray.const plainObject = settings.toObject(); // Result: { groups: [ { query: '...', color: '...' }, ... ] }Get current plugin settings
masterUse the
getSettings()method on theGraph3dPlugininstance to retrieve the currentGraphSettingsobject. This object represents the user's configured preferences for the 3D graph.const settings = plugin.getSettings();Configure node groups with GroupSettings and NodeGroup
masterThe
GroupSettingsclass manages a collection ofNodeGroupobjects used to categorize and color nodes in the 3D graph. EachNodeGroupis defined by aquery(used to match nodes) and acolor(the color applied to matched nodes).To create settings manually, instantiate
GroupSettingswith an array ofNodeGroupinstances.const settings = new GroupSettings([ new NodeGroup("tag:#work", "#ff0000"), new NodeGroup("./folder/subfolder", "#00ff00") ]);Reconstruct GroupSettings from a store object
masterIf you have a serialized settings object (e.g., from a storage provider), you can reconstruct a
GroupSettingsinstance using the staticfromStore(store)method. This method expects the store to have agroupsproperty containing objects withqueryandcolorkeys.const settings = GroupSettings.fromStore(storedData);Manage ForceGraph dimensions
masterThe
ForceGraphclass provides methods to manually adjust the size of the 3D rendering area. This is useful when the container element changes size (e.g., window resizing or layout shifts).updateDimensions(): Automatically calculates the new width and height based on therootHtmlElement'soffsetWidthandoffsetHeightand applies them to the graph instance.setDimensions(width, height): Directly sets the graph instance width and height to the provided numeric values.
// Example of updating dimensions forceGraph.updateDimensions(); // Example of setting specific dimensions forceGraph.setDimensions(800, 600);Configure visual parameters with DisplaySettings
masterThe
DisplaySettingsclass manages the visual properties of the 3D graph. You can instantiate it with specific values for node size, link thickness, particle size, and particle count. It also provides utility methods for hydrating settings from a data store or exporting them as a plain object.// Manual instantiation const settings = new DisplaySettings(10, 2, 5, 10); // Hydrating from a store object const store = { nodeSize: 8, linkThickness: 3 }; const settingsFromStore = DisplaySettings.fromStore(store); // Exporting to a plain object for serialization const configObject = settings.toObject();