~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Tween.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
 
2
 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
 
3
 * full text of the license. */
 
4
 
 
5
/**
 
6
 * Namespace: OpenLayers.Tween
 
7
 */
 
8
OpenLayers.Tween = OpenLayers.Class({
 
9
    
 
10
    /**
 
11
     * Constant: INTERVAL
 
12
     * {int} Interval in milliseconds between 2 steps
 
13
     */
 
14
    INTERVAL: 10,
 
15
    
 
16
    /**
 
17
     * APIProperty: easing
 
18
     * {<OpenLayers.Easing>(Function)} Easing equation used for the animation
 
19
     *     Defaultly set to OpenLayers.Easing.Expo.easeOut
 
20
     */
 
21
    easing: null,
 
22
    
 
23
    /**
 
24
     * APIProperty: begin
 
25
     * {Object} Values to start the animation with
 
26
     */
 
27
    begin: null,
 
28
    
 
29
    /**
 
30
     * APIProperty: finish
 
31
     * {Object} Values to finish the animation with
 
32
     */
 
33
    finish: null,
 
34
    
 
35
    /**
 
36
     * APIProperty: duration
 
37
     * {int} duration of the tween (number of steps)
 
38
     */
 
39
    duration: null,
 
40
    
 
41
    /**
 
42
     * APIProperty: callbacks
 
43
     * {Object} An object with start, eachStep and done properties whose values
 
44
     *     are functions to be call during the animation. They are passed the
 
45
     *     current computed value as argument.
 
46
     */
 
47
    callbacks: null,
 
48
    
 
49
    /**
 
50
     * Property: time
 
51
     * {int} Step counter
 
52
     */
 
53
    time: null,
 
54
    
 
55
    /**
 
56
     * Property: interval
 
57
     * {int} Interval id returned by window.setInterval
 
58
     */
 
59
    interval: null,
 
60
    
 
61
    /**
 
62
     * Property: playing
 
63
     * {Boolean} Tells if the easing is currently playing
 
64
     */
 
65
    playing: false,
 
66
    
 
67
    /** 
 
68
     * Constructor: OpenLayers.Tween
 
69
     * Creates a Tween.
 
70
     *
 
71
     * Parameters:
 
72
     * easing - {<OpenLayers.Easing>(Function)} easing function method to use
 
73
     */ 
 
74
    initialize: function(easing) {
 
75
        this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut;
 
76
    },
 
77
    
 
78
    /**
 
79
     * APIMethod: start
 
80
     * Plays the Tween, and calls the callback method on each step
 
81
     * 
 
82
     * Parameters:
 
83
     * begin - {Object} values to start the animation with
 
84
     * finish - {Object} values to finish the animation with
 
85
     * duration - {int} duration of the tween (number of steps)
 
86
     * options - {Object} hash of options (for example callbacks (start, eachStep, done))
 
87
     */
 
88
    start: function(begin, finish, duration, options) {
 
89
        this.playing = true;
 
90
        this.begin = begin;
 
91
        this.finish = finish;
 
92
        this.duration = duration;
 
93
        this.callbacks = options.callbacks;
 
94
        this.time = 0;
 
95
        if (this.interval) {
 
96
            window.clearInterval(this.interval);
 
97
            this.interval = null;
 
98
        }
 
99
        if (this.callbacks && this.callbacks.start) {
 
100
            this.callbacks.start.call(this, this.begin);
 
101
        }
 
102
        this.interval = window.setInterval(
 
103
            OpenLayers.Function.bind(this.play, this), this.INTERVAL);
 
104
    },
 
105
    
 
106
    /**
 
107
     * APIMethod: stop
 
108
     * Stops the Tween, and calls the done callback
 
109
     *     Doesn't do anything if animation is already finished
 
110
     */
 
111
    stop: function() {
 
112
        if (!this.playing) {
 
113
            return;
 
114
        }
 
115
        
 
116
        if (this.callbacks && this.callbacks.done) {
 
117
            this.callbacks.done.call(this, this.finish);
 
118
        }
 
119
        window.clearInterval(this.interval);
 
120
        this.interval = null;
 
121
        this.playing = false;
 
122
    },
 
123
    
 
124
    /**
 
125
     * Method: play
 
126
     * Calls the appropriate easing method
 
127
     */
 
128
    play: function() {
 
129
        var value = {};
 
130
        for (var i in this.begin) {
 
131
            var b = this.begin[i];
 
132
            var f = this.finish[i];
 
133
            if (b == null || f == null || isNaN(b) || isNaN(f)) {
 
134
                OpenLayers.Console.error('invalid value for Tween');
 
135
            }
 
136
            
 
137
            var c = f - b;
 
138
            value[i] = this.easing.apply(this, [this.time, b, c, this.duration]);
 
139
        }
 
140
        this.time++;
 
141
        
 
142
        if (this.callbacks && this.callbacks.eachStep) {
 
143
            this.callbacks.eachStep.call(this, value);
 
144
        }
 
145
        
 
146
        if (this.time > this.duration) {
 
147
            if (this.callbacks && this.callbacks.done) {
 
148
                this.callbacks.done.call(this, this.finish);
 
149
                this.playing = false;
 
150
            }
 
151
            window.clearInterval(this.interval);
 
152
            this.interval = null;
 
153
        }
 
154
    },
 
155
    
 
156
    /**
 
157
     * Create empty functions for all easing methods.
 
158
     */
 
159
    CLASS_NAME: "OpenLayers.Tween"
 
160
});
 
161
 
 
162
/**
 
163
 * Namespace: OpenLayers.Easing
 
164
 * 
 
165
 * Credits:
 
166
 *      Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>
 
167
 */
 
168
OpenLayers.Easing = {
 
169
    /**
 
170
     * Create empty functions for all easing methods.
 
171
     */
 
172
    CLASS_NAME: "OpenLayers.Easing"
 
173
};
 
174
 
 
175
/**
 
176
 * Namespace: OpenLayers.Easing.Linear
 
177
 */
 
178
OpenLayers.Easing.Linear = {
 
179
    
 
180
    /**
 
181
     * Function: easeIn
 
182
     * 
 
183
     * Parameters:
 
184
     * t - {Float} time
 
185
     * b - {Float} beginning position
 
186
     * c - {Float} total change
 
187
     * d - {Float} duration of the transition
 
188
     */
 
189
    easeIn: function(t, b, c, d) {
 
190
        return c*t/d + b;
 
191
    },
 
192
    
 
193
    /**
 
194
     * Function: easeOut
 
195
     * 
 
196
     * Parameters:
 
197
     * t - {Float} time
 
198
     * b - {Float} beginning position
 
199
     * c - {Float} total change
 
200
     * d - {Float} duration of the transition
 
201
     */
 
202
    easeOut: function(t, b, c, d) {
 
203
        return c*t/d + b;
 
204
    },
 
205
    
 
206
    /**
 
207
     * Function: easeInOut
 
208
     * 
 
209
     * Parameters:
 
210
     * t - {Float} time
 
211
     * b - {Float} beginning position
 
212
     * c - {Float} total change
 
213
     * d - {Float} duration of the transition
 
214
     */
 
215
    easeInOut: function(t, b, c, d) {
 
216
        return c*t/d + b;
 
217
    },
 
218
 
 
219
    CLASS_NAME: "OpenLayers.Easing.Linear"
 
220
};
 
221
 
 
222
/**
 
223
 * Namespace: OpenLayers.Easing.Expo
 
224
 */
 
225
OpenLayers.Easing.Expo = {
 
226
    
 
227
    /**
 
228
     * Function: easeIn
 
229
     * 
 
230
     * Parameters:
 
231
     * t - {Float} time
 
232
     * b - {Float} beginning position
 
233
     * c - {Float} total change
 
234
     * d - {Float} duration of the transition
 
235
     */
 
236
    easeIn: function(t, b, c, d) {
 
237
        return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
 
238
    },
 
239
    
 
240
    /**
 
241
     * Function: easeOut
 
242
     * 
 
243
     * Parameters:
 
244
     * t - {Float} time
 
245
     * b - {Float} beginning position
 
246
     * c - {Float} total change
 
247
     * d - {Float} duration of the transition
 
248
     */
 
249
    easeOut: function(t, b, c, d) {
 
250
        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
 
251
    },
 
252
    
 
253
    /**
 
254
     * Function: easeInOut
 
255
     * 
 
256
     * Parameters:
 
257
     * t - {Float} time
 
258
     * b - {Float} beginning position
 
259
     * c - {Float} total change
 
260
     * d - {Float} duration of the transition
 
261
     */
 
262
    easeInOut: function(t, b, c, d) {
 
263
        if (t==0) return b;
 
264
        if (t==d) return b+c;
 
265
        if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
 
266
        return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
 
267
    },
 
268
 
 
269
    CLASS_NAME: "OpenLayers.Easing.Expo"
 
270
};
 
271
 
 
272
/**
 
273
 * Namespace: OpenLayers.Easing.Quad
 
274
 */
 
275
OpenLayers.Easing.Quad = {
 
276
    
 
277
    /**
 
278
     * Function: easeIn
 
279
     * 
 
280
     * Parameters:
 
281
     * t - {Float} time
 
282
     * b - {Float} beginning position
 
283
     * c - {Float} total change
 
284
     * d - {Float} duration of the transition
 
285
     */
 
286
    easeIn: function(t, b, c, d) {
 
287
        return c*(t/=d)*t + b;
 
288
    },
 
289
    
 
290
    /**
 
291
     * Function: easeOut
 
292
     * 
 
293
     * Parameters:
 
294
     * t - {Float} time
 
295
     * b - {Float} beginning position
 
296
     * c - {Float} total change
 
297
     * d - {Float} duration of the transition
 
298
     */
 
299
    easeOut: function(t, b, c, d) {
 
300
        return -c *(t/=d)*(t-2) + b;
 
301
    },
 
302
    
 
303
    /**
 
304
     * Function: easeInOut
 
305
     * 
 
306
     * Parameters:
 
307
     * t - {Float} time
 
308
     * b - {Float} beginning position
 
309
     * c - {Float} total change
 
310
     * d - {Float} duration of the transition
 
311
     */
 
312
    easeInOut: function(t, b, c, d) {
 
313
        if ((t/=d/2) < 1) return c/2*t*t + b;
 
314
        return -c/2 * ((--t)*(t-2) - 1) + b;
 
315
    },
 
316
 
 
317
    CLASS_NAME: "OpenLayers.Easing.Quad"
 
318
};