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

@@ -48,7 +48,7 @@
// arrowMarkerAbsolute: true, // arrowMarkerAbsolute: true,
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}', // themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
logLevel: 0, logLevel: 0,
flowchart: { curve: 'linear', "htmlLabels": true }, flowchart: { curve: 'linear', htmlLabels: true },
// gantt: { axisFormat: '%m/%d/%Y' }, // gantt: { axisFormat: '%m/%d/%Y' },
sequence: { actorMargin: 50, showSequenceNumbers: true }, sequence: { actorMargin: 50, showSequenceNumbers: true },
// sequenceDiagram: { actorMargin: 300 } // deprecated // sequenceDiagram: { actorMargin: 300 } // deprecated
@@ -57,9 +57,11 @@
// fontFamily: '"arial", sans-serif', // fontFamily: '"arial", sans-serif',
// }, // },
curve: 'linear', curve: 'linear',
securityLevel: 'loose' securityLevel: 'loose',
}); });
function callback(){alert('It worked');} function callback() {
alert('It worked');
}
</script> </script>
</body> </body>
</html> </html>

View File

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