mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Get rid of "var "
This commit is contained in:
parent
daba43dcba
commit
f16143de7c
@ -2,21 +2,21 @@ import _ from 'lodash'
|
||||
|
||||
import { logger } from '../../logger'
|
||||
|
||||
var commits = {}
|
||||
var head = null
|
||||
var branches = { 'master': head }
|
||||
var curBranch = 'master'
|
||||
var direction = 'LR'
|
||||
var seq = 0
|
||||
let commits = {}
|
||||
let head = null
|
||||
let branches = { 'master': head }
|
||||
let curBranch = 'master'
|
||||
let direction = 'LR'
|
||||
let seq = 0
|
||||
|
||||
function getRandomInt (min, max) {
|
||||
return Math.floor(Math.random() * (max - min)) + min
|
||||
}
|
||||
|
||||
function getId () {
|
||||
var pool = '0123456789abcdef'
|
||||
var id = ''
|
||||
for (var i = 0; i < 7; i++) {
|
||||
const pool = '0123456789abcdef'
|
||||
let id = ''
|
||||
for (let i = 0; i < 7; i++) {
|
||||
id += pool[getRandomInt(0, 16)]
|
||||
}
|
||||
return id
|
||||
@ -40,8 +40,8 @@ function isfastforwardable (currentCommit, otherCommit) {
|
||||
}
|
||||
|
||||
function isReachableFrom (currentCommit, otherCommit) {
|
||||
var currentSeq = currentCommit.seq
|
||||
var otherSeq = otherCommit.seq
|
||||
const currentSeq = currentCommit.seq
|
||||
const otherSeq = otherCommit.seq
|
||||
if (currentSeq > otherSeq) return isfastforwardable(otherCommit, currentCommit)
|
||||
return false
|
||||
}
|
||||
@ -49,7 +49,7 @@ function isReachableFrom (currentCommit, otherCommit) {
|
||||
export const setDirection = function (dir) {
|
||||
direction = dir
|
||||
}
|
||||
var options = {}
|
||||
let options = {}
|
||||
export const setOptions = function (rawOptString) {
|
||||
logger.debug('options str', rawOptString)
|
||||
rawOptString = rawOptString && rawOptString.trim()
|
||||
@ -66,7 +66,7 @@ export const getOptions = function () {
|
||||
}
|
||||
|
||||
export const commit = function (msg) {
|
||||
var commit = {
|
||||
const commit = {
|
||||
id: getId(),
|
||||
message: msg,
|
||||
seq: seq++,
|
||||
@ -84,8 +84,8 @@ export const branch = function (name) {
|
||||
}
|
||||
|
||||
export const merge = function (otherBranch) {
|
||||
var currentCommit = commits[branches[curBranch]]
|
||||
var otherCommit = commits[branches[otherBranch]]
|
||||
const currentCommit = commits[branches[curBranch]]
|
||||
const otherCommit = commits[branches[otherBranch]]
|
||||
if (isReachableFrom(currentCommit, otherCommit)) {
|
||||
logger.debug('Already merged')
|
||||
return
|
||||
@ -95,7 +95,7 @@ export const merge = function (otherBranch) {
|
||||
head = commits[branches[curBranch]]
|
||||
} else {
|
||||
// create merge commit
|
||||
var commit = {
|
||||
const commit = {
|
||||
id: getId(),
|
||||
message: 'merged branch ' + otherBranch + ' into ' + curBranch,
|
||||
seq: seq++,
|
||||
@ -112,21 +112,21 @@ export const merge = function (otherBranch) {
|
||||
export const checkout = function (branch) {
|
||||
logger.debug('in checkout')
|
||||
curBranch = branch
|
||||
var id = branches[curBranch]
|
||||
const id = branches[curBranch]
|
||||
head = commits[id]
|
||||
}
|
||||
|
||||
export const reset = function (commitRef) {
|
||||
logger.debug('in reset', commitRef)
|
||||
var ref = commitRef.split(':')[0]
|
||||
var parentCount = parseInt(commitRef.split(':')[1])
|
||||
var commit = ref === 'HEAD' ? head : commits[branches[ref]]
|
||||
const ref = commitRef.split(':')[0]
|
||||
let parentCount = parseInt(commitRef.split(':')[1])
|
||||
let commit = ref === 'HEAD' ? head : commits[branches[ref]]
|
||||
logger.debug(commit, parentCount)
|
||||
while (parentCount > 0) {
|
||||
commit = commits[commit.parent]
|
||||
parentCount--
|
||||
if (!commit) {
|
||||
var err = 'Critical error - unique parent commit not found during reset'
|
||||
const err = 'Critical error - unique parent commit not found during reset'
|
||||
logger.error(err)
|
||||
throw err
|
||||
}
|
||||
@ -145,8 +145,8 @@ function upsert (arr, key, newval) {
|
||||
}
|
||||
|
||||
function prettyPrintCommitHistory (commitArr) {
|
||||
var commit = _.maxBy(commitArr, 'seq')
|
||||
var line = ''
|
||||
const commit = _.maxBy(commitArr, 'seq')
|
||||
let line = ''
|
||||
commitArr.forEach(function (c) {
|
||||
if (c === commit) {
|
||||
line += '\t*'
|
||||
@ -154,19 +154,19 @@ function prettyPrintCommitHistory (commitArr) {
|
||||
line += '\t|'
|
||||
}
|
||||
})
|
||||
var label = [line, commit.id, commit.seq]
|
||||
const label = [line, commit.id, commit.seq]
|
||||
_.each(branches, function (value, key) {
|
||||
if (value === commit.id) label.push(key)
|
||||
})
|
||||
logger.debug(label.join(' '))
|
||||
if (Array.isArray(commit.parent)) {
|
||||
var newCommit = commits[commit.parent[0]]
|
||||
const newCommit = commits[commit.parent[0]]
|
||||
upsert(commitArr, commit, newCommit)
|
||||
commitArr.push(commits[commit.parent[1]])
|
||||
} else if (commit.parent == null) {
|
||||
return
|
||||
} else {
|
||||
var nextCommit = commits[commit.parent]
|
||||
const nextCommit = commits[commit.parent]
|
||||
upsert(commitArr, commit, nextCommit)
|
||||
}
|
||||
commitArr = _.uniqBy(commitArr, 'id')
|
||||
@ -175,7 +175,7 @@ function prettyPrintCommitHistory (commitArr) {
|
||||
|
||||
export const prettyPrint = function () {
|
||||
logger.debug(commits)
|
||||
var node = getCommitsArray()[0]
|
||||
const node = getCommitsArray()[0]
|
||||
prettyPrintCommitHistory([node])
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ export const getBranchesAsObjArray = function () {
|
||||
export const getBranches = function () { return branches }
|
||||
export const getCommits = function () { return commits }
|
||||
export const getCommitsArray = function () {
|
||||
var commitArr = Object.keys(commits).map(function (key) {
|
||||
const commitArr = Object.keys(commits).map(function (key) {
|
||||
return commits[key]
|
||||
})
|
||||
commitArr.forEach(function (o) { logger.debug(o.id) })
|
||||
|
@ -5,9 +5,9 @@ import gitGraphParser from './parser/gitGraph'
|
||||
import d3 from '../../d3'
|
||||
import { logger } from '../../logger'
|
||||
|
||||
var allCommitsDict = {}
|
||||
var branchNum
|
||||
var config = {
|
||||
let allCommitsDict = {}
|
||||
let branchNum
|
||||
let config = {
|
||||
nodeSpacing: 150,
|
||||
nodeFillColor: 'yellow',
|
||||
nodeStrokeWidth: 2,
|
||||
@ -25,7 +25,7 @@ var config = {
|
||||
y: 0
|
||||
}
|
||||
}
|
||||
var apiConfig = {}
|
||||
let apiConfig = {}
|
||||
export const setConf = function (c) {
|
||||
apiConfig = c
|
||||
}
|
||||
@ -53,8 +53,8 @@ function svgCreateDefs (svg) {
|
||||
|
||||
function svgDrawLine (svg, points, colorIdx, interpolate) {
|
||||
interpolate = interpolate || 'basis'
|
||||
var color = config.branchColors[colorIdx % config.branchColors.length]
|
||||
var lineGen = d3.svg.line()
|
||||
const color = config.branchColors[colorIdx % config.branchColors.length]
|
||||
const lineGen = d3.svg.line()
|
||||
.x(function (d) {
|
||||
return Math.round(d.x)
|
||||
})
|
||||
@ -73,9 +73,9 @@ function svgDrawLine (svg, points, colorIdx, interpolate) {
|
||||
// Pass in the element and its pre-transform coords
|
||||
function getElementCoords (element, coords) {
|
||||
coords = coords || element.node().getBBox()
|
||||
var ctm = element.node().getCTM()
|
||||
var xn = ctm.e + coords.x * ctm.a
|
||||
var yn = ctm.f + coords.y * ctm.d
|
||||
const ctm = element.node().getCTM()
|
||||
const xn = ctm.e + coords.x * ctm.a
|
||||
const yn = ctm.f + coords.y * ctm.d
|
||||
return {
|
||||
left: xn,
|
||||
top: yn,
|
||||
@ -86,16 +86,16 @@ function getElementCoords (element, coords) {
|
||||
|
||||
function svgDrawLineForCommits (svg, fromId, toId, direction, color) {
|
||||
logger.debug('svgDrawLineForCommits: ', fromId, toId)
|
||||
var fromBbox = getElementCoords(svg.select('#node-' + fromId + ' circle'))
|
||||
var toBbox = getElementCoords(svg.select('#node-' + toId + ' circle'))
|
||||
const fromBbox = getElementCoords(svg.select('#node-' + fromId + ' circle'))
|
||||
const toBbox = getElementCoords(svg.select('#node-' + toId + ' circle'))
|
||||
switch (direction) {
|
||||
case 'LR':
|
||||
// (toBbox)
|
||||
// +--------
|
||||
// + (fromBbox)
|
||||
if (fromBbox.left - toBbox.left > config.nodeSpacing) {
|
||||
var lineStart = { x: fromBbox.left - config.nodeSpacing, y: toBbox.top + toBbox.height / 2 }
|
||||
var lineEnd = { x: toBbox.left + toBbox.width, y: toBbox.top + toBbox.height / 2 }
|
||||
const lineStart = { x: fromBbox.left - config.nodeSpacing, 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')
|
||||
svgDrawLine(svg, [
|
||||
{ x: fromBbox.left, y: fromBbox.top + fromBbox.height / 2 },
|
||||
@ -124,8 +124,8 @@ function svgDrawLineForCommits (svg, fromId, toId, direction, color) {
|
||||
// |
|
||||
// + (toBbox)
|
||||
if (toBbox.top - fromBbox.top > config.nodeSpacing) {
|
||||
lineStart = { x: toBbox.left + toBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing }
|
||||
lineEnd = { x: toBbox.left + toBbox.width / 2, y: toBbox.top }
|
||||
const lineStart = { x: toBbox.left + toBbox.width / 2, y: fromBbox.top + fromBbox.height + config.nodeSpacing }
|
||||
const lineEnd = { x: toBbox.left + toBbox.width / 2, y: toBbox.top }
|
||||
svgDrawLine(svg, [lineStart, lineEnd], color, 'linear')
|
||||
svgDrawLine(svg, [
|
||||
{ x: fromBbox.left + fromBbox.width / 2, y: fromBbox.top + fromBbox.height },
|
||||
@ -156,8 +156,8 @@ function cloneNode (svg, selector) {
|
||||
}
|
||||
|
||||
function renderCommitHistory (svg, commitid, branches, direction) {
|
||||
var commit
|
||||
var numCommits = Object.keys(allCommitsDict).length
|
||||
let commit
|
||||
const numCommits = Object.keys(allCommitsDict).length
|
||||
if (_.isString(commitid)) {
|
||||
do {
|
||||
commit = allCommitsDict[commitid]
|
||||
@ -187,7 +187,7 @@ function renderCommitHistory (svg, commitid, branches, direction) {
|
||||
.attr('stroke', config.nodeStrokeColor)
|
||||
.attr('stroke-width', config.nodeStrokeWidth)
|
||||
|
||||
var branch = _.find(branches, ['commit', commit])
|
||||
const branch = _.find(branches, ['commit', commit])
|
||||
if (branch) {
|
||||
logger.debug('found branch ', branch.name)
|
||||
svg.select('#node-' + commit.id + ' p')
|
||||
@ -237,8 +237,7 @@ function renderLines (svg, commit, direction, branchColor) {
|
||||
|
||||
export const draw = function (txt, id, ver) {
|
||||
try {
|
||||
var parser
|
||||
parser = gitGraphParser.parser
|
||||
const parser = gitGraphParser.parser
|
||||
parser.yy = db
|
||||
|
||||
logger.debug('in gitgraph renderer', txt, id, ver)
|
||||
@ -247,15 +246,15 @@ export const draw = function (txt, id, ver) {
|
||||
|
||||
config = _.extend(config, apiConfig, db.getOptions())
|
||||
logger.debug('effective options', config)
|
||||
var direction = db.getDirection()
|
||||
const direction = db.getDirection()
|
||||
allCommitsDict = db.getCommits()
|
||||
var branches = db.getBranchesAsObjArray()
|
||||
const branches = db.getBranchesAsObjArray()
|
||||
if (direction === 'BT') {
|
||||
config.nodeLabel.x = branches.length * config.branchOffset
|
||||
config.nodeLabel.width = '100%'
|
||||
config.nodeLabel.y = -1 * 2 * config.nodeRadius
|
||||
}
|
||||
var svg = d3.select('#' + id)
|
||||
const svg = d3.select('#' + id)
|
||||
svgCreateDefs(svg)
|
||||
branchNum = 1
|
||||
_.each(branches, function (v) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user