@@ -29,26 +29,23 @@ var ARROWPATHS = require('./arrow_paths');
2929 * @param {number } options.standoff: distance in px to move the arrow point from its target
3030 */
3131module . 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 ;
4542
4643 if ( el . nodeName === 'line' ) {
4744 start = { x : + el3 . attr ( 'x1' ) , y : + el3 . attr ( 'y1' ) } ;
4845 end = { x : + el3 . attr ( 'x2' ) , y : + el3 . attr ( 'y2' ) } ;
4946
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 ;
5249
5350 startRot = Math . atan2 ( dy , dx ) ;
5451 endRot = startRot + Math . PI ;
@@ -86,16 +83,19 @@ module.exports = function drawArrowHead(el3, ends, options) {
8683 }
8784
8885 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+
9189 startRot = Math . atan2 ( start0 . y - dstart . y , start0 . x - dstart . x ) ;
9290 start = el . getPointAtLength ( Math . min ( backOff , pathlen ) ) ;
91+
9392 if ( backOff ) dashArray = '0px,' + backOff + 'px,' ;
9493 }
9594
9695 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+
9999 endRot = Math . atan2 ( end0 . y - dend . y , end0 . x - dend . x ) ;
100100 end = el . getPointAtLength ( Math . max ( 0 , pathlen - backOff ) ) ;
101101
@@ -114,6 +114,7 @@ module.exports = function drawArrowHead(el3, ends, options) {
114114 function drawhead ( p , rot ) {
115115 if ( ! headStyle . path ) return ;
116116 if ( options . arrowhead > 5 ) rot = 0 ; // don't rotate square or circle
117+
117118 d3 . select ( el . parentNode ) . append ( 'path' )
118119 . attr ( {
119120 'class' : el3 . attr ( 'class' ) ,
0 commit comments