ran preetier

This commit is contained in:
Sibin Thomas
2023-07-19 21:55:24 +05:30
parent 52a4f8f077
commit cba5b5a7e3

View File

@@ -253,28 +253,17 @@ const drawCommits = (svg, commits, modifyGraph) => {
.attr('height', bbox.height + 2 * py); .attr('height', bbox.height + 2 * py);
if (dir === 'TB') { if (dir === 'TB') {
labelBkg labelBkg.attr('x', x - (bbox.width + 4 * px + 5)).attr('y', y - 12);
.attr('x', x - (bbox.width + 4 * px + 5)) text.attr('x', x - (bbox.width + 4 * px)).attr('y', y + bbox.height - 12);
.attr('y', y - 12);
text
.attr('x', x - (bbox.width + 4 * px))
.attr('y', y + bbox.height - 12);
} }
if (dir !== 'TB') { if (dir !== 'TB') {
text.attr('x', pos + 10 - bbox.width / 2); text.attr('x', pos + 10 - bbox.width / 2);
} }
if (gitGraphConfig.rotateCommitLabel) { if (gitGraphConfig.rotateCommitLabel) {
if (dir === 'TB') if (dir === 'TB') {
{ text.attr('transform', 'rotate(' + -45 + ', ' + x + ', ' + y + ')');
text.attr( labelBkg.attr('transform', 'rotate(' + -45 + ', ' + x + ', ' + y + ')');
'transform',
'rotate(' + -45 + ', ' + x + ', ' + y + ')'
);
labelBkg.attr(
'transform',
'rotate(' + -45 + ', ' + x + ', ' + y + ')'
);
} else { } else {
let r_x = -7.5 - ((bbox.width + 10) / 25) * 9.5; let r_x = -7.5 - ((bbox.width + 10) / 25) * 9.5;
let r_y = 10 + (bbox.width / 25) * 8.5; let r_y = 10 + (bbox.width / 25) * 8.5;
@@ -316,8 +305,7 @@ const drawCommits = (svg, commits, modifyGraph) => {
.attr('r', 1.5) .attr('r', 1.5)
.attr('class', 'tag-hole'); .attr('class', 'tag-hole');
if (dir === 'TB') if (dir === 'TB') {
{
rect rect
.attr('class', 'tag-label-bkg') .attr('class', 'tag-label-bkg')
.attr( .attr(
@@ -429,19 +417,19 @@ const drawArrow = (svg, commit1, commit2, allCommits) => {
if (dir === 'TB') { if (dir === 'TB') {
if (p1.x < p2.x) { if (p1.x < p2.x) {
lineDef = `M ${p1.x} ${p1.y} L ${lineX - radius} ${p1.y} ${arc2} ${lineX} ${p1.y + offset} L ${ lineDef = `M ${p1.x} ${p1.y} L ${lineX - radius} ${p1.y} ${arc2} ${lineX} ${
lineX p1.y + offset
} ${p2.y - radius} ${arc} ${lineX + offset} ${p2.y} L ${p2.x} ${p2.y}`; } L ${lineX} ${p2.y - radius} ${arc} ${lineX + offset} ${p2.y} L ${p2.x} ${p2.y}`;
} else { } else {
lineDef = `M ${p1.x} ${p1.y} L ${lineX + radius} ${p1.y} ${arc} ${ lineDef = `M ${p1.x} ${p1.y} L ${lineX + radius} ${p1.y} ${arc} ${lineX} ${
lineX p1.y + offset
} ${p1.y + offset} L ${lineX} ${p2.y - radius} ${arc2} ${lineX - offset} ${p2.y} L ${p2.x} ${p2.y}`; } L ${lineX} ${p2.y - radius} ${arc2} ${lineX - offset} ${p2.y} L ${p2.x} ${p2.y}`;
} }
} else { } else {
if (p1.y < p2.y) { if (p1.y < p2.y) {
lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${lineY - radius} ${arc} ${p1.x + offset} ${lineY} L ${ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${lineY - radius} ${arc} ${
p2.x - radius p1.x + offset
} ${lineY} ${arc2} ${p2.x} ${lineY + offset} L ${p2.x} ${p2.y}`; } ${lineY} L ${p2.x - radius} ${lineY} ${arc2} ${p2.x} ${lineY + offset} L ${p2.x} ${p2.y}`;
} else { } else {
lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${lineY + radius} ${arc2} ${ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${lineY + radius} ${arc2} ${
p1.x + offset p1.x + offset
@@ -449,8 +437,7 @@ const drawArrow = (svg, commit1, commit2, allCommits) => {
} }
} }
} else { } else {
if (dir === 'TB') if (dir === 'TB') {
{
if (p1.x < p2.x) { if (p1.x < p2.x) {
arc = 'A 20 20, 0, 0, 0,'; arc = 'A 20 20, 0, 0, 0,';
arc2 = 'A 20 20, 0, 0, 1,'; arc2 = 'A 20 20, 0, 0, 1,';
@@ -460,9 +447,9 @@ const drawArrow = (svg, commit1, commit2, allCommits) => {
// Figure out the color of the arrow,arrows going down take the color from the destination branch // Figure out the color of the arrow,arrows going down take the color from the destination branch
colorClassNum = branchPos[commit2.branch].index; colorClassNum = branchPos[commit2.branch].index;
lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${p1.y + offset} L ${ lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${
p2.x p1.y + offset
} ${p2.y}`; } L ${p2.x} ${p2.y}`;
} }
if (p1.x > p2.x) { if (p1.x > p2.x) {
arc = 'A 20 20, 0, 0, 0,'; arc = 'A 20 20, 0, 0, 0,';
@@ -472,16 +459,16 @@ const drawArrow = (svg, commit1, commit2, allCommits) => {
// Arrows going up take the color from the source branch // Arrows going up take the color from the source branch
colorClassNum = branchPos[commit1.branch].index; colorClassNum = branchPos[commit1.branch].index;
lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y-radius} ${arc2} ${p1.x-offset} ${p2.y} L ${ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc2} ${p1.x - offset} ${
p2.x p2.y
} ${p2.y}`; } L ${p2.x} ${p2.y}`;
} }
if (p1.x === p2.x) { if (p1.x === p2.x) {
colorClassNum = branchPos[commit1.branch].index; colorClassNum = branchPos[commit1.branch].index;
lineDef = `M ${p1.x} ${p1.y} L ${p1.x + radius} ${p1.y} ${arc} ${p1.x + offset} ${p2.y + radius} L ${ lineDef = `M ${p1.x} ${p1.y} L ${p1.x + radius} ${p1.y} ${arc} ${p1.x + offset} ${
p2.x p2.y + radius
} ${p2.y}`; } L ${p2.x} ${p2.y}`;
} }
} else { } else {
if (p1.y < p2.y) { if (p1.y < p2.y) {
@@ -592,18 +579,8 @@ const drawBranches = (svg, branches) => {
')' ')'
); );
if (dir === 'TB') { if (dir === 'TB') {
bkg bkg.attr('x', pos - bbox.width / 2 - 10).attr('y', 0);
.attr('x', pos - bbox.width/2 - 10) label.attr('transform', 'translate(' + (pos - bbox.width / 2 - 5) + ', ' + 0 + ')');
.attr('y', 0);
label
.attr(
'transform',
'translate(' +
(pos - bbox.width/2 - 5) +
', ' +
(0) +
')'
);
} }
if (dir !== 'TB') { if (dir !== 'TB') {
bkg.attr('transform', 'translate(' + -19 + ', ' + (pos - bbox.height / 2) + ')'); bkg.attr('transform', 'translate(' + -19 + ', ' + (pos - bbox.height / 2) + ')');
@@ -639,14 +616,12 @@ export const draw = function (txt, id, ver, diagObj) {
let bbox = labelElement.getBBox(); let bbox = labelElement.getBBox();
branchPos[branch.name] = { pos, index }; branchPos[branch.name] = { pos, index };
pos += 50 + (gitGraphConfig.rotateCommitLabel ? 40 : 0) + ((dir === 'TB') ? bbox.width/2 : 0); pos += 50 + (gitGraphConfig.rotateCommitLabel ? 40 : 0) + (dir === 'TB' ? bbox.width / 2 : 0);
label.remove(); label.remove();
branchLabel.remove(); branchLabel.remove();
g.remove(); g.remove();
}); });
drawCommits(diagram, allCommitsDict, false); drawCommits(diagram, allCommitsDict, false);
if (gitGraphConfig.showBranches) { if (gitGraphConfig.showBranches) {
drawBranches(diagram, branches); drawBranches(diagram, branches);