[483] | 1 | define(["dojo/_base/connect", "dojo/_base/declare", "dojo/_base/array", "./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, array, PlotAction, dfe, m, gf, df){ |
---|
| 4 | |
---|
| 5 | /*===== |
---|
| 6 | var __MoveSliceCtorArgs = { |
---|
| 7 | // summary: |
---|
| 8 | // Additional arguments for move slice 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 | // scale: Number? |
---|
| 15 | // The amount to scale the pie slice. Default is 1.05. |
---|
| 16 | // shift: Number? |
---|
| 17 | // The amount in pixels to shift the pie slice. Default is 7. |
---|
| 18 | }; |
---|
| 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: __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.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, "+", 0), |
---|
| 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", 0), |
---|
| 68 | "* 2 * Math.PI / this", df.foldl(o.run.data, "a + b.y", 0)); |
---|
| 69 | } |
---|
| 70 | this.angles = array.map(this.angles, function(item){ |
---|
| 71 | return item + startAngle; |
---|
| 72 | }); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | var index = o.index, anim, startScale, endScale, startOffset, endOffset, |
---|
| 76 | angle = (this.angles[index] + this.angles[index + 1]) / 2, |
---|
| 77 | rotateTo0 = m.rotateAt(-angle, o.cx, o.cy), |
---|
| 78 | rotateBack = m.rotateAt( angle, o.cx, o.cy); |
---|
| 79 | |
---|
| 80 | anim = this.anim[index]; |
---|
| 81 | |
---|
| 82 | if(anim){ |
---|
| 83 | anim.action.stop(true); |
---|
| 84 | }else{ |
---|
| 85 | this.anim[index] = anim = {}; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if(o.type == "onmouseover"){ |
---|
| 89 | startOffset = 0; |
---|
| 90 | endOffset = this.shift; |
---|
| 91 | startScale = 1; |
---|
| 92 | endScale = this.scale; |
---|
| 93 | }else{ |
---|
| 94 | startOffset = this.shift; |
---|
| 95 | endOffset = 0; |
---|
| 96 | startScale = this.scale; |
---|
| 97 | endScale = 1; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | anim.action = gf.animateTransform({ |
---|
| 101 | shape: o.shape, |
---|
| 102 | duration: this.duration, |
---|
| 103 | easing: this.easing, |
---|
| 104 | transform: [ |
---|
| 105 | rotateBack, |
---|
| 106 | {name: "translate", start: [startOffset, 0], end: [endOffset, 0]}, |
---|
| 107 | {name: "scaleAt", start: [startScale, o.cx, o.cy], end: [endScale, o.cx, o.cy]}, |
---|
| 108 | rotateTo0 |
---|
| 109 | ] |
---|
| 110 | }); |
---|
| 111 | |
---|
| 112 | if(o.type == "onmouseout"){ |
---|
| 113 | hub.connect(anim.action, "onEnd", this, function(){ |
---|
| 114 | delete this.anim[index]; |
---|
| 115 | }); |
---|
| 116 | } |
---|
| 117 | anim.action.play(); |
---|
| 118 | }, |
---|
| 119 | |
---|
| 120 | reset: function(){ |
---|
| 121 | delete this.angles; |
---|
| 122 | } |
---|
| 123 | }); |
---|
| 124 | }); |
---|