@@ -40,7 +40,11 @@ module.exports = Element.extend({
40
40
var closePath = me . _loop ;
41
41
var index , previous , currentVM ;
42
42
43
- if ( me . _loop && points . length ) {
43
+ if ( ! points . length ) {
44
+ return ;
45
+ }
46
+
47
+ if ( me . _loop ) {
44
48
for ( index = 0 ; index < points . length ; ++ index ) {
45
49
previous = helpers . previousItem ( points , index ) ;
46
50
// If the line has an open path, shift the point array
@@ -73,31 +77,27 @@ module.exports = Element.extend({
73
77
74
78
// Stroke Line
75
79
ctx . beginPath ( ) ;
76
- lastDrawnIndex = - 1 ;
77
80
78
- for ( index = 0 ; index < points . length ; ++ index ) {
79
- previous = helpers . previousItem ( points , index ) ;
81
+ // First point moves to it's starting position no matter what
82
+ currentVM = points [ 0 ] . _view ;
83
+ if ( ! currentVM . skip ) {
84
+ ctx . moveTo ( currentVM . x , currentVM . y ) ;
85
+ lastDrawnIndex = 0 ;
86
+ }
87
+
88
+ for ( index = 1 ; index < points . length ; ++ index ) {
80
89
currentVM = points [ index ] . _view ;
90
+ previous = lastDrawnIndex === - 1 ? helpers . previousItem ( points , index ) : points [ lastDrawnIndex ] ;
81
91
82
- // First point moves to it's starting position no matter what
83
- if ( index === 0 ) {
84
- if ( ! currentVM . skip ) {
92
+ if ( ! currentVM . skip ) {
93
+ if ( ( lastDrawnIndex !== ( index - 1 ) && ! spanGaps ) || lastDrawnIndex === - 1 ) {
94
+ // There was a gap and this is the first point after the gap
85
95
ctx . moveTo ( currentVM . x , currentVM . y ) ;
86
- lastDrawnIndex = index ;
87
- }
88
- } else {
89
- previous = lastDrawnIndex === - 1 ? previous : points [ lastDrawnIndex ] ;
90
-
91
- if ( ! currentVM . skip ) {
92
- if ( ( lastDrawnIndex !== ( index - 1 ) && ! spanGaps ) || lastDrawnIndex === - 1 ) {
93
- // There was a gap and this is the first point after the gap
94
- ctx . moveTo ( currentVM . x , currentVM . y ) ;
95
- } else {
96
- // Line to next point
97
- helpers . canvas . lineTo ( ctx , previous . _view , currentVM ) ;
98
- }
99
- lastDrawnIndex = index ;
96
+ } else {
97
+ // Line to next point
98
+ helpers . canvas . lineTo ( ctx , previous . _view , currentVM ) ;
100
99
}
100
+ lastDrawnIndex = index ;
101
101
}
102
102
}
103
103
0 commit comments