Skip to content

Commit

Permalink
Update gitgraph.js to fix "Cannot read property color of undefined" (g…
Browse files Browse the repository at this point in the history
…o-gitea#4095)

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
  • Loading branch information
axifive authored and lafriks committed Jun 2, 2018
1 parent 9a1772b commit 7893e59
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion public/vendor/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ File(s): /vendor/plugins/clipboard/clipboard.min.js
Version: 1.5.9

File(s): /vendor/plugins/gitgraph/gitgraph.js
Version: 9b492e8bf1ddf7908a4997b8f83fa38a809a9da3
Version: 745f604212e2abfe2f0a59169ea530857b46625c

File(s): /vendor/plugins/vue/vue.min.js
Version: 2.1.10
Expand Down
71 changes: 44 additions & 27 deletions public/vendor/plugins/gitgraph/gitgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,20 @@ var gitGraph = function (canvas, rawGraphList, config) {
!(row[i - 2] && row[i] === "_" && row[i - 2] === "|")) {}

return i;
}
};

var findLineBreak = function (row) {
if (!row) {
return -1
}

var i = row.length;

while (i-- &&
!(row[i - 1] && row[i - 2] && row[i] === " " && row[i - 1] === "|" && row[i - 2] === "_")) {}

return i;
};

var genNewFlow = function () {
var newId;
Expand All @@ -138,21 +151,21 @@ var gitGraph = function (canvas, rawGraphList, config) {
return {id:newId, color:"#" + newId};
};

//draw method
var drawLineRight = function (x, y, color) {
//Draw methods
var drawLine = function (moveX, moveY, lineX, lineY, color) {
ctx.strokeStyle = color;
ctx.beginPath();
ctx.moveTo(x, y + config.unitSize / 2);
ctx.lineTo(x + config.unitSize, y + config.unitSize / 2);
ctx.moveTo(moveX, moveY);
ctx.lineTo(lineX, lineY);
ctx.stroke();
};

var drawLineRight = function (x, y, color) {
drawLine(x, y + config.unitSize / 2, x + config.unitSize, y + config.unitSize / 2, color);
};

var drawLineUp = function (x, y, color) {
ctx.strokeStyle = color;
ctx.beginPath();
ctx.moveTo(x, y + config.unitSize / 2);
ctx.lineTo(x, y - config.unitSize / 2);
ctx.stroke();
drawLine(x, y + config.unitSize / 2, x, y - config.unitSize / 2, color);
};

var drawNode = function (x, y, color) {
Expand All @@ -166,37 +179,28 @@ var gitGraph = function (canvas, rawGraphList, config) {
};

var drawLineIn = function (x, y, color) {
ctx.strokeStyle = color;

ctx.beginPath();
ctx.moveTo(x + config.unitSize, y + config.unitSize / 2);
ctx.lineTo(x, y - config.unitSize / 2);
ctx.stroke();
drawLine(x + config.unitSize, y + config.unitSize / 2, x, y - config.unitSize / 2, color);
};

var drawLineOut = function (x, y, color) {
ctx.strokeStyle = color;
ctx.beginPath();
ctx.moveTo(x, y + config.unitSize / 2);
ctx.lineTo(x + config.unitSize, y - config.unitSize / 2);
ctx.stroke();
drawLine(x, y + config.unitSize / 2, x + config.unitSize, y - config.unitSize / 2, color);
};

var draw = function (graphList) {
var colomn, colomnIndex, prevColomn, condenseIndex;
var colomn, colomnIndex, prevColomn, condenseIndex, breakIndex = -1;
var x, y;
var color;
var nodePos, outPos;
var nodePos;
var tempFlow;
var prevRowLength = 0;
var flowSwapPos = -1;
var lastLinePos;
var i, k, l;
var i, l;
var condenseCurrentLength, condensePrevLength = 0, condenseNextLength = 0;

var inlineIntersect = false;

//initiate for first row
//initiate color array for first row
for (i = 0, l = graphList[0].length; i < l; i++) {
if (graphList[0][i] !== "_" && graphList[0][i] !== " ") {
flows.push(genNewFlow());
Expand Down Expand Up @@ -275,13 +279,26 @@ var gitGraph = function (canvas, rawGraphList, config) {
colomnIndex = 0; //reset index
condenseIndex = 0;
condensePrevLength = 0;
breakIndex = -1; //reset break index
while (colomnIndex < currentRow.length) {
colomn = currentRow[colomnIndex];

if (colomn !== " " && colomn !== "_") {
++condensePrevLength;
}

//check and fix line break in next row
if (colomn === "/" && currentRow[colomnIndex - 1] && currentRow[colomnIndex - 1] === "|") {
if ((breakIndex = findLineBreak(nextRow)) !== -1) {
nextRow.splice(breakIndex, 1);
}
}
//if line break found replace all '/' with '|' after breakIndex in previous row
if (breakIndex !== - 1 && colomn === "/" && colomnIndex > breakIndex) {
currentRow[colomnIndex] = "|";
colomn = "|";
}

if (colomn === " " &&
currentRow[colomnIndex + 1] &&
currentRow[colomnIndex + 1] === "_" &&
Expand All @@ -294,7 +311,7 @@ var gitGraph = function (canvas, rawGraphList, config) {
colomn = "/";
}

//create new flow only when no intersetc happened
//create new flow only when no intersect happened
if (flowSwapPos === -1 &&
colomn === "/" &&
currentRow[colomnIndex - 1] &&
Expand Down Expand Up @@ -415,4 +432,4 @@ var gitGraph = function (canvas, rawGraphList, config) {
init();
draw(graphList);
};
// @end-license
// @end-license

0 comments on commit 7893e59

Please sign in to comment.