mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-23 09:20:03 +02:00
Update of prettier, eslint and rules
This commit is contained in:
@@ -49,11 +49,11 @@ function uniqBy(list, fn) {
|
||||
}, []);
|
||||
}
|
||||
|
||||
export const setDirection = function(dir) {
|
||||
export const setDirection = function (dir) {
|
||||
direction = dir;
|
||||
};
|
||||
let options = {};
|
||||
export const setOptions = function(rawOptString) {
|
||||
export const setOptions = function (rawOptString) {
|
||||
log.debug('options str', rawOptString);
|
||||
rawOptString = rawOptString && rawOptString.trim();
|
||||
rawOptString = rawOptString || '{}';
|
||||
@@ -64,16 +64,16 @@ export const setOptions = function(rawOptString) {
|
||||
}
|
||||
};
|
||||
|
||||
export const getOptions = function() {
|
||||
export const getOptions = function () {
|
||||
return options;
|
||||
};
|
||||
|
||||
export const commit = function(msg) {
|
||||
export const commit = function (msg) {
|
||||
const commit = {
|
||||
id: getId(),
|
||||
message: msg,
|
||||
seq: seq++,
|
||||
parent: head == null ? null : head.id
|
||||
parent: head == null ? null : head.id,
|
||||
};
|
||||
head = commit;
|
||||
commits[commit.id] = commit;
|
||||
@@ -81,12 +81,12 @@ export const commit = function(msg) {
|
||||
log.debug('in pushCommit ' + commit.id);
|
||||
};
|
||||
|
||||
export const branch = function(name) {
|
||||
export const branch = function (name) {
|
||||
branches[name] = head != null ? head.id : null;
|
||||
log.debug('in createBranch');
|
||||
};
|
||||
|
||||
export const merge = function(otherBranch) {
|
||||
export const merge = function (otherBranch) {
|
||||
const currentCommit = commits[branches[curBranch]];
|
||||
const otherCommit = commits[branches[otherBranch]];
|
||||
if (isReachableFrom(currentCommit, otherCommit)) {
|
||||
@@ -102,7 +102,7 @@ export const merge = function(otherBranch) {
|
||||
id: getId(),
|
||||
message: 'merged branch ' + otherBranch + ' into ' + curBranch,
|
||||
seq: seq++,
|
||||
parent: [head == null ? null : head.id, branches[otherBranch]]
|
||||
parent: [head == null ? null : head.id, branches[otherBranch]],
|
||||
};
|
||||
head = commit;
|
||||
commits[commit.id] = commit;
|
||||
@@ -112,14 +112,14 @@ export const merge = function(otherBranch) {
|
||||
log.debug('in mergeBranch');
|
||||
};
|
||||
|
||||
export const checkout = function(branch) {
|
||||
export const checkout = function (branch) {
|
||||
log.debug('in checkout');
|
||||
curBranch = branch;
|
||||
const id = branches[curBranch];
|
||||
head = commits[id];
|
||||
};
|
||||
|
||||
export const reset = function(commitRef) {
|
||||
export const reset = function (commitRef) {
|
||||
log.debug('in reset', commitRef);
|
||||
const ref = commitRef.split(':')[0];
|
||||
let parentCount = parseInt(commitRef.split(':')[1]);
|
||||
@@ -153,7 +153,7 @@ function prettyPrintCommitHistory(commitArr) {
|
||||
return commit;
|
||||
}, commitArr[0]);
|
||||
let line = '';
|
||||
commitArr.forEach(function(c) {
|
||||
commitArr.forEach(function (c) {
|
||||
if (c === commit) {
|
||||
line += '\t*';
|
||||
} else {
|
||||
@@ -175,17 +175,17 @@ function prettyPrintCommitHistory(commitArr) {
|
||||
const nextCommit = commits[commit.parent];
|
||||
upsert(commitArr, commit, nextCommit);
|
||||
}
|
||||
commitArr = uniqBy(commitArr, c => c.id);
|
||||
commitArr = uniqBy(commitArr, (c) => c.id);
|
||||
prettyPrintCommitHistory(commitArr);
|
||||
}
|
||||
|
||||
export const prettyPrint = function() {
|
||||
export const prettyPrint = function () {
|
||||
log.debug(commits);
|
||||
const node = getCommitsArray()[0];
|
||||
prettyPrintCommitHistory([node]);
|
||||
};
|
||||
|
||||
export const clear = function() {
|
||||
export const clear = function () {
|
||||
commits = {};
|
||||
head = null;
|
||||
branches = { master: head };
|
||||
@@ -193,7 +193,7 @@ export const clear = function() {
|
||||
seq = 0;
|
||||
};
|
||||
|
||||
export const getBranchesAsObjArray = function() {
|
||||
export const getBranchesAsObjArray = function () {
|
||||
const branchArr = [];
|
||||
for (let branch in branches) {
|
||||
branchArr.push({ name: branch, commit: commits[branches[branch]] });
|
||||
@@ -201,29 +201,29 @@ export const getBranchesAsObjArray = function() {
|
||||
return branchArr;
|
||||
};
|
||||
|
||||
export const getBranches = function() {
|
||||
export const getBranches = function () {
|
||||
return branches;
|
||||
};
|
||||
export const getCommits = function() {
|
||||
export const getCommits = function () {
|
||||
return commits;
|
||||
};
|
||||
export const getCommitsArray = function() {
|
||||
const commitArr = Object.keys(commits).map(function(key) {
|
||||
export const getCommitsArray = function () {
|
||||
const commitArr = Object.keys(commits).map(function (key) {
|
||||
return commits[key];
|
||||
});
|
||||
commitArr.forEach(function(o) {
|
||||
commitArr.forEach(function (o) {
|
||||
log.debug(o.id);
|
||||
});
|
||||
commitArr.sort((a, b) => b.seq - a.seq);
|
||||
return commitArr;
|
||||
};
|
||||
export const getCurrentBranch = function() {
|
||||
export const getCurrentBranch = function () {
|
||||
return curBranch;
|
||||
};
|
||||
export const getDirection = function() {
|
||||
export const getDirection = function () {
|
||||
return direction;
|
||||
};
|
||||
export const getHead = function() {
|
||||
export const getHead = function () {
|
||||
return head;
|
||||
};
|
||||
|
||||
@@ -244,5 +244,5 @@ export default {
|
||||
getCommitsArray,
|
||||
getCurrentBranch,
|
||||
getDirection,
|
||||
getHead
|
||||
getHead,
|
||||
};
|
||||
|
@@ -22,11 +22,11 @@ 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;
|
||||
};
|
||||
|
||||
@@ -56,10 +56,10 @@ 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);
|
||||
@@ -82,7 +82,7 @@ function getElementCoords(element, coords) {
|
||||
left: xn,
|
||||
top: yn,
|
||||
width: coords.width,
|
||||
height: coords.height
|
||||
height: coords.height,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,7 +98,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 +108,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 +118,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 +145,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 +155,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 +168,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
|
||||
);
|
||||
@@ -191,10 +191,7 @@ function svgDrawLineForCommits(svg, fromId, toId, direction, color) {
|
||||
}
|
||||
|
||||
function cloneNode(svg, selector) {
|
||||
return svg
|
||||
.select(selector)
|
||||
.node()
|
||||
.cloneNode(true);
|
||||
return svg.select(selector).node().cloneNode(true);
|
||||
}
|
||||
|
||||
function renderCommitHistory(svg, commitid, branches, direction) {
|
||||
@@ -208,14 +205,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 (
|
||||
@@ -296,7 +293,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 +322,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 +334,5 @@ export const draw = function(txt, id, ver) {
|
||||
|
||||
export default {
|
||||
setConf,
|
||||
draw
|
||||
draw,
|
||||
};
|
||||
|
Reference in New Issue
Block a user