Skip to content

Commit 89122a6

Browse files
scaling, view changes
1 parent a80a74f commit 89122a6

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

web/js/ClassView.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ var ClassView = function (parent, container) {
1414
this.links = [];
1515
this.objects = [];
1616

17+
this.PAPER_SCALE = 1;
18+
this.MIN_PAPER_SCALE = 0.2;
19+
this.MAX_PAPER_SCALE = 5;
20+
1721
this.init();
1822

1923
};
@@ -161,6 +165,27 @@ ClassView.prototype.updateSizes = function () {
161165
this.paper.setDimensions(this.container.offsetWidth, this.container.offsetHeight);
162166
};
163167

168+
/**
169+
* Scale view according to delta.
170+
*
171+
* @param {number} delta
172+
*/
173+
ClassView.prototype.zoom = function (delta) {
174+
175+
var scaleOld = this.PAPER_SCALE, scaleDelta;
176+
this.PAPER_SCALE += delta*Math.min(0.5, Math.abs(this.PAPER_SCALE - (delta < 0 ? this.MIN_PAPER_SCALE : this.MAX_PAPER_SCALE))/2);
177+
this.paper.scale(
178+
this.PAPER_SCALE,
179+
this.PAPER_SCALE
180+
);
181+
scaleDelta = this.PAPER_SCALE - scaleOld;
182+
this.paper.setOrigin(
183+
this.paper.options.origin.x - scaleDelta*this.cacheUMLExplorer.elements.classViewContainer.offsetWidth/2,
184+
this.paper.options.origin.y - scaleDelta*this.cacheUMLExplorer.elements.classViewContainer.offsetHeight/2
185+
);
186+
187+
};
188+
164189
ClassView.prototype.init = function () {
165190

166191
var p, self = this,
@@ -216,6 +241,9 @@ ClassView.prototype.init = function () {
216241

217242
this.cacheUMLExplorer.elements.classViewContainer.addEventListener("mousemove", moveHandler);
218243
this.cacheUMLExplorer.elements.classViewContainer.addEventListener("touchmove", moveHandler);
244+
this.cacheUMLExplorer.elements.classViewContainer.addEventListener("mousewheel", function (e) {
245+
self.zoom(Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail))));
246+
});
219247

220248
//var classes = {
221249
//

web/jsLib/joint.shapes.uml.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
4040
attrs: {
4141
rect: { 'width': 200 },
4242

43-
'.uml-class-name-rect': { 'stroke': 'black', 'stroke-width': 2, 'fill': '#3498db' },
44-
'.uml-class-attrs-rect': { 'stroke': 'black', 'stroke-width': 2, 'fill': '#2980b9' },
45-
'.uml-class-methods-rect': { 'stroke': 'black', 'stroke-width': 2, 'fill': '#2980b9' },
43+
'.uml-class-name-rect': { 'stroke': 'black', 'stroke-width': 1, 'fill': '#3498db' },
44+
'.uml-class-attrs-rect': { 'stroke': 'black', 'stroke-width': 1, 'fill': '#2980b9' },
45+
'.uml-class-methods-rect': { 'stroke': 'black', 'stroke-width': 1, 'fill': '#2980b9' },
4646

4747
'.uml-class-name-text': {
4848
'ref': '.uml-class-name-rect', 'ref-y': .5, 'ref-x': .5, 'text-anchor': 'middle', 'y-alignment': 'middle', 'font-weight': 'bold',

0 commit comments

Comments
 (0)