Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Apr 26, 2015
2 parents 0c0c08c + 91d2c15 commit 3689ab8
Show file tree
Hide file tree
Showing 10 changed files with 25,093 additions and 117 deletions.
14 changes: 8 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var gulp = require("gulp"),

var banner = [
"",
"/** <%= pkg.name %>",
"/*! <%= pkg.name %>",
" ** <%= pkg.description %>",
" ** @author <%= pkg.author %>",
" ** @version <%= pkg.version %>",
Expand All @@ -35,17 +35,18 @@ gulp.task("clean", function () {

gulp.task("gatherLibs", ["clean"], function () {
return gulp.src([
"web/jsLib/joint.shapes.uml.js"
"web/jsLib/joint.js",
"web/jsLib/joint.shapes.uml.js"
])
.pipe(uglify({
output: {
ascii_only: true,
width: 30000,
max_line_len: 30000
}
},
preserveComments: "some"
}))
.pipe(addsrc.prepend([
"web/jsLib/joint.min.js",
.pipe(addsrc.append([
"web/jsLib/joint.layout.DirectedGraph.min.js"
]))
.pipe(stripComments({ safe: true }))
Expand All @@ -63,7 +64,8 @@ gulp.task("gatherScripts", ["clean", "gatherLibs"], function () {
ascii_only: true,
width: 30000,
max_line_len: 30000
}
},
preserveComments: "some"
}))
.pipe(header(banner, { pkg: pkg }))
.pipe(addsrc.prepend("build/web/js/CacheUMLExplorer.js"))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"gulp-rename": "^1.2.0",
"gulp-replace": "^0.5.0",
"gulp-strip-comments": "^1.0.1",
"gulp-uglify": "^1.0.1",
"gulp-uglify": "^1.2.0",
"gulp-wrap": "^0.5.0",
"gulp-zip": "^2.0.2"
},
Expand Down
1 change: 1 addition & 0 deletions web/css/classView.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#classView {
height: 100%;
cursor: -webkit-grab; cursor: -moz-grab;
}

.uml-class-name-rect {
Expand Down
4 changes: 2 additions & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<link rel="stylesheet" href="css/joint.min.css"/>
<!-- endbuild -->
<!-- build:js -->
<script type="text/javascript" src="jsLib/joint.min.js"></script>
<script type="text/javascript" src="jsLib/joint.js"></script>
<script type="text/javascript" src="jsLib/joint.shapes.uml.js"></script>
<script type="text/javascript" src="jsLib/joint.layout.DirectedGraph.min.js"></script>
<script type="text/javascript" src="js/ClassView.js"></script>
Expand All @@ -21,7 +21,7 @@
<script type="text/javascript" src="js/Source.js"></script>
<!-- endbuild -->
</head>
<body onload="var cue = new CacheUMLExplorer(document.getElementById('treeView'), document.getElementById('classView'))">
<body onload="cue = new CacheUMLExplorer(document.getElementById('treeView'), document.getElementById('classView'))">
<div class="ui-body">
<div class="ui-sideBlock">
<div id="treeView">
Expand Down
11 changes: 10 additions & 1 deletion web/js/CacheUMLExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ var CacheUMLExplorer = function (treeViewContainer, classViewContainer) {

CacheUMLExplorer.prototype.init = function () {

var self = this;
var self = this,
hash = location.hash;

this.classTree.showLoader();
this.source.getClassTree(function (err, data) {
if (!err) self.classTree.updateTree(data);
});

if (hash) {
if (hash.indexOf("class:") === 1) {
this.classView.loadClass(hash.substr(7));
} else if (hash.indexOf("package:") === 1) {
this.classView.loadPackage(hash.substr(9));
}
}

};
4 changes: 0 additions & 4 deletions web/js/ClassTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ ClassTree.prototype.classSelected = function (element, className) {
this.cacheUMLExplorer.classView.loadClass(className);
}

this.cacheUMLExplorer.elements.className.textContent = className;

};

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

this.cacheUMLExplorer.elements.className.textContent = packageName;

};

ClassTree.prototype.updateTree = function (treeObject) {
Expand Down
140 changes: 54 additions & 86 deletions web/js/ClassView.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ClassView = function (parent, container) {

this.PAPER_SCALE = 1;
this.MIN_PAPER_SCALE = 0.2;
this.MAX_PAPER_SCALE = 5;
this.MAX_PAPER_SCALE = 4;

this.init();

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

var insertString = function (array, string) {
var insertString = function (array, string, extraString) {
string.match(/.{1,44}/g).forEach(function (p) {
array.push(p);
array.push(p + (extraString ? extraString : ""));
});
};

Expand All @@ -94,10 +94,17 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
}
return arr;
})(classParams, classProps),
methods: methArr = (function (ps) {
methods: methArr = (function (met) {
var arr = [], n;
for (n in ps) {
insertString(arr, "+ " + n + (ps[n]["returns"] ? ": " + ps[n]["returns"] : ""));
for (n in met) {
insertString(
arr,
"+ " + n + (met[n]["returns"] ? ": " + met[n]["returns"] : ""),
(met[n]["classMethod"] ?
"\x1b" + JSON.stringify({STYLES:{
textDecoration: "underline"
}}) : "")
);
}
return arr;
})(classMethods),
Expand Down Expand Up @@ -147,6 +154,22 @@ ClassView.prototype.render = function (data) {
}
}

for (p in data["aggregation"]) {
relTo = (classes[p] || {}).instance;
for (pp in data["aggregation"][p]) {
relFrom = (classes[pp] || {}).instance;
if (relFrom && relTo) {
this.graph.addCell(connector = new uml.Aggregation({
source: { id: relFrom.id },
target: { id: relTo.id },
router: { name: "manhattan" },
connector: { name: "rounded" }
}));
this.links.push(connector);
}
}
}

joint.layout.DirectedGraph.layout(this.graph, {
setLinkVertices: false,
nodeSep: 100,
Expand All @@ -155,6 +178,10 @@ ClassView.prototype.render = function (data) {

this.updateSizes();

for (var i in this.links) {
this.paper.findViewByModel(this.links[i]).update();
}

var bb = this.paper.getContentBBox(), q = this.paper;
this.paper.setOrigin(
q.options.width/2 - bb.width/2,
Expand All @@ -179,6 +206,9 @@ ClassView.prototype.loadClass = function (className) {
}
});

this.cacheUMLExplorer.elements.className.textContent = className;
location.hash = "class:" + className;

};

ClassView.prototype.loadPackage = function (packageName) {
Expand All @@ -197,6 +227,9 @@ ClassView.prototype.loadPackage = function (packageName) {
}
});

this.cacheUMLExplorer.elements.className.textContent = packageName;
location.hash = "package:" + packageName;

};

ClassView.prototype.updateSizes = function () {
Expand All @@ -211,21 +244,23 @@ ClassView.prototype.updateSizes = function () {
ClassView.prototype.zoom = function (delta) {

var scaleOld = this.PAPER_SCALE, scaleDelta;
var sw = this.cacheUMLExplorer.elements.classViewContainer.offsetWidth,
sh = this.cacheUMLExplorer.elements.classViewContainer.offsetHeight,
side = delta > 0 ? 1 : -1,
ox = this.paper.options.origin.x,
oy = this.paper.options.origin.y;
if (typeof delta === "number") {
this.PAPER_SCALE += delta *Math.min(
0.5,
Math.abs(this.PAPER_SCALE - (delta < 0 ? this.MIN_PAPER_SCALE : this.MAX_PAPER_SCALE))/2
);
} else {
this.PAPER_SCALE = 1;
}
this.PAPER_SCALE += delta * Math.min(
0.3,
Math.abs(this.PAPER_SCALE - (delta < 0 ? this.MIN_PAPER_SCALE : this.MAX_PAPER_SCALE))/2
);
} else { this.PAPER_SCALE = 1; }
this.paper.scale(this.PAPER_SCALE, this.PAPER_SCALE);
scaleDelta = this.PAPER_SCALE - scaleOld;
scaleDelta = side *
(side > 0 ? this.PAPER_SCALE / scaleOld - 1 : (scaleOld - this.PAPER_SCALE) / scaleOld);
this.paper.setOrigin(
this.paper.options.origin.x
- scaleDelta*this.cacheUMLExplorer.elements.classViewContainer.offsetWidth/2,
this.paper.options.origin.y
- scaleDelta*this.cacheUMLExplorer.elements.classViewContainer.offsetHeight/2
ox - (sw/2 - ox)*scaleDelta,
oy - (sh/2 - oy)*scaleDelta
);

};
Expand All @@ -241,7 +276,7 @@ ClassView.prototype.init = function () {
el: this.container,
width: this.container.offsetWidth,
height: this.container.offsetHeight,
gridSize: 30,
gridSize: 20,
model: this.graph,
origin: {
x: 0,
Expand Down Expand Up @@ -298,71 +333,4 @@ ClassView.prototype.init = function () {
self.zoom(null);
});

//var classes = {
//
// mammal: new uml.Interface({
// position: { x:300 , y: 50 },
// size: { width: 240, height: 100 },
// name: 'Mammal',
// attributes: ['dob: Date'],
// methods: ['+ setDateOfBirth(dob: Date): Void','+ getAgeAsDays(): Numeric']
// }),
//
// person: new uml.Abstract({
// position: { x:300 , y: 300 },
// size: { width: 240, height: 100 },
// name: 'Person',
// attributes: ['firstName: String','lastName: String'],
// methods: ['+ setName(first: String, last: String): Void','+ getName(): String']
// }),
//
// bloodgroup: new uml.Class({
// position: { x:20 , y: 190 },
// size: { width: 220, height: 100 },
// name: 'BloodGroup',
// attributes: ['bloodGroup: String'],
// methods: ['+ isCompatible(bG: String): Boolean']
// }),
//
// address: new uml.Class({
// position: { x:630 , y: 190 },
// size: { width: 160, height: 100 },
// name: 'Address',
// attributes: ['houseNumber: Integer','streetName: String','town: String','postcode: String'],
// methods: []
// }),
//
// man: new uml.Class({
// position: { x:200 , y: 500 },
// size: { width: 180, height: 50 },
// name: 'Man'
// }),
//
// woman: new uml.Class({
// position: { x:450 , y: 500 },
// size: { width: 180, height: 50 },
// name: 'Woman',
// methods: ['+ giveABrith(): Person []']
// })
//
//
//};
//
//_.each(classes, function(c) { graph.addCell(c); });
//
//var relations = [
// new uml.Generalization({
// source: { id: classes.man.id },
// target: { id: classes.person.id },
// router: { name: 'manhattan' },
// connector: { name: 'rounded' }
// }),
// new uml.Generalization({ source: { id: classes.woman.id }, target: { id: classes.person.id }}),
// new uml.Implementation({ source: { id: classes.person.id }, target: { id: classes.mammal.id }}),
// new uml.Aggregation({ source: { id: classes.person.id }, target: { id: classes.address.id }}),
// new uml.Composition({ source: { id: classes.person.id }, target: { id: classes.bloodgroup.id }})
//];
//
//_.each(relations, function(r) { graph.addCell(r); });

};
Loading

0 comments on commit 3689ab8

Please sign in to comment.