Skip to content

Commit 3689ab8

Browse files
Merge remote-tracking branch 'upstream/master'
2 parents 0c0c08c + 91d2c15 commit 3689ab8

File tree

10 files changed

+25093
-117
lines changed

10 files changed

+25093
-117
lines changed

gulpfile.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var gulp = require("gulp"),
1818

1919
var banner = [
2020
"",
21-
"/** <%= pkg.name %>",
21+
"/*! <%= pkg.name %>",
2222
" ** <%= pkg.description %>",
2323
" ** @author <%= pkg.author %>",
2424
" ** @version <%= pkg.version %>",
@@ -35,17 +35,18 @@ gulp.task("clean", function () {
3535

3636
gulp.task("gatherLibs", ["clean"], function () {
3737
return gulp.src([
38-
"web/jsLib/joint.shapes.uml.js"
38+
"web/jsLib/joint.js",
39+
"web/jsLib/joint.shapes.uml.js"
3940
])
4041
.pipe(uglify({
4142
output: {
4243
ascii_only: true,
4344
width: 30000,
4445
max_line_len: 30000
45-
}
46+
},
47+
preserveComments: "some"
4648
}))
47-
.pipe(addsrc.prepend([
48-
"web/jsLib/joint.min.js",
49+
.pipe(addsrc.append([
4950
"web/jsLib/joint.layout.DirectedGraph.min.js"
5051
]))
5152
.pipe(stripComments({ safe: true }))
@@ -63,7 +64,8 @@ gulp.task("gatherScripts", ["clean", "gatherLibs"], function () {
6364
ascii_only: true,
6465
width: 30000,
6566
max_line_len: 30000
66-
}
67+
},
68+
preserveComments: "some"
6769
}))
6870
.pipe(header(banner, { pkg: pkg }))
6971
.pipe(addsrc.prepend("build/web/js/CacheUMLExplorer.js"))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"gulp-rename": "^1.2.0",
2121
"gulp-replace": "^0.5.0",
2222
"gulp-strip-comments": "^1.0.1",
23-
"gulp-uglify": "^1.0.1",
23+
"gulp-uglify": "^1.2.0",
2424
"gulp-wrap": "^0.5.0",
2525
"gulp-zip": "^2.0.2"
2626
},

web/css/classView.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#classView {
22
height: 100%;
3+
cursor: -webkit-grab; cursor: -moz-grab;
34
}
45

56
.uml-class-name-rect {

web/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<link rel="stylesheet" href="css/joint.min.css"/>
1212
<!-- endbuild -->
1313
<!-- build:js -->
14-
<script type="text/javascript" src="jsLib/joint.min.js"></script>
14+
<script type="text/javascript" src="jsLib/joint.js"></script>
1515
<script type="text/javascript" src="jsLib/joint.shapes.uml.js"></script>
1616
<script type="text/javascript" src="jsLib/joint.layout.DirectedGraph.min.js"></script>
1717
<script type="text/javascript" src="js/ClassView.js"></script>
@@ -21,7 +21,7 @@
2121
<script type="text/javascript" src="js/Source.js"></script>
2222
<!-- endbuild -->
2323
</head>
24-
<body onload="var cue = new CacheUMLExplorer(document.getElementById('treeView'), document.getElementById('classView'))">
24+
<body onload="cue = new CacheUMLExplorer(document.getElementById('treeView'), document.getElementById('classView'))">
2525
<div class="ui-body">
2626
<div class="ui-sideBlock">
2727
<div id="treeView">

web/js/CacheUMLExplorer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ var CacheUMLExplorer = function (treeViewContainer, classViewContainer) {
2727

2828
CacheUMLExplorer.prototype.init = function () {
2929

30-
var self = this;
30+
var self = this,
31+
hash = location.hash;
3132

3233
this.classTree.showLoader();
3334
this.source.getClassTree(function (err, data) {
3435
if (!err) self.classTree.updateTree(data);
3536
});
3637

38+
if (hash) {
39+
if (hash.indexOf("class:") === 1) {
40+
this.classView.loadClass(hash.substr(7));
41+
} else if (hash.indexOf("package:") === 1) {
42+
this.classView.loadPackage(hash.substr(9));
43+
}
44+
}
45+
3746
};

web/js/ClassTree.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ ClassTree.prototype.classSelected = function (element, className) {
4646
this.cacheUMLExplorer.classView.loadClass(className);
4747
}
4848

49-
this.cacheUMLExplorer.elements.className.textContent = className;
50-
5149
};
5250

5351
ClassTree.prototype.packageSelected = function (element, packageName) {
@@ -62,8 +60,6 @@ ClassTree.prototype.packageSelected = function (element, packageName) {
6260
this.cacheUMLExplorer.classView.loadPackage(packageName);
6361
}
6462

65-
this.cacheUMLExplorer.elements.className.textContent = packageName;
66-
6763
};
6864

6965
ClassTree.prototype.updateTree = function (treeObject) {

web/js/ClassView.js

Lines changed: 54 additions & 86 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

@@ -72,9 +72,9 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
7272
classProps = classMetaData["properties"],
7373
classMethods = classMetaData["methods"];
7474

75-
var insertString = function (array, string) {
75+
var insertString = function (array, string, extraString) {
7676
string.match(/.{1,44}/g).forEach(function (p) {
77-
array.push(p);
77+
array.push(p + (extraString ? extraString : ""));
7878
});
7979
};
8080

@@ -94,10 +94,17 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
9494
}
9595
return arr;
9696
})(classParams, classProps),
97-
methods: methArr = (function (ps) {
97+
methods: methArr = (function (met) {
9898
var arr = [], n;
99-
for (n in ps) {
100-
insertString(arr, "+ " + n + (ps[n]["returns"] ? ": " + ps[n]["returns"] : ""));
99+
for (n in met) {
100+
insertString(
101+
arr,
102+
"+ " + n + (met[n]["returns"] ? ": " + met[n]["returns"] : ""),
103+
(met[n]["classMethod"] ?
104+
"\x1b" + JSON.stringify({STYLES:{
105+
textDecoration: "underline"
106+
}}) : "")
107+
);
101108
}
102109
return arr;
103110
})(classMethods),
@@ -147,6 +154,22 @@ ClassView.prototype.render = function (data) {
147154
}
148155
}
149156

157+
for (p in data["aggregation"]) {
158+
relTo = (classes[p] || {}).instance;
159+
for (pp in data["aggregation"][p]) {
160+
relFrom = (classes[pp] || {}).instance;
161+
if (relFrom && relTo) {
162+
this.graph.addCell(connector = new uml.Aggregation({
163+
source: { id: relFrom.id },
164+
target: { id: relTo.id },
165+
router: { name: "manhattan" },
166+
connector: { name: "rounded" }
167+
}));
168+
this.links.push(connector);
169+
}
170+
}
171+
}
172+
150173
joint.layout.DirectedGraph.layout(this.graph, {
151174
setLinkVertices: false,
152175
nodeSep: 100,
@@ -155,6 +178,10 @@ ClassView.prototype.render = function (data) {
155178

156179
this.updateSizes();
157180

181+
for (var i in this.links) {
182+
this.paper.findViewByModel(this.links[i]).update();
183+
}
184+
158185
var bb = this.paper.getContentBBox(), q = this.paper;
159186
this.paper.setOrigin(
160187
q.options.width/2 - bb.width/2,
@@ -179,6 +206,9 @@ ClassView.prototype.loadClass = function (className) {
179206
}
180207
});
181208

209+
this.cacheUMLExplorer.elements.className.textContent = className;
210+
location.hash = "class:" + className;
211+
182212
};
183213

184214
ClassView.prototype.loadPackage = function (packageName) {
@@ -197,6 +227,9 @@ ClassView.prototype.loadPackage = function (packageName) {
197227
}
198228
});
199229

230+
this.cacheUMLExplorer.elements.className.textContent = packageName;
231+
location.hash = "package:" + packageName;
232+
200233
};
201234

202235
ClassView.prototype.updateSizes = function () {
@@ -211,21 +244,23 @@ ClassView.prototype.updateSizes = function () {
211244
ClassView.prototype.zoom = function (delta) {
212245

213246
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;
214252
if (typeof delta === "number") {
215-
this.PAPER_SCALE += delta *Math.min(
216-
0.5,
217-
Math.abs(this.PAPER_SCALE - (delta < 0 ? this.MIN_PAPER_SCALE : this.MAX_PAPER_SCALE))/2
218-
);
219-
} else {
220-
this.PAPER_SCALE = 1;
221-
}
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; }
222258
this.paper.scale(this.PAPER_SCALE, this.PAPER_SCALE);
223-
scaleDelta = this.PAPER_SCALE - scaleOld;
259+
scaleDelta = side *
260+
(side > 0 ? this.PAPER_SCALE / scaleOld - 1 : (scaleOld - this.PAPER_SCALE) / scaleOld);
224261
this.paper.setOrigin(
225-
this.paper.options.origin.x
226-
- scaleDelta*this.cacheUMLExplorer.elements.classViewContainer.offsetWidth/2,
227-
this.paper.options.origin.y
228-
- scaleDelta*this.cacheUMLExplorer.elements.classViewContainer.offsetHeight/2
262+
ox - (sw/2 - ox)*scaleDelta,
263+
oy - (sh/2 - oy)*scaleDelta
229264
);
230265

231266
};
@@ -241,7 +276,7 @@ ClassView.prototype.init = function () {
241276
el: this.container,
242277
width: this.container.offsetWidth,
243278
height: this.container.offsetHeight,
244-
gridSize: 30,
279+
gridSize: 20,
245280
model: this.graph,
246281
origin: {
247282
x: 0,
@@ -298,71 +333,4 @@ ClassView.prototype.init = function () {
298333
self.zoom(null);
299334
});
300335

301-
//var classes = {
302-
//
303-
// mammal: new uml.Interface({
304-
// position: { x:300 , y: 50 },
305-
// size: { width: 240, height: 100 },
306-
// name: 'Mammal',
307-
// attributes: ['dob: Date'],
308-
// methods: ['+ setDateOfBirth(dob: Date): Void','+ getAgeAsDays(): Numeric']
309-
// }),
310-
//
311-
// person: new uml.Abstract({
312-
// position: { x:300 , y: 300 },
313-
// size: { width: 240, height: 100 },
314-
// name: 'Person',
315-
// attributes: ['firstName: String','lastName: String'],
316-
// methods: ['+ setName(first: String, last: String): Void','+ getName(): String']
317-
// }),
318-
//
319-
// bloodgroup: new uml.Class({
320-
// position: { x:20 , y: 190 },
321-
// size: { width: 220, height: 100 },
322-
// name: 'BloodGroup',
323-
// attributes: ['bloodGroup: String'],
324-
// methods: ['+ isCompatible(bG: String): Boolean']
325-
// }),
326-
//
327-
// address: new uml.Class({
328-
// position: { x:630 , y: 190 },
329-
// size: { width: 160, height: 100 },
330-
// name: 'Address',
331-
// attributes: ['houseNumber: Integer','streetName: String','town: String','postcode: String'],
332-
// methods: []
333-
// }),
334-
//
335-
// man: new uml.Class({
336-
// position: { x:200 , y: 500 },
337-
// size: { width: 180, height: 50 },
338-
// name: 'Man'
339-
// }),
340-
//
341-
// woman: new uml.Class({
342-
// position: { x:450 , y: 500 },
343-
// size: { width: 180, height: 50 },
344-
// name: 'Woman',
345-
// methods: ['+ giveABrith(): Person []']
346-
// })
347-
//
348-
//
349-
//};
350-
//
351-
//_.each(classes, function(c) { graph.addCell(c); });
352-
//
353-
//var relations = [
354-
// new uml.Generalization({
355-
// source: { id: classes.man.id },
356-
// target: { id: classes.person.id },
357-
// router: { name: 'manhattan' },
358-
// connector: { name: 'rounded' }
359-
// }),
360-
// new uml.Generalization({ source: { id: classes.woman.id }, target: { id: classes.person.id }}),
361-
// new uml.Implementation({ source: { id: classes.person.id }, target: { id: classes.mammal.id }}),
362-
// new uml.Aggregation({ source: { id: classes.person.id }, target: { id: classes.address.id }}),
363-
// new uml.Composition({ source: { id: classes.person.id }, target: { id: classes.bloodgroup.id }})
364-
//];
365-
//
366-
//_.each(relations, function(r) { graph.addCell(r); });
367-
368336
};

0 commit comments

Comments
 (0)