You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://mybinder.org/v2/gh/GLVis/pyglvis/HEAD?filepath=examples%2Fex1.ipynb)
7
7
[](https://mybinder.org/v2/gh/GLVis/pyglvis/HEAD?filepath=examples%2Fex9.ipynb)
8
8
9
-
This repository contains a [Jupyter](https://jupyter.org/) widget for the [GLVis](https://glvis.org/) finite element
10
-
visualization tool based on the [glvis-js](https://github.com/GLVis/glvis-js) JavaScript/WebAssembly library.
9
+
PyGLVis is an interactive [Jupyter](https://jupyter.org/) widget for visualizing finite element meshes and functions, built on-top of the [GLVis](https://glvis.org/) library.
11
10
12
-
## Usage
11
+
## 📦 Installation
13
12
14
-
```python
15
-
from glvis import glvis
13
+
The GLVis Jupyter widget is installed using `pip`. To install the latest version from the repository:
16
14
17
-
glvis(data[, width=640, height=480])
15
+
```bash
16
+
git clone https://github.com/GLVis/pyglvis.git
17
+
cd pyglvis
18
+
pip install .
19
+
```
18
20
19
-
# or assign if you want to update later
20
-
g = glvis(data)
21
-
# run a cell with `g` to show it
22
-
g
21
+
Or, install directly from PyPi,
22
+
```bash
23
+
pip install glvis
23
24
```
24
25
25
-
The `data` object and be one of:
26
+
PyGLVis requires the Python wrapper for MFEM, [PyMFEM](https://github.com/mfem/pymfem), which can be installed with
27
+
```bash
28
+
pip install mfem
29
+
```
26
30
27
-
- a `str`, in the format of `*.saved` files
28
-
- a `Mesh`, defined in [PyMFEM](https://github.com/mfem/pymfem)
29
-
- a `(Mesh, GridFunction)` tuple, defined in [PyMFEM](https://github.com/mfem/pymfem)
30
31
31
-
[PyMFEM](https://github.com/mfem/pymfem) can be installed with `pip install mfem --no-binary mfem`.
32
32
33
+
## 🚀 Usage
34
+
35
+
### Basic usage
33
36
34
-
Once you have a `glvis` object there are a few methods that can used to update the
35
-
visualization:
36
37
```python
37
-
# show a new Mesh/GridFunction, resets keys
38
-
g.plot(data)
39
-
# show an updated visualization with the same `Mesh` and `GridFunction`
40
-
# dimensions, preserves keys
41
-
g.update(data)
42
-
# change the image size
43
-
g.set_size(width, height)
44
-
# force the widget to render. if the widget isn't the last statement in a cell it
45
-
# will not be shown without this. see ex9.ipynb
46
-
g.render()
47
-
```
38
+
from glvis import glvis
48
39
49
-
See the [examples](examples/) directory for additional examples. To test those locally, start a Jupyter notebook server with
40
+
# Create a `glvis` object
41
+
g = glvis(data, width=640, height=480)
50
42
43
+
# Run a cell with `g` as the last statement to display the widget
44
+
g
51
45
```
52
-
jupyter notebook
53
-
```
54
-
55
-
## Installation
56
-
57
-
The GLVis Jupyter widget can be simply installed with `pip`:
58
46
59
-
```
60
-
pip install glvis
61
-
```
47
+
The `data` object can be one of:
62
48
63
-
It order for the installation to be useful you must enable the extension for one or both
64
-
of the [Classic Notebook](https://jupyter-notebook.readthedocs.io/en/stable/) and
65
-
[Jupyter Lab](https://jupyterlab.readthedocs.io/en/stable/), see the next two sections:
49
+
-`Mesh`, defined in [PyMFEM](https://github.com/mfem/pymfem)
50
+
-`(Mesh, GridFunction)` tuple, defined in [PyMFEM](https://github.com/mfem/pymfem)
51
+
-`str`, in the format of `*.saved` files [used by MFEM and GLVis](https://mfem.org/mesh-format-v1.0/). See [examples/basic.ipynb](examples/basic.ipynb) for an example.
66
52
67
-
### Jupyter Notebook
53
+
### Customization with key commands
68
54
69
-
To use the widget with the basic Notebook enable it with `jupyter nbextension enable`:
55
+
GLVis has many keyboard commands that can be used to customize the visualization.
56
+
A few of the most common are listed below. See the [GLVis README](https://github.com/GLVis/glvis?tab=readme-ov-file#key-commands) for a full list.
57
+
-`r` - reset the view
58
+
-`c` - toggle the colorbar
59
+
-`j` - toggle perspective
60
+
-`l` - toggle the light
61
+
-`g` - toggle the background color (white/black)
62
+
-`a` - cycle through bounding box axes states
63
+
-`m` - cycle through mesh states
64
+
-`p` - cycle through color palettes
65
+
-`t` - cycle through materials and lights
66
+
-`0` - begin rotating around z-axis
67
+
-`.` - pause rotation
68
+
-`*`/`/` - zoom in/out
70
69
70
+
These can be set using the `keys` argument when creating a `glvis` object.
71
+
```python
72
+
glvis(data, keys='rljgac//0')
71
73
```
72
-
jupyter nbextension enable --py glvis
73
-
```
74
-
75
-
After enabling the extension you can verify you're good to go with:
74
+
This combination of keys would: `r` reset the view, `l` toggle the light, `j` toggle perspective, `g` toggle the background color to black (default is white), `a` show the bounding box, `c` show the colorbar, `//` zoom out twice, and `0` begin rotating around the z-axis:
This widget was originally developed using the [jupyter widget cookiecutter](https://github.com/jupyter-widgets/widget-cookiecutter); however, [recent changes to the Jupyter ecosystem](https://jupyter-notebook.readthedocs.io/en/latest/migrate_to_notebook7.html#why-a-new-version) have broken a lot of functionality, leading to a rewrite using [anywidget](https://anywidget.dev/). If you encounter any problems, please consider supporting development by opening an [issue](https://github.com/GLVis/pyglvis/issues).
118
107
119
-
1. Bump the version in _pyglvis/js/package.json_ and _glvis-js/package.json_
120
-
2.`npm install path/to/glvis-js`
121
108
122
109
123
-
Each time you update stuff in _pyglvis/js/src_:
110
+
## 🤖 Development
124
111
125
-
1.`npm install`
126
-
2.`npx webpack`
127
-
128
-
129
-
Once:
112
+
### PyGLVis dependencies
130
113
114
+
```mermaid
115
+
graph TD;
116
+
A[mfem] --> B[pymfem];
117
+
A --> C[glvis];
118
+
C --> D[glvis-js];
119
+
Ext1[emscripten] --> D;
120
+
D-.-E["glvis-js\n(npm/esm mirror)"]
121
+
B & E --> G[pyglvis];
122
+
Ext2[jupyter] --> G;
131
123
```
132
-
git clone https://github.com/glvis/pyglvis.git
133
-
cd pyglvis
134
-
pip install -e .
135
-
```
136
124
137
-
### Developing in Jupyter Notebook
125
+
`pyglvis` is most directly depednent on `PyMFEM` and `glvis-js`. [PyMFEM](https://github.com/mfem/pymfem) is a Python wrapper of the finite element library, `MFEM`, while `glvis-js` is a JavaScript/WebAssembly port of `glvis`.
126
+
127
+
`glvis-js` is hosted on [github](https://github.com/glvis/glvis-js) and mirrored on [npm](https://www.npmjs.com/package/glvis). [esm.sh](https://esm.sh/glvis) allows `pyglvis` to pull the latest version of `glvis-js` directly from npm. This can be seen in the first line of [glvis/widget.js](glvis/widget.js):
You can specify a different version of `glvis-js` by adding `@x.y.z` to the end of this import statement, where `x.y.z` matches a version number available on `npm`, e.g.
0 commit comments