source: Dev/branches/rest-dojo-ui/client/dojox/charting/action2d/MoveSlice.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.7 KB
Line 
1define(["dojo/_base/connect", "dojo/_base/declare", "./PlotAction", "dojo/fx/easing", "dojox/gfx/matrix",
2        "dojox/gfx/fx", "dojox/lang/functional", "dojox/lang/functional/scan", "dojox/lang/functional/fold"],
3        function(hub, declare, PlotAction, dfe, m, gf, df, dfs, dff){
4
5        /*=====
6        dojo.declare("dojox.charting.action2d.__MoveSliceCtorArgs", dojox.charting.action2d.__PlotActionCtorArgs, {
7                //      summary:
8                //              Additional arguments for highlighting actions.
9       
10                //      scale: Number?
11                //              The amount to scale the pie slice.  Default is 1.05.
12                scale: 1.05,
13       
14                //      shift: Number?
15                //              The amount in pixels to shift the pie slice.  Default is 7.
16                shift: 7
17        });
18        var PlotAction = dojox.charting.action2d.PlotAction;
19        =====*/
20       
21        var DEFAULT_SCALE = 1.05,
22                DEFAULT_SHIFT = 7;      // px
23
24        return declare("dojox.charting.action2d.MoveSlice", PlotAction, {
25                //      summary:
26                //              Create an action for a pie chart that moves and scales a pie slice.
27
28                // the data description block for the widget parser
29                defaultParams: {
30                        duration: 400,  // duration of the action in ms
31                        easing:   dfe.backOut,  // easing for the action
32                        scale:    DEFAULT_SCALE,        // scale of magnification
33                        shift:    DEFAULT_SHIFT         // shift of the slice
34                },
35                optionalParams: {},     // no optional parameters
36
37                constructor: function(chart, plot, kwArgs){
38                        //      summary:
39                        //              Create the slice moving action and connect it to the plot.
40                        //      chart: dojox.charting.Chart
41                        //              The chart this action belongs to.
42                        //      plot: String?
43                        //              The plot this action is attached to.  If not passed, "default" is assumed.
44                        //      kwArgs: dojox.charting.action2d.__MoveSliceCtorArgs?
45                        //              Optional keyword arguments object for setting parameters.
46                        if(!kwArgs){ kwArgs = {}; }
47                        this.scale = typeof kwArgs.scale == "number" ? kwArgs.scale : DEFAULT_SCALE;
48                        this.shift = typeof kwArgs.shift == "number" ? kwArgs.shift : DEFAULT_SHIFT;
49
50                        this.connect();
51                },
52
53                process: function(o){
54                        //      summary:
55                        //              Process the action on the given object.
56                        //      o: dojox.gfx.Shape
57                        //              The object on which to process the slice moving action.
58                        if(!o.shape || o.element != "slice" || !(o.type in this.overOutEvents)){ return; }
59
60                        if(!this.angles){
61                                // calculate the running total of slice angles
62                                var startAngle = m._degToRad(o.plot.opt.startAngle);
63                                if(typeof o.run.data[0] == "number"){
64                                        this.angles = df.map(df.scanl(o.run.data, "+", startAngle),
65                                                "* 2 * Math.PI / this", df.foldl(o.run.data, "+", 0));
66                                }else{
67                                        this.angles = df.map(df.scanl(o.run.data, "a + b.y", startAngle),
68                                                "* 2 * Math.PI / this", df.foldl(o.run.data, "a + b.y", 0));
69                                }
70                        }
71
72                        var index = o.index, anim, startScale, endScale, startOffset, endOffset,
73                                angle = (this.angles[index] + this.angles[index + 1]) / 2,
74                                rotateTo0  = m.rotateAt(-angle, o.cx, o.cy),
75                                rotateBack = m.rotateAt( angle, o.cx, o.cy);
76
77                        anim = this.anim[index];
78
79                        if(anim){
80                                anim.action.stop(true);
81                        }else{
82                                this.anim[index] = anim = {};
83                        }
84
85                        if(o.type == "onmouseover"){
86                                startOffset = 0;
87                                endOffset   = this.shift;
88                                startScale  = 1;
89                                endScale    = this.scale;
90                        }else{
91                                startOffset = this.shift;
92                                endOffset   = 0;
93                                startScale  = this.scale;
94                                endScale    = 1;
95                        }
96
97                        anim.action = gf.animateTransform({
98                                shape:    o.shape,
99                                duration: this.duration,
100                                easing:   this.easing,
101                                transform: [
102                                        rotateBack,
103                                        {name: "translate", start: [startOffset, 0], end: [endOffset, 0]},
104                                        {name: "scaleAt",   start: [startScale, o.cx, o.cy],  end: [endScale, o.cx, o.cy]},
105                                        rotateTo0
106                                ]
107                        });
108
109                        if(o.type == "onmouseout"){
110                                hub.connect(anim.action, "onEnd", this, function(){
111                                        delete this.anim[index];
112                                });
113                        }
114                        anim.action.play();
115                },
116
117                reset: function(){
118                        delete this.angles;
119                }
120        });
121});
Note: See TracBrowser for help on using the repository browser.