Lint fixes

This commit is contained in:
Knut Sveidqvist
2022-03-10 19:58:56 +01:00
parent 2b3f99d0e9
commit 781b239d0d
2 changed files with 69 additions and 36 deletions

View File

@@ -22,14 +22,15 @@ let config = {
width: 75,
height: 100,
x: -25,
y: 0
}
y: 0,
},
};
let apiConfig = {};
export const setConf = function(c) {
export const setConf = function (c) {
apiConfig = c;
};
/** @param svg */
function svgCreateDefs(svg) {
svg
.append('defs')
@@ -52,14 +53,20 @@ function svgCreateDefs(svg) {
.html('');
}
/**
* @param svg
* @param points
* @param colorIdx
* @param interpolate
*/
function svgDrawLine(svg, points, colorIdx, interpolate) {
const curve = interpolateToCurve(interpolate, curveBasis);
const color = config.branchColors[colorIdx % config.branchColors.length];
const lineGen = line()
.x(function(d) {
.x(function (d) {
return Math.round(d.x);
})
.y(function(d) {
.y(function (d) {
return Math.round(d.y);
})
.curve(curve);
@@ -73,6 +80,10 @@ function svgDrawLine(svg, points, colorIdx, interpolate) {
}
// Pass in the element and its pre-transform coords
/**
* @param element
* @param coords
*/
function getElementCoords(element, coords) {
coords = coords || element.node().getBBox();
const ctm = element.node().getCTM();
@@ -82,10 +93,17 @@ function getElementCoords(element, coords) {
left: xn,
top: yn,
width: coords.width,
height: coords.height
height: coords.height,
};
}
/**
* @param svg
* @param fromId
* @param toId
* @param direction
* @param color
*/
function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
logger.debug('svgDrawLineForCommits: ', fromId, toId);
const fromBbox = getElementCoords(svg.select('#node-' + fromId + ' circle'));
@@ -98,7 +116,7 @@ function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
if (fromBbox.left - toBbox.left > config.nodeSpacing) {
const lineStart = {
x: fromBbox.left - config.nodeSpacing,
y: toBbox.top + toBbox.height / 2
y: toBbox.top + toBbox.height / 2,
};
const lineEnd = { x: toBbox.left + toBbox.width, y: toBbox.top + toBbox.height / 2 };
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear');
@@ -108,7 +126,7 @@ function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
{ x: fromBbox.left, y: fromBbox.top + fromBbox.height / 2 },
{ x: fromBbox.left - config.nodeSpacing / 2, y: fromBbox.top + fromBbox.height / 2 },
{ x: fromBbox.left - config.nodeSpacing / 2, y: lineStart.y },
lineStart
lineStart,
],
color
);
@@ -118,20 +136,20 @@ function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
[
{
x: fromBbox.left,
y: fromBbox.top + fromBbox.height / 2
y: fromBbox.top + fromBbox.height / 2,
},
{
x: fromBbox.left - config.nodeSpacing / 2,
y: fromBbox.top + fromBbox.height / 2
y: fromBbox.top + fromBbox.height / 2,
},
{
x: fromBbox.left - config.nodeSpacing / 2,
y: toBbox.top + toBbox.height / 2
y: toBbox.top + toBbox.height / 2,
},
{
x: toBbox.left + toBbox.width,
y: toBbox.top + toBbox.height / 2
}
y: toBbox.top + toBbox.height / 2,
},
],
color
);
@@ -145,7 +163,7 @@ function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
if (toBbox.top - fromBbox.top > config.nodeSpacing) {
const lineStart = {
x: toBbox.left + toBbox.width / 2,
y: fromBbox.top + fromBbox.height + config.nodeSpacing
y: fromBbox.top + fromBbox.height + config.nodeSpacing,
};
const lineEnd = { x: toBbox.left + toBbox.width / 2, y: toBbox.top };
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear');
@@ -155,10 +173,10 @@ function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
{ x: fromBbox.left + fromBbox.width / 2, y: fromBbox.top + fromBbox.height },
{
x: fromBbox.left + fromBbox.width / 2,
y: fromBbox.top + fromBbox.height + config.nodeSpacing / 2
y: fromBbox.top + fromBbox.height + config.nodeSpacing / 2,
},
{ x: toBbox.left + toBbox.width / 2, y: lineStart.y - config.nodeSpacing / 2 },
lineStart
lineStart,
],
color
);
@@ -168,20 +186,20 @@ function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
[
{
x: fromBbox.left + fromBbox.width / 2,
y: fromBbox.top + fromBbox.height
y: fromBbox.top + fromBbox.height,
},
{
x: fromBbox.left + fromBbox.width / 2,
y: fromBbox.top + config.nodeSpacing / 2
y: fromBbox.top + config.nodeSpacing / 2,
},
{
x: toBbox.left + toBbox.width / 2,
y: toBbox.top - config.nodeSpacing / 2
y: toBbox.top - config.nodeSpacing / 2,
},
{
x: toBbox.left + toBbox.width / 2,
y: toBbox.top
}
y: toBbox.top,
},
],
color
);
@@ -190,13 +208,20 @@ function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
}
}
/**
* @param svg
* @param selector
*/
function cloneNode(svg, selector) {
return svg
.select(selector)
.node()
.cloneNode(true);
return svg.select(selector).node().cloneNode(true);
}
/**
* @param svg
* @param commitid
* @param branches
* @param direction
*/
function renderCommitHistory(svg, commitid, branches, direction) {
let commit;
const numCommits = Object.keys(allCommitsDict).length;
@@ -208,14 +233,14 @@ function renderCommitHistory(svg, commitid, branches, direction) {
return;
}
svg
.append(function() {
.append(function () {
return cloneNode(svg, '#def-commit');
})
.attr('class', 'commit')
.attr('id', function() {
.attr('id', function () {
return 'node-' + commit.id;
})
.attr('transform', function() {
.attr('transform', function () {
switch (direction) {
case 'LR':
return (
@@ -279,6 +304,12 @@ function renderCommitHistory(svg, commitid, branches, direction) {
}
}
/**
* @param svg
* @param commit
* @param direction
* @param branchColor
*/
function renderLines(svg, commit, direction, branchColor) {
branchColor = branchColor || 0;
while (commit.seq > 0 && !commit.lineDrawn) {
@@ -296,7 +327,7 @@ function renderLines(svg, commit, direction, branchColor) {
}
}
export const draw = function(txt, id, ver) {
export const draw = function (txt, id, ver) {
try {
const parser = gitGraphParser.parser;
parser.yy = db;
@@ -325,7 +356,7 @@ export const draw = function(txt, id, ver) {
renderLines(svg, v.commit, direction);
branchNum++;
}
svg.attr('height', function() {
svg.attr('height', function () {
if (direction === 'BT') return Object.keys(allCommitsDict).length * config.nodeSpacing;
return (branches.length + 1) * config.branchOffset;
});
@@ -337,5 +368,5 @@ export const draw = function(txt, id, ver) {
export default {
setConf,
draw
draw,
};