vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
71 KiB

11 years ago
11 years ago
11 years ago
  1. /**
  2. * vis.js
  3. * https://github.com/almende/vis
  4. *
  5. * A dynamic, browser-based visualization library.
  6. *
  7. * @version 0.0.7
  8. * @date 2013-05-01
  9. *
  10. * @license
  11. * Copyright (C) 2011-2013 Almende B.V, http://almende.com
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  14. * use this file except in compliance with the License. You may obtain a copy
  15. * of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  22. * License for the specific language governing permissions and limitations under
  23. * the License.
  24. */
  25. (function(t){if("function"==typeof bootstrap)bootstrap("vis",t);else if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeVis=t}else"undefined"!=typeof window?window.vis=t():global.vis=t()})(function(){var t;return function(t,e,n){function i(n,o){if(!e[n]){if(!t[n]){var s="function"==typeof require&&require;if(!o&&s)return s(n,!0);if(r)return r(n,!0);throw Error("Cannot find module '"+n+"'")}var a=e[n]={exports:{}};t[n][0].call(a.exports,function(e){var r=t[n][1][e];return i(r?r:e)},a,a.exports)}return e[n].exports}for(var r="function"==typeof require&&require,o=0;n.length>o;o++)i(n[o]);return i}({1:[function(e,n,i){function r(t){var e=this;this.options=t||{},this.data={},this.fieldId=this.options.fieldId||"id",this.fieldTypes={},this.options.fieldTypes&&S.forEach(this.options.fieldTypes,function(t,n){e.fieldTypes[n]="Date"==t||"ISODate"==t||"ASPDate"==t?"Date":t}),this.subscribers={},this.internalIds={}}function o(t,e){this.parent=t,this.options={order:function(t,e){return e.width-t.width||t.left-e.left}},this.ordered=[],this.setOptions(e)}function s(t){this.id=S.randomUUID(),this.start=0,this.end=0,this.options={min:null,max:null,zoomMin:null,zoomMax:null},this.setOptions(t),this.listeners=[]}function a(){this.id=S.randomUUID(),this.components={},this.repaintTimer=void 0,this.reflowTimer=void 0}function h(){this.id=null,this.parent=null,this.depends=null,this.controller=null,this.options=null,this.frame=null,this.top=0,this.left=0,this.width=0,this.height=0}function c(t,e,n){this.id=S.randomUUID(),this.parent=t,this.depends=e,this.options={},this.setOptions(n)}function p(t,e){this.id=S.randomUUID(),this.container=t,this.options={autoResize:!0},this.listeners={},this.setOptions(e)}function u(t,e,n){this.id=S.randomUUID(),this.parent=t,this.depends=e,this.dom={majorLines:[],majorTexts:[],minorLines:[],minorTexts:[],redundant:{majorLines:[],majorTexts:[],minorLines:[],minorTexts:[]}},this.props={range:{start:0,end:0,minimumStep:0},lineTop:0},this.options={orientation:"bottom",showMinorLabels:!0,showMajorLabels:!0},this.conversion=null,this.range=null,this.setOptions(n)}function d(t,e,n){this.id=S.randomUUID(),this.parent=t,this.depends=e,this.options={style:"box",align:"center",orientation:"bottom",margin:{axis:20,item:10},padding:5},this.dom={};var i=this;this.data=null,this.range=null,this.listeners={add:function(t,e){i._onAdd(e.items)},update:function(t,e){i._onUpdate(e.items)},remove:function(t,e){i._onRemove(e.items)}},this.items={},this.queue={},this.stack=new o(this),this.conversion=null,this.setOptions(n)}function l(t,e,n){this.parent=t,this.data=e,this.selected=!1,this.visible=!0,this.dom=null,this.options=n}function f(t,e,n){this.props={dot:{left:0,top:0,width:0,height:0},line:{top:0,left:0,width:0,height:0}},l.call(this,t,e,n)}function m(t,e,n){this.props={dot:{top:0,width:0,height:0},content:{height:0,marginLeft:0}},l.call(this,t,e,n)}function g(t,e,n){this.props={content:{left:0,width:0}},l.call(this,t,e,n)}function v(t,e,n){var i=this;if(this.options={orientation:"bottom",zoomMin:10,zoomMax:31536e10,moveable:!0,zoomable:!0},this.controller=new a,!t)throw Error("No container element provided");this.main=new p(t,{autoResize:!1,height:function(){return i.timeaxis.height+i.itemset.height}}),this.controller.add(this.main);var r=y().hours(0).minutes(0).seconds(0).milliseconds(0);this.range=new s({start:r.clone().add("days",-3).valueOf(),end:r.clone().add("days",4).valueOf()}),this.range.subscribe(this.main,"move","horizontal"),this.range.subscribe(this.main,"zoom","horizontal"),this.range.on("rangechange",function(){i.controller.requestReflow()}),this.range.on("rangechanged",function(){i.controller.requestReflow()}),this.timeaxis=new u(this.main,[],{orientation:this.options.orientation,range:this.range}),this.timeaxis.setRange(this.range),this.controller.add(this.timeaxis),this.itemset=new d(this.main,[this.timeaxis],{orientation:this.options.orientation}),this.itemset.setRange(this.range),this.controlle
  26. },h.prototype.getContainer=function(){return null},h.prototype.getFrame=function(){return this.frame},h.prototype.repaint=function(){return!1},h.prototype.reflow=function(){return!1},h.prototype.requestRepaint=function(){if(!this.controller)throw Error("Cannot request a repaint: no controller configured");this.controller.requestRepaint()},h.prototype.requestReflow=function(){if(!this.controller)throw Error("Cannot request a reflow: no controller configured");this.controller.requestReflow()},h.prototype.on=function(t,e){if(!this.parent)throw Error("Cannot attach event: no root panel found");this.parent.on(t,e)},c.prototype=new h,c.prototype.getContainer=function(){return this.frame},c.prototype.repaint=function(){var t=0,e=S.updateProperty,n=S.option.asSize,i=this.options,r=this.frame;if(r||(r=document.createElement("div"),r.className="panel",i.className&&("function"==typeof i.className?S.addClassName(r,i.className()+""):S.addClassName(r,i.className+"")),this.frame=r,t+=1),!r.parentNode){if(!this.parent)throw Error("Cannot repaint panel: no parent attached");var o=this.parent.getContainer();if(!o)throw Error("Cannot repaint panel: parent has no container element");o.appendChild(r),t+=1}return t+=e(r.style,"top",n(i.top,"0px")),t+=e(r.style,"left",n(i.left,"0px")),t+=e(r.style,"width",n(i.width,"100%")),t+=e(r.style,"height",n(i.height,"100%")),t>0},c.prototype.reflow=function(){var t=0,e=S.updateProperty,n=this.frame;return n?(t+=e(this,"top",n.offsetTop),t+=e(this,"left",n.offsetLeft),t+=e(this,"width",n.offsetWidth),t+=e(this,"height",n.offsetHeight)):t+=1,t>0},p.prototype=new c,p.prototype.setOptions=function(t){S.extend(this.options,t),this.options.autoResize?this._watch():this._unwatch()},p.prototype.repaint=function(){var t=0,e=S.updateProperty,n=S.option.asSize,i=this.options,r=this.frame;if(r||(r=document.createElement("div"),r.className="graph panel",i.className&&S.addClassName(r,S.option.asString(i.className)),this.frame=r,t+=1),!r.parentNode){if(!this.container)throw Error("Cannot repaint root panel: no container attached");this.container.appendChild(r),t+=1}return t+=e(r.style,"top",n(i.top,"0px")),t+=e(r.style,"left",n(i.left,"0px")),t+=e(r.style,"width",n(i.width,"100%")),t+=e(r.style,"height",n(i.height,"100%")),this._updateEventEmitters(),t>0},p.prototype.reflow=function(){var t=0,e=S.updateProperty,n=this.frame;return n?(t+=e(this,"top",n.offsetTop),t+=e(this,"left",n.offsetLeft),t+=e(this,"width",n.offsetWidth),t+=e(this,"height",n.offsetHeight)):t+=1,t>0},p.prototype._watch=function(){var t=this;this._unwatch();var e=function(){return t.options.autoResize?(t.frame&&(t.frame.clientWidth!=t.width||t.frame.clientHeight!=t.height)&&t.requestReflow(),void 0):(t._unwatch(),void 0)};S.addEventListener(window,"resize",e),this.watchTimer=setInterval(e,1e3)},p.prototype._unwatch=function(){this.watchTimer&&(clearInterval(this.watchTimer),this.watchTimer=void 0)},p.prototype.on=function(t,e){var n=this.listeners[t];n||(n=[],this.listeners[t]=n),n.push(e),this._updateEventEmitters()},p.prototype._updateEventEmitters=function(){if(this.listeners){var t=this;S.forEach(this.listeners,function(e,n){if(t.emitters||(t.emitters={}),!(n in t.emitters)){var i=t.frame;if(i){var r=function(t){e.forEach(function(e){e(t)})};t.emitters[n]=r,S.addEventListener(i,n,r)}}})}},u.prototype=new h,u.prototype.setOptions=function(t){S.extend(this.options,t)},u.prototype.setRange=function(t){if(!(t instanceof s||t&&t.start&&t.end))throw new TypeError("Range must be an instance of Range, or an object containing start and end.");this.range=t},u.prototype.toTime=function(t){var e=this.conversion;return new Date(t/e.factor+e.offset)},u.prototype.toScreen=function(t){var e=this.conversion;return(t.valueOf()-e.offset)*e.factor},u.prototype.repaint=function(){var t=0,e=S.updateProperty,n=S.option.asSize,i=this.options,r=this.props,o=this.step,s=this.frame;if(s||(s=document.createElement("div"),this.frame=s,t+=1),s.className="axis "+i.orientation,!s.parentNode){if(!this.parent)throw Error("Cannot repaint time axis: no parent attached");var a=thi
  27. },dddd:function(t){return this.lang().weekdays(this,t)},w:function(){return this.week()},W:function(){return this.isoWeek()},YY:function(){return u(this.year()%100,2)},YYYY:function(){return u(this.year(),4)},YYYYY:function(){return u(this.year(),5)},a:function(){return this.lang().meridiem(this.hours(),this.minutes(),!0)},A:function(){return this.lang().meridiem(this.hours(),this.minutes(),!1)},H:function(){return this.hours()},h:function(){return this.hours()%12||12},m:function(){return this.minutes()},s:function(){return this.seconds()},S:function(){return~~(this.milliseconds()/100)},SS:function(){return u(~~(this.milliseconds()/10),2)},SSS:function(){return u(this.milliseconds(),3)},Z:function(){var t=-this.zone(),e="+";return 0>t&&(t=-t,e="-"),e+u(~~(t/60),2)+":"+u(~~t%60,2)},ZZ:function(){var t=-this.zone(),e="+";return 0>t&&(t=-t,e="-"),e+u(~~(10*t/6),4)},X:function(){return this.unix()}};oe.length;)H=oe.pop(),ae[H+"o"]=o(ae[H]);for(;se.length;)H=se.pop(),ae[H+H]=r(ae[H],2);for(ae.DDDD=r(ae.DDD,3),s.prototype={set:function(t){var e,n;for(n in t)e=t[n],"function"==typeof e?this[n]=e:this["_"+n]=e},_months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),months:function(t){return this._months[t.month()]},_monthsShort:"Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),monthsShort:function(t){return this._monthsShort[t.month()]},monthsParse:function(t){var e,n,i;for(this._monthsParse||(this._monthsParse=[]),e=0;12>e;e++)if(this._monthsParse[e]||(n=k([2e3,e]),i="^"+this.months(n,"")+"|^"+this.monthsShort(n,""),this._monthsParse[e]=RegExp(i.replace(".",""),"i")),this._monthsParse[e].test(t))return e},_weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),weekdays:function(t){return this._weekdays[t.day()]},_weekdaysShort:"Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),weekdaysShort:function(t){return this._weekdaysShort[t.day()]},_weekdaysMin:"Su_Mo_Tu_We_Th_Fr_Sa".split("_"),weekdaysMin:function(t){return this._weekdaysMin[t.day()]},_longDateFormat:{LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D YYYY",LLL:"MMMM D YYYY LT",LLLL:"dddd, MMMM D YYYY LT"},longDateFormat:function(t){var e=this._longDateFormat[t];return!e&&this._longDateFormat[t.toUpperCase()]&&(e=this._longDateFormat[t.toUpperCase()].replace(/MMMM|MM|DD|dddd/g,function(t){return t.slice(1)}),this._longDateFormat[t]=e),e},meridiem:function(t,e,n){return t>11?n?"pm":"PM":n?"am":"AM"},_calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[last] dddd [at] LT",sameElse:"L"},calendar:function(t,e){var n=this._calendar[t];return"function"==typeof n?n.apply(e):n},_relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},relativeTime:function(t,e,n,i){var r=this._relativeTime[n];return"function"==typeof r?r(t,e,n,i):r.replace(/%d/i,t)},pastFuture:function(t,e){var n=this._relativeTime[t>0?"future":"past"];return"function"==typeof n?n(e):n.replace(/%s/i,e)},ordinal:function(t){return this._ordinal.replace("%d",t)},_ordinal:"%d",preparse:function(t){return t},postformat:function(t){return t},week:function(t){return x(t,this._week.dow,this._week.doy)},_week:{dow:0,doy:6}},k=function(t,e,n){return A({_i:t,_f:e,_l:n,_isUTC:!1})},k.utc=function(t,e,n){return A({_useUTC:!0,_isUTC:!0,_l:n,_i:t,_f:e})},k.unix=function(t){return k(1e3*t)},k.duration=function(t,e){var n,i=k.isDuration(t),r="number"==typeof t,o=i?t._data:r?{}:t;return r&&(e?o[e]=t:o.milliseconds=t),n=new h(o),i&&t.hasOwnProperty("_lang")&&(n._lang=t._lang),n},k.version=I,k.defaultFormat=G,k.lang=function(t,e){return t?(e?m(t,e):R[t]||g(t),k.duration.fn._lang=k.fn._lang=g(t),i):k.fn._lang._abbr},k.langData=function(t){return t&&t._lang&&t._lang._abbr&&(t=t._lang._abbr),g(t)},k.isMoment=function(t){return t instanceof a},k.isDuration=function(t){return t instanceof h},k.fn=a.prototype={clone:function(){return k(this)},valueOf:function(){return+