functionChartInternal(api){var$$=this;$$.d3=window.d3?window.d3:typeofrequire!=='undefined'?require('d3'):undefined;$$.api=api;$$.config=$$.getDefaultConfig();$$.data={};$$.cache={};$$.axes={};}varc3_chart_internal_fn=ChartInternal.prototype;c3_chart_internal_fn.beforeInit=function(){// can do something
};c3_chart_internal_fn.afterInit=function(){// can do something
};c3_chart_internal_fn.init=function(){var$$=this,config=$$.config;$$.initParams();if(config.data_url){$$.convertUrlToData(config.data_url,config.data_mimeType,config.data_headers,config.data_keys,$$.initWithData);}elseif(config.data_json){$$.initWithData($$.convertJsonToData(config.data_json,config.data_keys));}elseif(config.data_rows){$$.initWithData($$.convertRowsToData(config.data_rows));}elseif(config.data_columns){$$.initWithData($$.convertColumnsToData(config.data_columns));}else{throwError('url or json or rows or columns is required.');}};c3_chart_internal_fn.initParams=function(){var$$=this,d3$$1=$$.d3,config=$$.config;// MEMO: clipId needs to be unique because it conflicts when multiple charts exist
};c3_chart_internal_fn.initChartElements=function(){if(this.initBar){this.initBar();}if(this.initLine){this.initLine();}if(this.initArc){this.initArc();}if(this.initGauge){this.initGauge();}if(this.initText){this.initText();}};c3_chart_internal_fn.initWithData=function(data){var$$=this,d3$$1=$$.d3,config=$$.config;vardefs=void0,main=void0,binding=true;$$.axis=newAxis$$1($$);if($$.initPie){$$.initPie();}if($$.initBrush){$$.initBrush();}if($$.initZoom){$$.initZoom();}if(!config.bindto){$$.selectChart=d3$$1.selectAll([]);}elseif(typeofconfig.bindto.node==='function'){$$.selectChart=config.bindto;}else{$$.selectChart=d3$$1.select(config.bindto);}if($$.selectChart.empty()){$$.selectChart=d3$$1.select(document.createElement('div')).style('opacity',0);$$.observeInserted($$.selectChart);binding=false;}$$.selectChart.html('').classed('c3',true);// Init data as targets
$$.data.xs={};$$.data.targets=$$.convertDataToTargets(data);if(config.data_filter){$$.data.targets=$$.data.targets.filter(config.data_filter);}// Set targets to hide if needed
if(config.data_hide){$$.addHiddenTargetIds(config.data_hide===true?$$.mapToIds($$.data.targets):config.data_hide);}if(config.legend_hide){$$.addHiddenLegendIds(config.legend_hide===true?$$.mapToIds($$.data.targets):config.legend_hide);}// when gauge, hide legend // TODO: fix
if($$.hasType('gauge')){config.legend_show=false;}// Init sizes and scales
$$.updateSizes();$$.updateScales();// Set domains for each scale
$$.x.domain(d3$$1.extent($$.getXDomain($$.data.targets)));$$.y.domain($$.getYDomain($$.data.targets,'y'));$$.y2.domain($$.getYDomain($$.data.targets,'y2'));$$.subX.domain($$.x.domain());$$.subY.domain($$.y.domain());$$.subY2.domain($$.y2.domain());// Save original x domain for zoom update
$$.orgXDomain=$$.x.domain();// Set initialized scales to brush and zoom
defs=$$.svg.append('defs');$$.clipChart=$$.appendClip(defs,$$.clipId);$$.clipXAxis=$$.appendClip(defs,$$.clipIdForXAxis);$$.clipYAxis=$$.appendClip(defs,$$.clipIdForYAxis);$$.clipGrid=$$.appendClip(defs,$$.clipIdForGrid);$$.clipSubchart=$$.appendClip(defs,$$.clipIdForSubchart);$$.updateSvgSize();// Define regions
main=$$.main=$$.svg.append('g').attr('transform',$$.getTranslate('main'));if($$.initSubchart){$$.initSubchart();}if($$.initTooltip){$$.initTooltip();}if($$.initLegend){$$.initLegend();}if($$.initTitle){$$.initTitle();}/* -- Main Region --*/// text when empty
main.append('text').attr('class',CLASS.text+' '+CLASS.empty).attr('text-anchor','middle')// horizontal centering of text at x position in all browsers.
.attr('dominant-baseline','middle');// vertical centering of text at y position in all browsers, except IE.
main.insert('rect',config.zoom_privileged?null:'g.'+CLASS.regions).attr('class',CLASS.zoomRect).attr('width',$$.width).attr('height',$$.height).style('opacity',0).on('dblclick.zoom',null);// Set default extent if defined
$$.api.element=$$.selectChart.node();};c3_chart_internal_fn.smoothLines=function(el,type){var$$=this;if(type==='grid'){el.each(function(){varg=$$.d3.select(this),x1=g.attr('x1'),x2=g.attr('x2'),y1=g.attr('y1'),y2=g.attr('y2');g.attr({'x1':Math.ceil(x1),'x2':Math.ceil(x2),'y1':Math.ceil(y1),'y2':Math.ceil(y2)});});}};c3_chart_internal_fn.updateSizes=function(){var$$=this,config=$$.config;varlegendHeight=$$.legend?$$.getLegendHeight():0,legendWidth=$$.legend?$$.getLegendWidth():0,legendHeightForBottom=$$.isLegendRight||$$.isLegendInset?0:legendHeight,hasArc=$$.hasArcType(),xAxisHeight=config.axis_rotated||hasArc?0:$$.getHorizontalAxisHeight('x'),subchartHeight=config.subchart_show&&!hasArc?config.subchart_size_height+xAxisHeight:0;$$.currentWidth=$$.getCurrentWidth();$$.currentHeight=$$.getCurrentHeight();// for main
$$.margin=config.axis_rotated?{top:$$.getHorizontalAxisHeight('y2')+$$.getCurrentPaddingTop(),right:hasArc?0:$$.getCurrentPaddingRight(),bottom:$$.getHorizontalAxisHeight('y')+legendHeightForBottom+$$.getCurrentPaddingBottom(),left:subchartHeight+(hasArc?0:$$.getCurrentPaddingLeft())}:{top:4+$$.getCurrentPaddingTop(),// for top tick text
right:hasArc?0:$$.getCurrentPaddingRight(),bottom:xAxisHeight+subchartHeight+legendHeightForBottom+$$.getCurrentPaddingBottom(),left:hasArc?0:$$.getCurrentPaddingLeft()};// for subchart
$$.margin2=config.axis_rotated?{top:$$.margin.top,right:NaN,bottom:20+legendHeightForBottom,left:$$.rotated_padding_left}:{top:$$.currentHeight-subchartHeight-legendHeightForBottom,right:NaN,bottom:xAxisHeight+legendHeightForBottom,left:$$.margin.left};// for legend
$$.margin3={top:0,right:NaN,bottom:0,left:0};if($$.updateSizeForLegend){$$.updateSizeForLegend(legendHeight,legendWidth);}$$.width=$$.currentWidth-$$.margin.left-$$.margin.right;$$.height=$$.currentHeight-$$.margin.top-$$.margin.bottom;if($$.width<0){$$.width=0;}if($$.height<0){$$.height=0;}$$.width2=config.axis_rotated?$$.margin.left-$$.rotated_padding_left-$$.rotated_padding_right:$$.width;$$.height2=config.axis_rotated?$$.height:$$.currentHeight-$$.margin2.top-$$.margin2.bottom;if($$.width2<0){$$.width2=0;}if($$.height2<0){$$.height2=0;}// for arc
$$.arcWidth=$$.width-($$.isLegendRight?legendWidth+10:0);$$.arcHeight=$$.height-($$.isLegendRight?0:10);if($$.hasType('gauge')&&!config.gauge_fullCircle){$$.arcHeight+=$$.height-$$.getGaugeLabelHeight();}if($$.updateRadius){$$.updateRadius();}if($$.isLegendRight&&hasArc){$$.margin3.left=$$.arcWidth/2+$$.radiusExpanded*1.1;}};c3_chart_internal_fn.updateTargets=function(targets){var$$=this;/* -- Main --*/// -- Text --//
$$.updateTargetsForText(targets);// -- Bar --//
$$.updateTargetsForBar(targets);// -- Line --//
$$.updateTargetsForLine(targets);// -- Arc --//
if($$.hasArcType()&&$$.updateTargetsForArc){$$.updateTargetsForArc(targets);}/* -- Sub --*/if($$.updateTargetsForSubchart){$$.updateTargetsForSubchart(targets);}// Fade-in each chart
$$.showTargets();};c3_chart_internal_fn.showTargets=function(){var$$=this;$$.svg.selectAll('.'+CLASS.target).filter(function(d){return$$.isTargetToShow(d.id);}).transition().duration($$.config.transition_duration).style('opacity',1);};c3_chart_internal_fn.redraw=function(options,transitions){var$$=this,main=$$.main,d3$$1=$$.d3,config=$$.config;varareaIndices=$$.getShapeIndices($$.isAreaType),barIndices=$$.getShapeIndices($$.isBarType),lineIndices=$$.getShapeIndices($$.isLineType);varwithY=void0,withSubchart=void0,withTransition=void0,withTransitionForExit=void0,withTransitionForAxis=void0,withTransform=void0,withUpdateXDomain=void0,withUpdateOrgXDomain=void0,withTrimXDomain=void0,withLegend=void0,withEventRect=void0,withDimension=void0,withUpdateXAxis=void0;varhideAxis=$$.hasArcType();vardrawArea=void0,drawBar=void0,drawLine=void0,xForText=void0,yForText=void0;varduration=void0,durationForExit=void0,durationForAxis=void0;varwaitForDraw=void0,flow=void0;vartargetsToShow=$$.filterTargetsToShow($$.data.targets),tickValues=void0,i=void0,intervalForCulling=void0,xDomainForZoom=void0;varxv=$$.xv.bind($$),cx=void0,cy=void0;options=options||{};withY=getOption(options,'withY',true);withSubchart=getOption(options,'withSubchart',true);withTransition=getOption(options,'withTransition',true);withTransform=getOption(options,'withTransform',false);withUpdateXDomain=getOption(options,'withUpdateXDomain',false);withUpdateOrgXDomain=getOption(options,'withUpdateOrgXDomain',false);withTrimXDomain=getOption(options,'withTrimXDomain',true);withUpdateXAxis=getOption(options,'withUpdateXAxis',withUpdateXDomain);withLegend=getOption(options,'withLegend',false);withEventRect=getOption(options,'withEventRect',true);withDimension=getOption(options,'withDimension',true);withTransitionForExit=getOption(options,'withTransitionForExit',withTransition);withTransitionForAxis=getOption(options,'withTransitionForAxis',withTransition);duration=withTransition?config.transition_duration:0;durationForExit=withTransitionForExit?duration:0;durationForAxis=withTransitionForAxis?duration:0;transitions=transitions||$$.axis.generateTransitions(durationForAxis);// update legend and transform each g
if(withLegend&&config.legend_show){$$.updateLegend($$.mapToIds($$.data.targets),options,transitions);}elseif(withDimension){// need to update dimension (e.g. axis.y.tick.values) because y tick values should change
// no need to update axis in it because they will be updated in redraw()
$$.updateDimension(true);}// MEMO: needed for grids calculation
$$.axis.updateLabels(withTransition);// show/hide if manual culling needed
if((withUpdateXDomain||withUpdateXAxis)&&targetsToShow.length){if(config.axis_x_tick_culling&&tickValues){for(i=1;i<tickValues.length;i++){if(tickValues.length/i<config.axis_x_tick_culling_max){intervalForCulling=i;break;}}$$.svg.selectAll('.'+CLASS.axisX+' .tick text').each(function(e){varindex=tickValues.indexOf(e);if(index>=0){d3$$1.select(this).style('display',index%intervalForCulling?'none':'block');}});}else{$$.svg.selectAll('.'+CLASS.axisX+' .tick text').style('display','block');}}// setup drawer - MEMO: these must be called after axis updated
drawArea=$$.generateDrawArea?$$.generateDrawArea(areaIndices,false):undefined;drawBar=$$.generateDrawBar?$$.generateDrawBar(barIndices):undefined;drawLine=$$.generateDrawLine?$$.generateDrawLine(lineIndices,false):undefined;xForText=$$.generateXYForText(areaIndices,barIndices,lineIndices,true);yForText=$$.generateXYForText(areaIndices,barIndices,lineIndices,false);// Update sub domain
if($$.redrawSubchart){$$.redrawSubchart(withSubchart,transitions,duration,durationForExit,areaIndices,barIndices,lineIndices);}// circles for select
main.selectAll('.'+CLASS.selectedCircles).filter($$.isBarType.bind($$)).selectAll('circle').remove();// event rects will redrawn when flow called
if(config.interaction_enabled&&!options.flow&&withEventRect){$$.redrawEventRect();if($$.updateZoom){$$.updateZoom();}}// update circleY based on updated parameters
$$.updateCircleY();// generate circle x/y functions depending on updated params
cx=($$.config.axis_rotated?$$.circleY:$$.circleX).bind($$);cy=($$.config.axis_rotated?$$.circleX:$$.circleY).bind($$);if(options.flow){flow=$$.generateFlow({targets:targetsToShow,flow:options.flow,duration:options.flow.duration,drawBar:drawBar,drawLine:drawLine,drawArea:drawArea,cx:cx,cy:cy,xv:xv,xForText:xForText,yForText:yForText});}if((duration||flow)&&$$.isTabVisible()){// Only use transition if tab visible. See #938.
// transition should be derived from one transition
d3$$1.transition().duration(duration).each(function(){vartransitionsToWait=[];// redraw and gather transitions
[$$.redrawBar(drawBar,true),$$.redrawLine(drawLine,true),$$.redrawArea(drawArea,true),$$.redrawCircle(cx,cy,true),$$.redrawText(xForText,yForText,options.flow,true),$$.redrawRegion(true),$$.redrawGrid(true)].forEach(function(transitions){transitions.forEach(function(transition){transitionsToWait.push(transition);});});// Wait for end of transitions to call flow and onrendered callback
$$.mapToIds($$.data.targets).forEach(function(id){$$.withoutFadeIn[id]=true;});};c3_chart_internal_fn.updateAndRedraw=function(options){var$$=this,config=$$.config,transitions=void0;options=options||{};// same with redraw
options.withTransition=getOption(options,'withTransition',true);options.withTransform=getOption(options,'withTransform',false);options.withLegend=getOption(options,'withLegend',false);// NOT same with redraw
options.withUpdateXDomain=true;options.withUpdateOrgXDomain=true;options.withTransitionForExit=false;options.withTransitionForTransform=getOption(options,'withTransitionForTransform',options.withTransition);// MEMO: this needs to be called before updateLegend and it means this ALWAYS needs to be called)
$$.selectChart.style('max-height',$$.currentHeight+'px');};c3_chart_internal_fn.updateDimension=function(withoutAxis){var$$=this;if(!withoutAxis){if($$.config.axis_rotated){$$.axes.x.call($$.xAxis);$$.axes.subx.call($$.subXAxis);}else{$$.axes.y.call($$.yAxis);$$.axes.y2.call($$.y2Axis);}}$$.updateSizes();$$.updateScales();$$.updateSvgSize();$$.transformAll(false);};c3_chart_internal_fn.observeInserted=function(selection){var$$=this,observer=void0;if(typeofMutationObserver==='undefined'){window.console.error('MutationObserver not defined.');return;}observer=newMutationObserver(function(mutations){mutations.forEach(function(mutation){if(mutation.type==='childList'&&mutation.previousSibling){observer.disconnect();// need to wait for completion of load because size calculation requires the actual sizes determined after that completion
$$.intervalForObserveInserted=window.setInterval(function(){// parentNode will NOT be null when completed
if(selection.node().parentNode){window.clearInterval($$.intervalForObserveInserted);$$.updateDimension();if($$.brush){$$.brush.update();}$$.config.oninit.call($$);$$.redraw({withTransform:true,withUpdateXDomain:true,withUpdateOrgXDomain:true,withTransition:false,withTransitionForTransform:false,withLegend:true});selection.transition().style('opacity',1);}},10);}});});observer.observe(selection.node(),{attributes:true,childList:true,characterData:true});};c3_chart_internal_fn.bindResize=function(){var$$=this,config=$$.config;$$.resizeFunction=$$.generateResize();$$.resizeFunction.add(function(){config.onresize.call($$);});if(config.resize_auto){$$.resizeFunction.add(function(){if($$.resizeTimeout!==undefined){window.clearTimeout($$.resizeTimeout);}$$.resizeTimeout=window.setTimeout(function(){delete$$.resizeTimeout;$$.api.flush();},100);});}$$.resizeFunction.add(function(){config.onresized.call($$);});if(window.attachEvent){window.attachEvent('onresize',$$.resizeFunction);}elseif(window.addEventListener){window.addEventListener('resize',$$.resizeFunction,false);}else{// fallback to this, if this is a very old browser
varwrapper=window.onresize;if(!wrapper){// create a wrapper that will call all charts
wrapper=$$.generateResize();}elseif(!wrapper.add||!wrapper.remove){// there is already a handler registered, make sure we call it too
wrapper=$$.generateResize();wrapper.add(window.onresize);}// add this graph to the wrapper, we will be removed if the user calls destroy
wrapper.add($$.resizeFunction);window.onresize=wrapper;}};c3_chart_internal_fn.generateResize=function(){varresizeFunctions=[];functioncallResizeFunctions(){resizeFunctions.forEach(function(f){f();});}callResizeFunctions.add=function(f){resizeFunctions.push(f);};callResizeFunctions.remove=function(f){for(vari=0;i<resizeFunctions.length;i++){if(resizeFunctions[i]===f){resizeFunctions.splice(i,1);break;}}};returncallResizeFunctions;};c3_chart_internal_fn.endall=function(transition,callback){varn=0;transition.each(function(){++n;}).each('end',function(){if(!--n){callback.apply(this,arguments);}});};c3_chart_internal_fn.generateWait=function(){vartransitionsToWait=[],f=functionf(transition,callback){vartimer=setInterval(function(){vardone=0;transitionsToWait.forEach(function(t){if(t.empty()){done+=1;return;}try{t.transition();}catch(e){done+=1;}});if(done===transitionsToWait.length){clearInterval(timer);if(callback){callback();}}},10);};f.add=function(transition){transitionsToWait.push(transition);};returnf;};c3_chart_internal_fn.parseDate=function(date){var$$=this,parsedDate=void0;if(dateinstanceofDate){parsedDate=date;}elseif(typeofdate==='string'){parsedDate=$$.dataTimeFormat($$.config.data_xFormat).parse(date);}elseif(typeofdate==='number'&&!isNaN(date)){parsedDate=newDate(+date);}if(!parsedDate||isNaN(+parsedDate)){window.console.error("Failed to parse x '"+date+"' to Date object");}returnparsedDate;};c3_chart_internal_fn.isTabVisible=function(){varhidden=void0;if(typeofdocument.hidden!=='undefined'){// Opera 12.10 and Firefox 18 and later support
hidden='hidden';}elseif(typeofdocument.mozHidden!=='undefined'){hidden='mozHidden';}elseif(typeofdocument.msHidden!=='undefined'){hidden='msHidden';}elseif(typeofdocument.webkitHidden!=='undefined'){hidden='webkitHidden';}returndocument[hidden]?false:true;};c3_chart_internal_fn.getDefaultConfig=function(){varconfig={bindto:'#chart',svg_classname:undefined,size_width:undefined,size_height:undefined,padding_left:undefined,padding_right:undefined,padding_top:undefined,padding_bottom:undefined,resize_auto:true,zoom_enabled:false,zoom_extent:undefined,zoom_privileged:false,zoom_rescale:false,zoom_onzoom:functionzoom_onzoom(){},zoom_onzoomstart:functionzoom_onzoomstart(){},zoom_onzoomend:functionzoom_onzoomend(){},zoom_x_min:undefined,zoom_x_max:undefined,interaction_brighten:true,interaction_enabled:true,onmouseover:functiononmouseover(){},onmouseout:functiononmouseout(){},onresize:functiononresize(){},onresized:functiononresized(){},oninit:functiononinit(){},onrendered:functiononrendered(){},transition_duration:350,data_x:undefined,data_xs:{},data_xFormat:'%Y-%m-%d',data_xLocaltime:true,data_xSort:true,data_idConverter:functiondata_idConverter(id){returnid;},data_names:{},data_classes:{},data_groups:[],data_axes:{},data_type:undefined,data_types:{},data_labels:{},data_order:'desc',data_regions:{},data_color:undefined,data_colors:{},data_hide:false,data_filter:undefined,data_selection_enabled:false,data_selection_grouped:false,data_selection_isselectable:functiondata_selection_isselectable(){returntrue;},data_selection_multiple:true,data_selection_draggable:false,data_onclick:functiondata_onclick(){},data_onmouseover:functiondata_onmouseover(){},data_onmouseout:functiondata_onmouseout(){},data_onselected:functiondata_onselected(){},data_onunselected:functiondata_onunselected(){},data_url:undefined,data_headers:undefined,data_json:undefined,data_rows:undefined,data_columns:undefined,data_mimeType:undefined,data_keys:undefined,// configuration for no plot-able data supplied.
spline_interpolation_type:'cardinal',// region - region to change style
regions:[],// tooltip - show when mouseover on each data
tooltip_show:true,tooltip_grouped:true,tooltip_format_title:undefined,tooltip_format_name:undefined,tooltip_format_value:undefined,tooltip_position:undefined,tooltip_contents:functiontooltip_contents(d,defaultTitleFormat,defaultValueFormat,color){returnthis.getTooltipContent?this.getTooltipContent(d,defaultTitleFormat,defaultValueFormat,color):'';},tooltip_init_show:false,tooltip_init_x:0,tooltip_init_position:{top:'0px',left:'50px'},tooltip_onshow:functiontooltip_onshow(){},tooltip_onhide:functiontooltip_onhide(){},// title
$$.xAxisTickFormat=$$.axis.getXAxisTickFormat();$$.xAxisTickValues=$$.axis.getXAxisTickValues();$$.yAxisTickValues=$$.axis.getYAxisTickValues();$$.y2AxisTickValues=$$.axis.getY2AxisTickValues();$$.xAxis=$$.axis.getXAxis($$.x,$$.xOrient,$$.xAxisTickFormat,$$.xAxisTickValues,config.axis_x_tick_outer);$$.subXAxis=$$.axis.getXAxis($$.subX,$$.subXOrient,$$.xAxisTickFormat,$$.xAxisTickValues,config.axis_x_tick_outer);$$.yAxis=$$.axis.getYAxis($$.y,$$.yOrient,config.axis_y_tick_format,$$.yAxisTickValues,config.axis_y_tick_outer);$$.y2Axis=$$.axis.getYAxis($$.y2,$$.y2Orient,config.axis_y2_tick_format,$$.y2AxisTickValues,config.axis_y2_tick_outer);// Set initialized scales to brush and zoom
if(!forInit){if($$.brush){$$.brush.scale($$.subX);}if(config.zoom_enabled){$$.zoom.scale($$.x);}}// update for arc
yDomainMin=isValue(yMin)?yMin:isValue(yMax)?yDomainMin<yMax?yDomainMin:yMax-10:yDomainMin;yDomainMax=isValue(yMax)?yMax:isValue(yMin)?yMin<yDomainMax?yDomainMax:yMin+10:yDomainMax;if(yTargets.length===0){// use current domain if target of axisId is none
returnaxisId==='y2'?$$.y2.domain():$$.y.domain();}if(isNaN(yDomainMin)){// set minimum to zero when not number
yDomainMin=0;}if(isNaN(yDomainMax)){// set maximum to have same value as yDomainMin
yDomainMax=yDomainMin;}if(yDomainMin===yDomainMax){yDomainMin<0?yDomainMax=0:yDomainMin=0;}isAllPositive=yDomainMin>=0&&yDomainMax>=0;isAllNegative=yDomainMin<=0&&yDomainMax<=0;// Cancel zerobased if axis_*_min / axis_*_max specified
if(isValue(yMin)&&isAllPositive||isValue(yMax)&&isAllNegative){isZeroBased=false;}// Bar/Area chart should be 0-based if all positive|negative
if(isZeroBased){if(isAllPositive){yDomainMin=0;}if(isAllNegative){yDomainMax=0;}}domainLength=Math.abs(yDomainMax-yDomainMin);padding=padding_top=padding_bottom=domainLength*0.1;if(typeofcenter!=='undefined'){yDomainAbs=Math.max(Math.abs(yDomainMin),Math.abs(yDomainMax));yDomainMax=center+yDomainAbs;yDomainMin=center-yDomainAbs;}// add padding for data label
if(showHorizontalDataLabel){lengths=$$.getDataLabelLength(yDomainMin,yDomainMax,'width');diff=diffDomain($$.y.range());ratio=[lengths[0]/diff,lengths[1]/diff];padding_top+=domainLength*(ratio[1]/(1-ratio[0]-ratio[1]));padding_bottom+=domainLength*(ratio[0]/(1-ratio[0]-ratio[1]));}elseif(showVerticalDataLabel){lengths=$$.getDataLabelLength(yDomainMin,yDomainMax,'height');padding_top+=$$.axis.convertPixelsToAxisPadding(lengths[1],domainLength);padding_bottom+=$$.axis.convertPixelsToAxisPadding(lengths[0],domainLength);}if(axisId==='y'&¬Empty(config.axis_y_padding)){padding_top=$$.axis.getPadding(config.axis_y_padding,'top',padding_top,domainLength);padding_bottom=$$.axis.getPadding(config.axis_y_padding,'bottom',padding_bottom,domainLength);}if(axisId==='y2'&¬Empty(config.axis_y2_padding)){padding_top=$$.axis.getPadding(config.axis_y2_padding,'top',padding_top,domainLength);padding_bottom=$$.axis.getPadding(config.axis_y2_padding,'bottom',padding_bottom,domainLength);}// Bar/Area chart should be 0-based if all positive|negative
if(isZeroBased){if(isAllPositive){padding_bottom=yDomainMin;}if(isAllNegative){padding_top=-yDomainMax;}}domain=[yDomainMin-padding_bottom,yDomainMax+padding_top];returnisInverted?domain.reverse():domain;};c3_chart_internal_fn.getXDomainMin=function(targets){var$$=this,config=$$.config;returnisDefined(config.axis_x_min)?$$.isTimeSeries()?this.parseDate(config.axis_x_min):config.axis_x_min:$$.d3.min(targets,function(t){return$$.d3.min(t.values,function(v){returnv.x;});});};c3_chart_internal_fn.getXDomainMax=function(targets){var$$=this,config=$$.config;returnisDefined(config.axis_x_max)?$$.isTimeSeries()?this.parseDate(config.axis_x_max):config.axis_x_max:$$.d3.max(targets,function(t){return$$.d3.max(t.values,function(v){returnv.x;});});};c3_chart_internal_fn.getXDomainPadding=function(domain){var$$=this,config=$$.config,diff=domain[1]-domain[0],maxDataCount=void0,padding=void0,paddingLeft=void0,paddingRight=void0;if($$.isCategorized()){padding=0;}elseif($$.hasType('bar')){maxDataCount=$$.getMaxDataCount();padding=maxDataCount>1?diff/(maxDataCount-1)/2:0.5;}else{padding=diff*0.01;}if(_typeof(config.axis_x_padding)==='object'&¬Empty(config.axis_x_padding)){paddingLeft=isValue(config.axis_x_padding.left)?config.axis_x_padding.left:padding;paddingRight=isValue(config.axis_x_padding.right)?config.axis_x_padding.right:padding;}elseif(typeofconfig.axis_x_padding==='number'){paddingLeft=paddingRight=config.axis_x_padding;}else{paddingLeft=paddingRight=padding;}return{left:paddingLeft,right:paddingRight};};c3_chart_internal_fn.getXDomain=function(targets){var$$=this,xDomain=[$$.getXDomainMin(targets),$$.getXDomainMax(targets)],firstX=xDomain[0],lastX=xDomain[1],padding=$$.getXDomainPadding(xDomain),min=0,max=0;// show center of x domain if min and max are the same
if(firstX-lastX===0&&!$$.isCategorized()){if($$.isTimeSeries()){firstX=newDate(firstX.getTime()*0.5);lastX=newDate(lastX.getTime()*1.5);}else{firstX=firstX===0?1:firstX*0.5;lastX=lastX===0?-1:lastX*1.5;}}if(firstX||firstX===0){min=$$.isTimeSeries()?newDate(firstX.getTime()-padding.left):firstX-padding.left;}if(lastX||lastX===0){max=$$.isTimeSeries()?newDate(lastX.getTime()+padding.right):lastX+padding.right;}return[min,max];};c3_chart_internal_fn.updateXDomain=function(targets,withUpdateXDomain,withUpdateOrgXDomain,withTrim,domain){var$$=this,config=$$.config;if(withUpdateOrgXDomain){$$.x.domain(domain?domain:$$.d3.extent($$.getXDomain(targets)));$$.orgXDomain=$$.x.domain();if(config.zoom_enabled){$$.zoom.scale($$.x).updateScaleExtent();}$$.subX.domain($$.x.domain());if($$.brush){$$.brush.scale($$.subX);}}if(withUpdateXDomain){$$.x.domain(domain?domain:!$$.brush||$$.brush.empty()?$$.orgXDomain:$$.brush.extent());if(config.zoom_enabled){$$.zoom.scale($$.x).updateScaleExtent();}}// Trim domain when too big by zoom mousemove event
returntargets;};c3_chart_internal_fn.filterByX=function(targets,x){returnthis.d3.merge(targets.map(function(t){returnt.values;})).filter(function(v){returnv.x-x===0;});};c3_chart_internal_fn.filterRemoveNull=function(data){returndata.filter(function(d){returnisValue(d.value);});};c3_chart_internal_fn.filterByXDomain=function(targets,xDomain){returntargets.map(function(t){return{id:t.id,id_org:t.id_org,values:t.values.filter(function(v){returnxDomain[0]<=v.x&&v.x<=xDomain[1];})};});};c3_chart_internal_fn.hasDataLabel=function(){varconfig=this.config;if(typeofconfig.data_labels==='boolean'&&config.data_labels){returntrue;}elseif(_typeof(config.data_labels)==='object'&¬Empty(config.data_labels)){returntrue;}returnfalse;};c3_chart_internal_fn.getDataLabelLength=function(min,max,key){var$$=this,lengths=[0,0],paddingCoef=1.3;$$.selectChart.select('svg').selectAll('.dummy').data([min,max]).enter().append('text').text(function(d){return$$.dataLabelFormat(d.id)(d);}).each(function(d,i){lengths[i]=this.getBoundingClientRect()[key]*paddingCoef;}).remove();returnlengths;};c3_chart_internal_fn.isNoneArc=function(d){returnthis.hasTarget(this.data.targets,d.id);},c3_chart_internal_fn.isArc=function(d){return'data'ind&&this.hasTarget(this.data.targets,d.data.id);};c3_chart_internal_fn.findSameXOfValues=function(values,index){vari=void0,targetX=values[index].x,sames=[];for(i=index-1;i>=0;i--){if(targetX!==values[i].x){break;}sames.push(values[i]);}for(i=index;i<values.length;i++){if(targetX!==values[i].x){break;}sames.push(values[i]);}returnsames;};c3_chart_internal_fn.findClosestFromTargets=function(targets,pos){var$$=this,candidates=void0;// map to array of closest points of each target
return$$.findClosest(candidates,pos);};c3_chart_internal_fn.findClosest=function(values,pos){var$$=this,minDist=$$.config.point_sensitivity,closest=void0;// find mouseovering bar
values.filter(function(v){returnv&&$$.isBarType(v.id);}).forEach(function(v){varshape=$$.main.select('.'+CLASS.bars+$$.getTargetSelectorSuffix(v.id)+' .'+CLASS.bar+'-'+v.index).node();if(!closest&&$$.isWithinBar(shape)){closest=v;}});// find closest point from non-bar
values.filter(function(v){returnv&&!$$.isBarType(v.id);}).forEach(function(v){vard=$$.dist(v,pos);if(d<minDist){minDist=d;closest=v;}});returnclosest;};c3_chart_internal_fn.dist=function(data,pos){var$$=this,config=$$.config,xIndex=config.axis_rotated?1:0,yIndex=config.axis_rotated?0:1,y=$$.circleY(data,data.index),x=$$.x(data.x);returnMath.sqrt(Math.pow(x-pos[xIndex],2)+Math.pow(y-pos[yIndex],2));};c3_chart_internal_fn.convertValuesToStep=function(values){varconverted=[].concat(values),i=void0;if(!this.isCategorized()){returnvalues;}for(i=values.length+1;0<i;i--){converted[i]=converted[i-1];}converted[0]={x:converted[0].x-1,value:converted[0].value,id:converted[0].id};converted[values.length+1]={x:converted[values.length].x+1,value:converted[values.length].value,id:converted[values.length].id};returnconverted;};c3_chart_internal_fn.updateDataAttributes=function(name,attrs){var$$=this,config=$$.config,current=config['data_'+name];if(typeofattrs==='undefined'){returncurrent;}Object.keys(attrs).forEach(function(id){current[id]=attrs[id];});$$.redraw({withLegend:true});returncurrent;};c3_chart_internal_fn.convertUrlToData=function(url,mimeType,headers,keys,done){var$$=this,type=mimeType?mimeType:'csv';varreq=$$.d3.xhr(url);if(headers){Object.keys(headers).forEach(function(header){req.header(header,headers[header]);});}req.get(function(error,data){vard=void0;if(!data){thrownewError(error.responseURL+' '+error.status+' ('+error.statusText+')');}if(type==='json'){d=$$.convertJsonToData(JSON.parse(data.response),keys);}elseif(type==='tsv'){d=$$.convertTsvToData(data.response);}else{d=$$.convertCsvToData(data.response);}done.call($$,d);});};c3_chart_internal_fn.convertXsvToData=function(xsv,parser){varrows=parser.parseRows(xsv),d=void0;if(rows.length===1){d=[{}];rows[0].forEach(function(id){d[0][id]=null;});}else{d=parser.parse(xsv);}returnd;};c3_chart_internal_fn.convertCsvToData=function(csv){returnthis.convertXsvToData(csv,this.d3.csv);};c3_chart_internal_fn.convertTsvToData=function(tsv){returnthis.convertXsvToData(tsv,this.d3.tsv);};c3_chart_internal_fn.convertJsonToData=function(json,keys){var$$=this,new_rows=[],targetKeys=void0,data=void0;if(keys){// when keys specified, json would be an array that includes objects
if(keys.x){targetKeys=keys.value.concat(keys.x);$$.config.data_x=keys.x;}else{targetKeys=keys.value;}new_rows.push(targetKeys);json.forEach(function(o){varnew_row=[];targetKeys.forEach(function(key){// convert undefined to null because undefined data will be removed in convertDataToTargets()
varv=$$.findValueInJson(o,key);if(isUndefined(v)){v=null;}new_row.push(v);});new_rows.push(new_row);});data=$$.convertRowsToData(new_rows);}else{Object.keys(json).forEach(function(key){new_rows.push([key].concat(json[key]));});data=$$.convertColumnsToData(new_rows);}returndata;};c3_chart_internal_fn.findValueInJson=function(object,path){path=path.replace(/\[(\w+)\]/g,'.$1');// convert indexes to properties (replace [] with .)
path=path.replace(/^\./,'');// strip a leading dot
varpathArray=path.split('.');for(vari=0;i<pathArray.length;++i){vark=pathArray[i];if(kinobject){object=object[k];}else{return;}}returnobject;};c3_chart_internal_fn.convertRowsToData=function(rows){varkeys=rows[0],new_row={},new_rows=[],i=void0,j=void0;for(i=1;i<rows.length;i++){new_row={};for(j=0;j<rows[i].length;j++){if(isUndefined(rows[i][j])){thrownewError('Source data is missing a component at ('+i+','+j+')!');}new_row[keys[j]]=rows[i][j];}new_rows.push(new_row);}returnnew_rows;};c3_chart_internal_fn.convertColumnsToData=function(columns){varnew_rows=[],i=void0,j=void0,key=void0;for(i=0;i<columns.length;i++){key=columns[i][0];for(j=1;j<columns[i].length;j++){if(isUndefined(new_rows[j-1])){new_rows[j-1]={};}if(isUndefined(columns[i][j])){thrownewError('Source data is missing a component at ('+i+','+j+')!');}new_rows[j-1][key]=columns[i][j];}}returnnew_rows;};c3_chart_internal_fn.convertDataToTargets=function(data,appendXs){var$$=this,config=$$.config,ids=$$.d3.keys(data[0]).filter($$.isNotX,$$),xs=$$.d3.keys(data[0]).filter($$.isX,$$),targets=void0;// save x for update data by load when custom x and c3.x API
ids.forEach(function(id){varxKey=$$.getXKey(id);if($$.isCustomX()||$$.isTimeSeries()){// if included in input data
if(xs.indexOf(xKey)>=0){$$.data.xs[id]=(appendXs&&$$.data.xs[id]?$$.data.xs[id]:[]).concat(data.map(function(d){returnd[xKey];}).filter(isValue).map(function(rawX,i){return$$.generateTargetX(rawX,id,i);}));}// if not included in input data, find from preloaded data of other id's x
elseif(config.data_x){$$.data.xs[id]=$$.getOtherTargetXs();}// if not included in input data, find from preloaded data
elseif(notEmpty(config.data_xs)){$$.data.xs[id]=$$.getXValuesOfXKey(xKey,$$.data.targets);}// MEMO: if no x included, use same x of current will be used
}else{$$.data.xs[id]=data.map(function(d,i){returni;});}});// check x is defined
ids.forEach(function(id){if(!$$.data.xs[id]){thrownewError('x is not defined for id = "'+id+'".');}});// convert to target
targets=ids.map(function(id,index){varconvertedId=config.data_idConverter(id);return{id:convertedId,id_org:id,values:data.map(function(d,i){varxKey=$$.getXKey(id),rawX=d[xKey],value=d[id]!==null&&!isNaN(d[id])?+d[id]:null,x=void0;// use x as categories if custom x and categorized
if($$.isCustomX()&&$$.isCategorized()&&index===0&&!isUndefined(rawX)){if(index===0&&i===0){config.axis_x_categories=[];}x=config.axis_x_categories.indexOf(rawX);if(x===-1){x=config.axis_x_categories.length;config.axis_x_categories.push(rawX);}}else{x=$$.generateTargetX(rawX,id,i);}// mark as x = undefined if value is undefined and filter to remove after mapped
if(config.data_xSort){t.values=t.values.sort(function(v1,v2){varx1=v1.x||v1.x===0?v1.x:Infinity,x2=v2.x||v2.x===0?v2.x:Infinity;returnx1-x2;});}// indexing each value
i=0;t.values.forEach(function(v){v.index=i++;});// this needs to be sorted because its index and value.index is identical
$$.data.xs[t.id].sort(function(v1,v2){returnv1-v2;});});// cache information about values
$$.hasNegativeValue=$$.hasNegativeValueInTargets(targets);$$.hasPositiveValue=$$.hasPositiveValueInTargets(targets);// set target types
if(config.data_type){$$.setTargetType($$.mapToIds(targets).filter(function(id){return!(idinconfig.data_types);}),config.data_type);}// cache as original id keyed
targets.forEach(function(d){$$.addCache(d.id_org,d);});returntargets;};c3_chart_internal_fn.load=function(targets,args){var$$=this;if(targets){// filter loading targets if needed
if(args.filter){targets=targets.filter(args.filter);}// set type if args.types || args.type specified
if(args.type||args.types){targets.forEach(function(t){vartype=args.types&&args.types[t.id]?args.types[t.id]:args.type;$$.setTargetType(t.id,type);});}// Update/Add data
$$.data.targets.forEach(function(d){for(vari=0;i<targets.length;i++){if(d.id===targets[i].id){d.values=targets[i].values;targets.splice(i,1);break;}}});$$.data.targets=$$.data.targets.concat(targets);// add remained
}// Set targets
$$.updateTargets($$.data.targets);// Redraw with new targets
$$.data.targets=$$.data.targets.filter(function(t){returnt.id!==id;});});};c3_chart_internal_fn.categoryName=function(i){varconfig=this.config;returni<config.axis_x_categories.length?config.axis_x_categories[i]:i;};c3_chart_internal_fn.initEventRect=function(){var$$=this;$$.main.select('.'+CLASS.chart).append('g').attr('class',CLASS.eventRects).style('fill-opacity',0);};c3_chart_internal_fn.redrawEventRect=function(){var$$=this,config=$$.config,eventRectUpdate=void0,maxDataCountTarget=void0,isMultipleX=$$.isMultipleX();// rects for mouseover
vareventRects=$$.main.select('.'+CLASS.eventRects).style('cursor',config.zoom_enabled?config.axis_rotated?'ns-resize':'ew-resize':null).classed(CLASS.eventRectsMultiple,isMultipleX).classed(CLASS.eventRectsSingle,!isMultipleX);// clear old rects
eventRects.selectAll('.'+CLASS.eventRect).remove();// open as public variable
$$.eventRect=eventRects.selectAll('.'+CLASS.eventRect);if(isMultipleX){eventRectUpdate=$$.eventRect.data([0]);// enter : only one rect will be added
$$.updateEventRect(eventRectUpdate);// exit : not needed because always only one rect exists
}else{// Set data and update $$.eventRect
maxDataCountTarget=$$.getMaxDataCountTarget($$.data.targets);eventRects.datum(maxDataCountTarget?maxDataCountTarget.values:[]);$$.eventRect=eventRects.selectAll('.'+CLASS.eventRect);eventRectUpdate=$$.eventRect.data(function(d){returnd;});// enter
eventRectUpdate.exit().remove();}};c3_chart_internal_fn.updateEventRect=function(eventRectUpdate){var$$=this,config=$$.config,x=void0,y=void0,w=void0,h=void0,rectW=void0,rectX=void0;// set update selection if null
eventRectUpdate=eventRectUpdate||$$.eventRect.data(function(d){returnd;});if($$.isMultipleX()){// TODO: rotated not supported yet
x=0;y=0;w=$$.width;h=$$.height;}else{if(($$.isCustomX()||$$.isTimeSeries())&&!$$.isCategorized()){// update index for x that is used by prevX and nextX
$$.updateXs();rectW=functionrectW(d){varprevX=$$.getPrevX(d.index),nextX=$$.getNextX(d.index);// if there this is a single data point make the eventRect full width (or height)
if(prevX===null&&nextX===null){returnconfig.axis_rotated?$$.height:$$.width;}if(prevX===null){prevX=$$.x.domain()[0];}if(nextX===null){nextX=$$.x.domain()[1];}returnMath.max(0,($$.x(nextX)-$$.x(prevX))/2);};rectX=functionrectX(d){varprevX=$$.getPrevX(d.index),nextX=$$.getNextX(d.index),thisX=$$.data.xs[d.id][d.index];// if there this is a single data point position the eventRect at 0
if(prevX===null&&nextX===null){return0;}if(prevX===null){prevX=$$.x.domain()[0];}return($$.x(thisX)+$$.x(prevX))/2;};}else{rectW=$$.getEventRectWidth();rectX=functionrectX(d){return$$.x(d.x)-rectW/2;};}x=config.axis_rotated?0:rectX;y=config.axis_rotated?rectX:0;w=config.axis_rotated?$$.width:rectW;h=config.axis_rotated?rectW:$$.height;}eventRectUpdate.attr('class',$$.classEvent.bind($$)).attr('x',x).attr('y',y).attr('width',w).attr('height',h);};c3_chart_internal_fn.generateEventRectsForSingleX=function(eventRectEnter){var$$=this,d3$$1=$$.d3,config=$$.config,tap=false,tapX=void0;functionclick(shape,d){varindex=d.index;if($$.hasArcType()||!$$.toggleShape){return;}if($$.cancelClick){$$.cancelClick=false;return;}if($$.isStepType(d)&&config.line_step_type==='step-after'&&d3$$1.mouse(shape)[0]<$$.x($$.getXValue(d.id,index))){index-=1;}$$.main.selectAll('.'+CLASS.shape+'-'+index).each(function(d){if(config.data_selection_grouped||$$.isWithinShape(this,d)){$$.toggleShape(this,d,index);$$.config.data_onclick.call($$.api,d,this);}});}eventRectEnter.append('rect').attr('class',$$.classEvent.bind($$)).style('cursor',config.data_selection_enabled&&config.data_selection_grouped?'pointer':null).on('mouseover',function(d){varindex=d.index;if($$.dragging||$$.flowing){return;}// do nothing while dragging/flowing
$$.main.selectAll('.'+CLASS.shape+'-'+index).each(function(d){config.data_onmouseover.call($$.api,d);});}).on('mouseout',function(d){varindex=d.index;if(!$$.config){return;}// chart is destroyed
$$.main.selectAll('.'+CLASS.shape+'-'+index).each(function(d){config.data_onmouseout.call($$.api,d);});}).on('mousemove',function(d){varselectedData=void0,index=d.index,eventRect=$$.svg.select('.'+CLASS.eventRect+'-'+index);if($$.dragging||$$.flowing){return;}// do nothing while dragging/flowing
if($$.hasArcType()){return;}if($$.isStepType(d)&&$$.config.line_step_type==='step-after'&&d3$$1.mouse(this)[0]<$$.x($$.getXValue(d.id,index))){index-=1;}// Show tooltip
selectedData=$$.filterTargetsToShow($$.data.targets).map(function(t){return$$.addName($$.getValueOnIndex(t.values,index));});if(config.tooltip_grouped){$$.showTooltip(selectedData,this);$$.showXGridFocus(selectedData);}if(config.tooltip_grouped&&(!config.data_selection_enabled||config.data_selection_grouped)){return;}$$.main.selectAll('.'+CLASS.shape+'-'+index).each(function(){d3$$1.select(this).classed(CLASS.EXPANDED,true);if(config.data_selection_enabled){eventRect.style('cursor',config.data_selection_grouped?'pointer':null);}if(!config.tooltip_grouped){$$.hideXGridFocus();$$.hideTooltip();if(!config.data_selection_grouped){$$.unexpandCircles(index);$$.unexpandBars(index);}}}).filter(function(d){return$$.isWithinShape(this,d);}).each(function(d){if(config.data_selection_enabled&&(config.data_selection_grouped||config.data_selection_isselectable(d))){eventRect.style('cursor','pointer');}if(!config.tooltip_grouped){$$.showTooltip([d],this);$$.showXGridFocus([d]);if(config.point_focus_expand_enabled){$$.expandCircles(index,d.id,true);}$$.expandBars(index,d.id,true);}});}).on('click',function(d){// click event was simulated via a 'tap' touch event, cancel regular click
if(tap){return;}click(this,d);}).on('touchstart',function(d){// store current X selection for comparison during touch end event
tapX=d.x;}).on('touchend',function(d){varfinalX=d.x;// If end is not the same as the start, event doesn't count as a tap
if(tapX!==finalX){return;}click(this,d);// indictate tap event fired to prevent click;
tap=true;setTimeout(function(){tap=false;},config.touch_tap_delay);}).call(config.data_selection_draggable&&$$.drag?d3$$1.behavior.drag().origin(Object).on('drag',function(){$$.drag(d3$$1.mouse(this));}).on('dragstart',function(){$$.dragstart(d3$$1.mouse(this));}).on('dragend',function(){$$.dragend();}):function(){});};c3_chart_internal_fn.generateEventRectsForMultipleXs=function(eventRectEnter){var$$=this,d3$$1=$$.d3,config=$$.config,tap=false,tapX=void0,tapY=void0;functionmouseout(){$$.svg.select('.'+CLASS.eventRect).style('cursor',null);$$.hideXGridFocus();$$.hideTooltip();$$.unexpandCircles();$$.unexpandBars();}functionclick(shape){vartargetsToShow=$$.filterTargetsToShow($$.data.targets);varmouse=void0,closest=void0;if($$.hasArcType(targetsToShow)){return;}mouse=d3$$1.mouse(shape);closest=$$.findClosestFromTargets(targetsToShow,mouse);if(!closest){return;}// select if selection enabled
if($$.isBarType(closest.id)||$$.dist(closest,mouse)<config.point_sensitivity){$$.main.selectAll('.'+CLASS.shapes+$$.getTargetSelectorSuffix(closest.id)).selectAll('.'+CLASS.shape+'-'+closest.index).each(function(){if(config.data_selection_grouped||$$.isWithinShape(this,closest)){$$.toggleShape(this,closest,closest.index);$$.config.data_onclick.call($$.api,closest,this);}});}}eventRectEnter.append('rect').attr('x',0).attr('y',0).attr('width',$$.width).attr('height',$$.height).attr('class',CLASS.eventRect).on('mouseout',function(){if(!$$.config){return;}// chart is destroyed
if($$.hasArcType()){return;}mouseout();}).on('mousemove',function(){vartargetsToShow=$$.filterTargetsToShow($$.data.targets);varmouse=void0,closest=void0,sameXData=void0,selectedData=void0;if($$.dragging){return;}// do nothing when dragging
if($$.hasArcType(targetsToShow)){return;}mouse=d3$$1.mouse(this);closest=$$.findClosestFromTargets(targetsToShow,mouse);if($$.mouseover&&(!closest||closest.id!==$$.mouseover.id)){config.data_onmouseout.call($$.api,$$.mouseover);$$.mouseover=undefined;}if(!closest){mouseout();return;}if($$.isScatterType(closest)||!config.tooltip_grouped){sameXData=[closest];}else{sameXData=$$.filterByX(targetsToShow,closest.x);}// show tooltip when cursor is close to some point
if(config.point_focus_expand_enabled){$$.expandCircles(closest.index,closest.id,true);}$$.expandBars(closest.index,closest.id,true);// Show xgrid focus line
$$.showXGridFocus(selectedData);// Show cursor as pointer if point is close to mouse position
if($$.isBarType(closest.id)||$$.dist(closest,mouse)<config.point_sensitivity){$$.svg.select('.'+CLASS.eventRect).style('cursor','pointer');if(!$$.mouseover){config.data_onmouseover.call($$.api,closest);$$.mouseover=closest;}}}).on('click',function(){// click event was simulated via a 'tap' touch event, cancel regular click
if(tap){return;}click(this);}).on('touchstart',function(){varmouse=d3$$1.mouse(this);// store starting coordinates for distance comparision during touch end event
tapX=mouse[0];tapY=mouse[1];}).on('touchend',function(){varmouse=d3$$1.mouse(this),x=mouse[0],y=mouse[1];// If end is too far from start, event doesn't count as a tap
if(Math.abs(x-tapX)>config.touch_tap_radius||Math.abs(y-tapY)>config.touch_tap_radius){return;}click(this);// indictate tap event fired to prevent click;
return$$.axis.getYAxisLabelPosition().isOuter?30:1;}else{returnceil10($$.getAxisWidthByAxisId('y',withoutRecompute));}};c3_chart_internal_fn.getCurrentPaddingRight=function(){var$$=this,config=$$.config,defaultPadding=10,legendWidthOnRight=$$.isLegendRight?$$.getLegendWidth()+20:0;if(isValue(config.padding_right)){returnconfig.padding_right+1;// 1 is needed not to hide tick line
return2+legendWidthOnRight+($$.axis.getY2AxisLabelPosition().isOuter?20:0);}else{returnceil10($$.getAxisWidthByAxisId('y2'))+legendWidthOnRight;}};c3_chart_internal_fn.getParentRectValue=function(key){varparent=this.selectChart.node(),v=void0;while(parent&&parent.tagName!=='BODY'){try{v=parent.getBoundingClientRect()[key];}catch(e){if(key==='width'){// In IE in certain cases getBoundingClientRect
v=parent.offsetWidth;}}if(v){break;}parent=parent.parentNode;}returnv;};c3_chart_internal_fn.getParentWidth=function(){returnthis.getParentRectValue('width');};c3_chart_internal_fn.getParentHeight=function(){varh=this.selectChart.style('height');returnh.indexOf('px')>0?+h.replace('px',''):0;};c3_chart_internal_fn.getSvgLeft=function(withoutRecompute){var$$=this,config=$$.config,hasLeftAxisRect=config.axis_rotated||!config.axis_rotated&&!config.axis_y_inner,leftAxisClass=config.axis_rotated?CLASS.axisX:CLASS.axisY,leftAxis=$$.main.select('.'+leftAxisClass).node(),svgRect=leftAxis&&hasLeftAxisRect?leftAxis.getBoundingClientRect():{right:0},chartRect=$$.selectChart.node().getBoundingClientRect(),hasArc=$$.hasArcType(),svgLeft=svgRect.right-chartRect.left-(hasArc?0:$$.getCurrentPaddingLeft(withoutRecompute));returnsvgLeft>0?svgLeft:0;};c3_chart_internal_fn.getAxisWidthByAxisId=function(id,withoutRecompute){var$$=this,position=$$.axis.getLabelPositionById(id);return$$.axis.getMaxTickWidth(id,withoutRecompute)+(position.isInner?20:40);};c3_chart_internal_fn.getHorizontalAxisHeight=function(axisId){var$$=this,config=$$.config,h=30;if(axisId==='x'&&!config.axis_x_show){return8;}if(axisId==='x'&&config.axis_x_height){returnconfig.axis_x_height;}if(axisId==='y'&&!config.axis_y_show){returnconfig.legend_show&&!$$.isLegendRight&&!$$.isLegendInset?10:1;}if(axisId==='y2'&&!config.axis_y2_show){return$$.rotated_padding_top;}// Calculate x axis height when tick rotated
if(axisId==='x'&&!config.axis_rotated&&config.axis_x_tick_rotate){h=30+$$.axis.getMaxTickWidth(axisId)*Math.cos(Math.PI*(90-config.axis_x_tick_rotate)/180);}// Calculate y axis height when tick rotated
if(axisId==='y'&&config.axis_rotated&&config.axis_y_tick_rotate){h=30+$$.axis.getMaxTickWidth(axisId)*Math.cos(Math.PI*(90-config.axis_y_tick_rotate)/180);}returnh+($$.axis.getLabelPositionById(axisId).isInner?0:10)+(axisId==='y2'?-10:0);};c3_chart_internal_fn.getEventRectWidth=function(){returnMath.max(0,this.xAxis.tickInterval());};c3_chart_internal_fn.getShapeIndices=function(typeFilter){var$$=this,config=$$.config,indices={},i=0,j=void0,k=void0;$$.filterTargetsToShow($$.data.targets.filter(typeFilter,$$)).forEach(function(d){for(j=0;j<config.data_groups.length;j++){if(config.data_groups[j].indexOf(d.id)<0){continue;}for(k=0;k<config.data_groups[j].length;k++){if(config.data_groups[j][k]inindices){indices[d.id]=indices[config.data_groups[j][k]];break;}}}if(isUndefined(indices[d.id])){indices[d.id]=i++;}});indices.__max__=i-1;returnindices;};c3_chart_internal_fn.getShapeX=function(offset,targetsNum,indices,isSub){var$$=this,scale=isSub?$$.subX:$$.x;returnfunction(d){varindex=d.idinindices?indices[d.id]:0;returnd.x||d.x===0?scale(d.x)-offset*(targetsNum/2-index):0;};};c3_chart_internal_fn.getShapeY=function(isSub){var$$=this;returnfunction(d){varscale=isSub?$$.getSubYScale(d.id):$$.getYScale(d.id);returnscale(d.value);};};c3_chart_internal_fn.getShapeOffset=function(typeFilter,indices,isSub){var$$=this,targets=$$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter,$$))),targetIds=targets.map(function(t){returnt.id;});returnfunction(d,i){varscale=isSub?$$.getSubYScale(d.id):$$.getYScale(d.id),y0=scale(0),offset=y0;targets.forEach(function(t){varvalues=$$.isStepType(d)?$$.convertValuesToStep(t.values):t.values;if(t.id===d.id||indices[t.id]!==indices[d.id]){return;}if(targetIds.indexOf(t.id)<targetIds.indexOf(d.id)){// check if the x values line up
i=-1;values.forEach(function(v,j){if(v.x===d.x){i=j;}});}if(iinvalues&&values[i].value*d.value>=0){offset+=scale(values[i].value)-y0;}}});returnoffset;};};c3_chart_internal_fn.isWithinShape=function(that,d){var$$=this,shape=$$.d3.select(that),isWithin=void0;if(!$$.isTargetToShow(d.id)){isWithin=false;}elseif(that.nodeName==='circle'){isWithin=$$.isStepType(d)?$$.isWithinStep(that,$$.getYScale(d.id)(d.value)):$$.isWithinCircle(that,$$.pointSelectR(d)*1.5);}elseif(that.nodeName==='path'){isWithin=shape.classed(CLASS.bar)?$$.isWithinBar(that):true;}returnisWithin;};c3_chart_internal_fn.getInterpolate=function(d){var$$=this,interpolation=$$.isInterpolationType($$.config.spline_interpolation_type)?$$.config.spline_interpolation_type:'cardinal';return$$.isSplineType(d)?interpolation:$$.isStepType(d)?$$.config.line_step_type:'linear';};c3_chart_internal_fn.initLine=function(){var$$=this;$$.main.select('.'+CLASS.chart).append('g').attr('class',CLASS.chartLines);};c3_chart_internal_fn.updateTargetsForLine=function(targets){var$$=this,config=$$.config,mainLineUpdate=void0,mainLineEnter=void0,classChartLine=$$.classChartLine.bind($$),classLines=$$.classLines.bind($$),classAreas=$$.classAreas.bind($$),classCircles=$$.classCircles.bind($$),classFocus=$$.classFocus.bind($$);mainLineUpdate=$$.main.select('.'+CLASS.chartLines).selectAll('.'+CLASS.chartLine).data(targets).attr('class',function(d){returnclassChartLine(d)+classFocus(d);});mainLineEnter=mainLineUpdate.enter().append('g').attr('class',classChartLine).style('opacity',0).style('pointer-events','none');// Lines for each data
mainLineEnter.append('g').attr('class',classLines);// Areas
mainLineEnter.append('g').attr('class',function(d){return$$.generateClass(CLASS.selectedCircles,d.id);});mainLineEnter.append('g').attr('class',classCircles).style('cursor',function(d){returnconfig.data_selection_isselectable(d)?'pointer':null;});// Update date for selected circles
targets.forEach(function(t){$$.main.selectAll('.'+CLASS.selectedCircles+$$.getTargetSelectorSuffix(t.id)).selectAll('.'+CLASS.selectedCircle).each(function(d){d.value=t.values[d.index].value;});});// MEMO: can not keep same color...
var$$=this,config=$$.config,lineTargetsNum=lineIndices.__max__+1,x=$$.getShapeX(0,lineTargetsNum,lineIndices,!!isSub),y=$$.getShapeY(!!isSub),lineOffset=$$.getShapeOffset($$.isLineType,lineIndices,!!isSub),yScale=isSub?$$.getSubYScale:$$.getYScale;returnfunction(d,i){vary0=yScale.call($$,d.id)(0),offset=lineOffset(d,i)||y0,// offset is for stacked area chart
posX=x(d),posY=y(d);// fix posY not to overflow opposite quadrant
if(config.axis_rotated){if(0<d.value&&posY<y0||d.value<0&&y0<posY){posY=y0;}}// 1 point that marks the line position
return[[posX,posY-(y0-offset)],[posX,posY-(y0-offset)],// needed for compatibility
[posX,posY-(y0-offset)],// needed for compatibility
[posX,posY-(y0-offset)]];};};c3_chart_internal_fn.lineWithRegions=function(d,x,y,_regions){var$$=this,config=$$.config,prev=-1,i=void0,j=void0,s='M',sWithRegion=void0,xp=void0,yp=void0,dx=void0,dy=void0,dd=void0,diff=void0,diffx2=void0,xOffset=$$.isCategorized()?0.5:0,xValue=void0,yValue=void0,regions=[];functionisWithinRegions(x,regions){vari=void0;for(i=0;i<regions.length;i++){if(regions[i].start<x&&x<=regions[i].end){returntrue;}}returnfalse;}// Check start/end of regions
if(isDefined(_regions)){for(i=0;i<_regions.length;i++){regions[i]={};if(isUndefined(_regions[i].start)){regions[i].start=d[0].x;}else{regions[i].start=$$.isTimeSeries()?$$.parseDate(_regions[i].start):_regions[i].start;}if(isUndefined(_regions[i].end)){regions[i].end=d[d.length-1].x;}else{regions[i].end=$$.isTimeSeries()?$$.parseDate(_regions[i].end):_regions[i].end;}}}// Set scales
xValue=config.axis_rotated?function(d){returny(d.value);}:function(d){returnx(d.x);};yValue=config.axis_rotated?function(d){returnx(d.x);}:function(d){returny(d.value);};// Define svg generator function for region
var$$=this,config=$$.config,areaTargetsNum=areaIndices.__max__+1,x=$$.getShapeX(0,areaTargetsNum,areaIndices,!!isSub),y=$$.getShapeY(!!isSub),areaOffset=$$.getShapeOffset($$.isAreaType,areaIndices,!!isSub),yScale=isSub?$$.getSubYScale:$$.getYScale;returnfunction(d,i){vary0=yScale.call($$,d.id)(0),offset=areaOffset(d,i)||y0,// offset is for stacked area chart
posX=x(d),posY=y(d);// fix posY not to overflow opposite quadrant
if(config.axis_rotated){if(0<d.value&&posY<y0||d.value<0&&y0<posY){posY=y0;}}// 1 point that marks the area position
return[[posX,offset],[posX,posY-(y0-offset)],[posX,posY-(y0-offset)],// needed for compatibility
[posX,offset]];};};c3_chart_internal_fn.updateCircle=function(){var$$=this;$$.mainCircle=$$.main.selectAll('.'+CLASS.circles).selectAll('.'+CLASS.circle).data($$.lineOrScatterData.bind($$));$$.mainCircle.enter().append('circle').attr('class',$$.classCircle.bind($$)).attr('r',$$.pointR.bind($$)).style('fill',$$.color);$$.mainCircle.style('opacity',$$.initialOpacityForCircle.bind($$));$$.mainCircle.exit().remove();};c3_chart_internal_fn.redrawCircle=function(cx,cy,withTransition){varselectedCircles=this.main.selectAll('.'+CLASS.selectedCircle);return[(withTransition?this.mainCircle.transition(Math.random().toString()):this.mainCircle).style('opacity',this.opacityForCircle.bind(this)).style('fill',this.color).attr('cx',cx).attr('cy',cy),(withTransition?selectedCircles.transition(Math.random().toString()):selectedCircles).attr('cx',cx).attr('cy',cy)];};c3_chart_internal_fn.circleX=function(d){returnd.x||d.x===0?this.x(d.x):null;};c3_chart_internal_fn.updateCircleY=function(){var$$=this,lineIndices=void0,getPoints=void0;if($$.config.data_groups.length>0){lineIndices=$$.getShapeIndices($$.isLineType),getPoints=$$.generateGetLinePoints(lineIndices);$$.circleY=function(d,i){returngetPoints(d,i)[0][1];};}else{$$.circleY=function(d){return$$.getYScale(d.id)(d.value);};}};c3_chart_internal_fn.getCircles=function(i,id){var$$=this;return(id?$$.main.selectAll('.'+CLASS.circles+$$.getTargetSelectorSuffix(id)):$$.main).selectAll('.'+CLASS.circle+(isValue(i)?'-'+i:''));};c3_chart_internal_fn.expandCircles=function(i,id,reset){var$$=this,r=$$.pointExpandedR.bind($$);if(reset){$$.unexpandCircles();}$$.getCircles(i,id).classed(CLASS.EXPANDED,true).attr('r',r);};c3_chart_internal_fn.unexpandCircles=function(i){var$$=this,r=$$.pointR.bind($$);$$.getCircles(i).filter(function(){return$$.d3.select(this).classed(CLASS.EXPANDED);}).classed(CLASS.EXPANDED,false).attr('r',r);};c3_chart_internal_fn.pointR=function(d){var$$=this,config=$$.config;return$$.isStepType(d)?0:isFunction(config.point_r)?config.point_r(d):config.point_r;};c3_chart_internal_fn.pointExpandedR=function(d){var$$=this,config=$$.config;returnconfig.point_focus_expand_enabled?config.point_focus_expand_r?config.point_focus_expand_r:$$.pointR(d)*1.75:$$.pointR(d);};c3_chart_internal_fn.pointSelectR=function(d){var$$=this,config=$$.config;returnisFunction(config.point_select_r)?config.point_select_r(d):config.point_select_r?config.point_select_r:$$.pointR(d)*4;};c3_chart_internal_fn.isWithinCircle=function(that,r){vard3$$1=this.d3,mouse=d3$$1.mouse(that),d3_this=d3$$1.select(that),cx=+d3_this.attr('cx'),cy=+d3_this.attr('cy');returnMath.sqrt(Math.pow(cx-mouse[0],2)+Math.pow(cy-mouse[1],2))<r;};c3_chart_internal_fn.isWithinStep=function(that,y){returnMath.abs(y-this.d3.mouse(that)[1])<30;};c3_chart_internal_fn.initBar=function(){var$$=this;$$.main.select('.'+CLASS.chart).append('g').attr('class',CLASS.chartBars);};c3_chart_internal_fn.updateTargetsForBar=function(targets){var$$=this,config=$$.config,mainBarUpdate=void0,mainBarEnter=void0,classChartBar=$$.classChartBar.bind($$),classBars=$$.classBars.bind($$),classFocus=$$.classFocus.bind($$);mainBarUpdate=$$.main.select('.'+CLASS.chartBars).selectAll('.'+CLASS.chartBar).data(targets).attr('class',function(d){returnclassChartBar(d)+classFocus(d);});mainBarEnter=mainBarUpdate.enter().append('g').attr('class',classChartBar).style('opacity',0).style('pointer-events','none');// Bars for each data
mainBarEnter.append('g').attr('class',classBars).style('cursor',function(d){returnconfig.data_selection_isselectable(d)?'pointer':null;});};c3_chart_internal_fn.updateBar=function(durationForExit){var$$=this,barData=$$.barData.bind($$),classBar=$$.classBar.bind($$),initialOpacity=$$.initialOpacity.bind($$),color=functioncolor(d){return$$.color(d.id);};$$.mainBar=$$.main.selectAll('.'+CLASS.bars).selectAll('.'+CLASS.bar).data(barData);$$.mainBar.enter().append('path').attr('class',classBar).style('stroke',color).style('fill',color);$$.mainBar.style('opacity',initialOpacity);$$.mainBar.exit().transition().duration(durationForExit).style('opacity',0).remove();};c3_chart_internal_fn.redrawBar=function(drawBar,withTransition){return[(withTransition?this.mainBar.transition(Math.random().toString()):this.mainBar).attr('d',drawBar).style('fill',this.color).style('opacity',1)];};c3_chart_internal_fn.getBarW=function(axis,barTargetsNum){var$$=this,config=$$.config,w=typeofconfig.bar_width==='number'?config.bar_width:barTargetsNum?axis.tickInterval()*config.bar_width_ratio/barTargetsNum:0;returnconfig.bar_width_max&&w>config.bar_width_max?config.bar_width_max:w;};c3_chart_internal_fn.getBars=function(i,id){var$$=this;return(id?$$.main.selectAll('.'+CLASS.bars+$$.getTargetSelectorSuffix(id)):$$.main).selectAll('.'+CLASS.bar+(isValue(i)?'-'+i:''));};c3_chart_internal_fn.expandBars=function(i,id,reset){var$$=this;if(reset){$$.unexpandBars();}$$.getBars(i,id).classed(CLASS.EXPANDED,true);};c3_chart_internal_fn.unexpandBars=function(i){var$$=this;$$.getBars(i).classed(CLASS.EXPANDED,false);};c3_chart_internal_fn.generateDrawBar=function(barIndices,isSub){var$$=this,config=$$.config,getPoints=$$.generateGetBarPoints(barIndices,isSub);returnfunction(d,i){// 4 points that make a bar
varpoints=getPoints(d,i);// switch points if axis is rotated, not applicable for sub chart
varindexX=config.axis_rotated?1:0;varindexY=config.axis_rotated?0:1;varpath='M '+points[0][indexX]+','+points[0][indexY]+' '+'L'+points[1][indexX]+','+points[1][indexY]+' '+'L'+points[2][indexX]+','+points[2][indexY]+' '+'L'+points[3][indexX]+','+points[3][indexY]+' '+'z';returnpath;};};c3_chart_internal_fn.generateGetBarPoints=function(barIndices,isSub){var$$=this,axis=isSub?$$.subXAxis:$$.xAxis,barTargetsNum=barIndices.__max__+1,barW=$$.getBarW(axis,barTargetsNum),barX=$$.getShapeX(barW,barTargetsNum,barIndices,!!isSub),barY=$$.getShapeY(!!isSub),barOffset=$$.getShapeOffset($$.isBarType,barIndices,!!isSub),yScale=isSub?$$.getSubYScale:$$.getYScale;returnfunction(d,i){vary0=yScale.call($$,d.id)(0),offset=barOffset(d,i)||y0,// offset is for stacked bar chart
posX=barX(d),posY=barY(d);// fix posY not to overflow opposite quadrant
if($$.config.axis_rotated){if(0<d.value&&posY<y0||d.value<0&&y0<posY){posY=y0;}}// 4 points that make a bar
return[[posX,offset],[posX,posY-(y0-offset)],[posX+barW,posY-(y0-offset)],[posX+barW,offset]];};};c3_chart_internal_fn.isWithinBar=function(that){varmouse=this.d3.mouse(that),box=that.getBoundingClientRect(),seg0=that.pathSegList.getItem(0),seg1=that.pathSegList.getItem(1),x=Math.min(seg0.x,seg1.x),y=Math.min(seg0.y,seg1.y),w=box.width,h=box.height,offset=2,sx=x-offset,ex=x+w+offset,sy=y+h+offset,ey=y-offset;returnsx<mouse[0]&&mouse[0]<ex&&ey<mouse[1]&&mouse[1]<sy;};c3_chart_internal_fn.initText=function(){var$$=this;$$.main.select('.'+CLASS.chart).append('g').attr('class',CLASS.chartTexts);$$.mainText=$$.d3.selectAll([]);};c3_chart_internal_fn.updateTargetsForText=function(targets){var$$=this,mainTextUpdate=void0,mainTextEnter=void0,classChartText=$$.classChartText.bind($$),classTexts=$$.classTexts.bind($$),classFocus=$$.classFocus.bind($$);mainTextUpdate=$$.main.select('.'+CLASS.chartTexts).selectAll('.'+CLASS.chartText).data(targets).attr('class',function(d){returnclassChartText(d)+classFocus(d);});mainTextEnter=mainTextUpdate.enter().append('g').attr('class',classChartText).style('opacity',0).style('pointer-events','none');mainTextEnter.append('g').attr('class',classTexts);};c3_chart_internal_fn.updateText=function(durationForExit){var$$=this,config=$$.config,barOrLineData=$$.barOrLineData.bind($$),classText=$$.classText.bind($$);$$.mainText=$$.main.selectAll('.'+CLASS.texts).selectAll('.'+CLASS.text).data(barOrLineData);$$.mainText.enter().append('text').attr('class',classText).attr('text-anchor',function(d){returnconfig.axis_rotated?d.value<0?'end':'start':'middle';}).style('stroke','none').style('fill',function(d){return$$.color(d);}).style('fill-opacity',0);$$.mainText.text(function(d,i,j){return$$.dataLabelFormat(d.id)(d.value,d.id,i,j);});$$.mainText.exit().transition().duration(durationForExit).style('fill-opacity',0).remove();};c3_chart_internal_fn.redrawText=function(xForText,yForText,forFlow,withTransition){return[(withTransition?this.mainText.transition():this.mainText).attr('x',xForText).attr('y',yForText).style('fill',this.color).style('fill-opacity',forFlow?0:this.opacityForText.bind(this))];};c3_chart_internal_fn.getTextRect=function(text,cls,element){vardummy=this.d3.select('body').append('div').classed('c3',true),svg=dummy.append('svg').style('visibility','hidden').style('position','fixed').style('top',0).style('left',0),font=this.d3.select(element).style('font'),rect=void0;svg.selectAll('.dummy').data([text]).enter().append('text').classed(cls?cls:'',true).style('font',font).text(text).each(function(){rect=this.getBoundingClientRect();});dummy.remove();returnrect;};c3_chart_internal_fn.generateXYForText=function(areaIndices,barIndices,lineIndices,forX){var$$=this,getAreaPoints=$$.generateGetAreaPoints(areaIndices,false),getBarPoints=$$.generateGetBarPoints(barIndices,false),getLinePoints=$$.generateGetLinePoints(lineIndices,false),getter=forX?$$.getXForText:$$.getYForText;returnfunction(d,i){vargetPoints=$$.isAreaType(d)?getAreaPoints:$$.isBarType(d)?getBarPoints:getLinePoints;returngetter.call($$,getPoints(d,i),d,this);};};c3_chart_internal_fn.getXForText=function(points,d,textElement){var$$=this,box=textElement.getBoundingClientRect(),xPos=void0,padding=void0;if($$.config.axis_rotated){padding=$$.isBarType(d)?4:6;xPos=points[2][1]+padding*(d.value<0?-1:1);}else{xPos=$$.hasType('bar')?(points[2][0]+points[0][0])/2:points[0][0];}// show labels regardless of the domain if value is null
if(d.value===null){if(xPos>$$.width){xPos=$$.width-box.width;}elseif(xPos<0){xPos=4;}}returnxPos;};c3_chart_internal_fn.getYForText=function(points,d,textElement){var$$=this,box=textElement.getBoundingClientRect(),yPos=void0;if($$.config.axis_rotated){yPos=(points[0][0]+points[2][0]+box.height*0.6)/2;}else{yPos=points[2][1];if(d.value<0||d.value===0&&!$$.hasPositiveValue){yPos+=box.height;if($$.isBarType(d)&&$$.isSafari()){yPos-=3;}elseif(!$$.isBarType(d)&&$$.isChrome()){yPos+=3;}}else{yPos+=$$.isBarType(d)?-3:-6;}}// show labels regardless of the domain if value is null
$$.grid.style('visibility',$$.hasArcType()?'hidden':'visible');main.select('line.'+CLASS.xgridFocus).style('visibility','hidden');if(config.grid_x_show){$$.updateXGrid();}$$.xgridLines=main.select('.'+CLASS.xgridLines).selectAll('.'+CLASS.xgridLine).data(config.grid_x_lines);// enter
if(config.grid_y_show){$$.updateYGrid();}$$.ygridLines=main.select('.'+CLASS.ygridLines).selectAll('.'+CLASS.ygridLine).data(config.grid_y_lines);// enter
$$.ygridLines.exit().transition().duration(duration).style('opacity',0).remove();};c3_chart_internal_fn.redrawGrid=function(withTransition){var$$=this,config=$$.config,xv=$$.xv.bind($$),lines=$$.xgridLines.select('line'),texts=$$.xgridLines.select('text');return[(withTransition?lines.transition():lines).attr('x1',config.axis_rotated?0:xv).attr('x2',config.axis_rotated?$$.width:xv).attr('y1',config.axis_rotated?xv:0).attr('y2',config.axis_rotated?xv:$$.height).style('opacity',1),(withTransition?texts.transition():texts).attr('x',config.axis_rotated?$$.yGridTextX.bind($$):$$.xGridTextX.bind($$)).attr('y',xv).text(function(d){returnd.text;}).style('opacity',1)];};c3_chart_internal_fn.showXGridFocus=function(selectedData){var$$=this,config=$$.config,dataToShow=selectedData.filter(function(d){returnd&&isValue(d.value);}),focusEl=$$.main.selectAll('line.'+CLASS.xgridFocus),xx=$$.xx.bind($$);if(!config.tooltip_show){return;}// Hide when scatter plot exists
if($$.hasType('scatter')||$$.hasArcType()){return;}focusEl.style('visibility','visible').data([dataToShow[0]]).attr(config.axis_rotated?'y1':'x1',xx).attr(config.axis_rotated?'y2':'x2',xx);$$.smoothLines(focusEl,'grid');};c3_chart_internal_fn.hideXGridFocus=function(){this.main.select('line.'+CLASS.xgridFocus).style('visibility','hidden');};c3_chart_internal_fn.updateXgridFocus=function(){var$$=this,config=$$.config;$$.main.select('line.'+CLASS.xgridFocus).attr('x1',config.axis_rotated?0:-10).attr('x2',config.axis_rotated?$$.width:-10).attr('y1',config.axis_rotated?-10:0).attr('y2',config.axis_rotated?-10:$$.height);};c3_chart_internal_fn.generateGridData=function(type,scale){var$$=this,gridData=[],xDomain=void0,firstYear=void0,lastYear=void0,i=void0,tickNum=$$.main.select('.'+CLASS.axisX).selectAll('.tick').size();if(type==='year'){xDomain=$$.getXDomain();firstYear=xDomain[0].getFullYear();lastYear=xDomain[1].getFullYear();for(i=firstYear;i<=lastYear;i++){gridData.push(newDate(i+'-01-01 00:00:00'));}}else{gridData=scale.ticks(10);if(gridData.length>tickNum){// use only int
gridData=gridData.filter(function(d){return(''+d).indexOf('.')<0;});}}returngridData;};c3_chart_internal_fn.getGridFilterToRemove=function(params){returnparams?function(line){varfound=false;[].concat(params).forEach(function(param){if('value'inparam&&line.value===param.value||'class'inparam&&line.class===param.class){found=true;}});returnfound;}:function(){returntrue;};};c3_chart_internal_fn.removeGridLines=function(params,forX){var$$=this,config=$$.config,toRemove=$$.getGridFilterToRemove(params),toShow=functiontoShow(line){return!toRemove(line);},classLines=forX?CLASS.xgridLines:CLASS.ygridLines,classLine=forX?CLASS.xgridLine:CLASS.ygridLine;$$.main.select('.'+classLines).selectAll('.'+classLine).filter(toRemove).transition().duration(config.transition_duration).style('opacity',0).remove();if(forX){config.grid_x_lines=config.grid_x_lines.filter(toShow);}else{config.grid_y_lines=config.grid_y_lines.filter(toShow);}};c3_chart_internal_fn.initTooltip=function(){var$$=this,config=$$.config,i=void0;$$.tooltip=$$.selectChart.style('position','relative').append('div').attr('class',CLASS.tooltipContainer).style('position','absolute').style('pointer-events','none').style('display','none');// Show tooltip if needed
if(config.tooltip_init_show){if($$.isTimeSeries()&&isString(config.tooltip_init_x)){config.tooltip_init_x=$$.parseDate(config.tooltip_init_x);for(i=0;i<$$.data.targets[0].values.length;i++){if($$.data.targets[0].values[i].x-config.tooltip_init_x===0){break;}}config.tooltip_init_x=i;}$$.tooltip.html(config.tooltip_contents.call($$,$$.data.targets.map(function(d){return$$.addName(d.values[config.tooltip_init_x]);}),$$.axis.getXAxisTickFormat(),$$.getYFormat($$.hasArcType()),$$.color));$$.tooltip.style('top',config.tooltip_init_position.top).style('left',config.tooltip_init_position.left).style('display','block');}};c3_chart_internal_fn.getTooltipContent=function(d,defaultTitleFormat,defaultValueFormat,color){var$$=this,config=$$.config,titleFormat=config.tooltip_format_title||defaultTitleFormat,nameFormat=config.tooltip_format_name||function(name){returnname;},valueFormat=config.tooltip_format_value||defaultValueFormat,text=void0,i=void0,title=void0,value=void0,name=void0,bgcolor=void0,orderAsc=$$.isOrderAsc();if(config.data_groups.length===0){d.sort(function(a,b){varv1=a?a.value:null,v2=b?b.value:null;returnorderAsc?v1-v2:v2-v1;});}else{(function(){varids=$$.orderTargets($$.data.targets).map(function(i){returni.id;});d.sort(function(a,b){varv1=a?a.value:null,v2=b?b.value:null;if(v1>0&&v2>0){v1=a?ids.indexOf(a.id):null;v2=b?ids.indexOf(b.id):null;}returnorderAsc?v1-v2:v2-v1;});})();}for(i=0;i<d.length;i++){if(!(d[i]&&(d[i].value||d[i].value===0))){continue;}if(!text){title=sanitise(titleFormat?titleFormat(d[i].x):d[i].x);text="<table class='"+$$.CLASS.tooltip+"'>"+(title||title===0?"<tr><th colspan='2'>"+title+'</th></tr>':'');}value=sanitise(valueFormat(d[i].value,d[i].ratio,d[i].id,d[i].index,d));if(value!==undefined){// Skip elements when their name is set to null
if(d[i].name===null){continue;}name=sanitise(nameFormat(d[i].name,d[i].ratio,d[i].id,d[i].index));bgcolor=$$.levelColor?$$.levelColor(d[i].value):color(d[i].id);text+="<tr class='"+$$.CLASS.tooltipName+'-'+$$.getTargetSelectorSuffix(d[i].id)+"'>";text+="<td class='name'><span style='background-color:"+bgcolor+"'></span>"+name+'</td>';text+="<td class='value'>"+value+'</td>';text+='</tr>';}}returntext+'</table>';};c3_chart_internal_fn.tooltipPosition=function(dataToShow,tWidth,tHeight,element){var$$=this,config=$$.config,d3$$1=$$.d3;varsvgLeft=void0,tooltipLeft=void0,tooltipRight=void0,tooltipTop=void0,chartRight=void0;varforArc=$$.hasArcType(),mouse=d3$$1.mouse(element);// Determin tooltip position
if(forArc){tooltipLeft=($$.width-($$.isLegendRight?$$.getLegendWidth():0))/2+mouse[0];tooltipTop=$$.height/2+mouse[1]+20;}else{svgLeft=$$.getSvgLeft(true);if(config.axis_rotated){tooltipLeft=svgLeft+mouse[0]+100;tooltipRight=tooltipLeft+tWidth;chartRight=$$.currentWidth-$$.getCurrentPaddingRight();tooltipTop=$$.x(dataToShow[0].x)+20;}else{tooltipLeft=svgLeft+$$.getCurrentPaddingLeft(true)+$$.x(dataToShow[0].x)+20;tooltipRight=tooltipLeft+tWidth;chartRight=svgLeft+$$.currentWidth-$$.getCurrentPaddingRight();tooltipTop=mouse[1]+15;}if(tooltipRight>chartRight){// 20 is needed for Firefox to keep tooltip width
tooltipLeft-=tooltipRight-chartRight+20;}if(tooltipTop+tHeight>$$.currentHeight){tooltipTop-=tHeight+30;}}if(tooltipTop<0){tooltipTop=0;}return{top:tooltipTop,left:tooltipLeft};};c3_chart_internal_fn.showTooltip=function(selectedData,element){var$$=this,config=$$.config;vartWidth=void0,tHeight=void0,position=void0;varforArc=$$.hasArcType(),dataToShow=selectedData.filter(function(d){returnd&&isValue(d.value);}),positionFunction=config.tooltip_position||c3_chart_internal_fn.tooltipPosition;if(dataToShow.length===0||!config.tooltip_show){return;}$$.tooltip.html(config.tooltip_contents.call($$,selectedData,$$.axis.getXAxisTickFormat(),$$.getYFormat(forArc),$$.color)).style('display','block');// Get tooltip dimensions
tWidth=$$.tooltip.property('offsetWidth');tHeight=$$.tooltip.property('offsetHeight');position=positionFunction.call(this,dataToShow,tWidth,tHeight,element);// Set tooltip
$$.tooltip.style('top',position.top+'px').style('left',position.left+'px');};c3_chart_internal_fn.hideTooltip=function(){this.tooltip.style('display','none');};c3_chart_internal_fn.initLegend=function(){var$$=this;$$.legendItemTextBox={};$$.legendHasRendered=false;$$.legend=$$.svg.append('g').attr('transform',$$.getTranslate('legend'));if(!$$.config.legend_show){$$.legend.style('visibility','hidden');$$.hiddenLegendIds=$$.mapToIds($$.data.targets);return;}// MEMO: call here to update legend box and tranlate for all
$$.updateLegendWithDefaults();};c3_chart_internal_fn.updateLegendWithDefaults=function(){var$$=this;$$.updateLegend($$.mapToIds($$.data.targets),{withTransform:false,withTransitionForTransform:false,withTransition:false});};c3_chart_internal_fn.updateSizeForLegend=function(legendHeight,legendWidth){var$$=this,config=$$.config,insetLegendPosition={top:$$.isLegendTop?$$.getCurrentPaddingTop()+config.legend_inset_y+5.5:$$.currentHeight-legendHeight-$$.getCurrentPaddingBottom()-config.legend_inset_y,left:$$.isLegendLeft?$$.getCurrentPaddingLeft()+config.legend_inset_x+0.5:$$.currentWidth-legendWidth-$$.getCurrentPaddingRight()-config.legend_inset_x+0.5};$$.margin3={top:$$.isLegendRight?0:$$.isLegendInset?insetLegendPosition.top:$$.currentHeight-legendHeight,right:NaN,bottom:0,left:$$.isLegendRight?$$.currentWidth-legendWidth:$$.isLegendInset?insetLegendPosition.left:0};};c3_chart_internal_fn.transformLegend=function(withTransition){var$$=this;(withTransition?$$.legend.transition():$$.legend).attr('transform',$$.getTranslate('legend'));};c3_chart_internal_fn.updateLegendStep=function(step){this.legendStep=step;};c3_chart_internal_fn.updateLegendItemWidth=function(w){this.legendItemWidth=w;};c3_chart_internal_fn.updateLegendItemHeight=function(h){this.legendItemHeight=h;};c3_chart_internal_fn.getLegendWidth=function(){var$$=this;return$$.config.legend_show?$$.isLegendRight||$$.isLegendInset?$$.legendItemWidth*($$.legendStep+1):$$.currentWidth:0;};c3_chart_internal_fn.getLegendHeight=function(){var$$=this,h=0;if($$.config.legend_show){if($$.isLegendRight){h=$$.currentHeight;}else{h=Math.max(20,$$.legendItemHeight)*($$.legendStep+1);}}returnh;};c3_chart_internal_fn.opacityForLegend=function(legendItem){returnlegendItem.classed(CLASS.legendItemHidden)?null:1;};c3_chart_internal_fn.opacityForUnfocusedLegend=function(legendItem){returnlegendItem.classed(CLASS.legendItemHidden)?null:0.3;};c3_chart_internal_fn.toggleFocusLegend=function(targetIds,focus){var$$=this;targetIds=$$.mapToTargetIds(targetIds);$$.legend.selectAll('.'+CLASS.legendItem).filter(function(id){returntargetIds.indexOf(id)>=0;}).classed(CLASS.legendItemFocused,focus).transition().duration(100).style('opacity',function(){varopacity=focus?$$.opacityForLegend:$$.opacityForUnfocusedLegend;returnopacity.call($$,$$.d3.select(this));});};c3_chart_internal_fn.revertLegend=function(){var$$=this,d3$$1=$$.d3;$$.legend.selectAll('.'+CLASS.legendItem).classed(CLASS.legendItemFocused,false).transition().duration(100).style('opacity',function(){return$$.opacityForLegend(d3$$1.select(this));});};c3_chart_internal_fn.showLegend=function(targetIds){var$$=this,config=$$.config;if(!config.legend_show){config.legend_show=true;$$.legend.style('visibility','visible');if(!$$.legendHasRendered){$$.updateLegendWithDefaults();}}$$.removeHiddenLegendIds(targetIds);$$.legend.selectAll($$.selectorLegends(targetIds)).style('visibility','visible').transition().style('opacity',function(){return$$.opacityForLegend($$.d3.select(this));});};c3_chart_internal_fn.hideLegend=function(targetIds){var$$=this,config=$$.config;if(config.legend_show&&isEmpty(targetIds)){config.legend_show=false;$$.legend.style('visibility','hidden');}$$.addHiddenLegendIds(targetIds);$$.legend.selectAll($$.selectorLegends(targetIds)).style('opacity',0).style('visibility','hidden');};c3_chart_internal_fn.clearLegendItemTextBoxCache=function(){this.legendItemTextBox={};};c3_chart_internal_fn.updateLegend=function(targetIds,options,transitions){var$$=this,config=$$.config;varxForLegend=void0,xForLegendText=void0,xForLegendRect=void0,yForLegend=void0,yForLegendText=void0,yForLegendRect=void0,x1ForLegendTile=void0,x2ForLegendTile=void0,yForLegendTile=void0;varpaddingTop=4,paddingRight=10,maxWidth=0,maxHeight=0,posMin=10,tileWidth=config.legend_item_tile_width+5;varl=void0,totalLength=0,offsets={},widths={},heights={},margins=[0],steps={},step=0;varwithTransition=void0,withTransitionForTransform=void0;vartexts=void0,rects=void0,tiles=void0,background=void0;// Skip elements when their name is s
targetIds=targetIds.filter(function(id){return!isDefined(config.data_names[id])||config.data_names[id]!==null;});options=options||{};withTransition=getOption(options,'withTransition',true);withTransitionForTransform=getOption(options,'withTransitionForTransform',true);functiongetTextBox(textElement,id){if(!$$.legendItemTextBox[id]){$$.legendItemTextBox[id]=$$.getTextRect(textElement.textContent,CLASS.legendItem,textElement);}return$$.legendItemTextBox[id];}functionupdatePositions(textElement,id,index){varreset=index===0,isLast=index===targetIds.length-1,box=getTextBox(textElement,id),itemWidth=box.width+tileWidth+(isLast&&!($$.isLegendRight||$$.isLegendInset)?0:paddingRight)+config.legend_padding,itemHeight=box.height+paddingTop,itemLength=$$.isLegendRight||$$.isLegendInset?itemHeight:itemWidth,areaLength=$$.isLegendRight||$$.isLegendInset?$$.getLegendHeight():$$.getLegendWidth(),margin=void0,maxLength=void0;// MEMO: care about condifion of step, totalLength
functionupdateValues(id,withoutStep){if(!withoutStep){margin=(areaLength-totalLength-itemLength)/2;if(margin<posMin){margin=(areaLength-itemLength)/2;totalLength=0;step++;}}steps[id]=step;margins[step]=$$.isLegendInset?10:margin;offsets[id]=totalLength;totalLength+=itemLength;}if(reset){totalLength=0;step=0;maxWidth=0;maxHeight=0;}if(config.legend_show&&!$$.isLegendToShow(id)){widths[id]=heights[id]=steps[id]=offsets[id]=0;return;}widths[id]=itemWidth;heights[id]=itemHeight;if(!maxWidth||itemWidth>=maxWidth){maxWidth=itemWidth;}if(!maxHeight||itemHeight>=maxHeight){maxHeight=itemHeight;}maxLength=$$.isLegendRight||$$.isLegendInset?maxHeight:maxWidth;if(config.legend_equally){Object.keys(widths).forEach(function(id){widths[id]=maxWidth;});Object.keys(heights).forEach(function(id){heights[id]=maxHeight;});margin=(areaLength-maxLength*targetIds.length)/2;if(margin<posMin){totalLength=0;step=0;targetIds.forEach(function(id){updateValues(id);});}else{updateValues(id,true);}}else{updateValues(id);}}if($$.isLegendInset){step=config.legend_inset_step?config.legend_inset_step:targetIds.length;$$.updateLegendStep(step);}if($$.isLegendRight){xForLegend=functionxForLegend(id){returnmaxWidth*steps[id];};yForLegend=functionyForLegend(id){returnmargins[steps[id]]+offsets[id];};}elseif($$.isLegendInset){xForLegend=functionxForLegend(id){returnmaxWidth*steps[id]+10;};yForLegend=functionyForLegend(id){returnmargins[steps[id]]+offsets[id];};}else{xForLegend=functionxForLegend(id){returnmargins[steps[id]]+offsets[id];};yForLegend=functionyForLegend(id){returnmaxHeight*steps[id];};}xForLegendText=functionxForLegendText(id,i){returnxForLegend(id,i)+4+config.legend_item_tile_width;};yForLegendText=functionyForLegendText(id,i){returnyForLegend(id,i)+9;};xForLegendRect=functionxForLegendRect(id,i){returnxForLegend(id,i);};yForLegendRect=functionyForLegendRect(id,i){returnyForLegend(id,i)-5;};x1ForLegendTile=functionx1ForLegendTile(id,i){returnxForLegend(id,i)-2;};x2ForLegendTile=functionx2ForLegendTile(id,i){returnxForLegend(id,i)-2+config.legend_item_tile_width;};yForLegendTile=functionyForLegendTile(id,i){returnyForLegend(id,i)+4;};// Define g for legend area
l=$$.legend.selectAll('.'+CLASS.legendItem).data(targetIds).enter().append('g').attr('class',function(id){return$$.generateClass(CLASS.legendItem,id);}).style('visibility',function(id){return$$.isLegendToShow(id)?'visible':'hidden';}).style('cursor','pointer').on('click',function(id){if(config.legend_item_onclick){config.legend_item_onclick.call($$,id);}else{if($$.d3.event.altKey){$$.api.hide();$$.api.show(id);}else{$$.api.toggle(id);$$.isTargetToShow(id)?$$.api.focus(id):$$.api.revert();}}}).on('mouseover',function(id){if(config.legend_item_onmouseover){config.legend_item_onmouseover.call($$,id);}else{$$.d3.select(this).classed(CLASS.legendItemFocused,true);if(!$$.transiting&&$$.isTargetToShow(id)){$$.api.focus(id);}}}).on('mouseout',function(id){if(config.legend_item_onmouseout){config.legend_item_onmouseout.call($$,id);}else{$$.d3.select(this).classed(CLASS.legendItemFocused,false);$$.api.revert();}});l.append('text').text(function(id){returnisDefined(config.data_names[id])?config.data_names[id]:id;}).each(function(id,i){updatePositions(this,id,i);}).style('pointer-events','none').attr('x',$$.isLegendRight||$$.isLegendInset?xForLegendText:-200).attr('y',$$.isLegendRight||$$.isLegendInset?-200:yForLegendText);l.append('rect').attr('class',CLASS.legendItemEvent).style('fill-opacity',0).attr('x',$$.isLegendRight||$$.isLegendInset?xForLegendRect:-200).attr('y',$$.isLegendRight||$$.isLegendInset?-200:yForLegendRect);l.append('line').attr('class',CLASS.legendItemTile).style('stroke',$$.color).style('pointer-events','none').attr('x1',$$.isLegendRight||$$.isLegendInset?x1ForLegendTile:-200).attr('y1',$$.isLegendRight||$$.isLegendInset?-200:yForLegendTile).attr('x2',$$.isLegendRight||$$.isLegendInset?x2ForLegendTile:-200).attr('y2',$$.isLegendRight||$$.isLegendInset?-200:yForLegendTile).attr('stroke-width',config.legend_item_tile_height);// Set background for inset legend
background=$$.legend.select('.'+CLASS.legendBackground+' rect');if($$.isLegendInset&&maxWidth>0&&background.size()===0){background=$$.legend.insert('g','.'+CLASS.legendItem).attr('class',CLASS.legendBackground).append('rect');}texts=$$.legend.selectAll('text').data(targetIds).text(function(id){returnisDefined(config.data_names[id])?config.data_names[id]:id;})// MEMO: needed for update
.each(function(id,i){updatePositions(this,id,i);});(withTransition?texts.transition():texts).attr('x',xForLegendText).attr('y',yForLegendText);rects=$$.legend.selectAll('rect.'+CLASS.legendItemEvent).data(targetIds);(withTransition?rects.transition():rects).attr('width',function(id){returnwidths[id];}).attr('height',function(id){returnheights[id];}).attr('x',xForLegendRect).attr('y',yForLegendRect);tiles=$$.legend.selectAll('line.'+CLASS.legendItemTile).data(targetIds);(withTransition?tiles.transition():tiles).style('stroke',$$.color).attr('x1',x1ForLegendTile).attr('y1',yForLegendTile).attr('x2',x2ForLegendTile).attr('y2',yForLegendTile);if(background){(withTransition?background.transition():background).attr('height',$$.getLegendHeight()-12).attr('width',maxWidth*(step+1)+10);}// toggle legend state
$$.legend.selectAll('.'+CLASS.legendItem).classed(CLASS.legendItemHidden,function(id){return!$$.isTargetToShow(id);});// Update all to reflect change of legend
$$.updateLegendItemWidth(maxWidth);$$.updateLegendItemHeight(maxHeight);$$.updateLegendStep(step);// Update size and scale
$$.updateSizes();$$.updateScales();$$.updateSvgSize();// Update g positions
$$.transformAll(withTransitionForTransform,transitions);$$.legendHasRendered=true;};c3_chart_internal_fn.initTitle=function(){var$$=this;$$.title=$$.svg.append('text').text($$.config.title_text).attr('class',$$.CLASS.title);};c3_chart_internal_fn.redrawTitle=function(){var$$=this;$$.title.attr('x',$$.xForTitle.bind($$)).attr('y',$$.yForTitle.bind($$));};c3_chart_internal_fn.xForTitle=function(){var$$=this,config=$$.config,position=config.title_position||'left',x=void0;if(position.indexOf('right')>=0){x=$$.currentWidth-$$.getTextRect($$.title.node().textContent,$$.CLASS.title,$$.title.node()).width-config.title_padding.right;}elseif(position.indexOf('center')>=0){x=($$.currentWidth-$$.getTextRect($$.title.node().textContent,$$.CLASS.title,$$.title.node()).width)/2;}else{// left
x=config.title_padding.left;}returnx;};c3_chart_internal_fn.yForTitle=function(){var$$=this;return$$.config.title_padding.top+$$.getTextRect($$.title.node().textContent,$$.CLASS.title,$$.title.node()).height;};c3_chart_internal_fn.getTitlePadding=function(){var$$=this;return$$.yForTitle()+$$.config.title_padding.bottom;};c3_chart_internal_fn.getClipPath=function(id){varisIE9=window.navigator.appVersion.toLowerCase().indexOf('msie 9.')>=0;return'url('+(isIE9?'':document.URL.split('#')[0])+'#'+id+')';};c3_chart_internal_fn.appendClip=function(parent,id){returnparent.append('clipPath').attr('id',id).append('rect');};c3_chart_internal_fn.getAxisClipX=function(forHorizontal){// axis line width + padding for left
varleft=Math.max(30,this.margin.left);returnforHorizontal?-(1+left):-(left-1);};c3_chart_internal_fn.getAxisClipY=function(forHorizontal){returnforHorizontal?-20:-this.margin.top;};c3_chart_internal_fn.getXAxisClipX=function(){var$$=this;return$$.getAxisClipX(!$$.config.axis_rotated);};c3_chart_internal_fn.getXAxisClipY=function(){var$$=this;return$$.getAxisClipY(!$$.config.axis_rotated);};c3_chart_internal_fn.getYAxisClipX=function(){var$$=this;return$$.config.axis_y_inner?-1:$$.getAxisClipX($$.config.axis_rotated);};c3_chart_internal_fn.getYAxisClipY=function(){var$$=this;return$$.getAxisClipY($$.config.axis_rotated);};c3_chart_internal_fn.getAxisClipWidth=function(forHorizontal){var$$=this,left=Math.max(30,$$.margin.left),right=Math.max(30,$$.margin.right);// width + axis line width + padding for left/right
returnforHorizontal?$$.width+2+left+right:$$.margin.left+20;};c3_chart_internal_fn.getAxisClipHeight=function(forHorizontal){// less than 20 is not enough to show the axis label 'outer' without legend
return(forHorizontal?this.margin.bottom:this.margin.top+this.height)+20;};c3_chart_internal_fn.getXAxisClipWidth=function(){var$$=this;return$$.getAxisClipWidth(!$$.config.axis_rotated);};c3_chart_internal_fn.getXAxisClipHeight=function(){var$$=this;return$$.getAxisClipHeight(!$$.config.axis_rotated);};c3_chart_internal_fn.getYAxisClipWidth=function(){var$$=this;return$$.getAxisClipWidth($$.config.axis_rotated)+($$.config.axis_y_inner?20:0);};c3_chart_internal_fn.getYAxisClipHeight=function(){var$$=this;return$$.getAxisClipHeight($$.config.axis_rotated);};c3_chart_internal_fn.initPie=function(){var$$=this,d3$$1=$$.d3,config=$$.config;$$.pie=d3$$1.layout.pie().value(function(d){returnd.values.reduce(function(a,b){returna+b.value;},0);});if(!config.data_order){$$.pie.sort(null);}};c3_chart_internal_fn.updateRadius=function(){var$$=this,config=$$.config,w=config.gauge_width||config.donut_width;$$.radiusExpanded=Math.min($$.arcWidth,$$.arcHeight)/2;$$.radius=$$.radiusExpanded*0.95;$$.innerRadiusRatio=w?($$.radius-w)/$$.radius:0.6;$$.innerRadius=$$.hasType('donut')||$$.hasType('gauge')?$$.radius*$$.innerRadiusRatio:0;};c3_chart_internal_fn.updateArc=function(){var$$=this;$$.svgArc=$$.getSvgArc();$$.svgArcExpanded=$$.getSvgArcExpanded();$$.svgArcExpandedSub=$$.getSvgArcExpanded(0.98);};c3_chart_internal_fn.updateAngle=function(d){var$$=this,config=$$.config,found=false,index=0,gMin=void0,gMax=void0,gTic=void0,gValue=void0;if(!config){returnnull;}$$.pie($$.filterTargetsToShow($$.data.targets)).forEach(function(t){if(!found&&t.data.id===d.data.id){found=true;d=t;d.index=index;}index++;});if(isNaN(d.startAngle)){d.startAngle=0;}if(isNaN(d.endAngle)){d.endAngle=d.startAngle;}if($$.isGaugeType(d.data)){gMin=config.gauge_min;gMax=config.gauge_max;gTic=Math.PI*(config.gauge_fullCircle?2:1)/(gMax-gMin);gValue=d.value<gMin?0:d.value<gMax?d.value-gMin:gMax-gMin;d.startAngle=config.gauge_startingAngle;d.endAngle=d.startAngle+gTic*gValue;}returnfound?d:null;};c3_chart_internal_fn.getSvgArc=function(){var$$=this,arc=$$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius),newArc=functionnewArc(d,withoutUpdate){varupdated=void0;if(withoutUpdate){returnarc(d);}// for interpolate
updated=$$.updateAngle(d);returnupdated?arc(updated):'M 0 0';};// TODO: extends all function
newArc.centroid=arc.centroid;returnnewArc;};c3_chart_internal_fn.getSvgArcExpanded=function(rate){var$$=this,arc=$$.d3.svg.arc().outerRadius($$.radiusExpanded*(rate?rate:1)).innerRadius($$.innerRadius);returnfunction(d){varupdated=$$.updateAngle(d);returnupdated?arc(updated):'M 0 0';};};c3_chart_internal_fn.getArc=function(d,withoutUpdate,force){returnforce||this.isArcType(d.data)?this.svgArc(d,withoutUpdate):'M 0 0';};c3_chart_internal_fn.transformForArcLabel=function(d){var$$=this,config=$$.config,updated=$$.updateAngle(d),c=void0,x=void0,y=void0,h=void0,ratio=void0,translate='';if(updated&&!$$.hasType('gauge')){c=this.svgArc.centroid(updated);x=isNaN(c[0])?0:c[0];y=isNaN(c[1])?0:c[1];h=Math.sqrt(x*x+y*y);if($$.hasType('donut')&&config.donut_label_ratio){ratio=isFunction(config.donut_label_ratio)?config.donut_label_ratio(d,$$.radius,h):config.donut_label_ratio;}elseif($$.hasType('pie')&&config.pie_label_ratio){ratio=isFunction(config.pie_label_ratio)?config.pie_label_ratio(d,$$.radius,h):config.pie_label_ratio;}else{ratio=$$.radius&&h?(36/$$.radius>0.375?1.175-36/$$.radius:0.8)*$$.radius/h:0;}translate='translate('+x*ratio+','+y*ratio+')';}returntranslate;};c3_chart_internal_fn.getArcRatio=function(d){var$$=this,config=$$.config,whole=Math.PI*($$.hasType('gauge')&&!config.gauge_fullCircle?1:2);returnd?(d.endAngle-d.startAngle)/whole:null;};c3_chart_internal_fn.convertToArcData=function(d){returnthis.addName({id:d.data.id,value:d.value,ratio:this.getArcRatio(d),index:d.index});};c3_chart_internal_fn.textForArcLabel=function(d){var$$=this,updated=void0,value=void0,ratio=void0,id=void0,format=void0;if(!$$.shouldShowArcLabel()){return'';}updated=$$.updateAngle(d);value=updated?updated.value:null;ratio=$$.getArcRatio(updated);id=d.data.id;if(!$$.hasType('gauge')&&!$$.meetsArcLabelThreshold(ratio)){return'';}format=$$.getArcLabelFormat();returnformat?format(value,ratio,id):$$.defaultArcValueFormat(value,ratio);};c3_chart_internal_fn.expandArc=function(targetIds){var$$=this,interval=void0;// MEMO: avoid to cancel transition
if($$.transiting){interval=window.setInterval(function(){if(!$$.transiting){window.clearInterval(interval);if($$.legend.selectAll('.c3-legend-item-focused').size()>0){$$.expandArc(targetIds);}}},10);return;}targetIds=$$.mapToTargetIds(targetIds);$$.svg.selectAll($$.selectorTargets(targetIds,'.'+CLASS.chartArc)).each(function(d){if(!$$.shouldExpand(d.data.id)){return;}$$.d3.select(this).selectAll('path').transition().duration($$.expandDuration(d.data.id)).attr('d',$$.svgArcExpanded).transition().duration($$.expandDuration(d.data.id)*2).attr('d',$$.svgArcExpandedSub).each(function(d){if($$.isDonutType(d.data)){// callback here
}});});};c3_chart_internal_fn.unexpandArc=function(targetIds){var$$=this;if($$.transiting){return;}targetIds=$$.mapToTargetIds(targetIds);$$.svg.selectAll($$.selectorTargets(targetIds,'.'+CLASS.chartArc)).selectAll('path').transition().duration(function(d){return$$.expandDuration(d.data.id);}).attr('d',$$.svgArc);$$.svg.selectAll('.'+CLASS.arc).style('opacity',1);};c3_chart_internal_fn.expandDuration=function(id){var$$=this,config=$$.config;if($$.isDonutType(id)){returnconfig.donut_expand_duration;}elseif($$.isGaugeType(id)){returnconfig.gauge_expand_duration;}elseif($$.isPieType(id)){returnconfig.pie_expand_duration;}else{return50;}};c3_chart_internal_fn.shouldExpand=function(id){var$$=this,config=$$.config;return$$.isDonutType(id)&&config.donut_expand||$$.isGaugeType(id)&&config.gauge_expand||$$.isPieType(id)&&config.pie_expand;};c3_chart_internal_fn.shouldShowArcLabel=function(){var$$=this,config=$$.config,shouldShow=true;if($$.hasType('donut')){shouldShow=config.donut_label_show;}elseif($$.hasType('pie')){shouldShow=config.pie_label_show;}// when gauge, always true
returnshouldShow;};c3_chart_internal_fn.meetsArcLabelThreshold=function(ratio){var$$=this,config=$$.config,threshold=$$.hasType('donut')?config.donut_label_threshold:config.pie_label_threshold;returnratio>=threshold;};c3_chart_internal_fn.getArcLabelFormat=function(){var$$=this,config=$$.config,format=config.pie_label_format;if($$.hasType('gauge')){format=config.gauge_label_format;}elseif($$.hasType('donut')){format=config.donut_label_format;}returnformat;};c3_chart_internal_fn.getArcTitle=function(){var$$=this;return$$.hasType('donut')?$$.config.donut_title:'';};c3_chart_internal_fn.updateTargetsForArc=function(targets){var$$=this,main=$$.main,mainPieUpdate=void0,mainPieEnter=void0,classChartArc=$$.classChartArc.bind($$),classArcs=$$.classArcs.bind($$),classFocus=$$.classFocus.bind($$);mainPieUpdate=main.select('.'+CLASS.chartArcs).selectAll('.'+CLASS.chartArc).data($$.pie(targets)).attr('class',function(d){returnclassChartArc(d)+classFocus(d.data);});mainPieEnter=mainPieUpdate.enter().append('g').attr('class',classChartArc);mainPieEnter.append('g').attr('class',classArcs);mainPieEnter.append('text').attr('dy',$$.hasType('gauge')?'-.1em':'.35em').style('opacity',0).style('text-anchor','middle').style('pointer-events','none');// MEMO: can not keep same color..., but not bad to update color in redraw
// mainPieUpdate.exit().remove();
};c3_chart_internal_fn.initArc=function(){var$$=this;$$.arcs=$$.main.select('.'+CLASS.chart).append('g').attr('class',CLASS.chartArcs).attr('transform',$$.getTranslate('arc'));$$.arcs.append('text').attr('class',CLASS.chartArcsTitle).style('text-anchor','middle').text($$.getArcTitle());};c3_chart_internal_fn.redrawArc=function(duration,durationForExit,withTransform){var$$=this,d3$$1=$$.d3,config=$$.config,main=$$.main,mainArc=void0;mainArc=main.selectAll('.'+CLASS.arcs).selectAll('.'+CLASS.arc).data($$.arcData.bind($$));mainArc.enter().append('path').attr('class',$$.classArc.bind($$)).style('fill',function(d){return$$.color(d.data);}).style('cursor',function(d){returnconfig.interaction_enabled&&config.data_selection_isselectable(d)?'pointer':null;}).style('opacity',0).each(function(d){if($$.isGaugeType(d.data)){d.startAngle=d.endAngle=config.gauge_startingAngle;}this._current=d;});mainArc.attr('transform',function(d){return!$$.isGaugeType(d.data)&&withTransform?'scale(0)':'';}).style('opacity',function(d){returnd===this._current?0:1;}).on('mouseover',config.interaction_enabled?function(d){varupdated=void0,arcData=void0;if($$.transiting){// skip while transiting
$$.expandArc(updated.data.id);$$.api.focus(updated.data.id);$$.toggleFocusLegend(updated.data.id,true);$$.config.data_onmouseover(arcData,this);}}:null).on('mousemove',config.interaction_enabled?function(d){varupdated=$$.updateAngle(d),arcData=void0,selectedData=void0;if(updated){arcData=$$.convertToArcData(updated),selectedData=[arcData];$$.showTooltip(selectedData,this);}}:null).on('mouseout',config.interaction_enabled?function(d){varupdated=void0,arcData=void0;if($$.transiting){// skip while transiting
if(isNaN(this._current.startAngle)){this._current.startAngle=0;}if(isNaN(this._current.endAngle)){this._current.endAngle=this._current.startAngle;}interpolate=d3$$1.interpolate(this._current,updated);this._current=interpolate(0);returnfunction(t){varinterpolated=interpolate(t);interpolated.data=d.data;// data.id will be updated by interporator
return$$.getArc(interpolated,true);};}).attr('transform',withTransform?'scale(1)':'').style('fill',function(d){return$$.levelColor?$$.levelColor(d.data.values[0].value):$$.color(d.data.id);})// Where gauge reading color would receive customization.
.style('opacity',1).call($$.endall,function(){$$.transiting=false;});mainArc.exit().transition().duration(durationForExit).style('opacity',0).remove();main.selectAll('.'+CLASS.chartArc).select('text').style('opacity',0).attr('class',function(d){return$$.isGaugeType(d.data)?CLASS.gaugeValue:'';}).text($$.textForArcLabel.bind($$)).attr('transform',$$.transformForArcLabel.bind($$)).style('font-size',function(d){return$$.isGaugeType(d.data)?Math.round($$.radius/5)+'px':'';}).transition().duration(duration).style('opacity',function(d){return$$.isTargetToShow(d.data.id)&&$$.isArcType(d.data)?1:0;});main.select('.'+CLASS.chartArcsTitle).style('opacity',$$.hasType('donut')||$$.hasType('gauge')?1:0);if($$.hasType('gauge')){$$.arcs.select('.'+CLASS.chartArcsBackground).attr('d',function(){vard={data:[{value:config.gauge_max}],startAngle:config.gauge_startingAngle,endAngle:-1*config.gauge_startingAngle};return$$.getArc(d,true,true);});$$.arcs.select('.'+CLASS.chartArcsGaugeUnit).attr('dy','.75em').text(config.gauge_label_show?config.gauge_units:'');$$.arcs.select('.'+CLASS.chartArcsGaugeMin).attr('dx',-1*($$.innerRadius+($$.radius-$$.innerRadius)/(config.gauge_fullCircle?1:2))+'px').attr('dy','1.2em').text(config.gauge_label_show?config.gauge_min:'');$$.arcs.select('.'+CLASS.chartArcsGaugeMax).attr('dx',$$.innerRadius+($$.radius-$$.innerRadius)/(config.gauge_fullCircle?1:2)+'px').attr('dy','1.2em').text(config.gauge_label_show?config.gauge_max:'');}};c3_chart_internal_fn.initGauge=function(){vararcs=this.arcs;if(this.hasType('gauge')){arcs.append('path').attr('class',CLASS.chartArcsBackground);arcs.append('text').attr('class',CLASS.chartArcsGaugeUnit).style('text-anchor','middle').style('pointer-events','none');arcs.append('text').attr('class',CLASS.chartArcsGaugeMin).style('text-anchor','middle').style('pointer-events','none');arcs.append('text').attr('class',CLASS.chartArcsGaugeMax).style('text-anchor','middle').style('pointer-events','none');}};c3_chart_internal_fn.getGaugeLabelHeight=function(){returnthis.config.gauge_label_show?20:0;};c3_chart_internal_fn.initRegion=function(){var$$=this;$$.region=$$.main.append('g').attr('clip-path',$$.clipPath).attr('class',CLASS.regions);};c3_chart_internal_fn.updateRegion=function(duration){var$$=this,config=$$.config;// hide if arc type
$$.region.style('visibility',$$.hasArcType()?'hidden':'visible');$$.mainRegion=$$.main.select('.'+CLASS.regions).selectAll('.'+CLASS.region).data(config.regions);$$.mainRegion.enter().append('g').append('rect').style('fill-opacity',0);$$.mainRegion.attr('class',$$.classRegion.bind($$));$$.mainRegion.exit().transition().duration(duration).style('opacity',0).remove();};c3_chart_internal_fn.redrawRegion=function(withTransition){var$$=this,regions=$$.mainRegion.selectAll('rect').each(function(){// data is binded to g and it's not transferred to rect (child node) automatically,
varparentData=$$.d3.select(this.parentNode).datum();$$.d3.select(this).datum(parentData);}),x=$$.regionX.bind($$),y=$$.regionY.bind($$),w=$$.regionWidth.bind($$),h=$$.regionHeight.bind($$);return[(withTransition?regions.transition():regions).attr('x',x).attr('y',y).attr('width',w).attr('height',h).style('fill-opacity',function(d){returnisValue(d.opacity)?d.opacity:0.1;})];};c3_chart_internal_fn.regionX=function(d){var$$=this,config=$$.config,xPos=void0,yScale=d.axis==='y'?$$.y:$$.y2;if(d.axis==='y'||d.axis==='y2'){xPos=config.axis_rotated?'start'ind?yScale(d.start):0:0;}else{xPos=config.axis_rotated?0:'start'ind?$$.x($$.isTimeSeries()?$$.parseDate(d.start):d.start):0;}returnxPos;};c3_chart_internal_fn.regionY=function(d){var$$=this,config=$$.config,yPos=void0,yScale=d.axis==='y'?$$.y:$$.y2;if(d.axis==='y'||d.axis==='y2'){yPos=config.axis_rotated?0:'end'ind?yScale(d.end):0;}else{yPos=config.axis_rotated?'start'ind?$$.x($$.isTimeSeries()?$$.parseDate(d.start):d.start):0:0;}returnyPos;};c3_chart_internal_fn.regionWidth=function(d){var$$=this,config=$$.config,start=$$.regionX(d),end=void0,yScale=d.axis==='y'?$$.y:$$.y2;if(d.axis==='y'||d.axis==='y2'){end=config.axis_rotated?'end'ind?yScale(d.end):$$.width:$$.width;}else{end=config.axis_rotated?$$.width:'end'ind?$$.x($$.isTimeSeries()?$$.parseDate(d.end):d.end):$$.width;}returnend<start?0:end-start;};c3_chart_internal_fn.regionHeight=function(d){var$$=this,config=$$.config,start=this.regionY(d),end=void0,yScale=d.axis==='y'?$$.y:$$.y2;if(d.axis==='y'||d.axis==='y2'){end=config.axis_rotated?$$.height:'start'ind?yScale(d.start):$$.height;}else{end=config.axis_rotated?'end'ind?$$.x($$.isTimeSeries()?$$.parseDate(d.end):d.end):$$.height:$$.height;}returnend<start?0:end-start;};c3_chart_internal_fn.isRegionOnX=function(d){return!d.axis||d.axis==='x';};c3_chart_internal_fn.drag=function(mouse){var$$=this,config=$$.config,main=$$.main,d3$$1=$$.d3;varsx=void0,sy=void0,mx=void0,my=void0,minX=void0,maxX=void0,minY=void0,maxY=void0;if($$.hasArcType()){return;}if(!config.data_selection_enabled){return;}// do nothing if not selectable
return;}if(isWithin^isIncluded){shape.classed(CLASS.INCLUDED,!isIncluded);// TODO: included/unincluded callback here
shape.classed(CLASS.SELECTED,!isSelected);toggle.call($$,!isSelected,shape,d,i);}});};c3_chart_internal_fn.dragstart=function(mouse){var$$=this,config=$$.config;if($$.hasArcType()){return;}if(!config.data_selection_enabled){return;}// do nothing if not selectable
$$.dragStart=mouse;$$.main.select('.'+CLASS.chart).append('rect').attr('class',CLASS.dragarea).style('opacity',0.1);$$.dragging=true;};c3_chart_internal_fn.dragend=function(){var$$=this,config=$$.config;if($$.hasArcType()){return;}if(!config.data_selection_enabled){return;}// do nothing if not selectable
$$.main.select('.'+CLASS.dragarea).transition().duration(100).style('opacity',0).remove();$$.main.selectAll('.'+CLASS.shape).classed(CLASS.INCLUDED,false);$$.dragging=false;};c3_chart_internal_fn.selectPoint=function(target,d,i){var$$=this,config=$$.config,cx=(config.axis_rotated?$$.circleY:$$.circleX).bind($$),cy=(config.axis_rotated?$$.circleX:$$.circleY).bind($$),r=$$.pointSelectR.bind($$);config.data_onselected.call($$.api,d,target.node());// add selected-circle on low layer g
$$.main.select('.'+CLASS.selectedCircles+$$.getTargetSelectorSuffix(d.id)).selectAll('.'+CLASS.selectedCircle+'-'+i).data([d]).enter().append('circle').attr('class',function(){return$$.generateClass(CLASS.selectedCircle,i);}).attr('cx',cx).attr('cy',cy).attr('stroke',function(){return$$.color(d);}).attr('r',function(d){return$$.pointSelectR(d)*1.4;}).transition().duration(100).attr('r',r);};c3_chart_internal_fn.unselectPoint=function(target,d,i){var$$=this;$$.config.data_onunselected.call($$.api,d,target.node());// remove selected-circle from low layer g
$$.main.select('.'+CLASS.selectedCircles+$$.getTargetSelectorSuffix(d.id)).selectAll('.'+CLASS.selectedCircle+'-'+i).transition().duration(100).attr('r',0).remove();};c3_chart_internal_fn.togglePoint=function(selected,target,d,i){selected?this.selectPoint(target,d,i):this.unselectPoint(target,d,i);};c3_chart_internal_fn.selectPath=function(target,d){var$$=this;$$.config.data_onselected.call($$,d,target.node());if($$.config.interaction_brighten){target.transition().duration(100).style('fill',function(){return$$.d3.rgb($$.color(d)).brighter(0.75);});}};c3_chart_internal_fn.unselectPath=function(target,d){var$$=this;$$.config.data_onunselected.call($$,d,target.node());if($$.config.interaction_brighten){target.transition().duration(100).style('fill',function(){return$$.color(d);});}};c3_chart_internal_fn.togglePath=function(selected,target,d,i){selected?this.selectPath(target,d,i):this.unselectPath(target,d,i);};c3_chart_internal_fn.getToggle=function(that,d){var$$=this,toggle=void0;if(that.nodeName==='circle'){if($$.isStepType(d)){// circle is hidden in step chart, so treat as within the click area
}else{toggle=$$.togglePoint;}}elseif(that.nodeName==='path'){toggle=$$.togglePath;}returntoggle;};c3_chart_internal_fn.toggleShape=function(that,d,i){var$$=this,d3$$1=$$.d3,config=$$.config,shape=d3$$1.select(that),isSelected=shape.classed(CLASS.SELECTED),toggle=$$.getToggle(that,d).bind($$);if(config.data_selection_enabled&&config.data_selection_isselectable(d)){if(!config.data_selection_multiple){$$.main.selectAll('.'+CLASS.shapes+(config.data_selection_grouped?$$.getTargetSelectorSuffix(d.id):'')).selectAll('.'+CLASS.shape).each(function(d,i){varshape=d3$$1.select(this);if(shape.classed(CLASS.SELECTED)){toggle(false,shape.classed(CLASS.SELECTED,false),d,i);}});}shape.classed(CLASS.SELECTED,!isSelected);toggle(!isSelected,shape,d,i);}};c3_chart_internal_fn.initBrush=function(){var$$=this,d3$$1=$$.d3;$$.brush=d3$$1.svg.brush().on('brush',function(){$$.redrawForBrush();});$$.brush.update=function(){if($$.context){$$.context.select('.'+CLASS.brush).call(this);}returnthis;};$$.brush.scale=function(scale){return$$.config.axis_rotated?this.y(scale):this.x(scale);};};c3_chart_internal_fn.initSubchart=function(){var$$=this,config=$$.config,context=$$.context=$$.svg.append('g').attr('transform',$$.getTranslate('context')),visibility=config.subchart_show?'visible':'hidden';context.style('visibility',visibility);// Define g for chart area
context.append('g').attr('clip-path',$$.clipPathForSubchart).attr('class',CLASS.chart);// Define g for bar chart area
context.select('.'+CLASS.chart).append('g').attr('class',CLASS.chartBars);// Define g for line chart area
context.select('.'+CLASS.chart).append('g').attr('class',CLASS.chartLines);// Add extent rect for Brush
context.append('g').attr('clip-path',$$.clipPath).attr('class',CLASS.brush).call($$.brush);// ATTENTION: This must be called AFTER chart added
$$.axes.subx=context.append('g').attr('class',CLASS.axisX).attr('transform',$$.getTranslate('subx')).attr('clip-path',config.axis_rotated?'':$$.clipPathForXAxis).style('visibility',config.subchart_axis_x_show?visibility:'hidden');};c3_chart_internal_fn.updateTargetsForSubchart=function(targets){var$$=this,context=$$.context,config=$$.config,contextLineEnter=void0,contextLineUpdate=void0,contextBarEnter=void0,contextBarUpdate=void0,classChartBar=$$.classChartBar.bind($$),classBars=$$.classBars.bind($$),classChartLine=$$.classChartLine.bind($$),classLines=$$.classLines.bind($$),classAreas=$$.classAreas.bind($$);if(config.subchart_show){// -- Bar --//
contextBarUpdate=context.select('.'+CLASS.chartBars).selectAll('.'+CLASS.chartBar).data(targets).attr('class',classChartBar);contextBarEnter=contextBarUpdate.enter().append('g').style('opacity',0).attr('class',classChartBar);// Bars for each data
contextLineUpdate=context.select('.'+CLASS.chartLines).selectAll('.'+CLASS.chartLine).data(targets).attr('class',classChartLine);contextLineEnter=contextLineUpdate.enter().append('g').style('opacity',0).attr('class',classChartLine);// Lines for each data
drawAreaOnSub=$$.generateDrawArea(areaIndices,true);drawBarOnSub=$$.generateDrawBar(barIndices,true);drawLineOnSub=$$.generateDrawLine(lineIndices,true);$$.updateBarForSubchart(duration);$$.updateLineForSubchart(duration);$$.updateAreaForSubchart(duration);$$.redrawBarForSubchart(drawBarOnSub,duration,duration);$$.redrawLineForSubchart(drawLineOnSub,duration,duration);$$.redrawAreaForSubchart(drawAreaOnSub,duration,duration);}}};c3_chart_internal_fn.redrawForBrush=function(){var$$=this,x=$$.x;$$.redraw({withTransition:false,withY:$$.config.zoom_rescale,withSubchart:false,withUpdateXDomain:true,withDimension:false});$$.config.subchart_onbrush.call($$.api,x.orgDomain());};c3_chart_internal_fn.transformContext=function(withTransition,transitions){var$$=this,subXAxis=void0;if(transitions&&transitions.axisSubX){subXAxis=transitions.axisSubX;}else{subXAxis=$$.context.select('.'+CLASS.axisX);if(withTransition){subXAxis=subXAxis.transition();}}$$.context.attr('transform',$$.getTranslate('context'));subXAxis.attr('transform',$$.getTranslate('subx'));};c3_chart_internal_fn.getDefaultExtent=function(){var$$=this,config=$$.config,extent=isFunction(config.axis_x_extent)?config.axis_x_extent($$.getXDomain($$.data.targets)):config.axis_x_extent;if($$.isTimeSeries()){extent=[$$.parseDate(extent[0]),$$.parseDate(extent[1])];}returnextent;};c3_chart_internal_fn.initZoom=function(){var$$=this,d3$$1=$$.d3,config=$$.config,startEvent=void0;$$.zoom=d3$$1.behavior.zoom().on('zoomstart',function(){startEvent=d3$$1.event.sourceEvent;$$.zoom.altDomain=d3$$1.event.sourceEvent.altKey?$$.x.orgDomain():null;config.zoom_onzoomstart.call($$.api,d3$$1.event.sourceEvent);}).on('zoom',function(){$$.redrawForZoom.call($$);}).on('zoomend',function(){varevent=d3$$1.event.sourceEvent;// if click, do nothing. otherwise, click interaction will be canceled.
if(event&&startEvent.clientX===event.clientX&&startEvent.clientY===event.clientY){return;}$$.redrawEventRect();$$.updateZoom();config.zoom_onzoomend.call($$.api,$$.x.orgDomain());});$$.zoom.scale=function(scale){returnconfig.axis_rotated?this.y(scale):this.x(scale);};$$.zoom.orgScaleExtent=function(){varextent=config.zoom_extent?config.zoom_extent:[1,10];return[extent[0],Math.max($$.getMaxDataCount()/extent[1],extent[1])];};$$.zoom.updateScaleExtent=function(){varratio=diffDomain($$.x.orgDomain())/diffDomain($$.getZoomDomain()),extent=this.orgScaleExtent();this.scaleExtent([extent[0]*ratio,extent[1]*ratio]);returnthis;};};c3_chart_internal_fn.getZoomDomain=function(){var$$=this,config=$$.config,d3$$1=$$.d3,min=d3$$1.min([$$.orgXDomain[0],config.zoom_x_min]),max=d3$$1.max([$$.orgXDomain[1],config.zoom_x_max]);return[min,max];};c3_chart_internal_fn.updateZoom=function(){var$$=this,z=$$.config.zoom_enabled?$$.zoom:function(){};$$.main.select('.'+CLASS.zoomRect).call(z).on('dblclick.zoom',null);$$.main.selectAll('.'+CLASS.eventRect).call(z).on('dblclick.zoom',null);};c3_chart_internal_fn.redrawForZoom=function(){var$$=this,d3$$1=$$.d3,config=$$.config,zoom=$$.zoom,x=$$.x;if(!config.zoom_enabled){return;}if($$.filterTargetsToShow($$.data.targets).length===0){return;}if(d3$$1.event.sourceEvent.type==='mousemove'&&zoom.altDomain){x.domain(zoom.altDomain);zoom.scale(x).updateScaleExtent();return;}if($$.isCategorized()&&x.orgDomain()[0]===$$.orgXDomain[0]){x.domain([$$.orgXDomain[0]-1e-10,x.orgDomain()[1]]);}$$.redraw({withTransition:false,withY:config.zoom_rescale,withSubchart:false,withEventRect:false,withDimension:false});if(d3$$1.event.sourceEvent.type==='mousemove'){$$.cancelClick=true;}config.zoom_onzoom.call($$.api,x.orgDomain());};c3_chart_internal_fn.generateColor=function(){var$$=this,config=$$.config,d3$$1=$$.d3,colors=config.data_colors,pattern=notEmpty(config.color_pattern)?config.color_pattern:d3$$1.scale.category10().range(),callback=config.data_color,ids=[];returnfunction(d){varid=d.id||d.data&&d.data.id||d,color=void0;// if callback function is provided
else{if(ids.indexOf(id)<0){ids.push(id);}color=pattern[ids.indexOf(id)%pattern.length];colors[id]=color;}returncallbackinstanceofFunction?callback(color,d):color;};};c3_chart_internal_fn.generateLevelColor=function(){var$$=this,config=$$.config,colors=config.color_pattern,threshold=config.color_threshold,asValue=threshold.unit==='value',values=threshold.values&&threshold.values.length?threshold.values:[],max=threshold.max||100;returnnotEmpty(config.color_threshold)?function(value){vari=void0,v=void0,color=colors[colors.length-1];for(i=0;i<values.length;i++){v=asValue?value:value*100/max;if(v<values[i]){color=colors[i];break;}}returncolor;}:null;};c3_chart_internal_fn.getYFormat=function(forArc){var$$=this,formatForY=forArc&&!$$.hasType('gauge')?$$.defaultArcValueFormat:$$.yFormat,formatForY2=forArc&&!$$.hasType('gauge')?$$.defaultArcValueFormat:$$.y2Format;returnfunction(v,ratio,id){varformat=$$.axis.getId(id)==='y2'?formatForY2:formatForY;returnformat.call($$,v,ratio);};};c3_chart_internal_fn.yFormat=function(v){var$$=this,config=$$.config,format=config.axis_y_tick_format?config.axis_y_tick_format:$$.defaultValueFormat;returnformat(v);};c3_chart_internal_fn.y2Format=function(v){var$$=this,config=$$.config,format=config.axis_y2_tick_format?config.axis_y2_tick_format:$$.defaultValueFormat;returnformat(v);};c3_chart_internal_fn.defaultValueFormat=function(v){returnisValue(v)?+v:'';};c3_chart_internal_fn.defaultArcValueFormat=function(v,ratio){return(ratio*100).toFixed(1)+'%';};c3_chart_internal_fn.dataLabelFormat=function(targetId){var$$=this,data_labels=$$.config.data_labels,format=void0,defaultFormat=functiondefaultFormat(v){returnisValue(v)?+v:'';};// find format according to axis id
$$.updateAndRedraw(options);};c3_chart_internal_fn.generateFlow=function(args){var$$=this,config=$$.config,d3$$1=$$.d3;returnfunction(){vartargets=args.targets,flow=args.flow,drawBar=args.drawBar,drawLine=args.drawLine,drawArea=args.drawArea,cx=args.cx,cy=args.cy,xv=args.xv,xForText=args.xForText,yForText=args.yForText,duration=args.duration;vartranslateX=void0,scaleX=1,transform=void0,flowIndex=flow.index,flowLength=flow.length,flowStart=$$.getValueOnIndex($$.data.targets[0].values,flowIndex),flowEnd=$$.getValueOnIndex($$.data.targets[0].values,flowIndex+flowLength),orgDomain=$$.x.domain(),domain=void0,durationForFlow=flow.duration||duration,done=flow.done||function(){},wait=$$.generateWait();varxgrid=$$.xgrid||d3$$1.selectAll([]),xgridLines=$$.xgridLines||d3$$1.selectAll([]),mainRegion=$$.mainRegion||d3$$1.selectAll([]),mainText=$$.mainText||d3$$1.selectAll([]),mainBar=$$.mainBar||d3$$1.selectAll([]),mainLine=$$.mainLine||d3$$1.selectAll([]),mainArea=$$.mainArea||d3$$1.selectAll([]),mainCircle=$$.mainCircle||d3$$1.selectAll([]);// set flag
if($$.data.targets[0].values.length!==1){translateX=$$.x(orgDomain[0])-$$.x(domain[0]);}else{if($$.isTimeSeries()){flowStart=$$.getValueOnIndex($$.data.targets[0].values,0);flowEnd=$$.getValueOnIndex($$.data.targets[0].values,$$.data.targets[0].values.length-1);translateX=$$.x(flowStart.x)-$$.x(flowEnd.x);}else{translateX=diffDomain(domain)/2;}}}elseif(flow.orgDataCount===1||(flowStart&&flowStart.x)===(flowEnd&&flowEnd.x)){translateX=$$.x(orgDomain[0])-$$.x(domain[0]);}else{if($$.isTimeSeries()){translateX=$$.x(orgDomain[0])-$$.x(domain[0]);}else{translateX=$$.x(flowStart.x)-$$.x(flowEnd.x);}}scaleX=diffDomain(orgDomain)/diffDomain(domain);transform='translate('+translateX+',0) scale('+scaleX+',1)';$$.hideXGridFocus();d3$$1.transition().ease('linear').duration(durationForFlow).each(function(){wait.add($$.axes.x.transition().call($$.xAxis));wait.add(mainBar.transition().attr('transform',transform));wait.add(mainLine.transition().attr('transform',transform));wait.add(mainArea.transition().attr('transform',transform));wait.add(mainCircle.transition().attr('transform',transform));wait.add(mainText.transition().attr('transform',transform));wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform',transform));wait.add(xgrid.transition().attr('transform',transform));wait.add(xgridLines.transition().attr('transform',transform));}).call(wait,function(){vari=void0,shapes=[],texts=[],eventRects=[];// remove flowed elements
if(flowLength){for(i=0;i<flowLength;i++){shapes.push('.'+CLASS.shape+'-'+(flowIndex+i));texts.push('.'+CLASS.text+'-'+(flowIndex+i));eventRects.push('.'+CLASS.eventRect+'-'+(flowIndex+i));}$$.svg.selectAll('.'+CLASS.shapes).selectAll(shapes).remove();$$.svg.selectAll('.'+CLASS.texts).selectAll(texts).remove();$$.svg.selectAll('.'+CLASS.eventRects).selectAll(eventRects).remove();$$.svg.select('.'+CLASS.xgrid).remove();}// draw again for removing flowed elements and reverting attr
xgrid.attr('transform',null).attr($$.xgridAttr);xgridLines.attr('transform',null);xgridLines.select('line').attr('x1',config.axis_rotated?0:xv).attr('x2',config.axis_rotated?$$.width:xv);xgridLines.select('text').attr('x',config.axis_rotated?$$.width:0).attr('y',xv);mainBar.attr('transform',null).attr('d',drawBar);mainLine.attr('transform',null).attr('d',drawLine);mainArea.attr('transform',null).attr('d',drawArea);mainCircle.attr('transform',null).attr('cx',cx).attr('cy',cy);mainText.attr('transform',null).attr('x',xForText).attr('y',yForText).style('fill-opacity',$$.opacityForText.bind($$));mainRegion.attr('transform',null);mainRegion.select('rect').filter($$.isRegionOnX).attr('x',$$.regionX.bind($$)).attr('width',$$.regionWidth.bind($$));if(config.interaction_enabled){$$.redrawEventRect();}// callback for end of flow