/** * @file timeline.js * * @brief * The Timeline is an interactive visualization chart to visualize events in * time, having a start and end date. * You can freely move and zoom in the timeline by dragging * and scrolling in the Timeline. Items are optionally dragable. The time * scale on the axis is adjusted automatically, and supports scales ranging * from milliseconds to years. * * * Timeline is tested on Firefox 3.6, Safari 5.0, Chrome 6.0, Opera 10.6, and * Internet Explorer 6+. * * @license * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * Copyright (c) 2011-2012 Almende B.V. * * @author Jos de Jong, * @date 2012-05-01 * * * Modified - I had taken this code and made it specifically for timeline visualization from a * set data structure. I've added new functionality to deal with timezones and * formating the visual timline groups differently. Also I'm making this a stand alone * amd compatible plugin * * @modifier Ian Quattlebaum * @date 2013-03-01 */ !function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){var e=function(t){this.dom={},this.conversion={},this.eventParams={},this.groups=[],this.groupIndexes={},this.items=[],this.selection=void 0,this.listeners={},this.size={actualHeight:0,axis:{characterMajorHeight:0,characterMajorWidth:0,characterMinorHeight:0,characterMinorWidth:0,height:0,labelMajorTop:0,labelMinorTop:0,line:0,lineMajorWidth:0,lineMinorHeight:0,lineMinorTop:0,lineMinorWidth:0,top:0},contentHeight:0,contentLeft:0,contentWidth:0,dataChanged:!1,frameHeight:0,frameWidth:0,groupsLeft:0,groupsWidth:0,items:{top:0}},this.dom.container=t,this.options={utc:!1,width:"100%",height:"auto",minHeight:0,autoHeight:!0,eventMargin:10,eventMarginAxis:20,dragAreaWidth:10,min:void 0,max:void 0,intervalMin:10,intervalMax:31536e10,moveable:!0,zoomable:!0,selectable:!0,editable:!1,snapEvents:!0,groupChangeable:!0,showCurrentTime:!0,showCustomTime:!1,showMajorLabels:!0,showNavigation:!0,showButtonAdd:!0,groupsOnRight:!1,axisOnTop:!1,stackEvents:!0,animate:!0,animateZoom:!0,style:"box"},this.clientTimeOffset=3600;for(var i=this.dom;i.container.hasChildNodes();)i.container.removeChild(i.container.firstChild);this.step=new e.StepDate(this.options),this.data=[],this.firstDraw=!0,this.setVisibleChartRange(void 0,void 0,!1),this.redrawFrame(),Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;ts;s++){var o=t[s],a=this.createItem(o);i.push(a)}this.size.dataChanged=!0,this.redrawFrame(),this.recalcSize(),this.stackEvents(!1),this.redrawFrame(),this.size.dataChanged=!1},e.prototype.setGroups=function(t){this.deleteGroups();this.groups,this.groupIndexes;if(!e.isArray(t))throw"Unknown data type. DataTable or Array expected.";for(var i=0,s=t.length;s>i;i++){var n=t[i],o=n.group;o&&this.addGroup(o)}},e.prototype.getData=function(){return this.data},e.prototype.updateData=function(t,i){var s=this.data;if(!e.isArray(s))throw"Cannot update data, unknown type of data";var n=s[t];void 0==n&&(n={},s[t]=n),i.start&&(n.start=i.start),i.end&&(n.end=i.end),i.content&&(n.content=i.content),i.group&&(n.group=i.group)},e.prototype.getItemIndex=function(e){for(var t=e,i=this.dom,s=this.items,n=void 0;t.parentNode&&t.parentNode!==i.items.frame;)t=t.parentNode;if(t.parentNode===i.items.frame)for(var o=0,a=s.length;a>o;o++)if(s[o].dom===t){n=o;break}return n},e.prototype.setSize=function(e,t){e&&(this.options.width=e,this.dom.frame.style.width=e),t&&(this.options.height=t,this.options.autoHeight="auto"===this.options.height,"auto"!==t&&(this.dom.frame.style.height=t)),this.recalcSize(),this.stackEvents(!1),this.redrawFrame()},e.prototype.setVisibleChartRange=function(e,t,i){void 0==e&&(e=new Date,e.setDate(e.getDate()-3)),void 0==t&&(t=new Date,t.setDate(e.getDate()+4)),t.valueOf()<=e.valueOf()&&(t=new Date(e),t.setDate(t.getDate()+7));var s=this.options.min?this.options.min.valueOf():void 0;s&&e.valueOf()n&&(t=new Date(n)),this.applyRange(e,t),void 0==i||1==i?(this.recalcSize(),this.stackEvents(!1),this.redrawFrame()):this.recalcConversion()},e.prototype.setVisibleChartRangeAuto=function(){var e=this.items;startMin=void 0,endMax=void 0;for(var t=0,i=e.length;i>t;t++){var s=e[t],n=s.start?s.start.valueOf():void 0,o=s.end?s.end.valueOf():n;startMin=void 0!==startMin&&void 0!==n?Math.min(startMin,n):n,endMax=void 0!==endMax&&void 0!==o?Math.max(endMax,o):o}if(void 0!==startMin&&void 0!==endMax){var a=endMax-startMin;a=0,startMin-=.05*a,endMax+=.05*a,this.setVisibleChartRange(new XDate(startMin),new XDate(endMax))}else this.setVisibleChartRange(void 0,void 0)},e.prototype.setVisibleChartRangeNow=function(){var e=new Date,t=this.end.getTime()-this.start.getTime(),i=new Date(e.getTime()-t/2),s=new Date(i.getTime()+t);this.setVisibleChartRange(i,s)},e.prototype.getVisibleChartRange=function(){var e={start:new Date(this.start),end:new Date(this.end)};return e},e.prototype.redrawFrame=function(){var e=this.dom,t=this.options,i=this.size;e.frame||(e.frame=document.createElement("DIV"),e.frame.className="timeline-frame",e.frame.style.position="relative",e.frame.style.overflow="hidden",e.container.appendChild(e.frame)),e.frame.style.height=t.autoHeight?i.frameHeight+"px":t.height||"100%",e.frame.style.width=t.width||"100%",this.redrawContent(),this.redrawGroups(),this.redrawCurrentTime(),this.redrawCustomTime(),this.redrawNavigation()},e.prototype.redrawContent=function(){var t=this.dom,i=this.size;if(!t.content){t.content=document.createElement("DIV"),t.content.style.position="relative",t.content.style.overflow="hidden",t.frame.appendChild(t.content);var s=document.createElement("DIV");s.style.position="absolute",s.style.left="0px",s.style.top="0px",s.style.height="100%",s.style.width="0px",t.content.appendChild(s),t.contentTimelines=s;var n=this.eventParams,o=this;n.onMouseDown||(n.onMouseDown=function(e){o.onMouseDown(e)},e.addEventListener(t.content,"mousedown",n.onMouseDown)),n.onTouchStart||(n.onTouchStart=function(e){o.onTouchStart(e)},e.addEventListener(t.content,"touchstart",n.onTouchStart)),n.onMouseWheel||(n.onMouseWheel=function(e){o.onMouseWheel(e)},e.addEventListener(t.content,"mousewheel",n.onMouseWheel)),n.onDblClick||(n.onDblClick=function(e){o.onDblClick(e)},e.addEventListener(t.content,"dblclick",n.onDblClick))}t.content.style.left=i.contentLeft+"px",t.content.style.top="0px",t.content.style.width=i.contentWidth+"px",t.content.style.height=i.frameHeight+"px",this.redrawAxis(),this.redrawItems(),this.redrawDeleteButton(),this.redrawDragAreas()},e.prototype.redrawAxis=function(){var e=this.dom,t=this.options,i=this.size,s=this.step,n=e.axis;n||(n={},e.axis=n),void 0===i.axis.properties&&(i.axis.properties={}),void 0===n.minorTexts&&(n.minorTexts=[]),void 0===n.minorLines&&(n.minorLines=[]),void 0===n.majorTexts&&(n.majorTexts=[]),void 0===n.majorLines&&(n.majorLines=[]),n.frame||(n.frame=document.createElement("DIV"),n.frame.style.position="absolute",n.frame.style.left="0px",n.frame.style.top="0px",e.content.appendChild(n.frame)),e.content.removeChild(n.frame),n.frame.style.width=i.contentWidth+"px",n.frame.style.height=i.axis.height+"px";var o=this.screenToTime(0),a=this.screenToTime(i.contentWidth),r=i.contentWidth;this.minimumStep=this.screenToTime(6*i.axis.characterMinorWidth).valueOf()-this.screenToTime(0).valueOf(),s.setRange(o,a,this.minimumStep),this.redrawAxisCharacters(),this.redrawAxisStartOverwriting(),s.start();for(var h=void 0;!s.end();){var l=s.getCurrent(),d=this.timeToScreen(l),p=s.isMajor();this.redrawAxisMinorText(d,s.getLabelMinor()),p&&t.showMajorLabels?(d>0&&(void 0===h&&(h=d),this.redrawAxisMajorText(d,s.getLabelMajor())),this.redrawAxisMajorLine(d)):this.redrawAxisMinorLine(d),s.next()}if(t.showMajorLabels){var c=this.screenToTime(0),u=this.step.getLabelMajor(c),r=u.length*i.axis.characterMajorWidth+10;(void 0===h||h>r)&&this.redrawAxisMajorText(0,u,c)}this.redrawAxisHorizontal(),this.redrawAxisEndOverwriting(),e.content.insertBefore(n.frame,e.content.firstChild)},e.prototype.redrawAxisCharacters=function(){var e=this.dom,t=e.axis;if(!t.characterMinor){var i=document.createTextNode("0"),s=document.createElement("DIV");s.className="timeline-axis-text timeline-axis-text-minor",s.appendChild(i),s.style.position="absolute",s.style.visibility="hidden",s.style.paddingLeft="0px",s.style.paddingRight="0px",t.frame.appendChild(s),t.characterMinor=s}if(!t.characterMajor){var i=document.createTextNode("0"),n=document.createElement("DIV");n.className="timeline-axis-text timeline-axis-text-major",n.appendChild(i),n.style.position="absolute",n.style.visibility="hidden",n.style.paddingLeft="0px",n.style.paddingRight="0px",t.frame.appendChild(n),t.characterMajor=n}},e.prototype.redrawAxisStartOverwriting=function(){var e=this.size.axis.properties;e.minorTextNum=0,e.minorLineNum=0,e.majorTextNum=0,e.majorLineNum=0},e.prototype.redrawAxisEndOverwriting=function(){for(var e=this.dom,t=this.size.axis.properties,i=this.dom.axis.frame,s=e.axis.minorTexts,n=t.minorTextNum;s.length>n;){var o=s[n];i.removeChild(o),s.splice(n,1)}for(var a=e.axis.minorLines,n=t.minorLineNum;a.length>n;){var r=a[n];i.removeChild(r),a.splice(n,1)}for(var h=e.axis.majorTexts,n=t.majorTextNum;h.length>n;){var l=h[n];i.removeChild(l),h.splice(n,1)}for(var d=e.axis.majorLines,n=t.majorLineNum;d.length>n;){var p=d[n];i.removeChild(p),d.splice(n,1)}},e.prototype.redrawAxisHorizontal=function(){var e=this.dom.axis,t=this.size;if(!e.backgroundLine){var i=document.createElement("DIV");i.className="timeline-axis",i.style.position="absolute",i.style.left="0px",i.style.width="100%",i.style.border="none",e.frame.insertBefore(i,e.frame.firstChild),e.backgroundLine=i}if(e.backgroundLine.style.top=t.axis.top+"px",e.backgroundLine.style.height=t.axis.height+"px",e.line){var s=e.frame.removeChild(e.line);e.frame.appendChild(s)}else{var s=document.createElement("DIV");s.className="timeline-axis",s.style.position="absolute",s.style.left="0px",s.style.width="100%",s.style.height="0px",e.frame.appendChild(s),e.line=s}e.line.style.top=t.axis.line+"px"},e.prototype.redrawAxisMinorText=function(e,t){var i,s=this.size,n=this.dom,o=s.axis.properties,a=n.axis.frame,r=n.axis.minorTexts,h=o.minorTextNum;if(hu;u++){var g=items[u];switch(g.type){case"range":if(r>d){var v=n[d];v.firstChild.innerHTML=g.content,v.style.display="",g.dom=v,d++}else{var v=this.createEventRange(g.content,g.groupId,g.id);n[d]=v,s.appendChild(v),g.dom=v,d++,r++}break;case"box":if(h>p){var v=o[p];v.firstChild.innerHTML=g.content,v.style.display="",g.dom=v,p++}else{var v=this.createEventBox(g.content);o[p]=v,s.appendChild(v),s.insertBefore(v.line,s.firstChild),s.appendChild(v.dot),g.dom=v,p++,h++}break;case"dot":if(l>c){var v=a[c];v.firstChild.innerHTML=g.content,v.style.display="",g.dom=v,c++}else{var v=this.createEventDot(g.content);a[c]=v,s.appendChild(v),g.dom=v,c++,l++}}}for(var u=d;r>u;u++)s.removeChild(n[u]);n.splice(d,r-d);for(var u=p;h>u;u++){var f=o[u];s.removeChild(f.line),s.removeChild(f.dot),s.removeChild(f)}o.splice(p,h-p);for(var u=c;l>u;u++)s.removeChild(a[u]);a.splice(c,l-c)}for(var u=0,m=items.length;m>u;u++){var g=items[u],v=g.dom;switch(g.type){case"range":var y=this.timeToScreen(g.start),x=this.timeToScreen(g.end);-contentWidth>y&&(y=-contentWidth),x>2*contentWidth&&(x=2*contentWidth);var D=x>-contentWidth&&2*contentWidth>y;D||size.dataChanged?(g.hidden&&(g.hidden=!1,v.style.display=""),v.style.top=g.top+"px",v.style.left=y+"px",v.style.width=Math.max(x-y,1)+"px"):g.hidden||(v.style.display="none",g.hidden=!0);break;case"box":var y=this.timeToScreen(g.start),S=t.axisOnTop,M=(size.axis.height,size.axis.top),D=y+g.width/2>-contentWidth&&y-g.width/2<2*contentWidth;if(D||size.dataChanged){g.hidden&&(g.hidden=!1,v.style.display="",v.line.style.display="",v.dot.style.display=""),v.style.top=g.top+"px",v.style.left="right"==i?y-g.width+"px":"left"==i?y+"px":y-g.width/2+"px";var w=v.line;w.style.left=y-g.lineWidth/2+"px",S?(w.style.top="0px",w.style.height=Math.max(g.top,0)+"px"):(w.style.top=g.top+g.height+"px",w.style.height=Math.max(M-g.top-g.height,0)+"px");var T=v.dot;T.style.left=y-g.dotWidth/2+"px",T.style.top=M-g.dotHeight/2+"px"}else g.hidden||(v.style.display="none",v.line.style.display="none",v.dot.style.display="none",g.hidden=!0);break;case"dot":var y=this.timeToScreen(g.start),S=t.axisOnTop,M=(size.axis.height,size.axis.top),D=y+g.width>-contentWidth&&2*contentWidth>y;D||size.dataChanged?(g.hidden&&(g.hidden=!1,v.style.display=""),v.style.top=g.top+"px",v.style.left=y-g.dotWidth/2+"px",v.content.style.marginLeft=1.5*g.dotWidth+"px",v.dot.style.top=(g.height-g.dotHeight)/2+"px"):g.hidden||(v.style.display="none",g.hidden=!0)}}if(this.selection){var g=this.selection.item;s.removeChild(g),s.appendChild(g)}e.content.appendChild(s)},e.prototype.createEventBox=function(e){var t=document.createElement("DIV");t.style.position="absolute",t.style.left="0px",t.style.top="0px",t.className="timeline-event timeline-event-box";var i=document.createElement("DIV");i.className="timeline-event-content",i.innerHTML=e,t.appendChild(i);var s=document.createElement("DIV");s.style.position="absolute",s.style.width="0px",s.className="timeline-event timeline-event-line",t.line=s;var n=document.createElement("DIV");return n.style.position="absolute",n.style.width="0px",n.style.height="0px",n.className="timeline-event timeline-event-dot",t.dot=n,t},e.prototype.createEventDot=function(e){var t=document.createElement("DIV");t.style.position="absolute";var i=document.createElement("DIV");i.className="timeline-event-content",i.innerHTML=e,t.appendChild(i);var s=document.createElement("DIV");return s.style.position="absolute",s.className="timeline-event timeline-event-dot",s.style.width="0px",s.style.height="0px",t.appendChild(s),t.content=i,t.dot=s,t},e.prototype.createEventRange=function(e,t,i){var s=document.createElement("DIV"),n=t?" timeline-group-"+t:"",o=i?" timeline-event-"+i:"";s.style.position="absolute",s.className="timeline-event timeline-event-range"+n+o;var a=document.createElement("DIV");return a.className="timeline-event-content",a.innerHTML=e,s.appendChild(a),s},e.prototype.redrawGroups=function(){var e=this.dom,t=this.options,i=this.size,s=this.groups;void 0===e.groups&&(e.groups={});var n=e.groups.labels;n||(n=[],e.groups.labels=n);var o=e.groups.labelLines;o||(o=[],e.groups.labelLines=o);var a=e.groups.itemLines;a||(a=[],e.groups.itemLines=a);var r=e.groups.frame;if(!r){var r=document.createElement("DIV");r.className="timeline-groups-axis",r.style.position="absolute",r.style.overflow="hidden",r.style.top="0px",r.style.height="100%",e.frame.appendChild(r),e.groups.frame=r}if(r.style.left=i.groupsLeft+"px",r.style.width=void 0!==t.groupsWidth?t.groupsWidth:i.groupsWidth+"px",r.style.display=0==s.length?"none":"",i.dataChanged){for(var h=n.length,l=s.length,d=0,p=Math.min(h,l);p>d;d++){var c=s[d],u=n[d];u.innerHTML=c.content,u.style.display=""}for(var d=h;l>d;d++){var c=s[d],u=document.createElement("DIV");u.className="timeline-groups-text",u.style.position="absolute",void 0===t.groupsWidth&&(u.style.whiteSpace="nowrap"),u.innerHTML=c.content,r.appendChild(u),n[d]=u;var m=document.createElement("DIV");m.className="timeline-axis-grid timeline-axis-grid-minor",m.style.position="absolute",m.style.left="0px",m.style.width="100%",m.style.height="0px",m.style.borderTopStyle="solid",r.appendChild(m),o[d]=m;var g=document.createElement("DIV");g.className="timeline-axis-grid timeline-axis-grid-minor",g.style.position="absolute",g.style.left="0px",g.style.width="100%",g.style.height="0px",g.style.borderTopStyle="solid",e.content.insertBefore(g,e.content.firstChild),a[d]=g}for(var d=l;h>d;d++){var u=n[d],m=o[d],g=a[d];r.removeChild(u),r.removeChild(m),e.content.removeChild(g)}n.splice(l,h-l),o.splice(l,h-l),a.splice(l,h-l),r.style.borderStyle=t.groupsOnRight?"none none none solid":"none solid none none"}for(var d=0,p=s.length;p>d;d++){var c=s[d],u=n[d],m=o[d],g=a[d];u.style.top=c.labelTop+"px",m.style.top=c.lineTop+"px",g.style.top=c.lineTop+"px",g.style.width=i.contentWidth+"px"}if(!e.groups.background){var v=document.createElement("DIV");v.className="timeline-axis",v.style.position="absolute",v.style.left="0px",v.style.width="100%",v.style.border="none",r.appendChild(v),e.groups.background=v}if(e.groups.background.style.top=i.axis.top+"px",e.groups.background.style.height=i.axis.height+"px",!e.groups.line){var f=document.createElement("DIV");f.className="timeline-axis",f.style.position="absolute",f.style.left="0px",f.style.width="100%",f.style.height="0px",r.appendChild(f),e.groups.line=f}e.groups.line.style.top=i.axis.line+"px"},e.prototype.redrawCurrentTime=function(){var e=this.options,t=this.dom,i=this.size;if(!e.showCurrentTime)return void(t.currentTime&&(t.contentTimelines.removeChild(t.currentTime),delete t.currentTime));if(!t.currentTime){var s=document.createElement("DIV");s.className="timeline-currenttime",s.style.position="absolute",s.style.top="0px",s.style.height="100%",t.contentTimelines.appendChild(s),t.currentTime=s}var n=new Date,o=new Date(n.getTime()+this.clientTimeOffset),a=this.timeToScreen(o),r=a>-i.contentWidth&&a<2*i.contentWidth;t.currentTime.style.display=r?"":"none",t.currentTime.style.left=a+"px",t.currentTime.title="Current time: "+o,void 0!=this.currentTimeTimer&&(clearTimeout(this.currentTimeTimer),delete this.currentTimeTimer);var h=this,l=function(){h.redrawCurrentTime()},d=1/this.conversion.factor/2;30>d&&(d=30),this.currentTimeTimer=setTimeout(l,d)},e.prototype.redrawCustomTime=function(){var e=this.options,t=this.dom,i=this.size;if(!e.showCustomTime)return void(t.customTime&&(t.contentTimelines.removeChild(t.customTime),delete t.customTime));if(!t.customTime){var s=document.createElement("DIV");s.className="timeline-customtime",s.style.position="absolute",s.style.top="0px",s.style.height="100%";var n=document.createElement("DIV");n.style.position="relative",n.style.top="0px",n.style.left="-10px",n.style.height="100%",n.style.width="20px",s.appendChild(n),t.contentTimelines.appendChild(s),t.customTime=s,this.customTime=new Date}var o=this.timeToScreen(this.customTime),a=o>-i.contentWidth&&o<2*i.contentWidth;t.customTime.style.display=a?"":"none",t.customTime.style.left=o+"px",t.customTime.title="Time: "+this.customTime},e.prototype.redrawDeleteButton=function(){var e=this.options,t=this.dom,i=this.size,s=t.items.frame;if(e.editable){var n=t.items.deleteButton;if(n||(n=document.createElement("DIV"),n.className="timeline-navigation-delete",n.style.position="absolute",s.appendChild(n),t.items.deleteButton=n),this.selection){var o,a=this.selection.index,r=this.items[a],h=(this.selection.item,r.top);switch(r.type){case"range":o=this.timeToScreen(r.end);break;case"box":o=this.timeToScreen(r.start)+r.width/2;break;case"dot":o=this.timeToScreen(r.start)+r.width}o<-i.contentWidth&&(o=-i.contentWidth),o>2*i.contentWidth&&(o=2*i.contentWidth),n.style.left=o+"px",n.style.top=h+"px",n.style.display="",s.removeChild(n),s.appendChild(n)}else n.style.display="none"}},e.prototype.redrawDragAreas=function(){var e=this.options,t=this.dom,i=(this.size,this.dom.items.frame);if(e.editable){var s=t.items.dragLeft;s||(s=document.createElement("DIV"),s.style.width=e.dragAreaWidth+"px",s.style.position="absolute",s.style.cursor="w-resize",i.appendChild(s),t.items.dragLeft=s);var n=t.items.dragRight;if(n||(n=document.createElement("DIV"),n.style.width=e.dragAreaWidth+"px",n.style.position="absolute",n.style.cursor="e-resize",i.appendChild(n),t.items.dragRight=n),this.selection){var o=this.selection.index,a=this.items[o];if("range"==a.type){var r=(a.dom,this.timeToScreen(a.start)),h=this.timeToScreen(a.end),l=a.top,d=a.height;s.style.left=r+"px",s.style.top=l+"px",s.style.height=d+"px",s.style.display="",i.removeChild(s),i.appendChild(s),n.style.left=h-e.dragAreaWidth+"px",n.style.top=l+"px",n.style.height=d+"px",n.style.display="",i.removeChild(n),i.appendChild(n)}}else s.style.display="none",n.style.display="none"}},e.prototype.redrawNavigation=function(){var t=this,i=this.options,s=this.dom,n=s.frame,o=s.navBar;if(!o){if((i.editable||i.showNavigation)&&(o=document.createElement("DIV"),o.style.position="absolute",o.className="timeline-navigation btn-group",i.groupsOnRight?o.style.left="10px":o.style.right="10px",i.axisOnTop?o.style.bottom="10px":o.style.top="10px",s.navBar=o,n.appendChild(o)),i.editable&&i.showButtonAdd){o.addButton=document.createElement("DIV"),o.addButton.className="timeline-navigation-new",o.addButton.title="Create new event";var a=function(s){e.preventDefault(s),e.stopPropagation(s);var n=t.size.contentWidth,o=n/2,a=t.screenToTime(o-n/10),r=t.screenToTime(o+n/10);i.snapEvents&&(t.step.snap(a),t.step.snap(r));var h="New",l=t.groups.length?t.groups[0].content:void 0;t.addItem({start:a,end:r,content:h,group:l});var d=t.items.length-1;t.selectItem(d),t.applyAdd=!0,t.trigger("add"),t.applyAdd||t.deleteItem(d),t.redrawDeleteButton(),t.redrawDragAreas()};e.addEventListener(o.addButton,"mousedown",a),o.appendChild(o.addButton)}if(i.editable&&i.showButtonAdd&&i.showNavigation&&(o.addButton.style.borderRightWidth="1px",o.addButton.style.borderRightStyle="solid"),i.showNavigation){o.zoomInButton=document.createElement("BUTTON"),o.zoomInButtonIcon=document.createElement("I"),o.zoomInButton.className="timeline-navigation-zoom-in btn btn-inverse",o.zoomInButtonIcon.className="icon-zoom-in",o.zoomInButton.title="Zoom in";var r=function(i){e.preventDefault(i),e.stopPropagation(i),t.zoom(.4),t.trigger("rangechange"),t.trigger("rangechanged")};e.addEventListener(o.zoomInButton,"mousedown",r),o.zoomInButton.appendChild(o.zoomInButtonIcon),o.appendChild(o.zoomInButton),o.zoomOutButton=document.createElement("BUTTON"),o.zoomOutButtonIcon=document.createElement("I"),o.zoomOutButton.className="timeline-navigation-zoom-out btn btn-inverse",o.zoomOutButtonIcon.className="icon-zoom-out",o.zoomOutButton.title="Zoom out";var h=function(i){e.preventDefault(i),e.stopPropagation(i),t.zoom(-.4),t.trigger("rangechange"),t.trigger("rangechanged")};e.addEventListener(o.zoomOutButton,"mousedown",h),o.zoomOutButton.appendChild(o.zoomOutButtonIcon),o.appendChild(o.zoomOutButton),o.moveLeftButton=document.createElement("BUTTON"),o.moveLeftButtonIcon=document.createElement("I"),o.moveLeftButton.className="timeline-navigation-move-left btn btn-inverse",o.moveLeftButtonIcon.className="icon-chevron-left",o.moveLeftButton.title="Move left";var l=function(i){e.preventDefault(i),e.stopPropagation(i),t.move(-.2),t.trigger("rangechange"),t.trigger("rangechanged")};e.addEventListener(o.moveLeftButton,"mousedown",l),o.moveLeftButton.appendChild(o.moveLeftButtonIcon),o.appendChild(o.moveLeftButton),o.moveRightButton=document.createElement("BUTTON"),o.moveRightButtonIcon=document.createElement("I"),o.moveRightButton.className="timeline-navigation-move-right btn btn-inverse",o.moveRightButtonIcon.className="icon-chevron-right",o.moveRightButton.title="Move right";var d=function(i){e.preventDefault(i),e.stopPropagation(i),t.move(.2),t.trigger("rangechange"),t.trigger("rangechanged")};e.addEventListener(o.moveRightButton,"mousedown",d),o.moveRightButton.appendChild(o.moveRightButtonIcon),o.appendChild(o.moveRightButton)}}},e.prototype.setCurrentTime=function(e){var t=new Date;this.clientTimeOffset=e.getTime()-t.getTime(),this.redrawCurrentTime()},e.prototype.getCurrentTime=function(){var e=new Date;return new Date(e.getTime()+this.clientTimeOffset)},e.prototype.setCustomTime=function(e){this.customTime=new Date(e),this.redrawCustomTime()},e.prototype.getCustomTime=function(){return new Date(this.customTime)},e.prototype.setScale=function(e,t){this.step.setScale(e,t),this.redrawFrame()},e.prototype.setAutoScale=function(e){this.step.setAutoScale(e),this.redrawFrame()},e.prototype.redraw=function(){this.setData(this.data)},e.prototype.checkResize=function(){var e=this.recalcSize();e&&this.redrawFrame()},e.filterImageUrls=function(t,i){for(var s=t.firstChild;s;){if("IMG"==s.tagName){var n=s.src;-1==i.indexOf(n)&&i.push(n)}e.filterImageUrls(s,i),s=s.nextSibling}},e.prototype.recalcSize=function(){var t=!1,i=this;if(size=this.size,options=this.options,axisOnTop=options.axisOnTop,dom=this.dom,axis=dom.axis,groups=this.groups,labels=dom.groups.labels,items=this.items,groupsWidth=size.groupsWidth,characterMinorWidth=axis.characterMinor?axis.characterMinor.clientWidth:0,characterMinorHeight=axis.characterMinor?axis.characterMinor.clientHeight:0,characterMajorWidth=axis.characterMajor?axis.characterMajor.clientWidth:0,characterMajorHeight=axis.characterMajor?axis.characterMajor.clientHeight:0,axisHeight=characterMinorHeight+(options.showMajorLabels?characterMajorHeight:0),actualHeight=size.actualHeight||axisHeight,size.dataChanged){for(var s=[],n=0,o=items.length;o>n;n++){var a=items[n],r=a.dom;r&&e.filterImageUrls(r,s)}if(s.length)for(var n=0;nn;n++){var p=groups[n];p.width=labels[n].clientWidth,p.height=labels[n].clientHeight,p.labelHeight=p.height,groupsWidth=Math.max(groupsWidth,p.width)}for(var n=0,o=items.length;o>n;n++){var a=items[n],r=a.dom,p=a.group,c=r?r.clientWidth:0,u=r?r.clientHeight:0;switch(t=t||a.width!=c,t=t||a.height!=u,a.width=c,a.height=u,a.type){case"range":break;case"box":a.dotHeight=r.dot.offsetHeight,a.dotWidth=r.dot.offsetWidth,a.lineWidth=r.line.offsetWidth;break;case"dot":a.dotHeight=r.dot.offsetHeight,a.dotWidth=r.dot.offsetWidth,a.contentHeight=r.content.offsetHeight}p&&(p.height=p.height?Math.max(p.height,a.height):a.height)}actualHeight=axisHeight+2*options.eventMarginAxis;for(var n=0,o=groups.length;o>n;n++)actualHeight+=groups[n].height+options.eventMargin}if(0==groups.length&&options.autoHeight){var m=0,g=0;if(this.animation&&this.animation.finalItems){var v=this.animation.finalItems,f=v[0];f&&f.top&&(m=f.top,g=f.top+f.height);for(var n=1,o=v.length;o>n;n++)f=v[n],m=Math.min(m,f.top),g=Math.max(g,f.top+f.height)}else{var a=items[0];a&&a.top&&(m=a.top,g=a.top+a.height);for(var n=1,o=items.length;o>n;n++){var a=items[n];a.top&&(m=Math.min(m,a.top),g=Math.max(g,a.top+a.height))}}if(actualHeight=g-m+2*options.eventMarginAxis+axisHeight,size.actualHeight!=actualHeight&&options.autoHeight&&!options.axisOnTop){var y=actualHeight-size.actualHeight;if(this.animation&&this.animation.finalItems)for(var v=this.animation.finalItems,n=0,o=v.length;o>n;n++)v[n].top+=y,v[n].item.top+=y;else for(var n=0,o=items.length;o>n;n++)items[n].top+=y}}var x=dom.frame?dom.frame.offsetWidth:0,D=Math.max(options.autoHeight?actualHeight:dom.frame?dom.frame.clientHeight:0,options.minHeight),S=axisOnTop?0:D-axisHeight,M=axisOnTop?axisHeight:S,w=axisOnTop?axisHeight:0,T=Math.max(D-axisHeight,0);void 0!==options.groupsWidth&&(groupsWidth=dom.groups.frame?dom.groups.frame.clientWidth:0);var C=options.groupsOnRight?x-groupsWidth:0;if(size.dataChanged){for(var E=options.eventMargin,L=axisOnTop?options.eventMarginAxis+E/2:T-options.eventMarginAxis+E/2,n=0,o=groups.length;o>n;n++){var p=groups[n];axisOnTop?(p.top=L,p.labelTop=L+axisHeight+(p.height-p.labelHeight)/2,p.lineTop=L+axisHeight+p.height+E/2,L+=p.height+E):(L-=p.height+E,p.top=L,p.labelTop=L+(p.height-p.labelHeight)/2,p.lineTop=L-E/2)}for(var n=0,o=items.length;o>n;n++){var a=items[n],p=a.group;p&&(a.top=p.top)}t=!0}return t=t||size.groupsWidth!==groupsWidth,t=t||size.groupsLeft!==C,t=t||size.actualHeight!==actualHeight,size.groupsWidth=groupsWidth,size.groupsLeft=C,size.actualHeight=actualHeight,t=t||size.frameWidth!==x,t=t||size.frameHeight!==D,size.frameWidth=x,size.frameHeight=D,t=t||size.groupsWidth!==groupsWidth,size.groupsWidth=groupsWidth,size.contentLeft=options.groupsOnRight?0:groupsWidth,size.contentWidth=Math.max(x-groupsWidth,0),size.contentHeight=T,t=t||size.axis.top!==S,t=t||size.axis.line!==M,t=t||size.axis.height!==axisHeight,t=t||size.items.top!==w,size.axis.top=S,size.axis.line=M,size.axis.height=axisHeight,size.axis.labelMajorTop=options.axisOnTop?0:M+characterMinorHeight,size.axis.labelMinorTop=options.axisOnTop?options.showMajorLabels?characterMajorHeight:0:M,size.axis.lineMinorTop=options.axisOnTop?size.axis.labelMinorTop:0,size.axis.lineMinorHeight=options.showMajorLabels?D-characterMajorHeight:D,size.axis.lineMinorWidth=dom.axis.minorLines.length?dom.axis.minorLines[0].offsetWidth:1,size.axis.lineMajorWidth=dom.axis.majorLines.length?dom.axis.majorLines[0].offsetWidth:1,size.items.top=w,t=t||size.axis.characterMinorWidth!==characterMinorWidth,t=t||size.axis.characterMinorHeight!==characterMinorHeight,t=t||size.axis.characterMajorWidth!==characterMajorWidth,t=t||size.axis.characterMajorHeight!==characterMajorHeight,size.axis.characterMinorWidth=characterMinorWidth,size.axis.characterMinorHeight=characterMinorHeight,size.axis.characterMajorWidth=characterMajorWidth,size.axis.characterMajorHeight=characterMajorHeight,this.recalcConversion(),t},e.prototype.recalcConversion=function(){this.conversion.offset=parseFloat(this.start.valueOf()),this.conversion.factor=parseFloat(this.size.contentWidth)/parseFloat(this.end.valueOf()-this.start.valueOf())},e.prototype.screenToTime=function(e){var t=this.conversion,i=new Date(parseFloat(e)/t.factor+t.offset);return i},e.prototype.timeToScreen=function(e){var t=this.conversion,i=(e.valueOf()-t.offset)*t.factor;return i},e.prototype.onTouchStart=function(t){var i=this.eventParams,s=(this.dom,this);i.touchDown||(i.touchDown=!0,i.zoomed=!1,this.onMouseDown(t),i.onTouchMove||(i.onTouchMove=function(e){s.onTouchMove(e)},e.addEventListener(document,"touchmove",i.onTouchMove)),i.onTouchEnd||(i.onTouchEnd=function(e){s.onTouchEnd(e)},e.addEventListener(document,"touchend",i.onTouchEnd)))},e.prototype.onTouchMove=function(t){var i=this.eventParams; if(t.scale&&1!==t.scale&&(i.zoomed=!0),i.zoomed){if(this.options.zoomable){i.zoomed=!0;var s=t.scale,n=i.end.valueOf()-i.start.valueOf(),o=n/s,a=o-n,r=new Date(parseInt(i.start.valueOf()-a/2)),h=new Date(parseInt(i.end.valueOf()+a/2));this.setVisibleChartRange(r,h),timeline.trigger("rangechange"),e.preventDefault(t)}}else this.onMouseMove(t)},e.prototype.onTouchEnd=function(t){var i=this.eventParams;i.touchDown=!1,i.zoomed&&timeline.trigger("rangechanged"),i.onTouchMove&&(e.removeEventListener(document,"touchmove",i.onTouchMove),delete i.onTouchMove),i.onTouchEnd&&(e.removeEventListener(document,"touchend",i.onTouchEnd),delete i.onTouchEnd),this.onMouseUp(t)},e.prototype.onMouseDown=function(t){t=t||window.event;var i=this.eventParams,s=this.options,n=this.dom,o=t.which?1==t.which:1==t.button;if(o||i.touchDown){if(this.recalcSize(),i.touchDown?(i.mouseX=t.targetTouches[0].clientX,i.mouseY=t.targetTouches[0].clientY):(i.mouseX=t.clientX,i.mouseY=t.clientY),void 0===i.mouseX&&(i.mouseX=0),void 0===i.mouseY&&(i.mouseY=0),i.frameLeft=e.getAbsoluteLeft(this.dom.content),i.frameTop=e.getAbsoluteTop(this.dom.content),i.previousLeft=0,i.previousOffset=0,i.moved=!1,i.start=new Date(this.start),i.end=new Date(this.end),i.target=e.getTarget(t),i.itemDragLeft=i.target===this.dom.items.dragLeft,i.itemDragRight=i.target===this.dom.items.dragRight,i.itemIndex=i.itemDragLeft||i.itemDragRight?this.selection?this.selection.index:void 0:this.getItemIndex(i.target),i.customTime=i.target===n.customTime||i.target.parentNode===n.customTime?this.customTime:void 0,i.addItem=s.editable&&t.ctrlKey,i.addItem){var a=i.mouseX-i.frameLeft,r=i.mouseY-i.frameTop,h=this.screenToTime(a);s.snapEvents&&this.step.snap(h);var l=new Date(h),d="New",p=this.getGroupFromHeight(r);this.addItem({start:h,end:l,content:d,group:p.content}),i.itemIndex=this.items.length-1,this.selectItem(i.itemIndex),i.itemDragRight=!0}if(i.editItem=s.editable?this.isSelected(i.itemIndex):void 0,i.editItem){var c=this.items[i.itemIndex];i.itemStart=c.start,i.itemEnd=c.end,i.itemType=c.type,"range"==i.itemType?(i.itemLeft=this.timeToScreen(c.start),i.itemRight=this.timeToScreen(c.end)):i.itemLeft=this.timeToScreen(c.start)}else this.dom.frame.style.cursor="move";if(!i.touchDown){var u=this;i.onMouseMove||(i.onMouseMove=function(e){u.onMouseMove(e)},e.addEventListener(document,"mousemove",i.onMouseMove)),i.onMouseUp||(i.onMouseUp=function(e){u.onMouseUp(e)},e.addEventListener(document,"mouseup",i.onMouseUp)),e.preventDefault(t)}}},e.prototype.onMouseMove=function(t){t=t||window.event;var i=this.eventParams,s=this.size,n=this.dom,o=this.options;if(i.touchDown)var a=t.targetTouches[0].clientX,r=t.targetTouches[0].clientY;else var a=t.clientX,r=t.clientY;void 0===a&&(a=0),void 0===r&&(r=0),void 0===i.mouseX&&(i.mouseX=a),void 0===i.mouseY&&(i.mouseY=r);{var h=parseFloat(a)-i.mouseX;parseFloat(r)-i.mouseY}if(i.moved=!0,i.customTime){var l=this.timeToScreen(i.customTime),d=l+h;this.customTime=this.screenToTime(d),this.redrawCustomTime(),this.trigger("timechange")}else if(i.editItem){{var p,c,u=this.items[i.itemIndex];u.dom}if(i.itemDragLeft?(p=i.itemLeft+h,c=i.itemRight,u.start=this.screenToTime(p),o.snapEvents&&(this.step.snap(u.start),p=this.timeToScreen(u.start)),p>c&&(p=c,u.start=this.screenToTime(p))):i.itemDragRight?(p=i.itemLeft,c=i.itemRight+h,u.end=this.screenToTime(c),o.snapEvents&&(this.step.snap(u.end),c=this.timeToScreen(u.end)),p>c&&(c=p,u.end=this.screenToTime(c))):(p=i.itemLeft+h,u.start=this.screenToTime(p),o.snapEvents&&(this.step.snap(u.start),p=this.timeToScreen(u.start)),u.end&&(c=p+(i.itemRight-i.itemLeft),u.end=this.screenToTime(c))),this.repositionItem(u,p,c),0==this.groups.length)this.stackEvents(o.animate),o.animate||this.redrawFrame();else if(o.groupsChangeable){var m=r-i.frameTop,g=this.getGroupFromHeight(m);if(u.group!==g){var v=this.items.indexOf(u);this.changeItem(v,{group:g.content}),u.top=g.top,this.repositionItem(u)}}this.redrawDeleteButton(),this.redrawDragAreas()}else if(o.moveable){var f=i.end.valueOf()-i.start.valueOf(),y=Math.round(parseFloat(-h)/s.contentWidth*f),x=new Date(i.start.valueOf()+y),D=new Date(i.end.valueOf()+y);this.applyRange(x,D);var S=this.start.valueOf()-x.valueOf();S&&(y+=S),this.recalcConversion();var M=i.previousLeft||0,w=parseFloat(n.items.frame.style.left)||0,T=i.previousOffset||0,C=T+(w-M),E=-y/f*s.contentWidth+C;i.previousOffset=C,i.previousLeft=E,n.items.frame.style.left=E+"px",this.redrawCurrentTime(),this.redrawCustomTime(),this.redrawAxis(),this.trigger("rangechange")}e.preventDefault(t)},e.prototype.onMouseUp=function(t){var i=this.eventParams,s=this.options;if(t=t||window.event,this.dom.frame.style.cursor="auto",i.onMouseMove&&(e.removeEventListener(document,"mousemove",i.onMouseMove),delete i.onMouseMove),i.onMouseUp&&(e.removeEventListener(document,"mouseup",i.onMouseUp),delete i.onMouseUp),i.customTime)this.trigger("timechanged");else if(i.editItem){var n=this.items[i.itemIndex];if(i.moved||i.addItem){if(this.applyChange=!0,this.applyAdd=!0,this.updateData(i.itemIndex,{start:n.start,end:n.end}),this.trigger(i.addItem?"add":"change"),i.addItem)this.applyAdd?this.updateData(i.itemIndex,{start:n.start,end:n.end,content:n.content,group:n.group?n.group.content:void 0}):this.deleteItem(i.itemIndex);else if(this.applyChange)this.updateData(i.itemIndex,{start:n.start,end:n.end});else{delete this.applyChange,delete this.applyAdd;{var n=this.items[i.itemIndex];n.dom}n.start=i.itemStart,n.end=i.itemEnd,this.repositionItem(n,i.itemLeft,i.itemRight)}this.recalcSize(),this.stackEvents(s.animate),s.animate||this.redrawFrame(),this.redrawDeleteButton(),this.redrawDragAreas()}}else i.moved||i.zoomed?(this.redrawFrame(),(i.moved&&s.moveable||i.zoomed&&s.zoomable)&&this.trigger("rangechanged")):s.editable&&i.target===this.dom.items.deleteButton?(this.selection&&this.confirmDeleteItem(this.selection.index),this.redrawFrame()):s.selectable&&(void 0!==i.itemIndex?this.isSelected(i.itemIndex)||(this.selectItem(i.itemIndex),this.redrawDeleteButton(),this.redrawDragAreas(),this.trigger("select")):(this.unselectItem(),this.redrawDeleteButton(),this.redrawDragAreas()))},e.prototype.onDblClick=function(t){var i=this.eventParams,s=this.options,n=this.dom,o=this.size;if(t=t||window.event,s.editable){if(void 0!==i.itemIndex)this.trigger("edit");else{var a=t.clientX-e.getAbsoluteLeft(n.content),r=t.clientY-e.getAbsoluteTop(n.content),h=this.screenToTime(a),l=this.screenToTime(a+o.frameWidth/10);s.snapEvents&&(this.step.snap(h),this.step.snap(l));var d="New",p=this.getGroupFromHeight(r);this.addItem({start:h,end:l,content:d,group:p.content}),i.itemIndex=this.items.length-1,this.selectItem(i.itemIndex),this.applyAdd=!0,this.trigger("add"),this.applyAdd||this.deleteItem(i.itemIndex),this.redrawDeleteButton(),this.redrawDragAreas()}e.preventDefault(t)}},e.prototype.onMouseWheel=function(t){if(this.options.zoomable){t||(t=window.event);var i=0;if(t.wheelDelta?i=t.wheelDelta/120:t.detail&&(i=-t.detail/3),i){var s=this,n=function(){s.recalcSize();var n=i/5,o=e.getAbsoluteLeft(s.dom.content),a=void 0!=t.clientX&&void 0!=o?s.screenToTime(t.clientX-o):void 0;s.zoom(n,a),s.trigger("rangechange"),s.trigger("rangechanged")};n()}e.preventDefault(t)}},e.prototype.zoom=function(e,t){void 0==t&&(t=new Date((this.start.valueOf()+this.end.valueOf())/2)),e>=1&&(e=.9),-1>=e&&(e=-.9),0>e&&(e/=1+e);var i=parseFloat(this.start.valueOf()-t.valueOf()),s=parseFloat(this.end.valueOf()-t.valueOf()),n=new Date(this.start.valueOf()-i*e),o=new Date(this.end.valueOf()-s*e);this.applyRange(n,o,t),this.recalcSize();var a=this.options.animate?this.options.animateZoom:!1;this.stackEvents(a),(!a||this.groups.length>0)&&this.redrawFrame()},e.prototype.move=function(e){var t=parseFloat(this.end.valueOf()-this.start.valueOf()),i=new Date(this.start.valueOf()+t*e),s=new Date(this.end.valueOf()+t*e);this.applyRange(i,s),this.recalcConversion(),this.redrawFrame()},e.prototype.repositionItem=function(e,t,i){var s=e.dom;switch(e.type){case"range":s.style.left=t+"px",s.style.width=Math.max(i-t,1)+"px";break;case"box":s.style.left=t-e.width/2+"px",s.line.style.left=t-e.lineWidth/2+"px",s.dot.style.left=t-e.dotWidth/2+"px";break;case"dot":s.style.left=t-e.dotWidth/2+"px"}this.groups.length>0&&(s.style.top=e.top+"px")},e.prototype.applyRange=function(e,t,i){var s=e.valueOf(),n=t.valueOf(),o=n-s,a=this.options,r=31536e6,h=Number(a.intervalMin)||10;10>h&&(h=10);var l=Number(a.intervalMax)||1e4*r;l>1e4*r&&(l=1e4*r),h>l&&(l=h);var d=a.min?a.min.valueOf():void 0,p=a.max?a.max.valueOf():void 0;if(d&&p){if(d>=p){var c=864e5;p=d+c}l>p-d&&(l=p-d),h>p-d&&(h=p-d)}if(s>=n&&(n+=864e5),h>o){var u=h-o,m=i?(i.valueOf()-s)/o:.5;s-=Math.round(u*m),n+=Math.round(u*(1-m))}if(o>l){var u=o-l,m=i?(i.valueOf()-s)/o:.5;s+=Math.round(u*m),n-=Math.round(u*(1-m))}if(d){var u=s-d;0>u&&(s-=u,n-=u)}if(p){var u=p-n;0>u&&(s+=u,n+=u)}this.start=new Date(s),this.end=new Date(n)},e.prototype.confirmDeleteItem=function(e){this.applyDelete=!0,this.isSelected(e)||this.selectItem(e),this.trigger("delete"),this.applyDelete&&this.deleteItem(e),delete this.applyDelete},e.prototype.deleteItem=function(t){if(t>=this.items.length)throw"Cannot delete row, index out of range";if(this.unselectItem(),this.items.splice(t,1),this.data){if(!e.isArray(this.data))throw"Cannot delete row from data, unknown data type";this.data.splice(t,1)}this.size.dataChanged=!0,this.redrawFrame(),this.recalcSize(),this.stackEvents(this.options.animate),this.options.animate||this.redrawFrame(),this.size.dataChanged=!1},e.prototype.deleteAllItems=function(){if(this.unselectItem(),this.items=[],this.deleteGroups(),this.data){if(!e.isArray(this.data))throw"Cannot delete row from data, unknown data type";this.data.splice(0,this.data.length)}this.size.dataChanged=!0,this.redrawFrame(),this.recalcSize(),this.stackEvents(this.options.animate),this.options.animate||this.redrawFrame(),this.size.dataChanged=!1},e.prototype.getGroupFromHeight=function(e){var t=this.groups,i=this.options,s=this.size,n=e-(i.axisOnTop?s.axis.height:0);if(t){for(var o,a=t.length-1;a>=0;a--)if(o=t[a],n>o.top)return o;return o}return void 0},e.prototype.getItem=function(e){if(e>=this.items.length)throw"Cannot get item, index out of range";var t=this.items[e],i={};return i.start=new Date(t.start),t.end&&(i.end=new Date(t.end)),i.content=t.content,t.group&&(i.group=t.group.content),i},e.prototype.addItem=function(e){var t=[e];this.addItems(t)},e.prototype.addItems=function(e){for(var t=e,i=this.items,s=(this.groups,this.groupIndexes,0),n=t.length;n>s;s++){var o=e[s];this.addGroup(o.group),i.push(this.createItem(o));var a=i.length-1;this.updateData(a,o)}this.size.dataChanged=!0,this.redrawFrame(),this.recalcSize(),this.stackEvents(!1),this.redrawFrame(),this.size.dataChanged=!1},e.prototype.createItem=function(e){var t={id:e.id,groupId:e.jobId,status:e.status,start:e.start,end:e.end,content:e.content,type:e.end?"range":this.options.style,group:this.findGroup(e.group),top:0,left:0,width:0,height:0,lineWidth:0,dotWidth:0,dotHeight:0};return t},e.prototype.changeItem=function(e,t){if(e>=this.items.length)throw"Cannot change item, index out of range";var i=(this.options.style,this.items[e]);t.start&&(i.start=t.start),t.end&&(i.end=t.end),t.content&&(i.content=t.content),t.group&&(i.group=this.addGroup(t.group)),this.updateData(e,t),this.size.dataChanged=!0,this.redrawFrame(),this.recalcSize(),this.stackEvents(!1),this.redrawFrame(),this.size.dataChanged=!1},e.prototype.findGroup=function(e){var t=this.groupIndexes[e];return void 0!=t?this.groups[t]:void 0},e.prototype.deleteGroups=function(){this.groups=[],this.groupIndexes={}},e.prototype.addGroup=function(e){var t=this.groups,i=this.groupIndexes,s=void 0,n=i[e];if(void 0===n&&void 0!==e){s={content:e,labelTop:0,lineTop:0},t.push(s),t.sort(this.options.axisOnTop?function(e,t){return e.content>t.content}:function(e,t){return e.contento;o++)i[t[o].content]=o}else s=t[n];return s},e.prototype.cancelChange=function(){this.applyChange=!1},e.prototype.cancelDelete=function(){this.applyDelete=!1},e.prototype.cancelAdd=function(){this.applyAdd=!1},e.prototype.setSelection=function(e){if(void 0!=e&&e.length>0){if(void 0!=e[0].row){var t=e[0].row;if(this.items[t]){var i=this.items[t];this.selectItem(t);var s=i.start,n=i.end;if(void 0!=n)var o=new Date((n.valueOf()+s.valueOf())/2);else var o=new Date(s);var a=this.end.valueOf()-this.start.valueOf(),r=new Date(o.valueOf()-a/2),h=new Date(o.valueOf()+a/2);return this.setVisibleChartRange(r,h),!0}}}else this.unselectItem();return!1},e.prototype.getSelection=function(){var e=[];return this.selection&&e.push({row:this.selection.index}),e},e.prototype.selectItem=function(e){if(this.unselectItem(),this.selection=void 0,void 0!==this.items[e]){var t=this.items[e],i=t.dom;switch(this.selection={index:e,item:i},this.options.editable&&(i.style.cursor="move"),t.type){case"range":i.className=i.className+" timeline-event-selected";break;case"box":i.className="timeline-event timeline-event-selected timeline-event-box",i.line.className="timeline-event timeline-event-selected timeline-event-line",i.dot.className="timeline-event timeline-event-selected timeline-event-dot";break;case"dot":i.className="timeline-event timeline-event-selected",i.dot.className="timeline-event timeline-event-selected timeline-event-dot"}}},e.prototype.isSelected=function(e){return this.selection&&this.selection.index===e},e.prototype.unselectItem=function(){if(this.selection){var e=this.items[this.selection.index];if(e&&e.dom){var t=e.dom;switch(t.style.cursor="",e.type){case"range":t.className=t.className.replace(" timeline-event-selected","");break;case"box":t.className="timeline-event timeline-event-box",t.line.className="timeline-event timeline-event-line",t.dot.className="timeline-event timeline-event-dot";break;case"dot":t.className="",t.dot.className="timeline-event timeline-event-dot"}}}this.selection=void 0},e.prototype.stackEvents=function(e){if(!(0==this.options.stackEvents||this.groups.length>0)){void 0==e&&(e=!0);var t=this.stackOrder(this.items),i=this.stackCalculateFinal(t,e),s=this.groupOrder(this.items),n=this.groupStackCalculateFinal(s,e);t=s,i=n;var o=this.animation;o||(o={},this.animation=o),o.finalItems=i;var a=this,r=function(){var e=a.stackMoveOneStep(t,o.finalItems);a.recalcSize(),a.redrawFrame(),e?(delete o.finalItems,delete o.timer):o.timer=setTimeout(r,30)};o.timer||(o.timer=setTimeout(r,30))}},e.prototype.stackOrder=function(e){var t=e.concat([]),i=function(e,t){return"range"==e.type&&"range"!=t.type?-1:"range"!=e.type&&"range"==t.type?1:e.left-t.left};return t.sort(i),t},e.prototype.groupOrder=function(e){for(var t=[],i=[],s=e.concat([]),n=[],o=s.length-1;o>=0;o--)"undefined"==typeof t[s[o].groupId]&&(t[s[o].groupId]=[],i.push({groupId:s[o].groupId,content:s[o].content})),t[s[o].groupId].push(s[o]);i.sort(function(e,t){return e.contentt.content?1:0});for(var o=0;oh;h++){var d,p,c,u,m=e[h],g=m.height,v=m.width;switch(d=n?i+a+o/2:i-g-a-o/2,u=d+g,m.type){case"range":case"dot":p=this.timeToScreen(m.start),c=m.end?this.timeToScreen(m.end):p+v;break;case"box":p=this.timeToScreen(m.start)-v/2,c=p+v}r[h]={left:p,top:d,right:c,bottom:u,height:g,item:m}}for(var h=0,l=r.length;l>h;h++){var f=r[h],y=null;do y=this.stackEventsCheckOverlap(r,h,0,h-1),null!=y&&(f.top=n?y.top+y.height+o:y.top-f.height-o,f.bottom=f.top+f.height);while(y)}return r},e.prototype.groupStackCalculateFinal=function(e){for(var t=this.size,i=t.axis.top,s=this.options,n=s.axisOnTop,o=s.eventMargin,a=s.eventMarginAxis,r=[],h=0;hi;i++){var n=t[i],o=n.item,a=parseInt(o.top),r=parseInt(n.top),h=r-a;if(h){var l=r==a?0:r>a?1:-1;Math.abs(h)>4&&(l=h/4);var d=parseInt(a+l);d!=r&&(s=!1),o.top=d,o.bottom=o.top+o.height}else o.top=n.top,o.bottom=n.bottom;o.left=n.left,o.right=n.right}return s},e.prototype.stackMoveToFinal=function(e,t){for(i=0,iMax=e.length;iMax>i;i++){var s=e[i],n=t[i];s.left=n.left,s.top=n.top,s.right=n.right,s.bottom=n.bottom}},e.prototype.stackEventsCheckOverlap=function(e,t,i,s){eventMargin=this.options.eventMargin,collision=this.collision;for(var n=e[t],o=s;o>=i;o--){var a=e[o];if(collision(n,a,eventMargin)&&o!=t)return a}},e.prototype.collision=function(e,t,i){return void 0==i&&(i=0),e.left-it.left&&e.top-it.top},e.prototype.trigger=function(t){var i=null;switch(t){case"rangechange":case"rangechanged":i={start:new Date(this.start),end:new Date(this.end)};break;case"timechange":case"timechanged":i={time:new Date(this.customTime)}}e.events.trigger(this,t,i)},e.events=e.events||{listeners:[],indexOf:function(e){for(var t=this.listeners,i=0,s=this.listeners.length;s>i;i++){var n=t[i];if(n&&n.object==e)return i}return-1},addListener:function(e,t,i){var s=this.indexOf(e),n=this.listeners[s];n||(n={object:e,events:{}},this.listeners.push(n));var o=n.events[t];o||(o=[],n.events[t]=o),-1==o.indexOf(i)&&o.push(i)},removeListener:function(e,t,i){var s=this.indexOf(e),n=this.listeners[s];if(n){var o=n.events[t];if(o){var s=o.indexOf(i);-1!=s&&o.splice(s,1),0==o.length&&delete n.events[t]}var a=0,r=n.events;for(var t in r)r.hasOwnProperty(t)&&a++;0==a&&delete this.listeners[s]}},removeAllListeners:function(){this.listeners=[]},trigger:function(e,t,i){var s=this.indexOf(e),n=this.listeners[s];if(n){var o=n.events[t];if(o)for(var a=0,r=o.length;r>a;a++)o[a](i)}}},e.StepDate=function(t){this.options=t,this.current=this.getDate(),this._start=this.getDate(),this._end=this.getDate(),this.autoScale=!0,this.scale=e.StepDate.SCALE.DAY,this.step=1,this.setRange(t.start,t.end,t.minimumStep)},e.StepDate.SCALE={MILLISECOND:1,SECOND:2,MINUTE:3,HOUR:4,DAY:5,MONTH:6,YEAR:7},e.StepDate.prototype.getDate=function(e){return this.options.utc?e?new XDate(e,!0):new XDate(!0):e?new XDate(e):new XDate},e.StepDate.prototype.setRange=function(e,t,i){isNaN(e)||isNaN(t)||(this._start=void 0!=e?this.getDate(e):this.getDate(),this._end=void 0!=t?this.getDate(t):this.getDate(),this.autoScale&&this.setMinimumStep(i))},e.StepDate.prototype.start=function(){this.current=this.getDate(this._start),this.roundToMinor()},e.StepDate.prototype.roundToMinor=function(){switch(this.scale){case e.StepDate.SCALE.YEAR:this.current.setFullYear(this.step*Math.floor(this.current.getFullYear()/this.step)),this.current.setMonth(0);case e.StepDate.SCALE.MONTH:this.current.setDate(1);case e.StepDate.SCALE.DAY:this.current.setHours(0);case e.StepDate.SCALE.HOUR:this.current.setMinutes(0);case e.StepDate.SCALE.MINUTE:this.current.setSeconds(0);case e.StepDate.SCALE.SECOND:this.current.setMilliseconds(0)}if(1!=this.step)switch(this.scale){case e.StepDate.SCALE.MILLISECOND:this.current.setMilliseconds(this.current.getMilliseconds()-this.current.getMilliseconds()%this.step);break;case e.StepDate.SCALE.SECOND:this.current.setSeconds(this.current.getSeconds()-this.current.getSeconds()%this.step);break;case e.StepDate.SCALE.MINUTE:this.current.setMinutes(this.current.getMinutes()-this.current.getMinutes()%this.step);break;case e.StepDate.SCALE.HOUR:this.current.setHours(this.current.getHours()-this.current.getHours()%this.step);break;case e.StepDate.SCALE.DAY:this.current.setDate(this.current.getDate()-1-(this.current.getDate()-1)%this.step+1);break;case e.StepDate.SCALE.MONTH:this.current.setMonth(this.current.getMonth()-this.current.getMonth()%this.step);break;case e.StepDate.SCALE.YEAR:this.current.setFullYear(this.current.getFullYear()-this.current.getFullYear()%this.step)}},e.StepDate.prototype.end=function(){return this.current.getTime()>this._end.getTime()},e.StepDate.prototype.next=function(){var t=this.current.getTime();if(this.current.getMonth()<6)switch(this.scale){case e.StepDate.SCALE.MILLISECOND:this.current=this.getDate(this.current.getTime()+this.step,!0);break;case e.StepDate.SCALE.SECOND:this.current=this.getDate(this.current.getTime()+1e3*this.step);break;case e.StepDate.SCALE.MINUTE:this.current=this.getDate(this.current.getTime()+1e3*this.step*60);break;case e.StepDate.SCALE.HOUR:this.current=this.getDate(this.current.getTime()+1e3*this.step*60*60);var i=this.current.getHours();this.current.setHours(i-i%this.step);break;case e.StepDate.SCALE.DAY:this.current.setDate(this.current.getDate()+this.step);break;case e.StepDate.SCALE.MONTH:this.current.setMonth(this.current.getMonth()+this.step);break;case e.StepDate.SCALE.YEAR:this.current.setFullYear(this.current.getFullYear()+this.step)}else switch(this.scale){case e.StepDate.SCALE.MILLISECOND:this.current=this.getDate(this.current.getTime()+this.step);break;case e.StepDate.SCALE.SECOND:this.current.setSeconds(this.current.getSeconds()+this.step);break;case e.StepDate.SCALE.MINUTE:this.current.setMinutes(this.current.getMinutes()+this.step);break;case e.StepDate.SCALE.HOUR:this.current.setHours(this.current.getHours()+this.step);break;case e.StepDate.SCALE.DAY:this.current.setDate(this.current.getDate()+this.step);break;case e.StepDate.SCALE.MONTH:this.current.setMonth(this.current.getMonth()+this.step);break;case e.StepDate.SCALE.YEAR:this.current.setFullYear(this.current.getFullYear()+this.step)}if(1!=this.step)switch(this.scale){case e.StepDate.SCALE.MILLISECOND:this.current.getMilliseconds()0&&(this.step=t),this.autoScale=!1},e.StepDate.prototype.setAutoScale=function(e){this.autoScale=e},e.StepDate.prototype.setMinimumStep=function(t){if(void 0!=t){var i=31104e6,s=2592e6,n=864e5,o=36e5,a=6e4,r=1e3,h=1;1e3*i>t&&(this.scale=e.StepDate.SCALE.YEAR,this.step=1e3),500*i>t&&(this.scale=e.StepDate.SCALE.YEAR,this.step=500),100*i>t&&(this.scale=e.StepDate.SCALE.YEAR,this.step=100),50*i>t&&(this.scale=e.StepDate.SCALE.YEAR,this.step=50),10*i>t&&(this.scale=e.StepDate.SCALE.YEAR,this.step=10),5*i>t&&(this.scale=e.StepDate.SCALE.YEAR,this.step=5),i>t&&(this.scale=e.StepDate.SCALE.YEAR,this.step=1),3*s>t&&(this.scale=e.StepDate.SCALE.MONTH,this.step=3),s>t&&(this.scale=e.StepDate.SCALE.MONTH,this.step=1),5*n>t&&(this.scale=e.StepDate.SCALE.DAY,this.step=5),2*n>t&&(this.scale=e.StepDate.SCALE.DAY,this.step=2),n>t&&(this.scale=e.StepDate.SCALE.DAY,this.step=1),4*o>t&&(this.scale=e.StepDate.SCALE.HOUR,this.step=4),o>t&&(this.scale=e.StepDate.SCALE.HOUR,this.step=1),15*a>t&&(this.scale=e.StepDate.SCALE.MINUTE,this.step=15),10*a>t&&(this.scale=e.StepDate.SCALE.MINUTE,this.step=10),5*a>t&&(this.scale=e.StepDate.SCALE.MINUTE,this.step=5),a>t&&(this.scale=e.StepDate.SCALE.MINUTE,this.step=1),15*r>t&&(this.scale=e.StepDate.SCALE.SECOND,this.step=15),10*r>t&&(this.scale=e.StepDate.SCALE.SECOND,this.step=10),5*r>t&&(this.scale=e.StepDate.SCALE.SECOND,this.step=5),r>t&&(this.scale=e.StepDate.SCALE.SECOND,this.step=1),200*h>t&&(this.scale=e.StepDate.SCALE.MILLISECOND,this.step=200),100*h>t&&(this.scale=e.StepDate.SCALE.MILLISECOND,this.step=100),50*h>t&&(this.scale=e.StepDate.SCALE.MILLISECOND,this.step=50),10*h>t&&(this.scale=e.StepDate.SCALE.MILLISECOND,this.step=10),5*h>t&&(this.scale=e.StepDate.SCALE.MILLISECOND,this.step=5),h>t&&(this.scale=e.StepDate.SCALE.MILLISECOND,this.step=1)}},e.StepDate.prototype.snap=function(t){if(this.scale==e.StepDate.SCALE.YEAR){var i=t.getFullYear()+Math.round(t.getMonth()/12);t.setFullYear(Math.round(i/this.step)*this.step),t.setMonth(0),t.setDate(0),t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0)}else if(this.scale==e.StepDate.SCALE.MONTH)t.getDate()>15?(t.setDate(1),t.setMonth(t.getMonth()+1)):t.setDate(1),t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0);else if(this.scale==e.StepDate.SCALE.DAY){switch(this.step){case 5:case 2:t.setHours(24*Math.round(t.getHours()/24));break;default:t.setHours(12*Math.round(t.getHours()/12))}t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0)}else if(this.scale==e.StepDate.SCALE.HOUR){switch(this.step){case 4:t.setMinutes(60*Math.round(t.getMinutes()/60));break;default:t.setMinutes(30*Math.round(t.getMinutes()/30))}t.setSeconds(0),t.setMilliseconds(0)}else if(this.scale==e.StepDate.SCALE.MINUTE){switch(this.step){case 15:case 10:t.setMinutes(5*Math.round(t.getMinutes()/5)),t.setSeconds(0);break;case 5:t.setSeconds(60*Math.round(t.getSeconds()/60));break;default:t.setSeconds(30*Math.round(t.getSeconds()/30))}t.setMilliseconds(0)}else if(this.scale==e.StepDate.SCALE.SECOND)switch(this.step){case 15:case 10:t.setSeconds(5*Math.round(t.getSeconds()/5)),t.setMilliseconds(0);break;case 5:t.setMilliseconds(1e3*Math.round(t.getMilliseconds()/1e3));break;default:t.setMilliseconds(500*Math.round(t.getMilliseconds()/500))}else if(this.scale==e.StepDate.SCALE.MILLISECOND){var s=this.step>5?this.step/2:1;t.setMilliseconds(Math.round(t.getMilliseconds()/s)*s)}},e.StepDate.prototype.isMajor=function(){switch(this.scale){case e.StepDate.SCALE.MILLISECOND:return 0==this.current.getMilliseconds();case e.StepDate.SCALE.SECOND:return 0==this.current.getSeconds();case e.StepDate.SCALE.MINUTE:return 0==this.current.getHours()&&0==this.current.getMinutes();case e.StepDate.SCALE.HOUR:return 0==this.current.getHours();case e.StepDate.SCALE.DAY:return 1==this.current.getDate();case e.StepDate.SCALE.MONTH:return 0==this.current.getMonth();case e.StepDate.SCALE.YEAR:return!1;default:return!1}},e.StepDate.prototype.getLabelMinor=function(t){var i=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");switch(void 0==t&&(t=this.current),this.scale){case e.StepDate.SCALE.MILLISECOND:return String(t.getMilliseconds());case e.StepDate.SCALE.SECOND:return String(t.getSeconds());case e.StepDate.SCALE.MINUTE:return this.addZeros(t.getHours(),2)+":"+this.addZeros(t.getMinutes(),2);case e.StepDate.SCALE.HOUR:return this.addZeros(t.getHours(),2)+":"+this.addZeros(t.getMinutes(),2);case e.StepDate.SCALE.DAY:return String(t.getDate());case e.StepDate.SCALE.MONTH:return i[t.getMonth()];case e.StepDate.SCALE.YEAR:return String(t.getFullYear());default:return""}},e.StepDate.prototype.getLabelMajor=function(t){var i=new Array("January","February","March","April","May","June","July","August","September","October","November","December"),s=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");switch(void 0==t&&(t=this.current),this.scale){case e.StepDate.SCALE.MILLISECOND:return this.addZeros(t.getHours(),2)+":"+this.addZeros(t.getMinutes(),2)+":"+this.addZeros(t.getSeconds(),2);case e.StepDate.SCALE.SECOND:return t.getDate()+" "+i[t.getMonth()]+" "+this.addZeros(t.getHours(),2)+":"+this.addZeros(t.getMinutes(),2);case e.StepDate.SCALE.MINUTE:return s[t.getDay()]+" "+t.getDate()+" "+i[t.getMonth()]+" "+t.getFullYear();case e.StepDate.SCALE.HOUR:return s[t.getDay()]+" "+t.getDate()+" "+i[t.getMonth()]+" "+t.getFullYear();case e.StepDate.SCALE.DAY:return i[t.getMonth()]+" "+t.getFullYear();case e.StepDate.SCALE.MONTH:return String(t.getFullYear());default:return""}},e.StepDate.prototype.addZeros=function(e,t){for(var i=""+e;i.length=0&&(t="DOMMouseScroll"),e.addEventListener(t,i,s)):e.attachEvent("on"+t,i)},e.removeEventListener=function(e,t,i,s){e.removeEventListener?(void 0===s&&(s=!1),"mousewheel"===t&&navigator.userAgent.indexOf("Firefox")>=0&&(t="DOMMouseScroll"),e.removeEventListener(t,i,s)):e.detachEvent("on"+t,i)},e.getTarget=function(e){if(!e)var e=window.event;var t;return e.target?t=e.target:e.srcElement&&(t=e.srcElement),void 0!==t.nodeType&&3==t.nodeType&&(t=t.parentNode),t},e.stopPropagation=function(e){if(!e)var e=window.event;e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},e.preventDefault=function(e){if(!e)var e=window.event;e.preventDefault?e.preventDefault():e.returnValue=!1},e.getAbsoluteLeft=function(e){for(var t=0;null!=e;)t+=e.offsetLeft,t-=e.scrollLeft,e=e.offsetParent;return!document.body.scrollLeft&&window.pageXOffset&&(t-=window.pageXOffset),t},e.getAbsoluteTop=function(e){for(var t=0;null!=e;)t+=e.offsetTop,t-=e.scrollTop,e=e.offsetParent;return!document.body.scrollTop&&window.pageYOffset&&(t-=window.pageYOffset),t},e.isArray=function(e){return e instanceof Array?!0:"[object Array]"===Object.prototype.toString.call(e)},e});