-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AST visualization functionality based on d3 (#178)
- nmodl.ast now has ast_view function that visualize in memory AST representation using d3.js based radial tree - necessary html, css and js files are added - get_nmodl_example_dir is removed and taken case by python modules Todo: utility tools should be outside the main repo (see #190)
- Loading branch information
Showing
12 changed files
with
413 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
from ._nmodl.ast import * # noqa | ||
from .config import * | ||
|
||
def ast_view(nmodl_ast): | ||
"""Visualize given NMODL AST by converting to JSON form""" | ||
from ._nmodl import to_json | ||
from distutils.dir_util import copy_tree | ||
import getpass | ||
import json | ||
import os | ||
import tempfile | ||
import webbrowser | ||
|
||
installed_viz_tool = os.path.join(PROJECT_INSTALL_DIR, "share", "viz") | ||
if os.path.exists(installed_viz_tool): | ||
viz_tool_dir = installed_viz_tool | ||
else: | ||
viz_tool_dir = os.path.join(PROJECT_SOURCE_DIR, "share", "viz") | ||
|
||
work_dir = os.path.join(tempfile.gettempdir(), getpass.getuser(), "nmodl") | ||
|
||
# first copy necessary files to temp work directory | ||
copy_tree(viz_tool_dir, work_dir) | ||
|
||
# prepare json data | ||
with open(os.path.join(work_dir, 'ast.js'), 'w') as outfile: | ||
json_data = json.loads(to_json(nmodl_ast, True, True, True)) | ||
outfile.write('var astRoot = %s;' % json.dumps(json_data)) | ||
|
||
# open browser with ast | ||
url = 'file://' + os.path.join(work_dir, "index.html") | ||
webbrowser.open(url, new=1, autoraise=True) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PROJECT_SOURCE_DIR="@PROJECT_SOURCE_DIR@" | ||
PROJECT_INSTALL_DIR="@CMAKE_INSTALL_PREFIX@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
from ._nmodl import * | ||
from .config import * | ||
|
||
|
||
def example_dir(): | ||
import os | ||
"""Return directory containing NMODL examples""" | ||
installed_example = os.path.join(PROJECT_INSTALL_DIR, "share", "example") | ||
if os.path.exists(installed_example): | ||
return installed_example | ||
else: | ||
return os.path.join(PROJECT_SOURCE_DIR, "share", "example") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ast { | ||
position: fixed; | ||
left: 0px; | ||
right: 0px; | ||
top: 0px; | ||
bottom: 0px; | ||
} | ||
|
||
.node { | ||
cursor: pointer; | ||
} | ||
|
||
.node circle { | ||
fill: #ffc8c8 !important; | ||
stroke: #c57bc4; | ||
stroke-width: 2.5px; | ||
} | ||
|
||
.node text { | ||
font-size: 12px !important; | ||
font-family: sans-serif; | ||
fill: #1f1f92; | ||
} | ||
|
||
.link { | ||
fill: none; | ||
stroke: #DCA5DB; | ||
stroke-width: 3px; | ||
} | ||
|
||
.templink { | ||
fill: none; | ||
stroke: red; | ||
stroke-width: 3px; | ||
} | ||
|
||
.dots { | ||
cursor: pointer; | ||
} | ||
|
||
.tooltip { | ||
background: #23298aeb; | ||
white-space: pre; | ||
padding: 10px; | ||
border-radius: 3px; | ||
color: white; | ||
font-size: 13px; | ||
font-family: "Monaco"; | ||
position: "absolute"; | ||
z-index: 10; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>NMODL AST Visualization</title> | ||
<link rel="stylesheet" href="css/tree.css"> | ||
</head> | ||
|
||
<body> | ||
<div id="ast"></div> | ||
|
||
<script src="js/d3.min.js"></script> | ||
<script src="ast.js"></script> | ||
<script src="js/tree.js"></script> | ||
</body> | ||
|
||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.