Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false number recomposing and NaN number problem #174

Merged
merged 3 commits into from
Aug 30, 2017

Conversation

agoat
Copy link
Contributor

@agoat agoat commented Jun 1, 2017

This PR fixes two problems.

Fix One
When animating numbers of a path or other number series and the numbers may change from a positive to a negative value, like in the following example, the recomposing of the number string will be wrong.

var ani = anime({
	targets: '#gras',
	d: [
		'M226.07 433.57c1.43-75-73.93-166.07-179.64-208.2',
		'M226.07 433.57c1.43-75 .36-212.5-40.36-350.36',
		'M226.07 433.57c1.43-75 67.5-231.78 233.22-140.36',
		'M226.07 433.57c1.43-75 .36-212.5-40.36-350.36',
		'M226.07 433.57c1.43-75-73.93-166.07-179.64-208.2',
	],
	duration: 3000,
	easing: 'linear',
	loop: true,
})

The problem results in the fact, that the returned string will be recomposed from the tween.to.string array, but the shortest form in a svg image can be no space (separator) but a negative number. So the string array will have '' and when the from number is still positive there is no separator to the following number.

Here is an example of how it will look like:
https://codepen.io/anon/pen/xdvjOM

And here how it will look with my fix:
https://codepen.io/anon/pen/EmqBNv

Second fix
This will avoid the returning of NaN numbers. It will also fix the issue in #167 and maybe #119 and #164.

The problem is that if the length of the tween.from.number array is lower than the tween.to.number array, the value calculation try to calculate with a non existing array value which then results in NaN. So we have to use at least a 0 when calculating.

@juliangarnier juliangarnier changed the base branch from master to 2.1.0 August 30, 2017 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants