@@ -72,12 +72,12 @@ export class GitGraph {
72
72
this . graphHeight = ( this . element as HTMLElement ) . getBoundingClientRect ( ) . height ;
73
73
this . graphWidth = ( this . element as HTMLElement ) . getBoundingClientRect ( ) . width ;
74
74
75
- // 按提交数据计算画布高度,并留出下方150,右边300空白 ,保证悬浮框不超出画布
75
+ // 按提交数据计算画布高度,并留出下方150,右边500空白 ,保证悬浮框不超出画布
76
76
const ch = Math . max ( this . graphHeight , this . offsetY + this . unitTime * this . mtime + 150 ) ;
77
- const cw = Math . max ( this . graphWidth , this . offsetX + this . unitSpace * this . mspace + 300 ) ;
77
+ const cw = Math . max ( this . graphWidth , this . offsetX + this . unitSpace * this . mspace + 500 ) ;
78
78
this . svg = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'svg' ) ;
79
79
this . svg . setAttribute ( 'height' , ch + '' ) ;
80
- this . svg . setAttribute ( 'width' , '100% ') ;
80
+ this . svg . setAttribute ( 'width' , cw + ' ') ;
81
81
this . element ?. appendChild ( this . svg ) ;
82
82
this . barHeight = Math . max ( this . graphHeight , this . unitTime * this . commits . length + 320 ) ;
83
83
@@ -237,7 +237,7 @@ export class GitGraph {
237
237
r : 4 ,
238
238
fill : '#fff' ,
239
239
strokeWidth : 1 ,
240
- stroke : this . colors [ commit . space ] ,
240
+ stroke : this . colors [ commit . space % 20 ] ,
241
241
style : 'cursor: pointer;'
242
242
} ;
243
243
this . setNodeAttr ( circle , attrs ) ;
@@ -265,7 +265,7 @@ export class GitGraph {
265
265
this . svg . appendChild ( img ) ;
266
266
267
267
if ( ! this . messageBoxWidth ) {
268
- this . messageBoxWidth = this . svg . getBoundingClientRect . width - ( avatar_box_x + 40 ) ;
268
+ this . messageBoxWidth = this . svg . getBoundingClientRect ( ) . width - ( avatar_box_x + 40 ) ;
269
269
}
270
270
// 画竖线
271
271
let route = [ 'M' , avatar_box_x + 15 , avatar_box_y - 20 , 'L' , avatar_box_x + 15 , avatar_box_y ] ;
@@ -292,17 +292,30 @@ export class GitGraph {
292
292
commit . author . name = commit . author . name . substr ( 0 , this . maxNameLength ) + '...' ;
293
293
}
294
294
295
- const commitText = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'text ' ) ;
295
+ const commitText = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'foreignObject ' ) ;
296
296
const commitAttrs = {
297
297
x : avatar_box_x + 40 ,
298
- y : y + 4 ,
298
+ y : y - 8 ,
299
299
'text-anchor' : 'start' ,
300
300
style : 'cursor: pointer;text-anchor: start;' ,
301
- fill : isdark ? '#e8e8e8' : '#2e2e2e' ,
302
- 'font-size' : 14 ,
301
+ width : this . messageBoxWidth ,
302
+ height : 20 ,
303
303
} ;
304
304
this . setNodeAttr ( commitText , commitAttrs ) ;
305
305
306
+ const textArr = {
307
+ style : 'width: 100%; height: 20px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;' ,
308
+ title : commit . message ,
309
+ } ;
310
+
311
+ const text = document . createElement ( 'div' ) ;
312
+ this . setNodeAttr ( text , textArr ) ;
313
+
314
+ text . innerText = commit . message . replace ( / \n / g, ' ' ) ;
315
+ commitText . appendChild ( text ) ;
316
+
317
+ this . svg . appendChild ( commitText ) ;
318
+
306
319
const tspan = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'tspan' ) ;
307
320
tspan . appendChild ( document . createTextNode ( commit . message . replace ( / \n / g, ' ' ) ) ) ;
308
321
commitText . appendChild ( tspan ) ;
@@ -339,9 +352,9 @@ export class GitGraph {
339
352
parentX1 = this . offsetX + this . unitSpace * ( this . mspace - parentCommit . space ) ;
340
353
parentX2 = this . offsetX + this . unitSpace * ( this . mspace - parent [ 1 ] ) ;
341
354
if ( parentCommit . space <= commit . space ) {
342
- color = this . colors [ commit . space ] ;
355
+ color = this . colors [ commit . space % 20 ] ;
343
356
} else {
344
- color = this . colors [ parentCommit . space ] ;
357
+ color = this . colors [ parentCommit . space % 20 ] ;
345
358
}
346
359
if ( parent [ 1 ] === commit . space ) {
347
360
offset = [ 0 , 5 ] ;
@@ -438,15 +451,15 @@ export class GitGraph {
438
451
439
452
const rectAttrs = {
440
453
fill : this . isDark ? '#4C4C4C' : '#fff' ,
441
- stroke : this . colors [ commit . space ] ,
454
+ stroke : this . colors [ commit . space % 20 ] ,
442
455
'stroke-width' : '1px' ,
443
456
d : path . join ( ' ' ) ,
444
457
transform : `matrix(1,0,0,1,-${ textbox . width + 26 } ,0)` ,
445
458
} ;
446
459
447
460
const newAttrs = {
448
461
transform : `matrix(1,0,0,1,-${ textbox . width + 26 } ,0)` ,
449
- fill : this . colors [ commit . space ] ,
462
+ fill : this . colors [ commit . space % 20 ] ,
450
463
} ;
451
464
452
465
this . setNodeAttr ( text , newAttrs ) ;
0 commit comments