// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
require({cache:{"url:esri/dijit/DimensionalProfile/templates/DimensionalProfile.html":'\x3cdiv role\x3d"presentation" class\x3d"${baseClass}" data-dojo-attach-point\x3d"containerNode"\x3e\r\n  \x3cdiv data-dojo-attach-point\x3d"_chartNode" class\x3d"${baseClass}ChartNode"\x3e\x3c/div\x3e\r\n    \x3cdiv\x3e\r\n      \x3cdiv data-dojo-attach-point\x3d"_chartLegendNode"\x3e\x3c/div\x3e\r\n    \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("esri/dijit/DimensionalProfile/MultiDimensionalProfile","dojo/aspect dojo/_base/declare dojo/_base/lang dojo/_base/array dijit/registry dijit/_WidgetBase dijit/_OnDijitClickMixin dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/_base/Color dojox/charting/Chart dojox/charting/plot2d/Grid dojox/charting/plot2d/Markers dojox/charting/themes/ThreeD dojox/charting/SimpleTheme dojox/charting/widget/SelectableLegend dojox/charting/action2d/Magnify dojox/charting/action2d/Highlight dojox/charting/action2d/Tooltip ../../request ../../graphic ../../TimeExtent ../../layers/DimensionalDefinition ../../layers/RasterFunction dojo/i18n!../../nls/jsapi dojo/text!./templates/DimensionalProfile.html xstyle/css!./css/MultiDimensionalProfile.css".split(" "),function(q,
r,d,l,p,t,u,v,w,n,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M){return r([t,u,v,w],{declaredClass:"esri.dijit.MultiDimensionalProfile",baseClass:"esriMultiDimensionalChart",templateString:M,SERIES_NAME_DIMENSIONS:"Dimensions",SERIES_NAME_LEGEND:"Point",_samplingDataCount:50,_reduceDataPoints:!0,_chartRenderingOptions:null,_defaultXAxisRange:{min:Number.MAX_VALUE,max:Number.MIN_VALUE},_defaultYAxisRange:{min:0,max:100},_xAxisRange:null,_yAxisRange:null,_profileResults:[],_maxResultCount:4,_map:null,_layers:[],
_dimension:null,_variable:null,_chart:null,_valueIndicator:[],_drawProfileGeometry:!0,_mapGraphics:[],_chartLocationGraphic:null,_posIndicator:null,_negIndicator:null,_chartLocationGraphicsLayer:null,_defaultMapSymbol:{type:"esriSMS",style:"esriSMSCross",color:[0,0,0,0],size:13,angle:0,xoffset:0,yoffset:0,outline:{type:"esriSLS",style:"esriSLSSolid",color:[0,0,0,255],width:3}},_profileSeries:[{stroke:"#ff00a9",fill:""},{stroke:"#00ff00",fill:""},{stroke:"#ff5722",fill:""},{stroke:"#0900ff",fill:""},
{stroke:"#845422",fill:""},{stroke:"#6C618D",fill:""}],_highlightColor:"#ffff00",_highlightSeriesName:"Current Selection",constructor:function(a){this._layers=[];this._i18n=L;a.hasOwnProperty("map")&&(this._map=a.map);a.hasOwnProperty("layers")&&a.layers.forEach(function(a){a.options=this._updateLayerOptions(a);this._layers.push(a)},this);1<this._layers.length&&(this._maxResultCount=this._layers.length);a.hasOwnProperty("dimension")&&(this._dimension=a.dimension);a.hasOwnProperty("variable")&&(this._variable=
a.variable);this._chartRenderingOptions=d.mixin({xAxisTitle:"X",yAxisTitle:"Y",chartFontFamily:"verdana",chartTitleFontSize:13,axisTitleFontSize:11,axisLabelFontSize:9,indicatorFontColor:"#eee",indicatorFillColor:"#666",titleFontColor:"#eee",axisFontColor:"#ccc",axisMajorTickColor:"#333",profileBackgroundTopColor:[250,250,250,.8],profileBackgroundBottomColor:[229,230,235,.7],profileLineColor:"#D2B48C",profileTopColor:"#8B4513",profileBottomColor:"#CD853F",indicatorMarkerStrokeColor:"#FF0000",indicatorMarkerSymbol:"m -6 -6, l 12 12, m 0 -12, l -12 12",
profileGeometrySymbol:this._defaultMapSymbol},a.chartOptions||{})},postCreate:function(){this.inherited(arguments);null!==p.getEnclosingWidget(this.domNode)&&this.own(q.after(p.getEnclosingWidget(this.domNode),"resize",d.hitch(this,this.resize),!0))},startup:function(){this.inherited(arguments);if(this._map&&this._layers.length&&this._dimension)if(this.map.loaded)this._initProfile();else this.map.on("load",d.hitch(this,this._initProfile));else this.emit("error",Error(this._i18n.widgets.DimensionalProfile.errors.MissingInputParameters)),
this.destroy()},clear:function(){this._clearProfileGeometriesOnMap();this._resetProfileResults();this._clearIndicators();this._clearChart();this.emit("clear")},refresh:function(){this.emit("refresh")},update:function(a){a?(a=this._reduceProfileResults(d.mixin({},a)),this._updateProfileResults(a),this._updateChart(a),this._updateGraphic(a),this._updateIndicators(),this.emit("update",a)):this.emit(Error(this._i18n.widgets.DimensionalProfile.errors.InvalidProfileResults))},resize:function(){this.inherited(arguments);
this._chart&&this._chart.resize()},destroy:function(){this._chart&&this._chart.destroy();this.inherited(arguments)},_updateLayerOptions:function(a){if(!a||!a.options)return{};var c=d.mixin({},a.options);if(a=a.options.renderingRule){var b=new K(a);b.functionName=a;c.renderingRule=b}return c},_setProfileGeometryAttr:function(a){a?(this._map.setMapCursor("progress"),this._clearMapTime(),this._layers.forEach(d.hitch(this,function(c){var b=this._createNewMapGraphic(a);this._drawProfileGeometryOnMap(b);
this._getProfile(c,b).then(d.hitch(this,function(a){this._map.setMapCursor("default");this.update(a)}),d.hitch(this,function(a){this._map.setMapCursor("default");this.emit("error",a)}))}))):this.emit("error",Error(this._i18n.widgets.DimensionalProfile.errors.NullGeometry))},_setTitleAttr:function(a){this._chart&&(this._chart.title=a,this._chart.dirty=!0,this._chart.render(),this.emit("title-changed"))},_resetProfileResults:function(){this._xAxisRange=d.mixin({},this._defaultXAxisRange);this._yAxisRange=
d.mixin({},this._defaultYAxisRange);this._profileResults=[]},_initProfile:function(){this._buildProfileSeries();this._getDefaultDimensionalRange().then(d.hitch(this,function(a){this._defaultXAxisRange=a;this._resetProfileResults();this._buildChart();this.emit("load")}))},_buildProfileSeries:function(){var a=0,c=2===this._layers.length,b=this._layers[0].options,e,g,f,d,k;e=g=b&&b.legendLabel;b=d=b&&b.seriesColor;c&&(f=(k=this._layers[1].options)&&k.legendLabel,k=k&&k.seriesColor);var m;for(a;a<this._maxResultCount;a++)a<
this._profileSeries.length&&c?(e=0===Math.abs(a%2)?g:f,b=0===Math.abs(a%2)?d:k):a<this._profileSeries.length&&!c&&g?e=g+" "+a:a>=this._profileSeries.length&&(m="#"+Math.floor(16777215*Math.random()).toString(16),this._profileSeries.push({stroke:m,fill:""})),b&&(this._profileSeries[a].stroke=b),this._profileSeries[a].name=this.SERIES_NAME_DIMENSIONS+"_"+a,this._profileSeries[a].legend=e||this.SERIES_NAME_LEGEND+" "+a},_buildChart:function(){var a=new x(this._chartNode,{title:this._chartRenderingOptions.title,
titlePos:"top",titleGap:10,titleFont:d.replace("normal normal bold {chartTitleFontSize}pt {chartFontFamily}",this._chartRenderingOptions),titleFontColor:this._chartRenderingOptions.titleFontColor});if(2===this._layers.length){var c=new B({markers:{CIRCLE:"m-3,0 c0,-4 6,-4 6,0 m-6,0 c0,4 6,4 6,0",SQUARE:"m-3,-3 l0,6 6,0 0,-6 z"}});a.setTheme(c)}else a.setTheme(A);a.fill="transparent";a.theme.axis.stroke.width=2;a.theme.axis.majorTick.color=n.named.white.concat(.5);a.theme.axis.majorTick.width=1;a.theme.plotarea.fill=
{type:"linear",space:"plot",x1:50,y1:100,x2:50,y2:0,colors:[{offset:0,color:this._chartRenderingOptions.profileBackgroundTopColor},{offset:1,color:this._chartRenderingOptions.profileBackgroundBottomColor}]};a.addAxis("y",{min:this._yAxisRange.min,max:this._yAxisRange.max,fontColor:this._chartRenderingOptions.axisFontColor,font:d.replace("normal normal bold {axisLabelFontSize}pt {chartFontFamily}",this._chartRenderingOptions),vertical:!0,natural:!0,fixed:!0,includeZero:!1,majorLabels:!0,minorLabels:!0,
majorTicks:!0,minorTicks:!0,majorTick:{color:this._chartRenderingOptions.axisMajorTickColor,length:6},title:this._chartRenderingOptions.yAxisTitle,titleGap:30,titleFont:d.replace("normal normal bold {axisTitleFontSize}pt {chartFontFamily}",this._chartRenderingOptions),titleFontColor:this._chartRenderingOptions.titleFontColor,titleOrientation:"axis"});a.addAxis("x",{min:this._xAxisRange.min,max:this._xAxisRange.max,fontColor:this._chartRenderingOptions.axisFontColor,font:d.replace("normal normal bold {axisLabelFontSize}pt {chartFontFamily}",
this._chartRenderingOptions),natural:!0,fixed:!0,includeZero:!1,majorLabels:!0,minorLabels:!0,majorTicks:!0,minorTicks:!0,majorTick:{color:this._chartRenderingOptions.axisMajorTickColor,length:6},title:this._chartRenderingOptions.xAxisTitle,titleGap:5,titleFont:d.replace("normal normal bold {axisTitleFontSize}pt {chartFontFamily}",this._chartRenderingOptions),titleFontColor:this._chartRenderingOptions.titleFontColor,titleOrientation:"away",labelFunc:d.hitch(this,this._formatChartValues)});a.addPlot("grid",
{type:y,hMajorLines:!0,hMinorLines:!1,vMajorLines:!1,vMinorLines:!1});a.addPlot("default",{type:z,tension:"X"});var c={plot:"default",stroke:{width:1.5,color:this._chartRenderingOptions.profileLineColor},fill:this._chartRenderingOptions.profileTopColor},b=d.clone(c);b.stroke.width=5;b.stroke.color=this._highlightColor;b.fill=this._highlightColor;a.addSeries(this._highlightSeriesName,[],b);var b=0,e;for(b;b<this._maxResultCount;b++)e=d.clone(c),e.stroke.color=this._profileSeries[b].stroke,e.fill=this._profileSeries[b].stroke,
e.legend=this._profileSeries[b].legend,a.addSeries(this._profileSeries[b].name,[],e);new D(a,"default",{scale:3});new E(a,"default");new F(a,"default");a.render();a.connectToPlot("default",d.hitch(this,function(a){if("onclick"===a.type){var b=a.run.data[a.index]||a;this._chart.updateSeries(this._highlightSeriesName,[b]);this._chart.render();a=b?new Date(b.closestXValue||b.x):new Date(a.x);this._setMapTime(a,a)}}));c=new C({chart:a,autoScale:!0},this._chartLegendNode);this._chart=a;this._chartLegend=
c},_formatChartValues:function(a,c){return this._dimension&&"stdtime"===this._dimension.toLowerCase()?(new Date(c)).toUTCString().substring(5,16):c},_chartTooltipForX:function(a){if(a)return a=a.x||a,this._dimension&&"stdtime"===this._dimension.toLowerCase()&&(a=(new Date(a)).toUTCString().substring(5,16)),this._chartRenderingOptions.xAxisTitle+": "+a},_chartTooltipForY:function(a){if(a)return a=a.y||a,a="string"===typeof a?parseFloat(a):a,this._chartRenderingOptions.yAxisTitle+": "+a.toFixed(3)},
_getProfile:function(a,c){var b=a.layer,e=c&&c.geometry;if(!b||!c||!e)return Error(this.strings.errors.UnableToProcessResults);var e={f:"json",geometry:JSON.stringify(e.toJson()),geometryType:"esriGeometryPoint",returnGeometry:!1,returnCatalogItems:!0},g=a.options,f=b.mosaicRule||b.defaultMosaicRule;g.variable&&f&&(f=d.clone(f),f.multidimensionalDefinition.push(new J({variableName:g.variable})),e.mosaicRule=JSON.stringify(f.toJson()));var f=["value"],h=g&&g.renderingRule||b.renderingRule;h&&(f.push(h.functionName.toLowerCase()),
e.renderingRule=JSON.stringify(h.toJson()));(g&&g.hasOwnProperty("useMapTime")?g.useMapTime:b.useMapTime)&&this._map.timeExtent&&(e.time=this._map.timeExtent.toJson().join(","));return G({url:b.url+"/identify",handleAs:"json",content:e}).then(d.hitch(this,function(a){if(a&&!(1>a.catalogItems.length)){var e=a.catalogItems.features,d=[],f=this._getLayerVariable(b);l.forEach(e,function(b,c){var e=a.properties.Values[c],g=b.attributes;!e||"nodata"===e.toLowerCase()||f&&g.Variable.toLowerCase()!==f.toLowerCase()||
(e={x:g[this.dimension],y:e,tooltip:this._chartTooltipForX(g[this.dimension])+" , "+this._chartTooltipForY(e)},d.push(e))},this);return{values:d,graphic:c}}}),d.hitch(this,function(){return Error(this.strings.errors.UnableToProcessResults)}))},_updateProfileResults:function(a){if(a){this._profileResults.length===this._profileSeries.length?(a.series=this._profileResults[0].series,this._profileResults.shift()):a.series=this._profileSeries[this._profileResults.length];a.values.sort(function(a,b){return a.x-
b.x});this._profileResults.push(a);a={min:Number.MAX_VALUE,max:Number.MIN_VALUE};var c,b;c=d.mixin({},a);b=d.mixin({},a);l.forEach(this._profileResults,function(a){var e=this._getArrayMin(a.values,"x"),d=this._getArrayMax(a.values,"x"),h=this._getArrayMin(a.values,"y");a=this._getArrayMax(a.values,"y");c.min=e<c.min?e:c.min;c.max=d>c.max?d:c.max;b.min=h<b.min?h:b.min;b.max=a>b.max?a:b.max},this);this._xAxisRange=c;this._yAxisRange=b;this._yAxisRange.min=b.min-.03*b.min;this._yAxisRange.max=b.max+
.03*b.max}},_updateChart:function(a){this._chart&&(this._chart.getAxis("x").opt.min=this._xAxisRange.min,this._chart.getAxis("x").opt.max=this._xAxisRange.max,this._chart.getAxis("y").opt.min=this._yAxisRange.min,this._chart.getAxis("y").opt.max=this._yAxisRange.max,this._chart.dirty=!0,a&&this._chart.updateSeries(a.series.name,a.values),this._chart.render(),this._chartLegend.refresh())},_clearChart:function(){if(this._chart){var a;for(a=0;a<this._chart.series.length;a++)this._chart.updateSeries(this._chart.series[a].name,
[]);this._chart.render();this._chartLegend.refresh();this._clearMapTime()}},_clearIndicators:function(){this._valueIndicator&&(l.forEach(this._valueIndicator,function(a){a.destroy();a=null}),this._valueIndicator=[])},_updateIndicators:function(){if(this._chart){this._clearIndicators();var a={mouseOver:!0,font:"normal normal bold 8pt Tahoma",fontColor:this._chartRenderingOptions.indicatorFontColor,fill:this._chartRenderingOptions.indicatorFillColor,markerFill:"none",markerStroke:{color:this._chartRenderingOptions.indicatorMarkerStrokeColor,
width:3},markerSymbol:this._chartRenderingOptions.indicatorMarkerSymbol},c=0,b;for(c;c<this._profileResults.length;c++)b=this._getSeriesLegend(this.SERIES_NAME_DIMENSIONS+"_"+c),b={label:b||this._chartRenderingOptions.yAxisTitle},b={labelFunc:d.hitch(b,this._chartTooltipForY)},d.mixin({series:this.SERIES_NAME_DIMENSIONS+"_"+c,offset:{x:10,y:20*(c+1)}},b,a);this._chart.fullRender()}},_getSeriesLegend:function(a){return(a=this._chart.getSeries(a))?a.legend:""},_createNewMapGraphic:function(a){if(this._map&&
a){var c=this._chartRenderingOptions.profileGeometrySymbol,c=c.hasOwnProperty("type")?c:c.toJson();"esriSMS"!==c.type&&"esriPMS"!==c.type&&(c=this._defaultMapSymbol);return new H({geometry:a,symbol:c})}},_drawProfileGeometryOnMap:function(a){this._map&&a&&this._drawProfileGeometry&&(this._mapGraphics.length===this._maxResultCount&&(this._map.graphics.remove(this._mapGraphics[0]),this._mapGraphics.shift()),this._mapGraphics.push(a),this._map.graphics.add(a))},_updateGraphic:function(a){if(a&&a.graphic){var c=
a.graphic;if(a=a.series)c.symbol.color=new n(a.stroke),c.symbol.outline.color=new n(a.stroke),c.draw()}},_clearProfileGeometriesOnMap:function(){this._mapGraphics&&(l.forEach(this._mapGraphics,function(a){this._map.graphics.remove(a)},this),this._mapGraphics=[])},_reduceProfileResults:function(a){var c=a.values;if(!this._reduceDataPoints||c.length<3*this._samplingDataCount)return a;var b=[],e=this._samplingDataCount/3,d=Math.ceil(c.length/e),f,h=[],k,m,l,n;for(f=0;f<d;f++)h=0===f?f*e:f*e+1,k=(f+1)*
e,h=c.slice(h,k),m=this._getArrayMin(h,"x"),l=this._getArrayMax(h,"x"),k=this._getArrayMin(h,"y"),n=this._getArrayMax(h,"y"),m=(m+l)/2,k=(k+n)/2,h=this._findClosestValue(m,h,"x"),b.push({x:m,y:k,tooltip:this._chartTooltipForX(m)+" , "+this._chartTooltipForY(k),closestXValue:h});a.values=b;return a},_getArrayMax:function(a,c){var b=l.map(a,function(a){return a[c]});return Math.max.apply(Math,b)},_getArrayMin:function(a,c){var b=l.map(a,function(a){return a[c]});return Math.min.apply(Math,b)},_getLayerVariable:function(a){var c=
null;a&&a.mosaicRule&&a.mosaicRule.multidimensionalDefinition&&a.mosaicRule.multidimensionalDefinition.length&&(c=a.mosaicRule.multidimensionalDefinition[0].variableName);return c},_getDefaultDimensionalRange:function(){var a=this._layers[0].layer;if(a){var c=this._getLayerVariable(a),b={min:0,max:100};return a.getMultidimensionalInfo().then(d.hitch(this,function(a){a&&a.variables&&a.variables.length&&c&&l.forEach(a.variables,function(a){a.name.toLowerCase()===c.toLowerCase()&&l.forEach(a.dimensions,
function(a){a.name.toLowerCase()===this.dimension.toLowerCase()&&a.extent&&2===a.extent.length&&(b.min=a.extent[0],b.max=a.extent[1])},this)},this);return b}),function(a){console.log(a);return b})}},_setMapTime:function(a,c){var b=new I;b.startTime=a;b.endTime=c;this.map.setTimeExtent(b)},_clearMapTime:function(){this.map.setTimeExtent(this.map.timeSlider?this.map.timeSlider.getCurrentTimeExtent():null)},_findClosestValue:function(a,c,b){var d=c[0][b],g=Math.abs(a-d);c.forEach(function(c){var e=Math.abs(a-
c[b]);e<g&&(g=e,d=c[b])});return d}})});