-
Notifications
You must be signed in to change notification settings - Fork 58
/
visavail.min.js
1 lines (1 loc) · 35.9 KB
/
visavail.min.js
1
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.visavail=factory()}(this,(function(){"use strict";var visavail={};function visavailChart(custom_options,dataset){var d3=window.d3?window.d3:"undefined"!=typeof require?require("d3"):void 0,moment=window.moment?window.moment:"undefined"!=typeof require?require("moment"):void 0,t0;if(!d3)throw new Error("Require D3.js before visavail script");if(!moment)throw new Error("Require moment before visavail script");var options={id:"",id_div_container:"visavail_container",id_div_graph:"example",margin:{top:65,right:60,bottom:20,left:100},width:960,moment_locale:window.navigator.userLanguage||window.navigator.language,reduce_space_wrap:35,line_spacing:35,padding:{top:-49,bottom:0,right:60,left:-100},emphasize_year_ticks:!0,emphasize_month_ticks:!0,ticks_for_graph:6,max_display_datasets:0,cur_display_first_dataset:0,display_date_range:["",""],custom_categories:!1,is_date_only_format:!0,date_in_utc:!1,date_is_descending:!1,show_y_title:!0,y_title_some_unavailability_class:"some_unavailability",y_title_total_unavailability_class:"total_unavailability",y_title_total_availability_class:"total_availability",y_percentage:{enabled:!1,some_unavailability_class:"some_unavailability",total_unavailability_class:"total_unavailability",total_availability_class:"total_availability",percentageFormat:d3.format(".2%"),unavailability_percentage:!1,custom_percentage:!1},defined_blocks:!1,y_title_tooltip:{enabled:!1,class:"y-tooltip",type:"right",spacing:{left:15,right:15,top:15,bottom:10},fixed:!1,duration:150},tooltip:{class:"tooltip",height:11,position:"top",left_spacing:0,date_plus_time:!1,only_first_date:!1,duration:150,hover_zoom:{enabled:!1,ratio:.4}},legend:{enabled:!0,line_space:12,offset:5,x_right_offset:150,has_no_data_text:"No Data available",has_data_text:"Data available"},title:{enabled:!0,text:"Data Availability Plot",line_spacing:16},sub_title:{enabled:!0,from_text:"from",to_text:"to",line_spacing:16},sub_chart:{enabled:!1,height:0,animation:!0,margin:{top:20,bottom:0},graph:{enabled:!0,width:7,height:7,line_spacing:7}},icon:{class_has_data:"fas fa-fw fa-check",class_has_no_data:"fas fa-fw fa-times"},zoom:{enabled:!1,onZoom:function onZoom(){},onZoomStart:function onZoomStart(){},onZoomEnd:function onZoomEnd(){}},onClickBlock:function onclickblock(){},graph:{type:"bar",width:18,height:18,hover_zoom:5},responsive:{enabled:!1,onresize:function onresize(){}},custom_time_format:{format_millisecond:".%L",format_second:":%S",format_minute:"%H:%M",format_hour:"%H",format_day:"%a %d",format_week:"%b %d",format_month:"%B",format_year:"%Y"}};function convertMomentToStrftime(momentFormat){var replacements={ddd:"a",dddd:"A",MMM:"b",MMMM:"B",lll:"c",DD:"d",D:"e","YYYY-MM-DD":"F",HH:"H",H:"H",hh:"I",h:"I",DDDD:"j",DDD:"-j",MM:"m",M:"-m",mm:"M",m:"-M",A:"p",a:"P",ss:"S",s:"-S",E:"u",d:"w",WW:"W",ll:"x",LTS:"X",YY:"y",YYYY:"Y",ZZ:"z",z:"Z",SSS:"L","%":"%"},tokens,strftime;return momentFormat.split(/( |\/|:|,|\]|\[|\.)/).map((function(token){return":"==token[0]||"/"==token[0]||" "==token[0]||","==token[0]?token:"["!=token[0]&&"]"!=token[0]?replacements.hasOwnProperty(token)?"%"+replacements[token]:token.length>0?"["+token+"]":token:void 0})).join("")}function periodInLocal(){return date_format_local.LTS.indexOf("a")>-1||date_format_local.LTS.indexOf("A")>-1}function loadConfig(default_option,custom_options){Object.keys(custom_options).forEach((function(key){key in default_option&&("object"==typeof default_option[key]?loadConfig(default_option[key],custom_options[key]):typeof custom_options[key]==typeof default_option[key]&&(default_option[key]=custom_options[key]))}))}loadConfig(options,custom_options),moment.locale(options.moment_locale);var date_format_local=moment().creationData().locale._longDateFormat;function multiFormat(date){return(d3.timeSecond(date)<date?d3.timeFormat(options.custom_time_format.format_millisecond):d3.timeMinute(date)<date?d3.timeFormat(options.custom_time_format.format_second):d3.timeHour(date)<date?d3.timeFormat(options.custom_time_format.format_minute):d3.timeDay(date)<date?d3.timeFormat(options.custom_time_format.format_hour):d3.timeMonth(date)<date?d3.timeWeek(date)<date?d3.timeFormat(options.custom_time_format.format_day):d3.timeFormat(options.custom_time_format.format_week):d3.timeYear(date)<date?d3.timeFormat(options.custom_time_format.format_month):d3.timeFormat(options.custom_time_format.format_year))(date)}function chart(selection){selection.each((function drawGraph(dataset){d3.timeFormatDefaultLocale(options.locale);var div=d3.select("#"+options.id_div_container).append("div").attr("class","visavail-tooltip "+options.id).attr("id",options.id).append("div").attr("class",options.tooltip.class+"-"+options.tooltip.position).style("opacity",0),yTitlediv=d3.select("#"+options.id_div_container).append("div").attr("class","visavail-ytitle-tooltip "+options.id).attr("id",options.id).append("div").attr("class",options.y_title_tooltip.class).style("opacity",0),width=options.width-options.margin.left-options.margin.right;options.oldwidth||(options.oldwidth=width);var maxPages=0,startSet,endSet;0!==options.max_display_datasets?(startSet=options.cur_display_first_dataset,endSet=options.cur_display_first_dataset+options.max_display_datasets>dataset.length?dataset.length:options.cur_display_first_dataset+options.max_display_datasets,maxPages=Math.ceil(dataset.length/options.max_display_datasets)):(startSet=0,endSet=dataset.length),selection.attr("data-max-pages",maxPages);for(var noOfDatasets=endSet-startSet,height=options.graph.height*noOfDatasets+options.line_spacing*noOfDatasets-1,i=0;i<dataset.length;i++)if(dataset[i].description&&(options.tooltip.description=!0),null!=dataset[i].data[0]&&3==dataset[i].data[0].length){options.defined_blocks=!0,options.custom_categories||Number.isInteger(dataset[i].data[0][1])||(options.custom_categories=!0);break}var format=d3.timeParse("%Y-%m-%d"),format_utc_time=d3.utcParse("%Y-%m-%d %H:%M:%S"),format_utc=d3.utcParse("%Y-%m-%d");if(options.date_in_utc)var parseDate=function(date){return format_utc(date)},parseDateTime=function(date){return format_utc_time(date)};else var parseDate=function(date){return format(date)},parseDateTime=function(date){return new Date(date)};var parseDateRegEx=new RegExp(/^\d{4}-\d{2}-\d{2}$/),parseDateTimeRegEx=new RegExp(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/),t0=performance.now();dataset.forEach((function(d){d.data.forEach((function(d1){if(!(d1[0]instanceof Date))if(parseDateTimeRegEx.test(d1[0]))d1[0]=parseDateTime(d1[0]),options.is_date_only_format=!1;else{if(!parseDateRegEx.test(d1[0]))throw new Error("Date/time format not recognized. Pick between 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'.");d1[0]=parseDate(d1[0])}if(!(d1[2]instanceof Date))if(options.defined_blocks){if(!d1[2])throw new Error("Defined block true but dataset not correct");parseDateTimeRegEx.test(d1[2])?d1[2]=parseDateTime(d1[2]):parseDateRegEx.test(d1[2])?d1[2]=parseDate(d1[2]):(d1[2]=d1[0],"rhombus"!=options.graph.type&&console.error("Date/time format not recognized. Pick between 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'."))}else d1[2]=d3.timeSecond.offset(d1[0],d.interval_s)}))}));var startDate=moment().year(2999).toDate(),endDate=moment().year(0).toDate();if(dataset.forEach((function(series,seriesI){var tmpData=[],dataLength=series.data.length;series.data.forEach((function(d,i){d[2]>=endDate&&(endDate=d[2]),d[0]<=startDate&&(startDate=d[0]),0!==i&&i<dataLength?d[1]===tmpData[tmpData.length-1][1]?options.defined_blocks?tmpData[tmpData.length-1][2].getTime()===d[0].getTime()?(tmpData[tmpData.length-1][2]=d[2],tmpData[tmpData.length-1][3]=d[1]):tmpData.push(d):(tmpData[tmpData.length-1][2]=d[2],tmpData[tmpData.length-1][3]=d[1]):(options.defined_blocks||(tmpData[tmpData.length-1][2]=d[0]),tmpData.push(d)):0===i&&(d.length<3&&(d[2]=d[0]),tmpData.push(d))})),dataset[seriesI].disp_data=tmpData})),options.display_date_range&&(options.display_date_range[0]||options.display_date_range[1])){if(options.display_date_range[0])if(options.display_date_range[0]instanceof Date)startDate=options.date_in_utc?moment.utc(options.display_date_range[0]).toDate():options.display_date_range[0];else{if(parseDateRegEx.test(options.display_date_range[0]))options.display_date_range[0]=parseDate(options.display_date_range[0]);else{if(!parseDateTimeRegEx.test(options.display_date_range[0]))throw new Error("Option of Display range Date/time format not recognized. Pick between 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'.");options.display_date_range[0]=parseDateTime(options.display_date_range[0])}startDate=options.display_date_range[0]}if(options.display_date_range[1])if(options.display_date_range[1]instanceof Date)endDate=options.date_in_utc?moment.utc(options.display_date_range[1]).toDate():options.display_date_range[1];else{if(parseDateRegEx.test(options.display_date_range[1]))options.display_date_range[1]=parseDate(options.display_date_range[1]);else{if(!parseDateTimeRegEx.test(options.display_date_range[1]))throw new Error("Option of Display range Date/time format not recognized. Pick between 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'.");options.display_date_range[1]=parseDateTime(options.display_date_range[1])}endDate=options.display_date_range[1]}}options.y_percentage.enabled&&!options.y_percentage.custom_percentage&&dataset.forEach((function(series,seriesI){dataset[seriesI].timeup_ms=0,dataset[seriesI].timedown_ms=0,options.custom_categories?series.disp_data.forEach((function(disp){disp[1]===series.category_percentage?dataset[seriesI].timeup_ms+=disp[2].getTime()-disp[0].getTime():dataset[seriesI].timedown_ms+=disp[2].getTime()-disp[0].getTime()})):series.disp_data.forEach((function(disp){disp[1]?dataset[seriesI].timeup_ms+=disp[2].getTime()-disp[0].getTime():dataset[seriesI].timedown_ms+=disp[2].getTime()-disp[0].getTime()}))}));var xScale=d3.scaleTime().domain([startDate,endDate]).range([0,width]),xScale2=d3.scaleTime().domain([startDate,endDate]).range([0,width]);options.date_is_descending&&(xScale.domain([endDate,startDate]),xScale2.domain([endDate,startDate])),options.xScale=xScale;var xAxis=d3.axisTop(options.xScale).scale(options.xScale).ticks(options.ticks_for_graph).tickFormat(multiFormat),subChartXAxis=d3.axisBottom(xScale2).scale(xScale2).ticks(options.ticks_for_graph).tickFormat(multiFormat),svg=d3.select(this).append("svg").attr("width",width+options.margin.left+options.margin.right).attr("height",height+options.margin.top+options.margin.bottom+options.sub_chart.height+options.sub_chart.margin.top+options.sub_chart.margin.bottom).append("g").attr("transform","translate("+options.margin.left+","+options.margin.top+")");function wrap(){for(var self=d3.select(this),textLength=self.node().getComputedTextLength(),text=self.text();textLength>-1*options.padding.left+options.reduce_space_wrap&&text.length>0;)text=text.slice(0,-1),self.text(text+"..."),textLength=self.node().getComputedTextLength()}if(svg.append("g").attr("id","g_axis"),svg.append("g").attr("id","g_data").append("rect").attr("id","zoom").attr("width",width).attr("height",height).attr("fill-opacity",0).attr("x",0).attr("y",0),svg.append("g").attr("id","g_axis_text"),svg.append("g").attr("id","g_title"),options.zoomed=d3.zoom().scaleExtent([1,1/0]).translateExtent([[0,0],[width,options.height]]).extent([[0,0],[width,options.height]]).on("start",(function(){var e=d3.event;e.sourceEvent&&"brush"===e.sourceEvent.type||(e.sourceEvent&&"touchstart"===e.sourceEvent.type&&e.sourceEvent.cancelable&&(event.preventDefault(),event.stopImmediatePropagation()),(e.transform.k||e.transform.x)&&(start_event=e,options.zoom.onZoomStart.call(this,e)))})).on("zoom",zoomed).on("end",(function(){var e=d3.event;null!=e&&(e.sourceEvent&&"brush"===e.sourceEvent.type||(e.sourceEvent&&"touchend"===e.sourceEvent.type&&e.sourceEvent.cancelable&&(event.preventDefault(),event.stopImmediatePropagation()),e.transform.k||e.transform.x?(options.scale=d3.zoomTransform(svg.select("#g_data").node()),options.zoom.onZoomEnd.call(this,options.xScale.domain())):(e.transform.k=start_event.transform.k,e.transform.x=start_event.transform.x,options.scale=d3.zoomIdentity.translate(e.transform.x,e.transform.y).scale(e.transform.k),options.zoom.onZoomEnd.call(this,options.xScale.domain()))))})),options.zoom.enabled&&svg.select("#g_data").call(options.zoomed).attr("cursor","ew-resize"),options.show_y_title){var y_axis_title=svg.select("#g_axis_text").append("g").attr("id","yAxis");if(y_axis_title.selectAll("text").data(dataset.slice(startSet,endSet)).enter().append("g").attr("id",(function(d,i){return i})),y_axis_title.selectAll("g").append("text").attr("x",options.padding.left).attr("y",(function(d,i){return(options.line_spacing+options.graph.height)*i+options.line_spacing+options.graph.height/2})).attr("dy","0.5ex").text((function(d){return d.measure||d.measure_html})).each(wrap).attr("class",(function(d){var returnCSSClass="ytitle";return null!=d.measure_url&&(returnCSSClass+=" link"),options.y_percentage.enabled&&!options.y_percentage.custom_percentage&&(0==d.timedown_ms?returnCSSClass+=" "+options.y_title_total_availability_class:0==d.timeup_ms?returnCSSClass+=" "+options.y_title_total_unavailability_class:returnCSSClass+=" "+options.y_title_some_unavailability_class),returnCSSClass})).on("click",(function(d){return null!=d.measure_url?window.open(d.measure_url):null})),y_axis_title.selectAll("g").append("circle").attr("class",(function(d){return"ytitle_icon_background "+((d.icon||"").background_class||"")})).attr("cx",(function(d){return d.icon&&d.icon.width?options.padding.left-d.icon.width/2-((d.icon.padding||0).right||0)-(d.icon.padding_right||0):0})).attr("cy",(function(d,i){return d.icon&&d.icon.height?(options.line_spacing+options.graph.height)*i+options.line_spacing+options.graph.height/2:0})).attr("r",(function(d){return d.icon&&d.icon.width?d.icon.width/2:0})),y_axis_title.selectAll("g").append("image").attr("class",(function(d){return"ytitle_icon_image "+((d.icon||"").image_class||"")})).attr("xlink:href",(function(d){return d.icon&&d.icon.url?d.icon.url:""})).attr("x",(function(d){return d.icon&&d.icon.width?options.padding.left-d.icon.width-((d.icon.padding||0).right||0)-(d.icon.padding_right||0):0})).attr("y",(function(d,i){return d.icon&&d.icon.height?(options.line_spacing+options.graph.height)*i-d.icon.height/2+options.line_spacing+options.graph.height/2:0})).attr("width",(function(d){return d.icon&&d.icon.width?d.icon.width:0})).attr("height",(function(d){return d.icon&&d.icon.height?d.icon.height:0})),options.y_title_tooltip.enabled){function drawTitleTooltipWhenOver(obj,dataset,d,i){if(options.y_title_tooltip.enabled){var matrix=obj.getCTM().translate(obj.getAttribute("x"),obj.getAttribute("y"));yTitlediv.transition().duration(options.y_title_tooltip.duration).style("opacity",1),yTitlediv.html((function(){var output;return d.measure_description||""})),"right"==options.y_title_tooltip.type&&yTitlediv.style("left",(function(){return options.y_title_tooltip.fixed?-1*options.padding.left+"px":options.y_title_tooltip.spacing.right+d3.select(obj).node().getComputedTextLength()+"px"})).classed(options.y_title_tooltip.type,!0).style("top",matrix.f-(document.getElementsByClassName(options.y_title_tooltip.class)[0].offsetHeight+(options.line_spacing+options.graph.height)*i)/2+"px"),"top"==options.y_title_tooltip.type&&yTitlediv.style("left","0px").style("top",matrix.f-(document.getElementsByClassName(options.y_title_tooltip.class)[0].offsetHeight+options.y_title_tooltip.spacing.top)+"px").classed(options.y_title_tooltip.type,!0),"bottom"==options.y_title_tooltip.type&&yTitlediv.style("left","0px").style("top",matrix.f+options.y_title_tooltip.spacing.bottom+"px").classed(options.y_title_tooltip.type,!0)}}function hideTitleTooltipWhenOver(){yTitlediv.transition().duration(options.y_title_tooltip.duration).style("opacity",0)}y_axis_title.selectAll("g").selectAll("text").on("mouseover",(function(d,i){drawTitleTooltipWhenOver(this,dataset,d,i)})).on("touchstart",(function(d,i){drawTitleTooltipWhenOver(this,d,i)})).on("mouseout",(function(){hideTitleTooltipWhenOver()})).on("touchleave",(function(){hideTitleTooltipWhenOver()})).on("touchcancel",(function(){hideTitleTooltipWhenOver()}))}else y_axis_title.selectAll("g").append("title").text((function(d){return d.measure_description||d.measure}))}if(options.y_percentage.enabled){var y_percentage_title=svg.select("#g_axis_text").append("g").attr("id","yPercentage");y_percentage_title.selectAll("text").data(dataset.slice(startSet,endSet)).enter().append("g").attr("id",(function(d,i){return i})),y_percentage_title.selectAll("g").append("text").attr("x",width).attr("dx",options.padding.right).attr("y",(function(d,i){return(options.line_spacing+options.graph.height)*i+options.line_spacing+options.graph.height/2})).attr("dy","0.5ex").attr("text-anchor","end").text((function(d){return!options.custom_categories&&options.y_percentage.unavailability_percentage?options.y_percentage.percentageFormat(d.timedown_ms/(d.timedown_ms+d.timeup_ms)):options.y_percentage.custom_percentage?(d.percentage||"").measure||"":options.y_percentage.percentageFormat(d.timeup_ms/(d.timeup_ms+d.timedown_ms))})).each(wrap).attr("class",(function(d){var returnCSSClass="ypercentage";return options.y_percentage.custom_percentage?options.y_percentage.custom_percentage&&(returnCSSClass+=" "+(d.percentage||"").class||""):0==d.timedown_ms?returnCSSClass+=" "+options.y_percentage.total_availability_class:0==d.timeup_ms?returnCSSClass+=" "+options.y_percentage.total_unavailability_class:returnCSSClass+=" "+options.y_percentage.some_unavailability_class,returnCSSClass}))}function createVGrid(scale){svg.select("#vGrid").selectAll("line.vert_grid").data(scale.ticks(options.ticks_for_graph)).enter().append("line").attr("x1",(function(d){return scale(d)})).attr("x2",(function(d){return scale(d)})).attr("y1",0).attr("y2",options.graph.height*noOfDatasets+options.line_spacing*noOfDatasets-1+options.margin.bottom).attr("class","vert_grid")}svg.select("#g_axis").append("g").attr("id","vGrid"),noOfDatasets&&createVGrid(options.xScale),svg.select("#g_axis").append("g").attr("id","hGrid").selectAll("line.horz_grid").data(dataset).enter().append("line").attr("x1",0).attr("x2",width).attr("y1",(function(d,i){return(options.line_spacing+options.graph.height)*i+options.line_spacing+options.graph.height/2})).attr("y2",(function(d,i){return(options.line_spacing+options.graph.height)*i+options.line_spacing+options.graph.height/2})).attr("class","horz_grid"),noOfDatasets&&svg.select("#g_axis").append("g").attr("class","xAxis").call(xAxis);var g=svg.select("#g_data").selectAll(".g_data").data(dataset.slice(startSet,endSet)).enter().append("g").attr("transform",(function(d,i){return"translate(0,"+(options.line_spacing+options.graph.height)*i+")"})).attr("cursor","pointer").attr("class","dataset");function redrawTooltipWhenMoved(pageX,pageY,obj){div.style("left",(function(){return options.width<pageX+div.property("offsetWidth")+options.tooltip.left_spacing?pageX-div.property("offsetWidth")-options.tooltip.left_spacing+"px":pageX+options.tooltip.left_spacing+"px"})),"top"===options.tooltip.position&&(options.width<pageX+div.property("offsetWidth")+options.tooltip.left_spacing?div.style("border-right","solid thin rgb(0, 0, 0)").style("border-left","none"):div.style("border-left","solid thin rgb(0, 0, 0)").style("border-right","none")),"overlay"===options.tooltip.position&&(document.getElementById(options.id_div_graph).offsetHeight<pageY+div.property("offsetHeight")?div.style("top",document.getElementById(options.id_div_graph).offsetHeight-div.property("offsetHeight")+"px"):div.style("top",pageY+"px"))}function redrawTooltipWhenOut(obj){options.tooltip.hover_zoom.enabled&&d3.select(obj).transition().duration(options.tooltip.duration).attr("x",(function(d){return xForPoint(d,options.graph.width,options.xScale,0)})).attr("width",(function(d){return widthForPoint(d,options.graph.width,options.xScale,0)})).attr("y",options.line_spacing).attr("height",options.graph.height).attr("transform",(function(d){return transformForTypeOfGraph(d,options.xScale,options.graph.height,options.line_spacing,0)})),div.transition().duration(options.tooltip.duration).style("opacity",0)}function redrawTooltipWhenOver(obj,dataset,pageX,pageY,d,i){options.tooltip.hover_zoom.enabled&&d3.select(obj).transition().duration(options.tooltip.duration).attr("x",(function(d){return"rhombus"==options.graph.type||"circle"==options.graph.type?xForPoint(d,options.graph.width,options.xScale,options.line_spacing*options.tooltip.hover_zoom.ratio*2):xForPoint(d,options.graph.width,options.xScale,0)})).attr("width",(function(d){return"rhombus"==options.graph.type||"circle"==options.graph.type?widthForPoint(d,options.graph.width,options.xScale,options.line_spacing*options.tooltip.hover_zoom.ratio):widthForPoint(d,options.graph.width,options.xScale,0)})).attr("y",options.line_spacing-options.line_spacing*options.tooltip.hover_zoom.ratio/2).attr("height",options.graph.height+options.line_spacing*options.tooltip.hover_zoom.ratio).attr("transform",(function(d){return transformForTypeOfGraph(d,options.xScale,options.graph.height,options.line_spacing,options.line_spacing*options.tooltip.hover_zoom.ratio)}));var matrix=obj.getCTM().translate(obj.getAttribute("x"),obj.getAttribute("y"));div.transition().duration(options.tooltip.duration).style("opacity",1),div.html((function(){var output="",series,series;options.custom_categories?output=(series=dataset.filter((function(series){return series.disp_data.indexOf(d)>=0}))[0])&&series.categories[d[1]].tooltip_html?series.categories[d[1]].tooltip_html:" "+d[1]+" ":output=1===d[1]?'<i class=" '+options.icon.class_has_data+' tooltip_has_data"></i>':'<i class=" '+options.icon.class_has_no_data+' tooltip_has_no_data"></i>';options.tooltip.description&&((series=dataset.filter((function(series){return series.disp_data.indexOf(d)>=0}))[0])&&series.description&&series.description[i]&&(output+=" "+series.description[i]+" "));return options.is_date_only_format&&!options.tooltip.date_plus_time?d[2]>d3.timeSecond.offset(d[0],86400)&&!options.tooltip.only_first_date?options.date_is_descending?output+moment(d[2]).format("l")+" - "+moment(d[0]).format("l"):output+moment(d[0]).format("l")+" - "+moment(d[2]).format("l"):options.date_is_descending?output+moment(d[2]).format("l"):output+moment(d[0]).format("l"):options.tooltip.only_first_date?d[2]>d3.timeSecond.offset(d[0],86400)||options.tooltip.date_plus_time?options.date_is_descending?output+moment(d[2]).format("l")+" "+moment(d[2]).format("LTS"):output+moment(d[0]).format("l")+" "+moment(d[0]).format("LTS"):options.date_is_descending?output+moment(d[2]).format("LTS"):output+moment(d[0]).format("LTS"):d[2]>d3.timeSecond.offset(d[0],86400)||options.tooltip.date_plus_time?options.date_is_descending?output+moment(d[2]).format("l")+" "+moment(d[2]).format("LTS")+" - "+moment(d[0]).format("l")+" "+moment(d[0]).format("LTS"):output+moment(d[0]).format("l")+" "+moment(d[0]).format("LTS")+" - "+moment(d[2]).format("l")+" "+moment(d[2]).format("LTS"):options.date_is_descending?output+moment(d[2]).format("LTS")+" - "+moment(d[0]).format("LTS"):output+moment(d[0]).format("LTS")+" - "+moment(d[2]).format("LTS")})).style("left",(function(){return options.width<pageX+div.property("offsetWidth")+options.tooltip.left_spacing?pageX-div.property("offsetWidth")-options.tooltip.left_spacing+"px":pageX+options.tooltip.left_spacing+"px"})),"top"===options.tooltip.position&&(div.style("top",(function(){return options.tooltip.hover_zoom.enabled?window.pageYOffset+matrix.f-options.tooltip.height-options.tooltip.hover_zoom.ratio*options.line_spacing+"px":matrix.f-options.tooltip.height+"px"})).style("height",(function(){return options.tooltip.hover_zoom.enabled?options.tooltip.hover_zoom.ratio*options.line_spacing+options.graph.height+options.tooltip.height+"px":options.graph.height+options.tooltip.height+"px"})),options.width<pageX+div.property("offsetWidth")+options.tooltip.left_spacing?div.style("border-right","solid thin rgb(0, 0, 0)").style("border-left","none"):div.style("border-left","solid thin rgb(0, 0, 0)").style("border-right","none")),"overlay"===options.tooltip.position&&div.style("top",pageY+"px")}function isYear(t){return+t==+new Date(t.getFullYear(),0,1,0,0,0)}function isMonth(t){return+t==+new Date(t.getFullYear(),t.getMonth(),1,0,0,0)}function emphasize(scale){var xTicks=scale.ticks(options.ticks_for_graph),isYearTick=xTicks.map(isYear),isMonthTick=xTicks.map(isMonth);options.emphasize_year_ticks&&!isYearTick.every((function(d){return!0===d}))&&isMonthTick.every((function(d){return!0===d}))&&(d3.selectAll("#"+options.id_div_graph+" g.tick").each((function(d,i){isYearTick[i]&&d3.select(this).attr("class","tick x_tick_emph")})),d3.selectAll("#"+options.id_div_graph+" .vert_grid").each((function(d,i){isYearTick[i]&&d3.select(this).attr("class","vert_grid vert_grid_emph")}))),options.emphasize_month_ticks&&!isMonthTick.every((function(d){return!0===d}))&&(d3.selectAll("#"+options.id_div_graph+" g.tick").each((function(d,i){isMonthTick[i]&&d3.select(this).attr("class","tick x_tick_emph")})),d3.selectAll("#"+options.id_div_graph+" g.vert_grid").each((function(d,i){isMonthTick[i]&&d3.select(this).attr("class","vert_grid vert_grid_emph")})))}if(g.selectAll("rect").data((function(d){return d.disp_data})).enter().append("rect").attr("x",(function(d){return xForPoint(d,options.graph.width,options.xScale,0)})).attr("width",(function(d){return widthForPoint(d,options.graph.width,options.xScale,0)})).attr("y",options.line_spacing).attr("height",options.graph.height).attr("transform",(function(d){return transformForTypeOfGraph(d,options.xScale,options.graph.height,options.line_spacing,0)})).attr("rx",(function(d){return roundedRect()})).attr("ry",(function(d){return roundedRect()})).attr("class",(function(d){if(!options.custom_categories)return 1===d[1]?"rect_has_data":"rect_has_no_data";var series=dataset.filter((function(series){return series.disp_data.indexOf(d)>=0}))[0];return series&&series.categories?series.categories[d[1]].class:void 0})).on("mouseover",(function(d,i){redrawTooltipWhenOver(this,dataset,d3.event.layerX,d3.event.layerY,d,i)})).on("mouseout",(function(){redrawTooltipWhenOut(this)})).on("click",(function(d,i){options.onClickBlock.call(this,d,i)})).on("mousemove",(function(){redrawTooltipWhenMoved(d3.event.layerX,d3.event.layerY,this)})),emphasize(xScale),options.title.enabled&&svg.select("#g_title").append("text").attr("x",options.padding.left).attr("y",options.padding.top).text(options.title.text).attr("class","heading"),options.sub_title.enabled){var subtitleText="";noOfDatasets&&(subtitleText=options.is_date_only_format?options.sub_title.from_text+" "+moment(startDate).format("MMMM Y")+" "+options.sub_title.to_text+" "+moment(endDate).format("MMMM Y"):options.sub_title.from_text+" "+moment(startDate).format("l")+" "+moment(startDate).format("LTS")+" "+options.sub_title.to_text+" "+moment(endDate).format("l")+" "+moment(endDate).format("LTS")),svg.select("#g_title").append("text").attr("x",options.padding.left).attr("y",options.padding.top+options.title.line_spacing).text(subtitleText).attr("class","subheading")}if(!options.custom_categories&&options.legend.enabled){var legend=svg.select("#g_title").append("g").attr("id","g_legend").attr("transform","translate(0,-12)");legend.append("rect").attr("x",width+options.margin.right-options.legend.x_right_offset).attr("y",options.padding.top).attr("height",15).attr("width",15).attr("class","rect_has_data"),legend.append("text").attr("x",width+options.margin.right-options.legend.x_right_offset+20).attr("y",options.padding.top+options.legend.line_space-options.legend.offset/2).text(options.legend.has_data_text).attr("dy","0.5ex").attr("class","legend"),legend.append("rect").attr("x",width+options.margin.right-options.legend.x_right_offset).attr("y",options.padding.top+options.legend.line_space+options.legend.offset).attr("height",15).attr("width",15).attr("class","rect_has_no_data"),legend.append("text").attr("x",width+options.margin.right-options.legend.x_right_offset+20).attr("y",options.padding.top+2*options.legend.line_space+options.legend.offset/2).text(options.legend.has_no_data_text).attr("dy","0.5ex").attr("class","legend")}function zoomed(){var e=d3.event;e.sourceEvent&&"brush"===e.sourceEvent.type&&!options.sub_chart.animation||e&&"zoom"!==e.type||(e.transform.k||e.transform.x)&&(options.xScale=e.transform.rescaleX(xScale),e.sourceEvent&&"touchmove"==e.sourceEvent?redrawTooltipWhenMoved(e.sourceEvent.touches[0].layerX,e.sourceEvent.touches[0].layerY):e.sourceEvent&&redrawTooltipWhenMoved(e.sourceEvent.layerX,e.sourceEvent.layerY),g.selectAll("rect").attr("x",(function(d){return xForPoint(d,options.graph.width,options.xScale,0)})).attr("width",(function(d){return widthForPoint(d,options.graph.width,options.xScale,0)})).attr("transform",(function(d){return transformForTypeOfGraph(d,options.xScale,options.graph.height,options.line_spacing,0)})),svg.select(".xAxis").call(xAxis.scale(options.xScale)),svg.select("#vGrid").selectAll("line").remove(),createVGrid(options.xScale),emphasize(options.xScale),options.sub_chart.enabled&&svg.select("#g_brush").call(brush.move,options.xScale.range().map(e.transform.invertX,e.transform)),options.zoom.onZoom.call(this,options.xScale.domain()))}if(options.sub_chart.enabled){var brush=d3.brushX().extent([[0,0],[width,options.sub_chart.height]]).on("brush end",brushed);function brushed(){if(!d3.event||!d3.event.sourceEvent||"zoom"!==d3.event.sourceEvent.type){var s=d3.event.selection||xScale2.range();svg.select("#g_data").call(options.zoomed.transform,d3.zoomIdentity.scale(width/(s[1]-s[0])).translate(-s[0],0))}}svg.append("g").attr("id","g_sub").append("g").attr("class","subchart-xAxis").attr("transform","translate( 0, "+(options.sub_chart.margin.top+options.sub_chart.height+height)+")").call(subChartXAxis).append("g"),svg.selectAll("#g_sub").append("g").attr("id","g_sub_data"),options.sub_chart.graph.enabled&&svg.selectAll("#g_sub_data").selectAll(".g_sub_data").data(dataset.slice(startSet,endSet)).enter().append("g").attr("transform",(function(d,i){return"translate( 0, "+((options.sub_chart.graph.line_spacing+options.sub_chart.graph.height)*i+options.sub_chart.margin.top+height)+")"})).selectAll("rect").data((function(d){return d.disp_data})).enter().append("rect").attr("x",(function(d){return xForPoint(d,options.sub_chart.graph.width,xScale2,0)})).attr("width",(function(d){return widthForPoint(d,options.sub_chart.graph.width,xScale2,0)})).attr("y",options.sub_chart.graph.line_spacing).attr("height",options.sub_chart.graph.height).attr("transform",(function(d){return transformForTypeOfGraph(d,xScale2,options.sub_chart.graph.height,options.sub_chart.graph.line_spacing,0)})).attr("rx",(function(d){return roundedRect()})).attr("ry",(function(d){return roundedRect()})).attr("class",(function(d){if(!options.custom_categories)return 1===d[1]?"rect_has_data":"rect_has_no_data";var series=dataset.filter((function(series){return series.disp_data.indexOf(d)>=0}))[0];return series&&series.categories?series.categories[d[1]].class:void 0})),svg.select("#g_sub").append("g").attr("id","g_brush").attr("class","brush").attr("width",width).attr("transform","translate( 0, "+(options.sub_chart.margin.top+height)+")").call(brush)}if(options.scale){var newX,new_translate=(-width*options.scale.k*(-1*options.scale.x/(options.oldwidth*options.scale.k))-options.scale.x)/options.scale.k;svg.select("#g_data").call(options.zoomed.transform,options.scale.translate(new_translate,0)),options.oldwidth=width}else options.sub_chart.enabled&&svg.select("#g_brush").call(brush.move,xScale.range());function xForPoint(d,graph_width,xScale,ratio){var x_scale=xScale(d[0])-ratio;return options.date_is_descending&&(x_scale=xScale(d[2])-ratio),isNaN(x_scale)||x_scale<=0||x_scale+ratio>width?0-ratio/2:"rhombus"==options.graph.type||"circle"==options.graph.type?xScale(d[0])-graph_width/2:x_scale}function widthForPoint(d,graph_width,xScale,ratio){var x_scale_d0=xScale(d[0])-ratio,x_scale_d2=xScale(d[2])+ratio;return options.date_is_descending&&(x_scale_d0=xScale(d[2])-ratio,x_scale_d2=xScale(d[0])+ratio),isNaN(x_scale_d0)||isNaN(x_scale_d2)||!options.date_is_descending&&x_scale_d2-x_scale_d0<0||x_scale_d2<=0&&x_scale_d0<=0?0:options.date_is_descending&&x_scale_d2-x_scale_d0<0?-1*(x_scale_d2-x_scale_d0):"rhombus"==options.graph.type||"circle"==options.graph.type?x_scale_d0+ratio<0?0-ratio:graph_width+ratio:x_scale_d0<0&&x_scale_d2>0?x_scale_d2>width?width:x_scale_d2-ratio:x_scale_d2<0&&x_scale_d0>0?x_scale_d0>width?width:x_scale_d0-ratio:x_scale_d2>width?width-x_scale_d0<0?0:width-x_scale_d0+ratio:x_scale_d2-x_scale_d0}function transformForTypeOfGraph(d,xScale,graph_height,line_spacing,ratio){var x_scale=xScale(d[0]);return("rhombus"==options.graph.type||"circle"==options.graph.type)&&x_scale>0?"rotate(45 "+x_scale+" "+(graph_height/2+line_spacing-ratio)+")":("rhombus"==options.graph.type||"circle"==options.graph.type)&&x_scale<=0?"rotate(45 0 "+(graph_height/2+line_spacing-ratio)+")":void 0}function roundedRect(){return"circle"==options.graph.type?2e5:0}}))}function removeElementsByClass(className){for(var elements=document.getElementsByClassName(className);elements.length>0;)elements[0].parentNode.removeChild(elements[0])}return options.locale={dateTime:convertMomentToStrftime(date_format_local.LLLL),date:convertMomentToStrftime(date_format_local.L),time:convertMomentToStrftime(date_format_local.LTS),periods:["AM","PM"],days:moment.weekdays(),shortDays:moment.weekdaysShort(),months:moment.months(),shortMonths:moment.monthsShort()},options.custom_time_format||(options.custom_time_format={format_millisecond:convertMomentToStrftime("SSS"),format_second:convertMomentToStrftime(":ss"),format_minute:convertMomentToStrftime(date_format_local.LT),format_hour:convertMomentToStrftime(date_format_local.LT.substring(0,1)+(periodInLocal()?" "+date_format_local.LT.slice(-1):"")),format_day:convertMomentToStrftime("ddd DD"),format_week:convertMomentToStrftime("MMM DD"),format_month:convertMomentToStrftime("MMMM"),format_year:convertMomentToStrftime("YYYY")}),custom_options.hasOwnProperty("width")||(options.width=document.getElementById(options.id_div_graph).offsetWidth),options.id="visavail-"+Math.random().toString(36).substring(7),chart.maxDisplayDatasets=function(_){return arguments.length?(options.max_display_datasets=_,chart):options.max_display_datasets},chart.displayDateRange=function(date_range,dataset){return arguments.length?(options.display_date_range=date_range,document.getElementById(options.id_div_graph)?chart.updateGraph(null,dataset):chart):options.display_date_range},chart.updateOptions=function(custom_options){return chart.updateGraph(custom_options)},chart.resizeWidth=function(width){return options.width=width,chart.updateGraph()},chart.updateGraph=function(custom_option,dataset){if(document.getElementById(options.id_div_graph)&&""!=document.getElementById(options.id_div_graph).innerHTML){if(document.getElementById(options.id_div_graph).innerHTML="",document.getElementById(options.id)&&removeElementsByClass(options.id),custom_option&&loadConfig(options,custom_options),dataset)return chart.createGraph(dataset);d3.select("#"+options.id_div_graph).call(chart)}return chart},chart.createGraph=function(dataset){return d3.select("#"+options.id_div_graph).datum(dataset).call(chart),chart},chart.destroy=function(_){return document.getElementById(options.id_div_graph)&&(document.getElementById(options.id_div_graph).innerHTML=""),document.getElementById(options.id)&&document.getElementById(options.id).remove(),Object.keys(options).forEach((function(key){options[key]=null})),null},options.responsive.function=function(){options.id_div_container&&document.getElementById(options.id_div_graph)&&""!=document.getElementById(options.id_div_graph).innerHTML&&chart.resizeWidth(document.getElementById(options.id_div_graph).offsetWidth)},options.responsive.enabled&&window.addEventListener("resize",options.responsive.function),chart.createGraph(dataset),chart}return Number.isInteger=Number.isInteger||function(value){return"number"==typeof value&&isFinite(value)&&Math.floor(value)===value},Element.prototype.remove=Element.prototype.remove||function(){this.parentNode&&this.parentNode.removeChild(this)},visavail.generate=function(config,dataset){return new visavailChart(config,dataset)},visavail}));