@@ -16,7 +16,7 @@ var ClassView = function (parent, container) {
16
16
17
17
this . PAPER_SCALE = 1 ;
18
18
this . MIN_PAPER_SCALE = 0.2 ;
19
- this . MAX_PAPER_SCALE = 5 ;
19
+ this . MAX_PAPER_SCALE = 4 ;
20
20
21
21
this . init ( ) ;
22
22
@@ -72,9 +72,9 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
72
72
classProps = classMetaData [ "properties" ] ,
73
73
classMethods = classMetaData [ "methods" ] ;
74
74
75
- var insertString = function ( array , string ) {
75
+ var insertString = function ( array , string , extraString ) {
76
76
string . match ( / .{ 1 , 44 } / g) . forEach ( function ( p ) {
77
- array . push ( p ) ;
77
+ array . push ( p + ( extraString ? extraString : "" ) ) ;
78
78
} ) ;
79
79
} ;
80
80
@@ -94,10 +94,17 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
94
94
}
95
95
return arr ;
96
96
} ) ( classParams , classProps ) ,
97
- methods : methArr = ( function ( ps ) {
97
+ methods : methArr = ( function ( met ) {
98
98
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
+ ) ;
101
108
}
102
109
return arr ;
103
110
} ) ( classMethods ) ,
@@ -147,6 +154,22 @@ ClassView.prototype.render = function (data) {
147
154
}
148
155
}
149
156
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
+
150
173
joint . layout . DirectedGraph . layout ( this . graph , {
151
174
setLinkVertices : false ,
152
175
nodeSep : 100 ,
@@ -155,6 +178,10 @@ ClassView.prototype.render = function (data) {
155
178
156
179
this . updateSizes ( ) ;
157
180
181
+ for ( var i in this . links ) {
182
+ this . paper . findViewByModel ( this . links [ i ] ) . update ( ) ;
183
+ }
184
+
158
185
var bb = this . paper . getContentBBox ( ) , q = this . paper ;
159
186
this . paper . setOrigin (
160
187
q . options . width / 2 - bb . width / 2 ,
@@ -179,6 +206,9 @@ ClassView.prototype.loadClass = function (className) {
179
206
}
180
207
} ) ;
181
208
209
+ this . cacheUMLExplorer . elements . className . textContent = className ;
210
+ location . hash = "class:" + className ;
211
+
182
212
} ;
183
213
184
214
ClassView . prototype . loadPackage = function ( packageName ) {
@@ -197,6 +227,9 @@ ClassView.prototype.loadPackage = function (packageName) {
197
227
}
198
228
} ) ;
199
229
230
+ this . cacheUMLExplorer . elements . className . textContent = packageName ;
231
+ location . hash = "package:" + packageName ;
232
+
200
233
} ;
201
234
202
235
ClassView . prototype . updateSizes = function ( ) {
@@ -211,21 +244,23 @@ ClassView.prototype.updateSizes = function () {
211
244
ClassView . prototype . zoom = function ( delta ) {
212
245
213
246
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 ;
214
252
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 ; }
222
258
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 ) ;
224
261
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
229
264
) ;
230
265
231
266
} ;
@@ -241,7 +276,7 @@ ClassView.prototype.init = function () {
241
276
el : this . container ,
242
277
width : this . container . offsetWidth ,
243
278
height : this . container . offsetHeight ,
244
- gridSize : 30 ,
279
+ gridSize : 20 ,
245
280
model : this . graph ,
246
281
origin : {
247
282
x : 0 ,
@@ -298,71 +333,4 @@ ClassView.prototype.init = function () {
298
333
self . zoom ( null ) ;
299
334
} ) ;
300
335
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
-
368
336
} ;
0 commit comments