@@ -89,7 +89,7 @@ export const drawActor = function (elem, left, verticalPos, description, conf) {
89
89
drawRect ( g , rect )
90
90
91
91
_drawTextCandidateFunc ( conf ) ( description , g ,
92
- rect . x , rect . y , rect . width , rect . height , { 'class' : 'actor' } )
92
+ rect . x , rect . y , rect . width , rect . height , { 'class' : 'actor' } , conf )
93
93
}
94
94
95
95
export const anchorElement = function ( elem ) {
@@ -252,22 +252,30 @@ const _drawTextCandidateFunc = (function () {
252
252
_setTextAttrs ( text , textAttrs )
253
253
}
254
254
255
- function byTspan ( content , g , x , y , width , height , textAttrs ) {
256
- const text = g . append ( 'text' )
257
- . attr ( 'x' , x + width / 2 ) . attr ( 'y' , y )
258
- . style ( 'text-anchor' , 'middle' )
259
- text . append ( 'tspan' )
260
- . attr ( 'x' , x + width / 2 ) . attr ( 'dy' , '0' )
261
- . text ( content )
262
-
263
- text . attr ( 'y' , y + height / 2.0 )
264
- . attr ( 'dominant-baseline' , 'central' )
265
- . attr ( 'alignment-baseline' , 'central' )
266
-
267
- _setTextAttrs ( text , textAttrs )
255
+ function byTspan ( content , g , x , y , width , height , textAttrs , conf ) {
256
+ const { actorFontSize, actorFontFamily } = conf
257
+
258
+ const lines = content . split ( / < b r \/ ? > / ig)
259
+ for ( let i = 0 ; i < lines . length ; i ++ ) {
260
+ const dy = ( i * actorFontSize ) - ( actorFontSize * ( lines . length - 1 ) / 2 )
261
+ const text = g . append ( 'text' )
262
+ . attr ( 'x' , x + width / 2 ) . attr ( 'y' , y )
263
+ . style ( 'text-anchor' , 'middle' )
264
+ . style ( 'font-size' , actorFontSize )
265
+ . style ( 'font-family' , actorFontFamily )
266
+ text . append ( 'tspan' )
267
+ . attr ( 'x' , x + width / 2 ) . attr ( 'dy' , dy )
268
+ . text ( lines [ i ] )
269
+
270
+ text . attr ( 'y' , y + height / 2.0 )
271
+ . attr ( 'dominant-baseline' , 'central' )
272
+ . attr ( 'alignment-baseline' , 'central' )
273
+
274
+ _setTextAttrs ( text , textAttrs )
275
+ }
268
276
}
269
277
270
- function byFo ( content , g , x , y , width , height , textAttrs ) {
278
+ function byFo ( content , g , x , y , width , height , textAttrs , conf ) {
271
279
const s = g . append ( 'switch' )
272
280
const f = s . append ( 'foreignObject' )
273
281
. attr ( 'x' , x ) . attr ( 'y' , y )
@@ -280,7 +288,7 @@ const _drawTextCandidateFunc = (function () {
280
288
. style ( 'text-align' , 'center' ) . style ( 'vertical-align' , 'middle' )
281
289
. text ( content )
282
290
283
- byTspan ( content , s , x , y , width , height , textAttrs )
291
+ byTspan ( content , s , x , y , width , height , textAttrs , conf )
284
292
_setTextAttrs ( text , textAttrs )
285
293
}
286
294
0 commit comments