[483] | 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 | var __ShakeCtorArgs = { |
---|
| 7 | // summary: |
---|
| 8 | // Additional arguments for shaking actions. |
---|
| 9 | // duration: Number? |
---|
| 10 | // The amount of time in milliseconds for an animation to last. Default is 400. |
---|
| 11 | // easing: dojo/fx/easing/*? |
---|
| 12 | // An easing object (see dojo.fx.easing) for use in an animation. The |
---|
| 13 | // default is dojo.fx.easing.backOut. |
---|
| 14 | // shift: Number? |
---|
| 15 | // The amount in pixels to shift the pie slice. Default is 3. |
---|
| 16 | }; |
---|
| 17 | =====*/ |
---|
| 18 | |
---|
| 19 | var DEFAULT_SHIFT = 3; |
---|
| 20 | |
---|
| 21 | return declare("dojox.charting.action2d.Shake", PlotAction, { |
---|
| 22 | // summary: |
---|
| 23 | // Create a shaking action for use on an element in a chart. |
---|
| 24 | |
---|
| 25 | // the data description block for the widget parser |
---|
| 26 | defaultParams: { |
---|
| 27 | duration: 400, // duration of the action in ms |
---|
| 28 | easing: dfe.backOut, // easing for the action |
---|
| 29 | shiftX: DEFAULT_SHIFT, // shift of the element along the X axis |
---|
| 30 | shiftY: DEFAULT_SHIFT // shift of the element along the Y axis |
---|
| 31 | }, |
---|
| 32 | optionalParams: {}, // no optional parameters |
---|
| 33 | |
---|
| 34 | constructor: function(chart, plot, kwArgs){ |
---|
| 35 | // summary: |
---|
| 36 | // Create the shaking action and connect it to the plot. |
---|
| 37 | // chart: dojox/charting/Chart |
---|
| 38 | // The chart this action belongs to. |
---|
| 39 | // plot: String? |
---|
| 40 | // The plot this action is attached to. If not passed, "default" is assumed. |
---|
| 41 | // kwArgs: __ShakeCtorArgs? |
---|
| 42 | // Optional keyword arguments object for setting parameters. |
---|
| 43 | if(!kwArgs){ kwArgs = {}; } |
---|
| 44 | this.shiftX = typeof kwArgs.shiftX == "number" ? kwArgs.shiftX : DEFAULT_SHIFT; |
---|
| 45 | this.shiftY = typeof kwArgs.shiftY == "number" ? kwArgs.shiftY : DEFAULT_SHIFT; |
---|
| 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 slice moving action. |
---|
| 55 | if(!o.shape || !(o.type in this.overOutEvents)){ return; } |
---|
| 56 | |
---|
| 57 | var runName = o.run.name, index = o.index, vector = [], anim; |
---|
| 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 | }); |
---|