source: Dev/branches/rest-dojo-ui/client/dojox/charting/action2d/Magnify.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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