How to save and load Graph View groups

Part of Obsidian guides
Published with Obsidian Share

Getting your current groups

Put this code into a note to retrieve your current group settings:

```dataviewjs
const settings = await app.internalPlugins.plugins.graph.loadData()
dv.paragraph('```json\n' + JSON.stringify(settings.colorGroups, null, 2) + '\n```')
```

It will show you something like this:

[
  {
    "query": "tag:#some-tag",
    "color": {
      "a": 1,
      "rgb": 16249602
    }
  },
  {
    "query": "tag:#another-tag",
    "color": {
      "a": 1,
      "rgb": 2969559
    }
  }
]

Take a note of the query and rgb values.

Updating the groups

Take the code below and put it into a note. It will update all your graph groups to be the two groups specified, #this-is-the-new-query and #another-new-query.

```dataviewjs
const graph = app.internalPlugins.plugins.graph
const settings = await graph.loadData()
settings.colorGroups = [
    {
        "query": "#this-is-the-new-query",
        "color": {
            "a": 1,
            "rgb": 16185856
        }
    },
    {
        "query": "#another-new-query",
        "color": {
            "a": 1,
            "rgb": 16187906
        }
    }
]
await graph.saveData(settings)
await graph.disable()
await graph.enable()
```

If you follow the structure inside the settings.colorGroups section, you can update the groups as you wish.

To change between different groups profiles, you just need to launch the Javascript code above. You could:

  • Create a couple of different notes with the groups that you want, and just load one of the notes to change all your groups.
  • Put the code in a Templater script and launch it from a hotkey.
  • Or one of the many other plugins which let you run arbitrary Javascript in Obsidian.