1 | define(["dojo/_base/connect", "dojo/_base/declare", "./PlotAction", |
---|
2 | "dojo/fx", "dojo/fx/easing", "dojox/gfx/matrix", "dojox/gfx/fx"], |
---|
3 | function(hub, declare, PlotAction, df, dfe, m, gf){ |
---|
4 | |
---|
5 | /*===== |
---|
6 | dojo.declare("dojox.charting.action2d.__ShakeCtorArgs", dojox.charting.action2d.__PlotActionCtorArgstorArgs, { |
---|
7 | // summary: |
---|
8 | // Additional arguments for highlighting actions. |
---|
9 | |
---|
10 | // shift: Number? |
---|
11 | // The amount in pixels to shift the pie slice. Default is 3. |
---|
12 | shift: 3 |
---|
13 | }); |
---|
14 | var PlotAction = dojox.charting.action2d.PlotAction; |
---|
15 | =====*/ |
---|
16 | |
---|
17 | var DEFAULT_SHIFT = 3; |
---|
18 | |
---|
19 | return declare("dojox.charting.action2d.Shake", PlotAction, { |
---|
20 | // summary: |
---|
21 | // Create a shaking action for use on an element in a chart. |
---|
22 | |
---|
23 | // the data description block for the widget parser |
---|
24 | defaultParams: { |
---|
25 | duration: 400, // duration of the action in ms |
---|
26 | easing: dfe.backOut, // easing for the action |
---|
27 | shiftX: DEFAULT_SHIFT, // shift of the element along the X axis |
---|
28 | shiftY: DEFAULT_SHIFT // shift of the element along the Y axis |
---|
29 | }, |
---|
30 | optionalParams: {}, // no optional parameters |
---|
31 | |
---|
32 | constructor: function(chart, plot, kwArgs){ |
---|
33 | // summary: |
---|
34 | // Create the shaking action and connect it to the plot. |
---|
35 | // chart: dojox.charting.Chart |
---|
36 | // The chart this action belongs to. |
---|
37 | // plot: String? |
---|
38 | // The plot this action is attached to. If not passed, "default" is assumed. |
---|
39 | // kwArgs: dojox.charting.action2d.__ShakeCtorArgs? |
---|
40 | // Optional keyword arguments object for setting parameters. |
---|
41 | if(!kwArgs){ kwArgs = {}; } |
---|
42 | this.shiftX = typeof kwArgs.shiftX == "number" ? kwArgs.shiftX : DEFAULT_SHIFT; |
---|
43 | this.shiftY = typeof kwArgs.shiftY == "number" ? kwArgs.shiftY : DEFAULT_SHIFT; |
---|
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 slice moving action. |
---|
53 | if(!o.shape || !(o.type in this.overOutEvents)){ return; } |
---|
54 | |
---|
55 | var runName = o.run.name, index = o.index, vector = [], anim, |
---|
56 | shiftX = o.type == "onmouseover" ? this.shiftX : -this.shiftX, |
---|
57 | shiftY = o.type == "onmouseover" ? this.shiftY : -this.shiftY; |
---|
58 | |
---|
59 | if(runName in this.anim){ |
---|
60 | anim = this.anim[runName][index]; |
---|
61 | }else{ |
---|
62 | this.anim[runName] = {}; |
---|
63 | } |
---|
64 | |
---|
65 | if(anim){ |
---|
66 | anim.action.stop(true); |
---|
67 | }else{ |
---|
68 | this.anim[runName][index] = anim = {}; |
---|
69 | } |
---|
70 | |
---|
71 | var kwArgs = { |
---|
72 | shape: o.shape, |
---|
73 | duration: this.duration, |
---|
74 | easing: this.easing, |
---|
75 | transform: [ |
---|
76 | {name: "translate", start: [this.shiftX, this.shiftY], end: [0, 0]}, |
---|
77 | m.identity |
---|
78 | ] |
---|
79 | }; |
---|
80 | if(o.shape){ |
---|
81 | vector.push(gf.animateTransform(kwArgs)); |
---|
82 | } |
---|
83 | if(o.oultine){ |
---|
84 | kwArgs.shape = o.outline; |
---|
85 | vector.push(gf.animateTransform(kwArgs)); |
---|
86 | } |
---|
87 | if(o.shadow){ |
---|
88 | kwArgs.shape = o.shadow; |
---|
89 | vector.push(gf.animateTransform(kwArgs)); |
---|
90 | } |
---|
91 | |
---|
92 | if(!vector.length){ |
---|
93 | delete this.anim[runName][index]; |
---|
94 | return; |
---|
95 | } |
---|
96 | |
---|
97 | anim.action = df.combine(vector); |
---|
98 | if(o.type == "onmouseout"){ |
---|
99 | hub.connect(anim.action, "onEnd", this, function(){ |
---|
100 | if(this.anim[runName]){ |
---|
101 | delete this.anim[runName][index]; |
---|
102 | } |
---|
103 | }); |
---|
104 | } |
---|
105 | anim.action.play(); |
---|
106 | } |
---|
107 | }); |
---|
108 | }); |
---|