Skip to content

Commit 10e8279

Browse files
Cauê Baasch de Souzaprusse-martin
authored andcommitted
WIP
1 parent ecdf163 commit 10e8279

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
CONDA_PY: ["36", "37", "38", "39"]
19+
include:
20+
- CONDA_PY: "36"
21+
PYTHON_VERSION: "=3.6"
22+
- CONDA_PY: "37"
23+
PYTHON_VERSION: "=3.7"
24+
- CONDA_PY: "38"
25+
PYTHON_VERSION: "=3.8"
26+
- CONDA_PY: "39"
27+
PYTHON_VERSION: "=3.9"
28+
1929

2030
steps:
2131
- uses: actions/checkout@v2
@@ -33,13 +43,18 @@ jobs:
3343
- name: Install
3444
env:
3545
CONDA_PY: ${{ matrix.CONDA_PY }}
46+
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
3647
run: |
3748
conda config --system --set always_yes yes --set changeps1 no
3849
conda install -c conda-forge conda-devenv
3950
conda info -a
4051
export TEST_QMXGRAPH=1
52+
echo "=== conda devenv -n qmxgraph --print-full ==="
53+
conda devenv -n qmxgraph --print-full
54+
echo "=== === ==="
4155
conda devenv -n qmxgraph
4256
conda install -n qmxgraph coveralls pytest-cov
57+
conda list -n qmxgraph
4358
conda init bash
4459
- name: Tests
4560
shell: bash -l {0}

environment.devenv.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{% set TEST_QMXGRAPH = os.environ.get('TEST_QMXGRAPH', '0') != '0' %}
22
{% set PYTHON_VERSION = os.environ.get('PYTHON_VERSION', '3.6') %}
3-
{% set PYTHON_VERSION = os.environ.get('TRAVIS_PYTHON_VERSION', PYTHON_VERSION) %}
43

54
name: qmxgraph
65

@@ -15,6 +14,10 @@ environment:
1514

1615
dependencies:
1716
- python ={{ PYTHON_VERSION }}
17+
{% if "PYTHON_VERSION" in os.environ %}
18+
- importlib_resources =1.3
19+
- zipp =3.3
20+
{% endif %}
1821

1922
{% if TEST_QMXGRAPH %}
2023
- cherrypy

src/qmxgraph/configuration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class GraphOptions(object):
6161
:ivar bool show_outline: Show outline of graph in a floating window.
6262
:ivar bool snap_to_grid: Snap to background grid when moving vertices
6363
in graph.
64+
:ivar bool zoom_to_cursor: Apply zoom focused on the position of the mouse cursor
65+
instead of on the center.
6466
"""
6567

6668
allow_create_target = attr.ib(default=False, validator=_is_bool)
@@ -85,6 +87,7 @@ class GraphOptions(object):
8587
show_highlight = attr.ib(default=True, validator=_is_bool)
8688
show_outline = attr.ib(default=False, validator=_is_bool)
8789
snap_to_grid = attr.ib(default=True, validator=_is_bool)
90+
zoom_to_cursor = attr.ib(default=False, validator=_is_bool)
8891

8992
def as_dict(self):
9093
return attr.asdict(self)

src/qmxgraph/page/api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,9 @@ graphs.Api.prototype.registerViewUpdateHandler = function registerViewUpdateHand
12411241
"use strict";
12421242
var graph = this._graphEditor.graph;
12431243
var listener = function (sender, evt) {
1244+
if (graph.getView().processingMouseWheel) {
1245+
return;
1246+
}
12441247
handler(this.dump(), this.getScaleAndTranslation());
12451248
}.bind(this);
12461249
graph.getView().addListener(mxEvent.SCALE, listener);

src/qmxgraph/page/graphs.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ graphs.createGraph = function createGraph(container, options, styles) {
4343
var editor = new mxEditor();
4444
editor.setGraphContainer(container);
4545
var graph = editor.graph;
46+
// Used to avoid sending events for the operations that are a part of zooming in/out.
47+
graph.view.processingMouseWheel = false;
4648

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

510512
// * Adds mouse wheel handling for zoom
511513
mxEvent.addMouseWheelListener(function (evt, up) {
514+
// Disable snapping, to make zooming in and out smoother.
515+
let gridEnabled = graph.gridEnabled;
516+
graph.gridEnabled = false;
517+
518+
let zoomToCursor = options["zoom_to_cursor"];
519+
let view = graph.view;
520+
view.processingMouseWheel = zoomToCursor;
521+
522+
let cursorBefore = graph.getPointForEvent(evt, false);
523+
512524
// - `up = true` direction:
513525
// Moves the viewport closer to the graph;
514526
// When browsing a web page the vertical scrollbar will move up;
@@ -520,6 +532,17 @@ graphs.createGraph = function createGraph(container, options, styles) {
520532
} else {
521533
graph.zoomOut();
522534
}
535+
536+
if (zoomToCursor) {
537+
view.processingMouseWheel = false;
538+
let cursorAfter = graph.getPointForEvent(evt, false);
539+
let deltaX = cursorAfter.x - cursorBefore.x;
540+
let deltaY = cursorAfter.y - cursorBefore.y;
541+
view.setTranslate(view.translate.x + deltaX, view.translate.y + deltaY);
542+
}
543+
544+
graph.gridEnabled = gridEnabled;
545+
523546
mxEvent.consume(evt);
524547
});
525548

0 commit comments

Comments
 (0)