Skip to content

Commit

Permalink
expose js bzvisualizer params
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Apr 8, 2024
1 parent 84cdd9e commit f44d97b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
11 changes: 9 additions & 2 deletions example/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"# This cell is only needed for development!\n",
"# This cell (autoloading & hot module replacement) is only needed for development!\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"%env ANYWIDGET_HMR=1"
Expand All @@ -30,7 +30,14 @@
"# element numbers of atoms\n",
"atom_numbers = [6]\n",
"\n",
"bz = BZVisualizer(cell, rel_coords, atom_numbers, width=\"100%\", height=\"400px\")\n",
"bz = BZVisualizer(\n",
" cell, rel_coords, atom_numbers,\n",
" width=\"100%\", height=\"400px\",\n",
" show_axes=True,\n",
" show_bvectors=True,\n",
" show_pathpoints=True,\n",
" disable_interact_overlay=True,\n",
")\n",
"display(bz)"
]
},
Expand Down
12 changes: 11 additions & 1 deletion js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ import { createBZVisualizer } from "brillouinzone-visualizer";
function render({ model, el }) {
let getSeekpathData = () => model.get("seekpath_data");

let getShowAxes = () => model.get("show_axes");
let getShowBVectors = () => model.get("show_bvectors");
let getShowPathpoints = () => model.get("show_pathpoints");
let getDisableInteractOverlay = () => model.get("disable_interact_overlay");

let container = document.createElement("div");
container.style.width = model.get("width");
container.style.height = model.get("height");
container.style.margin = "0 auto";

let mainBZVisualizer = createBZVisualizer(container, getSeekpathData());
let mainBZVisualizer = createBZVisualizer(container, getSeekpathData(), {
showAxes: getShowAxes(),
showBVectors: getShowBVectors(),
showPathpoints: getShowPathpoints(),
disableInteractOverlay: getDisableInteractOverlay(),
});

model.on("change:seekpath_data", () => {
mainBZVisualizer.loadBZ(getSeekpathData());
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"esbuild": "^0.20.0"
},
"dependencies": {
"brillouinzone-visualizer": "^0.3.2"
"brillouinzone-visualizer": "^0.3.3"
}
}
12 changes: 12 additions & 0 deletions src/widget_bzvisualizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class BZVisualizer(anywidget.AnyWidget):
_css = pathlib.Path(__file__).parent / "static" / "widget.css"

seekpath_data = traitlets.Dict({}).tag(sync=True)

# parameters passed to the js BZVisualizer
show_axes = traitlets.Bool(True).tag(sync=True)
show_bvectors = traitlets.Bool(True).tag(sync=True)
show_pathpoints = traitlets.Bool(False).tag(sync=True)
disable_interact_overlay = traitlets.Bool(False).tag(sync=True)

# Parameters to control the size of the div-container
width = traitlets.Unicode("100%").tag(sync=True)
height = traitlets.Unicode("400px").tag(sync=True)

Expand All @@ -27,6 +35,10 @@ def __init__(
atom_numbers,
**kwargs,
):
"""Method to create the widget.
The traitlets defined above can be set as a kwargs.
"""
super().__init__(**kwargs)
self.seekpath_data = utils.get_seekpath_data_for_visualizer(
cell, rel_coords, atom_numbers
Expand Down

0 comments on commit f44d97b

Please sign in to comment.