6
6
Branch ,
7
7
Coordinate ,
8
8
MergeStyle ,
9
- OrientationsEnum ,
10
9
} from "gitgraph-core/lib/index" ;
11
- import { toSvgPath } from "gitgraph-core/lib/utils" ;
10
+ import { toSvgPath , arrowSvgPath } from "gitgraph-core/lib/utils" ;
12
11
13
12
export interface GitgraphProps {
14
13
options ?: GitgraphOptions ;
@@ -144,17 +143,8 @@ export class Gitgraph extends React.Component<GitgraphProps, GitgraphState> {
144
143
) ) ;
145
144
}
146
145
147
- // TODO: extract arrow logic into its own file
148
146
private drawArrow ( parent : Commit , commit : Commit ) {
149
147
const commitRadius = commit . style . dot . size ;
150
- const size = this . gitgraph . template . arrow . size ! ;
151
- const h = commitRadius + this . gitgraph . template . arrow . offset ;
152
-
153
- // Delta between left & right (radian)
154
- const delta = Math . PI / 7 ;
155
-
156
- // Alpha angle between parent & commit (radian)
157
- const alpha = getAlpha ( this . gitgraph , parent , commit ) ;
158
148
159
149
// Starting point, relative to commit
160
150
const origin = {
@@ -166,26 +156,10 @@ export class Gitgraph extends React.Component<GitgraphProps, GitgraphState> {
166
156
: commitRadius ,
167
157
} ;
168
158
169
- // Top
170
- const x1 = h * Math . cos ( alpha ) ;
171
- const y1 = h * Math . sin ( alpha ) ;
172
-
173
- // Bottom right
174
- const x2 = ( h + size ) * Math . cos ( alpha - delta ) ;
175
- const y2 = ( h + size ) * Math . sin ( alpha - delta ) ;
176
-
177
- // Bottom center
178
- const x3 = ( h + size / 2 ) * Math . cos ( alpha ) ;
179
- const y3 = ( h + size / 2 ) * Math . sin ( alpha ) ;
180
-
181
- // Bottom left
182
- const x4 = ( h + size ) * Math . cos ( alpha + delta ) ;
183
- const y4 = ( h + size ) * Math . sin ( alpha + delta ) ;
184
-
185
159
return (
186
160
< g transform = { `translate(${ origin . x } , ${ origin . y } )` } >
187
161
< path
188
- d = { `M ${ x1 } , ${ y1 } L ${ x2 } , ${ y2 } Q ${ x3 } , ${ y3 } ${ x4 } , ${ y4 } L ${ x4 } , ${ y4 } ` }
162
+ d = { arrowSvgPath ( this . gitgraph , parent , commit ) }
189
163
fill = { this . gitgraph . template . arrow . color ! }
190
164
/>
191
165
</ g >
@@ -227,71 +201,5 @@ export class Gitgraph extends React.Component<GitgraphProps, GitgraphState> {
227
201
}
228
202
}
229
203
230
- function getAlpha ( graph : GitgraphCore , parent : Commit , commit : Commit ) : number {
231
- const deltaX = parent . x - commit . x ;
232
- const deltaY = parent . y - commit . y ;
233
- const commitSpacing = graph . template . commit . spacing ;
234
-
235
- let alphaY ;
236
- let alphaX ;
237
-
238
- // Angle always start from previous commit Y position:
239
- //
240
- // o
241
- // ↑ ↖ ︎
242
- // o | <-- path is straight until last commit Y position
243
- // ↑ o
244
- // | ↗︎
245
- // o
246
- //
247
- // So we need to default to commit spacing.
248
- // For horizontal orientation => same with commit X position.
249
- switch ( graph . orientation ) {
250
- case OrientationsEnum . Horizontal :
251
- alphaY = deltaY ;
252
- alphaX = - commitSpacing ;
253
- break ;
254
-
255
- case OrientationsEnum . HorizontalReverse :
256
- alphaY = deltaY ;
257
- alphaX = commitSpacing ;
258
- break ;
259
-
260
- case OrientationsEnum . VerticalReverse :
261
- alphaY = - commitSpacing ;
262
- alphaX = deltaX ;
263
- break ;
264
-
265
- default :
266
- alphaY = commitSpacing ;
267
- alphaX = deltaX ;
268
- break ;
269
- }
270
-
271
- if ( graph . reverseArrow ) {
272
- alphaY *= - 1 ;
273
- alphaX *= - 1 ;
274
-
275
- // If arrow is reverse, the previous commit position is considered
276
- // the same on the straight part of the curved path.
277
- //
278
- // o
279
- // ↓ \
280
- // o ↓ <-- arrow is like previous commit was on same X position
281
- // | o
282
- // ↓ ↙︎
283
- // o
284
- //
285
- // For horizontal orientation => same with commit Y position.
286
- if ( graph . isVertical ) {
287
- if ( Math . abs ( deltaY ) > commitSpacing ) alphaX = 0 ;
288
- } else {
289
- if ( Math . abs ( deltaX ) > commitSpacing ) alphaY = 0 ;
290
- }
291
- }
292
-
293
- return Math . atan2 ( alphaY , alphaX ) ;
294
- }
295
-
296
204
export default Gitgraph ;
297
205
export * from "gitgraph-core/lib/index" ;
0 commit comments