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
A data visualization curriculum of interactive notebooks.

A data visualization curriculum of interactive notebooks, using Vega-Lite and Altair. This repository contains a series of Python-based Jupyter notebooks.

UW Interactive Data Lab 1.2k Dec 30, 2022
An interactive dashboard built with python that enables you to visualise how rent prices differ across Sweden.

sweden-rent-dashboard An interactive dashboard built with python that enables you to visualise how rent prices differ across Sweden. The dashboard/web

Rory Crean 5 Dec 19, 2021
High-level geospatial data visualization library for Python.

geoplot: geospatial data visualization geoplot is a high-level Python geospatial plotting library. It's an extension to cartopy and matplotlib which m

Aleksey Bilogur 1k Jan 01, 2023
Visual Python is a GUI-based Python code generator, developed on the Jupyter Notebook environment as an extension.

Visual Python is a GUI-based Python code generator, developed on the Jupyter Notebook environment as an extension.

Visual Python 564 Jan 03, 2023
Minimal Ethereum fee data viewer for the terminal, contained in a single python script.

Minimal Ethereum fee data viewer for the terminal, contained in a single python script. Connects to your node and displays some metrics in real-time.

48 Dec 05, 2022
A D3.js plugin that produces flame graphs from hierarchical data.

d3-flame-graph A D3.js plugin that produces flame graphs from hierarchical data. If you don't know what flame graphs are, check Brendan Gregg's post.

Martin Spier 740 Dec 29, 2022
a robust room presence solution for home automation with nearly no false negatives

Argos Room Presence This project builds a room presence solution on top of Argos. Using just a cheap raspberry pi zero w (plus an attached pi camera,

Angad Singh 46 Sep 18, 2022
πŸŒ€β„οΈπŸŒ©οΈ This repository contains some examples for creating 2d and 3d weather plots using matplotlib and cartopy libraries in python3.

Weather-Plotting πŸŒ€ ❄️ 🌩️ This repository contains some examples for creating 2d and 3d weather plots using matplotlib and cartopy libraries in pytho

Giannis Dravilas 21 Dec 10, 2022
Data Visualizer for Super Mario Kart (SNES)

Data Visualizer for Super Mario Kart (SNES)

MrL314 21 Nov 20, 2022
:bowtie: Create a dashboard with python!

Installation | Documentation | Gitter Chat | Google Group Bowtie Introduction Bowtie is a library for writing dashboards in Python. No need to know we

Jacques Kvam 753 Dec 22, 2022
Python wrapper for Synoptic Data API. Retrieve data from thousands of mesonet stations and networks. Returns JSON from Synoptic as Pandas DataFrame

☁ Synoptic API for Python (unofficial) The Synoptic Mesonet API (formerly MesoWest) gives you access to real-time and historical surface-based weather

Brian Blaylock 23 Jan 06, 2023
The plottify package is makes matplotlib plots more legible

plottify The plottify package is makes matplotlib plots more legible. It's a thin wrapper around matplotlib that automatically adjusts font sizes, sca

Andy Jones 97 Nov 04, 2022
FURY - A software library for scientific visualization in Python

Free Unified Rendering in Python A software library for scientific visualization in Python. General Information β€’ Key Features β€’ Installation β€’ How to

169 Dec 21, 2022
A python wrapper for creating and viewing effects for Matt Parker's christmas tree.

Christmas Tree Visualizer A python wrapper for creating and viewing effects for Matt Parker's christmas tree. Displays py or csv effect files and allo

4 Nov 22, 2022
Process dataframe in a easily way.

Popanda Written by Shengxuan Wang at OSU. Used for processing dataframe, especially for machine learning. The name is from "Po" in the movie Kung Fu P

ShawnWang 1 Dec 24, 2021
Jupyter Notebook extension leveraging pandas DataFrames by integrating DataTables and ChartJS.

Jupyter DataTables Jupyter Notebook extension to leverage pandas DataFrames by integrating DataTables JS. About Data scientists and in fact many devel

Marek ČermÑk 142 Dec 28, 2022
Certificate generating and sending system written in Python.

Certificate Generator & Sender How to use git clone https://github.com/saadhaxxan/Certificate-Generator-Sender.git cd Certificate-Generator-Sender Add

Saad Hassan 11 Dec 01, 2022
Visualize large time-series data in plotly

plotly_resampler enables visualizing large sequential data by adding resampling functionality to Plotly figures. In this Plotly-Resampler demo over 11

PreDiCT.IDLab 604 Dec 28, 2022
termplotlib is a Python library for all your terminal plotting needs.

termplotlib termplotlib is a Python library for all your terminal plotting needs. It aims to work like matplotlib. Line plots For line plots, termplot

Nico SchlΓΆmer 553 Dec 30, 2022
Simple, realtime visualization of neural network training performance.

pastalog Simple, realtime visualization server for training neural networks. Use with Lasagne, Keras, Tensorflow, Torch, Theano, and basically everyth

Rewon Child 416 Dec 29, 2022