//>>built
define("dojox/charting/widget/SelectableLegend","dojo/_base/array dojo/_base/declare dojo/query dojo/_base/connect dojo/_base/Color ./Legend dijit/form/CheckBox ../action2d/Highlight dojox/lang/functional dojox/gfx/fx dojo/keys dojo/dom-construct dojo/dom-prop dijit/registry".split(" "),function(e,q,k,n,E,t,u,v,F,G,m,w,x,y){function z(a){return"mouseenter"==a?"onmouseover":"mouseleave"==a?"onmouseout":"on"+a}var A=q(null,{constructor:function(a){this.legend=a;this.index=0;this.horizontalLength=this._getHrizontalLength();
e.forEach(a.legends,function(b,c){0<c&&k("input",b).attr("tabindex",-1)});this.firstLabel=k("input",a.legends[0])[0];n.connect(this.firstLabel,"focus",this,function(){this.legend.active=!0});n.connect(this.legend.domNode,"keydown",this,"_onKeyEvent")},_getHrizontalLength:function(){var a=this.legend.horizontal;return"number"==typeof a?Math.min(a,this.legend.legends.length):a?this.legend.legends.length:1},_onKeyEvent:function(a){if(this.legend.active)if(a.keyCode==m.TAB)this.legend.active=!1;else{var b=
this.legend.legends.length;switch(a.keyCode){case m.LEFT_ARROW:this.index--;0>this.index&&(this.index+=b);break;case m.RIGHT_ARROW:this.index++;this.index>=b&&(this.index-=b);break;case m.UP_ARROW:0<=this.index-this.horizontalLength&&(this.index-=this.horizontalLength);break;case m.DOWN_ARROW:this.index+this.horizontalLength<b&&(this.index+=this.horizontalLength);break;default:return}this._moveToFocus();Event.stop(a)}},_moveToFocus:function(){k("input",this.legend.legends[this.index])[0].focus()}}),
B=q(v,{connect:function(){}});return q("dojox.charting.widget.SelectableLegend",t,{outline:!1,transitionFill:null,transitionStroke:null,autoScale:!1,postCreate:function(){this.legends=[];this.legendAnim={};this._cbs=[];this.inherited(arguments)},refresh:function(){this.legends=[];this._clearLabels();this.inherited(arguments);this._applyEvents();new A(this)},_clearLabels:function(){for(var a=this._cbs;a.length;)a.pop().destroyRecursive()},_addLabel:function(a,b){this.inherited(arguments);var c=k("td",
this.legendBody),d=c[c.length-1];this.legends.push(d);c=new u({checked:!0});this._cbs.push(c);w.place(c.domNode,d,"first");d=k("label",d)[0];x.set(d,"for",c.id)},_applyEvents:function(){this.chart.dirty||e.forEach(this.legends,function(a,b){if(this._isPie()){var c=this.chart.stack[0];var d=c.name;var f=this.chart.series[0].name}else c=this.chart.series[b],d=c.plot,f=c.name;var g=y.byNode(k(".dijitCheckBox",a)[0]);g.set("checked",!this._isHidden(d,b));n.connect(g,"onClick",this,function(l){this.toogle(d,
b,!g.get("checked"));l.stopPropagation()});var h=k(".dojoxLegendIcon",a)[0],p=this._getFilledShape(this._surfaces[b].children);e.forEach(["onmouseenter","onmouseleave"],function(l){n.connect(h,l,this,function(r){this._highlight(r,p,b,!g.get("checked"),f,d)})},this)},this)},_isHidden:function(a,b){return this._isPie()?-1!=e.indexOf(this.chart.getPlot(a).runFilter,b):this.chart.series[b].hidden},toogle:function(a,b,c){a=this.chart.getPlot(a);this._isPie()?-1!=e.indexOf(a.runFilter,b)?c||(a.runFilter=
e.filter(a.runFilter,function(d){return d!=b})):c&&a.runFilter.push(b):this.chart.series[b].hidden=c;this.autoScale?this.chart.dirty=!0:a.dirty=!0;this.chart.render()},_highlight:function(a,b,c,d,f,g){if(!d){var h=this._getAnim(g),p=this._isPie(),l=z(a.type);h.process({shape:b,index:p?"legend"+c:"legend",run:{name:f},type:l});e.forEach(this._getShapes(c,g),function(r,C){var D={shape:r,index:p?c:C,run:{name:f},type:l};h.duration=100;h.process(D)})}},_getShapes:function(a,b){var c=[];if(this._isPie()){var d=
0;e.forEach(this.chart.getPlot(b).runFilter,function(f){a>f&&d++});c.push(this.chart.stack[0].group.children[a-d])}else this._isCandleStick(b)?e.forEach(this.chart.series[a].group.children,function(f){e.forEach(f.children,function(g){e.forEach(g.children,function(h){"line"!=h.shape.type&&c.push(h)})})}):c=this.chart.series[a].group.children;return c},_getAnim:function(a){this.legendAnim[a]||(this.legendAnim[a]=new B(this.chart,a));return this.legendAnim[a]},_getTransitionFill:function(a){return-1!=
this.chart.stack[this.chart.plots[a]].declaredClass.indexOf("dojox.charting.plot2d.Stacked")?this.chart.theme.plotarea.fill:null},_getFilledShape:function(a){for(var b=0;a[b];){if(a[b].getFill())return a[b];b++}return null},_isPie:function(){return"dojox.charting.plot2d.Pie"==this.chart.stack[0].declaredClass},_isCandleStick:function(a){return"dojox.charting.plot2d.Candlesticks"==this.chart.stack[this.chart.plots[a]].declaredClass},destroy:function(){this._clearLabels();this.inherited(arguments)}})});