1
1
/**
2
2
* vivus - JavaScript library to make drawing animation on SVG
3
- * @version v0.3.1
3
+ * @version v0.3.2
4
4
* @link https://github.com/maxwellito/vivus
5
5
* @license MIT
6
6
*/
@@ -61,7 +61,7 @@ Pathformer.prototype.TYPES = ['line', 'ellipse', 'circle', 'polygon', 'polyline'
61
61
/**
62
62
* List of attribute names which contain
63
63
* data. This array list them to check if
64
- * they contain bad values, like percentage.
64
+ * they contain bad values, like percentage.
65
65
*
66
66
* @type {Array }
67
67
*/
@@ -75,7 +75,8 @@ Pathformer.prototype.ATTR_WATCH = ['cx', 'cy', 'points', 'r', 'rx', 'ry', 'x', '
75
75
*/
76
76
Pathformer . prototype . scan = function ( svg ) {
77
77
var fn , element , pathData , pathDom ,
78
- elements = svg . querySelectorAll ( this . TYPES . join ( ',' ) ) ;
78
+ elements = svg . querySelectorAll ( this . TYPES . join ( ',' ) ) ;
79
+
79
80
for ( var i = 0 ; i < elements . length ; i ++ ) {
80
81
element = elements [ i ] ;
81
82
fn = this [ element . tagName . toLowerCase ( ) + 'ToPath' ] ;
@@ -94,8 +95,13 @@ Pathformer.prototype.scan = function (svg) {
94
95
* @return {object } Data for a `path` element
95
96
*/
96
97
Pathformer . prototype . lineToPath = function ( element ) {
97
- var newElement = { } ;
98
- newElement . d = 'M' + element . x1 + ',' + element . y1 + 'L' + element . x2 + ',' + element . y2 ;
98
+ var newElement = { } ,
99
+ x1 = element . x1 || 0 ,
100
+ y1 = element . y1 || 0 ,
101
+ x2 = element . x2 || 0 ,
102
+ y2 = element . y2 || 0 ;
103
+
104
+ newElement . d = 'M' + x1 + ',' + y1 + 'L' + x2 + ',' + y2 ;
99
105
return newElement ;
100
106
} ;
101
107
@@ -110,10 +116,11 @@ Pathformer.prototype.lineToPath = function (element) {
110
116
*/
111
117
Pathformer . prototype . rectToPath = function ( element ) {
112
118
var newElement = { } ,
113
- x = parseFloat ( element . x ) || 0 ,
114
- y = parseFloat ( element . y ) || 0 ,
115
- width = parseFloat ( element . width ) || 0 ,
116
- height = parseFloat ( element . height ) || 0 ;
119
+ x = parseFloat ( element . x ) || 0 ,
120
+ y = parseFloat ( element . y ) || 0 ,
121
+ width = parseFloat ( element . width ) || 0 ,
122
+ height = parseFloat ( element . height ) || 0 ;
123
+
117
124
newElement . d = 'M' + x + ' ' + y + ' ' ;
118
125
newElement . d += 'L' + ( x + width ) + ' ' + y + ' ' ;
119
126
newElement . d += 'L' + ( x + width ) + ' ' + ( y + height ) + ' ' ;
@@ -129,10 +136,10 @@ Pathformer.prototype.rectToPath = function (element) {
129
136
* @return {object } Data for a `path` element
130
137
*/
131
138
Pathformer . prototype . polylineToPath = function ( element ) {
132
- var i , path ;
133
- var newElement = { } ;
134
- var points = element . points . trim ( ) . split ( ' ' ) ;
135
-
139
+ var newElement = { } ,
140
+ points = element . points . trim ( ) . split ( ' ' ) ,
141
+ i , path ;
142
+
136
143
// Reformatting if points are defined without commas
137
144
if ( element . points . indexOf ( ',' ) === - 1 ) {
138
145
var formattedPoints = [ ] ;
@@ -165,6 +172,7 @@ Pathformer.prototype.polylineToPath = function (element) {
165
172
*/
166
173
Pathformer . prototype . polygonToPath = function ( element ) {
167
174
var newElement = Pathformer . prototype . polylineToPath ( element ) ;
175
+
168
176
newElement . d += 'Z' ;
169
177
return newElement ;
170
178
} ;
@@ -177,15 +185,19 @@ Pathformer.prototype.polygonToPath = function (element) {
177
185
* @return {object } Data for a `path` element
178
186
*/
179
187
Pathformer . prototype . ellipseToPath = function ( element ) {
180
- var startX = element . cx - element . rx ,
181
- startY = element . cy ;
182
- var endX = parseFloat ( element . cx ) + parseFloat ( element . rx ) ,
183
- endY = element . cy ;
188
+ var newElement = { } ,
189
+ rx = parseFloat ( element . rx ) || 0 ,
190
+ ry = parseFloat ( element . ry ) || 0 ,
191
+ cx = parseFloat ( element . cx ) || 0 ,
192
+ cy = parseFloat ( element . cy ) || 0 ,
193
+ startX = cx - rx ,
194
+ startY = cy ,
195
+ endX = parseFloat ( cx ) + parseFloat ( rx ) ,
196
+ endY = cy ;
184
197
185
- var newElement = { } ;
186
198
newElement . d = 'M' + startX + ',' + startY +
187
- 'A' + element . rx + ',' + element . ry + ' 0,1,1 ' + endX + ',' + endY +
188
- 'A' + element . rx + ',' + element . ry + ' 0,1,1 ' + startX + ',' + endY ;
199
+ 'A' + rx + ',' + ry + ' 0,1,1 ' + endX + ',' + endY +
200
+ 'A' + rx + ',' + ry + ' 0,1,1 ' + startX + ',' + endY ;
189
201
return newElement ;
190
202
} ;
191
203
@@ -197,14 +209,18 @@ Pathformer.prototype.ellipseToPath = function (element) {
197
209
* @return {object } Data for a `path` element
198
210
*/
199
211
Pathformer . prototype . circleToPath = function ( element ) {
200
- var newElement = { } ;
201
- var startX = element . cx - element . r ,
202
- startY = element . cy ;
203
- var endX = parseFloat ( element . cx ) + parseFloat ( element . r ) ,
204
- endY = element . cy ;
212
+ var newElement = { } ,
213
+ r = parseFloat ( element . r ) || 0 ,
214
+ cx = parseFloat ( element . cx ) || 0 ,
215
+ cy = parseFloat ( element . cy ) || 0 ,
216
+ startX = cx - r ,
217
+ startY = cy ,
218
+ endX = parseFloat ( cx ) + parseFloat ( r ) ,
219
+ endY = cy ;
220
+
205
221
newElement . d = 'M' + startX + ',' + startY +
206
- 'A' + element . r + ',' + element . r + ' 0,1,1 ' + endX + ',' + endY +
207
- 'A' + element . r + ',' + element . r + ' 0,1,1 ' + startX + ',' + endY ;
222
+ 'A' + r + ',' + r + ' 0,1,1 ' + endX + ',' + endY +
223
+ 'A' + r + ',' + r + ' 0,1,1 ' + startX + ',' + endY ;
208
224
return newElement ;
209
225
} ;
210
226
@@ -458,7 +474,8 @@ Vivus.prototype.setOptions = function (options) {
458
474
this . forceRender = options . hasOwnProperty ( 'forceRender' ) ? ! ! options . forceRender : this . isIE ;
459
475
this . selfDestroy = ! ! options . selfDestroy ;
460
476
this . onReady = options . onReady ;
461
- this . frameLength = this . currentFrame = this . map = this . delayUnit = this . speed = this . handle = null ;
477
+ this . map = new Array ( ) ;
478
+ this . frameLength = this . currentFrame = this . delayUnit = this . speed = this . handle = null ;
462
479
463
480
this . ignoreInvisible = options . hasOwnProperty ( 'ignoreInvisible' ) ? ! ! options . ignoreInvisible : false ;
464
481
0 commit comments