| 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 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
var DEFAULT_SCALE = 1.05, |
| 22 |
DEFAULT_SHIFT = 7; |
| 23 |
|
| 24 |
return declare("dojox.charting.action2d.MoveSlice", PlotAction, { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
defaultParams: { |
| 30 |
duration: 400, |
| 31 |
easing: dfe.backOut, |
| 32 |
scale: DEFAULT_SCALE, |
| 33 |
shift: DEFAULT_SHIFT |
| 34 |
}, |
| 35 |
optionalParams: {}, |
| 36 |
|
| 37 |
constructor: function(chart, plot, kwArgs){ |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 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 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
if(!o.shape || o.element != "slice" || !(o.type in this.overOutEvents)){ return; } |
| 59 |
|
| 60 |
if(!this.angles){ |
| 61 |
|
| 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 |
}); |