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
85 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.8
  8. * @date 2013-05-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(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,i){function n(i,s){if(!e[i]){if(!t[i]){var o="function"==typeof require&&require;if(!s&&o)return o(i,!0);if(r)return r(i,!0);throw Error("Cannot find module '"+i+"'")}var a=e[i]={exports:{}};t[i][0].call(a.exports,function(e){var r=t[i][1][e];return n(r?r:e)},a,a.exports)}return e[i].exports}for(var r="function"==typeof require&&require,s=0;i.length>s;s++)n(i[s]);return n}({1:[function(e,i,n){function r(t){if(this.id=E.randomUUID(),this.options=t||{},this.data={},this.fieldId=this.options.fieldId||"id",this.fieldTypes={},this.options.fieldTypes)for(var e in this.options.fieldTypes)if(this.options.fieldTypes.hasOwnProperty(e)){var i=this.options.fieldTypes[e];this.fieldTypes[e]="Date"==i||"ISODate"==i||"ASPDate"==i?"Date":i}this.subscribers={},this.internalIds={}}function s(t,e){this.id=E.randomUUID(),this.data=null,this.ids={},this.options=e||{},this.fieldId="id",this.subscribers={};var i=this;this.listener=function(){i._onEvent.apply(i,arguments)},this.setData(t)}function o(t,e){this.parent=t,this.options=Object.create(t&&t.options||0),this.defaultOptions={order:function(t,e){if(t instanceof y){if(e instanceof y){var i=t.data.end-t.data.start,n=e.data.end-e.data.start;return i-n||t.data.start-e.data.start}return-1}return e instanceof y?1:t.data.start-e.data.start},margin:{item:10}},this.ordered=[],this.setOptions(e)}function a(t){this.id=E.randomUUID(),this.start=0,this.end=0,this.options={min:null,max:null,zoomMin:null,zoomMax:null},this.setOptions(t),this.listeners=[]}function h(){this.subscriptions=[]}function p(){this.id=E.randomUUID(),this.components={},this.repaintTimer=void 0,this.reflowTimer=void 0}function u(){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,i){this.id=E.randomUUID(),this.parent=t,this.depends=e,this.options=Object.create(t&&t.options||null),this.setOptions(i)}function d(t,e){this.id=E.randomUUID(),this.container=t,this.options=Object.create(e||null),this.defaultOptions={autoResize:!0},this.listeners={},this.setOptions(e)}function l(t,e,i){this.id=E.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=Object.create(t&&t.options||null),this.defaultOptions={orientation:"bottom",showMinorLabels:!0,showMajorLabels:!0},this.conversion=null,this.range=null,this.setOptions(i)}function f(t,e,i){this.id=E.randomUUID(),this.parent=t,this.depends=e,this.options=Object.create(t&&t.options||null),this.defaultOptions={style:"box",align:"center",orientation:"bottom",margin:{axis:20,item:10},padding:5},this.dom={};var n=this;this.itemsData=null,this.range=null,this.listeners={add:function(t,e,i){i!=n.id&&n._onAdd(e.items)},update:function(t,e,i){i!=n.id&&n._onUpdate(e.items)},remove:function(t,e,i){i!=n.id&&n._onRemove(e.items)}},this.items={},this.queue={},this.stack=new o(this),this.conversion=null,this.setOptions(i)}function m(t,e,i,n){this.parent=t,this.data=e,this.dom=null,this.options=i||{},this.defaultOptions=n||{},this.selected=!1,this.visible=!1,this.top=0,this.left=0,this.width=0,this.height=0}function g(t,e,i,n){this.props={dot:{left:0,top:0,width:0,height:0},line:{top:0,left:0,width:0,height:0}},m.call(this,t,e,i,n)}function v(t,e,i,n){this.props={dot:{top:0,width:0,height:0},content:{height:0,marginLeft:0}},m.call(this,t,e,i,n)}function y(t,e,i,n){this.props={content:{left:0,width:0}},m.call(this,t,e,i,n)}function w(t,e,i){this.id=E.randomUUID(),this.parent=t,this.groupId=e,this.itemsData=null,this.items=null,this.options=Object.create(t&&t.options||null)
  26. for(i=r.margin&&void 0!==r.margin.item?r.margin.item:this.defaultOptions.margin.item,t=0,e=n.length;e>t;t++){var a=n[t],h=null;do h=this.checkOverlap(n,t,0,t-1,i),null!=h&&(a.top=o?h.top+h.height+i:h.top-a.height-i);while(h)}},o.prototype.checkOverlap=function(t,e,i,n,r){for(var s=this.collision,o=t[e],a=n;a>=i;a--){var h=t[a];if(s(o,h,r)&&a!=e)return h}return null},o.prototype.collision=function(t,e,i){return t.left-i<e.left+e.width&&t.left+t.width+i>e.left&&t.top-i<e.top+e.height&&t.top+t.height+i>e.top},a.prototype.setOptions=function(t){E.extend(this.options,t),(null!=t.start||null!=t.end)&&this.setRange(t.start,t.end)},a.prototype.subscribe=function(t,e,i){var n,r=this;if("horizontal"!=i&&"vertical"!=i)throw new TypeError('Unknown direction "'+i+'". '+'Choose "horizontal" or "vertical".');if("move"==e)n={component:t,event:e,direction:i,callback:function(t){r._onMouseDown(t,n)},params:{}},t.on("mousedown",n.callback),r.listeners.push(n);else{if("zoom"!=e)throw new TypeError('Unknown event "'+e+'". '+'Choose "move" or "zoom".');n={component:t,event:e,direction:i,callback:function(t){r._onMouseWheel(t,n)},params:{}},t.on("mousewheel",n.callback),r.listeners.push(n)}},a.prototype.on=function(t,e){_.addListener(this,t,e)},a.prototype._trigger=function(t){_.trigger(this,t,{start:this.start,end:this.end})},a.prototype.setRange=function(t,e){var i=this._applyRange(t,e);i&&(this._trigger("rangechange"),this._trigger("rangechanged"))},a.prototype._applyRange=function(t,e){var i,n=null!=t?E.cast(t,"Number"):this.start,r=null!=e?E.cast(e,"Number"):this.end;if(isNaN(n))throw Error('Invalid start "'+t+'"');if(isNaN(r))throw Error('Invalid end "'+e+'"');if(n>r&&(r=n),null!=this.options.min){var s=this.options.min.valueOf();s>n&&(i=s-n,n+=i,r+=i)}if(null!=this.options.max){var o=this.options.max.valueOf();r>o&&(i=r-o,n-=i,r-=i)}if(null!=this.options.zoomMin){var a=this.options.zoomMin.valueOf();0>a&&(a=0),a>r-n&&(this.end-this.start>a?(i=a-(r-n),n-=i/2,r+=i/2):(n=this.start,r=this.end))}if(null!=this.options.zoomMax){var h=this.options.zoomMax.valueOf();0>h&&(h=0),r-n>h&&(h>this.end-this.start?(i=r-n-h,n+=i/2,r-=i/2):(n=this.start,r=this.end))}var p=this.start!=n||this.end!=r;return this.start=n,this.end=r,p},a.prototype.getRange=function(){return{start:this.start,end:this.end}},a.prototype.conversion=function(t){return this.start,this.end,a.conversion(this.start,this.end,t)},a.conversion=function(t,e,i){return 0!=i&&0!=e-t?{offset:t,factor:i/(e-t)}:{offset:0,factor:1}},a.prototype._onMouseDown=function(t,e){t=t||window.event;var i=e.params,n=t.which?1==t.which:1==t.button;if(n){i.mouseX=E.getPageX(t),i.mouseY=E.getPageY(t),i.previousLeft=0,i.previousOffset=0,i.moved=!1,i.start=this.start,i.end=this.end;var r=e.component.frame;r&&(r.style.cursor="move");var s=this;i.onMouseMove||(i.onMouseMove=function(t){s._onMouseMove(t,e)},E.addEventListener(document,"mousemove",i.onMouseMove)),i.onMouseUp||(i.onMouseUp=function(t){s._onMouseUp(t,e)},E.addEventListener(document,"mouseup",i.onMouseUp)),E.preventDefault(t)}},a.prototype._onMouseMove=function(t,e){t=t||window.event;var i=e.params,n=E.getPageX(t),r=E.getPageY(t);void 0==i.mouseX&&(i.mouseX=n),void 0==i.mouseY&&(i.mouseY=r);var s=n-i.mouseX,o=r-i.mouseY,a="horizontal"==e.direction?s:o;Math.abs(a)>=1&&(i.moved=!0);var h=i.end-i.start,p="horizontal"==e.direction?e.component.width:e.component.height,u=-a/p*h;this._applyRange(i.start+u,i.end+u),this._trigger("rangechange"),E.preventDefault(t)},a.prototype._onMouseUp=function(t,e){t=t||window.event;var i=e.params;e.component.frame&&(e.component.frame.style.cursor="auto"),i.onMouseMove&&(E.removeEventListener(document,"mousemove",i.onMouseMove),i.onMouseMove=null),i.onMouseUp&&(E.removeEventListener(document,"mouseup",i.onMouseUp),i.onMouseUp=null),i.moved&&this._trigger("rangechanged")},a.prototype._onMouseWheel=function(t,e){t=t||window.event;var i=0;if(t.wheelDelta?i=t.wheelDelta/120:t.detail&&(i=-t.detail/3),i){var n=this,r=function(){var r=i/5,s=null,o=e.component.frame;if(o){var a,h;if("horizontal"==e.direction){a=e.component.width,
  27. if(!r){r=document.createElement("div"),r.className="groupset";var s=n.className;s&&E.addClassName(r,E.option.asString(s)),this.frame=r,t+=1}if(!this.parent)throw Error("Cannot repaint groupset: no parent attached");var o=this.parent.getContainer();if(!o)throw Error("Cannot repaint groupset: parent has no container element");r.parentNode||(o.appendChild(r),t+=1),t+=e(r.style,"height",i(n.height,this.height+"px")),t+=e(r.style,"top",i(n.top,"0px")),t+=e(r.style,"left",i(n.left,"0px")),t+=e(r.style,"width",i(n.width,"100%"));var a=this,h=this.queue,p=this.groups;this.groupsData;var u=Object.keys(h);return u.length&&(u.forEach(function(t){for(var e=h[t],i=null,n=-1,r=0;p.length>r;r++)if(p[r].id==t){i=p[r],n=r;break}switch(e){case"add":case"update":i||(i=new w(a,t),i.setItems(a.itemsData),p.push(i),a.controller.add(i)),delete h[t];break;case"remove":i&&(i.setItems(),p.splice(n,1),a.controller.remove(i)),delete h[t];break;default:console.log('Error: unknown action "'+e+'"')}}),this.groups.forEach(function(t,e){var i=a.groups[e-1],n=0;i&&(n=function(){return i.top+i.height}),t.setOptions({top:n})})),t>0},b.prototype.getContainer=function(){return this.frame},b.prototype.reflow=function(){var t=0,e=this.options,i=E.updateProperty,n=E.option.asNumber,r=this.frame;if(r){var s,o=n(e.maxHeight);null!=e.height?s=r.offsetHeight:(s=0,this.groups.forEach(function(t){s+=t.height})),null!=o&&(s=Math.min(s,o)),t+=i(this,"height",s),t+=i(this,"top",r.offsetTop),t+=i(this,"left",r.offsetLeft),t+=i(this,"width",r.offsetWidth)}return t>0},b.prototype.hide=function(){return this.frame&&this.frame.parentNode?(this.frame.parentNode.removeChild(this.frame),!0):!1},b.prototype.show=function(){return this.frame&&this.frame.parentNode?!1:this.repaint()},b.prototype._onUpdate=function(t){this._toQueue(t,"update")},b.prototype._onAdd=function(t){this._toQueue(t,"add")},b.prototype._onRemove=function(t){this._toQueue(t,"remove")},b.prototype._toQueue=function(t,e){var i=this.queue;t.forEach(function(t){i[t]=e}),this.controller&&this.requestRepaint()},S.prototype.setOptions=function(t){t&&E.extend(this.options,t);var e,i,n,r,s=this;if(e="top"==this.options.orientation?function(){return s.timeaxis.height}:function(){return s.main.height-s.timeaxis.height-s.content.height},this.options.height?(n=this.options.height,i=function(){return s.main.height-s.timeaxis.height}):(n=function(){return s.timeaxis.height+s.content.height},i=null),this.options.maxHeight){if(!E.isNumber(this.options.maxHeight))throw new TypeError("Number expected for property maxHeight");r=function(){return s.options.maxHeight-s.timeaxis.height}}this.main.setOptions({height:n}),this.content.setOptions({top:e,height:i,maxHeight:r}),this.controller.repaint()},S.prototype.setItems=function(t){var e,i=null==this.itemsData;if(t?t instanceof r&&(e=t):e=null,t instanceof r||(e=new r({fieldTypes:{start:"Date",end:"Date"}}),e.add(t)),this.itemsData=e,this.content.setItems(e),i&&(void 0==this.options.start||void 0==this.options.end)){var n=this.getItemRange(),s=n.min,o=n.max;if(null!=s&&null!=o){var a=o.valueOf()-s.valueOf();s=new Date(s.valueOf()-.05*a),o=new Date(o.valueOf()+.05*a)}void 0!=this.options.start&&(s=new Date(this.options.start.valueOf())),void 0!=this.options.end&&(o=new Date(this.options.end.valueOf())),(null!=s||null!=o)&&this.range.setRange(s,o)}},S.prototype.setGroups=function(t){this.groupsData=t;var e=this.groupsData?b:f;this.content instanceof e||(this.content&&(this.content.hide(),this.content.setItems&&this.content.setItems(),this.content.setGroups&&this.content.setGroups(),this.controller.remove(this.content)),this.content=new e(this.main,[this.timeaxis]),this.content.setRange&&this.content.setRange(this.range),this.content.setItems&&this.content.setItems(this.itemsData),this.content.setGroups&&this.content.setGroups(this.groupsData),this.controller.add(this.content),this.setOptions(this.options))},S.prototype.getItemRange=function(){var t=this.itemsData,e=null,i=null;if(t){var n=t.min("start");e=n?n.start.valueOf():null;var r=t.max("start");r&&(i=r.start.valueOf());var s=t