/*! grafana - v4.5.1 - 2017-09-19
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["lodash","app/core/time_series2","app/core/core"],function(a,b){"use strict";var c,d,e,f;b&&b.id;return{setters:[function(a){c=a},function(a){d=a},function(a){e=a}],execute:function(){f=function(){function a(a){this.panel=a}return a.prototype.getSeriesList=function(a){var b=this;if(!a.dataList||0===a.dataList.length)return[];var c;if(a.dataList&&a.dataList.length>0){c=a.dataList[0];var d=this.getAutoDetectXAxisMode(c);this.panel.xaxis.mode!==d&&(this.panel.xaxis.mode=d,this.setPanelDefaultsForNewXAxisMode())}switch(this.panel.xaxis.mode){case"series":case"histogram":case"time":return a.dataList.map(function(c,d){return b.timeSeriesHandler(c,d,a)});case"field":return this.customHandler(c)}},a.prototype.getAutoDetectXAxisMode=function(a){switch(a.type){case"docs":return"field";case"table":return"field";default:return"series"===this.panel.xaxis.mode?"series":"histogram"===this.panel.xaxis.mode?"histogram":"time"}},a.prototype.setPanelDefaultsForNewXAxisMode=function(){switch(this.panel.xaxis.mode){case"time":this.panel.bars=!1,this.panel.lines=!0,this.panel.points=!1,this.panel.legend.show=!0,this.panel.tooltip.shared=!0,this.panel.xaxis.values=[];break;case"series":this.panel.bars=!0,this.panel.lines=!1,this.panel.points=!1,this.panel.stack=!1,this.panel.legend.show=!1,this.panel.tooltip.shared=!1,this.panel.xaxis.values=["total"];break;case"histogram":this.panel.bars=!0,this.panel.lines=!1,this.panel.points=!1,this.panel.stack=!1,this.panel.legend.show=!1,this.panel.tooltip.shared=!1}},a.prototype.timeSeriesHandler=function(a,b,c){var f=a.datapoints||[],g=a.target,h=b%e.colors.length,i=this.panel.aliasColors[g]||e.colors[h],j=new d.default({datapoints:f,alias:g,color:i,unit:a.unit});if(f&&f.length>0){var k=f[f.length-1][1],l=c.range.from;k-l<-1e4&&(j.isOutsideRange=!0)}return j},a.prototype.customHandler=function(a){var b=this.panel.xaxis.name;if(!b)throw{message:"No field name specified to use for x-axis, check your axes settings"};return[]},a.prototype.validateXAxisSeriesValue=function(){switch(this.panel.xaxis.mode){case"series":if(0===this.panel.xaxis.values.length)return void(this.panel.xaxis.values=["total"]);var a=this.getXAxisValueOptions({}),b=c.default.find(a,{value:this.panel.xaxis.values[0]});return void(b||(this.panel.xaxis.values=["total"]))}},a.prototype.getDataFieldNames=function(a,b){function d(a){c.default.forEach(a,function(a,f){if(c.default.isObject(a))g.push(f),d(a);else if(!b||c.default.isNumber(a)){var h=g.concat(f).join(".");e.push(h)}}),g.pop()}if(0===a.length)return[];var e=[],f=a[0],g=[];return"docs"===f.type?0===f.datapoints.length?[]:(d(f.datapoints[0]),e):void 0},a.prototype.getXAxisValueOptions=function(a){switch(this.panel.xaxis.mode){case"time":return[];case"series":return[{text:"Avg",value:"avg"},{text:"Min",value:"min"},{text:"Max",value:"max"},{text:"Total",value:"total"},{text:"Count",value:"count"}]}},a.prototype.pluckDeep=function(a,b){for(var c=b.split("."),d=a,e=0;e<c.length;++e){if(!d[c[e]])return;d=d[c[e]]}return d},a}(),a("DataProcessor",f)}}});