README file from
GithubBase Graph
Adds a Graph view to Obsidian Bases. The notes a base returns are drawn as a force-directed graph, like the core graph view.

- Filters: use the normal Bases toolbar to add, edit and remove filters. The graph updates as you change them.
- Depth: like the local graph, also show notes up to n links away from the base's results. Choose whether to follow links, backlinks or both.
- Groups: if the base is grouped, each group gets its own colour and appears in the legend. When grouped by a list property, each item in the list is its own group, and a note with several items is split equally between their colours. Colours stay the same as filters change, and you can choose a fixed colour for any value, even one that isn't in the results yet.
- Custom groups: colour the notes that match a property, such as
file.tagscontainingblocked, or a formula that's true, whatever group they're in. - Settings panel: change any view option, group colours and custom groups from a panel inside the graph.
- Link properties: draw only the links in chosen properties, such as
parentorblocks, to graph relationships like an org chart or task dependencies. Each property's links get their own colour. - Layouts: a free force-directed layout, rings by link distance from the base's results, or layers for hierarchies such as
parentlinks, running top to bottom, bottom to top, or sideways. - Clusters: optionally pull notes that share a property value together, separately from how they're coloured.
- Embeds: works anywhere a base does, including
![[Projects.base#Graph]]and inlinebasecode blocks.
Requires Obsidian 1.10.2 or later with the Bases core plugin turned on.
Usage
- Open a
.basefile. In the view switcher, select Add view, then choose Graph. - Set up filters from the toolbar as you would for a table.
- Drag the Depth slider in the top right to include linked notes. They take the colour of their group but are drawn faded, so you can tell them apart from notes the base matched.
Using the graph:
- Select a node to open it. Hold Ctrl/Cmd to open it in a new tab.
- Drag nodes to move them. Scroll to zoom, and drag the background to pan.
- Hover a node to see the properties chosen in the toolbar's Properties menu, rendered as they are in a table. Empty values are left out. Move onto the card to select its links.
- Select the pin on the card, or Pin highlight in the node's menu, to keep that note and its links highlighted. Select an empty part of the graph to unpin it.
- Hover with Ctrl/Cmd held for a page preview.
- Right-click a node for the file menu.
- Hover an item in the legend to highlight that group's notes or that link property's links. Select it to keep the highlight, and select it again to clear it. Hold Ctrl (Cmd on macOS) while selecting to highlight several items at once.
Settings panel
Select Settings (the sliders icon next to Zoom to fit) to open a panel on the right of the graph. It has the same options as the view's settings in the Bases toolbar, in collapsible sections, plus a Groups section for group colours and custom groups. Changes are saved in the .base file straight away, and changes made in the toolbar show up in the panel. Select the button again to close it.
Group colours
Each group's colour is picked from the theme's palette based on the group's name, so it doesn't change when filters or depth change the order groups appear in. Groups showing at the same time get different colours, up to the eight in the palette.
To fix a colour, open Groups in the settings panel and choose a colour next to the value. Values are listed with the number of nodes in each. Values marked Auto use the automatic colour. Select the reset button to go back to it.
A value with a saved colour stays listed when it's no longer in the results, marked Not in results, and uses its colour again when it comes back. Select the remove button to forget it. To choose a colour for a value before any notes have it, type the value under the list, choose a colour, then select Add. The value must match exactly, including case. For a link, include the brackets, like [[Project A]].

Colours are saved for the property the base is grouped by, so each group-by property keeps its own colours.
Custom groups
Custom groups colour the notes that match a property, overriding the colours of their groups. In the settings panel's Groups section, select New group, then choose:
- Name: shown in the legend. Leave it empty to show the property and value instead.
- Property: any property in the base, including formulas. Use a formula for more complex conditions, such as
formula.isBlocked. - Value: the note matches when the property, or any item in a list property, equals this value. Case and a leading
#are ignored, soblockedmatches the tag#blocked. Leave it empty to match any value that isn't empty or false. - Colour: the colour of matching notes.
Groups are checked from the top, and a note takes the colour of the first one it matches. Use the arrows to reorder them. Linked notes from Depth are matched too. Attachments and unresolved links never match. Groups that match notes in the graph appear in the legend after the base's groups, and highlight like them.
View options
These are under the view's settings in the Bases toolbar, and in the settings panel. They're saved in the .base file.
| Option | Description |
|---|---|
| Depth | How many links away from the base's results to include (0–5). |
| Follow | Follow links, backlinks, or both when expanding depth. |
| Layout | Free; Rings by depth to put the base's notes in the middle and linked notes in a ring for each step away; or Layered for one-way links such as parent. See Layered layout. |
| Direction | With Layered, which way the layers run: Top to bottom, Bottom to top, Left to right or Right to left. |
| Lay out clusters separately | With Layered and clusters, give each cluster its own layers instead of sharing them. See Layered layout. |
| Include attachments | Include linked attachments when expanding depth. |
| Link properties | Names of note properties to draw links from, such as parent or related. Depth follows only these links. Leave empty to use all links. |
| Include other links | With link properties set, also draw all other links, in the usual colour. |
| Show unresolved links | Show links to notes that don't exist. |
| Show orphans | Show results that aren't linked to anything in the graph. |
| Label property | Property to use as the node label. Defaults to the file name. |
| Size property | Numeric property that sets node size. Defaults to the number of links. |
| Cluster by group | Cluster notes by the base's groups instead of by a property. Notes in several groups, from a list, are in each of their groups' clusters. |
| Cluster by | Property whose values the notes are clustered by. Notes without a value aren't clustered. Each cluster gets a faint outline, background and label, in its group's colour if all its notes share one. |
| Display | Node size, link thickness and opacity, scale links by link count, text fade threshold, arrows, cluster outlines, height when embedded, and the node limit. |
| Forces | Center, repel and link forces, and link distance. Link distance also sets the gap between rings, and in Layered the gap between layers and the least space between notes in a layer. Cluster force sets how tightly clusters pull together, and cluster repel force how firmly notes are kept out of clusters they aren't in. |

Group colours and custom groups are saved in the view's config too, and can be edited by hand. Colours are hex, and group colours are saved by group-by property id, then by value:
views:
- type: base-graph
name: Tasks
groupColors:
note.status:
Done: "#08b94e"
Blocked: "#e93147"
customGroups:
- name: Blocked
property: file.tags
value: blocked
color: "#e93147"
- name: Overdue
property: formula.isOverdue
value: ""
color: "#e0ac00"
Layered layout
Layered suits links that only go one way, such as a parent property, task dependencies, or moons that orbit planets that orbit the Sun. Notes that don't link to anything are in the first layer, the notes linking to them are in the next layer, and so on. With Direction set to Top to bottom, the first layer is the top row. Linked notes are lined up with each other, and with clustering on, each cluster's notes stay together in every layer. When two notes link to each other through the same property, that link is ignored when placing them. When properties disagree, such as blocked_by and blocks between the same notes, the property listed first in Link properties decides, and other links come last.

Turn on Lay out clusters separately to lay out each cluster as its own small graph instead, from only the links inside it, with the clusters packed into rows to fit the view. Links between clusters are still drawn, but don't affect where notes go.

Embedding
Embed a view from a .base file:
![[Projects.base#Graph]]
Or define the base inline. Filters can refer to the note it's embedded in with this. For example, this shows the notes linking to the current note and everything linked to them:
```base
filters:
and:
- file.hasLink(this.file)
views:
- type: base-graph
name: Linked notes
depth: 1
height: 500
```
Development
npm install
npm run dev # watch build
npm run build # production build
npm run lint
To test, copy main.js, manifest.json and styles.css to <Vault>/.obsidian/plugins/base-graph/, reload Obsidian, and turn on Base Graph in Settings → Community plugins.
Layout
src/
main.ts Registers the Bases view and hover source
constants.ts
graph/
linkIndex.ts All links, plus a lazily built backlink index
propertyLinks.ts Only the links in chosen properties, from frontmatter links
buildGraph.ts Base results → nodes and links, with depth expansion
types.ts
view/
GraphBasesView.ts The BasesView: rebuilds on data and link changes, opens files
options.ts View options and reading them from the view config
clusters.ts Assigns clusters from the base's groups or a property
controls.ts Depth slider, fit and settings buttons, status line and legend
colorGroups.ts Sets group colours and custom groups on a built graph
groupColors.ts Saved group colours, and automatic colours from the palette
customGroups.ts Custom groups from the config, and matching notes to them
entries.ts Looks up entries, creating them for linked notes outside the base
groups.ts Maps notes, including linked ones, to the base's groups, splitting lists
propertyCard.ts Hover card listing the view's selected properties, with a pin button
panel/
SettingsPanel.ts Side panel with collapsible sections of view options
optionRows.ts A row for each view option, kept in step with the config
groupsSection.ts Group colours and custom groups
groupValues.ts Rows for group values, and adding a value
customGroupRow.ts Row for editing a custom group
widgets.ts Colour and property pickers, and focus helpers
types.ts
render/
renderer.ts d3-force simulation, zoom/pan, dragging, hit testing
clusterForce.ts Forces pulling each cluster together and keeping other notes out of it
clusterShapes.ts Cluster outlines, backgrounds and labels
rings.ts Ring sizes for the rings by depth layout
layers.ts Layers, and the order within them, for the layered layout
layered.ts Positions for the layered layout, packing clusters laid out separately
layerForces.ts Forces holding notes in their layers and lining up linked notes
hull.ts Convex hulls and rounded outlines for cluster shapes
draw.ts Canvas drawing
theme.ts Reads graph colours from the current theme, and colours nodes by group