Skip to content

Commit 521a01c

Browse files
committed
Fixed line break bug bluef#4
1 parent 7b984dd commit 521a01c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

gitgraph.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ var gitGraph = function (canvas, rawGraphList, config) {
127127
return i;
128128
};
129129

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

@@ -173,7 +186,7 @@ var gitGraph = function (canvas, rawGraphList, config) {
173186
};
174187

175188
var draw = function (graphList) {
176-
var colomn, colomnIndex, prevColomn, condenseIndex;
189+
var colomn, colomnIndex, prevColomn, condenseIndex, breakIndex = -1;
177190
var x, y;
178191
var color;
179192
var nodePos;
@@ -265,13 +278,26 @@ var gitGraph = function (canvas, rawGraphList, config) {
265278
colomnIndex = 0; //reset index
266279
condenseIndex = 0;
267280
condensePrevLength = 0;
281+
breakIndex = -1; //reset break index
268282
while (colomnIndex < currentRow.length) {
269283
colomn = currentRow[colomnIndex];
270284

271285
if (colomn !== " " && colomn !== "_") {
272286
++condensePrevLength;
273287
}
274288

289+
//check and fix line break in next row
290+
if (colomn === "/" && currentRow[colomnIndex - 1] && currentRow[colomnIndex - 1] === "|") {
291+
if ((breakIndex = findLineBreak(nextRow)) !== -1) {
292+
nextRow.splice(breakIndex, 1);
293+
}
294+
}
295+
//if line break found replace all '/' with '|' after breakIndex in previous row
296+
if (breakIndex !== - 1 && colomn === "/" && colomnIndex > breakIndex) {
297+
currentRow[colomnIndex] = "|";
298+
colomn = "|";
299+
}
300+
275301
if (colomn === " " &&
276302
currentRow[colomnIndex + 1] &&
277303
currentRow[colomnIndex + 1] === "_" &&

0 commit comments

Comments
 (0)