Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cauebs authored and prusse-martin committed Dec 8, 2022
1 parent ecdf163 commit 10e8279
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ jobs:
fail-fast: false
matrix:
CONDA_PY: ["36", "37", "38", "39"]
include:
- CONDA_PY: "36"
PYTHON_VERSION: "=3.6"
- CONDA_PY: "37"
PYTHON_VERSION: "=3.7"
- CONDA_PY: "38"
PYTHON_VERSION: "=3.8"
- CONDA_PY: "39"
PYTHON_VERSION: "=3.9"


steps:
- uses: actions/checkout@v2
Expand All @@ -33,13 +43,18 @@ jobs:
- name: Install
env:
CONDA_PY: ${{ matrix.CONDA_PY }}
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
run: |
conda config --system --set always_yes yes --set changeps1 no
conda install -c conda-forge conda-devenv
conda info -a
export TEST_QMXGRAPH=1
echo "=== conda devenv -n qmxgraph --print-full ==="
conda devenv -n qmxgraph --print-full
echo "=== === ==="
conda devenv -n qmxgraph
conda install -n qmxgraph coveralls pytest-cov
conda list -n qmxgraph
conda init bash
- name: Tests
shell: bash -l {0}
Expand Down
5 changes: 4 additions & 1 deletion environment.devenv.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% set TEST_QMXGRAPH = os.environ.get('TEST_QMXGRAPH', '0') != '0' %}
{% set PYTHON_VERSION = os.environ.get('PYTHON_VERSION', '3.6') %}
{% set PYTHON_VERSION = os.environ.get('TRAVIS_PYTHON_VERSION', PYTHON_VERSION) %}

name: qmxgraph

Expand All @@ -15,6 +14,10 @@ environment:

dependencies:
- python ={{ PYTHON_VERSION }}
{% if "PYTHON_VERSION" in os.environ %}
- importlib_resources =1.3
- zipp =3.3
{% endif %}

{% if TEST_QMXGRAPH %}
- cherrypy
Expand Down
3 changes: 3 additions & 0 deletions src/qmxgraph/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class GraphOptions(object):
:ivar bool show_outline: Show outline of graph in a floating window.
:ivar bool snap_to_grid: Snap to background grid when moving vertices
in graph.
:ivar bool zoom_to_cursor: Apply zoom focused on the position of the mouse cursor
instead of on the center.
"""

allow_create_target = attr.ib(default=False, validator=_is_bool)
Expand All @@ -85,6 +87,7 @@ class GraphOptions(object):
show_highlight = attr.ib(default=True, validator=_is_bool)
show_outline = attr.ib(default=False, validator=_is_bool)
snap_to_grid = attr.ib(default=True, validator=_is_bool)
zoom_to_cursor = attr.ib(default=False, validator=_is_bool)

def as_dict(self):
return attr.asdict(self)
Expand Down
3 changes: 3 additions & 0 deletions src/qmxgraph/page/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,9 @@ graphs.Api.prototype.registerViewUpdateHandler = function registerViewUpdateHand
"use strict";
var graph = this._graphEditor.graph;
var listener = function (sender, evt) {
if (graph.getView().processingMouseWheel) {
return;
}
handler(this.dump(), this.getScaleAndTranslation());
}.bind(this);
graph.getView().addListener(mxEvent.SCALE, listener);
Expand Down
23 changes: 23 additions & 0 deletions src/qmxgraph/page/graphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ graphs.createGraph = function createGraph(container, options, styles) {
var editor = new mxEditor();
editor.setGraphContainer(container);
var graph = editor.graph;
// Used to avoid sending events for the operations that are a part of zooming in/out.
graph.view.processingMouseWheel = false;

// NOTE: grid size must usually equal the size of grid GIF
// used as background of graph's div
Expand Down Expand Up @@ -509,6 +511,16 @@ graphs.createGraph = function createGraph(container, options, styles) {

// * Adds mouse wheel handling for zoom
mxEvent.addMouseWheelListener(function (evt, up) {
// Disable snapping, to make zooming in and out smoother.
let gridEnabled = graph.gridEnabled;
graph.gridEnabled = false;

let zoomToCursor = options["zoom_to_cursor"];
let view = graph.view;
view.processingMouseWheel = zoomToCursor;

let cursorBefore = graph.getPointForEvent(evt, false);

// - `up = true` direction:
// Moves the viewport closer to the graph;
// When browsing a web page the vertical scrollbar will move up;
Expand All @@ -520,6 +532,17 @@ graphs.createGraph = function createGraph(container, options, styles) {
} else {
graph.zoomOut();
}

if (zoomToCursor) {
view.processingMouseWheel = false;
let cursorAfter = graph.getPointForEvent(evt, false);
let deltaX = cursorAfter.x - cursorBefore.x;
let deltaY = cursorAfter.y - cursorBefore.y;
view.setTranslate(view.translate.x + deltaX, view.translate.y + deltaY);
}

graph.gridEnabled = gridEnabled;

mxEvent.consume(evt);
});

Expand Down

0 comments on commit 10e8279

Please sign in to comment.