8 lines
241 KiB
JavaScript
8 lines
241 KiB
JavaScript
|
(function(){var nv=window.nv||{};window.nv=nv;nv.dev=false;nv.tooltip=nv.tooltip||{};nv.utils=nv.utils||{};nv.models=nv.models||{};nv.charts={};nv.graphs=[];nv.logs={};nv.dispatch=d3.dispatch("render_start","render_end");if(!Function.prototype.bind){Function.prototype.bind=function(oThis){if(typeof this!=="function"){throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable")}var aArgs=Array.prototype.slice.call(arguments,1),fToBind=this,fNOP=function(){},fBound=function(){return fToBind.apply(this instanceof fNOP&&oThis?this:oThis,aArgs.concat(Array.prototype.slice.call(arguments)))};fNOP.prototype=this.prototype;fBound.prototype=new fNOP;return fBound}}if(nv.dev){nv.dispatch.on("render_start",function(e){nv.logs.startTime=+new Date});nv.dispatch.on("render_end",function(e){nv.logs.endTime=+new Date;nv.logs.totalTime=nv.logs.endTime-nv.logs.startTime;nv.log("total",nv.logs.totalTime)})}nv.log=function(){if(nv.dev&&window.console&&console.log&&console.log.apply)console.log.apply(console,arguments);else if(nv.dev&&window.console&&typeof console.log=="function"&&Function.prototype.bind){var log=Function.prototype.bind.call(console.log,console);log.apply(console,arguments)}return arguments[arguments.length-1]};nv.deprecated=function(name){if(nv.dev&&console&&console.warn){console.warn("`"+name+"` has been deprecated.")}};nv.render=function render(step){step=step||1;nv.render.active=true;nv.dispatch.render_start();setTimeout(function(){var chart,graph;for(var i=0;i<step&&(graph=nv.render.queue[i]);i++){chart=graph.generate();if(typeof graph.callback==typeof Function)graph.callback(chart);nv.graphs.push(chart)}nv.render.queue.splice(0,i);if(nv.render.queue.length)setTimeout(arguments.callee,0);else{nv.dispatch.render_end();nv.render.active=false}},0)};nv.render.active=false;nv.render.queue=[];nv.addGraph=function(obj){if(typeof arguments[0]===typeof Function){obj={generate:arguments[0],callback:arguments[1]}}nv.render.queue.push(obj);if(!nv.render.active){nv.render()}};nv.interactiveGuideline=function(){"use strict";var tooltip=nv.models.tooltip();var width=null;var height=null;var margin={left:0,top:0},xScale=d3.scale.linear(),yScale=d3.scale.linear(),dispatch=d3.dispatch("elementMousemove","elementMouseout","elementClick","elementDblclick"),showGuideLine=true;var svgContainer=null;var isMSIE="ActiveXObject"in window;function layer(selection){selection.each(function(data){var container=d3.select(this);var availableWidth=width||960,availableHeight=height||400;var wrap=container.selectAll("g.nv-wrap.nv-interactiveLineLayer").data([data]);var wrapEnter=wrap.enter().append("g").attr("class"," nv-wrap nv-interactiveLineLayer");wrapEnter.append("g").attr("class","nv-interactiveGuideLine");if(!svgContainer){return}function mouseHandler(){var d3mouse=d3.mouse(this);var mouseX=d3mouse[0];var mouseY=d3mouse[1];var subtractMargin=true;var mouseOutAnyReason=false;if(isMSIE){mouseX=d3.event.offsetX;mouseY=d3.event.offsetY;if(d3.event.target.tagName!=="svg"){subtractMargin=false}if(d3.event.target.className.baseVal.match("nv-legend")){mouseOutAnyReason=true}}if(subtractMargin){mouseX-=margin.left;mouseY-=margin.top}if(mouseX<0||mouseY<0||mouseX>availableWidth||mouseY>availableHeight||d3.event.relatedTarget&&d3.event.relatedTarget.ownerSVGElement===undefined||mouseOutAnyReason){if(isMSIE){if(d3.event.relatedTarget&&d3.event.relatedTarget.ownerSVGElement===undefined&&d3.event.relatedTarget.className.match(tooltip.nvPointerEventsClass)){return}}dispatch.elementMouseout({mouseX:mouseX,mouseY:mouseY});layer.renderGuideLine(null);return}var pointXValue=xScale.invert(mouseX);dispatch.elementMousemove({mouseX:mouseX,mouseY:mouseY,pointXValue:pointXValue});if(d3.event.type==="dblclick"){dispatch.elementDblclick({mouseX:mouseX,mouseY:mouseY,pointXValue:pointXValue})}if(d3.event.type==="click"){dispatch.elementClick({mouseX:mouseX,mouseY:mouseY,pointXValue:pointXValue})}}svgContainer.on("mousemove",mouseHandler,true).on("mouseout",mouseHandler,true).on("dblclick",mouseHandler).on("click",mouseHandler);layer.renderGui
|
||
|
nv.utils.inheritOptionsD3(chart,scale,["domain","range","rangeBand","rangeBands"]);return chart};nv.models.bullet=function(){"use strict";var margin={top:0,right:0,bottom:0,left:0},orient="left",reverse=false,ranges=function(d){return d.ranges},markers=function(d){return d.markers?d.markers:[0]},measures=function(d){return d.measures},rangeLabels=function(d){return d.rangeLabels?d.rangeLabels:[]},markerLabels=function(d){return d.markerLabels?d.markerLabels:[]},measureLabels=function(d){return d.measureLabels?d.measureLabels:[]},forceX=[0],width=380,height=30,tickFormat=null,color=nv.utils.getColor(["#1f77b4"]),dispatch=d3.dispatch("elementMouseover","elementMouseout");function chart(selection){selection.each(function(d,i){var availableWidth=width-margin.left-margin.right,availableHeight=height-margin.top-margin.bottom,container=d3.select(this);nv.utils.initSVG(container);var rangez=ranges.call(this,d,i).slice().sort(d3.descending),markerz=markers.call(this,d,i).slice().sort(d3.descending),measurez=measures.call(this,d,i).slice().sort(d3.descending),rangeLabelz=rangeLabels.call(this,d,i).slice(),markerLabelz=markerLabels.call(this,d,i).slice(),measureLabelz=measureLabels.call(this,d,i).slice();var x1=d3.scale.linear().domain(d3.extent(d3.merge([forceX,rangez]))).range(reverse?[availableWidth,0]:[0,availableWidth]);var x0=this.__chart__||d3.scale.linear().domain([0,Infinity]).range(x1.range());this.__chart__=x1;var rangeMin=d3.min(rangez),rangeMax=d3.max(rangez),rangeAvg=rangez[1];var wrap=container.selectAll("g.nv-wrap.nv-bullet").data([d]);var wrapEnter=wrap.enter().append("g").attr("class","nvd3 nv-wrap nv-bullet");var gEnter=wrapEnter.append("g");var g=wrap.select("g");gEnter.append("rect").attr("class","nv-range nv-rangeMax");gEnter.append("rect").attr("class","nv-range nv-rangeAvg");gEnter.append("rect").attr("class","nv-range nv-rangeMin");gEnter.append("rect").attr("class","nv-measure");gEnter.append("path").attr("class","nv-markerTriangle");wrap.attr("transform","translate("+margin.left+","+margin.top+")");var w0=function(d){return Math.abs(x0(d)-x0(0))},w1=function(d){return Math.abs(x1(d)-x1(0))};var xp0=function(d){return d<0?x0(d):x0(0)},xp1=function(d){return d<0?x1(d):x1(0)};g.select("rect.nv-rangeMax").attr("height",availableHeight).attr("width",w1(rangeMax>0?rangeMax:rangeMin)).attr("x",xp1(rangeMax>0?rangeMax:rangeMin)).datum(rangeMax>0?rangeMax:rangeMin);g.select("rect.nv-rangeAvg").attr("height",availableHeight).attr("width",w1(rangeAvg)).attr("x",xp1(rangeAvg)).datum(rangeAvg);g.select("rect.nv-rangeMin").attr("height",availableHeight).attr("width",w1(rangeMax)).attr("x",xp1(rangeMax)).attr("width",w1(rangeMax>0?rangeMin:rangeMax)).attr("x",xp1(rangeMax>0?rangeMin:rangeMax)).datum(rangeMax>0?rangeMin:rangeMax);g.select("rect.nv-measure").style("fill",color).attr("height",availableHeight/3).attr("y",availableHeight/3).attr("width",measurez<0?x1(0)-x1(measurez[0]):x1(measurez[0])-x1(0)).attr("x",xp1(measurez)).on("mouseover",function(){dispatch.elementMouseover({value:measurez[0],label:measureLabelz[0]||"Current",pos:[x1(measurez[0]),availableHeight/2]})}).on("mouseout",function(){dispatch.elementMouseout({value:measurez[0],label:measureLabelz[0]||"Current"})});var h3=availableHeight/6;if(markerz[0]){g.selectAll("path.nv-markerTriangle").attr("transform",function(d){return"translate("+x1(markerz[0])+","+availableHeight/2+")"}).attr("d","M0,"+h3+"L"+h3+","+-h3+" "+-h3+","+-h3+"Z").on("mouseover",function(){dispatch.elementMouseover({value:markerz[0],label:markerLabelz[0]||"Previous",pos:[x1(markerz[0]),availableHeight/2]})}).on("mouseout",function(){dispatch.elementMouseout({value:markerz[0],label:markerLabelz[0]||"Previous"})})}else{g.selectAll("path.nv-markerTriangle").remove()}wrap.selectAll(".nv-range").on("mouseover",function(d,i){var label=rangeLabelz[i]||(!i?"Maximum":i==1?"Mean":"Minimum");dispatch.elementMouseover({value:d,label:label,pos:[x1(d),availableHeight/2]})}).on("mouseout",function(d,i){var label=rangeLabelz[i]||(!i?"Maximum":i==1?"Mean":"Minimum");dispatch.elementMouseout({value:d,lab
|
||
|
nv.utils.initSVG(container);var availableWidth=(width||parseInt(container.style("width"))||960)-margin.left-margin.right,availableHeight=(height||parseInt(container.style("height"))||400)-margin.top-margin.bottom;chart.update=function(){dispatch.beforeUpdate();container.transition().duration(duration).call(chart)};chart.container=this;if(!data||!data.length||!data.filter(function(d){return d.values.length}).length){var noDataText=container.selectAll(".nv-noData").data([noData]);noDataText.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle");noDataText.attr("x",margin.left+availableWidth/2).attr("y",margin.top+availableHeight/2).text(function(d){return d});return chart}else{container.selectAll(".nv-noData").remove()}x=discretebar.xScale();y=discretebar.yScale().clamp(true);var wrap=container.selectAll("g.nv-wrap.nv-discreteBarWithAxes").data([data]);var gEnter=wrap.enter().append("g").attr("class","nvd3 nv-wrap nv-discreteBarWithAxes").append("g");var defsEnter=gEnter.append("defs");var g=wrap.select("g");gEnter.append("g").attr("class","nv-x nv-axis");gEnter.append("g").attr("class","nv-y nv-axis").append("g").attr("class","nv-zeroLine").append("line");gEnter.append("g").attr("class","nv-barsWrap");g.attr("transform","translate("+margin.left+","+margin.top+")");if(rightAlignYAxis){g.select(".nv-y.nv-axis").attr("transform","translate("+availableWidth+",0)")}discretebar.width(availableWidth).height(availableHeight);var barsWrap=g.select(".nv-barsWrap").datum(data.filter(function(d){return!d.disabled}));barsWrap.transition().call(discretebar);defsEnter.append("clipPath").attr("id","nv-x-label-clip-"+discretebar.id()).append("rect");g.select("#nv-x-label-clip-"+discretebar.id()+" rect").attr("width",x.rangeBand()*(staggerLabels?2:1)).attr("height",16).attr("x",-x.rangeBand()/(staggerLabels?1:2));if(showXAxis){xAxis.scale(x).ticks(nv.utils.calcTicksX(availableWidth/100,data)).tickSize(-availableHeight,0);g.select(".nv-x.nv-axis").attr("transform","translate(0,"+(y.range()[0]+(discretebar.showValues()&&y.domain()[0]<0?16:0))+")");g.select(".nv-x.nv-axis").call(xAxis);var xTicks=g.select(".nv-x.nv-axis").selectAll("g");if(staggerLabels){xTicks.selectAll("text").attr("transform",function(d,i,j){return"translate(0,"+(j%2==0?"5":"17")+")"})}}if(showYAxis){yAxis.scale(y).ticks(nv.utils.calcTicksY(availableHeight/36,data)).tickSize(-availableWidth,0);g.select(".nv-y.nv-axis").call(yAxis)}g.select(".nv-zeroLine line").attr("x1",0).attr("x2",availableWidth).attr("y1",y(0)).attr("y2",y(0));dispatch.on("tooltipShow",function(e){if(tooltips)showTooltip(e,that.parentNode)})});renderWatch.renderEnd("discreteBar chart immediate");return chart}discretebar.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+margin.left,e.pos[1]+margin.top];dispatch.tooltipShow(e)});discretebar.dispatch.on("elementMouseout.tooltip",function(e){dispatch.tooltipHide(e)});dispatch.on("tooltipHide",function(){if(tooltips)nv.tooltip.cleanup()});chart.dispatch=dispatch;chart.discretebar=discretebar;chart.xAxis=xAxis;chart.yAxis=yAxis;chart.options=nv.utils.optionsFunc.bind(chart);chart._options=Object.create({},{width:{get:function(){return width},set:function(_){width=_}},height:{get:function(){return height},set:function(_){height=_}},staggerLabels:{get:function(){return staggerLabels},set:function(_){staggerLabels=_}},showXAxis:{get:function(){return showXAxis},set:function(_){showXAxis=_}},showYAxis:{get:function(){return showYAxis},set:function(_){showYAxis=_}},tooltips:{get:function(){return tooltips},set:function(_){tooltips=_}},tooltipContent:{get:function(){return tooltip},set:function(_){tooltip=_}},noData:{get:function(){return noData},set:function(_){noData=_}},margin:{get:function(){return margin},set:function(_){margin.top=_.top!==undefined?_.top:margin.top;margin.right=_.right!==undefined?_.right:margin.right;margin.bottom=_.bottom!==undefined?_.bottom:margin.bottom;margin.left=_.left!==undefined?_.left:margin.left}},duration:{get:function(){return duration},set:function(_){duration=_;
|
||
|
},set:function(_){clipEdge=_}},margin:{get:function(){return margin},set:function(_){margin.top=_.top!==undefined?_.top:margin.top;margin.right=_.right!==undefined?_.right:margin.right;margin.bottom=_.bottom!==undefined?_.bottom:margin.bottom;margin.left=_.left!==undefined?_.left:margin.left}},duration:{get:function(){return duration},set:function(_){duration=_;renderWatch.reset(duration);scatter.duration(duration)}},isArea:{get:function(){return isArea},set:function(_){isArea=d3.functor(_)}},x:{get:function(){return getX},set:function(_){getX=_;scatter.x(_)}},y:{get:function(){return getY},set:function(_){getY=_;scatter.y(_)}},color:{get:function(){return color},set:function(_){color=nv.utils.getColor(_);scatter.color(color)}}});nv.utils.inheritOptions(chart,scatter);nv.utils.initOptions(chart);return chart};nv.models.lineChart=function(){"use strict";var lines=nv.models.line(),xAxis=nv.models.axis(),yAxis=nv.models.axis(),legend=nv.models.legend(),interactiveLayer=nv.interactiveGuideline();var margin={top:30,right:20,bottom:50,left:60},color=nv.utils.defaultColor(),width=null,height=null,showLegend=true,showXAxis=true,showYAxis=true,rightAlignYAxis=false,useInteractiveGuideline=false,tooltips=true,tooltip=function(key,x,y,e,graph){return"<h3>"+key+"</h3>"+"<p>"+y+" at "+x+"</p>"},x,y,state=nv.utils.state(),defaultState=null,noData="No Data Available.",dispatch=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState","renderEnd"),duration=250;xAxis.orient("bottom").tickPadding(7);yAxis.orient(rightAlignYAxis?"right":"left");var showTooltip=function(e,offsetElement){var left=e.pos[0]+(offsetElement.offsetLeft||0),top=e.pos[1]+(offsetElement.offsetTop||0),x=xAxis.tickFormat()(lines.x()(e.point,e.pointIndex)),y=yAxis.tickFormat()(lines.y()(e.point,e.pointIndex)),content=tooltip(e.series.key,x,y,e,chart);nv.tooltip.show([left,top],content,null,null,offsetElement)};var renderWatch=nv.utils.renderWatch(dispatch,duration);var stateGetter=function(data){return function(){return{active:data.map(function(d){return!d.disabled})}}};var stateSetter=function(data){return function(state){if(state.active!==undefined)data.forEach(function(series,i){series.disabled=!state.active[i]})}};function chart(selection){renderWatch.reset();renderWatch.models(lines);if(showXAxis)renderWatch.models(xAxis);if(showYAxis)renderWatch.models(yAxis);selection.each(function(data){var container=d3.select(this),that=this;nv.utils.initSVG(container);var availableWidth=(width||parseInt(container.style("width"))||960)-margin.left-margin.right,availableHeight=(height||parseInt(container.style("height"))||400)-margin.top-margin.bottom;chart.update=function(){if(duration===0)container.call(chart);else container.transition().duration(duration).call(chart)};chart.container=this;state.setter(stateSetter(data),chart.update).getter(stateGetter(data)).update();state.disabled=data.map(function(d){return!!d.disabled});if(!defaultState){var key;defaultState={};for(key in state){if(state[key]instanceof Array)defaultState[key]=state[key].slice(0);else defaultState[key]=state[key]}}if(!data||!data.length||!data.filter(function(d){return d.values.length}).length){var noDataText=container.selectAll(".nv-noData").data([noData]);noDataText.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle");noDataText.attr("x",margin.left+availableWidth/2).attr("y",margin.top+availableHeight/2).text(function(d){return d});return chart}else{container.selectAll(".nv-noData").remove()}x=lines.xScale();y=lines.yScale();var wrap=container.selectAll("g.nv-wrap.nv-lineChart").data([data]);var gEnter=wrap.enter().append("g").attr("class","nvd3 nv-wrap nv-lineChart").append("g");var g=wrap.select("g");gEnter.append("rect").style("opacity",0);gEnter.append("g").attr("class","nv-x nv-axis");gEnter.append("g").attr("class","nv-y nv-axis");gEnter.append("g").attr("class","nv-linesWrap");gEnter.append("g").attr("class","nv-legendWrap");gEnter.append("g").attr("class","nv-interactive");g.select("rect").attr("width",availableWidth).attr("height",ava
|
||
|
chart._options=Object.create({},{width:{get:function(){return width},set:function(_){width=_}},height:{get:function(){return height},set:function(_){height=_}},focusHeight:{get:function(){return height2},set:function(_){height2=_}},showLegend:{get:function(){return showLegend},set:function(_){showLegend=_}},brushExtent:{get:function(){return brushExtent},set:function(_){brushExtent=_}},tooltips:{get:function(){return tooltips},set:function(_){tooltips=_}},tooltipContent:{get:function(){return tooltip},set:function(_){tooltip=_}},defaultState:{get:function(){return defaultState},set:function(_){defaultState=_}},noData:{get:function(){return noData},set:function(_){noData=_}},margin:{get:function(){return margin},set:function(_){margin.top=_.top!==undefined?_.top:margin.top;margin.right=_.right!==undefined?_.right:margin.right;margin.bottom=_.bottom!==undefined?_.bottom:margin.bottom;margin.left=_.left!==undefined?_.left:margin.left}},color:{get:function(){return color},set:function(_){color=nv.utils.getColor(_);legend.color(color)}},interpolate:{get:function(){return lines.interpolate()},set:function(_){lines.interpolate(_);lines2.interpolate(_)}},xTickFormat:{get:function(){return xAxis.xTickFormat()},set:function(_){xAxis.xTickFormat(_);x2Axis.xTickFormat(_)}},yTickFormat:{get:function(){return yAxis.yTickFormat()},set:function(_){yAxis.yTickFormat(_);y2Axis.yTickFormat(_)}},duration:{get:function(){return transitionDuration},set:function(_){transitionDuration=_;yAxis.duration(transitionDuration);xAxis.duration(transitionDuration)}},x:{get:function(){return lines.x()},set:function(_){lines.x(_);lines2.x(_)}},y:{get:function(){return lines.y()},set:function(_){lines.y(_);lines2.y(_)}}});nv.utils.inheritOptions(chart,lines);nv.utils.initOptions(chart);return chart};nv.models.multiBar=function(){"use strict";var margin={top:0,right:0,bottom:0,left:0},width=960,height=500,x=d3.scale.ordinal(),y=d3.scale.linear(),id=Math.floor(Math.random()*1e4),getX=function(d){return d.x},getY=function(d){return d.y},forceY=[0],clipEdge=true,stacked=false,stackOffset="zero",color=nv.utils.defaultColor(),hideable=false,barColor=null,disabled,duration=500,xDomain,yDomain,xRange,yRange,groupSpacing=.1,dispatch=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout","renderEnd");var x0,y0,renderWatch=nv.utils.renderWatch(dispatch,duration);var last_datalength=0;function chart(selection){renderWatch.reset();selection.each(function(data){var availableWidth=width-margin.left-margin.right,availableHeight=height-margin.top-margin.bottom,container=d3.select(this);nv.utils.initSVG(container);var endFn=function(d,i){if(d.series===data.length-1&&i===data[0].values.length-1)return true;return false};if(hideable&&data.length)hideable=[{values:data[0].values.map(function(d){return{x:d.x,y:0,series:d.series,size:.01}})}];if(stacked)data=d3.layout.stack().offset(stackOffset).values(function(d){return d.values}).y(getY)(!data.length&&hideable?hideable:data);data.forEach(function(series,i){series.values.forEach(function(point){point.series=i})});if(stacked)data[0].values.map(function(d,i){var posBase=0,negBase=0;data.map(function(d){var f=d.values[i];f.size=Math.abs(f.y);if(f.y<0){f.y1=negBase;negBase=negBase-f.size}else{f.y1=f.size+posBase;posBase=posBase+f.size}})});var seriesData=xDomain&&yDomain?[]:data.map(function(d){return d.values.map(function(d,i){return{x:getX(d,i),y:getY(d,i),y0:d.y0,y1:d.y1}})});x.domain(xDomain||d3.merge(seriesData).map(function(d){return d.x})).rangeBands(xRange||[0,availableWidth],groupSpacing);y.domain(yDomain||d3.extent(d3.merge(seriesData).map(function(d){return stacked?d.y>0?d.y1:d.y1+d.y:d.y}).concat(forceY))).range(yRange||[availableHeight,0]);if(x.domain()[0]===x.domain()[1])x.domain()[0]?x.domain([x.domain()[0]-x.domain()[0]*.01,x.domain()[1]+x.domain()[1]*.01]):x.domain([-1,1]);if(y.domain()[0]===y.domain()[1])y.domain()[0]?y.domain([y.domain()[0]+y.domain()[0]*.01,y.domain()[1]-y.domain()[1]*.01]):y.domain([-1,1]);x0=x0||x;y0=y0||y;var wrap=container.selectAll("g.nv-wrap.nv-mult
|
||
|
}x=multibar.xScale();y=multibar.yScale();var wrap=container.selectAll("g.nv-wrap.nv-multiBarHorizontalChart").data([data]);var gEnter=wrap.enter().append("g").attr("class","nvd3 nv-wrap nv-multiBarHorizontalChart").append("g");var g=wrap.select("g");gEnter.append("g").attr("class","nv-x nv-axis");gEnter.append("g").attr("class","nv-y nv-axis").append("g").attr("class","nv-zeroLine").append("line");gEnter.append("g").attr("class","nv-barsWrap");gEnter.append("g").attr("class","nv-legendWrap");gEnter.append("g").attr("class","nv-controlsWrap");if(showLegend){legend.width(availableWidth-controlWidth());if(multibar.barColor())data.forEach(function(series,i){series.color=d3.rgb("#ccc").darker(i*1.5).toString()});g.select(".nv-legendWrap").datum(data).call(legend);if(margin.top!=legend.height()){margin.top=legend.height();availableHeight=(height||parseInt(container.style("height"))||400)-margin.top-margin.bottom}g.select(".nv-legendWrap").attr("transform","translate("+controlWidth()+","+-margin.top+")")}if(showControls){var controlsData=[{key:controlLabels.grouped||"Grouped",disabled:multibar.stacked()},{key:controlLabels.stacked||"Stacked",disabled:!multibar.stacked()}];controls.width(controlWidth()).color(["#444","#444","#444"]);g.select(".nv-controlsWrap").datum(controlsData).attr("transform","translate(0,"+-margin.top+")").call(controls)}wrap.attr("transform","translate("+margin.left+","+margin.top+")");multibar.disabled(data.map(function(series){return series.disabled})).width(availableWidth).height(availableHeight).color(data.map(function(d,i){return d.color||color(d,i)}).filter(function(d,i){return!data[i].disabled}));var barsWrap=g.select(".nv-barsWrap").datum(data.filter(function(d){return!d.disabled}));barsWrap.transition().call(multibar);if(showXAxis){xAxis.scale(x).ticks(nv.utils.calcTicksY(availableHeight/24,data)).tickSize(-availableWidth,0);g.select(".nv-x.nv-axis").call(xAxis);var xTicks=g.select(".nv-x.nv-axis").selectAll("g");xTicks.selectAll("line, text")}if(showYAxis){yAxis.scale(y).ticks(nv.utils.calcTicksX(availableWidth/100,data)).tickSize(-availableHeight,0);g.select(".nv-y.nv-axis").attr("transform","translate(0,"+availableHeight+")");g.select(".nv-y.nv-axis").call(yAxis)}g.select(".nv-zeroLine line").attr("x1",y(0)).attr("x2",y(0)).attr("y1",0).attr("y2",-availableHeight);legend.dispatch.on("stateChange",function(newState){for(var key in newState)state[key]=newState[key];dispatch.stateChange(state);chart.update()});controls.dispatch.on("legendClick",function(d,i){if(!d.disabled)return;controlsData=controlsData.map(function(s){s.disabled=true;return s});d.disabled=false;switch(d.key){case"Grouped":multibar.stacked(false);break;case"Stacked":multibar.stacked(true);break}state.stacked=multibar.stacked();dispatch.stateChange(state);stacked=multibar.stacked();chart.update()});dispatch.on("tooltipShow",function(e){if(tooltips)showTooltip(e,that.parentNode)});dispatch.on("changeState",function(e){if(typeof e.disabled!=="undefined"){data.forEach(function(series,i){series.disabled=e.disabled[i]});state.disabled=e.disabled}if(typeof e.stacked!=="undefined"){multibar.stacked(e.stacked);state.stacked=e.stacked;stacked=e.stacked}chart.update()})});renderWatch.renderEnd("multibar horizontal chart immediate");return chart}multibar.dispatch.on("elementMouseover.tooltip",function(e){e.pos=[e.pos[0]+margin.left,e.pos[1]+margin.top];dispatch.tooltipShow(e)});multibar.dispatch.on("elementMouseout.tooltip",function(e){dispatch.tooltipHide(e)});dispatch.on("tooltipHide",function(){if(tooltips)nv.tooltip.cleanup()});chart.dispatch=dispatch;chart.multibar=multibar;chart.legend=legend;chart.xAxis=xAxis;chart.yAxis=yAxis;chart.state=state;chart.options=nv.utils.optionsFunc.bind(chart);chart._options=Object.create({},{width:{get:function(){return width},set:function(_){width=_}},height:{get:function(){return height},set:function(_){height=_}},showLegend:{get:function(){return showLegend},set:function(_){showLegend=_}},showControls:{get:function(){return showControls},set:function(_){showControls=_}},controlLabels:{get:function
|
||
|
var i=d3.interpolate(this._current,a);this._current=i(0);return function(t){return arc(i(t))}}});renderWatch.renderEnd("pie immediate");return chart}chart.dispatch=dispatch;chart.options=nv.utils.optionsFunc.bind(chart);chart._options=Object.create({},{width:{get:function(){return width},set:function(_){width=_}},height:{get:function(){return height},set:function(_){height=_}},showLabels:{get:function(){return showLabels},set:function(_){showLabels=_}},title:{get:function(){return title},set:function(_){title=_}},titleOffset:{get:function(){return titleOffset},set:function(_){titleOffset=_}},labelThreshold:{get:function(){return labelThreshold},set:function(_){labelThreshold=_}},labelFormat:{get:function(){return labelFormat},set:function(_){labelFormat=_}},valueFormat:{get:function(){return valueFormat},set:function(_){valueFormat=_}},x:{get:function(){return getX},set:function(_){getX=_}},id:{get:function(){return id},set:function(_){id=_}},endAngle:{get:function(){return endAngle},set:function(_){endAngle=_}},startAngle:{get:function(){return startAngle},set:function(_){startAngle=_}},padAngle:{get:function(){return padAngle},set:function(_){padAngle=_}},cornerRadius:{get:function(){return cornerRadius},set:function(_){cornerRadius=_}},donutRatio:{get:function(){return donutRatio},set:function(_){donutRatio=_}},pieLabelsOutside:{get:function(){return pieLabelsOutside},set:function(_){pieLabelsOutside=_}},donutLabelsOutside:{get:function(){return donutLabelsOutside},set:function(_){donutLabelsOutside=_}},labelSunbeamLayout:{get:function(){return labelSunbeamLayout},set:function(_){labelSunbeamLayout=_}},donut:{get:function(){return donut},set:function(_){donut=_}},growOnHover:{get:function(){return growOnHover},set:function(_){growOnHover=_}},margin:{get:function(){return margin},set:function(_){margin.top=typeof _.top!="undefined"?_.top:margin.top;margin.right=typeof _.right!="undefined"?_.right:margin.right;margin.bottom=typeof _.bottom!="undefined"?_.bottom:margin.bottom;margin.left=typeof _.left!="undefined"?_.left:margin.left}},y:{get:function(){return getY},set:function(_){getY=d3.functor(_)}},color:{get:function(){return color},set:function(_){color=nv.utils.getColor(_)}},labelType:{get:function(){return labelType},set:function(_){labelType=_||"key"}}});nv.utils.initOptions(chart);return chart};nv.models.pieChart=function(){"use strict";var pie=nv.models.pie();var legend=nv.models.legend();var margin={top:30,right:20,bottom:20,left:20},width=null,height=null,showLegend=true,color=nv.utils.defaultColor(),tooltips=true,tooltip=function(key,y,e,graph){return'<h3 style="background-color: '+e.color+'">'+key+"</h3>"+"<p>"+y+"</p>"},state=nv.utils.state(),defaultState=null,noData="No Data Available.",duration=250,dispatch=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState","renderEnd");var showTooltip=function(e,offsetElement){var tooltipLabel=pie.x()(e.point);var left=e.pos[0]+(offsetElement&&offsetElement.offsetLeft||0),top=e.pos[1]+(offsetElement&&offsetElement.offsetTop||0),y=pie.valueFormat()(pie.y()(e.point)),content=tooltip(tooltipLabel,y,e,chart);nv.tooltip.show([left,top],content,e.value<0?"n":"s",null,offsetElement)};var renderWatch=nv.utils.renderWatch(dispatch);var stateGetter=function(data){return function(){return{active:data.map(function(d){return!d.disabled})}}};var stateSetter=function(data){return function(state){if(state.active!==undefined){data.forEach(function(series,i){series.disabled=!state.active[i]})}}};function chart(selection){renderWatch.reset();renderWatch.models(pie);selection.each(function(data){var container=d3.select(this);nv.utils.initSVG(container);var that=this;var availableWidth=(width||parseInt(container.style("width"),10)||960)-margin.left-margin.right,availableHeight=(height||parseInt(container.style("height"),10)||400)-margin.top-margin.bottom;chart.update=function(){container.transition().call(chart)};chart.container=this;state.setter(stateSetter(data),chart.update).getter(stateGetter(data)).update();state.disabled=data.map(function(d){return!!d.disabled});if(!
|
||
|
chart.update=function(){chart(selection)};chart.container=this;if(!data||!data.length){var noDataText=container.selectAll(".nv-noData").data([noData]);noDataText.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle");noDataText.attr("x",margin.left+availableWidth/2).attr("y",margin.top+availableHeight/2).text(function(d){return d});return chart}else{container.selectAll(".nv-noData").remove()}var currentValue=sparkline.y()(data[data.length-1],data.length-1);x=sparkline.xScale();y=sparkline.yScale();var wrap=container.selectAll("g.nv-wrap.nv-sparklineplus").data([data]);var wrapEnter=wrap.enter().append("g").attr("class","nvd3 nv-wrap nv-sparklineplus");var gEnter=wrapEnter.append("g");var g=wrap.select("g");gEnter.append("g").attr("class","nv-sparklineWrap");gEnter.append("g").attr("class","nv-valueWrap");gEnter.append("g").attr("class","nv-hoverArea");wrap.attr("transform","translate("+margin.left+","+margin.top+")");var sparklineWrap=g.select(".nv-sparklineWrap");sparkline.width(availableWidth).height(availableHeight);sparklineWrap.call(sparkline);var valueWrap=g.select(".nv-valueWrap");var value=valueWrap.selectAll(".nv-currentValue").data([currentValue]);value.enter().append("text").attr("class","nv-currentValue").attr("dx",rightAlignValue?-8:8).attr("dy",".9em").style("text-anchor",rightAlignValue?"end":"start");value.attr("x",availableWidth+(rightAlignValue?margin.right:0)).attr("y",alignValue?function(d){return y(d)}:0).style("fill",sparkline.color()(data[data.length-1],data.length-1)).text(yTickFormat(currentValue));gEnter.select(".nv-hoverArea").append("rect").on("mousemove",sparklineHover).on("click",function(){paused=!paused}).on("mouseout",function(){index=[];updateValueLine()});g.select(".nv-hoverArea rect").attr("transform",function(d){return"translate("+-margin.left+","+-margin.top+")"}).attr("width",availableWidth+margin.left+margin.right).attr("height",availableHeight+margin.top);function updateValueLine(){if(paused)return;var hoverValue=g.selectAll(".nv-hoverValue").data(index);var hoverEnter=hoverValue.enter().append("g").attr("class","nv-hoverValue").style("stroke-opacity",0).style("fill-opacity",0);hoverValue.exit().transition().duration(250).style("stroke-opacity",0).style("fill-opacity",0).remove();hoverValue.attr("transform",function(d){return"translate("+x(sparkline.x()(data[d],d))+",0)"}).transition().duration(250).style("stroke-opacity",1).style("fill-opacity",1);if(!index.length)return;hoverEnter.append("line").attr("x1",0).attr("y1",-margin.top).attr("x2",0).attr("y2",availableHeight);hoverEnter.append("text").attr("class","nv-xValue").attr("x",-6).attr("y",-margin.top).attr("text-anchor","end").attr("dy",".9em");g.select(".nv-hoverValue .nv-xValue").text(xTickFormat(sparkline.x()(data[index[0]],index[0])));hoverEnter.append("text").attr("class","nv-yValue").attr("x",6).attr("y",-margin.top).attr("text-anchor","start").attr("dy",".9em");g.select(".nv-hoverValue .nv-yValue").text(yTickFormat(sparkline.y()(data[index[0]],index[0])))}function sparklineHover(){if(paused)return;var pos=d3.mouse(this)[0]-margin.left;function getClosestIndex(data,x){var distance=Math.abs(sparkline.x()(data[0],0)-x);var closestIndex=0;for(var i=0;i<data.length;i++){if(Math.abs(sparkline.x()(data[i],i)-x)<distance){distance=Math.abs(sparkline.x()(data[i],i)-x);closestIndex=i}}return closestIndex}index=[getClosestIndex(data,Math.round(x.invert(pos)))];updateValueLine()}});return chart}chart.sparkline=sparkline;chart.options=nv.utils.optionsFunc.bind(chart);chart._options=Object.create({},{width:{get:function(){return width},set:function(_){width=_}},height:{get:function(){return height},set:function(_){height=_}},xTickFormat:{get:function(){return xTickFormat},set:function(_){xTickFormat=_}},yTickFormat:{get:function(){return yTickFormat},set:function(_){yTickFormat=_}},showValue:{get:function(){return showValue},set:function(_){showValue=_}},alignValue:{get:function(){return alignValue},set:function(_){alignValue=_}},rightAlignValue:{get:function(){return rightAlignValue
|