-
Notifications
You must be signed in to change notification settings - Fork 0
/
line-chart.min.js
6 lines (6 loc) · 27 KB
/
line-chart.min.js
1
2
3
4
5
6
/*
line-chart - v1.1.2 - 12 July 2014
https://github.com/n3-charts/line-chart
Copyright (c) 2014 n3-charts
*/
var directive,m,mod,old_m,__indexOf=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};old_m=angular.module("n3-charts.linechart",["n3charts.utils"]),m=angular.module("n3-line-chart",["n3charts.utils"]),directive=function(a,b){return old_m.directive(a,b),m.directive(a,b)},directive("linechart",["n3utils","$window","$timeout",function(a,b,c){var d;return d=function(d,e,f){var g,h,i,j,k,l;return l=a,g=l.getDefaultMargins(),d.updateDimensions=function(a){var b,c,d,f;return f=l.getPixelCssProp(e[0].parentElement,"padding-top"),b=l.getPixelCssProp(e[0].parentElement,"padding-bottom"),c=l.getPixelCssProp(e[0].parentElement,"padding-left"),d=l.getPixelCssProp(e[0].parentElement,"padding-right"),a.width=(e[0].parentElement.offsetWidth||900)-c-d,a.height=(e[0].parentElement.offsetHeight||500)-f-b},d.update=function(){return d.updateDimensions(g),d.redraw(g)},i=!1,h={onSeriesVisibilityChange:function(a){var b,c,e;return e=a.series,b=a.index,c=a.newVisibility,i=!0,d.options.series[b].visible=c,d.$apply(),i=!1}},d.redraw=function(a){var b,c,g,i,j,k,m;return k=l.sanitizeOptions(d.options,f.mode),i=angular.extend(h,l.getTooltipHandlers(k)),g=l.getDataPerSeries(d.data,k),j="thumbnail"===f.mode,l.clean(e[0]),m=l.bootstrap(e[0],a),b=l.createAxes(m,a,k.axes).andAddThemIf(j),g.length&&l.setScalesDomain(b,d.data,k.series,m,k),j?l.adjustMarginsForThumbnail(a,b):l.adjustMargins(m,a,k,d.data),l.createContent(m,i),g.length&&(c=l.getBestColumnWidth(a,g,k),l.drawArea(m,b,g,k,i).drawColumns(m,b,g,c,k,i).drawLines(m,b,g,k,i),k.drawDots&&l.drawDots(m,b,g,k,i)),k.drawLegend&&l.drawLegend(m,k.series,a,i),"scrubber"===k.tooltip.mode?l.createGlass(m,a,i,b,g,k,c):"none"!==k.tooltip.mode?l.addTooltips(m,a,k.axes):void 0},j=void 0,k=function(){return null!=j&&c.cancel(j),j=c(d.update,1)},b.addEventListener("resize",k),d.$watch("data",d.update,!0),d.$watch("options",function(){return i?void 0:d.update()},!0)},{replace:!0,restrict:"E",scope:{data:"=",options:"="},template:"<div></div>",link:d}}]),mod=angular.module("n3charts.utils",[]),mod.factory("n3utils",["$window","$log","$rootScope",function(a,b){return{addPatterns:function(a,b){var c;return c=a.select("defs").selectAll("pattern").data(b.filter(function(a){return a.striped})).enter().append("pattern").attr({id:function(a){return a.type+"Pattern_"+a.index},patternUnits:"userSpaceOnUse",x:0,y:0,width:60,height:60}).append("g").style({fill:function(a){return a.color},"fill-opacity":.3}),c.append("rect").style("fill-opacity",.3).attr("width",60).attr("height",60),c.append("path").attr("d","M 10 0 l10 0 l -20 20 l 0 -10 z"),c.append("path").attr("d","M40 0 l10 0 l-50 50 l0 -10 z"),c.append("path").attr("d","M60 10 l0 10 l-40 40 l-10 0 z"),c.append("path").attr("d","M60 40 l0 10 l-10 10 l -10 0 z")},drawArea:function(a,b,c,d){var e,f;return e=c.filter(function(a){return"area"===a.type}),this.addPatterns(a,e),f={y:this.createLeftAreaDrawer(b,d.lineMode,d.tension),y2:this.createRightAreaDrawer(b,d.lineMode,d.tension)},a.select(".content").selectAll(".areaGroup").data(e).enter().append("g").attr("class",function(a){return"areaGroup series_"+a.index}).append("path").attr("class","area").style("fill",function(a){return a.striped!==!0?a.color:"url(#areaPattern_"+a.index+")"}).style("opacity",function(a){return a.striped?"1":"0.3"}).attr("d",function(a){return f[a.axis](a.values)}),this},createLeftAreaDrawer:function(a,b,c){return d3.svg.area().x(function(b){return a.xScale(b.x)}).y0(function(b){return a.yScale(b.y0)}).y1(function(b){return a.yScale(b.y0+b.y)}).interpolate(b).tension(c)},createRightAreaDrawer:function(a,b,c){return d3.svg.area().x(function(b){return a.xScale(b.x)}).y0(function(b){return a.y2Scale(b.y0)}).y1(function(b){return a.y2Scale(b.y0+b.y)}).interpolate(b).tension(c)},getPseudoColumns:function(a,b){var c,d;return a=a.filter(function(a){return"column"===a.type}),d={},c=[],a.forEach(function(a){var e,f,g;return f=!1,b.stacks.forEach(function(b,e){var g;return null!=a.id&&(g=a.id,__indexOf.call(b.series,g)>=0)?(d[a.id]=e,__indexOf.call(c,e)<0&&c.push(e),f=!0):void 0}),f===!1?(e=d[a.id]=g=c.length,c.push(e)):void 0}),{pseudoColumns:d,keys:c}},getBestColumnWidth:function(a,b,c){var d,e,f,g,h,i;return b&&0!==b.length?0===b.filter(function(a){return"column"===a.type}).length?10:(i=this.getPseudoColumns(b,c),g=i.pseudoColumns,e=i.keys,f=b[0].values.length+2,h=e.length,d=a.width-a.left-a.right,parseInt(Math.max((d-(f-1)*c.columnsHGap)/(f*h),5))):10},getColumnAxis:function(a,b,c){var d,e,f,g;return g=this.getPseudoColumns(a,c),e=g.pseudoColumns,d=g.keys,f=d3.scale.ordinal().domain(d).rangeBands([0,d.length*b],0),function(a){var c;return null==e[a.id]?0:(c=e[a.id],f(c)-d.length*b/2)}},drawColumns:function(a,b,c,d,e,f){var g,h;return c=c.filter(function(a){return"column"===a.type}),h=this.getColumnAxis(c,d,e),c.forEach(function(a){return a.xOffset=h(a)+.5*d}),g=a.select(".content").selectAll(".columnGroup").data(c).enter().append("g").attr("class",function(a){return"columnGroup series_"+a.index}).style("stroke",function(a){return a.color}).style("fill",function(a){return a.color}).style("fill-opacity",.8).attr("transform",function(a){return"translate("+h(a)+",0)"}).on("mouseover",function(c){var d;return d=d3.select(d3.event.target),"function"==typeof f.onMouseOver?f.onMouseOver(a,{series:c,x:d.attr("x"),y:b[c.axis+"Scale"](d.datum().y0+d.datum().y),datum:d.datum()}):void 0}).on("mouseout",function(){return d3.select(d3.event.target).attr("r",2),"function"==typeof f.onMouseOut?f.onMouseOut(a):void 0}),g.selectAll("rect").data(function(a){return a.values}).enter().append("rect").style({"stroke-opacity":function(a){return 0===a.y?"0":"1"},"stroke-width":"1px","fill-opacity":function(a){return 0===a.y?0:.7}}).attr({width:d,x:function(a){return b.xScale(a.x)},height:function(a){return 0===a.y?b[a.axis+"Scale"].range()[0]:Math.abs(b[a.axis+"Scale"](a.y0+a.y)-b[a.axis+"Scale"](a.y0))},y:function(a){return 0===a.y?0:b[a.axis+"Scale"](Math.max(0,a.y0+a.y))}}),this},drawDots:function(a,b,c,d,e){var f;return f=a.select(".content").selectAll(".dotGroup").data(c.filter(function(a){var b;return("line"===(b=a.type)||"area"===b)&&a.drawDots})).enter().append("g"),f.attr({"class":function(a){return"dotGroup series_"+a.index},fill:function(a){return a.color}}).selectAll(".dot").data(function(a){return a.values}).enter().append("circle").attr({"class":"dot",r:2,cx:function(a){return b.xScale(a.x)},cy:function(a){return b[a.axis+"Scale"](a.y+a.y0)}}).style({stroke:"white","stroke-width":"2px"}),"none"!==d.tooltip.mode&&f.on("mouseover",function(b){var c;return c=d3.select(d3.event.target),c.attr("r",4),"function"==typeof e.onMouseOver?e.onMouseOver(a,{series:b,x:c.attr("cx"),y:c.attr("cy"),datum:c.datum()}):void 0}).on("mouseout",function(){return d3.select(d3.event.target).attr("r",2),"function"==typeof e.onMouseOut?e.onMouseOut(a):void 0}),this},computeLegendLayout:function(a,b,c){var d,e,f,g,h,i,j,k,l,m;for(i=10,l=this,h=this.getLegendItemsWidths(a,"y"),g=[0],e=1;e<h.length;)g.push(h[e-1]+g[e-1]+i),e++;if(k=this.getLegendItemsWidths(a,"y2"),!(k.length>0))return[g];for(m=c.width-c.right-c.left,d=0,j=[],f=k.length-1;f>=0;)j.push(m-d-k[f]),d+=k[f]+i,f--;return j.reverse(),[g,j]},getLegendItemsWidths:function(a,b){var c,d,e,f,g;if(f=this,c=function(a){return f.getTextBBox(a).width},e=a.selectAll(".legendItem."+b),!(e.length>0))return[];for(g=[],d=0;d<e[0].length;)g.push(c(e[0][d])),d++;return g},drawLegend:function(a,b,c,d){var e,f,g,h,i,j,k,l;return k=this,i=a.append("g").attr("class","legend"),e=16,a.select("defs").append("svg:clipPath").attr("id","legend-clip").append("circle").attr("r",e/2),f=i.selectAll(".legendItem").data(b),g=f.enter().append("g").attr({"class":function(a,b){return"legendItem series_"+b+" "+a.axis},opacity:function(b,c){return b.visible===!1?(k.toggleSeries(a,c),"0.2"):"1"}}),f.on("click",function(b,c){var e;return e=k.toggleSeries(a,c),d3.select(this).attr("opacity",e?"1":"0.2"),"function"==typeof d.onSeriesVisibilityChange?d.onSeriesVisibilityChange({series:b,index:c,newVisibility:e}):void 0}),f.append("circle").attr({fill:function(a){return a.color},stroke:function(a){return a.color},"stroke-width":"2px",r:e/2}),f.append("path").attr({"clip-path":"url(#legend-clip)","fill-opacity":function(a){var b;return"area"===(b=a.type)||"column"===b?"1":"0"},fill:"white",stroke:"white","stroke-width":"2px",d:function(a){return k.getLegendItemPath(a,e,e)}}),f.append("circle").attr({"fill-opacity":0,stroke:function(a){return a.color},"stroke-width":"2px",r:e/2}),f.append("text").attr({"class":function(a,b){return"legendText series_"+b},"font-family":"Courier","font-size":10,transform:"translate(13, 4)","text-rendering":"geometric-precision"}).text(function(a){return a.label||a.y}),l=this.computeLegendLayout(a,b,c),h=l[0],j=l[1],g.attr({transform:function(a){return"y"===a.axis?"translate("+h.shift()+","+(c.height-40)+")":"translate("+j.shift()+","+(c.height-40)+")"}}),this},getLegendItemPath:function(a,b,c){var d,e;return"column"===a.type?(e="M"+-b/3+" "+-c/8+" l0 "+c+" ",e+="M0 "+-c/3+" l0 "+c+" ",e+="M"+b/3+" "+-c/10+" l0 "+c+" "):(d="M-"+b/2+" 0"+c/3+" l"+b/3+" -"+c/3+" l"+b/3+" "+c/3+" l"+b/3+" -"+2*c/3,"area"===a.type,d)},toggleSeries:function(a,b){var c;return c=!1,a.select(".content").selectAll(".series_"+b).style("display",function(){return"none"===d3.select(this).style("display")?(c=!0,"initial"):(c=!1,"none")}),c},drawLines:function(a,b,c,d,e){var f,g,h;return f={y:this.createLeftLineDrawer(b,d.lineMode,d.tension),y2:this.createRightLineDrawer(b,d.lineMode,d.tension)},h=a.select(".content").selectAll(".lineGroup").data(c.filter(function(a){var b;return"line"===(b=a.type)||"area"===b})).enter().append("g"),h.style("stroke",function(a){return a.color}).attr("class",function(a){return"lineGroup series_"+a.index}).append("path").attr({"class":"line",d:function(a){return f[a.axis](a.values)}}).style({fill:"none","stroke-width":function(a){return a.thickness},"stroke-dasharray":function(a){return"dashed"===a.lineMode?"10,3":void 0}}),d.tooltip.interpolate&&(g=function(c){var d,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A;r=d3.select(d3.event.target);try{q=d3.mouse(this)}catch(B){f=B,q=[0,0]}for(s=r.datum().values,g=z=0,A=s.length;A>z;g=++z)d=s[g],t=b.xScale(d.x),w=b.yScale(d.y),("undefined"==typeof m||null===m||m>t)&&(m=t,n=d.x),("undefined"==typeof i||null===i||t>i)&&(i=t,j=d.x),("undefined"==typeof o||null===o||o>w)&&(o=w),("undefined"==typeof k||null===k||w>k)&&(k=w),("undefined"==typeof p||null===p||d.y<p)&&(p=d.y),("undefined"==typeof l||null===l||d.y>l)&&(l=d.y);return u=(q[0]-m)/(i-m),x=(q[1]-o)/(k-o),v=Math.round(u*(j-n)+n),y=Math.round((1-x)*(l-p)+p),h={x:v,y:y},"function"==typeof e.onMouseOver?e.onMouseOver(a,{series:c,x:q[0],y:q[1],datum:h}):void 0},h.on("mousemove",g).on("mouseout",function(){return"function"==typeof e.onMouseOut?e.onMouseOut(a):void 0})),this},createLeftLineDrawer:function(a,b,c){return d3.svg.line().x(function(b){return a.xScale(b.x)}).y(function(b){return a.yScale(b.y+b.y0)}).interpolate(b).tension(c)},createRightLineDrawer:function(a,b,c){return d3.svg.line().x(function(b){return a.xScale(b.x)}).y(function(b){return a.y2Scale(b.y+b.y0)}).interpolate(b).tension(c)},getPixelCssProp:function(b,c){var d;return d=a.getComputedStyle(b,null).getPropertyValue(c),+d.replace(/px$/,"")},getDefaultMargins:function(){return{top:20,right:50,bottom:60,left:50}},clean:function(a){return d3.select(a).on("keydown",null).on("keyup",null).select("svg").remove()},bootstrap:function(a,b){var c,d,e;return d3.select(a).classed("chart",!0),e=b.width,c=b.height,d=d3.select(a).append("svg").attr({width:e,height:c}).append("g").attr("transform","translate("+b.left+","+b.top+")"),d.append("defs").attr("class","patterns"),d},createContent:function(a){return a.append("g").attr("class","content")},createGlass:function(a,b,c,d,e,f,g){var h,i,j,k;return j=a.append("g").attr({"class":"glass-container",opacity:0}),k=j.selectAll(".scrubberItem").data(e).enter().append("g").attr("class",function(a,b){return"scrubberItem series_"+b}),h=k.append("g").attr({"class":function(){return"rightTT"}}),h.append("path").attr({"class":function(a,b){return"scrubberPath series_"+b},y:"-7px",fill:function(a){return a.color}}),this.styleTooltip(h.append("text").style("text-anchor","start").attr({"class":function(a,b){return"scrubberText series_"+b},height:"14px",transform:"translate(7, 3)","text-rendering":"geometric-precision"})).text(function(a){return a.label||a.y}),i=k.append("g").attr({"class":function(){return"leftTT"}}),i.append("path").attr({"class":function(a,b){return"scrubberPath series_"+b},y:"-7px",fill:function(a){return a.color}}),this.styleTooltip(i.append("text").style("text-anchor","end").attr({"class":function(a,b){return"scrubberText series_"+b},height:"14px",transform:"translate(-13, 3)","text-rendering":"geometric-precision"})).text(function(a){return a.label||a.y}),k.append("circle").attr({"class":function(a,b){return"scrubberDot series_"+b},fill:"white",stroke:function(a){return a.color},"stroke-width":"2px",r:4}),j.append("rect").attr({"class":"glass",width:b.width-b.left-b.right,height:b.height-b.top-b.bottom}).style("fill","white").style("fill-opacity",1e-6).on("mouseover",function(){return c.onChartHover(a,d3.select(d3.event.target),d,e,f,g)})},getDataPerSeries:function(a,b){var c,d,e,f;return e=b.series,c=b.axes,e&&e.length&&a&&a.length?(f=e.map(function(c,d){var e;return e={index:d,name:c.y,values:[],color:c.color,axis:c.axis||"y",xOffset:0,type:c.type,thickness:c.thickness,drawDots:c.drawDots!==!1},c.striped===!0&&(e.striped=!0),null!=c.lineMode&&(e.lineMode=c.lineMode),c.id&&(e.id=c.id),a.filter(function(a){return null!=a[c.y]}).forEach(function(a){return e.values.push({x:a[b.axes.x.key],y:a[c.y],y0:0,axis:c.axis||"y"})}),e}),null==b.stacks||0===b.stacks.length?f:(d=d3.layout.stack().values(function(a){return a.values}),b.stacks.forEach(function(a){var b;if(a.series.length>0)return b=f.filter(function(b){var c;return null!=b.id&&(c=b.id,__indexOf.call(a.series,c)>=0)}),d(b)}),f)):[]},resetMargins:function(a){var b;return b=this.getDefaultMargins(),a.left=b.left,a.right=b.right,a.top=b.top,a.bottom=b.bottom},adjustMargins:function(a,b,c,d){var e,f,g,h,i;return this.resetMargins(b),d&&d.length&&c.series.length&&(b.left=this.getWidestTickWidth(a,"y"),b.right=this.getWidestTickWidth(a,"y2"),0===b.right&&(b.right=20),"scrubber"!==c.tooltip.mode&&(i=c.series,e=i.filter(function(a){return"y2"!==a.axis}),f=this.getWidestOrdinate(d,e,c),b.left=this.estimateSideTooltipWidth(a,f).width+20,g=i.filter(function(a){return"y2"===a.axis}),g.length))?(h=this.getWidestOrdinate(d,g,c),b.right=this.estimateSideTooltipWidth(a,h).width+20):void 0},adjustMarginsForThumbnail:function(a){return a.top=1,a.bottom=2,a.left=0,a.right=1},estimateSideTooltipWidth:function(a,b){var c,d;return d=a.append("text"),d.text(""+b),this.styleTooltip(d),c=this.getTextBBox(d[0][0]),d.remove(),c},getTextBBox:function(a){return a.getBBox()},getWidestTickWidth:function(a,b){var c,d,e,f;return d=0,c=this.getTextBBox,e=a.select("."+b+".axis").selectAll(".tick"),null!=(f=e[0])&&f.map(function(a){return d=Math.max(d,c(a).width)}),d},getWidestOrdinate:function(a,b,c){var d;return d="",a.forEach(function(a){return b.forEach(function(b){var e,f;return e=a[b.y],null!=b.axis&&(null!=(f=c.axes[b.axis])?f.labelFunction:void 0)&&(e=c.axes[b.axis].labelFunction(e)),null!=e&&(""+e).length>(""+d).length?d=e:void 0})}),d},getDefaultOptions:function(){return{tooltip:{mode:"scrubber"},lineMode:"linear",tension:.7,axes:{x:{type:"linear",key:"x"},y:{type:"linear"}},series:[],drawLegend:!0,drawDots:!0,stacks:[],columnsHGap:5}},sanitizeOptions:function(a,b){return null==a?this.getDefaultOptions():("thumbnail"===b&&(a.drawLegend=!1,a.drawDots=!1,a.tooltip={mode:"none",interpolate:!1}),a.series=this.sanitizeSeriesOptions(a.series),a.stacks=this.sanitizeSeriesStacks(a.stacks,a.series),a.axes=this.sanitizeAxes(a.axes,this.haveSecondYAxis(a.series)),a.lineMode||(a.lineMode="linear"),a.tension=/^\d+(\.\d+)?$/.test(a.tension)?a.tension:.7,this.sanitizeTooltip(a),a.drawLegend=a.drawLegend!==!1,a.drawDots=a.drawDots!==!1,angular.isNumber(a.columnsHGap)||(a.columnsHGap=5),a)},sanitizeSeriesStacks:function(a,c){var d;return null==a?[]:(d={},c.forEach(function(a){return d[a.id]=a}),a.forEach(function(a){return a.series.forEach(function(c){var e;if(e=d[c],null!=e){if(e.axis!==a.axis)return b.warn("Series "+c+" is not on the same axis as its stack")}else if(!e)return b.warn("Unknown series found in stack : "+c)})}),a)},sanitizeTooltip:function(a){var b;if(!a.tooltip)return void(a.tooltip={mode:"scrubber"});if("none"!==(b=a.tooltip.mode)&&"axes"!==b&&"scrubber"!==b&&(a.tooltip.mode="scrubber"),"scrubber"===a.tooltip.mode?delete a.tooltip.interpolate:a.tooltip.interpolate=!!a.tooltip.interpolate,"scrubber"===a.tooltip.mode&&a.tooltip.interpolate)throw new Error("Interpolation is not supported for scrubber tooltip mode.")},sanitizeSeriesOptions:function(a){var b,c;return null==a?[]:(b=d3.scale.category10(),c={},a.forEach(function(a){if(null!=c[a.id])throw new Error("Twice the same ID ("+a.id+") ? Really ?");return null!=a.id?c[a.id]=a:void 0}),a.forEach(function(a,d){var e,f,g,h,i;if(a.axis="y2"!==(null!=(f=a.axis)?f.toLowerCase():void 0)?"y":"y2",a.color||(a.color=b(d)),a.type="line"===(g=a.type)||"area"===g||"column"===g?a.type:"line","column"===a.type?(delete a.thickness,delete a.lineMode,delete a.drawDots):/^\d+px$/.test(a.thickness)||(a.thickness="1px"),"line"!==(h=a.type)&&"area"!==h||"dashed"===(i=a.lineMode)||delete a.lineMode,null==a.id){for(e=0;null!=c["series_"+e];)e++;return a.id="series_"+e,c[a.id]=a}}),a)},sanitizeAxes:function(a,b){var c;return null==a&&(a={}),a.x=this.sanitizeAxisOptions(a.x),(c=a.x).key||(c.key="x"),a.y=this.sanitizeAxisOptions(a.y),b&&(a.y2=this.sanitizeAxisOptions(a.y2)),this.sanitizeExtrema(a.y),b&&this.sanitizeExtrema(a.y2),a},sanitizeExtrema:function(a){var b,c;return c=this.getSanitizedExtremum(a.min),null!=c?a.min=c:delete a.min,b=this.getSanitizedExtremum(a.max),null!=b?a.max=b:delete a.max},getSanitizedExtremum:function(a){var c;return null==a?void 0:(c=parseInt(a,10),isNaN(c)?void b.warn("Invalid extremum value : "+a+", deleting it."):c)},sanitizeAxisOptions:function(a){return null==a?{type:"linear"}:(a.type||(a.type="linear"),a)},createAxes:function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o;return d=null!=c.y2,h=b.width,e=b.height,h=h-b.left-b.right,e=e-b.top-b.bottom,i=void 0,i="date"===c.x.type?d3.time.scale().rangeRound([0,h]):d3.scale.linear().rangeRound([0,h]),k=void 0,k="log"===c.y.type?d3.scale.log().clamp(!0).rangeRound([e,0]):d3.scale.linear().rangeRound([e,0]),l=void 0,l=d&&"log"===c.y2.type?d3.scale.log().clamp(!0).rangeRound([e,0]):d3.scale.linear().rangeRound([e,0]),k.clamp(!0),l.clamp(!0),j=d3.svg.axis().scale(i).orient("bottom").tickFormat(c.x.labelFunction),n=d3.svg.axis().scale(k).orient("left").tickFormat(c.y.labelFunction),m=d3.svg.axis().scale(l).orient("right").tickFormat(null!=(o=c.y2)?o.labelFunction:void 0),f=function(a){return a.style({font:"10px Courier","shape-rendering":"crispEdges"}),a.selectAll("path").style({fill:"none",stroke:"#000"})},g=this,{xScale:i,yScale:k,y2Scale:l,xAxis:j,yAxis:n,y2Axis:m,andAddThemIf:function(b){return b||(f(a.append("g").attr("class","x axis").attr("transform","translate(0,"+e+")").call(j)),f(a.append("g").attr("class","y axis").call(n)),d&&f(a.append("g").attr("class","y2 axis").attr("transform","translate("+h+", 0)").call(m))),{xScale:i,yScale:k,y2Scale:l,xAxis:j,yAxis:n,y2Axis:m}}}},setScalesDomain:function(a,b,c,d,e){var f,g;return this.setXScale(a.xScale,b,c,e.axes),g=this.getVerticalDomain(e,b,c,"y"),f=this.getVerticalDomain(e,b,c,"y2"),a.yScale.domain(g).nice(),a.y2Scale.domain(f).nice(),d.selectAll(".x.axis").call(a.xAxis),d.selectAll(".y.axis").call(a.yAxis),d.selectAll(".y2.axis").call(a.y2Axis)},getVerticalDomain:function(a,b,c,d){var e,f;return(f=a.axes[d])?(e=this.yExtent(c.filter(function(a){return a.axis===d}),b,a.stacks.filter(function(a){return a.axis===d})),"log"===f.type&&(e[0]=0===e[0]?.001:e[0]),null!=f.min&&(e[0]=f.min),null!=f.max&&(e[1]=f.max),e):[]},yExtent:function(a,b,c){var d,e,f;return f=Number.POSITIVE_INFINITY,e=Number.NEGATIVE_INFINITY,d=[],c.forEach(function(b){return d.push(b.series.map(function(b){return a.filter(function(a){return a.id===b})[0]}))}),a.forEach(function(a){var b;return b=!1,c.forEach(function(c){var d;return d=a.id,__indexOf.call(c.series,d)>=0?b=!0:void 0}),b?void 0:d.push([a])}),d.forEach(function(a){return f=Math.min(f,d3.min(b,function(b){return a.reduce(function(a,c){return Math.min(a,b[c.y])},Number.POSITIVE_INFINITY)})),e=Math.max(e,d3.max(b,function(b){return a.reduce(function(a,c){return a+b[c.y]},0)}))}),f===e?f>0?[0,2*f]:[2*f,0]:[f,e]},setXScale:function(a,b,c,d){return a.domain(this.xExtent(b,d.x.key)),c.filter(function(a){return"column"===a.type}).length?this.adjustXScaleForColumns(a,b,d.x.key):void 0},xExtent:function(a,b){var c,d,e;return e=d3.extent(a,function(a){return a[b]}),c=e[0],d=e[1],c===d?c>0?[0,2*c]:[2*c,0]:[c,d]},adjustXScaleForColumns:function(a,b,c){var d,e;return e=this.getAverageStep(b,c),d=a.domain(),a.domain(angular.isDate(d[0])?[new Date(d[0].getTime()-e),new Date(d[1].getTime()+e)]:[d[0]-e,d[1]+e])},getAverageStep:function(a,b){var c,d,e;if(!(a.length>1))return 0;for(e=0,d=a.length-1,c=0;d>c;)e+=a[c+1][b]-a[c][b],c++;return e/d},haveSecondYAxis:function(a){return!a.every(function(a){return"y2"!==a.axis})},showScrubber:function(a,b,c,d,e,f){var g;return g=this,b.on("mousemove",function(){return a.selectAll(".glass-container").attr("opacity",1),g.updateScrubber(a,d3.mouse(this),c,d,e,f)}),b.on("mouseout",function(){return b.on("mousemove",null),a.selectAll(".glass-container").attr("opacity",0)})},getClosestPoint:function(a,b){var c,d,e;for(d=0,e=a.length-1,c=Math.round((e-d)/2);;)if(b<a[c].x?(e=c,c-=Math.ceil((e-d)/2)):(d=c,c+=Math.floor((e-d)/2)),c===d||c===e){c=Math.abs(b-a[d].x)<Math.abs(b-a[e].x)?d:e;break}return a[c]},updateScrubber:function(a,b,c,d,e,f){var g,h,i,j,k,l;return k=b[0],l=b[1],g=function(a){return a.transition().duration(50)},i=this,h=[],d.forEach(function(b,d){var f,j,l,m,n,o,p,q,r;return f=a.select(".scrubberItem.series_"+d),e.series[d].visible===!1?void f.attr("opacity",0):(f.attr("opacity",1),r=i.getClosestPoint(b.values,c.xScale.invert(k)),q=r.x+" : "+r.y,e.tooltip.formatter&&(q=e.tooltip.formatter(r.x,r.y,e.series[d])),n=f.select(".rightTT"),m=n.select("text"),m.text(q),l=f.select(".leftTT"),j=l.select("text"),j.text(q),p={right:i.getTextBBox(m[0][0]).width+5,left:i.getTextBBox(j[0][0]).width+5},o="y2"===b.axis?"right":"left",k=c.xScale(r.x),"left"===o?k+i.getTextBBox(j[0][0]).x-10<0&&(o="right"):"right"===o&&k+p.right>i.getTextBBox(a.select(".glass")[0][0]).width&&(o="left"),"left"===o?(g(n).attr("opacity",0),g(l).attr("opacity",1)):(g(n).attr("opacity",1),g(l).attr("opacity",0)),h[d]={index:d,x:k,y:c[r.axis+"Scale"](r.y+r.y0),side:o,sizes:p})}),h=this.preventOverlapping(h),j=Math.max(15,100/f),d.forEach(function(b,c){var d,f,k,l;if(e.series[c].visible!==!1)return f=h[c],d=a.select(".scrubberItem.series_"+c),k=d.select("."+f.side+"TT"),l="left"===f.side?b.xOffset:-b.xOffset,k.select("text").attr("transform",function(){return"left"===f.side?"translate("+(-3-j-l)+", "+(f.labelOffset+3)+")":"translate("+(4+j+l)+", "+(f.labelOffset+3)+")"}),k.select("path").attr("d",i.getScrubberPath(f.sizes[f.side]+1,f.labelOffset,f.side,j+l)),g(d).attr({transform:"translate("+(h[c].x+b.xOffset)+", "+h[c].y+")"})})},getScrubberPath:function(a,b,c,d){var e,f,g,h;return e=18,f=d,a=a,g="left"===c?1:-1,h=1,0!==b&&(h=Math.abs(b)/b),b||(b=0),["m0 0","l"+g+" 0","l0 "+(b+h),"l"+-g*(f+1)+" 0","l0 "+(-e/2-h),"l"+-g*a+" 0","l0 "+e,"l"+g*a+" 0","l0 "+(-e/2-h),"l"+g*(f-1)+" 0","l0 "+(-b+h),"l1 0","z"].join("")},preventOverlapping:function(a){var b,c,d,e;return d=18,b={},a.forEach(function(a){var c;return b[c=a.x]||(b[c]={left:[],right:[]}),b[a.x][a.side].push(a)}),c=function(a){var c,e,f,g,h,i,j,k,l;f=[];for(j in b)if(i=b[j],0!==i[a].length){for(g={};i[a].length>0;){h=i[a].pop(),c=!1;for(k in g)e=g[k],+k-d<=(l=h.y)&&+k+d>=l&&(e.push(h),c=!0);c||(g[h.y]=[h])}f.push(g)}return f},e=function(a){var b,c,d,e,f,g,h;f=20;for(b in a){g=a[b];for(h in g)d=g[h],c=d.length,1!==c?(d=d.sort(function(a,b){return a.y-b.y}),e=c%2===0?-(f/2)*(c/2):-(c-1)/2*f,d.forEach(function(a,b){return a.labelOffset=e+f*b})):d[0].labelOffset=0}},e(c("left")),e(c("right")),a},getTooltipHandlers:function(a){return"scrubber"===a.tooltip.mode?{onChartHover:angular.bind(this,this.showScrubber)}:{onMouseOver:angular.bind(this,this.onMouseOver),onMouseOut:angular.bind(this,this.onMouseOut)}},styleTooltip:function(a){return a.attr({"font-family":"monospace","font-size":10,fill:"white","text-rendering":"geometric-precision"})},addTooltips:function(a,b,c){var d,e,f,g,h,i,j,k;return h=b.width,e=b.height,h=h-b.left-b.right,e=e-b.top-b.bottom,g=24,d=18,f=5,i=a.append("g").attr({id:"xTooltip","class":"xTooltip",opacity:0}),i.append("path").attr("transform","translate(0,"+(e+1)+")"),this.styleTooltip(i.append("text").style("text-anchor","middle").attr({width:g,height:d,transform:"translate(0,"+(e+19)+")"})),k=a.append("g").attr({id:"yTooltip","class":"yTooltip",opacity:0}),k.append("path"),this.styleTooltip(k.append("text").attr({width:d,height:g})),null!=c.y2?(j=a.append("g").attr({id:"y2Tooltip","class":"y2Tooltip",opacity:0,transform:"translate("+h+",0)"}),j.append("path"),this.styleTooltip(j.append("text").attr({width:d,height:g}))):void 0},onMouseOver:function(a,b){return this.updateXTooltip(a,b),"y2"===b.series.axis?this.updateY2Tooltip(a,b):this.updateYTooltip(a,b)},onMouseOut:function(a){return this.hideTooltips(a)},updateXTooltip:function(a,b){var c,d,e,f,g,h;return g=b.x,c=b.datum,e=b.series,h=a.select("#xTooltip"),h.transition().attr({opacity:1,transform:"translate("+g+",0)"}),f=c.x,d=h.select("text"),d.text(f),h.select("path").attr("fill",e.color).attr("d",this.getXTooltipPath(d[0][0]))},getXTooltipPath:function(a){var b,c,d;return d=Math.max(this.getTextBBox(a).width,15),b=18,c=5,"m-"+d/2+" "+c+" l0 "+b+" l"+d+" 0 l0 "+-b+"l"+(-d/2+c)+" 0 l"+-c+" -"+b/4+" l"+-c+" "+b/4+" l"+(-d/2+c)+" 0z"},updateYTooltip:function(a,b){var c,d,e,f,g,h;return g=b.y,c=b.datum,e=b.series,h=a.select("#yTooltip"),h.transition().attr({opacity:1,transform:"translate(0, "+g+")"}),d=h.select("text"),d.text(c.y),f=this.getTextBBox(d[0][0]).width+5,d.attr({transform:"translate("+(-f-2)+",3)",width:f}),h.select("path").attr("fill",e.color).attr("d",this.getYTooltipPath(f))},updateY2Tooltip:function(a,b){var c,d,e,f,g,h;return g=b.y,c=b.datum,e=b.series,h=a.select("#y2Tooltip"),h.transition().attr("opacity",1),d=h.select("text"),d.text(c.y),f=this.getTextBBox(d[0][0]).width+5,d.attr({transform:"translate(7, "+(parseFloat(g)+3)+")",w:f}),h.select("path").attr({fill:e.color,d:this.getY2TooltipPath(f),transform:"translate(0, "+g+")"})},getYTooltipPath:function(a){var b,c;return b=18,c=5,"m0 0l"+-c+" "+-c+" l0 "+(-b/2+c)+" l"+-a+" 0 l0 "+b+" l"+a+" 0 l0 "+(-b/2+c)+"l"+-c+" "+c+"z"},getY2TooltipPath:function(a){var b,c;return b=18,c=5,"m0 0l"+c+" "+c+" l0 "+(b/2-c)+" l"+a+" 0 l0 "+-b+" l"+-a+" 0 l0 "+(b/2-c)+" l"+-c+" "+c+"z"},hideTooltips:function(a){return a.select("#xTooltip").transition().attr("opacity",0),a.select("#yTooltip").transition().attr("opacity",0),a.select("#y2Tooltip").transition().attr("opacity",0)}}}]);