Gaphas is the diagramming widget library for Python.

Overview

Gaphas

Build state Maintainability Test Coverage Docs build state Code style: black standard-readme compliant Gitter All Contributors

Gaphas is the diagramming widget library for Python.

Gaphas Demo

Gaphas is a library that provides the user interface component (widget) for drawing diagrams. Diagrams can be drawn to screen and then easily exported to a variety of formats, including SVG and PDF. Want to build an app with chart-like diagrams? Then Gaphas is for you! Use this library to build a tree, network, flowchart, or other diagrams.

This library is currently being used by Gaphor for UML drawing, RAFCON for state-machine based robot control, and ASCEND for solving mathematical models.

πŸ“‘ Table of Contents

πŸ“œ Background

Gaphas was built to provide the foundational diagramming portions of Gaphor. Since Gaphor is built on GTK and Cairo, PyGObject provides access to the GUI toolkit and PyCairo to the 2D graphics library. However, there wasn't a project that abstracted these technologies to easily create a diagramming tool. Hence, Gaphas was created as a library to allow others to create a diagramming tool using GTK and Cairo.

Here is how it works:

  • Items (Canvas items) can be added to a Canvas.
  • The Canvas maintains the tree structure (parent-child relationships between items).
  • A constraint solver is used to maintain item constraints and inter-item constraints.
  • The item (and user) should not be bothered with things like bounding-box calculations.
  • Very modular--e.g., handle support could be swapped in and swapped out.
  • Rendering using Cairo.

The main portions of the library include:

  • canvas - The main canvas class (container for Items).
  • items - Objects placed on a Canvas.
  • solver - A constraint solver to define the layout and connection of items.
  • gtkview - A view to be used in GTK applications that interacts with users with tools.
  • painters - The workers used to paint items.
  • tools - Tools are used to handle user events (such as mouse movement and button presses).
  • aspects - Provides an intermediate step between tools and items.

Gaphas contains default implementations for Canvas and Items. There are protocols in place to allow you to make your own canvas.

πŸ’Ύ Install

To install Gaphas, simply use pip:

$ pip install gaphas

Use of a virtual environment is highly recommended.

Development

To setup a development environment with Linux:

$ sudo apt-get install -y python3-dev python3-gi python3-gi-cairo
    gir1.2-gtk-3.0 libgirepository1.0-dev libcairo2-dev
$ pip install poetry
$ poetry install

πŸ”¦ Usage

API docs and tutorials can be found on Read the Docs.

β™₯ Contributing

Thanks goes to these wonderful people (emoji key):

Arjan Molenaar
Arjan Molenaar

πŸ’» πŸ› πŸ“– πŸ‘€ πŸ’¬ πŸ”Œ
Dan Yeaw
Dan Yeaw

πŸ’» ⚠️ πŸ‘€ πŸ› πŸ’¬ πŸš‡ πŸ“–
wrobell
wrobell

πŸ’» ⚠️ πŸ‘€
Jean-Luc Stevens
Jean-Luc Stevens

πŸ’» πŸ› πŸ“–
Franz Steinmetz
Franz Steinmetz

πŸ’» πŸ›
Adrian Boguszewski
Adrian Boguszewski

πŸ’»
Rico Belder
Rico Belder

πŸ› πŸ‘€
Adam Boduch
Adam Boduch

πŸ›
Janet Jose
Janet Jose

πŸ“–

This project follows the all-contributors specification. Contributions of any kind are welcome!

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. There is a first-timers-only tag for issues that should be ideal for people who are not very familiar with the codebase yet.
  2. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
  3. Write a test which shows that the bug was fixed or that the feature works as expected.
  4. Send a pull request and bug the maintainers until it gets merged and published. πŸ˜„

See the contributing file!

Β© License

Copyright Β© Arjan Molenaar and Dan Yeaw

Licensed under the Apache License 2.0.

Summary: You can do what you like with Gaphas, as long as you include the required notices. This permissive license contains a patent license from the contributors of the code.

Comments
  • Convert from PyGTK to PyGObject

    Convert from PyGTK to PyGObject

    Conversion from PyGTK to PyGObject (and Gtk+ 2 to 3). Steps taken include:

    1. Automatic rename using pygi-convert.sh to do basic find and replace between PyGTK and PyGObject syntax.
    2. Fixed some additional Python 3 compatibility cleanups with ez_setup and the tests
    3. Completed manual updates to finish the conversion, including the largest update which was to replace the scroll adjustment signals to inherit from Gtk.Scrollable

    All tests pass with both Python 2.7.15 and 3.7.0.

    opened by danyeaw 17
  • Record drawn items

    Record drawn items

    PR Type

    What kind of change does this PR introduce?

    • [ ] Bugfix
    • [X] Feature
    • [ ] Code style update (formatting, local variables)
    • [ ] Refactoring (no functional changes, no api changes)
    • [ ] Documentation content changes

    What is the current behavior?

    Drawing of complex (diagrams) is relatively slow, especially on platforms like macOS. Although the GtkView already uses a back-buffer, it still needs to draw() all elements when the widget is repainted. Worst case it needs to redraw it multiple times: once for bounding box calculation and any number of times to refresh the back buffer.

    Issue Number: N/A

    What is the new behavior?

    This PR contains a couple of improvements:

    • When items are painted for bounding box calculation, the resulting drawing (a cairo surface) is cached, so subsequent drawing operations can reuse this effort.
    • A special painter, RenderedItemPainter, can be used to draw items previously rendered.
    • The view is now automatically redrawn if the view's matrix has changed.
    • Update handling has been simplified. There are no matrix-updates anymore.

    Does this PR introduce a breaking change?

    • [X] Yes
    • [ ] No
    • update API

    Other information

    Since items were already drawn with the right offset (done by ItemPainter), it makes no sense to have a separate matrix-update. Such an update will result in a redraw anyway.

    As a result all matrix-update logic has been removed from GtkView, which resulted in a simpler interface. A nice bonus.

    I also considered putting a cache in ItemPainter. It is not easy to pass on data on which item needs updating and which items are removed. Therefore it seemed more logical to keep this data in the view and instead create a separate renderer (RenderedItemPainter), that takes a rendered surface from the view and draws that instead.

    BoundingBoxPainter is not needed anymore. It's kept in for now to ease the transition to the new drawing model.

    It looks like drawing is considerably slower when the demo app is in full screen. Small windows are fast, bigger ones are slow.

    To do

    • [x] There's still an issue where attached elements are not properly redrawn
    feature 
    opened by amolenaar 11
  • Back buffer: No drawing during resize of widget

    Back buffer: No drawing during resize of widget

    Is it intended/desired that during a resize operation of the GtkView, the canvas is not drawn, i.e. only the background color is visible?

    Our canvas is nested in (several) Gtk.Paned and resides next to a Gtk.Revealer. Thus, in three situations, no state machine now shown:

    • the panes are resized
    • the revealer slides up
    • the window is resized

    Personally, I would want the canvas to be drawn in all these situations.

    opened by franzlst 10
  • Updated README

    Updated README

    Hello,

    I have updated the README of Gaphas. I have reviewed and edited the file for :

    1. Spelling and grammar
    2. Edited the hyperlinks for virtual env

    I do have comments on this line-- The constraint solver can also be used to keep constraints contained within the item true, for example, to make sure a box maintains its rectangular shape. (the word "true" is confusing).

    opened by janettech 10
  • Is gaphas accepting new contributions and pull requests?

    Is gaphas accepting new contributions and pull requests?

    First, I wish to thank you for your work on gaphas!

    Gaphas has been a real delight to use. The code is of excellent quality, very readable and well documented. I love that gaphas has minimal dependencies, is written in pure Python and successfully abstracts away the more painful parts of using a gtk.DrawingArea as a canvas. Gaphas is quite wonderful, thank you!

    I've been working on a prototype project using gaphas to implement something like the Blender node editor. This project is currently in a private repository but I hope to make it public very soon.

    My main concern with gaphas is that the last public commit is from July 2012. Is development still active? Are you accepting pull requests? While learning gaphas, I have made several improvements that I would like to contribute back. Some suggestions that I would be happy to submit as a series of pull requests:

    • Multiple typo fixes.
    • Deletion of trailing whitespace.
    • Possible addition of a .gitignore to the gaphas repository.
    • Deletion of code that has been commented out (only a few instances of this).
    • Wrapping docstrings to 80 characters (mostly good already, but a few places could do with better wrapping).
    • A few other more technical ideas if you are interested!

    Please do tell me if you are interested in accepting these sorts of PRs!

    opened by jlstevens 8
  • simplegeneric => singledispatch: backward compatibility

    simplegeneric => singledispatch: backward compatibility

    With the change from simplegeneric to singledispatch, gaphas is no longer backward compatible with code that registers custom types, as you now need to call register instead of when_type.

    This is fine, as you increase the minor version.

    I was just wondering, whether you think there is an easy way for other software not requiring any code changes. Maybe somehow monkeypatching singledispatch? Doesn't sound like the best solution :-D

    opened by franzlst 6
  • Comments on the Gaphas documentation

    Comments on the Gaphas documentation

    Hello Dan,

    As discussed earlier, here are my review comments on Gaphas docs. I hope you find them useful. If you find anything that is not clear, please do ask. Also, ignore if I did any mistakes.

    The latter part of my document you will find just the grammatical correction on the content. I hope you find the corrections.

    Thanks! Janet Gaphas.docx

    opened by janettech 6
  • Update from LGPL 2.0 to 2.1 (or Apache)

    Update from LGPL 2.0 to 2.1 (or Apache)

    This issue goes along with https://github.com/gaphor/gaphor/issues/61. GitHub supports displaying the license on the repository overview. It only supports licenses from choose a license, which includes the LGPL 2.1, but not 2.0.

    The main changes are rewording Library to Lesser, and adding another option for using a shared library mechanism: b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.

    We are also considering moving to Apache instead of the LGPL, the summary of differences are:

    • LGPL requires that derivative works must be licensed using the LGPL as well
    • LGPL requires that source code must be disclosed with distribution, Apache does not
    • Apache requires an express grant of patent rights for contributions, LGPL v2.1 does not (v3 does)
    • Apache is more compatible, so we could include MIT or BSD software in our project, but we need to ensure that there is no other LGPL libraries that exist within the current software.

    Any other thoughts on upgrading to a newer version of the LGPL or to Apache?

    • [X] @danyeaw
    • [x] @amolenaar
    • [x] @wrobell
    • [X] @jlstevens - verified only removed whitespace and changed width of text
    • [X] @adrianboguszewski - no commits remain in current code base
    • [X] @franzlst
    opened by danyeaw 6
  • Fix Travis CI Build Config

    Fix Travis CI Build Config

    This change is to fix segmentation faults when trying to test Gaphas on Travis CI. These faults aren't reproducible locally, so this PR is to test the code using the CI.

    Signed-off-by: Dan Yeaw [email protected]

    opened by danyeaw 5
  • Improve render speed

    Improve render speed

    Is your feature request related to a problem?

    Currently, when implementing Item.draw(), you have to take into account speed: every time a canvas is redrawn, this method is called.

    Rendering is relatively slow, esp. on macOS.

    I did some trails with cairo.RecordingSurface, but that's probably not what we need: to render a surface it has to be applied as a pattern on the target surface. For our purposes it would be enough to just replay any drawing operation on the target surface. My assumption is that that will also be faster.

    Describe the solution you'd like

    When an item is drawn (the first time this happens is when the bounding box is calculated), the drawing operations should be recorded. On subsequent draws, the recorded items should be replayed. This ensures that:

    1. we always draw the same thing, until the item requires an update (keeps bounding box consistent)
    2. the concern of draw() being fast is less strict

    Solution to be determined still. See alternatives.

    Describe alternatives you've considered

    • Create a custom DrawingContext for Gaphas. Instead of calling DrawingContext.cairo methods, expose all required methods through DrawingContext directly. This should also expose methods for rendering Pango Layouts and SVG images (librsvg).
    • Use RecordingSurface. For one, @danyeaw got artifacts in the diagram. Secondly it's applied via patterns, where it's more logical for us to just just replay the recorded events on a surface.
    • Maybe add a bit of C/Cython) code that hooks into cairo and provides the required capabilities (e.g. expose RecordingSurface.replay or expose the surface observer code).

    Additional context

    We should handle SVG and Pango layouts as well. They render to a cairo.Context directly. Do we want to keep that interface, or provide a Gaphas specific way to render those?

    opened by amolenaar 4
  • GTK 4 support

    GTK 4 support

    PR Type

    What kind of change does this PR introduce?

    • [ ] Bugfix
    • [X] Feature
    • [ ] Code style update (formatting, local variables)
    • [ ] Refactoring (no functional changes, no api changes)
    • [ ] Documentation content changes

    The change

    Gaphas works for GTK+ 3. This PR adds support for GTK 4 -- without breaking backwards compatibility.

    Where there are incompatibilities between the GTK 3 and 4 api, a check for Gtk.get_major_version() == 3 is done.

    Tests can be executed with GTK 4 by running TEST_GTK_VERSION=4.0 pytest.

    Issue Number: https://github.com/gaphor/gaphor/issues/618

    Does this PR introduce a breaking change?

    • [ ] Yes
    • [X] No

    Other information

    In GTK 4, the canvas is a lot more responsive, on macOS at least.

    feature 
    opened by amolenaar 4
  • Line routing

    Line routing

    Many tools have an option to route lines, or at least create lines in a way that avoids other objects.

    Sources

    To create some sort of auto-layout thingy on top of this we'll need something like COLA (Constraint Layout)(https://www.adaptagrams.org/)

    Javascript implementation: https://ialab.it.monash.edu/webcola/ (github: https://github.com/tgdwyer/WebCola)

    opened by amolenaar 0
  • Obstacle avoidance for lines

    Obstacle avoidance for lines

    PR Type

    What kind of change does this PR introduce?

    • [ ] Bugfix
    • [X] Feature
    • [ ] Code style update (formatting, local variables)
    • [ ] Refactoring (no functional changes, no api changes)
    • [ ] Documentation content changes

    What is the current behavior?

    Lines are just straight.

    Issue Number: #360

    What is the new behavior?

    Gaphas has code that support object avoidance in the canvas.

    • [X] When a new line is drawn, the line tries to avoid obstacles
    • [ ] When an element is moved, the lines should move aside
    • [ ] When an element is moved, connected lines should reroute
    • [x] Avoidance for normal lines
    • [x] Avoidance for orthogonal lines
    • [ ] Sometimes the routing algorithm "hangs". Esp. when the paths are more complicated.

    Does this PR introduce a breaking change?

    • [X] Yes
    • [ ] No

    Other information

    Try examples/demo.py. The (experimental) collision avoidance code is activated there.

    feature 
    opened by amolenaar 1
Releases(3.9.2)
Owner
Gaphor
Gaphor is the simple modeling tool
Gaphor
Custom Plotly Dash components based on Mantine React Components library

Dash Mantine Components Dash Mantine Components is a Dash component library based on Mantine React Components Library. It makes it easier to create go

Snehil Vijay 239 Jan 08, 2023
A simple, fast, extensible python library for data validation.

Validr A simple, fast, extensible python library for data validation. Simple and readable schema 10X faster than jsonschema, 40X faster than schematic

kk 209 Sep 19, 2022
An interactive GUI for WhiteboxTools in a Jupyter-based environment

whiteboxgui An interactive GUI for WhiteboxTools in a Jupyter-based environment GitHub repo: https://github.com/giswqs/whiteboxgui Documentation: http

Qiusheng Wu 105 Dec 15, 2022
EPViz is a tool to aid researchers in developing, validating, and reporting their predictive modeling outputs.

EPViz (EEG Prediction Visualizer) EPViz is a tool to aid researchers in developing, validating, and reporting their predictive modeling outputs. A lig

Jeff 2 Oct 19, 2022
Data visualization using matplotlib

Data visualization using matplotlib project instructions Top 5 Most Common Coffee Origins In this visualization I used data from Ankur Chavda on Kaggl

13 Oct 27, 2021
A dashboard built using Plotly-Dash for interactive visualization of Dex-connected individuals across the country.

Dashboard For The DexConnect Platform of Dexterity Global Working prototype submission for internship at Dexterity Global Group. Dashboard for real ti

Yashasvi Misra 2 Jun 15, 2021
nptsne is a numpy compatible python binary package that offers a number of APIs for fast tSNE calculation.

nptsne nptsne is a numpy compatible python binary package that offers a number of APIs for fast tSNE calculation and HSNE modelling. For more detail s

Biomedical Visual Analytics Unit LUMC - TU Delft 29 Jul 05, 2022
Declarative statistical visualization library for Python

Altair http://altair-viz.github.io Altair is a declarative statistical visualization library for Python. With Altair, you can spend more time understa

Altair 8k Jan 05, 2023
Kglab - an abstraction layer in Python for building knowledge graphs

Graph Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, RDFlib, pySHACL, RAPIDS, NetworkX, iGraph, PyVis, pslpython, p

derwen.ai 466 Jan 09, 2023
Decision Border Visualizer for Classification Algorithms

dbv Decision Border Visualizer for Classification Algorithms Project description A python package for Machine Learning Engineers who want to visualize

Sven Eschlbeck 1 Nov 01, 2021
Render Jupyter notebook in the terminal

jut - JUpyter notebook Terminal viewer. The command line tool view the IPython/Jupyter notebook in the terminal. Install pip install jut Usage $jut --

Kracekumar 169 Dec 27, 2022
Yata is a fast, simple and easy Data Visulaization tool, running on python dash

Yata is a fast, simple and easy Data Visulaization tool, running on python dash. The main goal of Yata is to provide a easy way for persons with little programming knowledge to visualize their data e

Cybercreek 3 Jun 28, 2021
Interactive Dashboard for Visualizing OSM Data Change

Dashboard and intuitive data downloader for more interactive experience with interpreting osm change data.

1 Feb 20, 2022
A high performance implementation of HDBSCAN clustering. http://hdbscan.readthedocs.io/en/latest/

HDBSCAN Now a part of scikit-learn-contrib HDBSCAN - Hierarchical Density-Based Spatial Clustering of Applications with Noise. Performs DBSCAN over va

Leland McInnes 91 Dec 29, 2022
Python Data Structures for Humansβ„’.

Schematics Python Data Structures for Humansβ„’. About Project documentation: https://schematics.readthedocs.io/en/latest/ Schematics is a Python librar

Schematics 2.5k Dec 28, 2022
3D rendered visualization of the austrian monuments registry

Visualization of the Austrian Monuments Visualization of the monument landscape of the austrian monuments registry (Bundesdenkmalamt Denkmalverzeichni

Nikolai Janakiev 3 Oct 24, 2019
A Python-based non-fungible token (NFT) generator built using Samilla and Matplotlib

PyNFT A Pythonic NF (non-fungible token) generator built using Samilla and Matplotlib Use python pynft.py [amount] The intention behind this generato

Ayush Gundawar 6 Feb 07, 2022
Practical-statistics-for-data-scientists - Code repository for O'Reilly book

Code repository Practical Statistics for Data Scientists: 50+ Essential Concepts Using R and Python by Peter Bruce, Andrew Bruce, and Peter Gedeck Pub

1.7k Jan 04, 2023
nvitop, an interactive NVIDIA-GPU process viewer, the one-stop solution for GPU process management

An interactive NVIDIA-GPU process viewer, the one-stop solution for GPU process management.

Xuehai Pan 1.3k Jan 02, 2023
Simple addon for snapping active object to mesh ground

Snap to Ground Simple addon for snapping active object to mesh ground How to install: install the Python file as an addon use shortcut "D" in 3D view

Iyad Ahmed 12 Nov 07, 2022