Prevent loosing Groups in Graph View by Accident

Use case or problem

While using the Graph View, I’m constantly hitting the “Restore default settings” button by accident, when I simply want to close the settings box. This causes me to loose all my groups constantly. After a few times, it gets really frustrating to recreate.

Proposed solution

  1. (Most favorable solution) Move the Groups out of the settings box. Compared to all the other settings, Groups doesn’t seem like something you would want to reset, intuitively.
  2. Move the restore button away from the close button.
  3. Have a dialog box to confirm that the user wishes to reset the settings.
2 Likes

If it helps, you can get / store / set your groups like this. You can save the group settings to a note so you can easily restore or modify them.

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.
1 Like

Before/when it happens again …

In your vault in your file explorer there is a folder called:

.obsidian

… depending on your file system you may have to enable "show hidden files’ to see it.

In that folder the file …

graph.json

has all your graph settings.

When happy with your settings copy & paste that file somewhere safe so that you can paste it back in should you ever lose your settings again.

Thank you. It’s a great help for me to restore my group settings. - Is there also an option to restore my filter settings in Graph View?

I am new with Obsidian and I do not see the “Restore default settings” button but the same thing happens to me with the “Delete group” buttons and although the proposed solutions are useful to live with the problem, the usability problem persists and I think it could be solved easily fixing the position of the “Close” button when scrolling in the settings box