@@ -27,38 +27,56 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
27
27
markup : [
28
28
'<g class="rotatable">' ,
29
29
'<g class="scalable">' ,
30
- '<rect class="uml-class-name-rect"/><rect class="uml-class-attrs-rect"/><rect class="uml-class-methods-rect"/>' ,
30
+ '<rect class="uml-class-name-rect"/><rect class="uml-class-params-rect"/><text class="uml-class-params-label">Parameters</text><rect class="uml-class- attrs-rect"/><text class="uml-class-attrs-label">Properties</text>< rect class="uml-class-methods-rect"/><text class="uml-class-methods-label">Methods</text >' ,
31
31
'</g>' ,
32
- '<text class="uml-class-name-text"/><text class="uml-class-attrs-text"/><text class="uml-class-methods-text"/>' ,
32
+ '<text class="uml-class-name-text"/><text class="uml-class-params-text"/><text class="uml-class- attrs-text"/><text class="uml-class-methods-text"/>' ,
33
33
'</g>'
34
34
] . join ( '' ) ,
35
35
36
36
defaults : joint . util . deepSupplement ( {
37
37
38
38
type : 'uml.Class' ,
39
39
40
+ size : { width : 300 , height : 300 } ,
41
+
40
42
attrs : {
41
43
rect : { 'width' : 200 } ,
42
44
43
45
'.uml-class-name-rect' : { 'stroke' : 'black' , 'stroke-width' : 1 , 'fill' : '#3498db' } ,
46
+ '.uml-class-params-rect' : { 'stroke' : 'black' , 'stroke-width' : 1 , 'fill' : 'white' } ,
44
47
'.uml-class-attrs-rect' : { 'stroke' : 'black' , 'stroke-width' : 1 , 'fill' : '#2980b9' } ,
45
48
'.uml-class-methods-rect' : { 'stroke' : 'black' , 'stroke-width' : 1 , 'fill' : '#2980b9' } ,
46
49
47
50
'.uml-class-name-text' : {
48
51
'ref' : '.uml-class-name-rect' , 'ref-y' : .5 , 'ref-x' : .5 , 'text-anchor' : 'middle' , 'y-alignment' : 'middle' , 'font-weight' : 'bold' ,
49
- 'fill' : 'black' , 'font-size' : 12 , 'font-family' : 'Times New Roman'
52
+ 'fill' : 'black' , 'font-size' : 12
53
+ } ,
54
+ '.uml-class-params-text' : {
55
+ 'ref' : '.uml-class-params-rect' , 'ref-y' : 5 , 'ref-x' : 5 ,
56
+ 'fill' : 'black' , 'font-size' : 12
50
57
} ,
51
58
'.uml-class-attrs-text' : {
52
59
'ref' : '.uml-class-attrs-rect' , 'ref-y' : 5 , 'ref-x' : 5 ,
53
- 'fill' : 'black' , 'font-size' : 12 , 'font-family' : 'Times New Roman'
60
+ 'fill' : 'black' , 'font-size' : 12
54
61
} ,
55
62
'.uml-class-methods-text' : {
56
63
'ref' : '.uml-class-methods-rect' , 'ref-y' : 5 , 'ref-x' : 5 ,
57
- 'fill' : 'black' , 'font-size' : 12 , 'font-family' : 'Times New Roman'
64
+ 'fill' : 'black' , 'font-size' : 12
65
+ } ,
66
+ '.uml-class-attrs-label' : {
67
+ ref : '.uml-class-attrs-label' , fill : "black" , 'font-size' : 10 ,
68
+ xPos : - 56
69
+ } ,
70
+ '.uml-class-methods-label' : {
71
+ ref : '.uml-class-methods-label' , fill : "black" , 'font-size' : 10
72
+ } ,
73
+ '.uml-class-params-label' : {
74
+ ref : '.uml-class-methods-label' , fill : "black" , 'font-size' : 10
58
75
}
59
76
} ,
60
77
61
78
name : [ ] ,
79
+ params : [ ] ,
62
80
attributes : [ ] ,
63
81
methods : [ ]
64
82
@@ -68,7 +86,7 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
68
86
69
87
this . on ( 'change:name change:attributes change:methods' , function ( ) {
70
88
this . updateRectangles ( ) ;
71
- this . trigger ( 'uml-update' ) ;
89
+ this . trigger ( 'uml-update' ) ;
72
90
} , this ) ;
73
91
74
92
this . updateRectangles ( ) ;
@@ -87,31 +105,55 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
87
105
88
106
var rects = [
89
107
{ type : 'name' , text : this . getClassName ( ) } ,
108
+ { type : 'params' , text : this . get ( 'params' ) } ,
90
109
{ type : 'attrs' , text : this . get ( 'attributes' ) } ,
91
110
{ type : 'methods' , text : this . get ( 'methods' ) }
92
111
] ;
93
112
94
- var offsetY = 0 ;
113
+ var offsetY = 0 ,
114
+ maxWidth = 100 ;
95
115
96
116
var dp = self . get ( "directProps" ) || { } ,
97
117
nameClickHandler = dp . nameClickHandler ;
98
118
119
+ _ . each ( rects , function ( rect ) {
120
+ ( rect . text instanceof Array ? rect . text : [ rect . text ] ) . forEach ( function ( s ) { var t = s . split ( "\x1b" ) [ 0 ] . length * 6.66 + 8 ; if ( t > maxWidth ) {
121
+ maxWidth = t ;
122
+ } } ) ;
123
+ } ) ;
124
+
125
+ this . attributes . size . width = maxWidth ; // max width assign
126
+
99
127
_ . each ( rects , function ( rect ) {
100
128
101
- var lines = _ . isArray ( rect . text ) ? rect . text : [ rect . text ] ;
102
- var rectHeight = lines . length * 20 + 20 ;
129
+ var lines = _ . isArray ( rect . text ) ? rect . text : [ rect . text ] ,
130
+ rectHeight = lines . length * 12 + ( lines . length ? 10 : 0 ) ,
131
+ rectText = attrs [ '.uml-class-' + rect . type + '-text' ] ,
132
+ rectRect = attrs [ '.uml-class-' + rect . type + '-rect' ] ,
133
+ rectLabel = attrs [ '.uml-class-' + rect . type + '-label' ] ;
103
134
104
- attrs [ '.uml-class-' + rect . type + '-text' ] . text = lines . join ( '\n' ) ;
135
+ rectText . text = lines . join ( '\n' ) ;
105
136
if ( nameClickHandler ) {
106
137
if ( rect . type === "name" ) {
107
- attrs [ '.uml-class-' + rect . type + '-text' ] . clickHandler = nameClickHandler ;
138
+ rectText . clickHandler = nameClickHandler ;
139
+ }
140
+ }
141
+ rectRect . transform = 'translate(0,' + offsetY + ')' ;
142
+ if ( rectLabel ) {
143
+ if ( lines . length ) {
144
+ rectText . paddingTop = "17px" ; rectHeight += 5 ;
145
+ rectLabel . transform = 'translate(' + ( 2 ) + ',' + ( offsetY + 9 ) + ')' ;
146
+ } else {
147
+ rectLabel . display = "none" ;
108
148
}
109
149
}
110
- attrs [ '.uml-class-' + rect . type + '-rect' ] . height = rectHeight ;
111
- attrs [ '.uml-class-' + rect . type + '-rect' ] . transform = 'translate(0,' + offsetY + ')' ;
150
+ rectRect . height = rectHeight ;
112
151
offsetY += rectHeight ;
113
152
114
153
} ) ;
154
+
155
+ this . attributes . size . height = offsetY ;
156
+ this . attributes . attrs . rect . width = maxWidth ;
115
157
}
116
158
117
159
} ) ;
@@ -135,6 +177,7 @@ joint.shapes.uml.Abstract = joint.shapes.uml.Class.extend({
135
177
type : 'uml.Abstract' ,
136
178
attrs : {
137
179
'.uml-class-name-rect' : { fill : '#e74c3c' } ,
180
+ '.uml-class-params-rect' : { fill : '#c0392b' } ,
138
181
'.uml-class-attrs-rect' : { fill : '#c0392b' } ,
139
182
'.uml-class-methods-rect' : { fill : '#c0392b' }
140
183
}
@@ -258,12 +301,10 @@ joint.shapes.uml.State = joint.shapes.basic.Generic.extend({
258
301
} ,
259
302
260
303
updateName : function ( ) {
261
-
262
304
this . attr ( '.uml-state-name/text' , this . get ( 'name' ) ) ;
263
305
} ,
264
306
265
307
updateEvents : function ( ) {
266
-
267
308
this . attr ( '.uml-state-events/text' , this . get ( 'events' ) . join ( '\n' ) ) ;
268
309
} ,
269
310
0 commit comments