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
70 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.5
  8. * @date 2013-04-23
  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(){function t(t){var e=this;this.options=t||{},this.data={},this.fieldId=this.options.fieldId||"id",this.fieldTypes={},this.options.fieldTypes&&g.forEach(this.options.fieldTypes,function(t,n){e.fieldTypes[n]="Date"==t||"ISODate"==t||"ASPDate"==t?"Date":t}),this.subscribers={},this.internalIds={}}function e(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 n(t){this.id=g.randomUUID(),this.start=0,this.end=0,this.options={min:null,max:null,zoomMin:null,zoomMax:null},this.setOptions(t),this.listeners=[]}function i(){this.id=g.randomUUID(),this.components={},this.repaintTimer=void 0,this.reflowTimer=void 0}function o(){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 r(t,e,n){this.id=g.randomUUID(),this.parent=t,this.depends=e,this.options={},this.setOptions(n)}function s(t,e){this.id=g.randomUUID(),this.container=t,this.options={autoResize:!0},this.listeners={},this.setOptions(e)}function a(t,e,n){this.id=g.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 h(t,n,i){this.id=g.randomUUID(),this.parent=t,this.depends=n,this.options={style:"box",align:"center",orientation:"bottom",margin:{axis:20,item:10},padding:5};var o=this;this.data=null,this.range=null,this.listeners={add:function(t,e){o._onAdd(e.items)},update:function(t,e){o._onUpdate(e.items)},remove:function(t,e){o._onRemove(e.items)}},this.items={},this.queue={},this.stack=new e(this),this.conversion=null,this.setOptions(i)}function c(t,e,n){this.parent=t,this.data=e,this.selected=!1,this.visible=!0,this.dom=null,this.options=n}function p(t,e,n){this.props={dot:{left:0,top:0,width:0,height:0},line:{top:0,left:0,width:0,height:0}},c.call(this,t,e,n)}function u(t,e,n){this.props={dot:{top:0,width:0,height:0},content:{height:0,marginLeft:0}},c.call(this,t,e,n)}function l(t,e,n){this.props={content:{left:0,width:0}},c.call(this,t,e,n)}function d(t,e,o){var r=this;if(this.options={orientation:"bottom",zoomMin:10,zoomMax:31536e10,moveable:!0,zoomable:!0},this.controller=new i,!t)throw Error("No container element provided");this.main=new s(t,{autoResize:!1,height:function(){return r.timeaxis.height+r.itemset.height}}),this.controller.add(this.main);var c=moment().hours(0).minutes(0).seconds(0).milliseconds(0);this.range=new n({start:c.clone().add("days",-3).valueOf(),end:c.clone().add("days",4).valueOf()}),this.range.subscribe(this.main,"move","horizontal"),this.range.subscribe(this.main,"zoom","horizontal"),this.range.on("rangechange",function(){r.controller.requestReflow()}),this.range.on("rangechanged",function(){r.controller.requestReflow()}),this.timeaxis=new a(this.main,null,{orientation:this.options.orientation,range:this.range}),this.timeaxis.setRange(this.range),this.controller.add(this.timeaxis),this.itemset=new h(this.main,[this.timeaxis],{orientation:this.options.orientation}),this.itemset.setRange(this.range),e&&this.setData(e),this.controller.add(this.itemset),this.setOptions(o)}var f={component:{item:{}}},m=function(t){document.getElementsByTagName("script");var e=document.createElement("style");e.type="text/css",e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t)),document.getElementsByTagName("head")[0].appendChild(e)};"undefined"!=typeof exports&&(exports=f),"undefined"!=typeof module&&(module.exports=f),"function"==typeof define&&define(function(){return f}),"undefined"!=typeof window&&(window.vis=f);var g={};g.isNumber=function(t){return t instanceof Number||"number"==typeof t},g.isString=function(t){return t instanceof String||"string"==typeof t},g.isDate=function(t){if(t instanceof Date)return!0;if(g.isS
  26. this.controller.requestReflow()},o.prototype.on=function(t,e){if(!this.parent)throw Error("Cannot attach event: no root panel found");this.parent.on(t,e)},f.component.Component=o,r.prototype=new o,r.prototype.getContainer=function(){return this.frame},r.prototype.repaint=function(){var t=0,e=g.updateProperty,n=g.option.asSize,i=this.options,o=this.frame;if(o||(o=document.createElement("div"),o.className="panel",i.className&&("function"==typeof i.className?g.addClassName(o,i.className()+""):g.addClassName(o,i.className+"")),this.frame=o,t+=1),!o.parentNode){if(!this.parent)throw Error("Cannot repaint panel: no parent attached");var r=this.parent.getContainer();if(!r)throw Error("Cannot repaint panel: parent has no container element");r.appendChild(o),t+=1}return t+=e(o.style,"top",n(i.top,"0px")),t+=e(o.style,"left",n(i.left,"0px")),t+=e(o.style,"width",n(i.width,"100%")),t+=e(o.style,"height",n(i.height,"100%")),t>0},r.prototype.reflow=function(){var t=0,e=g.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},f.component.Panel=r,s.prototype=new r,s.prototype.setOptions=function(t){g.extend(this.options,t),this.options.autoResize?this._watch():this._unwatch()},s.prototype.repaint=function(){var t=0,e=g.updateProperty,n=g.option.asSize,i=this.options,o=this.frame;if(o||(o=document.createElement("div"),o.className="graph panel",i.className&&g.addClassName(o,g.option.asString(i.className)),this.frame=o,t+=1),!o.parentNode){if(!this.container)throw Error("Cannot repaint root panel: no container attached");this.container.appendChild(o),t+=1}return t+=e(o.style,"top",n(i.top,"0px")),t+=e(o.style,"left",n(i.left,"0px")),t+=e(o.style,"width",n(i.width,"100%")),t+=e(o.style,"height",n(i.height,"100%")),this._updateEventEmitters(),t>0},s.prototype.reflow=function(){var t=0,e=g.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},s.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)};g.addEventListener(window,"resize",e),this.watchTimer=setInterval(e,1e3)},s.prototype._unwatch=function(){this.watchTimer&&(clearInterval(this.watchTimer),this.watchTimer=void 0)},s.prototype.on=function(t,e){var n=this.listeners[t];n||(n=[],this.listeners[t]=n),n.push(e),this._updateEventEmitters()},s.prototype._updateEventEmitters=function(){if(this.listeners){var t=this;g.forEach(this.listeners,function(e,n){if(t.emitters||(t.emitters={}),!(n in t.emitters)){var i=t.frame;if(i){var o=function(t){e.forEach(function(e){e(t)})};t.emitters[n]=o,g.addEventListener(i,n,o)}}})}},f.component.RootPanel=s,a.prototype=new o,a.prototype.setOptions=function(t){g.extend(this.options,t)},a.prototype.setRange=function(t){if(!(t instanceof n||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},a.prototype.toTime=function(t){var e=this.conversion;return new Date(t/e.factor+e.offset)},a.prototype.toScreen=function(t){var e=this.conversion;return(t.valueOf()-e.offset)*e.factor},a.prototype.repaint=function(){var t=0,e=g.updateProperty,n=g.option.asSize,i=this.options,o=this.props,r=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=this.parent.getContainer();if(!a)throw Error("Cannot repaint time axis: parent has no container element");a.appendChild(s),t+=1}var h=s.parentNode;if(h){var c=s.nextSibling;h.removeChild(s);var p=i.orientation,u="bottom"==p&&this.props.parentHeight&&this.height?this.props.parentHeight-this.height+"px":"0px";if(t+=e(s.style,"top",n(i.top,u)),t+=e(s.style,"left",n(i.left,"0px")),t+=e(s.style,"widt
  27. },toDate:function(){return this._d},toJSON:function(){return O.utc(this).format("YYYY-MM-DD[T]HH:mm:ss.SSS[Z]")},toArray:function(){var t=this;return[t.year(),t.month(),t.date(),t.hours(),t.minutes(),t.seconds(),t.milliseconds()]},isValid:function(){return null==this._isValid&&(this._isValid=this._a?!u(this._a,(this._isUTC?O.utc(this._a):O(this._a)).toArray()):!isNaN(this._d.getTime())),!!this._isValid},utc:function(){return this._isUTC=!0,this},local:function(){return this._isUTC=!1,this},format:function(t){var e=g(this,t||O.defaultFormat);return this.lang().postformat(e)},add:function(t,e){var n;return n="string"==typeof t?O.duration(+e,t):O.duration(t,e),c(this,n,1),this},subtract:function(t,e){var n;return n="string"==typeof t?O.duration(+e,t):O.duration(t,e),c(this,n,-1),this},diff:function(t,e,n){var i,o,r=this._isUTC?O(t).utc():O(t).local(),s=6e4*(this.zone()-r.zone());return e&&(e=e.replace(/s$/,"")),"year"===e||"month"===e?(i=432e5*(this.daysInMonth()+r.daysInMonth()),o=12*(this.year()-r.year())+(this.month()-r.month()),o+=(this-O(this).startOf("month")-(r-O(r).startOf("month")))/i,"year"===e&&(o/=12)):(i=this-r-s,o="second"===e?i/1e3:"minute"===e?i/6e4:"hour"===e?i/36e5:"day"===e?i/864e5:"week"===e?i/6048e5:i),n?o:a(o)},from:function(t,e){return O.duration(this.diff(t)).lang(this.lang()._abbr).humanize(!e)},fromNow:function(t){return this.from(O(),t)},calendar:function(){var t=this.diff(O().startOf("day"),"days",!0),e=-6>t?"sameElse":-1>t?"lastWeek":0>t?"lastDay":1>t?"sameDay":2>t?"nextDay":7>t?"nextWeek":"sameElse";return this.format(this.lang().calendar(e,this))},isLeapYear:function(){var t=this.year();return 0===t%4&&0!==t%100||0===t%400},isDST:function(){return this.zone()<O([this.year()]).zone()||this.zone()<O([this.year(),5]).zone()},day:function(t){var e=this._isUTC?this._d.getUTCDay():this._d.getDay();return null==t?e:this.add({d:t-e})},startOf:function(t){switch(t=t.replace(/s$/,"")){case"year":this.month(0);case"month":this.date(1);case"week":case"day":this.hours(0);case"hour":this.minutes(0);case"minute":this.seconds(0);case"second":this.milliseconds(0)}return"week"===t&&this.day(0),this},endOf:function(t){return this.startOf(t).add(t.replace(/s?$/,"s"),1).subtract("ms",1)},isAfter:function(e,n){return n=n!==t?n:"millisecond",+this.clone().startOf(n)>+O(e).startOf(n)},isBefore:function(e,n){return n=n!==t?n:"millisecond",+this.clone().startOf(n)<+O(e).startOf(n)},isSame:function(e,n){return n=n!==t?n:"millisecond",+this.clone().startOf(n)===+O(e).startOf(n)},zone:function(){return this._isUTC?0:this._d.getTimezoneOffset()},daysInMonth:function(){return O.utc([this.year(),this.month()+1,0]).date()},dayOfYear:function(t){var e=H((O(this).startOf("day")-O(this).startOf("year"))/864e5)+1;return null==t?e:this.add("d",t-e)},isoWeek:function(t){var e=D(this,1,4);return null==t?e:this.add("d",7*(t-e))},week:function(t){var e=this.lang().week(this);return null==t?e:this.add("d",7*(t-e))},lang:function(e){return e===t?this._lang:(this._lang=d(e),this)}},N=0;G.length>N;N++)C(G[N].toLowerCase().replace(/s$/,""),G[N]);C("year","FullYear"),O.fn.days=O.fn.day,O.fn.weeks=O.fn.week,O.fn.isoWeeks=O.fn.isoWeek,O.duration.fn=r.prototype={weeks:function(){return a(this.days()/7)},valueOf:function(){return this._milliseconds+864e5*this._days+2592e6*this._months},humanize:function(t){var e=+this,n=_(e,!t,this.lang());return t&&(n=this.lang().pastFuture(e,n)),this.lang().postformat(n)},lang:O.fn.lang};for(N in te)te.hasOwnProperty(N)&&(A(N,te[N]),x(N.toLowerCase()));A("Weeks",6048e5),O.lang("en",{ordinal:function(t){var e=t%10,n=1===~~(t%100/10)?"th":1===e?"st":2===e?"nd":3===e?"rd":"th";return t+n}}),I&&(module.exports=O),"undefined"==typeof ender&&(this.moment=O),"function"==typeof define&&define.amd&&define("moment",[],function(){return O})}.call(this),m("/* vis.js stylesheet */\n\n.graph {\n position: relative;\n border: 1px solid #bfbfbf;\n}\n\n.graph .panel {\n position: absolute;\n}\n\n.graph .itemset {\n position: absolute;\n}\n\n\n.graph .item {\n position: absolute;\n color: #1A1A1A;\n borde