Skip to content

Commit 69a8967

Browse files
committed
fix(git-graph): 修复超多层级渲染不正确,文字超长不省略,图形超宽无滚动问题
1 parent f08a854 commit 69a8967

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

packages/devui-vue/devui/git-graph/src/git-graph-class.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ export class GitGraph {
7272
this.graphHeight = (this.element as HTMLElement).getBoundingClientRect().height;
7373
this.graphWidth = (this.element as HTMLElement).getBoundingClientRect().width;
7474

75-
// 按提交数据计算画布高度,并留出下方150,右边300空白,保证悬浮框不超出画布
75+
// 按提交数据计算画布高度,并留出下方150,右边500空白,保证悬浮框不超出画布
7676
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);
7878
this.svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
7979
this.svg.setAttribute('height', ch + '');
80-
this.svg.setAttribute('width', '100%');
80+
this.svg.setAttribute('width', cw + '');
8181
this.element?.appendChild(this.svg);
8282
this.barHeight = Math.max(this.graphHeight, this.unitTime * this.commits.length + 320);
8383

@@ -237,7 +237,7 @@ export class GitGraph {
237237
r: 4,
238238
fill: '#fff',
239239
strokeWidth: 1,
240-
stroke: this.colors[commit.space],
240+
stroke: this.colors[commit.space % 20],
241241
style: 'cursor: pointer;'
242242
};
243243
this.setNodeAttr(circle, attrs);
@@ -265,7 +265,7 @@ export class GitGraph {
265265
this.svg.appendChild(img);
266266

267267
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);
269269
}
270270
// 画竖线
271271
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 {
292292
commit.author.name = commit.author.name.substr(0, this.maxNameLength) + '...';
293293
}
294294

295-
const commitText = document.createElementNS('http://www.w3.org/2000/svg', 'text');
295+
const commitText = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
296296
const commitAttrs = {
297297
x: avatar_box_x + 40,
298-
y: y + 4,
298+
y: y - 8,
299299
'text-anchor': 'start',
300300
style: 'cursor: pointer;text-anchor: start;',
301-
fill: isdark ? '#e8e8e8' : '#2e2e2e',
302-
'font-size': 14,
301+
width: this.messageBoxWidth,
302+
height: 20,
303303
};
304304
this.setNodeAttr(commitText, commitAttrs);
305305

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+
306319
const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
307320
tspan.appendChild(document.createTextNode(commit.message.replace(/\n/g, ' ')));
308321
commitText.appendChild(tspan);
@@ -339,9 +352,9 @@ export class GitGraph {
339352
parentX1 = this.offsetX + this.unitSpace * (this.mspace - parentCommit.space);
340353
parentX2 = this.offsetX + this.unitSpace * (this.mspace - parent[1]);
341354
if (parentCommit.space <= commit.space) {
342-
color = this.colors[commit.space];
355+
color = this.colors[commit.space % 20];
343356
} else {
344-
color = this.colors[parentCommit.space];
357+
color = this.colors[parentCommit.space % 20];
345358
}
346359
if (parent[1] === commit.space) {
347360
offset = [0, 5];
@@ -438,15 +451,15 @@ export class GitGraph {
438451

439452
const rectAttrs = {
440453
fill: this.isDark ? '#4C4C4C' : '#fff',
441-
stroke: this.colors[commit.space],
454+
stroke: this.colors[commit.space % 20],
442455
'stroke-width': '1px',
443456
d: path.join(' '),
444457
transform: `matrix(1,0,0,1,-${textbox.width + 26},0)`,
445458
};
446459

447460
const newAttrs = {
448461
transform: `matrix(1,0,0,1,-${textbox.width + 26},0)`,
449-
fill: this.colors[commit.space],
462+
fill: this.colors[commit.space % 20],
450463
};
451464

452465
this.setNodeAttr(text, newAttrs);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.d-graph-wrapper {
2+
overflow-x: auto;
3+
}

packages/devui-vue/devui/git-graph/src/git-graph.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineComponent, onMounted, ref, SetupContext, nextTick } from "vue";
22
import { GitGraphProps, gitGraphProps } from "./git-graph-types";
33
import useGitGraph from "./use-git-graph";
4-
4+
import './git-graph.scss';
55

66
export default defineComponent({
77
name: 'DGitGraph',

0 commit comments

Comments
 (0)