define(["highcharts"],function(e){var t,n,r,i;return n=function(t){var n;return n=e.getOptions().colors,n[t%n.length]},t=/\d{4}-\d{2]-\d{2]/,r=function(e){var t,n,r;return r=parseInt(e.substr(0,4)),n=parseInt(e.substr(5,2))-1,t=parseInt(e.substr(8,2)),Date.UTC(r,n,t)},i=function(t,i,s){var o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z;if(i.length>2)throw new Error("3-dimensional charts are not supported.                Specify which field the series applies to.");if(!i)throw new Error("The datafield instances must be supplied");k=[],P=[],C=i[0],D=i[1],L=C.get("name"),N=C.get("enumerable")||C.get("simple_type")==="boolean",A=C.get("simple_type")==="date"?"datetime":"linear",D?(H=D.get("name"),_=D.get("enumerable")||D.get("simple_type")==="boolean",B=D.get("simple_type")==="date"?"datetime":"linear"):(H="Frequency",_=!1,B="linear"),N&&_?(u="scatter",k.push(" "),P.push(" ")):D&&!N&&!_?u="scatter":_?u="scatter":A==="datetime"||B==="datetime"?u="line":u="column",w={},a=t.clustered,U=t.data;for(c=F=0,q=U.length;F<q;c=++F)y=U[c],s!=null?x=y.values.slice(s,s+1)[0]:x="",(b=w[x])?(b.data.push(y),b.stats.min=Math.min(b.stats.min,y.count),b.stats.max=Math.max(b.stats.max,y.count),b.stats.sum+=y.count):(b=w[x]={name:x,stats:{min:y.count,max:y.count,sum:y.count}},N&&_?b.data=[{x:0,y:0,radius:0,sentinel:!0},y]:b.data=[y]),T=y.values[0],T===null&&(T="(no data)"),N?((h=k.indexOf(T.toString()))===-1&&(h=k.push(T.toString())-1),T=h):A==="datetime"&&(T=r(T)),D?(M=y.values[1],M===null&&(M="(no data)"),_?((h=P.indexOf(M.toString()))===-1&&(h=P.push(M.toString())-1),M=h):B==="datetime"&&(M=r(M))):M=y.count,y.x=T,y.y=M;E=[],N&&_&&(O=k.push(" ")-1,j=P.push(" ")-1),S=0;for(d in w){b=w[d],N&&_&&(b.data.push({x:0,y:j,radius:0,sentinel:!0}),b.data.push({x:O,y:j,radius:0,sentinel:!0}),b.data.push({x:O,y:j,radius:0,sentinel:!0})),E.push(b),o=b.stats.avg=b.stats.sum/parseFloat(b.data.length,10),p=b.stats.max;if(u==="scatter"){z=b.data;for(I=0,R=z.length;I<R;I++){g=z[I];if(g.sentinel)continue;v=Math.min(Math.max(parseInt(parseFloat(g.count,10)/o*5)/10,.05),1),f=e.Color(n(S)).setOpacity(v),g.marker={fillColor:f.get()},N&&(g.marker.radius=7)}}S++}return u==="scatter"&&N?E[1]?l=function(){return"<b>"+this.series.name+"</b><br>"+this.point.count+" for ("+this.series.xAxis.categories[this.point.x]+", "+this.series.yAxis.categories[this.point.y]+")"}:l=function(){return""+this.point.count+" for ("+this.series.xAxis.categories[this.point.x]+", "+this.series.yAxis.categories[this.point.y]+")"}:E[1]?l=function(){return"<b>"+this.series.name+"</b><br>"+this.point.count+" for ("+e.numberFormat(parseFloat(this.x))+", "+e.numberFormat(parseFloat(this.y))+")"}:l=function(){return""+this.point.count+" for ("+e.numberFormat(parseFloat(this.x))+", "+e.numberFormat(parseFloat(this.y))+")"},m={clustered:a,chart:{type:u},title:{text:D?""+L+" vs. "+H:""+L+" "+H},series:E,xAxis:{title:{text:L},type:A},yAxis:{title:{text:H},type:B},tooltip:{formatter:l,borderRadius:3,borderWidth:1}},k.length&&(m.xAxis.categories=k),P.length&&(m.yAxis.categories=P),E[1]||(m.legend={enabled:!1}),u==="scatter"&&(m.yAxis.gridLineWidth=0,N||(m.chart.zoomType="xy")),m},{processResponse:i}})