Вход Регистрация
Файл: wapxl.ru/top/amcharts/plugins/animate/animate.js
Строк: 435
<?php
/*
Plugin Name: amCharts Animate
Description: Smoothly animates the `dataProvider`
Author: Paul Chapman, amCharts
Version: 1.0.0
Author URI: http://www.amcharts.com/

Copyright 2015 amCharts

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Please note that the above license covers only this plugin. It by all means does
not apply to any other amCharts products that are covered by different licenses.
*/

/* globals AmCharts */
/* jshint -W061 */

( function() {
    
"use strict";


    
// For older browsers, e.g. IE9 and lower
    
if ( typeof requestAnimationFrame === "undefined" ) {
        var 
fps 1000 60;

        var 
raf = function( ) {
            
setTimeout( function() {
                
f( new Date().getTime() );
            }, 
fps );
        };

    } else {
        var 
raf requestAnimationFrame;
    }


    function 
tweentimefromto ) {
        return ( 
time * ( to from ) ) + from;
    }


    function 
easeInOut3) {
        var 
= ( 0.5 : ( ) * );
        
*= r;
        return ( 
0.5 - ( ) );
    }

    function 
easeIn3) {
        
*= t;
        return 
t;
    }

    function 
easeOut3) {
        var 
= ( );
        
*= r;
        return ( 
);
    }


    function 
Tweenobjectkeyfromto ) {
        
this._object object;
        
this._key key;
        
this._from from;
        
this._to to;
    }

    
Tween.prototype.interpolate = function( time ) {
        
this._objectthis._key ] = tweentimethis._fromthis._to );
    };


    function 
AnimationdurationeasingonCompletetweenschart ) {
        
this._finished false;
        
this._startTime null;

        
this._duration duration;
        
this._easing = ( easing == null easeOut3 easing );
        
this._onComplete onComplete;
        
this._tweens tweens;

        
this._chart chart;
    }

    
Animation.prototype.cancel = function() {
        
this._finished true;
        
this._startTime null;

        
this._duration null;
        
this._easing null;
        
this._onComplete null;
        
this._tweens null;

        
this._chart null;
    };

    
Animation.prototype._onFrame = function( now ) {
        
// This will only happen when the animation was cancelled
        
if ( this._finished ) {
            return 
true;

        } else if ( 
this._startTime === null ) {
            
this._startTime now;
            return 
false;

        } else {
            var 
diff now this._startTime;

            if ( 
diff this._duration ) {
                
this._tickdiff this._duration );
                return 
false;

            } else {
                
this._end);
                
// Cleanup all the properties
                
this.cancel();
                return 
true;
            }
        }
    };

    
Animation.prototype._tick = function( time ) {
        
// Apply the easing to the time ratio
        
time this._easingtime );

        var 
tweens this._tweens;

        for ( var 
0tweens.length; ++) {
            
tweens].interpolatetime );
        }

        
// TODO check the performance of this
        
pushNewneedsValidationthis._chart );
    };

    
Animation.prototype._end = function( time ) {
        
this._ticktime );

        if ( 
this._onComplete != null ) {
            
this._onComplete();
        }
    };


    function 
Animator() {
        
this._animating false;
        
this._animations = [];
        
this._onBeforeFrames = [];
        
this._onAfterFrames = [];

        var 
self this;

        
this._raf = function( now ) {
            
self._onFramenow );
        };
    }

    
Animator.prototype.animate = function( animation ) {
        
this._animations.pushanimation );

        if ( !
this._animating ) {
            
this._animating true;

            
rafthis._raf );
        }
    };


    
Animator.prototype.onBeforeFrame = function( ) {
        
this._onBeforeFrames.push);
    };

    
Animator.prototype.onAfterFrame = function( ) {
        
this._onAfterFrames.push);
    };


    
Animator.prototype._onFrame = function( now ) {
        var 
onBeforeFrames this._onBeforeFrames;

        for ( var 
0onBeforeFrames.length; ++) {
            
onBeforeFrames]( now );
        }


        var 
animations this._animations;

        for ( var 
0animations.length; ++) {
            var 
animation animations];

            
// If the animation is finished...
            
if ( animation._onFramenow ) ) {
                
// TODO this is a bit slow, but I don't know of a faster alternative
                
animations.splicei);
                --
i;
            }
        }


        var 
onAfterFrames this._onAfterFrames;

        for ( var 
0onAfterFrames.length; ++) {
            
onAfterFrames]( now );
        }


        
// All animations are finished
        
if ( animations.length === ) {
            
this._animating false;

        } else {
            
rafthis._raf );
        }
    };


    var 
_animator = new Animator();


    var 
needsValidation = [];

    
// This is more robust than the built-in `isNaN` function
    
function isNaN) {
        return 
!== x;
    }

    function 
each( array, fn ) {
        for ( var 
0< array.length; ++) {
            
fn( array[ ] );
        }
    }

    function 
pushNew( array, ) {
        for ( var 
0< array.length; ++) {
            if ( array[ 
] === ) {
                return;
            }
        }

        array.
push);
    }

    
// TODO check the performance of this
    
_animator.onAfterFrame( function() {
        for ( var 
0needsValidation.length; ++) {
            
needsValidation].validateData();
        }

        
needsValidation.length 0;
    } );


    
// This ensures that a key is only added once
    
function addKeykeysseenkey ) {
        if ( !
seenkey ] ) {
            
seenkey ] = true;
            
keys.pushkey );
        }
    }

    function 
addKeyskeysseenobject) {
        
eacha, function( key ) {
            var 
value objectkey ];

            if ( 
value != null ) {
                
addKeykeysseenvalue );
            }
        } );
    }


    function 
getKeysSlicedchartkeysseen ) {
        
addKeyskeysseenchart, [
            
"alphaField",
            
"valueField"
        
] );
    }

    function 
getKeysFunnelchartkeysseen ) {
        
getKeysSlicedchartkeysseen );
    }

    function 
getKeysPiechartkeysseen ) {
        
getKeysSlicedchartkeysseen );

        
addKeyskeysseenchart, [
            
"labelRadiusField"
        
] );
    }

    function 
getKeysGraphgraphkeysseen ) {
        
addKeyskeysseengraph, [
            
"alphaField",
            
"bulletSizeField",
            
"closeField",
            
"dashLengthField",
            
"errorField",
            
"highField",
            
"lowField",
            
"openField",
            
"valueField"
        
] );
    }

    function 
getKeysGraphsgraphskeysseen ) {
        
eachgraphs, function( graph ) {
            
getKeysGraphgraphkeysseen );
        } );
    }

    function 
getKeysCategoryAxiscategoryAxiskeysseen ) {
        
addKeyskeysseencategoryAxis, [
            
"widthField"
        
] );
    }


    
// Returns an array of all of the animatable keys
    
function getKeyschart ) {
        var 
keys = [];

        var 
seen = {};

        if ( 
chart.type === "funnel" ) {
            
getKeysFunnelchartkeysseen );

        } else if ( 
chart.type === "pie" ) {
            
getKeysPiechartkeysseen );

        } else if ( 
chart.type === "serial" ) {
            
getKeysCategoryAxischart.categoryAxiskeysseen );
            
getKeysGraphschart.graphskeysseen );

        } else if ( 
chart.type === "radar" ) {
            
getKeysGraphschart.graphskeysseen );
        }

        return 
keys;
    }


    function 
getCategoryFieldchart ) {
        if ( 
chart.type === "funnel" || chart.type === "pie" ) {
            return 
chart.titleField;

        } else if ( 
chart.type === "serial" || chart.type === "radar" ) {
            return 
chart.categoryField;
        }
    }


    function 
getValueobjectkey ) {
        var 
value objectkey ];

        if ( 
value == null ) {
            return 
null;

        } else {
            
value = +value;

            
// TODO test this
            // TODO what about Infinity, etc. ?
            
if ( isNaNvalue ) ) {
                return 
null;

            } else {
                return 
value;
            }
        }
    }

    function 
getCategoryobjectkey ) {
        var 
value objectkey ];

        if ( 
value == null ) {
            return 
null;

        } else {
            
// TODO better algorithm for this ?
            
return "" value;
        }
    }


    function 
getCategoriesdataProvidercategoryField ) {
        var 
categories = {};

        
eachdataProvider, function( data ) {
            var 
category getCategorydatacategoryField );

            if ( 
category != null ) {
                
categoriescategory ] = data;
            }
        } );

        return 
categories;
    }


    function 
getTweensdataProvidercategoryFieldcategorieskeys ) {
        var 
tweens = [];

        
eachdataProvider, function( newData ) {
            var 
category getCategorynewDatacategoryField );

            
// If the new data has the same category as the old data...
            
if ( category != null && category in categories ) {
                var 
oldData categoriescategory ];

                
eachkeys, function( key ) {
                    var 
oldValue getValueoldDatakey );
                    var 
newValue getValuenewDatakey );

                    
// If the old field and new field both exist...
                    
if ( oldValue != null && newValue != null ) {
                        
tweens.push( new TweennewDatakeyoldValuenewValue ) );
                    }
                } );
            }
        } );

        return 
tweens;
    }


    function 
animateDatadataProvideroptions ) {
        var 
chart this;

        var 
categoryField getCategoryFieldchart );
        var 
keys getKeyschart );

        var 
categories getCategorieschart.dataProvidercategoryField );

        var 
tweens getTweensdataProvidercategoryFieldcategorieskeys );

        
chart.dataProvider dataProvider;

        var 
animation = new Animation(
            
options.duration,
            
options.easing,
            
options.complete,
            
tweens,
            
chart
        
);

        
_animator.animateanimation );

        return 
animation;
    }


    
AmCharts.addInitHandler( function( chart ) {
        
chart.animateData animateData;
    }, [ 
"funnel""pie""serial""radar" ] );

} )();
?>
Онлайн: 0
Реклама