mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-06 07:39:48 +02:00
added most suggested changes
This commit is contained in:
@@ -10,7 +10,8 @@ import {
|
|||||||
setDiagramTitle,
|
setDiagramTitle,
|
||||||
getDiagramTitle,
|
getDiagramTitle,
|
||||||
} from '../common/commonDb.js';
|
} from '../common/commonDb.js';
|
||||||
import type { DiagramOrientation, Commit, GitGraphDB, CommitType } from './gitGraphTypes.js';
|
import type { DiagramOrientation, Commit, GitGraphDB } from './gitGraphTypes.js';
|
||||||
|
import { commitType } from './gitGraphTypes.js';
|
||||||
import { ImperativeState } from '../../utils/imperativeState.js';
|
import { ImperativeState } from '../../utils/imperativeState.js';
|
||||||
|
|
||||||
import DEFAULT_CONFIG from '../../defaultConfig.js';
|
import DEFAULT_CONFIG from '../../defaultConfig.js';
|
||||||
@@ -132,11 +133,9 @@ export const merge = (
|
|||||||
if (customId) {
|
if (customId) {
|
||||||
customId = common.sanitizeText(customId, config);
|
customId = common.sanitizeText(customId, config);
|
||||||
}
|
}
|
||||||
const currentBranchCheck: string | null | undefined = state.records.branches.get(
|
const currentBranchCheck = state.records.branches.get(state.records.currBranch);
|
||||||
state.records.currBranch
|
const otherBranchCheck = state.records.branches.get(otherBranch);
|
||||||
);
|
const currentCommit = currentBranchCheck
|
||||||
const otherBranchCheck: string | null | undefined = state.records.branches.get(otherBranch);
|
|
||||||
const currentCommit: Commit | undefined = currentBranchCheck
|
|
||||||
? state.records.commits.get(currentBranchCheck)
|
? state.records.commits.get(currentBranchCheck)
|
||||||
: undefined;
|
: undefined;
|
||||||
const otherCommit: Commit | undefined = otherBranchCheck
|
const otherCommit: Commit | undefined = otherBranchCheck
|
||||||
@@ -215,8 +214,8 @@ export const merge = (
|
|||||||
|
|
||||||
const verifiedBranch: string = otherBranchCheck ? otherBranchCheck : ''; //figure out a cleaner way to do this
|
const verifiedBranch: string = otherBranchCheck ? otherBranchCheck : ''; //figure out a cleaner way to do this
|
||||||
|
|
||||||
const commit: Commit = {
|
const commit = {
|
||||||
id: customId ? customId : state.records.seq + '-' + getID(),
|
id: customId ?? `${state.records.seq}-${getID()}`,
|
||||||
message: `merged branch ${otherBranch} into ${state.records.currBranch}`,
|
message: `merged branch ${otherBranch} into ${state.records.currBranch}`,
|
||||||
seq: state.records.seq++,
|
seq: state.records.seq++,
|
||||||
parents: state.records.head == null ? [] : [state.records.head.id, verifiedBranch],
|
parents: state.records.head == null ? [] : [state.records.head.id, verifiedBranch],
|
||||||
@@ -224,8 +223,8 @@ export const merge = (
|
|||||||
type: commitType.MERGE,
|
type: commitType.MERGE,
|
||||||
customType: overrideType,
|
customType: overrideType,
|
||||||
customId: customId ? true : false,
|
customId: customId ? true : false,
|
||||||
tags: customTags ? customTags : [],
|
tags: customTags ?? [],
|
||||||
};
|
} satisfies Commit;
|
||||||
state.records.head = commit;
|
state.records.head = commit;
|
||||||
state.records.commits.set(commit.id, commit);
|
state.records.commits.set(commit.id, commit);
|
||||||
state.records.branches.set(state.records.currBranch, commit.id);
|
state.records.branches.set(state.records.currBranch, commit.id);
|
||||||
@@ -379,7 +378,6 @@ function upsert(arr: any[], key: any, newVal: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param commitArr - array */
|
|
||||||
function prettyPrintCommitHistory(commitArr: Commit[]) {
|
function prettyPrintCommitHistory(commitArr: Commit[]) {
|
||||||
const commit = commitArr.reduce((out, commit) => {
|
const commit = commitArr.reduce((out, commit) => {
|
||||||
if (out.seq > commit.seq) {
|
if (out.seq > commit.seq) {
|
||||||
@@ -472,14 +470,6 @@ export const getHead = function () {
|
|||||||
return state.records.head;
|
return state.records.head;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const commitType: CommitType = {
|
|
||||||
NORMAL: 0,
|
|
||||||
REVERSE: 1,
|
|
||||||
HIGHLIGHT: 2,
|
|
||||||
MERGE: 3,
|
|
||||||
CHERRY_PICK: 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const db: GitGraphDB = {
|
export const db: GitGraphDB = {
|
||||||
commitType,
|
commitType,
|
||||||
getConfig,
|
getConfig,
|
||||||
|
@@ -6,8 +6,8 @@ import gitGraphStyles from './styles.js';
|
|||||||
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
||||||
|
|
||||||
export const diagram: DiagramDefinition = {
|
export const diagram: DiagramDefinition = {
|
||||||
parser: parser,
|
parser,
|
||||||
db: db,
|
db,
|
||||||
renderer: gitGraphRenderer,
|
renderer: gitGraphRenderer,
|
||||||
styles: gitGraphStyles,
|
styles: gitGraphStyles,
|
||||||
};
|
};
|
||||||
|
@@ -4,7 +4,7 @@ import type { ParserDefinition } from '../../diagram-api/types.js';
|
|||||||
import { log } from '../../logger.js';
|
import { log } from '../../logger.js';
|
||||||
import { populateCommonDb } from '../common/populateCommonDb.js';
|
import { populateCommonDb } from '../common/populateCommonDb.js';
|
||||||
import { db } from './gitGraphAst.js';
|
import { db } from './gitGraphAst.js';
|
||||||
import { commitType } from './gitGraphAst.js';
|
import { commitType } from './gitGraphTypes.js';
|
||||||
import type {
|
import type {
|
||||||
CheckoutAst,
|
CheckoutAst,
|
||||||
CherryPickingAst,
|
CherryPickingAst,
|
||||||
|
@@ -4,32 +4,8 @@ import { log } from '../../logger.js';
|
|||||||
import utils from '../../utils.js';
|
import utils from '../../utils.js';
|
||||||
import type { DrawDefinition } from '../../diagram-api/types.js';
|
import type { DrawDefinition } from '../../diagram-api/types.js';
|
||||||
import type d3 from 'd3';
|
import type d3 from 'd3';
|
||||||
import type {
|
import type { Commit, GitGraphDBRenderProvider, DiagramOrientation } from './gitGraphTypes.js';
|
||||||
CommitType,
|
import { commitType } from './gitGraphTypes.js';
|
||||||
Commit,
|
|
||||||
GitGraphDBRenderProvider,
|
|
||||||
DiagramOrientation,
|
|
||||||
} from './gitGraphTypes.js';
|
|
||||||
|
|
||||||
const DEFAULT_CONFIG = getConfig();
|
|
||||||
const DEFAULT_GITGRAPH_CONFIG = DEFAULT_CONFIG?.gitGraph;
|
|
||||||
|
|
||||||
let allCommitsDict = new Map();
|
|
||||||
|
|
||||||
const LAYOUT_OFFSET = 10;
|
|
||||||
const COMMIT_STEP = 40;
|
|
||||||
const PX = 4;
|
|
||||||
const PY = 2;
|
|
||||||
|
|
||||||
const commitType: CommitType = {
|
|
||||||
NORMAL: 0,
|
|
||||||
REVERSE: 1,
|
|
||||||
HIGHLIGHT: 2,
|
|
||||||
MERGE: 3,
|
|
||||||
CHERRY_PICK: 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
const THEME_COLOR_LIMIT = 8;
|
|
||||||
|
|
||||||
interface BranchPosition {
|
interface BranchPosition {
|
||||||
pos: number;
|
pos: number;
|
||||||
@@ -45,12 +21,22 @@ interface CommitPositionOffset extends CommitPosition {
|
|||||||
posWithOffset: number;
|
posWithOffset: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFAULT_CONFIG = getConfig();
|
||||||
|
const DEFAULT_GITGRAPH_CONFIG = DEFAULT_CONFIG?.gitGraph;
|
||||||
|
const LAYOUT_OFFSET = 10;
|
||||||
|
const COMMIT_STEP = 40;
|
||||||
|
const PX = 4;
|
||||||
|
const PY = 2;
|
||||||
|
|
||||||
|
const THEME_COLOR_LIMIT = 8;
|
||||||
const branchPos = new Map<string, BranchPosition>();
|
const branchPos = new Map<string, BranchPosition>();
|
||||||
const commitPos = new Map<string, CommitPosition>();
|
const commitPos = new Map<string, CommitPosition>();
|
||||||
|
const defaultPos = 30;
|
||||||
|
|
||||||
|
let allCommitsDict = new Map();
|
||||||
let lanes: number[] = [];
|
let lanes: number[] = [];
|
||||||
let maxPos = 0;
|
let maxPos = 0;
|
||||||
let dir: DiagramOrientation = 'LR';
|
let dir: DiagramOrientation = 'LR';
|
||||||
const defaultPos = 30;
|
|
||||||
|
|
||||||
const clear = () => {
|
const clear = () => {
|
||||||
branchPos.clear();
|
branchPos.clear();
|
||||||
@@ -306,7 +292,7 @@ const drawCommitLabel = (
|
|||||||
if (
|
if (
|
||||||
commit.type !== commitType.CHERRY_PICK &&
|
commit.type !== commitType.CHERRY_PICK &&
|
||||||
((commit.customId && commit.type === commitType.MERGE) || commit.type !== commitType.MERGE) &&
|
((commit.customId && commit.type === commitType.MERGE) || commit.type !== commitType.MERGE) &&
|
||||||
DEFAULT_GITGRAPH_CONFIG.showCommitLabel
|
DEFAULT_GITGRAPH_CONFIG?.showCommitLabel
|
||||||
) {
|
) {
|
||||||
const wrapper = gLabels.append('g');
|
const wrapper = gLabels.append('g');
|
||||||
const labelBkg = wrapper.insert('rect').attr('class', 'commit-label-bkg');
|
const labelBkg = wrapper.insert('rect').attr('class', 'commit-label-bkg');
|
||||||
@@ -549,10 +535,8 @@ const drawCommits = (
|
|||||||
if (dir === 'BT') {
|
if (dir === 'BT') {
|
||||||
if (isParallelCommits) {
|
if (isParallelCommits) {
|
||||||
setParallelBTPos(sortedKeys, commits, pos);
|
setParallelBTPos(sortedKeys, commits, pos);
|
||||||
sortedKeys = sortedKeys.reverse();
|
|
||||||
} else {
|
|
||||||
sortedKeys = sortedKeys.reverse();
|
|
||||||
}
|
}
|
||||||
|
sortedKeys = sortedKeys.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
sortedKeys.forEach((key) => {
|
sortedKeys.forEach((key) => {
|
||||||
|
@@ -1,13 +1,21 @@
|
|||||||
import type { GitGraphDiagramConfig } from '../../config.type.js';
|
import type { GitGraphDiagramConfig } from '../../config.type.js';
|
||||||
import type { DiagramDBBase } from '../../diagram-api/types.js';
|
import type { DiagramDBBase } from '../../diagram-api/types.js';
|
||||||
|
|
||||||
export interface CommitType {
|
export const commitType = {
|
||||||
NORMAL: number;
|
NORMAL: 0,
|
||||||
REVERSE: number;
|
REVERSE: 1,
|
||||||
HIGHLIGHT: number;
|
HIGHLIGHT: 2,
|
||||||
MERGE: number;
|
MERGE: 3,
|
||||||
CHERRY_PICK: number;
|
CHERRY_PICK: 4,
|
||||||
}
|
} as const;
|
||||||
|
|
||||||
|
export const gitcommitType = {
|
||||||
|
NORMAL: 0,
|
||||||
|
REVERSE: 1,
|
||||||
|
HIGHLIGHT: 2,
|
||||||
|
MERGE: 3,
|
||||||
|
CHERRY_PICK: 4,
|
||||||
|
} as const;
|
||||||
|
|
||||||
export interface Commit {
|
export interface Commit {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -25,11 +33,6 @@ export interface GitGraph {
|
|||||||
statements: Statement[];
|
statements: Statement[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Position {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Statement = CommitAst | BranchAst | MergeAst | CheckoutAst | CherryPickingAst;
|
export type Statement = CommitAst | BranchAst | MergeAst | CheckoutAst | CherryPickingAst;
|
||||||
|
|
||||||
export interface CommitAst {
|
export interface CommitAst {
|
||||||
@@ -62,12 +65,12 @@ export interface CheckoutAst {
|
|||||||
export interface CherryPickingAst {
|
export interface CherryPickingAst {
|
||||||
$type: 'CherryPicking';
|
$type: 'CherryPicking';
|
||||||
id: string;
|
id: string;
|
||||||
tags?: string[];
|
|
||||||
parent: string;
|
parent: string;
|
||||||
|
tags?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GitGraphDB extends DiagramDBBase<GitGraphDiagramConfig> {
|
export interface GitGraphDB extends DiagramDBBase<GitGraphDiagramConfig> {
|
||||||
commitType: CommitType;
|
commitType: typeof commitType;
|
||||||
setDirection: (dir: DiagramOrientation) => void;
|
setDirection: (dir: DiagramOrientation) => void;
|
||||||
setOptions: (rawOptString: string) => void;
|
setOptions: (rawOptString: string) => void;
|
||||||
getOptions: () => any;
|
getOptions: () => any;
|
||||||
@@ -98,7 +101,7 @@ export interface GitGraphDB extends DiagramDBBase<GitGraphDiagramConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface GitGraphDBParseProvider extends Partial<GitGraphDB> {
|
export interface GitGraphDBParseProvider extends Partial<GitGraphDB> {
|
||||||
commitType: CommitType;
|
commitType: typeof commitType;
|
||||||
setDirection: (dir: DiagramOrientation) => void;
|
setDirection: (dir: DiagramOrientation) => void;
|
||||||
commit: (msg: string, id: string, type: number, tags?: string[]) => void;
|
commit: (msg: string, id: string, type: number, tags?: string[]) => void;
|
||||||
branch: (name: string, order?: number) => void;
|
branch: (name: string, order?: number) => void;
|
||||||
|
Reference in New Issue
Block a user