Skip to content

Commit

Permalink
allow a mutated params on translate/zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Jun 21, 2018
1 parent f151803 commit 81379a2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rete",
"version": "1.0.0-alpha.2",
"version": "1.0.0-alpha.3",
"description": "JavaScript framework",
"main": "build/rete.js",
"types": "src/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class EditorEvents extends Events {
keydown: [],
keyup: [],
translate: [],
translated: [],
zoom: [],
zoomed: [],
click: [],
mousemove: [],
contextmenu: [],
Expand Down
18 changes: 12 additions & 6 deletions src/view/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,28 @@ export class Area extends Emitter {
}

translate(x, y) {
if (!this.trigger('translate', { transform: this.transform, x, y })) return;
const params = { transform: this.transform, x, y };

this.transform.x = x;
this.transform.y = y;
if (!this.trigger('translate', params)) return;

this.transform.x = params.x;
this.transform.y = params.y;

this.update();
this.trigger('translated');
}

zoom(zoom, ox = 0, oy = 0) {
if (!this.trigger('zoom', { transform: this.transform, zoom })) return;
const params = { transform: this.transform, zoom };

if (!this.trigger('zoom', params)) return;

this.transform.k = zoom;
this.transform.k = params.zoom;
this.transform.x += ox;
this.transform.y += oy;

this.update();
this.trigger('zoomed');
}

appendChild(el) {
Expand Down

0 comments on commit 81379a2

Please sign in to comment.