| 1 |
define(["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/Color", "dojo/_base/connect", "dojox/color/_base", |
| 2 |
"./PlotAction", "dojo/fx/easing", "dojox/gfx/fx"], |
| 3 |
function(lang, declare, Color, hub, c, PlotAction, dfe, dgf){ |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
var DEFAULT_SATURATION = 100, |
| 20 |
DEFAULT_LUMINOSITY1 = 75, |
| 21 |
DEFAULT_LUMINOSITY2 = 50, |
| 22 |
cc = function(color){ |
| 23 |
return function(){ return color; }; |
| 24 |
}, |
| 25 |
|
| 26 |
hl = function(color){ |
| 27 |
var a = new c.Color(color), |
| 28 |
x = a.toHsl(); |
| 29 |
if(x.s == 0){ |
| 30 |
x.l = x.l < 50 ? 100 : 0; |
| 31 |
}else{ |
| 32 |
x.s = DEFAULT_SATURATION; |
| 33 |
if(x.l < DEFAULT_LUMINOSITY2){ |
| 34 |
x.l = DEFAULT_LUMINOSITY1; |
| 35 |
}else if(x.l > DEFAULT_LUMINOSITY1){ |
| 36 |
x.l = DEFAULT_LUMINOSITY2; |
| 37 |
}else{ |
| 38 |
x.l = x.l - DEFAULT_LUMINOSITY2 > DEFAULT_LUMINOSITY1 - x.l ? |
| 39 |
DEFAULT_LUMINOSITY2 : DEFAULT_LUMINOSITY1; |
| 40 |
} |
| 41 |
} |
| 42 |
var rcolor = c.fromHsl(x); |
| 43 |
rcolor.a = a.a; |
| 44 |
return rcolor; |
| 45 |
}, |
| 46 |
|
| 47 |
spiderhl = function(color){ |
| 48 |
var r = hl(color); |
| 49 |
r.a = 0.7; |
| 50 |
return r; |
| 51 |
} |
| 52 |
|
| 53 |
return declare("dojox.charting.action2d.Highlight", PlotAction, { |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
defaultParams: { |
| 60 |
duration: 400, |
| 61 |
easing: dfe.backOut |
| 62 |
}, |
| 63 |
optionalParams: { |
| 64 |
highlight: "red" |
| 65 |
|
| 66 |
}, |
| 67 |
|
| 68 |
constructor: function(chart, plot, kwArgs){ |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
var a = kwArgs && kwArgs.highlight; |
| 78 |
this.colorFunc = a ? (lang.isFunction(a) ? a : cc(a)) : hl; |
| 79 |
this.connect(); |
| 80 |
}, |
| 81 |
|
| 82 |
process: function(o){ |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
if(!o.shape || !(o.type in this.overOutEvents)){ return; } |
| 88 |
|
| 89 |
|
| 90 |
if(o.element == "spider_circle" || o.element == "spider_plot"){ |
| 91 |
return; |
| 92 |
}else if(o.element == "spider_poly" && this.colorFunc == hl){ |
| 93 |
|
| 94 |
|
| 95 |
this.colorFunc = spiderhl; |
| 96 |
} |
| 97 |
|
| 98 |
var runName = o.run.name, index = o.index, anim; |
| 99 |
|
| 100 |
if(runName in this.anim){ |
| 101 |
anim = this.anim[runName][index]; |
| 102 |
}else{ |
| 103 |
this.anim[runName] = {}; |
| 104 |
} |
| 105 |
|
| 106 |
if(anim){ |
| 107 |
anim.action.stop(true); |
| 108 |
}else{ |
| 109 |
var color = o.shape.getFill(); |
| 110 |
if(!color || !(color instanceof Color)){ |
| 111 |
return; |
| 112 |
} |
| 113 |
this.anim[runName][index] = anim = { |
| 114 |
start: color, |
| 115 |
end: this.colorFunc(color) |
| 116 |
}; |
| 117 |
} |
| 118 |
|
| 119 |
var start = anim.start, end = anim.end; |
| 120 |
if(o.type == "onmouseout"){ |
| 121 |
|
| 122 |
var t = start; |
| 123 |
start = end; |
| 124 |
end = t; |
| 125 |
} |
| 126 |
|
| 127 |
anim.action = dgf.animateFill({ |
| 128 |
shape: o.shape, |
| 129 |
duration: this.duration, |
| 130 |
easing: this.easing, |
| 131 |
color: {start: start, end: end} |
| 132 |
}); |
| 133 |
if(o.type == "onmouseout"){ |
| 134 |
hub.connect(anim.action, "onEnd", this, function(){ |
| 135 |
if(this.anim[runName]){ |
| 136 |
delete this.anim[runName][index]; |
| 137 |
} |
| 138 |
}); |
| 139 |
} |
| 140 |
anim.action.play(); |
| 141 |
} |
| 142 |
}); |
| 143 |
|
| 144 |
}); |