UNPKG

vue2vis

Version:

Vue2 component that helps with Visjs interaction

1,713 lines (1,473 loc) 1.94 MB
module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "fae3"); /******/ }) /************************************************************************/ /******/ ({ /***/ "0366": /***/ (function(module, exports, __webpack_require__) { var aFunction = __webpack_require__("1c0b"); // optional / simple context binding module.exports = function (fn, that, length) { aFunction(fn); if (that === undefined) return fn; switch (length) { case 0: return function () { return fn.call(that); }; case 1: return function (a) { return fn.call(that, a); }; case 2: return function (a, b) { return fn.call(that, a, b); }; case 3: return function (a, b, c) { return fn.call(that, a, b, c); }; } return function (/* ...args */) { return fn.apply(that, arguments); }; }; /***/ }), /***/ "06cf": /***/ (function(module, exports, __webpack_require__) { var DESCRIPTORS = __webpack_require__("83ab"); var propertyIsEnumerableModule = __webpack_require__("d1e7"); var createPropertyDescriptor = __webpack_require__("5c6c"); var toIndexedObject = __webpack_require__("fc6a"); var toPrimitive = __webpack_require__("c04e"); var has = __webpack_require__("5135"); var IE8_DOM_DEFINE = __webpack_require__("0cfb"); var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; // `Object.getOwnPropertyDescriptor` method // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor exports.f = DESCRIPTORS ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) { O = toIndexedObject(O); P = toPrimitive(P, true); if (IE8_DOM_DEFINE) try { return nativeGetOwnPropertyDescriptor(O, P); } catch (error) { /* empty */ } if (has(O, P)) return createPropertyDescriptor(!propertyIsEnumerableModule.f.call(O, P), O[P]); }; /***/ }), /***/ "0cfb": /***/ (function(module, exports, __webpack_require__) { var DESCRIPTORS = __webpack_require__("83ab"); var fails = __webpack_require__("d039"); var createElement = __webpack_require__("cc12"); // Thank's IE8 for his funny defineProperty module.exports = !DESCRIPTORS && !fails(function () { return Object.defineProperty(createElement('div'), 'a', { get: function () { return 7; } }).a != 7; }); /***/ }), /***/ "14c3": /***/ (function(module, exports, __webpack_require__) { var classof = __webpack_require__("c6b6"); var regexpExec = __webpack_require__("9263"); // `RegExpExec` abstract operation // https://tc39.github.io/ecma262/#sec-regexpexec module.exports = function (R, S) { var exec = R.exec; if (typeof exec === 'function') { var result = exec.call(R, S); if (typeof result !== 'object') { throw TypeError('RegExp exec method returned something other than an Object or null'); } return result; } if (classof(R) !== 'RegExp') { throw TypeError('RegExp#exec called on incompatible receiver'); } return regexpExec.call(R, S); }; /***/ }), /***/ "159b": /***/ (function(module, exports, __webpack_require__) { var global = __webpack_require__("da84"); var DOMIterables = __webpack_require__("fdbc"); var forEach = __webpack_require__("17c2"); var createNonEnumerableProperty = __webpack_require__("9112"); for (var COLLECTION_NAME in DOMIterables) { var Collection = global[COLLECTION_NAME]; var CollectionPrototype = Collection && Collection.prototype; // some Chrome versions have non-configurable methods on DOMTokenList if (CollectionPrototype && CollectionPrototype.forEach !== forEach) try { createNonEnumerableProperty(CollectionPrototype, 'forEach', forEach); } catch (error) { CollectionPrototype.forEach = forEach; } } /***/ }), /***/ "17c2": /***/ (function(module, exports, __webpack_require__) { "use strict"; var $forEach = __webpack_require__("b727").forEach; var arrayMethodIsStrict = __webpack_require__("a640"); var arrayMethodUsesToLength = __webpack_require__("ae40"); var STRICT_METHOD = arrayMethodIsStrict('forEach'); var USES_TO_LENGTH = arrayMethodUsesToLength('forEach'); // `Array.prototype.forEach` method implementation // https://tc39.github.io/ecma262/#sec-array.prototype.foreach module.exports = (!STRICT_METHOD || !USES_TO_LENGTH) ? function forEach(callbackfn /* , thisArg */) { return $forEach(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); } : [].forEach; /***/ }), /***/ "1c0b": /***/ (function(module, exports) { module.exports = function (it) { if (typeof it != 'function') { throw TypeError(String(it) + ' is not a function'); } return it; }; /***/ }), /***/ "1d80": /***/ (function(module, exports) { // `RequireObjectCoercible` abstract operation // https://tc39.github.io/ecma262/#sec-requireobjectcoercible module.exports = function (it) { if (it == undefined) throw TypeError("Can't call method on " + it); return it; }; /***/ }), /***/ "1dde": /***/ (function(module, exports, __webpack_require__) { var fails = __webpack_require__("d039"); var wellKnownSymbol = __webpack_require__("b622"); var V8_VERSION = __webpack_require__("2d00"); var SPECIES = wellKnownSymbol('species'); module.exports = function (METHOD_NAME) { // We can't use this feature detection in V8 since it causes // deoptimization and serious performance degradation // https://github.com/zloirock/core-js/issues/677 return V8_VERSION >= 51 || !fails(function () { var array = []; var constructor = array.constructor = {}; constructor[SPECIES] = function () { return { foo: 1 }; }; return array[METHOD_NAME](Boolean).foo !== 1; }); }; /***/ }), /***/ "23cb": /***/ (function(module, exports, __webpack_require__) { var toInteger = __webpack_require__("a691"); var max = Math.max; var min = Math.min; // Helper for a popular repeating case of the spec: // Let integer be ? ToInteger(index). // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length). module.exports = function (index, length) { var integer = toInteger(index); return integer < 0 ? max(integer + length, 0) : min(integer, length); }; /***/ }), /***/ "23e7": /***/ (function(module, exports, __webpack_require__) { var global = __webpack_require__("da84"); var getOwnPropertyDescriptor = __webpack_require__("06cf").f; var createNonEnumerableProperty = __webpack_require__("9112"); var redefine = __webpack_require__("6eeb"); var setGlobal = __webpack_require__("ce4e"); var copyConstructorProperties = __webpack_require__("e893"); var isForced = __webpack_require__("94ca"); /* options.target - name of the target object options.global - target is the global object options.stat - export as static methods of target options.proto - export as prototype methods of target options.real - real prototype method for the `pure` version options.forced - export even if the native feature is available options.bind - bind methods to the target, required for the `pure` version options.wrap - wrap constructors to preventing global pollution, required for the `pure` version options.unsafe - use the simple assignment of property instead of delete + defineProperty options.sham - add a flag to not completely full polyfills options.enumerable - export as enumerable property options.noTargetGet - prevent calling a getter on target */ module.exports = function (options, source) { var TARGET = options.target; var GLOBAL = options.global; var STATIC = options.stat; var FORCED, target, key, targetProperty, sourceProperty, descriptor; if (GLOBAL) { target = global; } else if (STATIC) { target = global[TARGET] || setGlobal(TARGET, {}); } else { target = (global[TARGET] || {}).prototype; } if (target) for (key in source) { sourceProperty = source[key]; if (options.noTargetGet) { descriptor = getOwnPropertyDescriptor(target, key); targetProperty = descriptor && descriptor.value; } else targetProperty = target[key]; FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); // contained in target if (!FORCED && targetProperty !== undefined) { if (typeof sourceProperty === typeof targetProperty) continue; copyConstructorProperties(sourceProperty, targetProperty); } // add a flag to not completely full polyfills if (options.sham || (targetProperty && targetProperty.sham)) { createNonEnumerableProperty(sourceProperty, 'sham', true); } // extend global redefine(target, key, sourceProperty, options); } }; /***/ }), /***/ "241c": /***/ (function(module, exports, __webpack_require__) { var internalObjectKeys = __webpack_require__("ca84"); var enumBugKeys = __webpack_require__("7839"); var hiddenKeys = enumBugKeys.concat('length', 'prototype'); // `Object.getOwnPropertyNames` method // https://tc39.github.io/ecma262/#sec-object.getownpropertynames exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { return internalObjectKeys(O, hiddenKeys); }; /***/ }), /***/ "2d00": /***/ (function(module, exports, __webpack_require__) { var global = __webpack_require__("da84"); var userAgent = __webpack_require__("342f"); var process = global.process; var versions = process && process.versions; var v8 = versions && versions.v8; var match, version; if (v8) { match = v8.split('.'); version = match[0] + match[1]; } else if (userAgent) { match = userAgent.match(/Edge\/(\d+)/); if (!match || match[1] >= 74) { match = userAgent.match(/Chrome\/(\d+)/); if (match) version = match[1]; } } module.exports = version && +version; /***/ }), /***/ "342f": /***/ (function(module, exports, __webpack_require__) { var getBuiltIn = __webpack_require__("d066"); module.exports = getBuiltIn('navigator', 'userAgent') || ''; /***/ }), /***/ "4160": /***/ (function(module, exports, __webpack_require__) { "use strict"; var $ = __webpack_require__("23e7"); var forEach = __webpack_require__("17c2"); // `Array.prototype.forEach` method // https://tc39.github.io/ecma262/#sec-array.prototype.foreach $({ target: 'Array', proto: true, forced: [].forEach != forEach }, { forEach: forEach }); /***/ }), /***/ "428f": /***/ (function(module, exports, __webpack_require__) { var global = __webpack_require__("da84"); module.exports = global; /***/ }), /***/ "44ad": /***/ (function(module, exports, __webpack_require__) { var fails = __webpack_require__("d039"); var classof = __webpack_require__("c6b6"); var split = ''.split; // fallback for non-array-like ES3 and non-enumerable old V8 strings module.exports = fails(function () { // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 // eslint-disable-next-line no-prototype-builtins return !Object('z').propertyIsEnumerable(0); }) ? function (it) { return classof(it) == 'String' ? split.call(it, '') : Object(it); } : Object; /***/ }), /***/ "4930": /***/ (function(module, exports, __webpack_require__) { var fails = __webpack_require__("d039"); module.exports = !!Object.getOwnPropertySymbols && !fails(function () { // Chrome 38 Symbol has incorrect toString conversion // eslint-disable-next-line no-undef return !String(Symbol()); }); /***/ }), /***/ "4d64": /***/ (function(module, exports, __webpack_require__) { var toIndexedObject = __webpack_require__("fc6a"); var toLength = __webpack_require__("50c4"); var toAbsoluteIndex = __webpack_require__("23cb"); // `Array.prototype.{ indexOf, includes }` methods implementation var createMethod = function (IS_INCLUDES) { return function ($this, el, fromIndex) { var O = toIndexedObject($this); var length = toLength(O.length); var index = toAbsoluteIndex(fromIndex, length); var value; // Array#includes uses SameValueZero equality algorithm // eslint-disable-next-line no-self-compare if (IS_INCLUDES && el != el) while (length > index) { value = O[index++]; // eslint-disable-next-line no-self-compare if (value != value) return true; // Array#indexOf ignores holes, Array#includes - not } else for (;length > index; index++) { if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; } return !IS_INCLUDES && -1; }; }; module.exports = { // `Array.prototype.includes` method // https://tc39.github.io/ecma262/#sec-array.prototype.includes includes: createMethod(true), // `Array.prototype.indexOf` method // https://tc39.github.io/ecma262/#sec-array.prototype.indexof indexOf: createMethod(false) }; /***/ }), /***/ "4de4": /***/ (function(module, exports, __webpack_require__) { "use strict"; var $ = __webpack_require__("23e7"); var $filter = __webpack_require__("b727").filter; var arrayMethodHasSpeciesSupport = __webpack_require__("1dde"); var arrayMethodUsesToLength = __webpack_require__("ae40"); var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter'); // Edge 14- issue var USES_TO_LENGTH = arrayMethodUsesToLength('filter'); // `Array.prototype.filter` method // https://tc39.github.io/ecma262/#sec-array.prototype.filter // with adding support of @@species $({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT || !USES_TO_LENGTH }, { filter: function filter(callbackfn /* , thisArg */) { return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); } }); /***/ }), /***/ "4f27": /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * vis.js * https://github.com/almende/vis * * A dynamic, browser-based visualization library. * * @version 4.21.0 * @date 2017-10-12 * * @license * Copyright (C) 2011-2017 Almende B.V, http://almende.com * * Vis.js is dual licensed under both * * * The Apache 2.0 License * http://www.apache.org/licenses/LICENSE-2.0 * * and * * * The MIT License * http://opensource.org/licenses/MIT * * Vis.js may be distributed under either license. */ (function webpackUniversalModuleDefinition(root, factory) { if(true) module.exports = factory(); else {} })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 123); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; exports.default = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; exports.__esModule = true; var _defineProperty = __webpack_require__(169); var _defineProperty2 = _interopRequireDefault(_defineProperty); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; (0, _defineProperty2.default)(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _getIterator2 = __webpack_require__(77); var _getIterator3 = _interopRequireDefault(_getIterator2); var _create = __webpack_require__(29); var _create2 = _interopRequireDefault(_create); var _keys = __webpack_require__(8); var _keys2 = _interopRequireDefault(_keys); var _typeof2 = __webpack_require__(6); var _typeof3 = _interopRequireDefault(_typeof2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } // utility functions // first check if moment.js is already loaded in the browser window, if so, // use this instance. Else, load via commonjs. var moment = __webpack_require__(9); var uuid = __webpack_require__(157); /** * Test whether given object is a number * @param {*} object * @return {Boolean} isNumber */ exports.isNumber = function (object) { return object instanceof Number || typeof object == 'number'; }; /** * Remove everything in the DOM object * @param {Element} DOMobject */ exports.recursiveDOMDelete = function (DOMobject) { if (DOMobject) { while (DOMobject.hasChildNodes() === true) { exports.recursiveDOMDelete(DOMobject.firstChild); DOMobject.removeChild(DOMobject.firstChild); } } }; /** * this function gives you a range between 0 and 1 based on the min and max values in the set, the total sum of all values and the current value. * * @param {number} min * @param {number} max * @param {number} total * @param {number} value * @returns {number} */ exports.giveRange = function (min, max, total, value) { if (max == min) { return 0.5; } else { var scale = 1 / (max - min); return Math.max(0, (value - min) * scale); } }; /** * Test whether given object is a string * @param {*} object * @return {Boolean} isString */ exports.isString = function (object) { return object instanceof String || typeof object == 'string'; }; /** * Test whether given object is a Date, or a String containing a Date * @param {Date | String} object * @return {Boolean} isDate */ exports.isDate = function (object) { if (object instanceof Date) { return true; } else if (exports.isString(object)) { // test whether this string contains a date var match = ASPDateRegex.exec(object); if (match) { return true; } else if (!isNaN(Date.parse(object))) { return true; } } return false; }; /** * Create a semi UUID * source: http://stackoverflow.com/a/105074/1262753 * @return {string} uuid */ exports.randomUUID = function () { return uuid.v4(); }; /** * assign all keys of an object that are not nested objects to a certain value (used for color objects). * @param {object} obj * @param {number} value */ exports.assignAllKeys = function (obj, value) { for (var prop in obj) { if (obj.hasOwnProperty(prop)) { if ((0, _typeof3['default'])(obj[prop]) !== 'object') { obj[prop] = value; } } } }; /** * Copy property from b to a if property present in a. * If property in b explicitly set to null, delete it if `allowDeletion` set. * * Internal helper routine, should not be exported. Not added to `exports` for that reason. * * @param {object} a target object * @param {object} b source object * @param {string} prop name of property to copy to a * @param {boolean} allowDeletion if true, delete property in a if explicitly set to null in b * @private */ function copyOrDelete(a, b, prop, allowDeletion) { var doDeletion = false; if (allowDeletion === true) { doDeletion = b[prop] === null && a[prop] !== undefined; } if (doDeletion) { delete a[prop]; } else { a[prop] = b[prop]; // Remember, this is a reference copy! } } /** * Fill an object with a possibly partially defined other object. * * Only copies values for the properties already present in a. * That means an object is not created on a property if only the b object has it. * * @param {object} a * @param {object} b * @param {boolean} [allowDeletion=false] if true, delete properties in a that are explicitly set to null in b */ exports.fillIfDefined = function (a, b) { var allowDeletion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; // NOTE: iteration of properties of a // NOTE: prototype properties iterated over as well for (var prop in a) { if (b[prop] !== undefined) { if (b[prop] === null || (0, _typeof3['default'])(b[prop]) !== 'object') { // Note: typeof null === 'object' copyOrDelete(a, b, prop, allowDeletion); } else { if ((0, _typeof3['default'])(a[prop]) === 'object') { exports.fillIfDefined(a[prop], b[prop], allowDeletion); } } } } }; /** * Extend object a with the properties of object b or a series of objects * Only properties with defined values are copied * @param {Object} a * @param {...Object} b * @return {Object} a */ exports.extend = function (a, b) { // eslint-disable-line no-unused-vars for (var i = 1; i < arguments.length; i++) { var other = arguments[i]; for (var prop in other) { if (other.hasOwnProperty(prop)) { a[prop] = other[prop]; } } } return a; }; /** * Extend object a with selected properties of object b or a series of objects * Only properties with defined values are copied * @param {Array.<string>} props * @param {Object} a * @param {Object} b * @return {Object} a */ exports.selectiveExtend = function (props, a, b) { // eslint-disable-line no-unused-vars if (!Array.isArray(props)) { throw new Error('Array with property names expected as first argument'); } for (var i = 2; i < arguments.length; i++) { var other = arguments[i]; for (var p = 0; p < props.length; p++) { var prop = props[p]; if (other && other.hasOwnProperty(prop)) { a[prop] = other[prop]; } } } return a; }; /** * Extend object a with selected properties of object b. * Only properties with defined values are copied. * * **Note:** Previous version of this routine implied that multiple source objects * could be used; however, the implementation was **wrong**. * Since multiple (>1) sources weren't used anywhere in the `vis.js` code, * this has been removed * * @param {Array.<string>} props names of first-level properties to copy over * @param {object} a target object * @param {object} b source object * @param {boolean} [allowDeletion=false] if true, delete property in a if explicitly set to null in b * @returns {Object} a */ exports.selectiveDeepExtend = function (props, a, b) { var allowDeletion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; // TODO: add support for Arrays to deepExtend if (Array.isArray(b)) { throw new TypeError('Arrays are not supported by deepExtend'); } for (var p = 0; p < props.length; p++) { var prop = props[p]; if (b.hasOwnProperty(prop)) { if (b[prop] && b[prop].constructor === Object) { if (a[prop] === undefined) { a[prop] = {}; } if (a[prop].constructor === Object) { exports.deepExtend(a[prop], b[prop], false, allowDeletion); } else { copyOrDelete(a, b, prop, allowDeletion); } } else if (Array.isArray(b[prop])) { throw new TypeError('Arrays are not supported by deepExtend'); } else { copyOrDelete(a, b, prop, allowDeletion); } } } return a; }; /** * Extend object `a` with properties of object `b`, ignoring properties which are explicitly * specified to be excluded. * * The properties of `b` are considered for copying. * Properties which are themselves objects are are also extended. * Only properties with defined values are copied * * @param {Array.<string>} propsToExclude names of properties which should *not* be copied * @param {Object} a object to extend * @param {Object} b object to take properties from for extension * @param {boolean} [allowDeletion=false] if true, delete properties in a that are explicitly set to null in b * @return {Object} a */ exports.selectiveNotDeepExtend = function (propsToExclude, a, b) { var allowDeletion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; // TODO: add support for Arrays to deepExtend // NOTE: array properties have an else-below; apparently, there is a problem here. if (Array.isArray(b)) { throw new TypeError('Arrays are not supported by deepExtend'); } for (var prop in b) { if (!b.hasOwnProperty(prop)) continue; // Handle local properties only if (propsToExclude.indexOf(prop) !== -1) continue; // In exclusion list, skip if (b[prop] && b[prop].constructor === Object) { if (a[prop] === undefined) { a[prop] = {}; } if (a[prop].constructor === Object) { exports.deepExtend(a[prop], b[prop]); // NOTE: allowDeletion not propagated! } else { copyOrDelete(a, b, prop, allowDeletion); } } else if (Array.isArray(b[prop])) { a[prop] = []; for (var i = 0; i < b[prop].length; i++) { a[prop].push(b[prop][i]); } } else { copyOrDelete(a, b, prop, allowDeletion); } } return a; }; /** * Deep extend an object a with the properties of object b * * @param {Object} a * @param {Object} b * @param {boolean} [protoExtend=false] If true, the prototype values will also be extended. * (ie. the options objects that inherit from others will also get the inherited options) * @param {boolean} [allowDeletion=false] If true, the values of fields that are null will be deleted * @returns {Object} */ exports.deepExtend = function (a, b) { var protoExtend = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var allowDeletion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; for (var prop in b) { if (b.hasOwnProperty(prop) || protoExtend === true) { if (b[prop] && b[prop].constructor === Object) { if (a[prop] === undefined) { a[prop] = {}; } if (a[prop].constructor === Object) { exports.deepExtend(a[prop], b[prop], protoExtend); // NOTE: allowDeletion not propagated! } else { copyOrDelete(a, b, prop, allowDeletion); } } else if (Array.isArray(b[prop])) { a[prop] = []; for (var i = 0; i < b[prop].length; i++) { a[prop].push(b[prop][i]); } } else { copyOrDelete(a, b, prop, allowDeletion); } } } return a; }; /** * Test whether all elements in two arrays are equal. * @param {Array} a * @param {Array} b * @return {boolean} Returns true if both arrays have the same length and same * elements. */ exports.equalArray = function (a, b) { if (a.length != b.length) return false; for (var i = 0, len = a.length; i < len; i++) { if (a[i] != b[i]) return false; } return true; }; /** * Convert an object to another type * @param {boolean | number | string | Date | Moment | Null | undefined} object * @param {string | undefined} type Name of the type. Available types: * 'Boolean', 'Number', 'String', * 'Date', 'Moment', ISODate', 'ASPDate'. * @return {*} object * @throws Error */ exports.convert = function (object, type) { var match; if (object === undefined) { return undefined; } if (object === null) { return null; } if (!type) { return object; } if (!(typeof type === 'string') && !(type instanceof String)) { throw new Error('Type must be a string'); } //noinspection FallthroughInSwitchStatementJS switch (type) { case 'boolean': case 'Boolean': return Boolean(object); case 'number': case 'Number': if (exports.isString(object) && !isNaN(Date.parse(object))) { return moment(object).valueOf(); } else { return Number(object.valueOf()); } case 'string': case 'String': return String(object); case 'Date': if (exports.isNumber(object)) { return new Date(object); } if (object instanceof Date) { return new Date(object.valueOf()); } else if (moment.isMoment(object)) { return new Date(object.valueOf()); } if (exports.isString(object)) { match = ASPDateRegex.exec(object); if (match) { // object is an ASP date return new Date(Number(match[1])); // parse number } else { return moment(new Date(object)).toDate(); // parse string } } else { throw new Error('Cannot convert object of type ' + exports.getType(object) + ' to type Date'); } case 'Moment': if (exports.isNumber(object)) { return moment(object); } if (object instanceof Date) { return moment(object.valueOf()); } else if (moment.isMoment(object)) { return moment(object); } if (exports.isString(object)) { match = ASPDateRegex.exec(object); if (match) { // object is an ASP date return moment(Number(match[1])); // parse number } else { return moment(object); // parse string } } else { throw new Error('Cannot convert object of type ' + exports.getType(object) + ' to type Date'); } case 'ISODate': if (exports.isNumber(object)) { return new Date(object); } else if (object instanceof Date) { return object.toISOString(); } else if (moment.isMoment(object)) { return object.toDate().toISOString(); } else if (exports.isString(object)) { match = ASPDateRegex.exec(object); if (match) { // object is an ASP date return new Date(Number(match[1])).toISOString(); // parse number } else { return moment(object).format(); // ISO 8601 } } else { throw new Error('Cannot convert object of type ' + exports.getType(object) + ' to type ISODate'); } case 'ASPDate': if (exports.isNumber(object)) { return '/Date(' + object + ')/'; } else if (object instanceof Date) { return '/Date(' + object.valueOf() + ')/'; } else if (exports.isString(object)) { match = ASPDateRegex.exec(object); var value; if (match) { // object is an ASP date value = new Date(Number(match[1])).valueOf(); // parse number } else { value = new Date(object).valueOf(); // parse string } return '/Date(' + value + ')/'; } else { throw new Error('Cannot convert object of type ' + exports.getType(object) + ' to type ASPDate'); } default: throw new Error('Unknown type "' + type + '"'); } }; // parse ASP.Net Date pattern, // for example '/Date(1198908717056)/' or '/Date(1198908717056-0700)/' // code from http://momentjs.com/ var ASPDateRegex = /^\/?Date\((\-?\d+)/i; /** * Get the type of an object, for example exports.getType([]) returns 'Array' * @param {*} object * @return {string} type */ exports.getType = function (object) { var type = typeof object === 'undefined' ? 'undefined' : (0, _typeof3['default'])(object); if (type == 'object') { if (object === null) { return 'null'; } if (object instanceof Boolean) { return 'Boolean'; } if (object instanceof Number) { return 'Number'; } if (object instanceof String) { return 'String'; } if (Array.isArray(object)) { return 'Array'; } if (object instanceof Date) { return 'Date'; } return 'Object'; } else if (type == 'number') { return 'Number'; } else if (type == 'boolean') { return 'Boolean'; } else if (type == 'string') { return 'String'; } else if (type === undefined) { return 'undefined'; } return type; }; /** * Used to extend an array and copy it. This is used to propagate paths recursively. * * @param {Array} arr * @param {*} newValue * @returns {Array} */ exports.copyAndExtendArray = function (arr, newValue) { var newArr = []; for (var i = 0; i < arr.length; i++) { newArr.push(arr[i]); } newArr.push(newValue); return newArr; }; /** * Used to extend an array and copy it. This is used to propagate paths recursively. * * @param {Array} arr * @returns {Array} */ exports.copyArray = function (arr) { var newArr = []; for (var i = 0; i < arr.length; i++) { newArr.push(arr[i]); } return newArr; }; /** * Retrieve the absolute left value of a DOM element * @param {Element} elem A dom element, for example a div * @return {number} left The absolute left position of this element * in the browser page. */ exports.getAbsoluteLeft = function (elem) { return elem.getBoundingClientRect().left; }; exports.getAbsoluteRight = function (elem) { return elem.getBoundingClientRect().right; }; /** * Retrieve the absolute top value of a DOM element * @param {Element} elem A dom element, for example a div * @return {number} top The absolute top position of this element * in the browser page. */ exports.getAbsoluteTop = function (elem) { return elem.getBoundingClientRect().top; }; /** * add a className to the given elements style * @param {Element} elem * @param {string} classNames */ exports.addClassName = function (elem, classNames) { var classes = elem.className.split(' '); var newClasses = classNames.split(' '); classes = classes.concat(newClasses.filter(function (className) { return classes.indexOf(className) < 0; })); elem.className = classes.join(' '); }; /** * add a className to the given elements style * @param {Element} elem * @param {string} classNames */ exports.removeClassName = function (elem, classNames) { var classes = elem.className.split(' '); var oldClasses = classNames.split(' '); classes = classes.filter(function (className) { return oldClasses.indexOf(className) < 0; }); elem.className = classes.join(' '); }; /** * For each method for both arrays and objects. * In case of an array, the built-in Array.forEach() is applied. (**No, it's not!**) * In case of an Object, the method loops over all properties of the object. * @param {Object | Array} object An Object or Array * @param {function} callback Callback method, called for each item in * the object or array with three parameters: * callback(value, index, object) */ exports.forEach = function (object, callback) { var i, len; if (Array.isArray(object)) { // array for (i = 0, len = object.length; i < len; i++) { callback(object[i], i, object); } } else { // object for (i in object) { if (object.hasOwnProperty(i)) { callback(object[i], i, object); } } } }; /** * Convert an object into an array: all objects properties are put into the * array. The resulting array is unordered. * @param {Object} object * @returns {Array} array */ exports.toArray = function (object) { var array = []; for (var prop in object) { if (object.hasOwnProperty(prop)) array.push(object[prop]); } return array; }; /** * Update a property in an object * @param {Object} object * @param {string} key * @param {*} value * @return {Boolean} changed */ exports.updateProperty = function (object, key, value) { if (object[key] !== value) { object[key] = value; return true; } else { return false; } }; /** * Throttle the given function to be only executed once per animation frame * @param {function} fn * @returns {function} Returns the throttled function */ exports.throttle = function (fn) { var scheduled = false; return function throttled() { if (!scheduled) { scheduled = true; requestAnimationFrame(function () { scheduled = false; fn(); }); } }; }; /** * Add and event listener. Works for all browsers * @param {Element} element An html element * @param {string} action The action, for example "click", * without the prefix "on" * @param {function} listener The callback function to be executed * @param {boolean} [useCapture] */ exports.addEventListener = function (element, action, listener, useCapture) { if (element.addEventListener) { if (useCapture === undefined) useCapture = false; if (action === "mousewheel" && navigator.userAgent.indexOf("Firefox") >= 0) { action = "DOMMouseScroll"; // For Firefox } element.addEventListener(action, listener, useCapture); } else { element.attachEvent("on" + action, listener); // IE browsers } }; /** * Remove an event listener from an element * @param {Element} element An html dom element * @param {string} action The name of the event, for example "mousedown" * @param {function} listener The listener function * @param {boolean} [useCapture] */ exports.removeEventListener = function (element, action, listener, useCapture) { if (element.removeEventListener) { // non-IE browsers if (useCapture === undefined) useCapture = false; if (action === "mousewheel" && navigator.userAgent.indexOf("Firefox") >= 0) { action = "DOMMouseScroll"; // For Firefox } element.removeEventListener(action, listener, useCapture); } else { // IE browsers element.detachEvent("on" + action, listener); } }; /** * Cancels the event if it is cancelable, without stopping further propagation of the event. * @param {Event} event */ exports.preventDefault = function (event) { if (!event) event = window.event; if (event.preventDefault) { event.preventDefault(); // non-IE browsers } else { event.returnValue = false; // IE browsers } }; /** * Get HTML element which is the target of the event * @param {Event} event * @return {Element} target element */ exports.getTarget = function (event) { // code from http://www.quirksmode.org/js/events_properties.html if (!event) { event = window.event; } var target; if (event.target) { target = event.target; } else if (event.srcElement) { target = event.srcElement; } if (target.nodeType != undefined && target.nodeType == 3) { // defeat Safari bug target = target.parentNode; } return target; }; /** * Check if given element contains given parent somewhere in the DOM tree * @param {Element} element * @param {Element} parent * @returns {boolean} */ exports.hasParent = function (element, parent) { var e = element; while (e) { if (e === parent) { return true; } e = e.parentNode; } return false; }; exports.option = {}; /** * Convert a value into a boolean * @param {Boolean | function | undefined} value * @param {boolean} [defaultValue] * @returns {Boolean} bool */ exports.option.asBoolean = function (value, defaultValue) { if (typeof value == 'function') { value = value(); } if (value != null) { return value != false; } return defaultValue || null; }; /** * Convert a value into a number * @param {Boolean | function | undefined} value * @param {number} [defaultValue] * @returns {number} number */ exports.option.asNumber = function (value, defaultValue) { if (typeof value == 'function') { value = value(); } if (value != null) { return Number(value) || defaultValue || null; } return defaultValue || null; }; /** * Convert a value into a string * @param {string | function | undefined} value * @param {string} [defaultValue] * @returns {String} str */ exports.option.asString = function (value, defaultValue) { if (typeof value == 'function') { value = value(); } if (value != null) { return String(value); } return defaultValue || null; }; /** * Convert a size or location into a string with pixels or a percentage * @param {string | number | function | undefined} value * @param {string} [defaultValue] * @returns {String} size */ exports.option.asSize = function (value, defaultValue) { if (typeof value == 'function') { value = value(); } if (exports.isString(value)) { return value; } else if (exports.isNumber(value)) { return value + 'px'; } else { return defaultValue || null; } }; /** * Convert a value into a DOM element * @param {HTMLElement | function | undefined} value * @param {HTMLElement} [defaultValue] * @returns {HTMLElement | null} dom */ exports.option.asElement = function (value, defaultValue) { if (typeof value == 'function') { value = value(); } return value || defaultValue || null; }; /** * http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb * * @param {string} hex * @returns {{r: *, g: *, b: *}} | 255 range */ exports.hexToRGB = function (hex) { // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; hex = hex.replace(shorthandRegex, function (m, r, g, b) { return r + r + g + g + b + b; }); var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null; }; /** * This function takes color in hex format or rgb() or rgba() format and overrides the opacity. Returns rgba() string. * @param {string} color * @param {number} opacity * @returns {String} */ exports.overrideOpacity = function (color, opacity) { var rgb; if (color.indexOf("rgba") != -1) { return color; } else if (color.indexOf("rgb") != -1) { rgb = color.substr(color.indexOf("(") + 1).replace(")", "").split(","); return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + opacity + ")"; } else { rgb = exports.hexToRGB(color); if (rgb == null) { return color; } else { return "rgba(" + rgb.r + "," + rgb.g + "," + rgb.b + "," + opacity + ")"; } } }; /** * * @param {number} red 0 -- 255 * @param {number} green 0 -- 255 * @param {number} blue 0 -- 255 * @returns {String} * @constructor */ exports.RGBToHex = function (red, green, blue) { return "#" + ((1 << 24) + (red << 16) + (green << 8) + blue).toString(16).slice(1); }; /** * Parse a color property into an object with border, background, and * highlight colors * @param {Object | String} color * @return {Object} colorObject */ exports.parseColor = function (color) { var c; if (exports.isString(color) === true) { if (exports.isValidRGB(color) === true) { var rgb = color.substr(4).substr(0, color.length - 5).split(',').map(function (value) { return parseInt(value); }); color = exports.RGBToHex(rgb[0], rgb[1], rgb[2]); } if (exports.isValidHex(color) === true) { var hsv = exports.hexToHSV(color); var lighterColorHSV = { h: hsv.h, s: hsv.s * 0.8, v: Math.min(1, hsv.v * 1.02) }; var darkerColorHSV = { h: hsv.h, s: Math.min(1, hsv.s * 1.25), v: hsv.v * 0.8 }; var darkerColorHex = exports.HSVToHex(darkerColorHSV.h, darkerColorHSV.s, darkerColorHSV.v); var lighterColorHex = exports.HSVToHex(lighterColorHSV.h, lighterColorHSV.s, lighterColorHSV.v); c = { background: color, border: darkerColorHex, highlight: { background: lighterColorHex, border: darkerColorHex }, hover: { background: lighterColorHex, border: darkerColorHex } }; } else { c = { background: color, border: color, highlight: { background: color, border: color }, hover: { background: color, border: color } }; } } else { c = {}; c.background = color.background || undefined; c.border = color.border || undefined; if (exports.isString(color.highlight)) { c.highlight = { border: color.highlight, background: col