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

System.register(["lodash"],function(a,b){"use strict";function c(a){for(var b={},c=0,d=a;c<d.length;c++){var e=d[c],f=Number(e.alias);if(isNaN(f))return;for(var g=0,h=e.datapoints;g<h.length;g++){var i=h[g],j=i[w],k=i[x];if(v.default.isNumber(j)){var l=b[k];l||(l=b[k]={x:k,buckets:{}}),l.buckets[f]={y:f,count:j,values:[],points:[]}}}}return b}function d(a){var b=0,c=0,d=[];v.default.forEach(a,function(a){v.default.forEach(a.buckets,function(e){var f={x:a.x,y:e.y,yBounds:e.bounds,values:e.values,count:e.count};d.push(f),1===d.length&&(b=e.count,c=e.count),b=e.count<b?e.count:b,c=e.count>c?e.count:c})});var e={min:b,max:c};return{cards:d,cardStats:e}}function e(a,b){return v.default.forEach(a,function(a){var c=a.buckets,d={bounds:{bottom:0,top:0},values:[],points:[],count:0},e=c[0]||d,f=c[b]||d,g={y:0,bounds:{bottom:b,top:f.bounds.top||b},values:[],points:[],count:0};g.points=e.points.concat(f.points),g.values=e.values.concat(f.values),g.count=g.values.length,0!==g.count&&(delete c[b],c[0]=g)}),a}function f(a,b,c,d){void 0===d&&(d=1);for(var e={},f=function(a){var b=a.datapoints,d=a.label;v.default.forEach(b,function(a){var b=k(a[x],c);g(e,a,b,d)})},h=0,i=a;h<i.length;h++){var j=i[h];f(j)}return v.default.forEach(e,function(a){1!==d?a.buckets=o(a,b,d):a.buckets=l(a,b)}),e}function g(a,b,c,d){var e=b[w];if(null!==e&&void 0!==e&&!isNaN(e)){var f=v.default.concat(b,d);a[c]&&a[c].values?(a[c].values.push(e),a[c].points.push(f)):a[c]={x:c,values:[e],points:[f]}}}function h(a,b,c,d,e){var f=1;d.length>3&&(f=parseInt(d[2])),a[b]?(a[b].values.push(c),a[b].points.push(d),a[b].count+=f):a[b]={y:b,bounds:e,values:[c],points:[d],count:f}}function i(a,b,c){return 1===c?k(a,b):n(a,b,c)}function j(a,b){var c,d;return c=Math.floor(a/b)*b,d=(Math.floor(a/b)+1)*b,{bottom:c,top:d}}function k(a,b){var c=j(a,b);return c.bottom}function l(a,b){var c=a.values,d=a.points,e={};return v.default.forEach(c,function(a,c){var f=j(a,b),g=f.bottom;h(e,g,a,d[c],f)}),e}function m(a,b,c){var d,e;if(0===a)return{bottom:0,top:0};var f,g,h=q(a,c);if(1!==b&&b){var i=1/b,j=h-Math.floor(h);j=Math.floor(j/i)*i,f=Math.floor(h)+j,g=f+i}else f=Math.floor(h),g=f+1;return e=Math.pow(c,f),d=Math.pow(c,g),{bottom:e,top:d}}function n(a,b,c){var d=m(a,b,c);return d.bottom}function o(a,b,c){var d=a.values,e=a.points,f={};return v.default.forEach(d,function(a,d){var g=m(a,b,c),i=g.bottom;h(f,i,a,e[d],g)}),f}function p(a){var b=v.default.compact(v.default.map(a.datapoints,function(a){return a[0]}));return v.default.min(b)}function q(a,b){return Math.log(a)/Math.log(b)}function r(a,b){void 0===b&&(b=1);var c=1/0;if(0===a.length)return 0;if(1===a.length)return a[0];a=v.default.sortBy(a);for(var d=1;d<a.length;d++){var e=s(a[d],a[d-1],b);c=e<c?e:c}return c}function s(a,b,c){if(void 0===c&&(c=1),1===c)return Math.abs(b-a);var d=Math.max(a,b)/Math.min(a,b);return q(d,c)}function t(a,b){var c=!u(a,b);return v.default.forEach(a,function(a,d){return b[d]?u(a.buckets,b[d].buckets)?(c=!1,!1):(v.default.forEach(a.buckets,function(a,e){return b[d].buckets&&b[d].buckets[e]&&b[d].buckets[e].values?!!(c=v.default.isEqual(v.default.sortBy(a.values),v.default.sortBy(b[d].buckets[e].values)))&&void 0:(c=!1,!1)}),!!c&&void 0):(c=!1,!1)}),c}function u(a,b){return(v.default.isEmpty(a)||v.default.isEmpty(b))&&!(v.default.isEmpty(a)&&v.default.isEmpty(b))}b&&b.id;a("elasticHistogramToHeatmap",c),a("convertToCards",d),a("mergeZeroBuckets",e),a("convertToHeatMap",f),a("getValueBucketBound",i),a("getMinLog",p),a("calculateBucketSize",r),a("isHeatmapDataEqual",t);var v,w,x;return{setters:[function(a){v=a}],execute:function(){w=0,x=1}}});