Skip to content

Commit 7893e59

Browse files
axifivelafriks
authored andcommitted
Update gitgraph.js to fix "Cannot read property color of undefined" (#4095)
Signed-off-by: Alexey Terentyev <[email protected]>
1 parent 9a1772b commit 7893e59

File tree

2 files changed

+45
-28
lines changed

2 files changed

+45
-28
lines changed

public/vendor/VERSIONS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ File(s): /vendor/plugins/clipboard/clipboard.min.js
1515
Version: 1.5.9
1616

1717
File(s): /vendor/plugins/gitgraph/gitgraph.js
18-
Version: 9b492e8bf1ddf7908a4997b8f83fa38a809a9da3
18+
Version: 745f604212e2abfe2f0a59169ea530857b46625c
1919

2020
File(s): /vendor/plugins/vue/vue.min.js
2121
Version: 2.1.10

public/vendor/plugins/gitgraph/gitgraph.js

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,20 @@ var gitGraph = function (canvas, rawGraphList, config) {
126126
!(row[i - 2] && row[i] === "_" && row[i - 2] === "|")) {}
127127

128128
return i;
129-
}
129+
};
130+
131+
var findLineBreak = function (row) {
132+
if (!row) {
133+
return -1
134+
}
135+
136+
var i = row.length;
137+
138+
while (i-- &&
139+
!(row[i - 1] && row[i - 2] && row[i] === " " && row[i - 1] === "|" && row[i - 2] === "_")) {}
140+
141+
return i;
142+
};
130143

131144
var genNewFlow = function () {
132145
var newId;
@@ -138,21 +151,21 @@ var gitGraph = function (canvas, rawGraphList, config) {
138151
return {id:newId, color:"#" + newId};
139152
};
140153

141-
//draw method
142-
var drawLineRight = function (x, y, color) {
154+
//Draw methods
155+
var drawLine = function (moveX, moveY, lineX, lineY, color) {
143156
ctx.strokeStyle = color;
144157
ctx.beginPath();
145-
ctx.moveTo(x, y + config.unitSize / 2);
146-
ctx.lineTo(x + config.unitSize, y + config.unitSize / 2);
158+
ctx.moveTo(moveX, moveY);
159+
ctx.lineTo(lineX, lineY);
147160
ctx.stroke();
148161
};
149162

163+
var drawLineRight = function (x, y, color) {
164+
drawLine(x, y + config.unitSize / 2, x + config.unitSize, y + config.unitSize / 2, color);
165+
};
166+
150167
var drawLineUp = function (x, y, color) {
151-
ctx.strokeStyle = color;
152-
ctx.beginPath();
153-
ctx.moveTo(x, y + config.unitSize / 2);
154-
ctx.lineTo(x, y - config.unitSize / 2);
155-
ctx.stroke();
168+
drawLine(x, y + config.unitSize / 2, x, y - config.unitSize / 2, color);
156169
};
157170

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

168181
var drawLineIn = function (x, y, color) {
169-
ctx.strokeStyle = color;
170-
171-
ctx.beginPath();
172-
ctx.moveTo(x + config.unitSize, y + config.unitSize / 2);
173-
ctx.lineTo(x, y - config.unitSize / 2);
174-
ctx.stroke();
182+
drawLine(x + config.unitSize, y + config.unitSize / 2, x, y - config.unitSize / 2, color);
175183
};
176184

177185
var drawLineOut = function (x, y, color) {
178-
ctx.strokeStyle = color;
179-
ctx.beginPath();
180-
ctx.moveTo(x, y + config.unitSize / 2);
181-
ctx.lineTo(x + config.unitSize, y - config.unitSize / 2);
182-
ctx.stroke();
186+
drawLine(x, y + config.unitSize / 2, x + config.unitSize, y - config.unitSize / 2, color);
183187
};
184188

185189
var draw = function (graphList) {
186-
var colomn, colomnIndex, prevColomn, condenseIndex;
190+
var colomn, colomnIndex, prevColomn, condenseIndex, breakIndex = -1;
187191
var x, y;
188192
var color;
189-
var nodePos, outPos;
193+
var nodePos;
190194
var tempFlow;
191195
var prevRowLength = 0;
192196
var flowSwapPos = -1;
193197
var lastLinePos;
194-
var i, k, l;
198+
var i, l;
195199
var condenseCurrentLength, condensePrevLength = 0, condenseNextLength = 0;
196200

197201
var inlineIntersect = false;
198202

199-
//initiate for first row
203+
//initiate color array for first row
200204
for (i = 0, l = graphList[0].length; i < l; i++) {
201205
if (graphList[0][i] !== "_" && graphList[0][i] !== " ") {
202206
flows.push(genNewFlow());
@@ -275,13 +279,26 @@ var gitGraph = function (canvas, rawGraphList, config) {
275279
colomnIndex = 0; //reset index
276280
condenseIndex = 0;
277281
condensePrevLength = 0;
282+
breakIndex = -1; //reset break index
278283
while (colomnIndex < currentRow.length) {
279284
colomn = currentRow[colomnIndex];
280285

281286
if (colomn !== " " && colomn !== "_") {
282287
++condensePrevLength;
283288
}
284289

290+
//check and fix line break in next row
291+
if (colomn === "/" && currentRow[colomnIndex - 1] && currentRow[colomnIndex - 1] === "|") {
292+
if ((breakIndex = findLineBreak(nextRow)) !== -1) {
293+
nextRow.splice(breakIndex, 1);
294+
}
295+
}
296+
//if line break found replace all '/' with '|' after breakIndex in previous row
297+
if (breakIndex !== - 1 && colomn === "/" && colomnIndex > breakIndex) {
298+
currentRow[colomnIndex] = "|";
299+
colomn = "|";
300+
}
301+
285302
if (colomn === " " &&
286303
currentRow[colomnIndex + 1] &&
287304
currentRow[colomnIndex + 1] === "_" &&
@@ -294,7 +311,7 @@ var gitGraph = function (canvas, rawGraphList, config) {
294311
colomn = "/";
295312
}
296313

297-
//create new flow only when no intersetc happened
314+
//create new flow only when no intersect happened
298315
if (flowSwapPos === -1 &&
299316
colomn === "/" &&
300317
currentRow[colomnIndex - 1] &&
@@ -415,4 +432,4 @@ var gitGraph = function (canvas, rawGraphList, config) {
415432
init();
416433
draw(graphList);
417434
};
418-
// @end-license
435+
// @end-license

0 commit comments

Comments
 (0)