mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-11 03:19:42 +02:00
replace mock data with real
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>info below</h1>
|
<h1>info below</h1>
|
||||||
<div class="mermaid" style="width: 100%; height: 20%;">
|
<div class="mermaid2" style="width: 100%; height: 20%;">
|
||||||
gitGraph:
|
gitGraph:
|
||||||
commit "Ashish"
|
commit "Ashish"
|
||||||
branch newbranch
|
branch newbranch
|
||||||
@@ -41,6 +41,49 @@
|
|||||||
commit
|
commit
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mermaid" style="width: 100%; height: 20%;">
|
||||||
|
gitGraph:
|
||||||
|
commit
|
||||||
|
branch develop
|
||||||
|
checkout develop
|
||||||
|
commit
|
||||||
|
branch featureB
|
||||||
|
checkout featureB
|
||||||
|
commit
|
||||||
|
checkout master
|
||||||
|
branch hotfix
|
||||||
|
checkout hotfix
|
||||||
|
commit
|
||||||
|
checkout develop
|
||||||
|
commit
|
||||||
|
checkout featureB
|
||||||
|
commit
|
||||||
|
checkout master
|
||||||
|
merge hotfix
|
||||||
|
checkout featureB
|
||||||
|
commit
|
||||||
|
checkout develop
|
||||||
|
branch featureA
|
||||||
|
commit
|
||||||
|
checkout develop
|
||||||
|
merge hotfix
|
||||||
|
checkout featureA
|
||||||
|
commit
|
||||||
|
checkout featureB
|
||||||
|
commit
|
||||||
|
checkout develop
|
||||||
|
merge featureA
|
||||||
|
branch release
|
||||||
|
checkout release
|
||||||
|
commit
|
||||||
|
checkout master
|
||||||
|
commit
|
||||||
|
checkout release
|
||||||
|
merge master
|
||||||
|
checkout develop
|
||||||
|
merge release
|
||||||
|
|
||||||
|
</div>
|
||||||
<div class="mermaid2" style="width: 100%; height: 20%;">
|
<div class="mermaid2" style="width: 100%; height: 20%;">
|
||||||
gitGraph:
|
gitGraph:
|
||||||
commit
|
commit
|
||||||
@@ -53,14 +96,14 @@
|
|||||||
<script src="./mermaid.js"></script>
|
<script src="./mermaid.js"></script>
|
||||||
<script>
|
<script>
|
||||||
mermaid.parseError = function (err, hash) {
|
mermaid.parseError = function (err, hash) {
|
||||||
// console.error('Mermaid error: ', err);
|
// console.error('Mermaid error: ', err);
|
||||||
};
|
};
|
||||||
mermaid.initialize({
|
mermaid.initialize({
|
||||||
theme: 'default',
|
theme: 'default',
|
||||||
// arrowMarkerAbsolute: true,
|
// arrowMarkerAbsolute: true,
|
||||||
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
|
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
|
||||||
logLevel: 0,
|
logLevel: 1,
|
||||||
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
|
||||||
@@ -69,9 +112,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>
|
||||||
|
@@ -7,45 +7,48 @@ let curBranch = 'master';
|
|||||||
let direction = 'LR';
|
let direction = 'LR';
|
||||||
let seq = 0;
|
let seq = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function getId() {
|
function getId() {
|
||||||
return random({ length: 7 });
|
return random({ length: 7 });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* @param currentCommit
|
// * @param currentCommit
|
||||||
* @param otherCommit
|
// * @param otherCommit
|
||||||
*/
|
// */
|
||||||
function isfastforwardable(currentCommit, otherCommit) {
|
// function isfastforwardable(currentCommit, otherCommit) {
|
||||||
log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id);
|
// log.debug('Entering isfastforwardable:', currentCommit.id, otherCommit.id);
|
||||||
let cnt = 0;
|
// let cnt = 0;
|
||||||
while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit && cnt < 1000) {
|
// while (currentCommit.seq <= otherCommit.seq && currentCommit !== otherCommit && cnt < 1000) {
|
||||||
cnt++;
|
// cnt++;
|
||||||
// only if other branch has more commits
|
// // only if other branch has more commits
|
||||||
if (otherCommit.parent == null) break;
|
// if (otherCommit.parent == null) break;
|
||||||
if (Array.isArray(otherCommit.parent)) {
|
// if (Array.isArray(otherCommit.parent)) {
|
||||||
log.debug('In merge commit:', otherCommit.parent);
|
// log.debug('In merge commit:', otherCommit.parent);
|
||||||
return (
|
// return (
|
||||||
isfastforwardable(currentCommit, commits[otherCommit.parent[0]]) ||
|
// isfastforwardable(currentCommit, commits[otherCommit.parent[0]]) ||
|
||||||
isfastforwardable(currentCommit, commits[otherCommit.parent[1]])
|
// isfastforwardable(currentCommit, commits[otherCommit.parent[1]])
|
||||||
);
|
// );
|
||||||
} else {
|
// } else {
|
||||||
otherCommit = commits[otherCommit.parent];
|
// otherCommit = commits[otherCommit.parent];
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
log.debug(currentCommit.id, otherCommit.id);
|
// log.debug(currentCommit.id, otherCommit.id);
|
||||||
return currentCommit.id === otherCommit.id;
|
// return currentCommit.id === otherCommit.id;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param currentCommit
|
* @param currentCommit
|
||||||
* @param otherCommit
|
* @param otherCommit
|
||||||
*/
|
*/
|
||||||
function isReachableFrom(currentCommit, otherCommit) {
|
// function isReachableFrom(currentCommit, otherCommit) {
|
||||||
const currentSeq = currentCommit.seq;
|
// const currentSeq = currentCommit.seq;
|
||||||
const otherSeq = otherCommit.seq;
|
// const otherSeq = otherCommit.seq;
|
||||||
if (currentSeq > otherSeq) return isfastforwardable(otherCommit, currentCommit);
|
// if (currentSeq > otherSeq) return isfastforwardable(otherCommit, currentCommit);
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param list
|
* @param list
|
||||||
@@ -82,14 +85,15 @@ export const getOptions = function () {
|
|||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const commit = function(msg, id, type, tag) {
|
export const commit = function (msg, id, type, tag) {
|
||||||
const commit = {
|
const commit = {
|
||||||
id: id ? id : getId(),
|
id: id ? id : seq + '-' + getId(),
|
||||||
message: msg,
|
message: msg,
|
||||||
seq: seq++,
|
seq: seq++,
|
||||||
type: type ? type : commitType.NORMAL,
|
type: type ? type : commitType.NORMAL,
|
||||||
tag: tag ? tag : '',
|
tag: tag ? tag : '',
|
||||||
parent: head == null ? null : head.id,
|
parents: head == null ? [] : [head.id],
|
||||||
|
branch: curBranch,
|
||||||
};
|
};
|
||||||
head = commit;
|
head = commit;
|
||||||
commits[commit.id] = commit;
|
commits[commit.id] = commit;
|
||||||
@@ -105,25 +109,26 @@ export const branch = function (name) {
|
|||||||
export const merge = function (otherBranch) {
|
export const merge = function (otherBranch) {
|
||||||
const currentCommit = commits[branches[curBranch]];
|
const currentCommit = commits[branches[curBranch]];
|
||||||
const otherCommit = commits[branches[otherBranch]];
|
const otherCommit = commits[branches[otherBranch]];
|
||||||
if (isReachableFrom(currentCommit, otherCommit)) {
|
// if (isReachableFrom(currentCommit, otherCommit)) {
|
||||||
log.debug('Already merged');
|
// log.debug('Already merged');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (isfastforwardable(currentCommit, otherCommit)) {
|
// if (isfastforwardable(currentCommit, otherCommit)) {
|
||||||
branches[curBranch] = branches[otherBranch];
|
// branches[curBranch] = branches[otherBranch];
|
||||||
head = commits[branches[curBranch]];
|
// head = commits[branches[curBranch]];
|
||||||
} else {
|
// } else {
|
||||||
// create merge commit
|
// create merge commit
|
||||||
const commit = {
|
const commit = {
|
||||||
id: getId(),
|
id: seq + '-' + getId(),
|
||||||
message: 'merged branch ' + otherBranch + ' into ' + curBranch,
|
message: 'merged branch ' + otherBranch + ' into ' + curBranch,
|
||||||
seq: seq++,
|
seq: seq++,
|
||||||
parent: [head == null ? null : head.id, branches[otherBranch]],
|
parents: [head == null ? null : head.id, branches[otherBranch]],
|
||||||
};
|
branch: curBranch,
|
||||||
head = commit;
|
};
|
||||||
commits[commit.id] = commit;
|
head = commit;
|
||||||
branches[curBranch] = commit.id;
|
commits[commit.id] = commit;
|
||||||
}
|
branches[curBranch] = commit.id;
|
||||||
|
// }
|
||||||
log.debug(branches);
|
log.debug(branches);
|
||||||
log.debug('in mergeBranch');
|
log.debug('in mergeBranch');
|
||||||
};
|
};
|
||||||
@@ -135,24 +140,24 @@ export const checkout = function (branch) {
|
|||||||
head = commits[id];
|
head = commits[id];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const reset = function (commitRef) {
|
// export const reset = function (commitRef) {
|
||||||
log.debug('in reset', commitRef);
|
// log.debug('in reset', commitRef);
|
||||||
const ref = commitRef.split(':')[0];
|
// const ref = commitRef.split(':')[0];
|
||||||
let parentCount = parseInt(commitRef.split(':')[1]);
|
// let parentCount = parseInt(commitRef.split(':')[1]);
|
||||||
let commit = ref === 'HEAD' ? head : commits[branches[ref]];
|
// let commit = ref === 'HEAD' ? head : commits[branches[ref]];
|
||||||
log.debug(commit, parentCount);
|
// log.debug(commit, parentCount);
|
||||||
while (parentCount > 0) {
|
// while (parentCount > 0) {
|
||||||
commit = commits[commit.parent];
|
// commit = commits[commit.parent];
|
||||||
parentCount--;
|
// parentCount--;
|
||||||
if (!commit) {
|
// if (!commit) {
|
||||||
const err = 'Critical error - unique parent commit not found during reset';
|
// const err = 'Critical error - unique parent commit not found during reset';
|
||||||
log.error(err);
|
// log.error(err);
|
||||||
throw err;
|
// throw err;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
head = commit;
|
// head = commit;
|
||||||
branches[curBranch] = commit.id;
|
// branches[curBranch] = commit.id;
|
||||||
};
|
// };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param arr
|
* @param arr
|
||||||
@@ -187,14 +192,14 @@ function prettyPrintCommitHistory(commitArr) {
|
|||||||
if (branches[branch] === commit.id) label.push(branch);
|
if (branches[branch] === commit.id) label.push(branch);
|
||||||
}
|
}
|
||||||
log.debug(label.join(' '));
|
log.debug(label.join(' '));
|
||||||
if (Array.isArray(commit.parent)) {
|
if (commit.parents && commit.parents.length == 2) {
|
||||||
const newCommit = commits[commit.parent[0]];
|
const newCommit = commits[commit.parents[0]];
|
||||||
upsert(commitArr, commit, newCommit);
|
upsert(commitArr, commit, newCommit);
|
||||||
commitArr.push(commits[commit.parent[1]]);
|
commitArr.push(commits[commit.parents[1]]);
|
||||||
} else if (commit.parent == null) {
|
} else if (commit.parents.length == 0) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const nextCommit = commits[commit.parent];
|
const nextCommit = commits[commit.parents];
|
||||||
upsert(commitArr, commit, nextCommit);
|
upsert(commitArr, commit, nextCommit);
|
||||||
}
|
}
|
||||||
commitArr = uniqBy(commitArr, (c) => c.id);
|
commitArr = uniqBy(commitArr, (c) => c.id);
|
||||||
@@ -218,7 +223,8 @@ export const clear = function () {
|
|||||||
export const getBranchesAsObjArray = function () {
|
export const getBranchesAsObjArray = function () {
|
||||||
const branchArr = [];
|
const branchArr = [];
|
||||||
for (let branch in branches) {
|
for (let branch in branches) {
|
||||||
branchArr.push({ name: branch, commit: commits[branches[branch]] });
|
// branchArr.push({ name: branch, commit: commits[branches[branch]] });
|
||||||
|
branchArr.push({ name: branch });
|
||||||
}
|
}
|
||||||
return branchArr;
|
return branchArr;
|
||||||
};
|
};
|
||||||
@@ -236,7 +242,7 @@ export const getCommitsArray = function () {
|
|||||||
commitArr.forEach(function (o) {
|
commitArr.forEach(function (o) {
|
||||||
log.debug(o.id);
|
log.debug(o.id);
|
||||||
});
|
});
|
||||||
commitArr.sort((a, b) => b.seq - a.seq);
|
commitArr.sort((a, b) => a.seq - b.seq);
|
||||||
return commitArr;
|
return commitArr;
|
||||||
};
|
};
|
||||||
export const getCurrentBranch = function () {
|
export const getCurrentBranch = function () {
|
||||||
@@ -252,7 +258,7 @@ export const getHead = function () {
|
|||||||
export const commitType = {
|
export const commitType = {
|
||||||
NORMAL: 0,
|
NORMAL: 0,
|
||||||
REVERSE: 1,
|
REVERSE: 1,
|
||||||
HIGHLIGHT: 2
|
HIGHLIGHT: 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -263,7 +269,7 @@ export default {
|
|||||||
branch,
|
branch,
|
||||||
merge,
|
merge,
|
||||||
checkout,
|
checkout,
|
||||||
reset,
|
//reset,
|
||||||
prettyPrint,
|
prettyPrint,
|
||||||
clear,
|
clear,
|
||||||
getBranchesAsObjArray,
|
getBranchesAsObjArray,
|
||||||
@@ -273,5 +279,5 @@ export default {
|
|||||||
getCurrentBranch,
|
getCurrentBranch,
|
||||||
getDirection,
|
getDirection,
|
||||||
getHead,
|
getHead,
|
||||||
commitType
|
commitType,
|
||||||
};
|
};
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import { curveBasis, line, select } from 'd3';
|
import { curveBasis, line, select } from 'd3';
|
||||||
import { interpolateToCurve, getStylesFromArray, configureSvgSize } from '../../utils';
|
import { interpolateToCurve, getStylesFromArray, configureSvgSize } from '../../utils';
|
||||||
// import db from './gitGraphAst';
|
import db from './gitGraphAst';
|
||||||
import * as db from './mockDb';
|
//import * as db from './mockDb';
|
||||||
import gitGraphParser from './parser/gitGraph';
|
import gitGraphParser from './parser/gitGraph';
|
||||||
import { log } from '../../logger';
|
import { log } from '../../logger';
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
@@ -244,7 +244,7 @@ export const draw = function (txt, id, ver) {
|
|||||||
|
|
||||||
log.debug('in gitgraph renderer', txt + '\n', 'id:', id, ver);
|
log.debug('in gitgraph renderer', txt + '\n', 'id:', id, ver);
|
||||||
// // Parse the graph definition
|
// // Parse the graph definition
|
||||||
// parser.parse(txt + '\n');
|
parser.parse(txt + '\n');
|
||||||
|
|
||||||
// config = Object.assign(config, apiConfig, db.getOptions());
|
// config = Object.assign(config, apiConfig, db.getOptions());
|
||||||
const direction = db.getDirection();
|
const direction = db.getDirection();
|
||||||
|
39
src/diagrams/git/parser/desired syntax
Normal file
39
src/diagrams/git/parser/desired syntax
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
commit
|
||||||
|
branch develop
|
||||||
|
checkout develop
|
||||||
|
commit
|
||||||
|
branch featureB
|
||||||
|
checkout featureB
|
||||||
|
commit
|
||||||
|
checkout master
|
||||||
|
branch hotfix
|
||||||
|
checkout hotfix
|
||||||
|
commit
|
||||||
|
checkout develop
|
||||||
|
commit
|
||||||
|
checkout featureB
|
||||||
|
commit
|
||||||
|
checkout master
|
||||||
|
merge hotfix
|
||||||
|
checkout featureB
|
||||||
|
commit
|
||||||
|
checkout develop
|
||||||
|
branch featureA
|
||||||
|
commit
|
||||||
|
checkout develop
|
||||||
|
merge hotfix
|
||||||
|
checkout featureA
|
||||||
|
commit
|
||||||
|
checkout featureB
|
||||||
|
commit
|
||||||
|
checkout develop
|
||||||
|
merge featureA
|
||||||
|
branch release
|
||||||
|
checkout release
|
||||||
|
commit
|
||||||
|
checkout master
|
||||||
|
commit
|
||||||
|
checkout release
|
||||||
|
merge master
|
||||||
|
checkout develop
|
||||||
|
merge release
|
Reference in New Issue
Block a user