1
0
Fork 0
empact/app/jsx/charts/chart_animation_mixin.jsx

35 lines
1.3 KiB
React
Raw Normal View History

2015-03-13 12:08:13 +00:00
var ChartAnimationMixin = {
animDuration: 350,
animate: function(ref, attr, from, to) {
var node = ref.getDOMNode(),
2015-03-14 08:14:12 +00:00
anim = document.createElementNS('http://www.w3.org/2000/svg', 'animate');
2015-03-13 12:08:13 +00:00
anim.setAttributeNS(null, 'attributeType', 'XML');
anim.setAttributeNS(null, 'attributeName', attr);
anim.setAttributeNS(null, 'values', from +';'+ to);
anim.setAttributeNS(null, 'dur', this.animDuration +'ms');
anim.setAttributeNS(null, 'calcMode', 'spline');
2015-03-14 08:19:09 +00:00
// Easings to consider:
// easeOutCirc: 0.075 0.82 0.165 1
// easeOutBack: 0.175 0.885 0.32 1.275
// easeInOutCubic: 0.645 0.045 0.355 1
2015-03-18 09:53:44 +00:00
// easeOutBack2: 0.15 0.9 0.6 1.07 (more linear, less bouncy)
anim.setAttributeNS(null, 'keySplines', '0.15 0.9 0.6 1.07');
2015-03-13 12:08:13 +00:00
anim.setAttributeNS(null, 'repeatCount', '1');
2015-03-14 08:14:12 +00:00
anim.addEventListener('endEvent', function() {
node.setAttributeNS(null, attr, to);
});
2015-03-13 12:08:13 +00:00
node.appendChild(anim);
2015-03-14 08:14:12 +00:00
2015-03-13 12:08:13 +00:00
anim.beginElement();
},
clearAnimations: function(ref) {
var node = ref.getDOMNode();
2015-03-14 08:53:53 +00:00
while (node.firstChild && node.firstChild.nodeName === 'animate') {
2015-03-13 12:08:13 +00:00
node.removeChild(node.firstChild);
}
}
};