@@ -29,26 +29,23 @@ var ARROWPATHS = require('./arrow_paths');
29
29
* @param {number } options.standoff: distance in px to move the arrow point from its target
30
30
*/
31
31
module . exports = function drawArrowHead ( el3 , ends , options ) {
32
- var el = el3 . node ( ) ,
33
- headStyle = ARROWPATHS [ options . arrowhead || 0 ] ;
34
-
35
- var scale = ( Drawing . getPx ( el3 , 'stroke-width' ) || 1 ) * options . arrowsize ,
36
- stroke = el3 . style ( 'stroke' ) || Color . defaultLine ,
37
- opacity = el3 . style ( 'stroke-opacity' ) || 1 ,
38
- doStart = ends . indexOf ( 'start' ) >= 0 ,
39
- doEnd = ends . indexOf ( 'end' ) >= 0 ,
40
- backOff = headStyle . backoff * scale + options . standoff ,
41
- start ,
42
- end ,
43
- startRot ,
44
- endRot ;
32
+ var el = el3 . node ( ) ;
33
+ var headStyle = ARROWPATHS [ options . arrowhead || 0 ] ;
34
+ var scale = ( Drawing . getPx ( el3 , 'stroke-width' ) || 1 ) * options . arrowsize ;
35
+ var stroke = el3 . style ( 'stroke' ) || Color . defaultLine ;
36
+ var opacity = el3 . style ( 'stroke-opacity' ) || 1 ;
37
+ var doStart = ends . indexOf ( 'start' ) >= 0 ;
38
+ var doEnd = ends . indexOf ( 'end' ) >= 0 ;
39
+ var backOff = headStyle . backoff * scale + options . standoff ;
40
+
41
+ var start , end , startRot , endRot ;
45
42
46
43
if ( el . nodeName === 'line' ) {
47
44
start = { x : + el3 . attr ( 'x1' ) , y : + el3 . attr ( 'y1' ) } ;
48
45
end = { x : + el3 . attr ( 'x2' ) , y : + el3 . attr ( 'y2' ) } ;
49
46
50
- var dx = start . x - end . x ,
51
- dy = start . y - end . y ;
47
+ var dx = start . x - end . x ;
48
+ var dy = start . y - end . y ;
52
49
53
50
startRot = Math . atan2 ( dy , dx ) ;
54
51
endRot = startRot + Math . PI ;
@@ -86,16 +83,19 @@ module.exports = function drawArrowHead(el3, ends, options) {
86
83
}
87
84
88
85
if ( doStart ) {
89
- var start0 = el . getPointAtLength ( 0 ) ,
90
- dstart = el . getPointAtLength ( 0.1 ) ;
86
+ var start0 = el . getPointAtLength ( 0 ) ;
87
+ var dstart = el . getPointAtLength ( 0.1 ) ;
88
+
91
89
startRot = Math . atan2 ( start0 . y - dstart . y , start0 . x - dstart . x ) ;
92
90
start = el . getPointAtLength ( Math . min ( backOff , pathlen ) ) ;
91
+
93
92
if ( backOff ) dashArray = '0px,' + backOff + 'px,' ;
94
93
}
95
94
96
95
if ( doEnd ) {
97
- var end0 = el . getPointAtLength ( pathlen ) ,
98
- dend = el . getPointAtLength ( pathlen - 0.1 ) ;
96
+ var end0 = el . getPointAtLength ( pathlen ) ;
97
+ var dend = el . getPointAtLength ( pathlen - 0.1 ) ;
98
+
99
99
endRot = Math . atan2 ( end0 . y - dend . y , end0 . x - dend . x ) ;
100
100
end = el . getPointAtLength ( Math . max ( 0 , pathlen - backOff ) ) ;
101
101
@@ -114,6 +114,7 @@ module.exports = function drawArrowHead(el3, ends, options) {
114
114
function drawhead ( p , rot ) {
115
115
if ( ! headStyle . path ) return ;
116
116
if ( options . arrowhead > 5 ) rot = 0 ; // don't rotate square or circle
117
+
117
118
d3 . select ( el . parentNode ) . append ( 'path' )
118
119
. attr ( {
119
120
'class' : el3 . attr ( 'class' ) ,
0 commit comments