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