Skip to content

peixian/org-roam-force-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

D3 Force Diagram from Org-Roam DB

Scripts to generate a json of nodes and links from org-roam.db, and a basic html shim to display them.

Example:

https://wiki.malloc.dog/graph.html

./example-graph.png

Usage:

Prereq’s

You will need the networkx python library and the cdlib python libraries:

Both can be installed with pip install -r requirements.txt.

Generating the JSON and Viewing

`docker build .` and by default running

$> ./org-roam-d3.py && python3 -m http.server 9000

should generate a ./org-data.json file in the current directory and start up a server. Open http://localhost:9000, and you should see your graph.

By default this searches under $HOME/.emacs.d/org-roam.db. If you store the database in another location, you can use the –org-db-location flag.

The output location can be set with the --output flag. Note that the index.html file that is included with this repo is hardcoded to check for a file called org-data.json in the same directory, you will need to edit the HTML file if the output path is changed.

Additional Features

org-roam-d3.py supports a few additional features, such as replacement to generate url links (if you host your notes on a webpage, for example). It can also generate titles for communities, make sure to have an OPENAI_API_KEY set.

usage: org-roam-d3.py [-h] [--org-db-location DB_LOCATION] [--output OUTPUT_LOCATION] [--replace REPLACEMENTS [REPLACEMENTS ...]] [--top TOP] [--generate-groups]

Generates a json file from your org-roam DB

options:
  -h, --help            show this help message and exit
  --org-db-location DB_LOCATION
                        Location of org-roam.db file. Defaults to $HOME/.emacs.d/org-roam.db
  --output OUTPUT_LOCATION, -o OUTPUT_LOCATION
                        File to output as. Defaults to './org-data.json'
  --replace REPLACEMENTS [REPLACEMENTS ...]
                        Replacement to generate urls. Takes in <FILE_PATH> <REPLACEMENT_VALUE>
  --top TOP             Number of nodes to cut off by. Default is to generate all nodes
  --generate-groups     Generate groups based on file name. Uses the titles of the top 64 nodes with the most edges to generate a prompt for OpenAI to generate a name for the group. `OPENAI_API_KEY` must be set as an environment
                        variable.

Limitations

I have not tested this for:

  • org roam graphs without a central node
  • many other things

License

BSD 3 Clause. See the license file.

About

Code for generating D3 force diagrams and community detection from org-roam.db

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published