mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-15 02:04:08 +01:00
GitGraph: refactored overlapping fn for efficiency/performance
On previous rewrite, I had created new functions within the overlapping functions but these were being recreated on each iteration of Object.some(). I moved them outside this for clarity and so they're not recreated each iteration.
This commit is contained in:
@@ -351,17 +351,18 @@ const drawCommits = (svg, commits, modifyGraph) => {
|
|||||||
* commitA's x-position
|
* commitA's x-position
|
||||||
* and commitB's x-position
|
* and commitB's x-position
|
||||||
*/
|
*/
|
||||||
const hasOverlappingCommits = (commitA, commitB, allCommits) =>
|
const hasOverlappingCommits = (commitA, commitB, allCommits) => {
|
||||||
Object.values(allCommits).some((commitX) => {
|
const isOnSourceBranch = (x) => x.branch === commitA.branch;
|
||||||
const isOnSourceBranch = (x) => x.branch === commitA.branch;
|
const isOnTargetBranch = (x) => x.branch === commitB.branch;
|
||||||
const isOnTargetBranch = (x) => x.branch === commitB.branch;
|
const isBetweenCommits = (x) => x.seq > commitA.seq && x.seq < commitB.seq;
|
||||||
const isBetweenCommits = (x) => x.seq > commitA.seq && x.seq < commitB.seq;
|
const isTargetMain = (x) => x.branch === getConfig().gitGraph.mainBranchName;
|
||||||
const isTargetMain = (x) => x.branch === getConfig().gitGraph.mainBranchName;
|
return Object.values(allCommits).some((commitX) => {
|
||||||
return (
|
return (
|
||||||
(isOnSourceBranch(commitX) || (isOnTargetBranch(commitX) && !isTargetMain(commitX))) &&
|
(isOnSourceBranch(commitX) || (isOnTargetBranch(commitX) && !isTargetMain(commitX))) &&
|
||||||
isBetweenCommits(commitX)
|
isBetweenCommits(commitX)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function find a lane in the y-axis that is not overlapping with any other lanes. This is
|
* This function find a lane in the y-axis that is not overlapping with any other lanes. This is
|
||||||
|
|||||||
Reference in New Issue
Block a user