@@ -94,11 +94,15 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
9494 self = this ,
9595 classSigns = this . get ( 'classSigns' ) ,
9696 SYMBOL_12_WIDTH = this . get ( 'SYMBOL_12_WIDTH' ) || 6.6 ,
97- i , blockWidth , left = 3 , top = 3 , w ;
97+ i , j , blockWidth , left = 3 , top = 3 , w , positions = [ ] , sign ;
98+
99+ var subLabelWidth = function ( sign ) { // object
100+ return sign . text . length * SYMBOL_12_WIDTH + ( sign . icon ? 13 : 0 )
101+ } ;
98102
99103 // preserve space for sub-labels
100104 w = 0 ; for ( i in classSigns ) {
101- w += classSigns [ i ] . text . length * SYMBOL_12_WIDTH + ( classSigns [ i ] . icon ? 13 : 0 ) + ( i ? 3 : 0 ) ;
105+ w += subLabelWidth ( classSigns [ i ] ) ;
102106 i = 1 ;
103107 }
104108
@@ -116,18 +120,30 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
116120
117121 if ( classSigns . length ) this . HEAD_EMPTY_LINES = 1 ;
118122
123+ // centering algorithm - first, remember position without centering
124+ j = 0 ;
119125 for ( i in classSigns ) {
120126 w = classSigns [ i ] . text . length * SYMBOL_12_WIDTH + ( classSigns [ i ] . icon ? 13 : 0 ) ;
121- if ( left + w - 3 > blockWidth ) { top += 12 ; left = 3 ; this . HEAD_EMPTY_LINES ++ ; }
122- this . markup += '<g transform="translate(' + left + ', ' + top + ')">' +
123- ( classSigns [ i ] . icon ? '<image xlink:href="' + classSigns [ i ] . icon +
124- '" width="13" height="13"/>' : '' ) + '<text fill="black" font-size="11" ' +
125- ( classSigns [ i ] . textStyle ? 'style="' + classSigns [ i ] . textStyle + '"' : '' ) +
126- ' x="' + ( classSigns [ i ] . icon ? 13 : 0 ) + '" y="10">' + classSigns [ i ] . text +
127- '</text></g>' ;
127+ if ( left + w - 3 > blockWidth ) { top += 12 ; left = 3 ; this . HEAD_EMPTY_LINES ++ ; j ++ ; }
128+ if ( ! positions [ j ] ) positions [ j ] = [ ] ;
129+ positions [ j ] . push ( { top : top , left : left , o : classSigns [ i ] } ) ;
128130 left += w + 3 ;
129131 }
130132
133+ // then draw on position with computed seek by X to center content
134+ for ( i = 0 ; i < positions . length ; i ++ ) { // repeat positions and draw signs
135+ w = ( blockWidth - ( sign = positions [ i ] [ positions [ i ] . length - 1 ] ) . left - subLabelWidth ( sign . o ) ) / 2 ;
136+ for ( j = 0 ; j < positions [ i ] . length ; j ++ ) {
137+ sign = positions [ i ] [ j ] ;
138+ this . markup += '<g transform="translate(' + ( sign . left + w ) + ', ' + sign . top + ')">' +
139+ ( sign . o . icon ? '<image xlink:href="' + sign . o . icon +
140+ '" width="13" height="13"/>' : '' ) + '<text fill="black" font-size="11" ' +
141+ ( sign . o . textStyle ? 'style="' + sign . o . textStyle + '"' : '' ) +
142+ ' x="' + ( sign . o . icon ? 13 : 0 ) + '" y="10">' + sign . o . text +
143+ '</text></g>' ;
144+ }
145+ }
146+
131147 this . on ( 'change:name change:attributes change:methods' , function ( ) {
132148 this . updateRectangles ( ) ;
133149 this . trigger ( 'uml-update' ) ;
0 commit comments