Skip to content

Commit 017ad76

Browse files
🔥 after hours of simplest geometry tasks finally fixed zooming!
1 parent 9d37e50 commit 017ad76

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

web/js/ClassView.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var ClassView = function (parent, container) {
1616

1717
this.PAPER_SCALE = 1;
1818
this.MIN_PAPER_SCALE = 0.2;
19-
this.MAX_PAPER_SCALE = 5;
19+
this.MAX_PAPER_SCALE = 4;
2020

2121
this.init();
2222

@@ -244,21 +244,23 @@ ClassView.prototype.updateSizes = function () {
244244
ClassView.prototype.zoom = function (delta) {
245245

246246
var scaleOld = this.PAPER_SCALE, scaleDelta;
247+
var sw = this.cacheUMLExplorer.elements.classViewContainer.offsetWidth,
248+
sh = this.cacheUMLExplorer.elements.classViewContainer.offsetHeight,
249+
side = delta > 0 ? 1 : -1,
250+
ox = this.paper.options.origin.x,
251+
oy = this.paper.options.origin.y;
247252
if (typeof delta === "number") {
248-
this.PAPER_SCALE += delta *Math.min(
249-
0.5,
250-
Math.abs(this.PAPER_SCALE - (delta < 0 ? this.MIN_PAPER_SCALE : this.MAX_PAPER_SCALE))/2
251-
);
252-
} else {
253-
this.PAPER_SCALE = 1;
254-
}
253+
this.PAPER_SCALE += delta * Math.min(
254+
0.3,
255+
Math.abs(this.PAPER_SCALE - (delta < 0 ? this.MIN_PAPER_SCALE : this.MAX_PAPER_SCALE))/2
256+
);
257+
} else { this.PAPER_SCALE = 1; }
255258
this.paper.scale(this.PAPER_SCALE, this.PAPER_SCALE);
256-
scaleDelta = this.PAPER_SCALE - scaleOld;
259+
scaleDelta = side *
260+
(side > 0 ? this.PAPER_SCALE / scaleOld - 1 : (scaleOld - this.PAPER_SCALE) / scaleOld);
257261
this.paper.setOrigin(
258-
this.paper.options.origin.x
259-
- scaleDelta*this.cacheUMLExplorer.elements.classViewContainer.offsetWidth/2,
260-
this.paper.options.origin.y
261-
- scaleDelta*this.cacheUMLExplorer.elements.classViewContainer.offsetHeight/2
262+
ox - (sw/2 - ox)*scaleDelta,
263+
oy - (sh/2 - oy)*scaleDelta
262264
);
263265

264266
};
@@ -282,6 +284,8 @@ ClassView.prototype.init = function () {
282284
}
283285
});
284286

287+
setTimeout(function () {self.paper.setOrigin(0,0)},100);
288+
285289
// enables links re-routing when dragging objects
286290
this.graph.on("change:position", function (object) {
287291
if (_.contains(self.objects, object))

web/jsLib/joint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24405,7 +24405,7 @@ joint.routers.manhattan = (function() {
2440524405
var config = {
2440624406

2440724407
// size of the step to find a route
24408-
step: 20,
24408+
step: 25,
2440924409

2441024410
// use of the perpendicular linkView option to connect center of element with first vertex
2441124411
perpendicular: true,

0 commit comments

Comments
 (0)