@@ -125,7 +125,20 @@ var gitGraph = function (canvas, rawGraphList, config) {
125
125
! ( row [ i - 2 ] && row [ i ] === "_" && row [ i - 2 ] === "|" ) ) { }
126
126
127
127
return i ;
128
- }
128
+ } ;
129
+
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
+ } ;
129
142
130
143
var genNewFlow = function ( ) {
131
144
var newId ;
@@ -137,21 +150,21 @@ var gitGraph = function (canvas, rawGraphList, config) {
137
150
return { id :newId , color :"#" + newId } ;
138
151
} ;
139
152
140
- //draw method
141
- var drawLineRight = function ( x , y , color ) {
153
+ //Draw methods
154
+ var drawLine = function ( moveX , moveY , lineX , lineY , color ) {
142
155
ctx . strokeStyle = color ;
143
156
ctx . beginPath ( ) ;
144
- ctx . moveTo ( x , y + config . unitSize / 2 ) ;
145
- ctx . lineTo ( x + config . unitSize , y + config . unitSize / 2 ) ;
157
+ ctx . moveTo ( moveX , moveY ) ;
158
+ ctx . lineTo ( lineX , lineY ) ;
146
159
ctx . stroke ( ) ;
147
160
} ;
148
161
162
+ var drawLineRight = function ( x , y , color ) {
163
+ drawLine ( x , y + config . unitSize / 2 , x + config . unitSize , y + config . unitSize / 2 , color ) ;
164
+ } ;
165
+
149
166
var drawLineUp = function ( x , y , color ) {
150
- ctx . strokeStyle = color ;
151
- ctx . beginPath ( ) ;
152
- ctx . moveTo ( x , y + config . unitSize / 2 ) ;
153
- ctx . lineTo ( x , y - config . unitSize / 2 ) ;
154
- ctx . stroke ( ) ;
167
+ drawLine ( x , y + config . unitSize / 2 , x , y - config . unitSize / 2 , color ) ;
155
168
} ;
156
169
157
170
var drawNode = function ( x , y , color ) {
@@ -165,37 +178,28 @@ var gitGraph = function (canvas, rawGraphList, config) {
165
178
} ;
166
179
167
180
var drawLineIn = function ( x , y , color ) {
168
- ctx . strokeStyle = color ;
169
-
170
- ctx . beginPath ( ) ;
171
- ctx . moveTo ( x + config . unitSize , y + config . unitSize / 2 ) ;
172
- ctx . lineTo ( x , y - config . unitSize / 2 ) ;
173
- ctx . stroke ( ) ;
181
+ drawLine ( x + config . unitSize , y + config . unitSize / 2 , x , y - config . unitSize / 2 , color ) ;
174
182
} ;
175
183
176
184
var drawLineOut = function ( x , y , color ) {
177
- ctx . strokeStyle = color ;
178
- ctx . beginPath ( ) ;
179
- ctx . moveTo ( x , y + config . unitSize / 2 ) ;
180
- ctx . lineTo ( x + config . unitSize , y - config . unitSize / 2 ) ;
181
- ctx . stroke ( ) ;
185
+ drawLine ( x , y + config . unitSize / 2 , x + config . unitSize , y - config . unitSize / 2 , color ) ;
182
186
} ;
183
187
184
188
var draw = function ( graphList ) {
185
- var colomn , colomnIndex , prevColomn , condenseIndex ;
189
+ var colomn , colomnIndex , prevColomn , condenseIndex , breakIndex = - 1 ;
186
190
var x , y ;
187
191
var color ;
188
- var nodePos , outPos ;
192
+ var nodePos ;
189
193
var tempFlow ;
190
194
var prevRowLength = 0 ;
191
195
var flowSwapPos = - 1 ;
192
196
var lastLinePos ;
193
- var i , k , l ;
197
+ var i , l ;
194
198
var condenseCurrentLength , condensePrevLength = 0 , condenseNextLength = 0 ;
195
199
196
200
var inlineIntersect = false ;
197
201
198
- //initiate for first row
202
+ //initiate color array for first row
199
203
for ( i = 0 , l = graphList [ 0 ] . length ; i < l ; i ++ ) {
200
204
if ( graphList [ 0 ] [ i ] !== "_" && graphList [ 0 ] [ i ] !== " " ) {
201
205
flows . push ( genNewFlow ( ) ) ;
@@ -274,13 +278,26 @@ var gitGraph = function (canvas, rawGraphList, config) {
274
278
colomnIndex = 0 ; //reset index
275
279
condenseIndex = 0 ;
276
280
condensePrevLength = 0 ;
281
+ breakIndex = - 1 ; //reset break index
277
282
while ( colomnIndex < currentRow . length ) {
278
283
colomn = currentRow [ colomnIndex ] ;
279
284
280
285
if ( colomn !== " " && colomn !== "_" ) {
281
286
++ condensePrevLength ;
282
287
}
283
288
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
+
284
301
if ( colomn === " " &&
285
302
currentRow [ colomnIndex + 1 ] &&
286
303
currentRow [ colomnIndex + 1 ] === "_" &&
@@ -293,7 +310,7 @@ var gitGraph = function (canvas, rawGraphList, config) {
293
310
colomn = "/" ;
294
311
}
295
312
296
- //create new flow only when no intersetc happened
313
+ //create new flow only when no intersect happened
297
314
if ( flowSwapPos === - 1 &&
298
315
colomn === "/" &&
299
316
currentRow [ colomnIndex - 1 ] &&
0 commit comments