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