Skip to content

Commit 92a8e77

Browse files
committed
v.0.3.2
1 parent 4bcdfbe commit 92a8e77

File tree

4 files changed

+58
-34
lines changed

4 files changed

+58
-34
lines changed

dist/vivus.js

+45-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* vivus - JavaScript library to make drawing animation on SVG
3-
* @version v0.3.1
3+
* @version v0.3.2
44
* @link https://github.com/maxwellito/vivus
55
* @license MIT
66
*/
@@ -61,7 +61,7 @@ Pathformer.prototype.TYPES = ['line', 'ellipse', 'circle', 'polygon', 'polyline'
6161
/**
6262
* List of attribute names which contain
6363
* data. This array list them to check if
64-
* they contain bad values, like percentage.
64+
* they contain bad values, like percentage.
6565
*
6666
* @type {Array}
6767
*/
@@ -75,7 +75,8 @@ Pathformer.prototype.ATTR_WATCH = ['cx', 'cy', 'points', 'r', 'rx', 'ry', 'x', '
7575
*/
7676
Pathformer.prototype.scan = function (svg) {
7777
var fn, element, pathData, pathDom,
78-
elements = svg.querySelectorAll(this.TYPES.join(','));
78+
elements = svg.querySelectorAll(this.TYPES.join(','));
79+
7980
for (var i = 0; i < elements.length; i++) {
8081
element = elements[i];
8182
fn = this[element.tagName.toLowerCase() + 'ToPath'];
@@ -94,8 +95,13 @@ Pathformer.prototype.scan = function (svg) {
9495
* @return {object} Data for a `path` element
9596
*/
9697
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;
99105
return newElement;
100106
};
101107

@@ -110,10 +116,11 @@ Pathformer.prototype.lineToPath = function (element) {
110116
*/
111117
Pathformer.prototype.rectToPath = function (element) {
112118
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+
117124
newElement.d = 'M' + x + ' ' + y + ' ';
118125
newElement.d += 'L' + (x + width) + ' ' + y + ' ';
119126
newElement.d += 'L' + (x + width) + ' ' + (y + height) + ' ';
@@ -129,10 +136,10 @@ Pathformer.prototype.rectToPath = function (element) {
129136
* @return {object} Data for a `path` element
130137
*/
131138
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+
136143
// Reformatting if points are defined without commas
137144
if (element.points.indexOf(',') === -1) {
138145
var formattedPoints = [];
@@ -165,6 +172,7 @@ Pathformer.prototype.polylineToPath = function (element) {
165172
*/
166173
Pathformer.prototype.polygonToPath = function (element) {
167174
var newElement = Pathformer.prototype.polylineToPath(element);
175+
168176
newElement.d += 'Z';
169177
return newElement;
170178
};
@@ -177,15 +185,19 @@ Pathformer.prototype.polygonToPath = function (element) {
177185
* @return {object} Data for a `path` element
178186
*/
179187
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;
184197

185-
var newElement = {};
186198
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;
189201
return newElement;
190202
};
191203

@@ -197,14 +209,18 @@ Pathformer.prototype.ellipseToPath = function (element) {
197209
* @return {object} Data for a `path` element
198210
*/
199211
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+
205221
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;
208224
return newElement;
209225
};
210226

@@ -458,7 +474,8 @@ Vivus.prototype.setOptions = function (options) {
458474
this.forceRender = options.hasOwnProperty('forceRender') ? !!options.forceRender : this.isIE;
459475
this.selfDestroy = !!options.selfDestroy;
460476
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;
462479

463480
this.ignoreInvisible = options.hasOwnProperty('ignoreInvisible') ? !!options.ignoreInvisible : false;
464481

0 commit comments

Comments
 (0)