Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
simonzhao committed Aug 19, 2019
1 parent 6e36cff commit 040bbac
Show file tree
Hide file tree
Showing 14 changed files with 393 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.ipynb
.idea/
*.pyc
58 changes: 57 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
# thebrain2dot
thebrain json to dot / graphviz

thebrain10 `.json` (File>Export>JSON Files
) to `.dot` visualization with Graphviz

Before:

![thebrain10 screenshot](test/thebrain_screenshot.png)

After:

![](test/thebrain.png)

More Complicated Example:

![](test/thebrain_complex.PNG)

## API

Example: see [test/test.py](test/test.py)

```python
brain_json2dot(thoughts_path, links_path, dot_path='thebrain.dot', png_path='thebrain.png',
layout='dot', bg_color='grey22', node_shape='circle', node_color='white',
edge_default_color='white', edge_splines='', edge_font_size=10)
```

## Dependency

### Graphviz

Ubuntu:

```bash
apt install -y graphviz
```

Windows: TODO

### Pygraphviz

Ubuntu:

```bash
apt-get install -y graphviz-dev
pip install pygraphviz
```

Windows: TODO

## TODO

- Doc: parsing of thebrain10's `thoughts.json` & `links.json`
- Dev: publish package to PYPI
- Parsing: correct color mapping (thebrain exported json seems to have bugs about color)
- Layout: label / tag
- Layout: parent / sibling location restriction in visualization
- Layout: community detection
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pygraphviz == 1.5
networkx == 2.3
21 changes: 21 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="thebrain2dot",
version="0.0.1",
author="simoncos",
author_email="[email protected]",
description="thebrain10 json to dot / graphviz",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/simoncos/thebrain2dot",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
28 changes: 28 additions & 0 deletions test/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"f07554d3-0e52-49b7-8dd0-c47fbc5a21e1","Kind":1,"Relation":1,"Direction":5,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:00:39.919046","ModificationDateTime":"2019-08-14T10:00:53.604762","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"2d3a32ca-eba0-4020-8f9a-880f0ff55587"}
{"ThoughtIdA":"798ddd08-69d3-41e7-a24a-a5e8610adbf8","ThoughtIdB":"35033d4d-eb34-4cd3-ab99-480140aa2154","Kind":1,"Relation":3,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-19T03:35:30.486446","ModificationDateTime":"2019-08-19T03:35:30.486446","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"452ed870-a417-4ee3-8fca-0ada046d1912"}
{"ThoughtIdA":"35033d4d-eb34-4cd3-ab99-480140aa2154","ThoughtIdB":"2c4a67d8-a2a9-4ef6-a248-323b90233d71","Kind":1,"Relation":3,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-19T03:34:27.790097","ModificationDateTime":"2019-08-19T03:34:27.790098","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"459c1109-6d2b-4a45-a6e4-0a1eaa129ce1"}
{"ThoughtIdA":"2641dcf4-2043-4bee-8351-db8fb979d425","ThoughtIdB":"34661281-525a-4b88-a111-954f82ee949f","Kind":1,"Relation":1,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-19T03:35:26.784988","ModificationDateTime":"2019-08-19T03:35:26.784988","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"477c8248-689e-48a7-889c-e620b0b88cea"}
{"ThoughtIdA":"24739c42-7ad2-4214-8be9-c9a79644f0f1","ThoughtIdB":"c46d5e0e-e64f-4028-9f74-8a4ad8f9a331","Kind":1,"Relation":1,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-15T03:53:15.685938","ModificationDateTime":"2019-08-15T03:53:15.685938","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"48e95f93-c2aa-47fe-97cc-dcfd442120e0"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"6718ae14-f38c-4032-ad60-4aa5ed1c8e73","Kind":1,"Relation":3,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:02:57.587353","ModificationDateTime":"2019-08-14T10:02:57.587353","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"5619d750-0d3d-4347-8fb3-08993fc61a90"}
{"ThoughtIdA":"00000000-0000-0000-0000-000000000000","ThoughtIdB":"00000000-0000-0000-0000-000000000000","Kind":2,"Relation":0,"Direction":-1,"Meaning":0,"Name":"Y","Color":-16711936,"Thickness":-1,"CreationDateTime":"2019-08-15T03:42:44.103407","ModificationDateTime":"2019-08-19T03:34:01.491013","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"577c1ea3-0763-435c-9aab-42bd54993f34"}
{"ThoughtIdA":"35033d4d-eb34-4cd3-ab99-480140aa2154","ThoughtIdB":"46167cc3-2dde-49c0-8142-a151e02cf11b","Kind":1,"Relation":3,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-19T03:34:31.76813","ModificationDateTime":"2019-08-19T03:34:31.76813","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"5a2be1dc-877e-4dc8-aed3-72097611ce9b"}
{"ThoughtIdA":"00000000-0000-0000-0000-000000000000","ThoughtIdB":"00000000-0000-0000-0000-000000000000","Kind":2,"Relation":0,"Direction":-1,"Meaning":0,"Name":"X","Color":-65536,"Thickness":-1,"CreationDateTime":"2019-08-15T03:41:47.801784","ModificationDateTime":"2019-08-19T03:33:52.771762","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"63a6891c-f27d-49e0-bd76-297cde8f584e"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"46167cc3-2dde-49c0-8142-a151e02cf11b","Kind":1,"Relation":3,"Direction":3,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:02:34.74406","ModificationDateTime":"2019-08-14T10:04:11.0454","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"6415da64-cc21-4e68-b742-08bacd216ef0"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"f68fec36-1e2f-4444-bdcb-f5a04e000235","Kind":1,"Relation":3,"Direction":5,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:02:53.919945","ModificationDateTime":"2019-08-14T10:04:21.220404","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"7472ebab-f581-4528-ab65-5d6a8d909568"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"b2ac1608-b698-4006-a6a4-912bde83eab5","Kind":1,"Relation":3,"Direction":1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:01:03.832758","ModificationDateTime":"2019-08-14T10:01:22.216195","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"8f3b17fc-3ed9-4993-8eb6-c11a4a54164b"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"d82a2ce7-184c-43ab-93e1-6f9817509eef","Kind":1,"Relation":1,"Direction":-1,"Meaning":1,"TypeId":"577c1ea3-0763-435c-9aab-42bd54993f34","Thickness":-1,"CreationDateTime":"2019-08-15T03:42:21.826","ModificationDateTime":"2019-08-15T03:42:44.107083","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"90243068-4569-4ab3-8a88-25ebdf93ee3e"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"92034f18-f9c0-4e9a-8445-56050a8c5211","Kind":1,"Relation":1,"Direction":1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:01:42.504622","ModificationDateTime":"2019-08-14T10:02:07.955579","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"95fea354-3340-46fd-983b-f9bf06f90697"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"63e49886-304f-4788-902f-684b0ff48610","Kind":1,"Relation":1,"Direction":3,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:02:15.055841","ModificationDateTime":"2019-08-14T10:02:28.671697","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"9ca2cffa-95ea-42b5-9e4e-d3b5837a4206"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"35033d4d-eb34-4cd3-ab99-480140aa2154","Kind":1,"Relation":1,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:01:32.934449","ModificationDateTime":"2019-08-14T10:01:32.934449","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"9e8989bc-d2f4-422b-a84c-dd843e1a566e"}
{"ThoughtIdA":"798ddd08-69d3-41e7-a24a-a5e8610adbf8","ThoughtIdB":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","Kind":1,"Relation":1,"Direction":7,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:04:36.058749","ModificationDateTime":"2019-08-14T10:04:56.009243","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"b1836ef1-784e-4d49-8a27-da4974ebfb5d"}
{"ThoughtIdA":"6f8a1e15-69ae-415a-93c2-9b8eed83e437","ThoughtIdB":"c46d5e0e-e64f-4028-9f74-8a4ad8f9a331","Kind":1,"Relation":1,"Direction":-1,"Meaning":2,"Thickness":-1,"CreationDateTime":"2019-08-15T04:00:17.142283","ModificationDateTime":"2019-08-15T04:00:17.142283","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"b460cf9e-f0f3-4f59-a787-71e4c9175228"}
{"ThoughtIdA":"f07554d3-0e52-49b7-8dd0-c47fbc5a21e1","ThoughtIdB":"35033d4d-eb34-4cd3-ab99-480140aa2154","Kind":1,"Relation":3,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-19T03:34:39.785165","ModificationDateTime":"2019-08-19T03:34:39.785165","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"c2dc2129-4bfa-444e-8113-b0462036dcf4"}
{"ThoughtIdA":"2d047d85-4c72-4b8b-a7fb-140bff573d02","ThoughtIdB":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","Kind":1,"Relation":1,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:03:32.376882","ModificationDateTime":"2019-08-14T10:03:32.376882","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"c3d2cde8-7763-43e2-bea0-824321976e2b"}
{"ThoughtIdA":"2641dcf4-2043-4bee-8351-db8fb979d425","ThoughtIdB":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","Kind":1,"Relation":1,"Direction":3,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:03:38.652809","ModificationDateTime":"2019-08-14T10:04:49.565615","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"c5fe693e-d17c-45db-a8b9-7771542b5527"}
{"ThoughtIdA":"92034f18-f9c0-4e9a-8445-56050a8c5211","ThoughtIdB":"34661281-525a-4b88-a111-954f82ee949f","Kind":1,"Relation":3,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-19T03:35:33.81912","ModificationDateTime":"2019-08-19T03:35:33.81912","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"c9ecdf9b-02c0-4103-a97f-261fd984123c"}
{"ThoughtIdA":"2f78fc5d-15d3-4975-9daf-989c64d321cb","ThoughtIdB":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","Kind":1,"Relation":1,"Direction":-1,"Meaning":1,"Name":"X","Thickness":-1,"CreationDateTime":"2019-08-15T03:41:55.305119","ModificationDateTime":"2019-08-15T03:42:03.479241","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"cf5618f7-4117-4e8e-90d1-da7b313c621c"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"34661281-525a-4b88-a111-954f82ee949f","Kind":1,"Relation":1,"Direction":-1,"Meaning":1,"TypeId":"63a6891c-f27d-49e0-bd76-297cde8f584e","Thickness":-1,"CreationDateTime":"2019-08-15T03:41:33.576648","ModificationDateTime":"2019-08-15T03:41:47.805303","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"d6cbd9d6-d005-413e-a909-4a161276bfec"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"24739c42-7ad2-4214-8be9-c9a79644f0f1","Kind":1,"Relation":1,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-15T03:53:11.671938","ModificationDateTime":"2019-08-15T03:53:11.671938","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"dc9f0c5a-30e9-44b4-a09c-cb7521271142"}
{"ThoughtIdA":"b8a23727-aacc-4c88-936f-ba36867360e7","ThoughtIdB":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","Kind":1,"Relation":1,"Direction":1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-14T10:03:35.50398","ModificationDateTime":"2019-08-14T10:04:43.828874","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"e2752389-38f2-42db-8843-96b811e9cd31"}
{"ThoughtIdA":"5cfa34e0-1d2b-48cc-87be-b07a2928f71e","ThoughtIdB":"2c4a67d8-a2a9-4ef6-a248-323b90233d71","Kind":1,"Relation":3,"Direction":-1,"Meaning":1,"TypeId":"63a6891c-f27d-49e0-bd76-297cde8f584e","Thickness":-1,"CreationDateTime":"2019-08-15T03:42:10.823933","ModificationDateTime":"2019-08-15T03:42:17.843357","SyncSentId":"5e4bce46-19b2-45b4-ac0b-910b00d9812a","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"f44f6a7d-82dc-4517-9a07-52e633fa0c1c"}
{"ThoughtIdA":"f07554d3-0e52-49b7-8dd0-c47fbc5a21e1","ThoughtIdB":"34661281-525a-4b88-a111-954f82ee949f","Kind":1,"Relation":3,"Direction":-1,"Meaning":1,"Thickness":-1,"CreationDateTime":"2019-08-19T03:34:34.399324","ModificationDateTime":"2019-08-19T03:34:34.399324","BrainId":"36e1d232-56fb-480c-bb1b-aebe4604e198","Id":"f61aed69-1d16-48e7-85ac-aa91cd37693d"}
Binary file added test/test.brz
Binary file not shown.
12 changes: 12 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pathlib import Path
import sys

p = Path(__file__).absolute()
# make user-profiling in the import system's search list to support running this .py file as script
sys.path.insert(0, str(p.parent.parent))

from thebrain2dot.thebrain2dot import brain_json2dot

if __name__ == '__main__':
brain_json2dot(thoughts_path='thoughts.json', links_path='links.json')
# will output both .dot file + .png file
131 changes: 131 additions & 0 deletions test/thebrain.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
digraph "" {
graph [bgcolor=grey22,
penwidth=1
];
node [color=white,
fixedsize=True,
fontcolor=white,
shape=circle
];
edge [fontsize=10];
Test [fontsize=125.3590247722077,
width=31.42977018367797];
B [fontsize=52.135253893180234,
width=5.436169397012729];
Test -> B [color=white,
dir=forward,
fontcolor=white];
A [fontsize=66.90901686464305,
width=8.953633075586179];
Test -> A [color=white,
dir=none,
fontcolor=white];
Q [fontsize=43.6002232578829,
width=3.801958936274467];
Test -> Q [color="#ff0103",
dir=none,
fontcolor="#ff0103",
label=X];
N [fontsize=60.26223636012163,
width=7.263074262246332];
Test -> N [color="#ff0103",
dir=none,
fontcolor="#ff0103",
label=X];
R [fontsize=44.89087752138725,
width=4.030381769280382];
Test -> R [color=white,
dir=none,
fontcolor=white];
S [fontsize=55.37934570728099,
width=6.133743861933081];
Test -> S [color="#00fe03",
dir=none,
fontcolor="#00fe03",
label=Y];
I [fontsize=33.0928921382762,
width=2.1902790201511655];
Test -> I [color=white,
dir=none,
fontcolor=white];
G [fontsize=43.6002232578829,
width=3.801958936274467];
Test -> G [color=white,
dir=back,
fontcolor=white];
H [fontsize=33.0928921382762,
width=2.1902790201511655];
Test -> H [color=white,
dir=forward,
fontcolor=white];
C [fontsize=33.0928921382762,
width=2.1902790201511655];
Test -> C [color=white,
dir=forward,
fontcolor=white];
E [fontsize=43.72922067044773,
width=3.8244894808894268];
Test -> E [color=white,
dir=forward,
fontcolor=white];
F [fontsize=33.0928921382762,
width=2.1902790201511655];
Test -> F [color=white,
dir=back,
fontcolor=white];
B -> A [color=white,
dir=none,
fontcolor=white];
B -> N [color=white,
dir=none,
fontcolor=white];
M [fontsize=43.60022325788291,
width=3.8019589362744672];
M -> Test [color=white,
dir=back,
fontcolor=white];
M -> A [color=white,
dir=none,
fontcolor=white];
A -> Q [color=white,
dir=none,
fontcolor=white];
A -> G [color=white,
dir=none,
fontcolor=white];
L [fontsize=43.72922067044773,
width=3.824489480889427];
L -> Test [color=white,
dir=back,
fontcolor=white];
L -> N [color=white,
dir=none,
fontcolor=white];
R -> S [color=white,
dir=none,
fontcolor=white];
E -> N [color=white,
dir=none,
fontcolor=white];
T [fontsize=34.39780907705388,
width=2.366418538602901];
T -> S [color=white,
dir=none,
fontcolor=white];
J [fontsize=33.0928921382762,
width=2.1902790201511655];
J -> Test [color=white,
dir=none,
fontcolor=white];
O [fontsize=33.0928921382762,
width=2.1902790201511655];
O -> Test [color=white,
dir=none,
fontcolor=white,
label=X];
K [fontsize=33.0928921382762,
width=2.1902790201511655];
K -> Test [color=white,
dir=forward,
fontcolor=white];
}
Binary file added test/thebrain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/thebrain_complex.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/thebrain_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 040bbac

Please sign in to comment.