Phitigra is a graph editor widget for SageMath when using the Jupyter notebook.
Try the demo notebook on mybinder!
Note: for some unknown reason the above link stopped working.
With phitigra one can:
- draw graphs using the mouse to add vertices and edges
- move the vertices positions, zoom in and out
- draw undirected as well as directed graphs
- choose the color of vertices and edges
- apply various layout algorithms
- easily retrieve the drawn graph for use with SageMath
- run step-by-step a custom script on the drawn graph
- change and refresh the drawing with external functions
The following are not supported:
- multigraphs: multiple edges will not be drawn
- large graphs: the rendering will be unpraticably slow
- ipywidgets, for user interaction
- ipycanvas, for the drawing
With jupyter, you might need the following
jupyter nbextension enable --py widgetsnbextension
after you install ipywidgets, and possibly more if using virtualenv and working in an activated virtual environment, see ipywidget's documentation for full details.
This is the first thing to check if the import of the package works fine but nothing shows when you try to display the widget.
With jupyterlab, the jupyterlab_widgets
package is also required for the widget to show.
(Runs online, nothing to install.)
Note: for some unknown reason the link below stopped working.
Clicking here will open the demo notebook on mybinder in a new tab. Note that this uses the stable version of phitigra (that from the master
branch), which may differ from the one in the develop
branch.
This assumes that SageMath is installed on your system. See http://www.sagemath.org for install instructions.
The stable version is on pypi so it can be installed as follows
sage -pip install --upgrade phitigra
Clone the source from the repository
git clone https://github.com/jfraymond/phitigra.git
Install or upgrade with pip:
sage -pip install --upgrade path/to/the/cloned/repository
That's it!
To uninstall:
sage -pip uninstall phitigra
Note that the above commands should not be run from the repository directory, otherwise pip
might complain that it did not find files to uninstall.
from phitigra import GraphEditor
editor = GraphEditor(graphs.RandomGNP(10, 0.5))
editor.show()
# Now you can play with the graph!
A copy of the currently drawn graph can be obtained with the get_graph
function:
G = editor.get_graph()
# Now G is a copy of the graph drawn in editor e
There are many more examples in the demo notebook.
As with SageMath's code, tests and code quality checks can be started with the --tox
option (from the cloned directory):
sage --tox src/phitigra
From the package directory
cd docs
sage -sh -c "make html"
The main file of the documentation is then in docs/build/html/index.html
.
A recent build of the documentation can be found here.
- Minor change to adapt to the new ipycanvas; this version will not work with ipycanvas < 0.12.0
- Minor fixes in the documentation
- Fixed an issue when building the documentation
- Show/hide edge labels
- User-defined vertex labels
- Exposing vertex positioning functions
- Removing the
Next
button - Updating links after move to github
- More examples in the demo notebook
- Improved doc
- Polished code, which now passes all tests
- Changed package structure to follows python guidelines
- Single (major) change: renaming
SimpleGraphEditor
intoGraphEditor
. Code written for previous versions is not compatible with this one, but can be easily fixed.
- Demo notebook
- Binder link
- Improved update time when moving vertices
- Minor fixes
- Docstrings and doctests in (almost) all functions
- Hiding of internal objects
- Cleaning code