/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */
//>>built
define("esri/dijit/geoenrichment/RelatedVariables",["../../declare","./BaseSelectComparison","./dom","dojo/dom-construct","dojo/dom-attr","./lang","dojo/i18n!../../nls/jsapi","dojo/dom-class","dojo/query","dojo/string"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a){_7=_7.geoenrichment.dijit.RelatedVariables;var _b=_1("esri.dijit.geoenrichment.RelatedVariables",[_2],{_widthExpanded:460,_widthCollapsed:200,_calculate:function(){var _c,_d;var _e=Number.NEGATIVE_INFINITY;var _f=Number.POSITIVE_INFINITY;var _10=Number.NEGATIVE_INFINITY;var _11=Number.POSITIVE_INFINITY;var _12=Number.NEGATIVE_INFINITY;var _13=Number.POSITIVE_INFINITY;var _14=[];var _15=this._getNumericFields();for(var i=0;i<_15.length;i++){var _16=this._data.getCol(_15[i]);var _17=this._data.getValue(0,_16.name);var dif;if(this._state.selectedComparison>=0){dif=_17-this._data.getValue(this._getComparisonRow(),_16.name);}else{dif=Number.NaN;}if(dif>_10){_10=dif;}if(dif<_11){_11=dif;}var row=[];row.push(i);row.push(_16.alias);row.push(_17);row.push(dif);_14.push(row);if(_17>_e){_e=_17;_c=_15[i];}if(_17<_f){_f=_17;_d=_15[i];}if(_17>_12){_12=_17;}if(_17<_13){_13=_17;}}this._sortRows(_14);return {rows:_14,indexes:_15,minDif:_11,maxDif:_10,minPct:_13,maxPct:_12,highCol:_c,lowCol:_d};},updateUIExpanded:function(){this.inherited(arguments);var _18=this._calculate();var _19=Math.max(Math.abs(_18.minDif),Math.abs(_18.maxDif));var tr;var _1a=1;for(var i=this.table.rows.length;i<_18.indexes.length+_1a;i++){tr=this.table.insertRow(-1);if(i>0&&i%2==0){tr.className="AlternatingRow";}_5.set(tr.insertCell(-1),"class","RelatedVariables_TextColumn");_5.set(tr.insertCell(-1),"class","RelatedVariables_ValueColumn");tr.insertCell(-1);var td;td=tr.insertCell(-1);_5.set(td,"class","RelatedVariables_ChartNegative");_5.set(td,"style","padding: 0;");td=tr.insertCell(-1);_5.set(td,"class","RelatedVariables_ChartPositive");_5.set(td,"style","padding: 0;");}while(this.table.rows.length>_18.indexes.length+_1a){this.table.deleteRow(-1);}for(var i=0;i<_18.rows.length;i++){var _1b=this._data.getCol(_18.indexes[_18.rows[i][0]]);tr=this.table.rows[i+_1a];tr.cells[0].innerHTML=_18.rows[i][1];tr.cells[1].innerHTML=_1b.format(_18.rows[i][2]);var dif=_18.rows[i][3];if(_6.isNumber(dif)){var _1c;if(dif>0){_1c="+"+_1b.format(dif);}else{if(dif<0){_1c="-"+_1b.format(-dif);}else{_1c="0";}}tr.cells[2].innerHTML=_1c;tr.cells[2].className="RelatedVariables_DifferenceColumn";if(dif>0){_8.add(tr.cells[2],"RelatedVariables_DifferenceColumn_Positive");var _1d=_3.pct(dif/_19);tr.cells[3].innerHTML="";tr.cells[4].innerHTML="<div class='RelatedVariables_PositiveBar' style='width:"+_1d+"' />";}else{if(dif<0){_8.add(tr.cells[2],"RelatedVariables_DifferenceColumn_Negative");var _1d=_3.pct(-dif/_19);tr.cells[3].innerHTML="<div class='RelatedVariables_NegativeBar' style='width:"+_1d+"' />";tr.cells[4].innerHTML="";}else{tr.cells[3].innerHTML="";tr.cells[4].innerHTML="";}}}else{tr.cells[2].innerHTML="";tr.cells[3].innerHTML="";tr.cells[4].innerHTML="";}}var col=this._data.getCol(_18.highCol);this.highLabel.innerHTML=_a.substitute(_7.highLabel2,{alias:col.alias})+" ("+col.format(this._data.getValue(0,_18.highCol))+")";var col=this._data.getCol(_18.lowCol);this.lowLabel.innerHTML=_a.substitute(_7.lowLabel2,{alias:col.alias})+" ("+col.format(this._data.getValue(0,_18.lowCol))+")";},updateUICollapsed:function(){this.inherited(arguments);var _1e=this._calculate();var tr;var _1f=1;for(var i=this.table.rows.length;i<_1e.indexes.length+_1f;i++){tr=this.table.insertRow(-1);if(i>0&&i%2==0){tr.className="AlternatingRow";}_5.set(tr.insertCell(-1),"class","RelatedVariables_TextColumn");_5.set(tr.insertCell(-1),"class","RelatedVariables_ValueColumn");}while(this.table.rows.length>_1e.indexes.length+_1f){this.table.deleteRow(-1);}for(var i=0;i<_1e.rows.length;i++){var _20=this._data.getCol(_1e.indexes[_1e.rows[i][0]]);var tr=this.table.rows[i+_1f];tr.cells[0].innerHTML=_1e.rows[i][1];tr.cells[1].innerHTML=_20.format(_1e.rows[i][2]);_8.remove(tr.cells[1],"MaxPct");_8.remove(tr.cells[1],"MinPct");if(_1e.rows[i][2]==_1e.maxPct){_8.add(tr.cells[1],"MaxPct");}if(_1e.rows[i][2]==_1e.minPct){_8.add(tr.cells[1],"MinPct");}}},createUIExpanded:function(_21){this.inherited(arguments);var _22=_21.addHeader("div",{"class":"RelatedVariables_Labels"});this.highLabel=_4.create("div",{"class":"RelatedVariables_HighLabel"},_22);this.lowLabel=_4.create("div",{"class":"RelatedVariables_LowLabel"},_22);this.table=_21.addContent("table",{"class":"RelatedVariables_Table","cellpadding":"2","cellspacing":"0"});_3.createCols(this.table,[0.35,0.15,0.15,0.175,0.175]);var tr=this.table.insertRow(0);this._appendSortHeader(tr,_7.indicatorCol,0,{"class":"RelatedVariables_TextColumnHeader"});this._appendSortHeader(tr,_7.valueCol,2,{"class":"RelatedVariables_ValueColumnHeader"});this._appendSortHeader(tr,_7.difCol,3,{"class":"RelatedVariables_DifferenceColumnHeader","colspan":"3"});var _23=_21.addFooter("div",{"class":"RelatedVariables_ComparisonDiv"});_4.create("div",{"class":"RelatedVariables_ComparisonLabel",innerHTML:_7.chartLabel},_23);this._createComboBox(_23);},createUICollapsed:function(_24){this.inherited(arguments);this.table=_24.addContent("table",{"class":"RelatedVariables_Table","cellpadding":"2","cellspacing":"0"});_3.createCols(this.table,[0.7,0.3]);var tr=this.table.insertRow(0);this._appendSortHeader(tr,_7.indicatorCol,0,{"class":"RelatedVariables_TextColumnHeader"});this._appendSortHeader(tr,_7.valueCol,2,{"class":"RelatedVariables_ValueColumnHeader"});}});return _b;});