source: Dev/trunk/src/client/dojox/charting/action2d/Magnify.js @ 483

Last change on this file since 483 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.2 KB
Line 
1define(["dojo/_base/connect", "dojo/_base/declare",
2        "./PlotAction", "dojox/gfx/matrix",
3        "dojox/gfx/fx", "dojo/fx", "dojo/fx/easing"],
4        function(Hub, declare, PlotAction, m, gf, df, dfe){
5
6        /*=====
7        var __MagnifyCtorArgs = {
8                // summary:
9                //              Additional arguments for magnifying actions.
10                // duration: Number?
11                //              The amount of time in milliseconds for an animation to last.  Default is 400.
12                // easing: dojo/fx/easing/*?
13                //              An easing object (see dojo.fx.easing) for use in an animation.  The
14                //              default is dojo.fx.easing.backOut.
15                // scale: Number?
16                //              The amount to magnify the given object to.  Default is 2.
17        };
18        =====*/
19       
20        var DEFAULT_SCALE = 2;
21
22        return declare("dojox.charting.action2d.Magnify", PlotAction, {
23                // summary:
24                //              Create an action that magnifies the object the action is applied to.
25
26                // the data description block for the widget parser
27                defaultParams: {
28                        duration: 400,  // duration of the action in ms
29                        easing:   dfe.backOut,  // easing for the action
30                        scale:    DEFAULT_SCALE // scale of magnification
31                },
32                optionalParams: {},     // no optional parameters
33
34                constructor: function(chart, plot, kwArgs){
35                        // summary:
36                        //              Create the magnifying action.
37                        // chart: dojox/charting/Chart
38                        //              The chart this action belongs to.
39                        // plot: String?
40                        //              The plot to apply the action to. If not passed, "default" is assumed.
41                        // kwArgs: __MagnifyCtorArgs?
42                        //              Optional keyword arguments for this action.
43
44                        // process optional named parameters
45                        this.scale = kwArgs && typeof kwArgs.scale == "number" ? kwArgs.scale : DEFAULT_SCALE;
46
47                        this.connect();
48                },
49
50                process: function(o){
51                        // summary:
52                        //              Process the action on the given object.
53                        // o: dojox/gfx/shape.Shape
54                        //              The object on which to process the magnifying action.
55                        if(!o.shape || !(o.type in this.overOutEvents) ||
56                                !("cx" in o) || !("cy" in o)){ return; }
57
58                        // if spider deal only with circle
59                        if(o.element == "spider_plot" || o.element == "spider_poly"){
60                                return;
61                        }
62
63                        var runName = o.run.name, index = o.index, vector = [], anim, init, scale;
64
65                        if(runName in this.anim){
66                                anim = this.anim[runName][index];
67                        }else{
68                                this.anim[runName] = {};
69                        }
70
71                        if(anim){
72                                anim.action.stop(true);
73                        }else{
74                                this.anim[runName][index] = anim = {};
75                        }
76
77                        if(o.type == "onmouseover"){
78                                init  = m.identity;
79                                scale = this.scale;
80                        }else{
81                                init  = m.scaleAt(this.scale, o.cx, o.cy);
82                                scale = 1 / this.scale;
83                        }
84
85                        var kwArgs = {
86                                shape:    o.shape,
87                                duration: this.duration,
88                                easing:   this.easing,
89                                transform: [
90                                        {name: "scaleAt", start: [1, o.cx, o.cy], end: [scale, o.cx, o.cy]},
91                                        init
92                                ]
93                        };
94                        if(o.shape){
95                                vector.push(gf.animateTransform(kwArgs));
96                        }
97                        if(o.outline){
98                                kwArgs.shape = o.outline;
99                                vector.push(gf.animateTransform(kwArgs));
100                        }
101                        if(o.shadow){
102                                kwArgs.shape = o.shadow;
103                                vector.push(gf.animateTransform(kwArgs));
104                        }
105
106                        if(!vector.length){
107                                delete this.anim[runName][index];
108                                return;
109                        }
110
111                        anim.action = df.combine(vector);
112                        if(o.type == "onmouseout"){
113                                Hub.connect(anim.action, "onEnd", this, function(){
114                                        if(this.anim[runName]){
115                                                delete this.anim[runName][index];
116                                        }
117                                });
118                        }
119                        anim.action.play();
120                }
121        });
122       
123});
Note: See TracBrowser for help on using the repository browser.