diff --git a/package.json b/package.json index 57d1d68a0..e73b01299 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,10 @@ "dagre-layout": "^0.8.8", "graphlibrary": "^2.2.0", "he": "^1.2.0", - "lodash": "^4.17.11", + "lodash.assign": "^4.2.0", + "lodash.maxby": "^4.6.0", + "lodash.orderby": "^4.6.0", + "lodash.uniqby": "^4.7.0", "moment-mini": "^2.22.1", "scope-css": "^1.2.1" }, diff --git a/src/diagrams/git/gitGraphAst.js b/src/diagrams/git/gitGraphAst.js index e734453b7..f71a15a8c 100644 --- a/src/diagrams/git/gitGraphAst.js +++ b/src/diagrams/git/gitGraphAst.js @@ -1,4 +1,6 @@ -import _ from 'lodash' +import maxBy from 'lodash.maxby' +import orderBy from 'lodash.orderby' +import uniqBy from 'lodash.uniqby' import { logger } from '../../logger' @@ -145,7 +147,7 @@ function upsert (arr, key, newval) { } function prettyPrintCommitHistory (commitArr) { - const commit = _.maxBy(commitArr, 'seq') + const commit = maxBy(commitArr, 'seq') let line = '' commitArr.forEach(function (c) { if (c === commit) { @@ -155,9 +157,9 @@ function prettyPrintCommitHistory (commitArr) { } }) const label = [line, commit.id, commit.seq] - _.each(branches, function (value, key) { - if (value === commit.id) label.push(key) - }) + for (let branch in branches) { + if (branches[branch] === commit.id) label.push(branch) + } logger.debug(label.join(' ')) if (Array.isArray(commit.parent)) { const newCommit = commits[commit.parent[0]] @@ -169,7 +171,7 @@ function prettyPrintCommitHistory (commitArr) { const nextCommit = commits[commit.parent] upsert(commitArr, commit, nextCommit) } - commitArr = _.uniqBy(commitArr, 'id') + commitArr = uniqBy(commitArr, 'id') prettyPrintCommitHistory(commitArr) } @@ -188,9 +190,10 @@ export const clear = function () { } export const getBranchesAsObjArray = function () { - const branchArr = _.map(branches, function (value, key) { - return { 'name': key, 'commit': commits[value] } - }) + const branchArr = [] + for (let branch in branches) { + branchArr.push({ name: branch, commit: commits[branches[branch]] }) + } return branchArr } @@ -201,7 +204,7 @@ export const getCommitsArray = function () { return commits[key] }) commitArr.forEach(function (o) { logger.debug(o.id) }) - return _.orderBy(commitArr, ['seq'], ['desc']) + return orderBy(commitArr, ['seq'], ['desc']) } export const getCurrentBranch = function () { return curBranch } export const getDirection = function () { return direction } diff --git a/src/diagrams/git/gitGraphRenderer.js b/src/diagrams/git/gitGraphRenderer.js index 3ef56478d..79aae45fe 100644 --- a/src/diagrams/git/gitGraphRenderer.js +++ b/src/diagrams/git/gitGraphRenderer.js @@ -1,5 +1,5 @@ -import _ from 'lodash' import * as d3 from 'd3' +import assign from 'lodash.assign' import db from './gitGraphAst' import gitGraphParser from './parser/gitGraph' @@ -160,7 +160,7 @@ function cloneNode (svg, selector) { function renderCommitHistory (svg, commitid, branches, direction) { let commit const numCommits = Object.keys(allCommitsDict).length - if (_.isString(commitid)) { + if (typeof commitid === 'string') { do { commit = allCommitsDict[commitid] logger.debug('in renderCommitHistory', commit.id, commit.seq) @@ -189,7 +189,13 @@ function renderCommitHistory (svg, commitid, branches, direction) { .attr('stroke', config.nodeStrokeColor) .attr('stroke-width', config.nodeStrokeWidth) - const branch = _.find(branches, ['commit', commit]) + let branch + for (let branchName in branches) { + if (branches[branchName].commit === commit) { + branch = branches[branchName] + break + } + } if (branch) { logger.debug('found branch ', branch.name) svg.select('#node-' + commit.id + ' p') @@ -211,7 +217,7 @@ function renderCommitHistory (svg, commitid, branches, direction) { } while (commitid && allCommitsDict[commitid]) } - if (_.isArray(commitid)) { + if (Array.isArray(commitid)) { logger.debug('found merge commmit', commitid) renderCommitHistory(svg, commitid[0], branches, direction) branchNum++ @@ -223,11 +229,11 @@ function renderCommitHistory (svg, commitid, branches, direction) { function renderLines (svg, commit, direction, branchColor) { branchColor = branchColor || 0 while (commit.seq > 0 && !commit.lineDrawn) { - if (_.isString(commit.parent)) { + if (typeof commit.parent === 'string') { svgDrawLineForCommits(svg, commit.id, commit.parent, direction, branchColor) commit.lineDrawn = true commit = allCommitsDict[commit.parent] - } else if (_.isArray(commit.parent)) { + } else if (Array.isArray(commit.parent)) { svgDrawLineForCommits(svg, commit.id, commit.parent[0], direction, branchColor) svgDrawLineForCommits(svg, commit.id, commit.parent[1], direction, branchColor + 1) renderLines(svg, allCommitsDict[commit.parent[1]], direction, branchColor + 1) @@ -246,7 +252,7 @@ export const draw = function (txt, id, ver) { // Parse the graph definition parser.parse(txt + '\n') - config = _.extend(config, apiConfig, db.getOptions()) + config = assign(config, apiConfig, db.getOptions()) logger.debug('effective options', config) const direction = db.getDirection() allCommitsDict = db.getCommits() @@ -259,11 +265,12 @@ export const draw = function (txt, id, ver) { const svg = d3.select(`[id="${id}"]`) svgCreateDefs(svg) branchNum = 1 - _.each(branches, function (v) { + for (let branch in branches) { + const v = branches[branch] renderCommitHistory(svg, v.commit.id, branches, direction) renderLines(svg, v.commit, direction) branchNum++ - }) + } svg.attr('height', function () { if (direction === 'BT') return Object.keys(allCommitsDict).length * config.nodeSpacing return (branches.length + 1) * config.branchOffset diff --git a/yarn.lock b/yarn.lock index 05126cf55..e0acdf892 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5163,11 +5163,21 @@ lodash.keys@^3.0.0: lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" +lodash.maxby@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.maxby/-/lodash.maxby-4.6.0.tgz#082240068f3c7a227aa00a8380e4f38cf0786e3d" + integrity sha1-CCJABo88eiJ6oAqDgOTzjPB4bj0= + lodash.mergewith@^4.6.0: version "4.6.1" resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927" integrity sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ== +lodash.orderby@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.orderby/-/lodash.orderby-4.6.0.tgz#e697f04ce5d78522f54d9338b32b81a3393e4eb3" + integrity sha1-5pfwTOXXhSL1TZM4syuBozk+TrM= + lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" @@ -5203,6 +5213,11 @@ lodash.templatesettings@^3.0.0: lodash._reinterpolate "^3.0.0" lodash.escape "^3.0.0" +lodash.uniqby@^4.7.0: + version "4.7.0" + resolved "https://registry.yarnpkg.com/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz#d99c07a669e9e6d24e1362dfe266c67616af1302" + integrity sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI= + lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.3.0, lodash@~4.17.10: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"