diff --git a/README.md b/README.md new file mode 100644 index 00000000..37f36d8b --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# wisemapping-frontend + +This monorepo uses lerna and contains all the packages that compose the wisemapping frontend. + +This is a WIP migration from [legacy wisemapping](https://bitbucket.org/wisemapping/wisemapping-open-source/) into a modern web development project with multiple improvements. + +`nvm use` +`yarn install` +`yarn bootstrap` +`yarn run build` diff --git a/libraries/mootools-core-1.4.5.js b/libraries/mootools-core-1.4.5.js index 9eb4e843..32a26b11 100644 --- a/libraries/mootools-core-1.4.5.js +++ b/libraries/mootools-core-1.4.5.js @@ -16,61 +16,787 @@ ... */ -(function(){this.MooTools={version:"1.4.5",build:"ab8ea8824dc3b24b6666867a2c4ed58ebb762cf0"};var o=this.typeOf=function(i){if(i==null){return"null";}if(i.$family!=null){return i.$family(); -}if(i.nodeName){if(i.nodeType==1){return"element";}if(i.nodeType==3){return(/\S/).test(i.nodeValue)?"textnode":"whitespace";}}else{if(typeof i.length=="number"){if(i.callee){return"arguments"; -}if("item" in i){return"collection";}}}return typeof i;};var j=this.instanceOf=function(t,i){if(t==null){return false;}var s=t.$constructor||t.constructor; - while(s){if(s===i){return true;}s=s.parent;}if(!t.hasOwnProperty){return false;}return t instanceof i;};var f=this.Function;var p=true;for(var k in {toString:1}){p=null; -}if(p){p=["hasOwnProperty","valueOf","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","constructor"];}f.prototype.overloadSetter=function(s){var i=this; - return function(u,t){if(u==null){return this;}if(s||typeof u!="string"){for(var v in u){i.call(this,v,u[v]);}if(p){for(var w=p.length;w--;){v=p[w];if(u.hasOwnProperty(v)){i.call(this,v,u[v]); - }}}}else{i.call(this,u,t);}return this;};};f.prototype.overloadGetter=function(s){var i=this;return function(u){var v,t;if(typeof u!="string"){v=u;}else{if(arguments.length>1){v=arguments; -}else{if(s){v=[u];}}}if(v){t={};for(var w=0;w>>0; - b>>0;b>>0;for(var a=(d<0)?Math.max(0,b+d):d||0;a>>0,b=Array(d);for(var a=0;a>>0; - b-1:String(this).indexOf(a)>-1;},trim:function(){return String(this).replace(/^\s+|\s+$/g,""); -},clean:function(){return String(this).replace(/\s+/g," ").trim();},camelCase:function(){return String(this).replace(/-\D/g,function(a){return a.charAt(1).toUpperCase(); -});},hyphenate:function(){return String(this).replace(/[A-Z]/g,function(a){return("-"+a.charAt(0).toLowerCase());});},capitalize:function(){return String(this).replace(/\b[a-z]/g,function(a){return a.toUpperCase(); -});},escapeRegExp:function(){return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1");},rgbToHex:function(b){var a=String(this).match(/\d{1,3}/g); - return(a)?a.rgbToHex(b):null;},substitute:function(a,b){return String(this).replace(b||(/\\?\{([^{}]+)\}/g),function(d,c){if(d.charAt(0)=="\\"){return d.slice(1); -}return(a[c]!=null)?a[c]:"";});}}); -Function.implement({bind:function(e){var a=this,b=arguments.length>1?Array.slice(arguments,1):null,d=function(){};var c=function(){var g=e,h=arguments.length;if(this instanceof c){d.prototype=a.prototype;g=new d;}var f=(!b&&!h)?a.call(g):a.apply(g,b&&h?b.concat(Array.slice(arguments)):b||arguments);return g==e?f:g;};return c;},pass:function(b,c){var a=this;if(b!=null){b=Array.from(b);}return function(){return a.apply(c,b||arguments);};},delay:function(b,c,a){return setTimeout(this.pass((a==null?[]:a),c),b);},}); -Number.alias("each","times");(function(b){var a={};b.each(function(c){if(!Number[c]){a[c]=function(){return Math[c].apply(null,[this].concat(Array.from(arguments))); -};}});Number.implement(a);})(["abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","max","min","pow","sin","sqrt","tan"]);(function(){var a=this.Class=new Type("Class",function(h){if(instanceOf(h,Function)){h={initialize:h}; -}var g=function(){e(this);if(g.$prototyping){return this;}this.$caller=null;var i=(this.initialize)?this.initialize.apply(this,arguments):this;this.$caller=this.caller=null; - return i;}.extend(this).implement(h);g.$constructor=a;g.prototype.$constructor=g;g.prototype.parent=c;return g;});var c=function(){if(!this.$caller){throw new Error('The method "parent" cannot be called.'); -}var g=this.$caller.$name,h=this.$caller.$owner.parent,i=(h)?h.prototype[g]:null;if(!i){throw new Error('The method "'+g+'" has no parent.');}return i.apply(this,arguments); -};var e=function(g){for(var h in g){var j=g[h];switch(typeOf(j)){case"object":var i=function(){};i.prototype=j;g[h]=e(new i);break;case"array":g[h]=j.clone(); - break;}}return g;};var b=function(g,h,j){if(j.$origin){j=j.$origin;}var i=function(){if(j.$protected&&this.$caller==null){throw new Error('The method "'+h+'" cannot be called.'); -}var l=this.caller,m=this.$caller;this.caller=m;this.$caller=i;var k=j.apply(this,arguments);this.$caller=m;this.caller=l;return k;}.extend({$owner:g,$origin:j,$name:h}); - return i;};var f=function(h,i,g){if(a.Mutators.hasOwnProperty(h)){i=a.Mutators[h].call(this,i);if(i==null){return this;}}if(typeOf(i)=="function"){if(i.$hidden){return this; -}this.prototype[h]=(g)?i:b(this,h,i);}else{Object.merge(this.prototype,h,i);}return this;};var d=function(g){g.$prototyping=true;var h=new g;delete g.$prototyping; - return h;};a.implement("implement",f.overloadSetter());a.Mutators={Extends:function(g){this.parent=g;this.prototype=d(g);},Implements:function(g){Array.from(g).each(function(j){var h=new j;for(var i in h){f.call(this,i,h[i],true);}},this);}};})(); \ No newline at end of file +(function () { + this.MooTools = { version: '1.4.5', build: 'ab8ea8824dc3b24b6666867a2c4ed58ebb762cf0' }; + var o = (this.typeOf = function (i) { + if (i == null) { + return 'null'; + } + if (i.$family != null) { + return i.$family(); + } + if (i.nodeName) { + if (i.nodeType == 1) { + return 'element'; + } + if (i.nodeType == 3) { + return /\S/.test(i.nodeValue) ? 'textnode' : 'whitespace'; + } + } else { + if (typeof i.length == 'number') { + if (i.callee) { + return 'arguments'; + } + if ('item' in i) { + return 'collection'; + } + } + } + return typeof i; + }); + var j = (this.instanceOf = function (t, i) { + if (t == null) { + return false; + } + var s = t.$constructor || t.constructor; + while (s) { + if (s === i) { + return true; + } + s = s.parent; + } + if (!t.hasOwnProperty) { + return false; + } + return t instanceof i; + }); + var f = this.Function; + var p = true; + for (var k in { toString: 1 }) { + p = null; + } + if (p) { + p = [ + 'hasOwnProperty', + 'valueOf', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'toLocaleString', + 'toString', + 'constructor', + ]; + } + f.prototype.overloadSetter = function (s) { + var i = this; + return function (u, t) { + if (u == null) { + return this; + } + if (s || typeof u != 'string') { + for (var v in u) { + i.call(this, v, u[v]); + } + if (p) { + for (var w = p.length; w--; ) { + v = p[w]; + if (u.hasOwnProperty(v)) { + i.call(this, v, u[v]); + } + } + } + } else { + i.call(this, u, t); + } + return this; + }; + }; + f.prototype.overloadGetter = function (s) { + var i = this; + return function (u) { + var v, t; + if (typeof u != 'string') { + v = u; + } else { + if (arguments.length > 1) { + v = arguments; + } else { + if (s) { + v = [u]; + } + } + } + if (v) { + t = {}; + for (var w = 0; w < v.length; w++) { + t[v[w]] = i.call(this, v[w]); + } + } else { + t = i.call(this, u); + } + return t; + }; + }; + f.prototype.extend = function (i, s) { + this[i] = s; + }.overloadSetter(); + f.prototype.implement = function (i, s) { + this.prototype[i] = s; + }.overloadSetter(); + var n = Array.prototype.slice; + f.from = function (i) { + return o(i) == 'function' + ? i + : function () { + return i; + }; + }; + Array.from = function (i) { + if (i == null) { + return []; + } + return a.isEnumerable(i) && typeof i != 'string' ? (o(i) == 'array' ? i : n.call(i)) : [i]; + }; + Number.from = function (s) { + var i = parseFloat(s); + return isFinite(i) ? i : null; + }; + String.from = function (i) { + return i + ''; + }; + f.implement({ + hide: function () { + this.$hidden = true; + return this; + }, + protect: function () { + this.$protected = true; + return this; + }, + }); + var a = (this.Type = function (u, t) { + if (u) { + var s = u.toLowerCase(); + var i = function (v) { + return o(v) == s; + }; + a['is' + u] = i; + if (t != null) { + t.prototype.$family = function () { + return s; + }.hide(); + } + } + if (t == null) { + return null; + } + t.extend(this); + t.$constructor = a; + t.prototype.$constructor = t; + return t; + }); + var e = Object.prototype.toString; + a.isEnumerable = function (i) { + return i != null && typeof i.length == 'number' && e.call(i) != '[object Function]'; + }; + var q = {}; + var r = function (i) { + var s = o(i.prototype); + return q[s] || (q[s] = []); + }; + var b = function (t, x) { + if (x && x.$hidden) { + return; + } + var s = r(this); + for (var u = 0; u < s.length; u++) { + var w = s[u]; + if (o(w) == 'type') { + b.call(w, t, x); + } else { + w.call(this, t, x); + } + } + var v = this.prototype[t]; + if (v == null || !v.$protected) { + this.prototype[t] = x; + } + if (this[t] == null && o(x) == 'function') { + m.call(this, t, function (i) { + return x.apply(i, n.call(arguments, 1)); + }); + } + }; + var m = function (i, t) { + if (t && t.$hidden) { + return; + } + var s = this[i]; + if (s == null || !s.$protected) { + this[i] = t; + } + }; + a.implement({ + implement: b.overloadSetter(), + extend: m.overloadSetter(), + alias: function (i, s) { + b.call(this, i, this.prototype[s]); + }.overloadSetter(), + mirror: function (i) { + r(this).push(i); + return this; + }, + }); + new a('Type', a); + var d = function (s, x, v) { + var u = x != Object, + B = x.prototype; + if (u) { + x = new a(s, x); + } + for (var y = 0, w = v.length; y < w; y++) { + var C = v[y], + A = x[C], + z = B[C]; + if (A) { + A.protect(); + } + if (u && z) { + x.implement(C, z.protect()); + } + } + if (u) { + var t = B.propertyIsEnumerable(v[0]); + x.forEachMethod = function (G) { + if (!t) { + for (var F = 0, D = v.length; F < D; F++) { + G.call(B, B[v[F]], v[F]); + } + } + for (var E in B) { + G.call(B, B[E], E); + } + }; + } + return d; + }; + d('String', String, [ + 'charAt', + 'charCodeAt', + 'concat', + 'indexOf', + 'lastIndexOf', + 'match', + 'quote', + 'replace', + 'search', + 'slice', + 'split', + 'substr', + 'substring', + 'trim', + 'toLowerCase', + 'toUpperCase', + ])('Array', Array, [ + 'pop', + 'push', + 'reverse', + 'shift', + 'sort', + 'splice', + 'unshift', + 'concat', + 'join', + 'slice', + 'indexOf', + 'lastIndexOf', + 'filter', + 'forEach', + 'every', + 'map', + 'some', + 'reduce', + 'reduceRight', + ])('Number', Number, ['toExponential', 'toFixed', 'toLocaleString', 'toPrecision'])( + 'Function', + f, + ['apply', 'call', 'bind'] + )('RegExp', RegExp, ['exec', 'test'])('Object', Object, [ + 'create', + 'defineProperty', + 'defineProperties', + 'keys', + 'getPrototypeOf', + 'getOwnPropertyDescriptor', + 'getOwnPropertyNames', + 'preventExtensions', + 'isExtensible', + 'seal', + 'isSealed', + 'freeze', + 'isFrozen', + ])('Date', Date, ['now']); + Object.extend = m.overloadSetter(); + Date.extend('now', function () { + return +new Date(); + }); + new a('Boolean', Boolean); + Number.prototype.$family = function () { + return isFinite(this) ? 'number' : 'null'; + }.hide(); + Number.extend('random', function (s, i) { + return Math.floor(Math.random() * (i - s + 1) + s); + }); + var g = Object.prototype.hasOwnProperty; + Object.extend('forEach', function (i, t, u) { + for (var s in i) { + if (g.call(i, s)) { + t.call(u, i[s], s, i); + } + } + }); + Object.each = Object.forEach; + Array.implement({ + forEach: function (u, v) { + for (var t = 0, s = this.length; t < s; t++) { + if (t in this) { + u.call(v, this[t], t, this); + } + } + }, + each: function (i, s) { + Array.forEach(this, i, s); + return this; + }, + }); + var l = function (i) { + switch (o(i)) { + case 'array': + return i.clone(); + case 'object': + return Object.clone(i); + default: + return i; + } + }; + Array.implement('clone', function () { + var s = this.length, + t = new Array(s); + while (s--) { + t[s] = l(this[s]); + } + return t; + }); + var h = function (s, i, t) { + switch (o(t)) { + case 'object': + if (o(s[i]) == 'object') { + Object.merge(s[i], t); + } else { + s[i] = Object.clone(t); + } + break; + case 'array': + s[i] = t.clone(); + break; + default: + s[i] = t; + } + return s; + }; + Object.extend({ + merge: function (z, u, t) { + if (o(u) == 'string') { + return h(z, u, t); + } + for (var y = 1, s = arguments.length; y < s; y++) { + var w = arguments[y]; + for (var x in w) { + h(z, x, w[x]); + } + } + return z; + }, + clone: function (i) { + var t = {}; + for (var s in i) { + t[s] = l(i[s]); + } + return t; + }, + append: function (w) { + for (var v = 1, t = arguments.length; v < t; v++) { + var s = arguments[v] || {}; + for (var u in s) { + w[u] = s[u]; + } + } + return w; + }, + }); + ['Object', 'WhiteSpace', 'TextNode', 'Collection', 'Arguments'].each(function (i) { + new a(i); + }); + var c = Date.now(); + String.extend('uniqueID', function () { + return (c++).toString(36); + }); +})(); +Array.implement({ + every: function (c, d) { + for (var b = 0, a = this.length >>> 0; b < a; b++) { + if (b in this && !c.call(d, this[b], b, this)) { + return false; + } + } + return true; + }, + filter: function (d, f) { + var c = []; + for (var e, b = 0, a = this.length >>> 0; b < a; b++) { + if (b in this) { + e = this[b]; + if (d.call(f, e, b, this)) { + c.push(e); + } + } + } + return c; + }, + indexOf: function (c, d) { + var b = this.length >>> 0; + for (var a = d < 0 ? Math.max(0, b + d) : d || 0; a < b; a++) { + if (this[a] === c) { + return a; + } + } + return -1; + }, + map: function (c, e) { + var d = this.length >>> 0, + b = Array(d); + for (var a = 0; a < d; a++) { + if (a in this) { + b[a] = c.call(e, this[a], a, this); + } + } + return b; + }, + some: function (c, d) { + for (var b = 0, a = this.length >>> 0; b < a; b++) { + if (b in this && c.call(d, this[b], b, this)) { + return true; + } + } + return false; + }, + clean: function () { + return this.filter(function (a) { + return a != null; + }); + }, + invoke: function (a) { + var b = Array.slice(arguments, 1); + return this.map(function (c) { + return c[a].apply(c, b); + }); + }, + associate: function (c) { + var d = {}, + b = Math.min(this.length, c.length); + for (var a = 0; a < b; a++) { + d[c[a]] = this[a]; + } + return d; + }, + link: function (c) { + var a = {}; + for (var e = 0, b = this.length; e < b; e++) { + for (var d in c) { + if (c[d](this[e])) { + a[d] = this[e]; + delete c[d]; + break; + } + } + } + return a; + }, + contains: function (a, b) { + return this.indexOf(a, b) != -1; + }, + append: function (a) { + this.push.apply(this, a); + return this; + }, + getLast: function () { + return this.length ? this[this.length - 1] : null; + }, + getRandom: function () { + return this.length ? this[Number.random(0, this.length - 1)] : null; + }, + include: function (a) { + if (!this.contains(a)) { + this.push(a); + } + return this; + }, + combine: function (c) { + for (var b = 0, a = c.length; b < a; b++) { + this.include(c[b]); + } + return this; + }, + erase: function (b) { + for (var a = this.length; a--; ) { + if (this[a] === b) { + this.splice(a, 1); + } + } + return this; + }, + empty: function () { + this.length = 0; + return this; + }, + flatten: function () { + var d = []; + for (var b = 0, a = this.length; b < a; b++) { + var c = typeOf(this[b]); + if (c == 'null') { + continue; + } + d = d.concat( + c == 'array' || c == 'collection' || c == 'arguments' || instanceOf(this[b], Array) + ? Array.flatten(this[b]) + : this[b] + ); + } + return d; + }, + pick: function () { + for (var b = 0, a = this.length; b < a; b++) { + if (this[b] != null) { + return this[b]; + } + } + return null; + }, + rgbToHex: function (d) { + if (this.length < 3) { + return null; + } + if (this.length == 4 && this[3] == 0 && !d) { + return 'transparent'; + } + var b = []; + for (var a = 0; a < 3; a++) { + var c = (this[a] - 0).toString(16); + b.push(c.length == 1 ? '0' + c : c); + } + return d ? b : '#' + b.join(''); + }, +}); +String.implement({ + test: function (a, b) { + return (typeOf(a) == 'regexp' ? a : new RegExp('' + a, b)).test(this); + }, + contains: function (a, b) { + return b ? (b + this + b).indexOf(b + a + b) > -1 : String(this).indexOf(a) > -1; + }, + trim: function () { + return String(this).replace(/^\s+|\s+$/g, ''); + }, + clean: function () { + return String(this).replace(/\s+/g, ' ').trim(); + }, + camelCase: function () { + return String(this).replace(/-\D/g, function (a) { + return a.charAt(1).toUpperCase(); + }); + }, + hyphenate: function () { + return String(this).replace(/[A-Z]/g, function (a) { + return '-' + a.charAt(0).toLowerCase(); + }); + }, + capitalize: function () { + return String(this).replace(/\b[a-z]/g, function (a) { + return a.toUpperCase(); + }); + }, + escapeRegExp: function () { + return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1'); + }, + rgbToHex: function (b) { + var a = String(this).match(/\d{1,3}/g); + return a ? a.rgbToHex(b) : null; + }, + substitute: function (a, b) { + return String(this).replace(b || /\\?\{([^{}]+)\}/g, function (d, c) { + if (d.charAt(0) == '\\') { + return d.slice(1); + } + return a[c] != null ? a[c] : ''; + }); + }, +}); +Function.implement({ + bind: function (e) { + var a = this, + b = arguments.length > 1 ? Array.slice(arguments, 1) : null, + d = function () {}; + var c = function () { + var g = e, + h = arguments.length; + if (this instanceof c) { + d.prototype = a.prototype; + g = new d(); + } + var f = + !b && !h + ? a.call(g) + : a.apply(g, b && h ? b.concat(Array.slice(arguments)) : b || arguments); + return g == e ? f : g; + }; + return c; + }, + pass: function (b, c) { + var a = this; + if (b != null) { + b = Array.from(b); + } + return function () { + return a.apply(c, b || arguments); + }; + }, + delay: function (b, c, a) { + return setTimeout(this.pass(a == null ? [] : a, c), b); + }, +}); +Number.alias('each', 'times'); +(function (b) { + var a = {}; + b.each(function (c) { + if (!Number[c]) { + a[c] = function () { + return Math[c].apply(null, [this].concat(Array.from(arguments))); + }; + } + }); + Number.implement(a); +})([ + 'abs', + 'acos', + 'asin', + 'atan', + 'atan2', + 'ceil', + 'cos', + 'exp', + 'floor', + 'log', + 'max', + 'min', + 'pow', + 'sin', + 'sqrt', + 'tan', +]); +(function () { + var a = (this.Class = new Type('Class', function (h) { + if (instanceOf(h, Function)) { + h = { initialize: h }; + } + var g = function () { + e(this); + if (g.$prototyping) { + return this; + } + this.$caller = null; + var i = this.initialize ? this.initialize.apply(this, arguments) : this; + this.$caller = this.caller = null; + return i; + } + .extend(this) + .implement(h); + g.$constructor = a; + g.prototype.$constructor = g; + g.prototype.parent = c; + return g; + })); + var c = function () { + if (!this.$caller) { + throw new Error('The method "parent" cannot be called.'); + } + var g = this.$caller.$name, + h = this.$caller.$owner.parent, + i = h ? h.prototype[g] : null; + if (!i) { + throw new Error('The method "' + g + '" has no parent.'); + } + return i.apply(this, arguments); + }; + var e = function (g) { + for (var h in g) { + var j = g[h]; + switch (typeOf(j)) { + case 'object': + var i = function () {}; + i.prototype = j; + g[h] = e(new i()); + break; + case 'array': + g[h] = j.clone(); + break; + } + } + return g; + }; + var b = function (g, h, j) { + if (j.$origin) { + j = j.$origin; + } + var i = function () { + if (j.$protected && this.$caller == null) { + throw new Error('The method "' + h + '" cannot be called.'); + } + var l = this.caller, + m = this.$caller; + this.caller = m; + this.$caller = i; + var k = j.apply(this, arguments); + this.$caller = m; + this.caller = l; + return k; + }.extend({ $owner: g, $origin: j, $name: h }); + return i; + }; + var f = function (h, i, g) { + if (a.Mutators.hasOwnProperty(h)) { + i = a.Mutators[h].call(this, i); + if (i == null) { + return this; + } + } + if (typeOf(i) == 'function') { + if (i.$hidden) { + return this; + } + this.prototype[h] = g ? i : b(this, h, i); + } else { + Object.merge(this.prototype, h, i); + } + return this; + }; + var d = function (g) { + g.$prototyping = true; + var h = new g(); + delete g.$prototyping; + return h; + }; + a.implement('implement', f.overloadSetter()); + a.Mutators = { + Extends: function (g) { + this.parent = g; + this.prototype = d(g); + }, + Implements: function (g) { + Array.from(g).each(function (j) { + var h = new j(); + for (var i in h) { + f.call(this, i, h[i], true); + } + }, this); + }, + }; +})(); diff --git a/packages/mindplot/lib/components/libraries/underscorejs/underscore-min.js b/libraries/underscore-min.js similarity index 100% rename from packages/mindplot/lib/components/libraries/underscorejs/underscore-min.js rename to libraries/underscore-min.js diff --git a/package.json b/package.json index 11d5d4d0..58facaf6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "build": "lerna run build", "clean": "lerna clean && rm -rf node_modules", "lint": "lerna run lint --stream", - "test": "lerna run test --stream" + "test": "lerna run test --stream", + "test:snapshots": "lerna run test:snapshots --stream" }, "private": true, "devDependencies": { diff --git a/packages/core-js/README.md b/packages/core-js/README.md index 194e9eba..012fbd24 100644 --- a/packages/core-js/README.md +++ b/packages/core-js/README.md @@ -11,6 +11,6 @@ To build up the package core-js and use in production, you have to use command ` To start using core-js it has to be required as a module and then intanciarce as a function ``` -const coreJs = require('core-js'); +import coreJs from 'core-js'; coreJs(); ``` diff --git a/packages/core-js/__tests__/core.test.js b/packages/core-js/__tests__/core.test.js index 9ac914ca..4f505c57 100644 --- a/packages/core-js/__tests__/core.test.js +++ b/packages/core-js/__tests__/core.test.js @@ -1,6 +1,6 @@ 'use strict'; -const coreJs = require('..'); +import coreJs from '..'; describe('core-js', () => { it('needs tests'); diff --git a/packages/core-js/babel.config.json b/packages/core-js/babel.config.json index ed1f3427..3d669db0 100644 --- a/packages/core-js/babel.config.json +++ b/packages/core-js/babel.config.json @@ -13,5 +13,6 @@ } } ] - ] + ], + "sourceType": "unambiguous" } diff --git a/packages/core-js/jsconfig.json b/packages/core-js/jsconfig.json new file mode 100644 index 00000000..d7ce2a30 --- /dev/null +++ b/packages/core-js/jsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "module": "commonjs", + "paths": { + "@libraries/*": ["../../libraries/*"] + } + }, + "exclude": ["node_modules"] +} diff --git a/packages/core-js/lib/core.js b/packages/core-js/lib/core.js deleted file mode 100644 index bfed9fac..00000000 --- a/packages/core-js/lib/core.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -module.exports = coreJs; // eslint-disable-line - -function coreJs() { - global.core = require('./header'); // eslint-disable-line - require('./Functions'); // eslint-disable-line - require('./Utils'); // eslint-disable-line - global.Options = require('@wisemapping/mindplot/lib/components/Options'); - global.BootstrapDialog = require('@wisemapping/mindplot/lib/components/libraries/bootstrap/BootstrapDialog'); - require('@wisemapping/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.Request'); - return global.core; // eslint-disable-line no-undef -} diff --git a/packages/core-js/package.json b/packages/core-js/package.json index a8ef5089..075415ae 100644 --- a/packages/core-js/package.json +++ b/packages/core-js/package.json @@ -1,15 +1,15 @@ { - "name": "@wismapping/core-js", + "name": "@wisemapping/core-js", "version": "0.0.1", "description": "core-js", "license": "ISC", - "main": "lib/core.js", + "main": "dist/core.js", "directories": { - "lib": "lib", + "lib": "src", "test": "__tests__" }, "files": [ - "lib" + "src" ], "publishConfig": { "registry": "https://registry.yarnpkg.com" @@ -20,7 +20,7 @@ }, "scripts": { "build": "webpack --config webpack.prod.js", - "dev": "webpack --mode development" + "dev": "webpack --mode development --config webpack.dev.js" }, "devDependencies": { "@babel/core": "^7.14.6", @@ -32,7 +32,5 @@ "webpack-cli": "^4.7.2", "webpack-merge": "^5.8.0" }, - "dependencies": { - "@wisemapping/mindplot": "^0.0.1" - } -} + "dependencies": {} +} \ No newline at end of file diff --git a/packages/core-js/lib/Functions.js b/packages/core-js/src/Functions.js similarity index 56% rename from packages/core-js/lib/Functions.js rename to packages/core-js/src/Functions.js index 3252e95e..db1c1033 100644 --- a/packages/core-js/lib/Functions.js +++ b/packages/core-js/src/Functions.js @@ -6,12 +6,11 @@ obj - object to inspect */ -global.$defined = function (obj) { - return (obj != undefined); +export const $defined = function (obj) { + return obj != undefined; }; - -global.$assert = function (assert, message) { +export const $assert = function (assert, message) { if (!$defined(assert) || !assert) { logStackTrace(); console.log(message); @@ -19,32 +18,33 @@ global.$assert = function (assert, message) { } }; -Math.sign = function (value) { - return (value >= 0) ? 1 : -1; +export const sign = function (value) { + return value >= 0 ? 1 : -1; }; -function logStackTrace(exception) { - +export function logStackTrace(exception) { if (!$defined(exception)) { try { - throw Error("Unexpected Exception"); + throw Error('Unexpected Exception'); } catch (e) { exception = e; } } - var result = ""; - if (exception.stack) { //Firefox and Chrome... + var result = ''; + if (exception.stack) { + //Firefox and Chrome... result = exception.stack; - } - else if (window.opera && exception.message) { //Opera + } else if (window.opera && exception.message) { + //Opera result = exception.message; - } else { //IE and Safari - result = exception.sourceURL + ': ' + exception.line + "\n\n"; + } else { + //IE and Safari + result = exception.sourceURL + ': ' + exception.line + '\n\n'; var currentFunction = arguments.callee.caller; while (currentFunction) { var fn = currentFunction.toString(); - result = result + "\n" + fn; + result = result + '\n' + fn; currentFunction = currentFunction.caller; } } diff --git a/packages/core-js/lib/Utils.js b/packages/core-js/src/Utils.js similarity index 94% rename from packages/core-js/lib/Utils.js rename to packages/core-js/src/Utils.js index 17071d3d..f0723ca1 100644 --- a/packages/core-js/lib/Utils.js +++ b/packages/core-js/src/Utils.js @@ -16,9 +16,7 @@ * limitations under the License. */ -core.Utils = {}; - -core.Utils.innerXML = function (node) { +export const innerXML = function (node) { // summary: // Implementation of MS's innerXML function. if ($defined(node.innerXML)) { @@ -36,7 +34,7 @@ core.Utils.innerXML = function (node) { /** * Cross-browser implementation of creating an XML document object. */ -core.Utils.createDocument = function () { +export const createDocument = function () { var doc = null; if ($defined(window.ActiveXObject)) { //http://blogs.msdn.com/b/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx @@ -54,4 +52,3 @@ core.Utils.createDocument = function () { return doc; }; - diff --git a/packages/core-js/src/core.js b/packages/core-js/src/core.js new file mode 100644 index 00000000..3cce5665 --- /dev/null +++ b/packages/core-js/src/core.js @@ -0,0 +1,18 @@ +import * as Functions from './Functions'; +import * as Util from './Utils'; + +export const Function = Functions; +export const Utils = Util; + +function coreJs() { + global.core = { + Function, + Utils + }; + Math.sign = Function.sign; + global.$assert = Function.$assert; + global.$defined = Function.$defined; + return global.core; +} + +export default coreJs; diff --git a/packages/core-js/webpack.common.js b/packages/core-js/webpack.common.js index 925a2a9d..7f09214a 100644 --- a/packages/core-js/webpack.common.js +++ b/packages/core-js/webpack.common.js @@ -1,12 +1,15 @@ const path = require('path'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); module.exports = { - entry: './lib/core.js', + entry: './src/core.js', output: { - path: path.resolve(__dirname, 'dist'), + path: path.resolve(__dirname, 'dist'), filename: 'core.js', publicPath: '', + library: { + type: 'umd', + }, }, target: 'web', module: { @@ -14,11 +17,18 @@ module.exports = { { use: 'babel-loader', test: /.js$/, - exclude: /node_modules/, - } + exclude: [ + /node_modules/, + path.resolve(__dirname, '../../libraries/mootools-core-1.4.5'), + path.resolve(__dirname, '../../libraries/underscore-min'), + ] + }, ], }, resolve: { + alias: { + '@libraries': path.resolve(__dirname, '../../libraries/'), + }, extensions: ['.js'], }, plugins: [new CleanWebpackPlugin()], diff --git a/packages/editor/package.json b/packages/editor/package.json index 85af4c39..c45ceee1 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -25,9 +25,9 @@ }, "dependencies": { "@types/styled-components": "^5.1.4", - "@wismapping/core-js": "^0.0.1", + "@wisemapping/core-js": "^0.0.1", "react": "^17.0.1", "react-dom": "^17.0.1", "styled-components": "^5.2.1" } -} +} \ No newline at end of file diff --git a/packages/mindplot/.eslintignore b/packages/mindplot/.eslintignore new file mode 100644 index 00000000..1eae0cf6 --- /dev/null +++ b/packages/mindplot/.eslintignore @@ -0,0 +1,2 @@ +dist/ +node_modules/ diff --git a/packages/mindplot/.eslintrc.json b/packages/mindplot/.eslintrc.json index 128db24a..89fb77f1 100644 --- a/packages/mindplot/.eslintrc.json +++ b/packages/mindplot/.eslintrc.json @@ -4,10 +4,28 @@ "commonjs": true }, "extends": [ - "airbnb-base" + "airbnb-base", + "plugin:cypress/recommended" ], + "globals":{ + "Class": "readonly", + "$": "readonly", + "$assert": "readonly", + "$defined": "readonly", + "$msg": "readonly", + "$notify": "readonly", + "_": "readonly" + }, "plugins": ["only-warn"], "rules": { - "no-underscore-dangle": "off" - } -} \ No newline at end of file + "no-underscore-dangle": "off", + "import/no-extraneous-dependencies": ["error", {"devDependencies": ["!cypress/**/*.js"]}] + }, + "settings": { + "import/resolver": { + "webpack": { + "config": "./webpack.common.js" + } + } + } +} diff --git a/packages/mindplot/.gitignore b/packages/mindplot/.gitignore new file mode 100644 index 00000000..c96f2fe9 --- /dev/null +++ b/packages/mindplot/.gitignore @@ -0,0 +1,4 @@ +cypress/screenshots +cypress/videos +cypress/downloads +cypress/snapshots/*/__diff_output__ \ No newline at end of file diff --git a/packages/mindplot/README.md b/packages/mindplot/README.md index 1b7da5fc..67c00fa0 100644 --- a/packages/mindplot/README.md +++ b/packages/mindplot/README.md @@ -38,6 +38,6 @@ once this is done, it will open the explorer where you can see a menu with the t To start using mindplot it has to be required as a module and then intanciarce as a function ``` -const mindplot = require('@wisemapping/mindplot'); +import mindplot from '@wisemapping/mindplot'; mindplot(); ``` diff --git a/packages/mindplot/__tests__/mindplot.test.js b/packages/mindplot/__tests__/mindplot.test.js index 96c92eb4..58f09d89 100644 --- a/packages/mindplot/__tests__/mindplot.test.js +++ b/packages/mindplot/__tests__/mindplot.test.js @@ -1,7 +1,5 @@ -'use strict'; - -const mindplot = require('..'); +import mindplot from '..'; describe('mindplot', () => { - it('needs tests'); + it('needs tests'); }); diff --git a/packages/mindplot/babel.config.json b/packages/mindplot/babel.config.json index ed1f3427..3d669db0 100644 --- a/packages/mindplot/babel.config.json +++ b/packages/mindplot/babel.config.json @@ -13,5 +13,6 @@ } } ] - ] + ], + "sourceType": "unambiguous" } diff --git a/packages/mindplot/cypress.json b/packages/mindplot/cypress.json new file mode 100644 index 00000000..091c5f0f --- /dev/null +++ b/packages/mindplot/cypress.json @@ -0,0 +1,4 @@ +{ + "video": false, + "videoUploadOnPasses": false +} \ No newline at end of file diff --git a/packages/mindplot/cypress/integration/playground.test.js b/packages/mindplot/cypress/integration/playground.test.js new file mode 100644 index 00000000..35aad990 --- /dev/null +++ b/packages/mindplot/cypress/integration/playground.test.js @@ -0,0 +1,17 @@ +const BASE_URL = 'http://localhost:8081'; + +context('Playground', () => { + it('the playground layout page should match its snapshot', () => { + // TODO: check why this error is happening, and remove this handling + cy.on('uncaught:exception', (err) => { + expect(err.message).to.include('Prediction is incorrectly positioned'); + return false; + }); + cy.visit(`${BASE_URL}/layout.html`); + cy.matchImageSnapshot('layout'); + }); + it('the playground viewmode.html page should match its snapshot', () => { + cy.visit(`${BASE_URL}/viewmode.html`); + cy.matchImageSnapshot('viewmode'); + }); +}); diff --git a/packages/mindplot/cypress/plugins/index.js b/packages/mindplot/cypress/plugins/index.js new file mode 100644 index 00000000..8a0fa140 --- /dev/null +++ b/packages/mindplot/cypress/plugins/index.js @@ -0,0 +1,24 @@ +/// +// *********************************************************** +// This example plugins/index.js can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin'); + +/** + * @type {Cypress.PluginConfig} + */ +module.exports = (on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config + addMatchImageSnapshotPlugin(on, config); +}; diff --git a/packages/mindplot/cypress/snapshots/playground.test.js/layout.snap.png b/packages/mindplot/cypress/snapshots/playground.test.js/layout.snap.png new file mode 100644 index 00000000..19b29fd8 Binary files /dev/null and b/packages/mindplot/cypress/snapshots/playground.test.js/layout.snap.png differ diff --git a/packages/mindplot/cypress/snapshots/playground.test.js/viewmode.snap.png b/packages/mindplot/cypress/snapshots/playground.test.js/viewmode.snap.png new file mode 100644 index 00000000..4ec6503e Binary files /dev/null and b/packages/mindplot/cypress/snapshots/playground.test.js/viewmode.snap.png differ diff --git a/packages/mindplot/cypress/support/commands.js b/packages/mindplot/cypress/support/commands.js new file mode 100644 index 00000000..4f9b69b0 --- /dev/null +++ b/packages/mindplot/cypress/support/commands.js @@ -0,0 +1,29 @@ +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) + +import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command'; + +addMatchImageSnapshotCommand(); diff --git a/packages/mindplot/cypress/support/index.js b/packages/mindplot/cypress/support/index.js new file mode 100644 index 00000000..37a498fb --- /dev/null +++ b/packages/mindplot/cypress/support/index.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/index.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands'; + +// Alternatively you can use CommonJS syntax: +// require('./commands') diff --git a/packages/mindplot/jsconfig.json b/packages/mindplot/jsconfig.json new file mode 100644 index 00000000..a68c753c --- /dev/null +++ b/packages/mindplot/jsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "module": "commonjs", + "paths": { + "@libraries/*": ["../../libraries/*"], + "@commands/*": ["./src/components/commands/*"], + "@layout/*": ["./src/components/layout/*"], + "@libs/*": ["./src/components/libraries/*"], + "@model/*": ["./src/components/model/*"], + "@persistence/*": ["./src/components/persistence/*"], + "@util/*": ["./src/components/util/*"], + "@widget/*": ["./src/components/widget/*"], + "@components/*": ["./src/components/*"] + } + }, + "exclude": ["node_modules"] +} diff --git a/packages/mindplot/lib/components/IconGroup.js b/packages/mindplot/lib/components/IconGroup.js deleted file mode 100644 index 61d85884..00000000 --- a/packages/mindplot/lib/components/IconGroup.js +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright [2015] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * 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. - */ -const web2D = require('@wismapping/web2d'); - -const web2d = web2D(); -const Icon = require('./Icon'); - -const IconGroup = new Class(/** @lends IconGroup */{ - /** - * @constructs - * @param topicId - * @param iconSize - * @throws will throw an error if topicId is null or undefined - * @throws will throw an error if iconSize is null or undefined - */ - initialize(topicId, iconSize) { - $assert($defined(topicId), 'topicId can not be null'); - $assert($defined(iconSize), 'iconSize can not be null'); - - this._icons = []; - this._group = new web2d.Group({ - width: 0, - height: iconSize, - x: 0, - y: 0, - coordSizeWidth: 0, - coordSizeHeight: 100, - }); - this._removeTip = new IconGroup.RemoveTip(this._group, topicId); - this.seIconSize(iconSize, iconSize); - - this._registerListeners(); - }, - - /** */ - setPosition(x, y) { - this._group.setPosition(x, y); - }, - - /** */ - getPosition() { - return this._group.getPosition(); - }, - - /** */ - getNativeElement() { - return this._group; - }, - - /** */ - getSize() { - return this._group.getSize(); - }, - - /** */ - seIconSize(width, height) { - this._iconSize = { width, height }; - this._resize(this._icons.length); - }, - - /** - * @param icon the icon to be added to the icon group - * @param {Boolean} remove - * @throws will throw an error if icon is not defined - */ - addIcon(icon, remove) { - $defined(icon, 'icon is not defined'); - - icon.setGroup(this); - this._icons.push(icon); - - // Adjust group and position ... - this._resize(this._icons.length); - this._positionIcon(icon, this._icons.length - 1); - - const imageShape = icon.getImage(); - this._group.append(imageShape); - - // Register event for the group .. - if (remove) { - this._removeTip.decorate(this._topicId, icon); - } - }, - - _findIconFromModel(iconModel) { - let result = null; - _.each(this._icons, (icon) => { - const elModel = icon.getModel(); - if (elModel.getId() == iconModel.getId()) { - result = icon; - } - }, this); - - if (result == null) { - throw new Error(`Icon can no be found:${iconModel.getId()}, Icons:${this._icons}`); - } - - return result; - }, - - /** */ - removeIconByModel(featureModel) { - $assert(featureModel, 'featureModel can not be null'); - - const icon = this._findIconFromModel(featureModel); - this._removeIcon(icon); - }, - - _removeIcon(icon) { - $assert(icon, 'icon can not be null'); - - this._removeTip.close(0); - this._group.removeChild(icon.getImage()); - - this._icons.erase(icon); - this._resize(this._icons.length); - const me = this; - // Add all again ... - _.each(this._icons, (elem, i) => { - me._positionIcon(elem, i); - }); - }, - - /** */ - moveToFront() { - this._group.moveToFront(); - }, - - _registerListeners() { - this._group.addEvent('click', (event) => { - // Avoid node creation ... - event.stopPropagation(); - }); - - this._group.addEvent('dblclick', (event) => { - event.stopPropagation(); - }); - }, - - _resize(iconsLength) { - this._group.setSize(iconsLength * this._iconSize.width, this._iconSize.height); - - const iconSize = Icon.SIZE + (IconGroup.ICON_PADDING * 2); - this._group.setCoordSize(iconsLength * iconSize, iconSize); - }, - - _positionIcon(icon, order) { - const iconSize = Icon.SIZE + (IconGroup.ICON_PADDING * 2); - icon.getImage().setPosition(iconSize * order + IconGroup.ICON_PADDING, IconGroup.ICON_PADDING); - }, -}); - -/** - * @constant - * @type {Number} - * @default - */ -IconGroup.ICON_PADDING = 5; - -IconGroup.RemoveTip = new Class(/** @lends IconGroup.RemoveTip */{ - /** - * @classdesc inner class of IconGroup - * @constructs - * @param container - */ - initialize(container) { - $assert(container, 'group can not be null'); - this._fadeElem = container; - }, - - /** - * @param topicId - * @param icon - * @throws will throw an error if icon is null or undefined - */ - show(topicId, icon) { - $assert(icon, 'icon can not be null'); - - // Nothing to do ... - if (this._activeIcon != icon) { - // If there is an active icon, close it first ... - if (this._activeIcon) { - this.close(0); - } - - // Now, let move the position the icon... - const pos = icon.getPosition(); - - // Register events ... - const widget = this._buildWeb2d(); - widget.addEvent('click', () => { - icon.remove(); - }); - - const me = this; - - widget.addEvent('mouseover', () => { - me.show(topicId, icon); - }); - - widget.addEvent('mouseout', () => { - me.hide(); - }); - - widget.setPosition(pos.x + 80, pos.y - 50); - this._fadeElem.append(widget); - - // Setup current element ... - this._activeIcon = icon; - this._widget = widget; - } else { - clearTimeout(this._closeTimeoutId); - } - }, - - /** */ - hide() { - this.close(200); - }, - - /** - * @param delay - */ - close(delay) { - // This is not ok, trying to close the same dialog twice ? - if (this._closeTimeoutId) { - clearTimeout(this._closeTimeoutId); - } - - const me = this; - if (this._activeIcon) { - const widget = this._widget; - const close = function () { - me._activeIcon = null; - me._fadeElem.removeChild(widget); - me._widget = null; - me._closeTimeoutId = null; - }; - - if (!$defined(delay) || delay == 0) { - close(); - } else { - this._closeTimeoutId = close.delay(delay); - } - } - }, - - _buildWeb2d() { - const result = new web2d.Group({ - width: 10, - height: 10, - x: 0, - y: 0, - coordSizeWidth: 10, - coordSizeHeight: 10, - }); - - const outerRect = new web2d.Rect(0, { - x: 0, - y: 0, - width: 10, - height: 10, - stroke: '0', - fillColor: 'black', - }); - result.append(outerRect); - outerRect.setCursor('pointer'); - - const innerRect = new web2d.Rect(0, { - x: 1, - y: 1, - width: 8, - height: 8, - stroke: '1 solid white', - fillColor: 'gray', - }); - result.append(innerRect); - - const line = new web2d.Line({ stroke: '1 solid white' }); - line.setFrom(1, 1); - line.setTo(9, 9); - result.append(line); - - const line2 = new web2d.Line({ stroke: '1 solid white' }); - line2.setFrom(1, 9); - line2.setTo(9, 1); - result.append(line2); - - // Some events ... - result.addEvent('mouseover', () => { - innerRect.setFill('#CC0033'); - }); - result.addEvent('mouseout', () => { - innerRect.setFill('gray'); - }); - - result.setSize(50, 50); - return result; - }, - - /** - * @param topicId - * @param icon - */ - decorate(topicId, icon) { - const me = this; - - if (!icon.__remove) { - icon.addEvent('mouseover', () => { - me.show(topicId, icon); - }); - - icon.addEvent('mouseout', () => { - me.hide(); - }); - icon.__remove = true; - } - }, - -}); - -export default IconGroup; diff --git a/packages/mindplot/lib/components/MainTopic.js b/packages/mindplot/lib/components/MainTopic.js deleted file mode 100644 index 6eab42bf..00000000 --- a/packages/mindplot/lib/components/MainTopic.js +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright [2015] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * 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. - */ -const Core = require('@wismapping/core-js'); - -const core = Core(); -const web2D = require('@wismapping/web2d'); - -const web2d = web2D(); - -const Topic = require('./Topic').default; -const { TopicShape } = require('./model/INodeModel'); -const Shape = require('./util/Shape').default; - -const MainTopic = new Class(/** @lends MainTopic */ { - Extends: Topic, - /** - * @extends mindplot.Topic - * @constructs - * @param model - * @param options - */ - initialize(model, options) { - this.parent(model, options); - }, - - INNER_RECT_ATTRIBUTES: { stroke: '0.5 solid #009900' }, - - _buildDragShape() { - const innerShape = this._buildShape(this.INNER_RECT_ATTRIBUTES, this.getShapeType()); - const size = this.getSize(); - innerShape.setSize(size.width, size.height); - innerShape.setPosition(0, 0); - innerShape.setOpacity(0.5); - innerShape.setCursor('default'); - innerShape.setVisibility(true); - - const brColor = this.getBorderColor(); - innerShape.setAttribute('strokeColor', brColor); - - const bgColor = this.getBackgroundColor(); - innerShape.setAttribute('fillColor', bgColor); - - // Create group ... - const groupAttributes = { - width: 100, - height: 100, - coordSizeWidth: 100, - coordSizeHeight: 100, - }; - const group = new web2d.Group(groupAttributes); - group.append(innerShape); - - // Add Text ... - if (this.getShapeType() != TopicShape.IMAGE) { - const textShape = this._buildTextShape(true); - const text = this.getText(); - textShape.setText(text); - textShape.setOpacity(0.5); - group.append(textShape); - } - return group; - }, - - /** */ - updateTopicShape(targetTopic, workspace) { - // Change figure based on the connected topic ... - const model = this.getModel(); - let shapeType = model.getShapeType(); - if (!targetTopic.isCentralTopic()) { - if (!$defined(shapeType)) { - // Get the real shape type ... - shapeType = this.getShapeType(); - this._setShapeType(shapeType, false); - } - } - }, - - /** */ - disconnect(workspace) { - this.parent(workspace); - const size = this.getSize(); - - const model = this.getModel(); - let shapeType = model.getShapeType(); - if (!$defined(shapeType)) { - // Change figure ... - shapeType = this.getShapeType(); - this._setShapeType(TopicShape.ROUNDED_RECT, false); - } - const innerShape = this.getInnerShape(); - innerShape.setVisibility(true); - }, - - _updatePositionOnChangeSize(oldSize, newSize) { - const xOffset = Math.round((newSize.width - oldSize.width) / 2); - const pos = this.getPosition(); - if ($defined(pos)) { - if (pos.x > 0) { - pos.x += xOffset; - } else { - pos.x -= xOffset; - } - this.setPosition(pos); - } - }, - - /** */ - workoutIncomingConnectionPoint(sourcePosition) { - return Shape.workoutIncomingConnectionPoint(this, sourcePosition); - }, - - /** */ - workoutOutgoingConnectionPoint(targetPosition) { - $assert(targetPosition, 'targetPoint can not be null'); - const pos = this.getPosition(); - const isAtRight = Shape.isAtRight(targetPosition, pos); - const size = this.getSize(); - - let result; - if (this.getShapeType() == TopicShape.LINE) { - result = new core.Point(); - const groupPosition = this._elem2d.getPosition(); - const innerShareSize = this.getInnerShape().getSize(); - - if (innerShareSize) { - const magicCorrectionNumber = 0.3; - if (!isAtRight) { - result.x = groupPosition.x + innerShareSize.width - magicCorrectionNumber; - } else { - result.x = groupPosition.x + magicCorrectionNumber; - } - result.y = groupPosition.y + innerShareSize.height; - } else { - // Hack: When the size has not being defined. This is because the node has not being added. - // Try to do our best ... - if (!isAtRight) { - result.x = pos.x + size.width / 2; - } else { - result.x = pos.x - size.width / 2; - } - result.y = pos.y + size.height / 2; - } - } else { - result = Shape.calculateRectConnectionPoint( - pos, - size, - isAtRight, - true, - ); - } - return result; - }, -}); - -export default MainTopic; diff --git a/packages/mindplot/lib/components/commands/AddFeatureToTopicCommand.js b/packages/mindplot/lib/components/commands/AddFeatureToTopicCommand.js deleted file mode 100644 index 259ba865..00000000 --- a/packages/mindplot/lib/components/commands/AddFeatureToTopicCommand.js +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright [2015] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * 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. - */ -const Command = require('../Command').default; - -const AddFeatureToTopicCommand = new Class(/** @lends AddFeatureToTopicCommand */{ - Extends: Command, - /** - * @classdesc This command class handles do/undo of adding features to topics, e.g. an - * icon or a note. For a reference of existing features, refer to {@link mindplot.TopicFeature} - * @constructs - * @param {String} topicId the id of the topic - * @param {String} featureType the id of the feature type to add, e.g. "icon" - * @param {Object} attributes the attribute(s) of the respective feature model - * @extends mindplot.Command - * @see mindplot.model.FeatureModel and subclasses - */ - initialize(topicId, featureType, attributes) { - $assert($defined(topicId), 'topicId can not be null'); - $assert(featureType, 'featureType can not be null'); - $assert(attributes, 'attributes can not be null'); - - this.parent(); - this._topicId = topicId; - this._featureType = featureType; - this._attributes = attributes; - this._featureModel = null; - }, - - /** - * Overrides abstract parent method - */ - execute(commandContext) { - const topic = commandContext.findTopics(this._topicId)[0]; - - // Feature must be created only one time. - if (!this._featureModel) { - const model = topic.getModel(); - this._featureModel = model.createFeature(this._featureType, this._attributes); - } - topic.addFeature(this._featureModel); - }, - - /** - * Overrides abstract parent method - * @see {@link mindplot.Command.undoExecute} - */ - undoExecute(commandContext) { - const topic = commandContext.findTopics(this._topicId)[0]; - topic.removeFeature(this._featureModel); - }, -}); - -export default AddFeatureToTopicCommand; diff --git a/packages/mindplot/lib/components/commands/index.js b/packages/mindplot/lib/components/commands/index.js deleted file mode 100644 index 9ce3d770..00000000 --- a/packages/mindplot/lib/components/commands/index.js +++ /dev/null @@ -1,21 +0,0 @@ -const addFeatureToTopicCommand = require('./AddFeatureToTopicCommand').default; -const addRelationshipCommand = require('./AddRelationshipCommand').default; -const addTopicCommand = require('./AddTopicCommand').default; -const changeFeatureToTopicCommand = require('./ChangeFeatureToTopicCommand').default; -const deleteCommand = require('./DeleteCommand').default; -const dragTopicCommand = require('./DragTopicCommand').default; -const genericFunctionCommand = require('./GenericFunctionCommand').default; -const moveControlPointCommand = require('./MoveControlPointCommand').default; -const removeFeatureFromTopicCommand = require('./RemoveFeatureFromTopicCommand').default; - -export const Commands = { - AddFeatureToTopicCommand: addFeatureToTopicCommand, - AddRelationshipCommand: addRelationshipCommand, - AddTopicCommand: addTopicCommand, - ChangeFeatureToTopicCommand: changeFeatureToTopicCommand, - DeleteCommand: deleteCommand, - DragTopicCommand: dragTopicCommand, - GenericFunctionCommand: genericFunctionCommand, - MoveControlPointCommand: moveControlPointCommand, - RemoveFeatureFromTopicCommand: removeFeatureFromTopicCommand, -}; diff --git a/packages/mindplot/lib/components/index.js b/packages/mindplot/lib/components/index.js deleted file mode 100644 index 6c12d16f..00000000 --- a/packages/mindplot/lib/components/index.js +++ /dev/null @@ -1,108 +0,0 @@ -const actionDispatcher = require('./ActionDispatcher').default; -const actionIcon = require('./ActionIcon').default; -const centralTopic = require('./CentralTopic').default; -const command = require('./Command').default; -const connectionLine = require('./ConnectionLine').default; -const controlPoint = require('./ControlPoint').default; -const designer = require('./Designer').default; -const designerActionRunner = require('./DesignerActionRunner').default; -const designerKeyboard = require('./DesignerKeyboard').default; -const designerModal = require('./DesignerModel').default; -const designerUndoManager = require('./DesignerUndoManager').default; -const dragConnector = require('./DragConnector').default; -const dragManager = require('./DragManager').default; -const dragPivot = require('./DragPivot').default; -const dragTopic = require('./DragTopic').default; -const editorOptions = require('./EditorOptions').default; -const editorProperties = require('./EditorProperties').default; -const events = require('./Events').default; -const footer = require('./footer'); -const header = require('./header'); -const icon = require('./Icon').default; -const iconGroup = require('./IconGroup').default; -const imageIcon = require('./ImageIcon').default; -const keyboard = require('./Keyboard').default; -const linkIcon = require('./LinkIcon').default; -const localSorageManager = require('./LocalStorageManager').default; -const mainTopic = require('./MainTopic').default; -const messages = require('./Messages').default; -const multilineTextEditor = require('./MultilineTextEditor').default; -const nodeGraph = require('./NodeGraph').default; -const noteIcon = require('./NoteIcon').default; -const options = require('./Options').default; - -const persistenceManager = require('./PersistenceManager').default; -const relationship = require('./Relationship').default; -const relationshipPivot = require('./RelationshipPivot').default; -const resetPersistenceManager = require('./RestPersistenceManager').default; - -const screenManager = require('./ScreenManager').default; -const shrinkConnector = require('./ShrinkConnector').default; -const standaloneActionDispatcher = require('./StandaloneActionDispatcher').default; -const textEditor = require('./TextEditor').default; - -const textEditorFactory = require('./TextEditorFactory').default; - -const topic = require('./Topic').default; -const topicEventDispatcher = require('./TopicEventDispatcher').default; -const topicFeature = require('./TopicFeature').default; -const topicStyle = require('./TopicStyle').default; -const workspace = require('./Workspace').default; - -export const Components = { - ActionDispatcher: actionDispatcher, - - ActionIcon: actionIcon, - CentralTopic: centralTopic, - Command: command, - ConnectionLine: connectionLine, - ControlPoint: controlPoint, - Designer: designer, - - DesignerActionRunner: designerActionRunner, - DesignerKeyboard: designerKeyboard, - DesignerModel: designerModal, - DesignerUndoManager: designerUndoManager, - - DragConnector: dragConnector, - DragManager: dragManager, - DragPivot: dragPivot, - DragTopic: dragTopic, - EditorOptions: editorOptions, - EditorProperties: editorProperties, - Events: events, - - footer, - header, - - Icon: icon, - IconGroup: iconGroup, - ImageIcon: imageIcon, - Keyboard: keyboard, - LinkIcon: linkIcon, - - localSorageManager, - MainTopic: mainTopic, - - Messages: messages, - MultilineTextEditor: multilineTextEditor, - NodeGraph: nodeGraph, - NoteIcon: noteIcon, - Options: options, - - PersistenceManager: persistenceManager, - Relationship: relationship, - RelationshipPivot: relationshipPivot, - RestPersistenceManager: resetPersistenceManager, - ScreenManager: screenManager, - ShrinkConnector: shrinkConnector, - StandaloneActionDispatcher: standaloneActionDispatcher, - TextEditor: textEditor, - TextEditorFactory: textEditorFactory, - - Topic: topic, - TopicEventDispatcher: topicEventDispatcher, - TopicFeature: topicFeature, - TopicStyle: topicStyle, - Workspace: workspace, -}; diff --git a/packages/mindplot/lib/components/layout/index.js b/packages/mindplot/lib/components/layout/index.js deleted file mode 100644 index c4f9dac4..00000000 --- a/packages/mindplot/lib/components/layout/index.js +++ /dev/null @@ -1,27 +0,0 @@ -const abstractBasicSorter = require('./AbstractBasicSorter').default; -const balancedSorter = require('./BalancedSorter').default; -const changeEvent = require('./ChangeEvent').default; -const childrenSorterStrategy = require('./ChildrenSorterStrategy').default; -const eventBus = require('./EventBus').default; -const eventBusDispatcher = require('./EventBusDispatcher').default; -const gridSorter = require('./GridSorter').default; -const layoutManager = require('./LayoutManager').default; -const node = require('./Node').default; -const originalLayout = require('./OriginalLayout').default; -const rootedTreeSet = require('./RootedTreeSet').default; -const symmetricSorter = require('./SymmetricSorter').default; - -export const Layout = { - AbstractBasicSorter: abstractBasicSorter, - BalancedSorter: balancedSorter, - ChangeEvent: changeEvent, - ChildrenSorterStrategy: childrenSorterStrategy, - EventBus: eventBus, - EventBusDispatcher: eventBusDispatcher, - GridSorter: gridSorter, - LayoutManager: layoutManager, - Node: node, - OriginalLayout: originalLayout, - RootedTreeSet: rootedTreeSet, - SymmetricSorter: symmetricSorter, -}; diff --git a/packages/mindplot/lib/components/model/index.js b/packages/mindplot/lib/components/model/index.js deleted file mode 100644 index 55ff4f89..00000000 --- a/packages/mindplot/lib/components/model/index.js +++ /dev/null @@ -1,21 +0,0 @@ -const featureModel = require('./FeatureModel').default; -const iconModel = require('./IconModel').default; -const iMindmap = require('./IMindmap').default; -const iNodeModel = require('./INodeModel').default; -const linkModel = require('./LinkModel').default; -const noteModel = require('./NoteModel').default; -const mindmap = require('./Mindmap').default; -const nodeModel = require('./NodeModel').default; -const relationshipModel = require('./RelationshipModel').default; - -export const Model = { - FeatureModel: featureModel, - IconModel: iconModel, - IMindmap: iMindmap, - INodeModel: iNodeModel, - LinkModel: linkModel, - NoteModel: noteModel, - Mindmap: mindmap, - NodeModel: nodeModel, - RelationshipModel: relationshipModel, -}; diff --git a/packages/mindplot/lib/components/persistence/index.js b/packages/mindplot/lib/components/persistence/index.js deleted file mode 100644 index b2525dd5..00000000 --- a/packages/mindplot/lib/components/persistence/index.js +++ /dev/null @@ -1,17 +0,0 @@ -const beta2PelaMigrator = require('./Beta2PelaMigrator').default; -const modelCodeName = require('./ModelCodeName').default; -const pela2TangoMigrator = require('./Pela2TangoMigrator').default; -const xmlSerializer_Beta = require('./XMLSerializer_Beta').default; -const xmlSerializer_Pela = require('./XMLSerializer_Pela').default; -const xmlSerializer_Tango = require('./XMLSerializer_Tango').default; -const xmlSerializerFactory = require('./XMLSerializerFactory').default; - -export const Persistence = { - Beta2PelaMigrator: beta2PelaMigrator, - ModelCodeName: modelCodeName, - Pela2TangoMigrator: pela2TangoMigrator, - XMLSerializer_Beta: xmlSerializer_Beta, - XMLSerializer_Pela: xmlSerializer_Pela, - XMLSerializer_Tango: xmlSerializer_Tango, - XMLSerializerFactory: xmlSerializerFactory, -}; diff --git a/packages/mindplot/lib/components/util/index.js b/packages/mindplot/lib/components/util/index.js deleted file mode 100644 index 527fe177..00000000 --- a/packages/mindplot/lib/components/util/index.js +++ /dev/null @@ -1,7 +0,0 @@ -const fadeEffect = require('./FadeEffect').default; -const shape = require('./Shape').default; - -export const Utils = { - FadeEffect: fadeEffect, - Shape: shape, -}; diff --git a/packages/mindplot/lib/components/widget/index.js b/packages/mindplot/lib/components/widget/index.js deleted file mode 100644 index 1fbb5fb9..00000000 --- a/packages/mindplot/lib/components/widget/index.js +++ /dev/null @@ -1,37 +0,0 @@ -const colorPalettePanel = require('./ColorPalettePanel').default; -const floatingTip = require('./FloatingTip').default; -const fontFamilyPanel = require('./FontFamilyPanel').default; -const fontSizePanel = require('./FontSizePanel').default; -const iconPanel = require('./IconPanel').default; -const iMenu = require('./IMenu').default; -const keyboardShortcutTooltip = require('./KeyboardShortcutTooltip').default; -const linkEditor = require('./LinkEditor').default; -const linkIconTooltip = require('./LinkIconTooltip').default; -const listToolbarPanel = require('./ListToolbarPanel').default; -const menu = require('./Menu').default; -const modalDialogNotifier = require('./ModalDialogNotifier').default; -const noteEditor = require('./NoteEditor').default; -const toolbarItem = require('./ToolbarItem').default; -const toolbarNotifier = require('./ToolbarNotifier').default; -const toolbarPanelItem = require('./ToolbarPaneItem').default; -const topicShapePanel = require('./TopicShapePanel').default; - -export const Widgets = { - ColorPalettePanel: colorPalettePanel, - FloatingTip: floatingTip, - FontFamilyPanel: fontFamilyPanel, - FontSizePanel: fontSizePanel, - IconPanel: iconPanel, - IMenu: iMenu, - KeyboardShortcutTooltip: keyboardShortcutTooltip, - LinkEditor: linkEditor, - LinkIconTooltip: linkIconTooltip, - ListToolbarPanel: listToolbarPanel, - Menu: menu, - ModalDialogNotifier: modalDialogNotifier, - NoteEditor: noteEditor, - ToolbarItem: toolbarItem, - ToolbarNotifier: toolbarNotifier, - ToolbarPaneItem: toolbarPanelItem, - TopicShapePanel: topicShapePanel, -}; diff --git a/packages/mindplot/lib/mindplot.js b/packages/mindplot/lib/mindplot.js deleted file mode 100644 index bbc7aca1..00000000 --- a/packages/mindplot/lib/mindplot.js +++ /dev/null @@ -1,56 +0,0 @@ -module.exports = mindplot; //eslint-disable-line - -function mindplot() { - // Jquery for mindplot and bootstrap - global.$ = require('jquery'); - global.jQuery = require('jquery'); - - // Mootools for the classes of Mindplot - require('mootools'); - - // Underscore handling common tasks - global._ = require('underscore'); - - // Core-js packages of Wisemapping - global.core = require('@wismapping/core-js'); - - define(['raphael'], (Raphael) => { - global.Raphael = Raphael; - }); - require('../test/playground/lib/raphael-plugins'); - - // Bootsrap for styles - require('./components/libraries/bootstrap/js/bootstrap.min'); - - /* * * * * * * * - * MINDPLOT * - * * * * * * * */ - - // Commands - const { Commands } = require('./components/commands'); - - // Layout - const { Layout } = require('./components/layout'); - - // Model - - const { Model } = require('./components/model'); - - // Persistence - const { Persistence } = require('./components/persistence'); - - // Widgets - const { Widgets } = require('./components/widget'); - - // Components - const { Components } = require('./components'); - - return { - commands: Commands, - layout: Layout, - models: Model, - persistence: Persistence, - widget: Widgets, - component: Components, - }; -} diff --git a/packages/mindplot/package.json b/packages/mindplot/package.json index 6ed51f96..bdeac472 100644 --- a/packages/mindplot/package.json +++ b/packages/mindplot/package.json @@ -2,15 +2,15 @@ "name": "@wisemapping/mindplot", "version": "0.0.1", "description": "mindplot", - "homepage": "http://localhost:8080/react/packages/mindplot", + "homepage": "http://localhost:8081/react/packages/mindplot", "license": "ISC", - "main": "lib/mindplot.js", + "main": "dist/main.js", "directories": { - "lib": "lib", + "lib": "src", "test": "__tests__" }, "files": [ - "lib" + "src" ], "publishConfig": { "registry": "https://registry.yarnpkg.com" @@ -22,14 +22,18 @@ "scripts": { "build": "webpack --config webpack.prod.js", "dev": "webpack serve --config webpack.dev.js", - "playground": "webpack serve --config webpack.playground.js" + "lint": "eslint src", + "playground": "webpack serve --config webpack.playground.js", + "cy:run": "cypress run", + "cy:run:update": "cypress run --env updateSnapshots=true", + "test:snapshots": "start-server-and-test playground http-get://localhost:8081 cy:run", + "test:snapshots:update": "start-server-and-test playground http-get://localhost:8081 cy:run:update" }, "dependencies": { - "@wismapping/core-js": "^0.0.1", - "@wismapping/web2d": "^0.0.1", + "@wisemapping/core-js": "^0.0.1", + "@wisemapping/web2d": "^0.0.1", "jquery": "2.1.0", "mootools": "1.4.5", - "raphael": "^2.3.0", "underscore": "^1.13.1" }, "devDependencies": { @@ -38,15 +42,20 @@ "@babel/preset-env": "^7.14.7", "babel-loader": "^8.2.2", "clean-webpack-plugin": "^4.0.0-alpha.0", + "copy-webpack-plugin": "^10.0.0", "core-js": "^3.15.2", + "cypress": "^8.6.0", + "cypress-image-snapshot": "^4.0.1", "eslint": "^5.16.0", "eslint-config-airbnb-base": "^14.2.1", "eslint-config-standard": "^16.0.3", "eslint-loader": "^4.0.2", + "eslint-plugin-cypress": "^2.12.1", "eslint-plugin-import": "^2.24.2", "eslint-plugin-only-warn": "^1.0.3", "html-webpack-plugin": "^5.3.2", "nodemon": "^2.0.12", + "start-server-and-test": "^1.14.0", "webpack": "^5.44.0", "webpack-cli": "^4.7.2", "webpack-dev-server": "^3.11.2", diff --git a/packages/mindplot/lib/components/.gitignore b/packages/mindplot/src/components/.gitignore similarity index 100% rename from packages/mindplot/lib/components/.gitignore rename to packages/mindplot/src/components/.gitignore diff --git a/packages/mindplot/lib/components/ActionDispatcher.js b/packages/mindplot/src/components/ActionDispatcher.js similarity index 66% rename from packages/mindplot/lib/components/ActionDispatcher.js rename to packages/mindplot/src/components/ActionDispatcher.js index fc3fd102..447806fc 100644 --- a/packages/mindplot/lib/components/ActionDispatcher.js +++ b/packages/mindplot/src/components/ActionDispatcher.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-vars */ /* * Copyright [2015] [wisemapping] * @@ -15,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Events = require('./Events').default; +import Events from './Events'; // noinspection JSUnusedLocalSymbols const ActionDispatcher = new Class({ @@ -25,79 +26,79 @@ const ActionDispatcher = new Class({ }, addRelationship(model, mindmap) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, addTopics(models, parentTopicId) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, deleteEntities(topicsIds, relIds) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, dragTopic(topicId, position, order, parentTopic) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, moveTopic(topicId, position) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, moveControlPoint(ctrlPoint, point) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeFontFamilyToTopic(topicIds, fontFamily) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeFontStyleToTopic(topicsIds) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeFontColorToTopic(topicsIds, color) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeFontSizeToTopic(topicsIds, size) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeBackgroundColorToTopic(topicsIds, color) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeBorderColorToTopic(topicsIds, color) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeShapeTypeToTopic(topicsIds, shapeType) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeFontWeightToTopic(topicsIds) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeTextToTopic(topicsIds, text) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, shrinkBranch(topicsIds, collapse) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, addFeatureToTopic(topicId, type, attributes) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, changeFeatureToTopic(topicId, featureId, attributes) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, removeFeatureFromTopic(topicId, featureId) { - throw 'method must be implemented.'; + throw new Error('method must be implemented.'); }, }); diff --git a/packages/mindplot/lib/components/ActionIcon.js b/packages/mindplot/src/components/ActionIcon.js similarity index 97% rename from packages/mindplot/lib/components/ActionIcon.js rename to packages/mindplot/src/components/ActionIcon.js index 96ed6df7..73bf33a9 100644 --- a/packages/mindplot/lib/components/ActionIcon.js +++ b/packages/mindplot/src/components/ActionIcon.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Icon = require('./Icon').default; +import Icon from './Icon'; const ActionIcon = new Class({ Extends: Icon, diff --git a/packages/mindplot/lib/components/CentralTopic.js b/packages/mindplot/src/components/CentralTopic.js similarity index 85% rename from packages/mindplot/lib/components/CentralTopic.js rename to packages/mindplot/src/components/CentralTopic.js index d94ad143..644b1a78 100644 --- a/packages/mindplot/lib/components/CentralTopic.js +++ b/packages/mindplot/src/components/CentralTopic.js @@ -15,11 +15,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); - -const core = Core(); -const Topic = require('./Topic').default; -const Shape = require('./util/Shape').default; +import web2d from '@wisemapping/web2d'; +import Topic from './Topic'; +import Shape from './util/Shape'; const CentralTopic = new Class( /** @lends CentralTopic */ { @@ -37,7 +35,8 @@ const CentralTopic = new Class( _registerEvents() { this.parent(); - // This disable the drag of the central topic. But solves the problem of deselecting the nodes when the screen is clicked. + // This disable the drag of the central topic. + // But solves the problem of deselecting the nodes when the screen is clicked. this.addEvent('mousedown', (event) => { event.stopPropagation(); }); @@ -59,7 +58,7 @@ const CentralTopic = new Class( _updatePositionOnChangeSize() { // Center main topic ... - const zeroPoint = new core.Point(0, 0); + const zeroPoint = new web2d.Point(0, 0); this.setPosition(zeroPoint); }, diff --git a/packages/mindplot/lib/components/Command.js b/packages/mindplot/src/components/Command.js similarity index 100% rename from packages/mindplot/lib/components/Command.js rename to packages/mindplot/src/components/Command.js diff --git a/packages/mindplot/lib/components/ConnectionLine.js b/packages/mindplot/src/components/ConnectionLine.js similarity index 91% rename from packages/mindplot/lib/components/ConnectionLine.js rename to packages/mindplot/src/components/ConnectionLine.js index e5a78b54..ec723775 100644 --- a/packages/mindplot/lib/components/ConnectionLine.js +++ b/packages/mindplot/src/components/ConnectionLine.js @@ -15,16 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import web2d from '@wisemapping/web2d'; -const core = Core(); -const web2D = require('@wismapping/web2d'); - -const web2d = web2D(); - -const INodeModel = require('./model/INodeModel').default; -const { TopicShape } = require('./model/INodeModel'); -const Topic = require('./Topic').default; +import INodeModel, { TopicShape } from './model/INodeModel'; +import TopicConfig from './TopicConfig'; const ConnectionLine = new Class({ initialize(sourceNode, targetNode, lineType) { @@ -58,7 +52,7 @@ const ConnectionLine = new Class({ const srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition()); const destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition()); const deltaX = (srcPos.x - destPos.x) / 3; - return [new core.Point(deltaX, 0), new core.Point(-deltaX, 0)]; + return [new web2d.Point(deltaX, 0), new web2d.Point(-deltaX, 0)]; }, _createLine(lineType, defaultStyle) { @@ -106,8 +100,8 @@ const ConnectionLine = new Class({ const targetTopic = this._targetTopic; const targetPosition = targetTopic.getPosition(); - let sPos; let - tPos; + let sPos; + let tPos; sPos = sourceTopic.workoutOutgoingConnectionPoint(targetPosition); tPos = targetTopic.workoutIncomingConnectionPoint(sourcePosition); @@ -126,10 +120,10 @@ const ConnectionLine = new Class({ _positionateConnector(targetTopic) { const targetPosition = targetTopic.getPosition(); - const offset = Topic.CONNECTOR_WIDTH / 2; + const offset = TopicConfig.CONNECTOR_WIDTH / 2; const targetTopicSize = targetTopic.getSize(); - let y; let - x; + let y; + let x; if (targetTopic.getShapeType() == TopicShape.LINE) { y = targetTopicSize.height; } else { @@ -143,7 +137,7 @@ const ConnectionLine = new Class({ x = targetTopicSize.width; connector.setPosition(x, y); } else { - x = -Topic.CONNECTOR_WIDTH; + x = -TopicConfig.CONNECTOR_WIDTH; } connector.setPosition(x, y); } diff --git a/packages/mindplot/lib/components/ControlPoint.js b/packages/mindplot/src/components/ControlPoint.js similarity index 79% rename from packages/mindplot/lib/components/ControlPoint.js rename to packages/mindplot/src/components/ControlPoint.js index f623453e..e85a5cfc 100644 --- a/packages/mindplot/lib/components/ControlPoint.js +++ b/packages/mindplot/src/components/ControlPoint.js @@ -15,15 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import web2d from '@wisemapping/web2d'; -const core = Core(); -const web2D = require('@wismapping/web2d'); - -const web2d = web2D(); - -const Shape = require('./util/Shape').default; -const ActionDispatcher = require('./ActionDispatcher').default; +import Shape from './util/Shape'; +import ActionDispatcher from './ActionDispatcher'; const ControlPoint = new Class({ initialize() { @@ -46,29 +41,31 @@ const ControlPoint = new Class({ control2.setCursor('pointer'); this._controlPointsController = [control1, control2]; - this._controlLines = [new web2d.Line({ strokeColor: '#6589de', strokeWidth: 1, opacity: 0.3 }), - new web2d.Line({ strokeColor: '#6589de', strokeWidth: 1, opacity: 0.3 })]; + this._controlLines = [ + new web2d.Line({ strokeColor: '#6589de', strokeWidth: 1, opacity: 0.3 }), + new web2d.Line({ strokeColor: '#6589de', strokeWidth: 1, opacity: 0.3 }), + ]; this._isBinded = false; const me = this; this._controlPointsController[0].addEvent('mousedown', (event) => { - (me._mouseDown)(event, ControlPoint.FROM, me); + me._mouseDown(event, ControlPoint.FROM, me); }); this._controlPointsController[0].addEvent('click', (event) => { - (me._mouseClick)(event); + me._mouseClick(event); }); this._controlPointsController[0].addEvent('dblclick', (event) => { - (me._mouseClick)(event); + me._mouseClick(event); }); this._controlPointsController[1].addEvent('mousedown', (event) => { - (me._mouseDown)(event, ControlPoint.TO, me); + me._mouseDown(event, ControlPoint.TO, me); }); this._controlPointsController[1].addEvent('click', (event) => { - (me._mouseClick)(event); + me._mouseClick(event); }); this._controlPointsController[1].addEvent('dblclick', (event) => { - (me._mouseClick)(event); + me._mouseClick(event); }); }, @@ -93,29 +90,39 @@ const ControlPoint = new Class({ _createControlPoint() { this._controls = this._line.getLine().getControlPoints(); let pos = this._line.getLine().getFrom(); - this._controlPointsController[0].setPosition(this._controls[ControlPoint.FROM].x + pos.x, this._controls[ControlPoint.FROM].y + pos.y - 3); + this._controlPointsController[0].setPosition( + this._controls[ControlPoint.FROM].x + pos.x, + this._controls[ControlPoint.FROM].y + pos.y - 3, + ); this._controlLines[0].setFrom(pos.x, pos.y); - this._controlLines[0].setTo(this._controls[ControlPoint.FROM].x + pos.x + 3, this._controls[ControlPoint.FROM].y + pos.y); + this._controlLines[0].setTo( + this._controls[ControlPoint.FROM].x + pos.x + 3, + this._controls[ControlPoint.FROM].y + pos.y, + ); pos = this._line.getLine().getTo(); this._controlLines[1].setFrom(pos.x, pos.y); - this._controlLines[1].setTo(this._controls[ControlPoint.TO].x + pos.x + 3, this._controls[ControlPoint.TO].y + pos.y); - this._controlPointsController[1].setPosition(this._controls[ControlPoint.TO].x + pos.x, this._controls[ControlPoint.TO].y + pos.y - 3); + this._controlLines[1].setTo( + this._controls[ControlPoint.TO].x + pos.x + 3, + this._controls[ControlPoint.TO].y + pos.y, + ); + this._controlPointsController[1].setPosition( + this._controls[ControlPoint.TO].x + pos.x, + this._controls[ControlPoint.TO].y + pos.y - 3, + ); }, - _removeLine() { - - }, + _removeLine() {}, _mouseDown(event, point, me) { if (!this._isBinded) { this._isBinded = true; this._mouseMoveFunction = function (event) { - (me._mouseMoveEvent)(event, point, me); + me._mouseMoveEvent(event, point, me); }; this._workspace.getScreenManager().addEvent('mousemove', this._mouseMoveFunction); this._mouseUpFunction = function (event) { - (me._mouseUp)(event, point, me); + me._mouseUp(event, point, me); }; this._workspace.getScreenManager().addEvent('mouseup', this._mouseUpFunction); } @@ -132,15 +139,15 @@ const ControlPoint = new Class({ if (point == 0) { cords = Shape.calculateRelationShipPointCoordinates(this._line.getSourceTopic(), pos); this._line.setFrom(cords.x, cords.y); - this._line.setSrcControlPoint(new core.Point(pos.x - cords.x, pos.y - cords.y)); + this._line.setSrcControlPoint(new web2d.Point(pos.x - cords.x, pos.y - cords.y)); } else { cords = Shape.calculateRelationShipPointCoordinates(this._line.getTargetTopic(), pos); this._line.setTo(cords.x, cords.y); - this._line.setDestControlPoint(new core.Point(pos.x - cords.x, pos.y - cords.y)); + this._line.setDestControlPoint(new web2d.Point(pos.x - cords.x, pos.y - cords.y)); } - this._controls[point].x = (pos.x - cords.x); - this._controls[point].y = (pos.y - cords.y); + this._controls[point].x = pos.x - cords.x; + this._controls[point].y = pos.y - cords.y; this._controlPointsController[point].setPosition(pos.x - 5, pos.y - 3); this._controlLines[point].setFrom(cords.x, cords.y); this._controlLines[point].setTo(pos.x - 2, pos.y); diff --git a/packages/mindplot/lib/components/Designer.js b/packages/mindplot/src/components/Designer.js similarity index 93% rename from packages/mindplot/lib/components/Designer.js rename to packages/mindplot/src/components/Designer.js index 1d3c0f0d..f2a46912 100644 --- a/packages/mindplot/lib/components/Designer.js +++ b/packages/mindplot/src/components/Designer.js @@ -15,34 +15,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Events = require('./Events').default; -const Messages = require('./Messages').default; +import Events from './Events'; +import Messages from './Messages'; -const { StandaloneActionDispatcher, CommandContext } = require('./StandaloneActionDispatcher'); -const ActionDispatcher = require('./ActionDispatcher').default; +import { StandaloneActionDispatcher, CommandContext } from './StandaloneActionDispatcher'; +import ActionDispatcher from './ActionDispatcher'; -const DesignerModel = require('./DesignerModel').default; -const DesignerKeyboard = require('./DesignerKeyboard').default; +import DesignerModel from './DesignerModel'; +import DesignerKeyboard from './DesignerKeyboard'; -const ScreenManager = require('./ScreenManager').default; -const Workspace = require('./Workspace').default; +import ScreenManager from './ScreenManager'; +import Workspace from './Workspace'; -const DragConnector = require('./DragConnector').default; -const DragManager = require('./DragManager').default; -const RelationshipPivot = require('./RelationshipPivot').default; -const Relationship = require('./Relationship').default; +import DragConnector from './DragConnector'; +import DragManager from './DragManager'; +import RelationshipPivot from './RelationshipPivot'; +import Relationship from './Relationship'; -const TopicEventDispatcher = require('./TopicEventDispatcher').default; -const TopicFeature = require('./TopicFeature').default; -const { TopicEvent } = require('./TopicEventDispatcher'); +import TopicEventDispatcher, { TopicEvent } from './TopicEventDispatcher'; +import TopicFeature from './TopicFeature'; -const NodeGraph = require('./NodeGraph').default; +import NodeGraphUtils from './NodeGraphUtils'; -const EventBusDispatcher = require('./layout/EventBusDispatcher').default; -const LayoutManager = require('./layout/LayoutManager').default; +import EventBus from './layout/EventBus'; +import EventBusDispatcher from './layout/EventBusDispatcher'; +import LayoutManager from './layout/LayoutManager'; -const INodeModel = require('./model/INodeModel').default; -const { TopicShape } = require('./model/INodeModel'); +import INodeModel, { TopicShape } from './model/INodeModel'; const Designer = new Class( /** @lends Designer */ { @@ -163,17 +162,14 @@ const Designer = new Class( }); // Create nodes on double click... - screenManager.addEvent( - 'dblclick', - (event) => { - if (workspace.isWorkspaceEventsEnabled()) { - const mousePos = screenManager.getWorkspaceMousePosition(event); - const centralTopic = me.getModel().getCentralTopic(); - const model = me._createChildModel(centralTopic, mousePos); - this._actionDispatcher.addTopics([model], [centralTopic.getId()]); - } - }, - ); + screenManager.addEvent('dblclick', (event) => { + if (workspace.isWorkspaceEventsEnabled()) { + const mousePos = screenManager.getWorkspaceMousePosition(event); + const centralTopic = me.getModel().getCentralTopic(); + const model = me._createChildModel(centralTopic, mousePos); + this._actionDispatcher.addTopics([model], [centralTopic.getId()]); + } + }); // Register mouse drag and drop event ... function noopHandler(evt) { @@ -242,7 +238,7 @@ const Designer = new Class( */ _buildNodeGraph(model, readOnly) { // Create node graph ... - const topic = NodeGraph.create(model, { readOnly }); + const topic = NodeGraphUtils.create(model, { readOnly }); this.getModel().addTopic(topic); const me = this; // Add Topic events ... @@ -520,7 +516,7 @@ const Designer = new Class( /** * @private * @param {mindplot.Topic} topic the parent topic of the child to create the NodeModel for - * @param {core.Point} mousePos the mouse position + * @param {web2d.Point} mousePos the mouse position * @return {mindplot.NodeModel} the node model for the new child */ _createChildModel(topic, mousePos) { @@ -803,9 +799,9 @@ const Designer = new Class( const targetTopic = dmodel.findTopicById(targetTopicId); $assert( targetTopic, - `targetTopic could not be found:${ - targetTopicId - }${dmodel.getTopics().map((e) => e.getId())}`, + `targetTopic could not be found:${targetTopicId}${dmodel + .getTopics() + .map((e) => e.getId())}`, ); // Build relationship line .... @@ -884,7 +880,8 @@ const Designer = new Class( // If there are more than one node selected, $notify($msg('ENTITIES_COULD_NOT_BE_DELETED')); return; - } if (topics.length == 1 && topics[0].isCentralTopic()) { + } + if (topics.length == 1 && topics[0].isCentralTopic()) { $notify($msg('CENTRAL_TOPIC_CAN_NOT_BE_DELETED')); return; } diff --git a/packages/mindplot/lib/components/DesignerActionRunner.js b/packages/mindplot/src/components/DesignerActionRunner.js similarity index 93% rename from packages/mindplot/lib/components/DesignerActionRunner.js rename to packages/mindplot/src/components/DesignerActionRunner.js index 777e1737..6cd3401e 100644 --- a/packages/mindplot/lib/components/DesignerActionRunner.js +++ b/packages/mindplot/src/components/DesignerActionRunner.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const DesignerUndoManager = require('./DesignerUndoManager').default; -const EventBus = require('./layout/EventBus').default; +import DesignerUndoManager from './DesignerUndoManager'; +import EventBus from './layout/EventBus'; const DesignerActionRunner = new Class({ initialize(commandContext, notifier) { diff --git a/packages/mindplot/lib/components/DesignerKeyboard.js b/packages/mindplot/src/components/DesignerKeyboard.js similarity index 97% rename from packages/mindplot/lib/components/DesignerKeyboard.js rename to packages/mindplot/src/components/DesignerKeyboard.js index c7e85a92..35816de6 100644 --- a/packages/mindplot/lib/components/DesignerKeyboard.js +++ b/packages/mindplot/src/components/DesignerKeyboard.js @@ -15,19 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Keyboard = require('./Keyboard').default; +import Keyboard from './Keyboard'; const DesignerKeyboard = new Class({ Extends: Keyboard, - Static: { - register(designer) { - this._instance = new DesignerKeyboard(designer); - }, - - getInstance() { - return this._instance; - }, - }, initialize(designer) { $assert(designer, 'designer can not be null'); @@ -430,4 +421,12 @@ DesignerKeyboard.specialKeys = { 224: 'meta', }; +DesignerKeyboard.register = function register(designer) { + this._instance = new DesignerKeyboard(designer); +}; + +DesignerKeyboard.getInstance = function getInstance() { + return this._instance; +}; + export default DesignerKeyboard; diff --git a/packages/mindplot/lib/components/DesignerModel.js b/packages/mindplot/src/components/DesignerModel.js similarity index 99% rename from packages/mindplot/lib/components/DesignerModel.js rename to packages/mindplot/src/components/DesignerModel.js index 994214a0..11289985 100644 --- a/packages/mindplot/lib/components/DesignerModel.js +++ b/packages/mindplot/src/components/DesignerModel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Events = require('./Events').default; +import Events from './Events'; const DesignerModel = new Class(/** @lends DesignerModel */{ Implements: [Events], diff --git a/packages/mindplot/lib/components/DesignerUndoManager.js b/packages/mindplot/src/components/DesignerUndoManager.js similarity index 100% rename from packages/mindplot/lib/components/DesignerUndoManager.js rename to packages/mindplot/src/components/DesignerUndoManager.js diff --git a/packages/mindplot/lib/components/DragConnector.js b/packages/mindplot/src/components/DragConnector.js similarity index 100% rename from packages/mindplot/lib/components/DragConnector.js rename to packages/mindplot/src/components/DragConnector.js diff --git a/packages/mindplot/lib/components/DragManager.js b/packages/mindplot/src/components/DragManager.js similarity index 98% rename from packages/mindplot/lib/components/DragManager.js rename to packages/mindplot/src/components/DragManager.js index 6c855ed2..9d9cbdca 100644 --- a/packages/mindplot/lib/components/DragManager.js +++ b/packages/mindplot/src/components/DragManager.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const DragTopic = require('./DragTopic').default; +import DragTopic from './DragTopic'; const DragManager = new Class({ initialize(workspace, eventDispatcher) { diff --git a/packages/mindplot/lib/components/DragPivot.js b/packages/mindplot/src/components/DragPivot.js similarity index 89% rename from packages/mindplot/lib/components/DragPivot.js rename to packages/mindplot/src/components/DragPivot.js index c689789e..5ce7ff4c 100644 --- a/packages/mindplot/lib/components/DragPivot.js +++ b/packages/mindplot/src/components/DragPivot.js @@ -15,21 +15,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import web2d from '@wisemapping/web2d'; -const core = Core(); -const web2D = require('@wismapping/web2d'); - -const web2d = web2D(); - -const DragTopic = require('./DragTopic').default; -const Shape = require('./util/Shape').default; -const INodeModel = require('./model/INodeModel').default; +import DragTopicConfig from './DragTopicConfig'; +import Shape from './util/Shape'; +import INodeModel from './model/INodeModel'; const DragPivot = new Class({ initialize() { - this._position = new core.Point(); - this._size = DragTopic.PIVOT_SIZE; + this._position = new web2d.Point(); + this._size = DragTopicConfig.PIVOT_SIZE; this._straightLine = this._buildStraightLine(); this._curvedLine = this._buildCurvedLine(); @@ -86,8 +81,8 @@ const DragPivot = new Class({ line.setFrom(pivotPoint.x, pivotPoint.y); // Update rect position - const cx = position.x - (parseInt(size.width) / 2); - const cy = position.y - (parseInt(size.height) / 2); + const cx = position.x - parseInt(size.width) / 2; + const cy = position.y - parseInt(size.height) / 2; pivotRect.setPosition(cx, cy); // Make line visible only when the position has been already changed. @@ -108,7 +103,11 @@ const DragPivot = new Class({ _buildRect() { const size = this._size; const rectAttributes = { - fillColor: '#CC0033', opacity: 0.4, width: size.width, height: size.height, strokeColor: '#FF9933', + fillColor: '#CC0033', + opacity: 0.4, + width: size.width, + height: size.height, + strokeColor: '#FF9933', }; const rect = new web2d.Rect(0, rectAttributes); rect.setVisibility(false); @@ -216,8 +215,8 @@ const DragPivot = new Class({ connectRect.setSize(width, height); const targetPosition = targetTopic.getPosition(); - const cx = Math.ceil(targetPosition.x - (width / 2)); - const cy = Math.ceil(targetPosition.y - (height / 2)); + const cx = Math.ceil(targetPosition.x - width / 2); + const cy = Math.ceil(targetPosition.y - height / 2); connectRect.setPosition(cx, cy); // Change elements position ... diff --git a/packages/mindplot/lib/components/DragTopic.js b/packages/mindplot/src/components/DragTopic.js similarity index 90% rename from packages/mindplot/lib/components/DragTopic.js rename to packages/mindplot/src/components/DragTopic.js index d876a1f0..f011df0a 100644 --- a/packages/mindplot/lib/components/DragTopic.js +++ b/packages/mindplot/src/components/DragTopic.js @@ -15,12 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import web2d from '@wisemapping/web2d'; -const core = Core(); - -const ActionDispatcher = require('./ActionDispatcher').default; -const DragPivot = require('./DragPivot').default; +import ActionDispatcher from './ActionDispatcher'; +import DragPivot from './DragPivot'; const DragTopic = new Class({ initialize(dragShape, draggedNode, layoutManger) { @@ -32,7 +30,7 @@ const DragTopic = new Class({ this._order = null; this._draggedNode = draggedNode; this._layoutManager = layoutManger; - this._position = new core.Point(); + this._position = new web2d.Point(); this._isInWorkspace = false; this._isFreeLayoutEnabled = false; }, @@ -47,7 +45,12 @@ const DragTopic = new Class({ if (this.isFreeLayoutOn() && this.isConnected()) { const { _layoutManager } = this; const par = this.getConnectedToTopic(); - position = _layoutManager.predict(par.getId(), this._draggedNode.getId(), position, true).position; + position = _layoutManager.predict( + par.getId(), + this._draggedNode.getId(), + position, + true, + ).position; } this._position.setValue(position.x, position.y); @@ -56,13 +59,17 @@ const DragTopic = new Class({ const draggedNode = this._draggedNode; const size = draggedNode.getSize(); const cx = position.x - (position.x > 0 ? 0 : size.width); - const cy = Math.ceil(position.y - (size.height / 2)); + const cy = Math.ceil(position.y - size.height / 2); this._elem2d.setPosition(cx, cy); // In case is not free, pivot must be draw ... if (this.isConnected() && !this.isFreeLayoutOn()) { const parent = this.getConnectedToTopic(); - const predict = this._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition()); + const predict = this._layoutManager.predict( + parent.getId(), + this._draggedNode.getId(), + this.getPosition(), + ); if (this._order != predict.order) { const dragPivot = this._getDragPivot(); const pivotPosition = predict.position; @@ -105,7 +112,11 @@ const DragTopic = new Class({ $assert(parent, 'Parent connection node can not be null.'); // Where it should be connected ? - const predict = designer._eventBussDispatcher._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition()); + const predict = designer._eventBussDispatcher._layoutManager.predict( + parent.getId(), + this._draggedNode.getId(), + this.getPosition(), + ); // Connect pivot ... const dragPivot = this._getDragPivot(); @@ -197,11 +208,8 @@ const DragTopic = new Class({ // Disable free layout ... return false; }, - }); -DragTopic.PIVOT_SIZE = { width: 50, height: 6 }; - DragTopic.init = function (workspace) { $assert(workspace, 'workspace can not be null'); const pivot = DragTopic.__getDragPivot(); diff --git a/packages/mindplot/src/components/DragTopicConfig.js b/packages/mindplot/src/components/DragTopicConfig.js new file mode 100644 index 00000000..ef339928 --- /dev/null +++ b/packages/mindplot/src/components/DragTopicConfig.js @@ -0,0 +1,5 @@ +export const PIVOT_SIZE = { width: 50, height: 6 }; + +export default { + PIVOT_SIZE, +}; diff --git a/packages/mindplot/lib/components/EditorOptions.js b/packages/mindplot/src/components/EditorOptions.js similarity index 100% rename from packages/mindplot/lib/components/EditorOptions.js rename to packages/mindplot/src/components/EditorOptions.js diff --git a/packages/mindplot/lib/components/EditorProperties.js b/packages/mindplot/src/components/EditorProperties.js similarity index 100% rename from packages/mindplot/lib/components/EditorProperties.js rename to packages/mindplot/src/components/EditorProperties.js diff --git a/packages/mindplot/lib/components/Events.js b/packages/mindplot/src/components/Events.js similarity index 100% rename from packages/mindplot/lib/components/Events.js rename to packages/mindplot/src/components/Events.js diff --git a/packages/mindplot/lib/components/Icon.js b/packages/mindplot/src/components/Icon.js similarity index 95% rename from packages/mindplot/lib/components/Icon.js rename to packages/mindplot/src/components/Icon.js index b983227a..db2e9164 100644 --- a/packages/mindplot/lib/components/Icon.js +++ b/packages/mindplot/src/components/Icon.js @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const web2D = require('@wismapping/web2d'); - -const web2d = web2D(); +import web2d from '@wisemapping/web2d'; const Icon = new Class({ initialize(url) { diff --git a/packages/mindplot/src/components/IconGroup.js b/packages/mindplot/src/components/IconGroup.js new file mode 100644 index 00000000..48b0477e --- /dev/null +++ b/packages/mindplot/src/components/IconGroup.js @@ -0,0 +1,346 @@ +/* + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * 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. + */ +import web2d from '@wisemapping/web2d'; + +import Icon from './Icon'; + +const IconGroup = new Class( + /** @lends IconGroup */ { + /** + * @constructs + * @param topicId + * @param iconSize + * @throws will throw an error if topicId is null or undefined + * @throws will throw an error if iconSize is null or undefined + */ + initialize(topicId, iconSize) { + $assert($defined(topicId), 'topicId can not be null'); + $assert($defined(iconSize), 'iconSize can not be null'); + + this._icons = []; + this._group = new web2d.Group({ + width: 0, + height: iconSize, + x: 0, + y: 0, + coordSizeWidth: 0, + coordSizeHeight: 100, + }); + this._removeTip = new IconGroup.RemoveTip(this._group, topicId); + this.seIconSize(iconSize, iconSize); + + this._registerListeners(); + }, + + /** */ + setPosition(x, y) { + this._group.setPosition(x, y); + }, + + /** */ + getPosition() { + return this._group.getPosition(); + }, + + /** */ + getNativeElement() { + return this._group; + }, + + /** */ + getSize() { + return this._group.getSize(); + }, + + /** */ + seIconSize(width, height) { + this._iconSize = { width, height }; + this._resize(this._icons.length); + }, + + /** + * @param icon the icon to be added to the icon group + * @param {Boolean} remove + * @throws will throw an error if icon is not defined + */ + addIcon(icon, remove) { + $defined(icon, 'icon is not defined'); + + icon.setGroup(this); + this._icons.push(icon); + + // Adjust group and position ... + this._resize(this._icons.length); + this._positionIcon(icon, this._icons.length - 1); + + const imageShape = icon.getImage(); + this._group.append(imageShape); + + // Register event for the group .. + if (remove) { + this._removeTip.decorate(this._topicId, icon); + } + }, + + _findIconFromModel(iconModel) { + let result = null; + _.each( + this._icons, + (icon) => { + const elModel = icon.getModel(); + if (elModel.getId() == iconModel.getId()) { + result = icon; + } + }, + this, + ); + + if (result == null) { + throw new Error(`Icon can no be found:${iconModel.getId()}, Icons:${this._icons}`); + } + + return result; + }, + + /** */ + removeIconByModel(featureModel) { + $assert(featureModel, 'featureModel can not be null'); + + const icon = this._findIconFromModel(featureModel); + this._removeIcon(icon); + }, + + _removeIcon(icon) { + $assert(icon, 'icon can not be null'); + + this._removeTip.close(0); + this._group.removeChild(icon.getImage()); + + this._icons.erase(icon); + this._resize(this._icons.length); + const me = this; + // Add all again ... + _.each(this._icons, (elem, i) => { + me._positionIcon(elem, i); + }); + }, + + /** */ + moveToFront() { + this._group.moveToFront(); + }, + + _registerListeners() { + this._group.addEvent('click', (event) => { + // Avoid node creation ... + event.stopPropagation(); + }); + + this._group.addEvent('dblclick', (event) => { + event.stopPropagation(); + }); + }, + + _resize(iconsLength) { + this._group.setSize(iconsLength * this._iconSize.width, this._iconSize.height); + + const iconSize = Icon.SIZE + IconGroup.ICON_PADDING * 2; + this._group.setCoordSize(iconsLength * iconSize, iconSize); + }, + + _positionIcon(icon, order) { + const iconSize = Icon.SIZE + IconGroup.ICON_PADDING * 2; + icon.getImage().setPosition( + iconSize * order + IconGroup.ICON_PADDING, + IconGroup.ICON_PADDING, + ); + }, + }, +); + +/** + * @constant + * @type {Number} + * @default + */ +IconGroup.ICON_PADDING = 5; + +IconGroup.RemoveTip = new Class( + /** @lends IconGroup.RemoveTip */ { + /** + * @classdesc inner class of IconGroup + * @constructs + * @param container + */ + initialize(container) { + $assert(container, 'group can not be null'); + this._fadeElem = container; + }, + + /** + * @param topicId + * @param icon + * @throws will throw an error if icon is null or undefined + */ + show(topicId, icon) { + $assert(icon, 'icon can not be null'); + + // Nothing to do ... + if (this._activeIcon != icon) { + // If there is an active icon, close it first ... + if (this._activeIcon) { + this.close(0); + } + + // Now, let move the position the icon... + const pos = icon.getPosition(); + + // Register events ... + const widget = this._buildWeb2d(); + widget.addEvent('click', () => { + icon.remove(); + }); + + const me = this; + + widget.addEvent('mouseover', () => { + me.show(topicId, icon); + }); + + widget.addEvent('mouseout', () => { + me.hide(); + }); + + widget.setPosition(pos.x + 80, pos.y - 50); + this._fadeElem.append(widget); + + // Setup current element ... + this._activeIcon = icon; + this._widget = widget; + } else { + clearTimeout(this._closeTimeoutId); + } + }, + + /** */ + hide() { + this.close(200); + }, + + /** + * @param delay + */ + close(delay) { + // This is not ok, trying to close the same dialog twice ? + if (this._closeTimeoutId) { + clearTimeout(this._closeTimeoutId); + } + + const me = this; + if (this._activeIcon) { + const widget = this._widget; + const close = function () { + me._activeIcon = null; + me._fadeElem.removeChild(widget); + me._widget = null; + me._closeTimeoutId = null; + }; + + if (!$defined(delay) || delay == 0) { + close(); + } else { + this._closeTimeoutId = close.delay(delay); + } + } + }, + + _buildWeb2d() { + const result = new web2d.Group({ + width: 10, + height: 10, + x: 0, + y: 0, + coordSizeWidth: 10, + coordSizeHeight: 10, + }); + + const outerRect = new web2d.Rect(0, { + x: 0, + y: 0, + width: 10, + height: 10, + stroke: '0', + fillColor: 'black', + }); + result.append(outerRect); + outerRect.setCursor('pointer'); + + const innerRect = new web2d.Rect(0, { + x: 1, + y: 1, + width: 8, + height: 8, + stroke: '1 solid white', + fillColor: 'gray', + }); + result.append(innerRect); + + const line = new web2d.Line({ stroke: '1 solid white' }); + line.setFrom(1, 1); + line.setTo(9, 9); + result.append(line); + + const line2 = new web2d.Line({ stroke: '1 solid white' }); + line2.setFrom(1, 9); + line2.setTo(9, 1); + result.append(line2); + + // Some events ... + result.addEvent('mouseover', () => { + innerRect.setFill('#CC0033'); + }); + result.addEvent('mouseout', () => { + innerRect.setFill('gray'); + }); + + result.setSize(50, 50); + return result; + }, + + /** + * @param topicId + * @param icon + */ + decorate(topicId, icon) { + const me = this; + + if (!icon.__remove) { + icon.addEvent('mouseover', () => { + me.show(topicId, icon); + }); + + icon.addEvent('mouseout', () => { + me.hide(); + }); + icon.__remove = true; + } + }, + }, +); + +export default IconGroup; diff --git a/packages/mindplot/lib/components/ImageIcon.js b/packages/mindplot/src/components/ImageIcon.js similarity index 98% rename from packages/mindplot/lib/components/ImageIcon.js rename to packages/mindplot/src/components/ImageIcon.js index 3d0f0f59..e3498476 100644 --- a/packages/mindplot/lib/components/ImageIcon.js +++ b/packages/mindplot/src/components/ImageIcon.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Icon = require('./Icon').default; -const ActionDispatcher = require('./ActionDispatcher').default; +import Icon from './Icon'; +import ActionDispatcher from './ActionDispatcher'; const ImageIcon = new Class({ Extends: Icon, diff --git a/packages/mindplot/lib/components/Keyboard.js b/packages/mindplot/src/components/Keyboard.js similarity index 100% rename from packages/mindplot/lib/components/Keyboard.js rename to packages/mindplot/src/components/Keyboard.js diff --git a/packages/mindplot/lib/components/LinkIcon.js b/packages/mindplot/src/components/LinkIcon.js similarity index 92% rename from packages/mindplot/lib/components/LinkIcon.js rename to packages/mindplot/src/components/LinkIcon.js index 491597a0..ad484edf 100644 --- a/packages/mindplot/lib/components/LinkIcon.js +++ b/packages/mindplot/src/components/LinkIcon.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Icon = require('./Icon').default; -const LinkIconTooltip = require('./widget/LinkIconTooltip').default; +import Icon from './Icon'; +import LinkIconTooltip from './widget/LinkIconTooltip'; const LinkIcon = new Class({ @@ -56,7 +56,7 @@ const LinkIcon = new Class({ }); } - $(this.getImage()._peer._native).mouseenter(() => { + $(this.getImage().peer._native).mouseenter(() => { me._tip.show(); }); }, diff --git a/packages/mindplot/lib/components/LocalStorageManager.js b/packages/mindplot/src/components/LocalStorageManager.js similarity index 96% rename from packages/mindplot/lib/components/LocalStorageManager.js rename to packages/mindplot/src/components/LocalStorageManager.js index ed2358d1..e4aafe8b 100644 --- a/packages/mindplot/lib/components/LocalStorageManager.js +++ b/packages/mindplot/src/components/LocalStorageManager.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const PersistenceManager = require('./PersistenceManager').default; +import PersistenceManager from './PersistenceManager'; const LocalStorageManager = new Class({ Extends: PersistenceManager, diff --git a/packages/mindplot/src/components/MainTopic.js b/packages/mindplot/src/components/MainTopic.js new file mode 100644 index 00000000..9f2da86c --- /dev/null +++ b/packages/mindplot/src/components/MainTopic.js @@ -0,0 +1,162 @@ +/* + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * 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. + */ +import web2d from '@wisemapping/web2d'; + +import Topic from './Topic'; +import { TopicShape } from './model/INodeModel'; +import Shape from './util/Shape'; + +const MainTopic = new Class( + /** @lends MainTopic */ { + Extends: Topic, + /** + * @extends mindplot.Topic + * @constructs + * @param model + * @param options + */ + initialize(model, options) { + this.parent(model, options); + }, + + INNER_RECT_ATTRIBUTES: { stroke: '0.5 solid #009900' }, + + _buildDragShape() { + const innerShape = this._buildShape(this.INNER_RECT_ATTRIBUTES, this.getShapeType()); + const size = this.getSize(); + innerShape.setSize(size.width, size.height); + innerShape.setPosition(0, 0); + innerShape.setOpacity(0.5); + innerShape.setCursor('default'); + innerShape.setVisibility(true); + + const brColor = this.getBorderColor(); + innerShape.setAttribute('strokeColor', brColor); + + const bgColor = this.getBackgroundColor(); + innerShape.setAttribute('fillColor', bgColor); + + // Create group ... + const groupAttributes = { + width: 100, + height: 100, + coordSizeWidth: 100, + coordSizeHeight: 100, + }; + const group = new web2d.Group(groupAttributes); + group.append(innerShape); + + // Add Text ... + if (this.getShapeType() !== TopicShape.IMAGE) { + const textShape = this._buildTextShape(true); + const text = this.getText(); + textShape.setText(text); + textShape.setOpacity(0.5); + group.append(textShape); + } + return group; + }, + + /** */ + updateTopicShape(targetTopic, workspace) { + // Change figure based on the connected topic ... + const model = this.getModel(); + let shapeType = model.getShapeType(); + if (!targetTopic.isCentralTopic()) { + if (!$defined(shapeType)) { + // Get the real shape type ... + shapeType = this.getShapeType(); + this._setShapeType(shapeType, false); + } + } + }, + + /** */ + disconnect(workspace) { + this.parent(workspace); + const size = this.getSize(); + + const model = this.getModel(); + let shapeType = model.getShapeType(); + if (!$defined(shapeType)) { + // Change figure ... + shapeType = this.getShapeType(); + this._setShapeType(TopicShape.ROUNDED_RECT, false); + } + const innerShape = this.getInnerShape(); + innerShape.setVisibility(true); + }, + + _updatePositionOnChangeSize(oldSize, newSize) { + const xOffset = Math.round((newSize.width - oldSize.width) / 2); + const pos = this.getPosition(); + if ($defined(pos)) { + if (pos.x > 0) { + pos.x += xOffset; + } else { + pos.x -= xOffset; + } + this.setPosition(pos); + } + }, + + /** */ + workoutIncomingConnectionPoint(sourcePosition) { + return Shape.workoutIncomingConnectionPoint(this, sourcePosition); + }, + + /** */ + workoutOutgoingConnectionPoint(targetPosition) { + $assert(targetPosition, 'targetPoint can not be null'); + const pos = this.getPosition(); + const isAtRight = Shape.isAtRight(targetPosition, pos); + const size = this.getSize(); + + let result; + if (this.getShapeType() === TopicShape.LINE) { + result = new web2d.Point(); + const groupPosition = this._elem2d.getPosition(); + const innerShareSize = this.getInnerShape().getSize(); + + if (innerShareSize) { + const magicCorrectionNumber = 0.3; + if (!isAtRight) { + result.x = groupPosition.x + innerShareSize.width - magicCorrectionNumber; + } else { + result.x = groupPosition.x + magicCorrectionNumber; + } + result.y = groupPosition.y + innerShareSize.height; + } else { + // Hack: When the size has not being defined. This is because the node has not being added. + // Try to do our best ... + if (!isAtRight) { + result.x = pos.x + size.width / 2; + } else { + result.x = pos.x - size.width / 2; + } + result.y = pos.y + size.height / 2; + } + } else { + result = Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); + } + return result; + }, + }, +); + +export default MainTopic; diff --git a/packages/mindplot/lib/components/Messages.js b/packages/mindplot/src/components/Messages.js similarity index 69% rename from packages/mindplot/lib/components/Messages.js rename to packages/mindplot/src/components/Messages.js index 49cf03e4..2d9c162f 100644 --- a/packages/mindplot/lib/components/Messages.js +++ b/packages/mindplot/src/components/Messages.js @@ -17,25 +17,24 @@ */ const Messages = new Class({ - Static: { - init(locale) { - locale = $defined(locale) ? locale : 'en'; - let bundle = Messages.BUNDLES[locale]; - if (bundle == null && locale.indexOf('_') != -1) { - // Try to locate without the specialization ... - locale = locale.substring(0, locale.indexOf('_')); - bundle = Messages.BUNDLES[locale]; - } - Messages.__bundle = bundle; - }, - }, + }); -global.$msg = function (key) { +Messages.init = (locale) => { + locale = $defined(locale) ? locale : 'en'; + let bundle = Messages.BUNDLES[locale]; + if (bundle == null && locale.indexOf('_') !== -1) { + // Try to locate without the specialization ... + locale = locale.substring(0, locale.indexOf('_')); + bundle = Messages.BUNDLES[locale]; + } + Messages.__bundle = bundle || {}; +}; + +global.$msg = function $msg(key) { if (!Messages.__bundle) { Messages.init('en'); } - const msg = Messages.__bundle[key]; return msg || key; }; diff --git a/packages/mindplot/lib/components/MultilineTextEditor.js b/packages/mindplot/src/components/MultilineTextEditor.js similarity index 98% rename from packages/mindplot/lib/components/MultilineTextEditor.js rename to packages/mindplot/src/components/MultilineTextEditor.js index c6a4fabc..080a597c 100644 --- a/packages/mindplot/lib/components/MultilineTextEditor.js +++ b/packages/mindplot/src/components/MultilineTextEditor.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Events = require('./Events').default; -const ActionDispatcher = require('./ActionDispatcher').default; +import Events from './Events'; +import ActionDispatcher from './ActionDispatcher'; const MultilineTextEditor = new Class({ Extends: Events, diff --git a/packages/mindplot/lib/components/NodeGraph.js b/packages/mindplot/src/components/NodeGraph.js similarity index 74% rename from packages/mindplot/lib/components/NodeGraph.js rename to packages/mindplot/src/components/NodeGraph.js index 8e047cc2..003b9d69 100644 --- a/packages/mindplot/lib/components/NodeGraph.js +++ b/packages/mindplot/src/components/NodeGraph.js @@ -15,9 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Topic = require('./Topic').default; -const DragTopic = require('./DragTopic').default; -const INodeModel = require('./model/INodeModel').default; +import TopicConfig from './TopicConfig'; +import DragTopic from './DragTopic'; const NodeGraph = new Class( /** @lends NodeGraph */ { @@ -72,7 +71,7 @@ const NodeGraph = new Class( /** @abstract */ setPosition(point, fireEvent) { - throw 'Unsupported operation'; + throw new Error('Unsupported operation'); }, /** */ @@ -110,8 +109,8 @@ const NodeGraph = new Class( /** @param {Object} size */ setSize(size) { - this._size.width = parseInt(size.width); - this._size.height = parseInt(size.height); + this._size.width = parseInt(size.width, 10); + this._size.height = parseInt(size.height, 10); }, /** @@ -138,14 +137,14 @@ const NodeGraph = new Class( /** */ setOnFocus(focus) { - if (this._onFocus != focus) { + if (this._onFocus !== focus) { this._onFocus = focus; const outerShape = this.getOuterShape(); if (focus) { - outerShape.setFill(Topic.OUTER_SHAPE_ATTRIBUTES_FOCUS.fillColor); + outerShape.setFill(TopicConfig.OUTER_SHAPE_ATTRIBUTES_FOCUS.fillColor); outerShape.setOpacity(1); } else { - outerShape.setFill(Topic.OUTER_SHAPE_ATTRIBUTES.fillColor); + outerShape.setFill(TopicConfig.OUTER_SHAPE_ATTRIBUTES.fillColor); outerShape.setOpacity(0); } this.setCursor('move'); @@ -187,36 +186,4 @@ const NodeGraph = new Class( }, ); -/** - * creates a new topic from the given node model - * @memberof mindplot.Nodegraph - * @param {mindplot.model.NodeModel} nodeModel - * @param {Object} options - * @throws will throw an error if nodeModel is null or undefined - * @throws will throw an error if the nodeModel's type is null or undefined - * @throws will throw an error if the node type cannot be recognized as either central or main - * topic type - * @return {mindplot.CentralTopic|mindplot.MainTopic} the new topic - */ -NodeGraph.create = function (nodeModel, options) { - const CentralTopic = require('./CentralTopic').default; - const MainTopic = require('./MainTopic').default; - - $assert(nodeModel, 'Model can not be null'); - - const type = nodeModel.getType(); - $assert(type, 'Node model type can not be null'); - - let result; - if (type == INodeModel.CENTRAL_TOPIC_TYPE) { - result = new CentralTopic(nodeModel, options); - } else if (type == INodeModel.MAIN_TOPIC_TYPE) { - result = new MainTopic(nodeModel, options); - } else { - $assert(false, `unsupported node type:${type}`); - } - - return result; -}; - export default NodeGraph; diff --git a/packages/mindplot/src/components/NodeGraphUtils.js b/packages/mindplot/src/components/NodeGraphUtils.js new file mode 100644 index 00000000..3b466eb3 --- /dev/null +++ b/packages/mindplot/src/components/NodeGraphUtils.js @@ -0,0 +1,36 @@ +import CentralTopic from './CentralTopic'; +import MainTopic from './MainTopic'; +import INodeModel from './model/INodeModel'; + +/** + * creates a new topic from the given node model + * @memberof mindplot.Nodegraph + * @param {mindplot.model.NodeModel} nodeModel + * @param {Object} options + * @throws will throw an error if nodeModel is null or undefined + * @throws will throw an error if the nodeModel's type is null or undefined + * @throws will throw an error if the node type cannot be recognized as either central or main + * topic type + * @return {mindplot.CentralTopic|mindplot.MainTopic} the new topic + */ +export const create = (nodeModel, options) => { + $assert(nodeModel, 'Model can not be null'); + + const type = nodeModel.getType(); + $assert(type, 'Node model type can not be null'); + + let result; + if (type === INodeModel.CENTRAL_TOPIC_TYPE) { + result = new CentralTopic(nodeModel, options); + } else if (type === INodeModel.MAIN_TOPIC_TYPE) { + result = new MainTopic(nodeModel, options); + } else { + $assert(false, `unsupported node type:${type}`); + } + + return result; +}; + +export default { + create, +}; diff --git a/packages/mindplot/lib/components/NoteIcon.js b/packages/mindplot/src/components/NoteIcon.js similarity index 85% rename from packages/mindplot/lib/components/NoteIcon.js rename to packages/mindplot/src/components/NoteIcon.js index a1a4f1da..2a42ea62 100644 --- a/packages/mindplot/lib/components/NoteIcon.js +++ b/packages/mindplot/src/components/NoteIcon.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Icon = require('./Icon').default; -const FloatingTip = require('./widget/FloatingTip').default; +import Icon from './Icon'; +import FloatingTip from './widget/FloatingTip'; const NoteIcon = new Class({ Extends: Icon, @@ -42,7 +42,7 @@ const NoteIcon = new Class({ event.stopPropagation(); }); } - this._tip = new FloatingTip($(me.getImage()._peer._native), { + this._tip = new FloatingTip($(me.getImage().peer._native), { title: $msg('NOTE'), container: 'body', // Content can also be a function of the target element! @@ -56,13 +56,13 @@ const NoteIcon = new Class({ }, _buildTooltipContent() { - if ($('body').find('#textPopoverNote').length == 1) { - var text = $('body').find('#textPopoverNote'); + if ($('body').find('#textPopoverNote').length === 1) { + const text = $('body').find('#textPopoverNote'); text.text(this._linksModel.getText()); } else { const result = $('
').css({ padding: '5px' }); - var text = $('
').text(this._linksModel.getText()) + const text = $('
').text(this._linksModel.getText()) .css({ 'white-space': 'pre-wrap', 'word-wrap': 'break-word', diff --git a/packages/mindplot/lib/components/Options.js b/packages/mindplot/src/components/Options.js similarity index 100% rename from packages/mindplot/lib/components/Options.js rename to packages/mindplot/src/components/Options.js diff --git a/packages/mindplot/lib/components/PersistenceManager.js b/packages/mindplot/src/components/PersistenceManager.js similarity index 84% rename from packages/mindplot/lib/components/PersistenceManager.js rename to packages/mindplot/src/components/PersistenceManager.js index b3e3ceba..59c63683 100644 --- a/packages/mindplot/lib/components/PersistenceManager.js +++ b/packages/mindplot/src/components/PersistenceManager.js @@ -15,22 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import Core from '@wisemapping/core-js'; +import XMLSerializerFactory from './persistence/XMLSerializerFactory'; const core = Core(); -const XMLSerializerFactory = require('./persistence/XMLSerializerFactory'); const PersistenceManager = new Class({ - Static: { - loadFromDom(mapId, mapDom) { - $assert(mapId, 'mapId can not be null'); - $assert(mapDom, 'mapDom can not be null'); - - const serializer = XMLSerializerFactory.getSerializerFromDocument(mapDom); - return serializer.loadFromDom(mapDom, mapId); - }, - }, - initialize() {}, save(mindmap, editorProperties, saveHistory, events, sync) { @@ -84,4 +74,12 @@ PersistenceManager.getInstance = function () { return PersistenceManager._instance; }; +PersistenceManager.loadFromDom = function loadFromDom(mapId, mapDom) { + $assert(mapId, 'mapId can not be null'); + $assert(mapDom, 'mapDom can not be null'); + + const serializer = XMLSerializerFactory.getSerializerFromDocument(mapDom); + return serializer.loadFromDom(mapDom, mapId); +}; + export default PersistenceManager; diff --git a/packages/mindplot/lib/components/Relationship.js b/packages/mindplot/src/components/Relationship.js similarity index 89% rename from packages/mindplot/lib/components/Relationship.js rename to packages/mindplot/src/components/Relationship.js index a587fe03..d0d233b7 100644 --- a/packages/mindplot/lib/components/Relationship.js +++ b/packages/mindplot/src/components/Relationship.js @@ -15,29 +15,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import web2d from '@wisemapping/web2d'; -const core = Core(); +import ConnectionLine from './ConnectionLine'; +import ControlPoint from './ControlPoint'; -const web2D = require('@wismapping/web2d'); +import INodeModel from './model/INodeModel'; -const web2d = web2D(); - -const ConnectionLine = require('./ConnectionLine').default; -const ControlPoint = require('./ControlPoint').default; - -const INodeModel = require('./model/INodeModel').default; - -const Shape = require('./util/Shape').default; +import Shape from './util/Shape'; const Relationship = new Class({ Extends: ConnectionLine, - Static: { - getStrokeColor() { - return '#9b74e6'; - }, - type: 'Relationship', - }, + initialize(sourceNode, targetNode, model) { $assert(sourceNode, 'sourceNode can not be null'); $assert(targetNode, 'targetNode can not be null'); @@ -98,29 +87,32 @@ const Relationship = new Class({ const targetTopic = this._targetTopic; let targetPosition = targetTopic.getPosition(); - if (targetTopic.getType() == INodeModel.CENTRAL_TOPIC_TYPE) { + if (targetTopic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { targetPosition = Shape.workoutIncomingConnectionPoint(targetTopic, sourcePosition); } - let sPos; let - tPos; + let sPos; + let tPos; this._line2d.setStroke(2); const ctrlPoints = this._line2d.getControlPoints(); if (!this._line2d.isDestControlPointCustom() && !this._line2d.isSrcControlPointCustom()) { - const defaultPoints = Shape.calculateDefaultControlPoints(sourcePosition, targetPosition); + const defaultPoints = Shape.calculateDefaultControlPoints( + sourcePosition, + targetPosition, + ); ctrlPoints[0].x = defaultPoints[0].x; ctrlPoints[0].y = defaultPoints[0].y; ctrlPoints[1].x = defaultPoints[1].x; ctrlPoints[1].y = defaultPoints[1].y; } - const spoint = new core.Point(); - spoint.x = parseInt(ctrlPoints[0].x) + parseInt(sourcePosition.x); - spoint.y = parseInt(ctrlPoints[0].y) + parseInt(sourcePosition.y); + const spoint = new web2d.Point(); + spoint.x = parseInt(ctrlPoints[0].x, 10) + parseInt(sourcePosition.x, 10); + spoint.y = parseInt(ctrlPoints[0].y, 10) + parseInt(sourcePosition.y, 10); - const tpoint = new core.Point(); - tpoint.x = parseInt(ctrlPoints[1].x) + parseInt(targetPosition.x); - tpoint.y = parseInt(ctrlPoints[1].y) + parseInt(targetPosition.y); + const tpoint = new web2d.Point(); + tpoint.x = parseInt(ctrlPoints[1].x, 10) + parseInt(targetPosition.x, 10); + tpoint.y = parseInt(ctrlPoints[1].y, 10) + parseInt(targetPosition.y, 10); sPos = Shape.calculateRelationShipPointCoordinates(sourceTopic, spoint); tPos = Shape.calculateRelationShipPointCoordinates(targetTopic, tpoint); @@ -155,7 +147,7 @@ const Relationship = new Class({ this._endArrow.moveToBack(); } - if (this._line2d.getType() == 'CurvedLine') { + if (this._line2d.getType() === 'CurvedLine') { const controlPoints = this._line2d.getControlPoints(); this._startArrow.setControlPoint(controlPoints[0]); if (this._endArrow) { @@ -211,7 +203,7 @@ const Relationship = new Class({ setOnFocus(focus) { // Change focus shape - if (this.isOnFocus() != focus) { + if (this.isOnFocus() !== focus) { if (focus) { this._refreshShape(); this._controlPointsController.setLine(this); @@ -240,7 +232,7 @@ const Relationship = new Class({ addEvent(type, listener) { // Translate to web 2d events ... - if (type == 'onfocus') { + if (type === 'onfocus') { type = 'mousedown'; } @@ -334,4 +326,10 @@ const Relationship = new Class({ }, }); +Relationship.getStrokeColor = function getStrokeColor() { + return '#9b74e6'; +}; + +Relationship.type = 'Relationship'; + export default Relationship; diff --git a/packages/mindplot/lib/components/RelationshipPivot.js b/packages/mindplot/src/components/RelationshipPivot.js similarity index 90% rename from packages/mindplot/lib/components/RelationshipPivot.js rename to packages/mindplot/src/components/RelationshipPivot.js index b597e93e..375b310f 100644 --- a/packages/mindplot/lib/components/RelationshipPivot.js +++ b/packages/mindplot/src/components/RelationshipPivot.js @@ -15,14 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import web2d from '@wisemapping/web2d'; -const core = Core(); -const web2D = require('@wismapping/web2d'); - -const web2d = web2D(); -const INodeModel = require('./model/INodeModel').default; -const Shape = require('./util/Shape').default; +import INodeModel from './model/INodeModel'; +import Shape from './util/Shape'; const RelationshipPivot = new Class({ initialize(workspace, designer) { @@ -134,14 +130,14 @@ const RelationshipPivot = new Class({ _calculateFromPosition(toPosition) { // Calculate origin position ... let sourcePosition = this._sourceTopic.getPosition(); - if (this._sourceTopic.getType() == INodeModel.CENTRAL_TOPIC_TYPE) { + if (this._sourceTopic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { sourcePosition = Shape.workoutIncomingConnectionPoint(this._sourceTopic, toPosition); } const controlPoint = Shape.calculateDefaultControlPoints(sourcePosition, toPosition); - const spoint = new core.Point(); - spoint.x = parseInt(controlPoint[0].x) + parseInt(sourcePosition.x); - spoint.y = parseInt(controlPoint[0].y) + parseInt(sourcePosition.y); + const spoint = new web2d.Point(); + spoint.x = parseInt(controlPoint[0].x, 10) + parseInt(sourcePosition.x, 10); + spoint.y = parseInt(controlPoint[0].y, 10) + parseInt(sourcePosition.y, 10); return Shape.calculateRelationShipPointCoordinates(this._sourceTopic, spoint); }, @@ -150,7 +146,7 @@ const RelationshipPivot = new Class({ const mindmap = this._designer.getMindmap(); // Avoid circular connections ... - if (targetTopic.getId() != sourceTopic.getId()) { + if (targetTopic.getId() !== sourceTopic.getId()) { const relModel = mindmap.createRelationship(targetTopic.getId(), sourceTopic.getId()); this._designer._actionDispatcher.addRelationship(relModel); } diff --git a/packages/mindplot/lib/components/RestPersistenceManager.js b/packages/mindplot/src/components/RestPersistenceManager.js similarity index 98% rename from packages/mindplot/lib/components/RestPersistenceManager.js rename to packages/mindplot/src/components/RestPersistenceManager.js index d5795c83..e3a8cfda 100644 --- a/packages/mindplot/lib/components/RestPersistenceManager.js +++ b/packages/mindplot/src/components/RestPersistenceManager.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const PersistenceManager = require('./PersistenceManager').default; +import PersistenceManager from './PersistenceManager'; const RESTPersistenceManager = new Class({ Extends: PersistenceManager, @@ -81,7 +81,7 @@ const RESTPersistenceManager = new Class({ let userMsg = { severity: 'SEVERE', message: $msg('SAVE_COULD_NOT_BE_COMPLETED') }; const contentType = xhr.getResponseHeader('Content-Type'); - if (contentType != null && contentType.indexOf('application/json') != -1) { + if (contentType != null && contentType.indexOf('application/json') !== -1) { let serverMsg = null; try { serverMsg = $.parseJSON(responseText); diff --git a/packages/mindplot/lib/components/ScreenManager.js b/packages/mindplot/src/components/ScreenManager.js similarity index 86% rename from packages/mindplot/lib/components/ScreenManager.js rename to packages/mindplot/src/components/ScreenManager.js index 83c47b2f..36d8e227 100644 --- a/packages/mindplot/lib/components/ScreenManager.js +++ b/packages/mindplot/src/components/ScreenManager.js @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); - -const core = Core(); +import web2d from '@wisemapping/web2d'; const ScreenManager = new Class({ initialize(divElement) { @@ -43,12 +41,12 @@ const ScreenManager = new Class({ }, addEvent(event, listener) { - if (event == 'click') this._clickEvents.push(listener); + if (event === 'click') this._clickEvents.push(listener); else this._divContainer.bind(event, listener); }, removeEvent(event, listener) { - if (event == 'click') { + if (event === 'click') { this._clickEvents.remove(listener); } else { this._divContainer.unbind(event, listener); @@ -56,7 +54,7 @@ const ScreenManager = new Class({ }, fireEvent(type, event) { - if (type == 'click') { + if (type === 'click') { _.each(this._clickEvents, (listener) => { listener(type, event); }); @@ -96,10 +94,13 @@ const ScreenManager = new Class({ const groupSize = group.getSize(); const coordSize = group.getCoordSize(); - const scale = { x: coordSize.width / parseInt(groupSize.width), y: coordSize.height / parseInt(groupSize.height) }; + const scale = { + x: coordSize.width / parseInt(groupSize.width, 10), + y: coordSize.height / parseInt(groupSize.height, 10), + }; - let x = (elementPosition.x - coordOrigin.x - (parseInt(imageSize.width) / 2)) / scale.x; - let y = (elementPosition.y - coordOrigin.y - (parseInt(imageSize.height) / 2)) / scale.y; + let x = (elementPosition.x - coordOrigin.x - parseInt(imageSize.width, 10) / 2) / scale.x; + let y = (elementPosition.y - coordOrigin.y - parseInt(imageSize.height, 10) / 2) / scale.y; // Retrieve iconGroup Position const groupPosition = iconGroup.getPosition(); @@ -109,7 +110,7 @@ const ScreenManager = new Class({ // Retrieve topic Position const topic = iconGroup.getTopic(); const topicPosition = this._getElementPosition(topic); - topicPosition.x -= (parseInt(topic.getSize().width) / 2); + topicPosition.x -= parseInt(topic.getSize().width, 10) / 2; // Remove decimal part.. return { x: x + topicPosition.x, y: y + topicPosition.y }; @@ -134,7 +135,7 @@ const ScreenManager = new Class({ y += this._padding.y; // Remove decimal part.. - return new core.Point(x, y); + return new web2d.Point(x, y); }, getContainer() { diff --git a/packages/mindplot/lib/components/ShrinkConnector.js b/packages/mindplot/src/components/ShrinkConnector.js similarity index 86% rename from packages/mindplot/lib/components/ShrinkConnector.js rename to packages/mindplot/src/components/ShrinkConnector.js index ea02d655..b93f5ef4 100644 --- a/packages/mindplot/lib/components/ShrinkConnector.js +++ b/packages/mindplot/src/components/ShrinkConnector.js @@ -15,20 +15,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const web2D = require('@wismapping/web2d'); +import web2d from '@wisemapping/web2d'; -const web2d = web2D(); - -const Topic = require('./Topic').default; -const ActionDispatcher = require('./ActionDispatcher').default; +import TopicConfig from './TopicConfig'; +import ActionDispatcher from './ActionDispatcher'; const ShirinkConnector = new Class({ initialize(topic) { - const ellipse = new web2D.Elipse(Topic.prototype.INNER_RECT_ATTRIBUTES); + const ellipse = new web2d.Elipse(TopicConfig.INNER_RECT_ATTRIBUTES); this._ellipse = ellipse; ellipse.setFill('rgb(62,118,179)'); - ellipse.setSize(Topic.CONNECTOR_WIDTH, Topic.CONNECTOR_WIDTH); + ellipse.setSize(TopicConfig.CONNECTOR_WIDTH, TopicConfig.CONNECTOR_WIDTH); ellipse.addEvent('click', (event) => { const model = topic.getModel(); const collapse = !model.areChildrenShrunken(); @@ -50,11 +48,11 @@ const ShirinkConnector = new Class({ event.stopPropagation(); }); - ellipse.addEvent('mouseover', (event) => { + ellipse.addEvent('mouseover', () => { ellipse.setFill('rgb(153, 0, 255)'); }); const me = this; - ellipse.addEvent('mouseout', (event) => { + ellipse.addEvent('mouseout', () => { const color = topic.getBackgroundColor(); me.setFill(color); }); diff --git a/packages/mindplot/lib/components/StandaloneActionDispatcher.js b/packages/mindplot/src/components/StandaloneActionDispatcher.js similarity index 89% rename from packages/mindplot/lib/components/StandaloneActionDispatcher.js rename to packages/mindplot/src/components/StandaloneActionDispatcher.js index 0442fa3d..53cefe27 100644 --- a/packages/mindplot/lib/components/StandaloneActionDispatcher.js +++ b/packages/mindplot/src/components/StandaloneActionDispatcher.js @@ -15,18 +15,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ActionDispatcher = require('./ActionDispatcher').default; -const DesignerActionRunner = require('./DesignerActionRunner').default; -const AddTopicCommand = require('./commands/AddTopicCommand').default; -const AddRelationshipCommand = require('./commands/AddRelationshipCommand').default; -const AddFeatureToTopicCommand = require('./commands/AddFeatureToTopicCommand').default; -const DeleteCommand = require('./commands/DeleteCommand').default; -const RemoveFeatureFromTopicCommand = require('./commands/RemoveFeatureFromTopicCommand').default; -const DragTopicCommand = require('./commands/DragTopicCommand').default; -const GenericFunctionCommand = require('./commands/GenericFunctionCommand').default; -const MoveControlPointCommand = require('./commands/MoveControlPointCommand').default; -const ChangeFeatureToTopicCommand = require('./commands/ChangeFeatureToTopicCommand').default; -const NodeModel = require('./model/NodeModel').default; +import ActionDispatcher from './ActionDispatcher'; +import DesignerActionRunner from './DesignerActionRunner'; +import AddTopicCommand from './commands/AddTopicCommand'; +import AddRelationshipCommand from './commands/AddRelationshipCommand'; +import AddFeatureToTopicCommand from './commands/AddFeatureToTopicCommand'; +import DeleteCommand from './commands/DeleteCommand'; +import RemoveFeatureFromTopicCommand from './commands/RemoveFeatureFromTopicCommand'; +import DragTopicCommand from './commands/DragTopicCommand'; +import GenericFunctionCommand from './commands/GenericFunctionCommand'; +import MoveControlPointCommand from './commands/MoveControlPointCommand'; +import ChangeFeatureToTopicCommand from './commands/ChangeFeatureToTopicCommand'; +import NodeModel from './model/NodeModel'; const StandaloneActionDispatcher = new Class( /** @lends StandaloneActionDispatcher */ { @@ -93,7 +93,7 @@ const StandaloneActionDispatcher = new Class( changeFontStyleToTopic(topicsIds) { const commandFunc = function (topic) { const result = topic.getFontStyle(); - const style = result == 'italic' ? 'normal' : 'italic'; + const style = result === 'italic' ? 'normal' : 'italic'; topic.setFontStyle(style, true); return result; }; @@ -219,7 +219,7 @@ const StandaloneActionDispatcher = new Class( const commandFunc = function (topic) { const result = topic.getFontWeight(); - const weight = result == 'bold' ? 'normal' : 'bold'; + const weight = result === 'bold' ? 'normal' : 'bold'; topic.setFontWeight(weight, true); topic._adjustShapes(); @@ -289,10 +289,10 @@ const CommandContext = new Class( const designerTopics = this._designer.getModel().getTopics(); const result = designerTopics.filter((topic) => topicsIds.contains(topic.getId())); - if (result.length != topicsIds.length) { + if (result.length !== topicsIds.length) { const ids = designerTopics.map((topic) => topic.getId()); $assert( - result.length == topicsIds.length, + result.length === topicsIds.length, `Could not find topic. Result:${ result }, Filter Criteria:${ diff --git a/packages/mindplot/lib/components/TextEditor.js b/packages/mindplot/src/components/TextEditor.js similarity index 92% rename from packages/mindplot/lib/components/TextEditor.js rename to packages/mindplot/src/components/TextEditor.js index 29864daf..2b54422d 100644 --- a/packages/mindplot/lib/components/TextEditor.js +++ b/packages/mindplot/src/components/TextEditor.js @@ -12,11 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const web2D = require('@wismapping/web2d'); +import web2d from '@wisemapping/web2d'; -const web2d = web2D(); - -const ActionDispatcher = require('./ActionDispatcher').default; +import ActionDispatcher from './ActionDispatcher'; // FIXME: Not used! const TextEditor = new Class({ @@ -42,12 +40,11 @@ const TextEditor = new Class({ }); inputContainer.inject(result); - const inputText = new Element('input', - { - type: 'text', - tabindex: '-1', - value: '', - }); + const inputText = new Element('input', { + type: 'text', + tabindex: '-1', + value: '', + }); inputText.setStyles({ border: 'none', background: 'transparent', @@ -82,8 +79,9 @@ const TextEditor = new Class({ default: spanElem.innerHTML = inputElem.value; var size = inputElem.value.length + 1; + inputElem.size = size; - if (spanElem.offsetWidth > (parseInt(divElem.style.width) - 100)) { + if (spanElem.offsetWidth > parseInt(divElem.style.width, 10) - 100) { divElem.style.width = `${spanElem.offsetWidth + 100}px`; } break; @@ -104,11 +102,11 @@ const TextEditor = new Class({ }, isVisible() { - return $defined(this._containerElem) && this._containerElem.getStyle('display') == 'block'; + return $defined(this._containerElem) && this._containerElem.getStyle('display') === 'block'; }, _updateModel() { - if (this._topic.getText() != this._getText()) { + if (this._topic.getText() !== this._getText()) { const text = this._getText(); const topicId = this._topic.getId(); @@ -196,7 +194,9 @@ const TextEditor = new Class({ _setText(text) { const inputField = this._getTextareaElem(); inputField.size = text.length + 1; - this._containerElem.style.width = `${inputField.size * parseInt(inputField.style.fontSize) + 100}px`; + this._containerElem.style.width = `${ + inputField.size * parseInt(inputField.style.fontSize, 10) + 100 + }px`; const spanField = this._getSpanElem(); spanField.innerHTML = text; inputField.value = text; @@ -216,7 +216,7 @@ const TextEditor = new Class({ _setEditorSize(width, height) { const textShape = this._topic.getTextShape(); - const scale = web2d.utils.TransformUtil.workoutScale(textShape._peer); + const scale = web2d.utils.TransformUtil.workoutScale(textShape.peer); this._size = { width: width * scale.width, height: height * scale.height }; this._containerElem.style.width = `${this._size.width * 2}px`; this._containerElem.style.height = `${this._size.height}px`; @@ -224,8 +224,8 @@ const TextEditor = new Class({ _positionCursor(inputElem, selectText) { // Select text if it's required ... - if (inputElem.createTextRange) // ie - { + if (inputElem.createTextRange) { + // ie const range = inputElem.createTextRange(); const pos = inputElem.value.length; if (!selectText) { diff --git a/packages/mindplot/lib/components/TextEditorFactory.js b/packages/mindplot/src/components/TextEditorFactory.js similarity index 95% rename from packages/mindplot/lib/components/TextEditorFactory.js rename to packages/mindplot/src/components/TextEditorFactory.js index a2016404..ff9ed8fa 100644 --- a/packages/mindplot/lib/components/TextEditorFactory.js +++ b/packages/mindplot/src/components/TextEditorFactory.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const TextEditor = require('./TextEditor').default; +import TextEditor from './TextEditor'; const TextEditorFactory = {}; diff --git a/packages/mindplot/lib/components/Topic.js b/packages/mindplot/src/components/Topic.js similarity index 94% rename from packages/mindplot/lib/components/Topic.js rename to packages/mindplot/src/components/Topic.js index 5bd9922e..252d38d0 100644 --- a/packages/mindplot/lib/components/Topic.js +++ b/packages/mindplot/src/components/Topic.js @@ -15,23 +15,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const web2D = require('@wismapping/web2d'); +import web2d from '@wisemapping/web2d'; -const web2d = web2D(); -const NodeGraph = require('./NodeGraph').default; -const { TopicShape } = require('./model/INodeModel'); -const TopicStyle = require('./TopicStyle').default; -const TopicFeature = require('./TopicFeature').default; -const ConnectionLine = require('./ConnectionLine').default; -const IconGroup = require('./IconGroup').default; -const FadeEffect = require('./util/FadeEffect').default; -const EventBus = require('./layout/EventBus').default; -const ShirinkConnector = require('./ShrinkConnector').default; -const NoteEditor = require('./widget/NoteEditor').default; -const ActionDispatcher = require('./ActionDispatcher').default; -const LinkEditor = require('./widget/LinkEditor').default; -const TopicEventDispatcher = require('./TopicEventDispatcher').default; -const INodeModel = require('./model/INodeModel').default; +import NodeGraph from './NodeGraph'; +import TopicConfig from './TopicConfig'; +import TopicStyle from './TopicStyle'; +import TopicFeature from './TopicFeature'; +import ConnectionLine from './ConnectionLine'; +import IconGroup from './IconGroup'; +import FadeEffect from './util/FadeEffect'; +import EventBus from './layout/EventBus'; +import ShirinkConnector from './ShrinkConnector'; +import NoteEditor from './widget/NoteEditor'; +import ActionDispatcher from './ActionDispatcher'; +import LinkEditor from './widget/LinkEditor'; +import TopicEventDispatcher, { TopicEvent } from './TopicEventDispatcher'; +import INodeModel, { TopicShape } from './model/INodeModel'; const Topic = new Class( /** @lends Topic */ { @@ -151,7 +150,7 @@ const Topic = new Class( if (!$defined(this._innerShape)) { // Create inner box. this._innerShape = this._buildShape( - Topic.INNER_RECT_ATTRIBUTES, + TopicConfig.INNER_RECT_ATTRIBUTES, this.getShapeType(), ); @@ -178,9 +177,9 @@ const Topic = new Class( $assert(shapeType, 'shapeType can not be null'); let result; - if (shapeType == TopicShape.RECTANGLE) { + if (shapeType === TopicShape.RECTANGLE) { result = new web2d.Rect(0, attributes); - } else if (shapeType == TopicShape.IMAGE) { + } else if (shapeType === TopicShape.IMAGE) { const model = this.getModel(); const url = model.getImageUrl(); const size = model.getImageSize(); @@ -194,11 +193,11 @@ const Topic = new Class( }; result.setPosition = function () {}; - } else if (shapeType == TopicShape.ELLIPSE) { + } else if (shapeType === TopicShape.ELLIPSE) { result = new web2d.Rect(0.9, attributes); - } else if (shapeType == TopicShape.ROUNDED_RECT) { + } else if (shapeType === TopicShape.ROUNDED_RECT) { result = new web2d.Rect(0.3, attributes); - } else if (shapeType == TopicShape.LINE) { + } else if (shapeType === TopicShape.LINE) { result = new web2d.Line({ strokeColor: '#495879', strokeWidth: 1 }); result.setSize = function (width, height) { this.size = { width, height }; @@ -241,7 +240,10 @@ const Topic = new Class( /** @return outer shape */ getOuterShape() { if (!$defined(this._outerShape)) { - const rect = this._buildShape(Topic.OUTER_SHAPE_ATTRIBUTES, TopicShape.ROUNDED_RECT); + const rect = this._buildShape( + TopicConfig.OUTER_SHAPE_ATTRIBUTES, + TopicShape.ROUNDED_RECT, + ); rect.setPosition(-2, -3); rect.setOpacity(0); this._outerShape = rect; @@ -293,7 +295,7 @@ const Topic = new Class( const icon = TopicFeature.createIcon(this, featureModel, this.isReadOnly()); result.addIcon( icon, - featureModel.getType() == TopicFeature.Icon.id && !this.isReadOnly(), + featureModel.getType() === TopicFeature.Icon.id && !this.isReadOnly(), ); } @@ -316,7 +318,7 @@ const Topic = new Class( const result = TopicFeature.createIcon(this, featureModel, this.isReadOnly()); iconGroup.addIcon( result, - featureModel.getType() == TopicFeature.Icon.id && !this.isReadOnly(), + featureModel.getType() === TopicFeature.Icon.id && !this.isReadOnly(), ); this._adjustShapes(); @@ -506,7 +508,7 @@ const Topic = new Class( /** */ setText(text) { // Avoid empty nodes ... - if (!text || $.trim(text).length == 0) { + if (!text || $.trim(text).length === 0) { text = null; } @@ -606,7 +608,7 @@ const Topic = new Class( // Update figure size ... const model = this.getModel(); - if (model.getFeatures().length != 0) { + if (model.getFeatures().length !== 0) { this.getOrBuildIconGroup(); } @@ -1334,34 +1336,4 @@ const Topic = new Class( }, ); -/** - * @constant - * @type {Number} - * @default - */ -Topic.CONNECTOR_WIDTH = 6; -/** - * @constant - * @type {Object} - * @default - */ -Topic.OUTER_SHAPE_ATTRIBUTES = { - fillColor: 'rgb(252,235,192)', - stroke: '1 dot rgb(241,163,39)', - x: 0, - y: 0, -}; -/** - * @constant - * @type {Object} - * @default - */ -Topic.OUTER_SHAPE_ATTRIBUTES_FOCUS = { fillColor: 'rgb(244,184,45)', x: 0, y: 0 }; -/** - * @constant - * @type {Object} - * @default - * */ -Topic.INNER_RECT_ATTRIBUTES = { stroke: '2 solid' }; - export default Topic; diff --git a/packages/mindplot/src/components/TopicConfig.js b/packages/mindplot/src/components/TopicConfig.js new file mode 100644 index 00000000..731511d2 --- /dev/null +++ b/packages/mindplot/src/components/TopicConfig.js @@ -0,0 +1,36 @@ +/** + * @constant + * @type {Number} + * @default + */ +export const CONNECTOR_WIDTH = 6; +/** + * @constant + * @type {Object} + * @default + */ +export const OUTER_SHAPE_ATTRIBUTES = { + fillColor: 'rgb(252,235,192)', + stroke: '1 dot rgb(241,163,39)', + x: 0, + y: 0, +}; +/** + * @constant + * @type {Object} + * @default + */ +export const OUTER_SHAPE_ATTRIBUTES_FOCUS = { fillColor: 'rgb(244,184,45)', x: 0, y: 0 }; +/** + * @constant + * @type {Object} + * @default + * */ +export const INNER_RECT_ATTRIBUTES = { stroke: '2 solid' }; + +export default { + CONNECTOR_WIDTH, + OUTER_SHAPE_ATTRIBUTES, + OUTER_SHAPE_ATTRIBUTES_FOCUS, + INNER_RECT_ATTRIBUTES, +}; diff --git a/packages/mindplot/lib/components/TopicEventDispatcher.js b/packages/mindplot/src/components/TopicEventDispatcher.js similarity index 78% rename from packages/mindplot/lib/components/TopicEventDispatcher.js rename to packages/mindplot/src/components/TopicEventDispatcher.js index e82bccf5..a31273b1 100644 --- a/packages/mindplot/lib/components/TopicEventDispatcher.js +++ b/packages/mindplot/src/components/TopicEventDispatcher.js @@ -15,23 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Events = require('./Events').default; -const MultilineTextEditor = require('./MultilineTextEditor').default; -const { TopicShape } = require('./model/INodeModel'); +import Events from './Events'; +import MultilineTextEditor from './MultilineTextEditor'; +import { TopicShape } from './model/INodeModel'; + +const TopicEvent = { + EDIT: 'editnode', + CLICK: 'clicknode', +}; const TopicEventDispatcher = new Class({ Extends: Events, - Static: { - _instance: null, - - configure(readOnly) { - this._instance = new TopicEventDispatcher(readOnly); - }, - - getInstance() { - return this._instance; - }, - }, initialize(readOnly) { this._readOnly = readOnly; @@ -61,9 +55,9 @@ const TopicEventDispatcher = new Class({ // Open the new editor ... const model = topic.getModel(); if ( - model.getShapeType() != TopicShape.IMAGE + model.getShapeType() !== TopicShape.IMAGE && !this._readOnly - && eventType == TopicEvent.EDIT + && eventType === TopicEvent.EDIT ) { this._multilineEditor.show(topic, options ? options.text : null); this._activeEditor = this._multilineEditor; @@ -77,10 +71,15 @@ const TopicEventDispatcher = new Class({ }, }); -const TopicEvent = { - EDIT: 'editnode', - CLICK: 'clicknode', +TopicEventDispatcher._instance = null; + +TopicEventDispatcher.configure = function configure(readOnly) { + this._instance = new TopicEventDispatcher(readOnly); +}; + +TopicEventDispatcher.getInstance = function getInstance() { + return this._instance; }; export { TopicEvent }; -export default TopicEvent; +export default TopicEventDispatcher; diff --git a/packages/mindplot/lib/components/TopicFeature.js b/packages/mindplot/src/components/TopicFeature.js similarity index 87% rename from packages/mindplot/lib/components/TopicFeature.js rename to packages/mindplot/src/components/TopicFeature.js index 1312349c..758173a1 100644 --- a/packages/mindplot/lib/components/TopicFeature.js +++ b/packages/mindplot/src/components/TopicFeature.js @@ -17,12 +17,12 @@ */ /** */ -const IconModel = require('./model/IconModel').default; -const ImageIcon = require('./ImageIcon').default; -const LinkModel = require('./model/LinkModel').default; -const LinkIcon = require('./LinkIcon').default; -const NoteModel = require('./model/NoteModel').default; -const NoteIcon = require('./NoteIcon').default; +import IconModel from './model/IconModel'; +import ImageIcon from './ImageIcon'; +import LinkModel from './model/LinkModel'; +import LinkIcon from './LinkIcon'; +import NoteModel from './model/NoteModel'; +import NoteIcon from './NoteIcon'; const TopicFeature = { /** the icon object */ @@ -51,7 +51,7 @@ const TopicFeature = { * @return {Boolean} returns true if the given id is contained in the metadata array */ isSupported(id) { - return TopicFeature._featuresMetadataById.some((elem) => elem.id == id); + return TopicFeature._featuresMetadataById.some((elem) => elem.id === id); }, /** @@ -66,7 +66,7 @@ const TopicFeature = { $assert(type, 'type can not be null'); $assert(attributes, 'attributes can not be null'); - const { model } = TopicFeature._featuresMetadataById.filter((elem) => elem.id == type)[0]; + const { model } = TopicFeature._featuresMetadataById.filter((elem) => elem.id === type)[0]; return new model(attributes); }, @@ -82,7 +82,7 @@ const TopicFeature = { $assert(topic, 'topic can not be null'); $assert(model, 'model can not be null'); - const { icon } = TopicFeature._featuresMetadataById.filter((elem) => elem.id == model.getType())[0]; + const { icon } = TopicFeature._featuresMetadataById.filter((elem) => elem.id === model.getType())[0]; return new icon(topic, model, readOnly); }, }; diff --git a/packages/mindplot/lib/components/TopicStyle.js b/packages/mindplot/src/components/TopicStyle.js similarity index 61% rename from packages/mindplot/lib/components/TopicStyle.js rename to packages/mindplot/src/components/TopicStyle.js index 9e34da5c..7db56086 100644 --- a/packages/mindplot/lib/components/TopicStyle.js +++ b/packages/mindplot/src/components/TopicStyle.js @@ -15,57 +15,55 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const { TopicShape } = require('./model/INodeModel'); +import { TopicShape } from './model/INodeModel'; -const TopicStyle = new Class({ - Static: { - _getStyles(topic) { - $assert(topic, 'topic can not be null'); +const TopicStyle = new Class({}); - let result; - if (topic.isCentralTopic()) { - result = TopicStyle.STYLES.CENTRAL_TOPIC; +TopicStyle._getStyles = function _getStyles(topic) { + $assert(topic, 'topic can not be null'); + + let result; + if (topic.isCentralTopic()) { + result = TopicStyle.STYLES.CENTRAL_TOPIC; + } else { + const targetTopic = topic.getOutgoingConnectedTopic(); + if ($defined(targetTopic)) { + if (targetTopic.isCentralTopic()) { + result = TopicStyle.STYLES.MAIN_TOPIC; } else { - const targetTopic = topic.getOutgoingConnectedTopic(); - if ($defined(targetTopic)) { - if (targetTopic.isCentralTopic()) { - result = TopicStyle.STYLES.MAIN_TOPIC; - } else { - result = TopicStyle.STYLES.SUB_TOPIC; - } - } else { - result = TopicStyle.STYLES.ISOLATED_TOPIC; - } + result = TopicStyle.STYLES.SUB_TOPIC; } - return result; - }, + } else { + result = TopicStyle.STYLES.ISOLATED_TOPIC; + } + } + return result; +}; - defaultText(topic) { - const { msgKey } = this._getStyles(topic); - return $msg(msgKey); - }, +TopicStyle.defaultText = function defaultText(topic) { + const { msgKey } = this._getStyles(topic); + return $msg(msgKey); +}; - defaultFontStyle(topic) { - return this._getStyles(topic).fontStyle; - }, +TopicStyle.defaultFontStyle = function defaultFontStyle(topic) { + return this._getStyles(topic).fontStyle; +}; - defaultBackgroundColor(topic) { - return this._getStyles(topic).backgroundColor; - }, +TopicStyle.defaultBackgroundColor = function defaultBackgroundColor(topic) { + return this._getStyles(topic).backgroundColor; +}; - defaultBorderColor(topic) { - return this._getStyles(topic).borderColor; - }, +TopicStyle.defaultBorderColor = function defaultBorderColor(topic) { + return this._getStyles(topic).borderColor; +}; - getInnerPadding(topic) { - return this._getStyles(topic).innerPadding; - }, +TopicStyle.getInnerPadding = function getInnerPadding(topic) { + return this._getStyles(topic).innerPadding; +}; - defaultShapeType(topic) { - return this._getStyles(topic).shapeType; - }, - }, -}); +TopicStyle.defaultShapeType = function defaultShapeType(topic) { + return this._getStyles(topic).shapeType; +}; TopicStyle.STYLES = { CENTRAL_TOPIC: { diff --git a/packages/mindplot/lib/components/Workspace.js b/packages/mindplot/src/components/Workspace.js similarity index 97% rename from packages/mindplot/lib/components/Workspace.js rename to packages/mindplot/src/components/Workspace.js index a975525f..80c3be05 100644 --- a/packages/mindplot/lib/components/Workspace.js +++ b/packages/mindplot/src/components/Workspace.js @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const web2D = require('@wismapping/web2d'); - -const web2d = web2D(); +import web2d from '@wisemapping/web2d'; const Workspace = new Class({ initialize(screenManager, zoom) { @@ -29,8 +27,8 @@ const Workspace = new Class({ this._screenManager = screenManager; const divContainer = screenManager.getContainer(); - this._screenWidth = parseInt(divContainer.css('width')); - this._screenHeight = parseInt(divContainer.css('height')); + this._screenWidth = parseInt(divContainer.css('width'), 10); + this._screenHeight = parseInt(divContainer.css('height'), 10); // Initialize web2d workspace. const workspace = this._createWorkspace(); diff --git a/packages/mindplot/src/components/commands/AddFeatureToTopicCommand.js b/packages/mindplot/src/components/commands/AddFeatureToTopicCommand.js new file mode 100644 index 00000000..b013ffe9 --- /dev/null +++ b/packages/mindplot/src/components/commands/AddFeatureToTopicCommand.js @@ -0,0 +1,70 @@ +/* + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * 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. + */ +import Command from '../Command'; + +const AddFeatureToTopicCommand = new Class( + /** @lends AddFeatureToTopicCommand */ { + Extends: Command, + /* + * @classdesc This command class handles do/undo of adding features to topics, e.g. an + * icon or a note. For a reference of existing features, refer to {@link mindplot.TopicFeature} + * @constructs + * @param {String} topicId the id of the topic + * @param {String} featureType the id of the feature type to add, e.g. "icon" + * @param {Object} attributes the attribute(s) of the respective feature model + * @extends mindplot.Command + * @see mindplot.model.FeatureModel and subclasses + */ + initialize(topicId, featureType, attributes) { + $assert($defined(topicId), 'topicId can not be null'); + $assert(featureType, 'featureType can not be null'); + $assert(attributes, 'attributes can not be null'); + + this.parent(); + this._topicId = topicId; + this._featureType = featureType; + this._attributes = attributes; + this._featureModel = null; + }, + + /** + * Overrides abstract parent method + */ + execute(commandContext) { + const topic = commandContext.findTopics(this._topicId)[0]; + + // Feature must be created only one time. + if (!this._featureModel) { + const model = topic.getModel(); + this._featureModel = model.createFeature(this._featureType, this._attributes); + } + topic.addFeature(this._featureModel); + }, + + /** + * Overrides abstract parent method + * @see {@link mindplot.Command.undoExecute} + */ + undoExecute(commandContext) { + const topic = commandContext.findTopics(this._topicId)[0]; + topic.removeFeature(this._featureModel); + }, + }, +); + +export default AddFeatureToTopicCommand; diff --git a/packages/mindplot/lib/components/commands/AddRelationshipCommand.js b/packages/mindplot/src/components/commands/AddRelationshipCommand.js similarity index 97% rename from packages/mindplot/lib/components/commands/AddRelationshipCommand.js rename to packages/mindplot/src/components/commands/AddRelationshipCommand.js index 88180472..cbad2d3e 100644 --- a/packages/mindplot/lib/components/commands/AddRelationshipCommand.js +++ b/packages/mindplot/src/components/commands/AddRelationshipCommand.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Command = require('../Command').default; +import Command from '../Command'; const AddRelationshipCommand = new Class(/** @lends AddRelationshipCommand */{ Extends: Command, diff --git a/packages/mindplot/lib/components/commands/AddTopicCommand.js b/packages/mindplot/src/components/commands/AddTopicCommand.js similarity index 84% rename from packages/mindplot/lib/components/commands/AddTopicCommand.js rename to packages/mindplot/src/components/commands/AddTopicCommand.js index 76fde1f5..471d60aa 100644 --- a/packages/mindplot/lib/components/commands/AddTopicCommand.js +++ b/packages/mindplot/src/components/commands/AddTopicCommand.js @@ -15,20 +15,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Command = require('../Command').default; +import Command from '../Command'; const AddTopicCommand = new Class( /** @lends AddTopicCommand */ { Extends: Command, /** - * @classdesc This command class handles do/undo of adding one or multiple topics to - * the mindmap. - * @constructs - * @param {Array} models one or multiple models - * @param {Array} parentTopicsId ids of the parent topics to add the children to, or null - * when attaching a dragged node or a node/branch from clipboard - * @extends mindplot.Command - */ + * @classdesc This command class handles do/undo of adding one or multiple topics to + * the mindmap. + * @constructs + * @param {Array} models one or multiple models + * @param {Array} parentTopicsId ids of the parent topics to add the children to, or null + * when attaching a dragged node or a node/branch from clipboard + * @extends mindplot.Command + */ initialize(models, parentTopicsId) { $assert(models, 'models can not be null'); $assert( diff --git a/packages/mindplot/lib/components/commands/ChangeFeatureToTopicCommand.js b/packages/mindplot/src/components/commands/ChangeFeatureToTopicCommand.js similarity index 97% rename from packages/mindplot/lib/components/commands/ChangeFeatureToTopicCommand.js rename to packages/mindplot/src/components/commands/ChangeFeatureToTopicCommand.js index a5dc5625..3babdd1a 100644 --- a/packages/mindplot/lib/components/commands/ChangeFeatureToTopicCommand.js +++ b/packages/mindplot/src/components/commands/ChangeFeatureToTopicCommand.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Command = require('../Command').default; +import Command from '../Command'; const ChangeFeatureToTopicCommand = new Class(/** @lends ChangeFeatureToTopicCommand */{ Extends: Command, diff --git a/packages/mindplot/lib/components/commands/DeleteCommand.js b/packages/mindplot/src/components/commands/DeleteCommand.js similarity index 99% rename from packages/mindplot/lib/components/commands/DeleteCommand.js rename to packages/mindplot/src/components/commands/DeleteCommand.js index 00d54c4b..39ab3c10 100644 --- a/packages/mindplot/lib/components/commands/DeleteCommand.js +++ b/packages/mindplot/src/components/commands/DeleteCommand.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Command = require('../Command').default; +import Command from '../Command'; const DeleteCommand = new Class(/** @lends mindplot.commands.DeleteCommand */{ Extends: Command, diff --git a/packages/mindplot/lib/components/commands/DragTopicCommand.js b/packages/mindplot/src/components/commands/DragTopicCommand.js similarity index 94% rename from packages/mindplot/lib/components/commands/DragTopicCommand.js rename to packages/mindplot/src/components/commands/DragTopicCommand.js index b0c5135f..1536109b 100644 --- a/packages/mindplot/lib/components/commands/DragTopicCommand.js +++ b/packages/mindplot/src/components/commands/DragTopicCommand.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Command = require('../Command').default; +import Command from '../Command'; const DragTopicCommand = new Class(/** @lends DragTopicCommand */{ Extends: Command, @@ -54,7 +54,7 @@ const DragTopicCommand = new Class(/** @lends DragTopicCommand */{ const origPosition = topic.getPosition(); // Disconnect topic .. - if ($defined(origParentTopic) && origParentTopic != this._parentId) { + if ($defined(origParentTopic) && origParentTopic !== this._parentId) { commandContext.disconnect(topic); } @@ -68,7 +68,7 @@ const DragTopicCommand = new Class(/** @lends DragTopicCommand */{ } // Finally, connect topic ... - if (origParentTopic != this._parentId) { + if (origParentTopic !== this._parentId) { if ($defined(this._parentId)) { const parentTopic = commandContext.findTopics(this._parentId)[0]; commandContext.connect(topic, parentTopic); diff --git a/packages/mindplot/lib/components/commands/GenericFunctionCommand.js b/packages/mindplot/src/components/commands/GenericFunctionCommand.js similarity index 97% rename from packages/mindplot/lib/components/commands/GenericFunctionCommand.js rename to packages/mindplot/src/components/commands/GenericFunctionCommand.js index 731f27de..193c7254 100644 --- a/packages/mindplot/lib/components/commands/GenericFunctionCommand.js +++ b/packages/mindplot/src/components/commands/GenericFunctionCommand.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Command = require('../Command').default; +import Command from '../Command'; const GenericFunctionCommand = new Class(/** @lends GenericFunctionCommand */{ Extends: Command, @@ -87,7 +87,7 @@ const GenericFunctionCommand = new Class(/** @lends GenericFunctionCommand */{ this.applied = false; this._oldValues = []; } else { - throw 'undo can not be applied.'; + throw new Error('undo can not be applied.'); } }, }); diff --git a/packages/mindplot/lib/components/commands/MoveControlPointCommand.js b/packages/mindplot/src/components/commands/MoveControlPointCommand.js similarity index 96% rename from packages/mindplot/lib/components/commands/MoveControlPointCommand.js rename to packages/mindplot/src/components/commands/MoveControlPointCommand.js index fdfa9e74..c6fc7232 100644 --- a/packages/mindplot/lib/components/commands/MoveControlPointCommand.js +++ b/packages/mindplot/src/components/commands/MoveControlPointCommand.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Command = require('../Command').default; +import Command from '../Command'; const MoveControlPointCommand = new Class( /** @lends MoveControlPointCommand */ { @@ -50,6 +50,8 @@ const MoveControlPointCommand = new Class( this._wasCustom = this._line.getLine().isDestControlPointCustom(); this._endPoint = this._line.getLine().getTo().clone(); break; + default: + break; } this._point = point; }, @@ -57,7 +59,7 @@ const MoveControlPointCommand = new Class( /** * Overrides abstract parent method */ - execute(commandContext) { + execute() { const model = this._line.getModel(); switch (this._point) { case 0: @@ -73,6 +75,8 @@ const MoveControlPointCommand = new Class( this._line.setIsDestControlPointCustom(true); this._line.setDestControlPoint(this._controlPoint.clone()); break; + default: + break; } if (this._line.isOnFocus()) { this._line._refreshShape(); @@ -85,7 +89,7 @@ const MoveControlPointCommand = new Class( * Overrides abstract parent method * @see {@link mindplot.Command.undoExecute} */ - undoExecute(commandContext) { + undoExecute() { const line = this._line; const model = line.getModel(); switch (this._point) { @@ -105,6 +109,8 @@ const MoveControlPointCommand = new Class( line.setIsDestControlPointCustom(this._wasCustom); } break; + default: + break; } this._line.getLine().updateLine(this._point); if (this._line.isOnFocus()) { diff --git a/packages/mindplot/lib/components/commands/RemoveFeatureFromTopicCommand.js b/packages/mindplot/src/components/commands/RemoveFeatureFromTopicCommand.js similarity index 97% rename from packages/mindplot/lib/components/commands/RemoveFeatureFromTopicCommand.js rename to packages/mindplot/src/components/commands/RemoveFeatureFromTopicCommand.js index cfd725d1..7e0aa2f7 100644 --- a/packages/mindplot/lib/components/commands/RemoveFeatureFromTopicCommand.js +++ b/packages/mindplot/src/components/commands/RemoveFeatureFromTopicCommand.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Command = require('../Command').default; +import Command from '../Command'; const RemoveFeatureFromTopicCommand = new Class(/** @lends RemoveFeatureFromTopicCommand */{ Extends: Command, diff --git a/packages/mindplot/src/components/commands/index.js b/packages/mindplot/src/components/commands/index.js new file mode 100644 index 00000000..20c113d5 --- /dev/null +++ b/packages/mindplot/src/components/commands/index.js @@ -0,0 +1,21 @@ +import addFeatureToTopicCommand from './AddFeatureToTopicCommand'; +import addRelationshipCommand from './AddRelationshipCommand'; +import addTopicCommand from './AddTopicCommand'; +import changeFeatureToTopicCommand from './ChangeFeatureToTopicCommand'; +import deleteCommand from './DeleteCommand'; +import dragTopicCommand from './DragTopicCommand'; +import genericFunctionCommand from './GenericFunctionCommand'; +import moveControlPointCommand from './MoveControlPointCommand'; +import removeFeatureFromTopicCommand from './RemoveFeatureFromTopicCommand'; + +export default { + AddFeatureToTopicCommand: addFeatureToTopicCommand, + AddRelationshipCommand: addRelationshipCommand, + AddTopicCommand: addTopicCommand, + ChangeFeatureToTopicCommand: changeFeatureToTopicCommand, + DeleteCommand: deleteCommand, + DragTopicCommand: dragTopicCommand, + GenericFunctionCommand: genericFunctionCommand, + MoveControlPointCommand: moveControlPointCommand, + RemoveFeatureFromTopicCommand: removeFeatureFromTopicCommand, +}; diff --git a/packages/mindplot/lib/components/footer.js b/packages/mindplot/src/components/footer.js similarity index 100% rename from packages/mindplot/lib/components/footer.js rename to packages/mindplot/src/components/footer.js diff --git a/packages/mindplot/lib/components/header.js b/packages/mindplot/src/components/header.js similarity index 100% rename from packages/mindplot/lib/components/header.js rename to packages/mindplot/src/components/header.js diff --git a/packages/mindplot/src/components/index.js b/packages/mindplot/src/components/index.js new file mode 100644 index 00000000..b6b417ed --- /dev/null +++ b/packages/mindplot/src/components/index.js @@ -0,0 +1,95 @@ +import actionDispatcher from './ActionDispatcher'; +import actionIcon from './ActionIcon'; +import centralTopic from './CentralTopic'; +import command from './Command'; +import connectionLine from './ConnectionLine'; +import controlPoint from './ControlPoint'; +import designer from './Designer'; +import designerActionRunner from './DesignerActionRunner'; +import designerKeyboard from './DesignerKeyboard'; +import designerModal from './DesignerModel'; +import designerUndoManager from './DesignerUndoManager'; +import dragConnector from './DragConnector'; +import dragManager from './DragManager'; +import dragPivot from './DragPivot'; +import dragTopic from './DragTopic'; +import editorOptions from './EditorOptions'; +import editorProperties from './EditorProperties'; +import events from './Events'; +import footer from './footer'; +import header from './header'; +import icon from './Icon'; +import iconGroup from './IconGroup'; +import imageIcon from './ImageIcon'; +import keyboard from './Keyboard'; +import linkIcon from './LinkIcon'; +import localSorageManager from './LocalStorageManager'; +import mainTopic from './MainTopic'; +import messages from './Messages'; +import multilineTextEditor from './MultilineTextEditor'; +import nodeGraph from './NodeGraph'; +import noteIcon from './NoteIcon'; +import options from './Options'; +import persistenceManager from './PersistenceManager'; +import relationship from './Relationship'; +import relationshipPivot from './RelationshipPivot'; +import resetPersistenceManager from './RestPersistenceManager'; +import screenManager from './ScreenManager'; +import shrinkConnector from './ShrinkConnector'; +import standaloneActionDispatcher from './StandaloneActionDispatcher'; +import textEditor from './TextEditor'; +import textEditorFactory from './TextEditorFactory'; +import topic from './Topic'; +import topicEventDispatcher from './TopicEventDispatcher'; +import topicFeature from './TopicFeature'; +import topicStyle from './TopicStyle'; +import workspace from './Workspace'; + +export default { + ActionDispatcher: actionDispatcher, + ActionIcon: actionIcon, + CentralTopic: centralTopic, + Command: command, + ConnectionLine: connectionLine, + ControlPoint: controlPoint, + Designer: designer, + DesignerActionRunner: designerActionRunner, + DesignerKeyboard: designerKeyboard, + DesignerModel: designerModal, + DesignerUndoManager: designerUndoManager, + DragConnector: dragConnector, + DragManager: dragManager, + DragPivot: dragPivot, + DragTopic: dragTopic, + EditorOptions: editorOptions, + EditorProperties: editorProperties, + Events: events, + Footer: footer, + Header: header, + Icon: icon, + IconGroup: iconGroup, + ImageIcon: imageIcon, + Keyboard: keyboard, + LinkIcon: linkIcon, + LocalStorageManager: localSorageManager, + MainTopic: mainTopic, + Messages: messages, + MultilineTextEditor: multilineTextEditor, + NodeGraph: nodeGraph, + NoteIcon: noteIcon, + Options: options, + PersistenceManager: persistenceManager, + Relationship: relationship, + RelationshipPivot: relationshipPivot, + RestPersistenceManager: resetPersistenceManager, + ScreenManager: screenManager, + ShrinkConnector: shrinkConnector, + StandaloneActionDispatcher: standaloneActionDispatcher, + TextEditor: textEditor, + TextEditorFactory: textEditorFactory, + Topic: topic, + TopicEventDispatcher: topicEventDispatcher, + TopicFeature: topicFeature, + TopicStyle: topicStyle, + Workspace: workspace, +}; diff --git a/packages/mindplot/lib/components/layout/AbstractBasicSorter.js b/packages/mindplot/src/components/layout/AbstractBasicSorter.js similarity index 94% rename from packages/mindplot/lib/components/layout/AbstractBasicSorter.js rename to packages/mindplot/src/components/layout/AbstractBasicSorter.js index 0c95b6a7..505363c7 100644 --- a/packages/mindplot/lib/components/layout/AbstractBasicSorter.js +++ b/packages/mindplot/src/components/layout/AbstractBasicSorter.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ChildrenSorterStrategy = require('./ChildrenSorterStrategy').default; +import ChildrenSorterStrategy from './ChildrenSorterStrategy'; /** * @class @@ -45,7 +45,7 @@ const AbstractBasicSorter = new Class( let result; const children = treeSet.getChildren(node); - if (children.length == 0 || node.areChildrenShrunken()) { + if (children.length === 0 || node.areChildrenShrunken()) { result = height; } else { let childrenHeight = 0; diff --git a/packages/mindplot/lib/components/layout/BalancedSorter.js b/packages/mindplot/src/components/layout/BalancedSorter.js similarity index 99% rename from packages/mindplot/lib/components/layout/BalancedSorter.js rename to packages/mindplot/src/components/layout/BalancedSorter.js index 0f67c9e5..867915bd 100644 --- a/packages/mindplot/lib/components/layout/BalancedSorter.js +++ b/packages/mindplot/src/components/layout/BalancedSorter.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const AbstractBasicSorter = require('./AbstractBasicSorter').default; +import AbstractBasicSorter from './AbstractBasicSorter'; const BalancedSorter = new Class( /** @lends BalancedSorter */ { diff --git a/packages/mindplot/lib/components/layout/ChangeEvent.js b/packages/mindplot/src/components/layout/ChangeEvent.js similarity index 100% rename from packages/mindplot/lib/components/layout/ChangeEvent.js rename to packages/mindplot/src/components/layout/ChangeEvent.js diff --git a/packages/mindplot/lib/components/layout/ChildrenSorterStrategy.js b/packages/mindplot/src/components/layout/ChildrenSorterStrategy.js similarity index 100% rename from packages/mindplot/lib/components/layout/ChildrenSorterStrategy.js rename to packages/mindplot/src/components/layout/ChildrenSorterStrategy.js diff --git a/packages/mindplot/lib/components/layout/EventBus.js b/packages/mindplot/src/components/layout/EventBus.js similarity index 96% rename from packages/mindplot/lib/components/layout/EventBus.js rename to packages/mindplot/src/components/layout/EventBus.js index d4e473d1..17a890b9 100644 --- a/packages/mindplot/lib/components/layout/EventBus.js +++ b/packages/mindplot/src/components/layout/EventBus.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Events = require('../Events').default; +import Events from '../Events'; const EventBus = new Class(/** @lends EventBus */{ Implements: Events, diff --git a/packages/mindplot/lib/components/layout/EventBusDispatcher.js b/packages/mindplot/src/components/layout/EventBusDispatcher.js similarity index 98% rename from packages/mindplot/lib/components/layout/EventBusDispatcher.js rename to packages/mindplot/src/components/layout/EventBusDispatcher.js index b2e9cb15..e634e1d3 100644 --- a/packages/mindplot/lib/components/layout/EventBusDispatcher.js +++ b/packages/mindplot/src/components/layout/EventBusDispatcher.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const EventBus = require('./EventBus').default; +import EventBus from './EventBus'; const EventBusDispatcher = new Class(/** @lends EventBusDispatcher */{ /** diff --git a/packages/mindplot/lib/components/layout/GridSorter.js b/packages/mindplot/src/components/layout/GridSorter.js similarity index 97% rename from packages/mindplot/lib/components/layout/GridSorter.js rename to packages/mindplot/src/components/layout/GridSorter.js index c3f6bd86..6c9e962e 100644 --- a/packages/mindplot/lib/components/layout/GridSorter.js +++ b/packages/mindplot/src/components/layout/GridSorter.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const AbstractBasicSorter = require('./AbstractBasicSorter').default; +import AbstractBasicSorter from './AbstractBasicSorter'; /** * @class diff --git a/packages/mindplot/lib/components/layout/LayoutManager.js b/packages/mindplot/src/components/layout/LayoutManager.js similarity index 95% rename from packages/mindplot/lib/components/layout/LayoutManager.js rename to packages/mindplot/src/components/layout/LayoutManager.js index b925fa61..240d7566 100644 --- a/packages/mindplot/lib/components/layout/LayoutManager.js +++ b/packages/mindplot/src/components/layout/LayoutManager.js @@ -15,10 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Events = require('../Events').default; -const RootedTreeSet = require('./RootedTreeSet').default; -const OriginalLayout = require('./OriginalLayout').default; -const ChangeEvent = require('./ChangeEvent').default; +import Events from '../Events'; +import RootedTreeSet from './RootedTreeSet'; +import OriginalLayout from './OriginalLayout'; +import ChangeEvent from './ChangeEvent'; const LayoutManager = new Class( /** @lends LayoutManager */ { @@ -202,10 +202,15 @@ const LayoutManager = new Class( * @return canvas */ plot(containerId, size) { + // this method is only used from tests that include Raphael + if (!global.Raphael) { + console.warn('Raphael.js not found, exiting plot()'); + return null; + } $assert(containerId, 'containerId cannot be null'); size = size || { width: 200, height: 200 }; const squaresize = 10; - const canvas = Raphael(containerId, size.width, size.height); + const canvas = global.Raphael(containerId, size.width, size.height); canvas.drawGrid( 0, 0, diff --git a/packages/mindplot/lib/components/layout/Node.js b/packages/mindplot/src/components/layout/Node.js similarity index 100% rename from packages/mindplot/lib/components/layout/Node.js rename to packages/mindplot/src/components/layout/Node.js diff --git a/packages/mindplot/lib/components/layout/OriginalLayout.js b/packages/mindplot/src/components/layout/OriginalLayout.js similarity index 98% rename from packages/mindplot/lib/components/layout/OriginalLayout.js rename to packages/mindplot/src/components/layout/OriginalLayout.js index 7a338189..ee62054d 100644 --- a/packages/mindplot/lib/components/layout/OriginalLayout.js +++ b/packages/mindplot/src/components/layout/OriginalLayout.js @@ -16,9 +16,9 @@ * limitations under the License. */ -const Node = require('./Node').default; -const SymmetricSorter = require('./SymmetricSorter').default; -const BalancedSorter = require('./BalancedSorter').default; +import Node from './Node'; +import SymmetricSorter from './SymmetricSorter'; +import BalancedSorter from './BalancedSorter'; const OriginalLayout = new Class( /** @lends OriginalLayout */ { diff --git a/packages/mindplot/lib/components/layout/RootedTreeSet.js b/packages/mindplot/src/components/layout/RootedTreeSet.js similarity index 100% rename from packages/mindplot/lib/components/layout/RootedTreeSet.js rename to packages/mindplot/src/components/layout/RootedTreeSet.js diff --git a/packages/mindplot/lib/components/layout/SymmetricSorter.js b/packages/mindplot/src/components/layout/SymmetricSorter.js similarity index 99% rename from packages/mindplot/lib/components/layout/SymmetricSorter.js rename to packages/mindplot/src/components/layout/SymmetricSorter.js index 9bb46ba3..590b2c2d 100644 --- a/packages/mindplot/lib/components/layout/SymmetricSorter.js +++ b/packages/mindplot/src/components/layout/SymmetricSorter.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const AbstractBasicSorter = require('./AbstractBasicSorter').default; +import AbstractBasicSorter from './AbstractBasicSorter'; const SymmetricSorter = new Class( /** @lends SymmetricSorter */ { diff --git a/packages/mindplot/src/components/layout/index.js b/packages/mindplot/src/components/layout/index.js new file mode 100644 index 00000000..3071d189 --- /dev/null +++ b/packages/mindplot/src/components/layout/index.js @@ -0,0 +1,27 @@ +import abstractBasicSorter from './AbstractBasicSorter'; +import balancedSorter from './BalancedSorter'; +import changeEvent from './ChangeEvent'; +import childrenSorterStrategy from './ChildrenSorterStrategy'; +import eventBus from './EventBus'; +import eventBusDispatcher from './EventBusDispatcher'; +import gridSorter from './GridSorter'; +import layoutManager from './LayoutManager'; +import node from './Node'; +import originalLayout from './OriginalLayout'; +import rootedTreeSet from './RootedTreeSet'; +import symmetricSorter from './SymmetricSorter'; + +export default { + AbstractBasicSorter: abstractBasicSorter, + BalancedSorter: balancedSorter, + ChangeEvent: changeEvent, + ChildrenSorterStrategy: childrenSorterStrategy, + EventBus: eventBus, + EventBusDispatcher: eventBusDispatcher, + GridSorter: gridSorter, + LayoutManager: layoutManager, + Node: node, + OriginalLayout: originalLayout, + RootedTreeSet: rootedTreeSet, + SymmetricSorter: symmetricSorter, +}; diff --git a/packages/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.Request.js b/packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.Request.js similarity index 95% rename from packages/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.Request.js rename to packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.Request.js index 01920850..2f92cf29 100644 --- a/packages/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.Request.js +++ b/packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.Request.js @@ -1,4 +1,4 @@ -const BootstrapDialog = require('./BootstrapDialog').default; +import BootstrapDialog from './BootstrapDialog'; BootstrapDialog.Request = new Class({ diff --git a/packages/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.js b/packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.js similarity index 98% rename from packages/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.js rename to packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.js index 5aa9a24a..9098942c 100644 --- a/packages/mindplot/lib/components/libraries/bootstrap/BootstrapDialog.js +++ b/packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.js @@ -1,4 +1,4 @@ -const Options = require('../../Options').default; +import Options from '../../Options'; const BootstrapDialog = new Class({ Implements: Options, diff --git a/packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-colorpicker.css b/packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-colorpicker.css similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-colorpicker.css rename to packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-colorpicker.css diff --git a/packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-colorpicker.min.css b/packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-colorpicker.min.css similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-colorpicker.min.css rename to packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-colorpicker.min.css diff --git a/packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-theme.css b/packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-theme.css similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-theme.css rename to packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-theme.css diff --git a/packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-theme.css.map b/packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-theme.css.map similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-theme.css.map rename to packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-theme.css.map diff --git a/packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-theme.min.css b/packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-theme.min.css similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap-theme.min.css rename to packages/mindplot/src/components/libraries/bootstrap/css/bootstrap-theme.min.css diff --git a/packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap.css b/packages/mindplot/src/components/libraries/bootstrap/css/bootstrap.css similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap.css rename to packages/mindplot/src/components/libraries/bootstrap/css/bootstrap.css diff --git a/packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap.css.map b/packages/mindplot/src/components/libraries/bootstrap/css/bootstrap.css.map similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap.css.map rename to packages/mindplot/src/components/libraries/bootstrap/css/bootstrap.css.map diff --git a/packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap.min.css b/packages/mindplot/src/components/libraries/bootstrap/css/bootstrap.min.css similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/css/bootstrap.min.css rename to packages/mindplot/src/components/libraries/bootstrap/css/bootstrap.min.css diff --git a/packages/mindplot/lib/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.eot b/packages/mindplot/src/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.eot similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.eot rename to packages/mindplot/src/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.eot diff --git a/packages/mindplot/lib/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.svg b/packages/mindplot/src/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.svg similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.svg rename to packages/mindplot/src/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.svg diff --git a/packages/mindplot/lib/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.ttf b/packages/mindplot/src/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.ttf similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.ttf rename to packages/mindplot/src/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.ttf diff --git a/packages/mindplot/lib/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.woff b/packages/mindplot/src/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.woff similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.woff rename to packages/mindplot/src/components/libraries/bootstrap/fonts/glyphicons-halflings-regular.woff diff --git a/packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/alpha-horizontal.png b/packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/alpha-horizontal.png similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/alpha-horizontal.png rename to packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/alpha-horizontal.png diff --git a/packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/alpha.png b/packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/alpha.png similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/alpha.png rename to packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/alpha.png diff --git a/packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/hue-horizontal.png b/packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/hue-horizontal.png similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/hue-horizontal.png rename to packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/hue-horizontal.png diff --git a/packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/hue.png b/packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/hue.png similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/hue.png rename to packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/hue.png diff --git a/packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/saturation.png b/packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/saturation.png similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/img/bootstrap-colorpicker/saturation.png rename to packages/mindplot/src/components/libraries/bootstrap/img/bootstrap-colorpicker/saturation.png diff --git a/packages/mindplot/lib/components/libraries/bootstrap/img/glyphicons-halflings-blue.png b/packages/mindplot/src/components/libraries/bootstrap/img/glyphicons-halflings-blue.png similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/img/glyphicons-halflings-blue.png rename to packages/mindplot/src/components/libraries/bootstrap/img/glyphicons-halflings-blue.png diff --git a/packages/mindplot/lib/components/libraries/bootstrap/js/bootstrap-colorpicker.js b/packages/mindplot/src/components/libraries/bootstrap/js/bootstrap-colorpicker.js similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/js/bootstrap-colorpicker.js rename to packages/mindplot/src/components/libraries/bootstrap/js/bootstrap-colorpicker.js diff --git a/packages/mindplot/lib/components/libraries/bootstrap/js/bootstrap-colorpicker.min.js b/packages/mindplot/src/components/libraries/bootstrap/js/bootstrap-colorpicker.min.js similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/js/bootstrap-colorpicker.min.js rename to packages/mindplot/src/components/libraries/bootstrap/js/bootstrap-colorpicker.min.js diff --git a/packages/mindplot/lib/components/libraries/bootstrap/js/bootstrap.js b/packages/mindplot/src/components/libraries/bootstrap/js/bootstrap.js similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/js/bootstrap.js rename to packages/mindplot/src/components/libraries/bootstrap/js/bootstrap.js diff --git a/packages/mindplot/lib/components/libraries/bootstrap/js/bootstrap.min.js b/packages/mindplot/src/components/libraries/bootstrap/js/bootstrap.min.js similarity index 100% rename from packages/mindplot/lib/components/libraries/bootstrap/js/bootstrap.min.js rename to packages/mindplot/src/components/libraries/bootstrap/js/bootstrap.min.js diff --git a/packages/mindplot/lib/components/libraries/hotkeys/jquery.hotkeys.js b/packages/mindplot/src/components/libraries/hotkeys/jquery.hotkeys.js similarity index 100% rename from packages/mindplot/lib/components/libraries/hotkeys/jquery.hotkeys.js rename to packages/mindplot/src/components/libraries/hotkeys/jquery.hotkeys.js diff --git a/packages/mindplot/lib/components/libraries/jquery/jquery-2.1.0.js b/packages/mindplot/src/components/libraries/jquery/jquery-2.1.0.js similarity index 100% rename from packages/mindplot/lib/components/libraries/jquery/jquery-2.1.0.js rename to packages/mindplot/src/components/libraries/jquery/jquery-2.1.0.js diff --git a/packages/mindplot/lib/components/libraries/jquery/jquery-2.1.0.min.js b/packages/mindplot/src/components/libraries/jquery/jquery-2.1.0.min.js similarity index 100% rename from packages/mindplot/lib/components/libraries/jquery/jquery-2.1.0.min.js rename to packages/mindplot/src/components/libraries/jquery/jquery-2.1.0.min.js diff --git a/packages/mindplot/lib/components/libraries/jquery/jquery.mousewheel.min.js b/packages/mindplot/src/components/libraries/jquery/jquery.mousewheel.min.js similarity index 100% rename from packages/mindplot/lib/components/libraries/jquery/jquery.mousewheel.min.js rename to packages/mindplot/src/components/libraries/jquery/jquery.mousewheel.min.js diff --git a/packages/mindplot/lib/components/libraries/less/less-1.4.2.min.js b/packages/mindplot/src/components/libraries/less/less-1.4.2.min.js similarity index 100% rename from packages/mindplot/lib/components/libraries/less/less-1.4.2.min.js rename to packages/mindplot/src/components/libraries/less/less-1.4.2.min.js diff --git a/packages/mindplot/lib/components/libraries/less/less-1.6.2.min.js b/packages/mindplot/src/components/libraries/less/less-1.6.2.min.js similarity index 99% rename from packages/mindplot/lib/components/libraries/less/less-1.6.2.min.js rename to packages/mindplot/src/components/libraries/less/less-1.6.2.min.js index 57b3a78b..7c11e839 100644 --- a/packages/mindplot/lib/components/libraries/less/less-1.6.2.min.js +++ b/packages/mindplot/src/components/libraries/less/less-1.6.2.min.js @@ -291,13 +291,13 @@ }; } for (g = 0; g < q.length; g++) { if (l = q[g].group, l === t || l === m) { - try { d = q[g].mixin, d instanceof a.mixin.Definition || (d = new a.mixin.Definition('', [], d.rules, null, !1), d.originalRuleset = c[g].originalRuleset || c[g]), Array.prototype.push.apply(o, d.eval(b, e, this.important).rules); } catch (w) { - throw { - message: w.message, index: this.index, filename: this.currentFileInfo.filename, stack: w.stack, - }; - } -} -} if (p) { if (!this.currentFileInfo || !this.currentFileInfo.reference) for (f = 0; f < o.length; f++)k = o[f], k.markReferenced && k.markReferenced(); return o; } + try { d = q[g].mixin, d instanceof a.mixin.Definition || (d = new a.mixin.Definition('', [], d.rules, null, !1), d.originalRuleset = c[g].originalRuleset || c[g]), Array.prototype.push.apply(o, d.eval(b, e, this.important).rules); } catch (w) { + throw { + message: w.message, index: this.index, filename: this.currentFileInfo.filename, stack: w.stack, + }; + } + } + } if (p) { if (!this.currentFileInfo || !this.currentFileInfo.reference) for (f = 0; f < o.length; f++)k = o[f], k.markReferenced && k.markReferenced(); return o; } } } throw j ? { type: 'Runtime', message: `No matching definition was found for \`${this.format(e)}\``, index: this.index, filename: this.currentFileInfo.filename, diff --git a/packages/mindplot/lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js b/packages/mindplot/src/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js similarity index 100% rename from packages/mindplot/lib/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js rename to packages/mindplot/src/components/libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js diff --git a/packages/mindplot/lib/components/libraries/mootools/mootools-core-1.4.5.js b/packages/mindplot/src/components/libraries/mootools/mootools-core-1.4.5.js similarity index 100% rename from packages/mindplot/lib/components/libraries/mootools/mootools-core-1.4.5.js rename to packages/mindplot/src/components/libraries/mootools/mootools-core-1.4.5.js diff --git a/packages/mindplot/lib/components/libraries/mootools/mootools-core-1.6.0.js b/packages/mindplot/src/components/libraries/mootools/mootools-core-1.6.0.js similarity index 100% rename from packages/mindplot/lib/components/libraries/mootools/mootools-core-1.6.0.js rename to packages/mindplot/src/components/libraries/mootools/mootools-core-1.6.0.js diff --git a/packages/mindplot/src/components/libraries/underscorejs/underscore-min.js b/packages/mindplot/src/components/libraries/underscorejs/underscore-min.js new file mode 100644 index 00000000..90b5ebfd --- /dev/null +++ b/packages/mindplot/src/components/libraries/underscorejs/underscore-min.js @@ -0,0 +1,13 @@ +// Underscore.js 1.6.0 +// http://underscorejs.org +// (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors +// Underscore may be freely distributed under the MIT license. +(function () { + const n = this; const t = n._; const r = {}; const e = Array.prototype; const u = Object.prototype; const i = Function.prototype; const a = e.push; const o = e.slice; const c = e.concat; const l = u.toString; const f = u.hasOwnProperty; const s = e.forEach; const p = e.map; const h = e.reduce; const v = e.reduceRight; const g = e.filter; const d = e.every; const m = e.some; const y = e.indexOf; const b = e.lastIndexOf; const x = Array.isArray; const w = Object.keys; const _ = i.bind; var j = function (n) { return n instanceof j ? n : this instanceof j ? void (this._wrapped = n) : new j(n); }; typeof exports !== 'undefined' ? (typeof module !== 'undefined' && module.exports && (exports = module.exports = j), exports._ = j) : n._ = j, j.VERSION = '1.6.0'; const A = j.each = j.forEach = function (n, t, e) { if (n == null) return n; if (s && n.forEach === s)n.forEach(t, e); else if (n.length === +n.length) { for (var u = 0, i = n.length; i > u; u++) if (t.call(e, n[u], u, n) === r) return; } else for (var a = j.keys(n), u = 0, i = a.length; i > u; u++) if (t.call(e, n[a[u]], a[u], n) === r) return; return n; }; j.map = j.collect = function (n, t, r) { const e = []; return n == null ? e : p && n.map === p ? n.map(t, r) : (A(n, (n, u, i) => { e.push(t.call(r, n, u, i)); }), e); }; const O = 'Reduce of empty array with no initial value'; j.reduce = j.foldl = j.inject = function (n, t, r, e) { let u = arguments.length > 2; if (n == null && (n = []), h && n.reduce === h) return e && (t = j.bind(t, e)), u ? n.reduce(t, r) : n.reduce(t); if (A(n, (n, i, a) => { u ? r = t.call(e, r, n, i, a) : (r = n, u = !0); }), !u) throw new TypeError(O); return r; }, j.reduceRight = j.foldr = function (n, t, r, e) { let u = arguments.length > 2; if (n == null && (n = []), v && n.reduceRight === v) return e && (t = j.bind(t, e)), u ? n.reduceRight(t, r) : n.reduceRight(t); let i = n.length; if (i !== +i) { var a = j.keys(n); i = a.length; } if (A(n, (o, c, l) => { c = a ? a[--i] : --i, u ? r = t.call(e, r, n[c], c, l) : (r = n[c], u = !0); }), !u) throw new TypeError(O); return r; }, j.find = j.detect = function (n, t, r) { let e; return k(n, (n, u, i) => (t.call(r, n, u, i) ? (e = n, !0) : void 0)), e; }, j.filter = j.select = function (n, t, r) { const e = []; return n == null ? e : g && n.filter === g ? n.filter(t, r) : (A(n, (n, u, i) => { t.call(r, n, u, i) && e.push(n); }), e); }, j.reject = function (n, t, r) { return j.filter(n, (n, e, u) => !t.call(r, n, e, u), r); }, j.every = j.all = function (n, t, e) { t || (t = j.identity); let u = !0; return n == null ? u : d && n.every === d ? n.every(t, e) : (A(n, (n, i, a) => ((u = u && t.call(e, n, i, a)) ? void 0 : r)), !!u); }; var k = j.some = j.any = function (n, t, e) { t || (t = j.identity); let u = !1; return n == null ? u : m && n.some === m ? n.some(t, e) : (A(n, (n, i, a) => (u || (u = t.call(e, n, i, a)) ? r : void 0)), !!u); }; j.contains = j.include = function (n, t) { return n == null ? !1 : y && n.indexOf === y ? n.indexOf(t) != -1 : k(n, (n) => n === t); }, j.invoke = function (n, t) { const r = o.call(arguments, 2); const e = j.isFunction(t); return j.map(n, (n) => (e ? t : n[t]).apply(n, r)); }, j.pluck = function (n, t) { return j.map(n, j.property(t)); }, j.where = function (n, t) { return j.filter(n, j.matches(t)); }, j.findWhere = function (n, t) { return j.find(n, j.matches(t)); }, j.max = function (n, t, r) { if (!t && j.isArray(n) && n[0] === +n[0] && n.length < 65535) return Math.max.apply(Math, n); let e = -1 / 0; let u = -1 / 0; return A(n, (n, i, a) => { const o = t ? t.call(r, n, i, a) : n; o > u && (e = n, u = o); }), e; }, j.min = function (n, t, r) { if (!t && j.isArray(n) && n[0] === +n[0] && n.length < 65535) return Math.min.apply(Math, n); let e = 1 / 0; let u = 1 / 0; return A(n, (n, i, a) => { const o = t ? t.call(r, n, i, a) : n; u > o && (e = n, u = o); }), e; }, j.shuffle = function (n) { let t; let r = 0; const e = []; return A(n, (n) => { t = j.random(r++), e[r - 1] = e[t], e[t] = n; }), e; }, j.sample = function (n, t, r) { return t == null || r ? (n.length !== +n.length && (n = j.values(n)), n[j.random(n.length - 1)]) : j.shuffle(n).slice(0, Math.max(0, t)); }; const E = function (n) { return n == null ? j.identity : j.isFunction(n) ? n : j.property(n); }; j.sortBy = function (n, t, r) { return t = E(t), j.pluck(j.map(n, (n, e, u) => ({ value: n, index: e, criteria: t.call(r, n, e, u) })).sort((n, t) => { const r = n.criteria; const e = t.criteria; if (r !== e) { if (r > e || r === void 0) return 1; if (e > r || e === void 0) return -1; } return n.index - t.index; }), 'value'); }; const F = function (n) { return function (t, r, e) { const u = {}; return r = E(r), A(t, (i, a) => { const o = r.call(e, i, a, t); n(u, o, i); }), u; }; }; j.groupBy = F((n, t, r) => { j.has(n, t) ? n[t].push(r) : n[t] = [r]; }), j.indexBy = F((n, t, r) => { n[t] = r; }), j.countBy = F((n, t) => { j.has(n, t) ? n[t]++ : n[t] = 1; }), j.sortedIndex = function (n, t, r, e) { r = E(r); for (var u = r.call(e, t), i = 0, a = n.length; a > i;) { const o = i + a >>> 1; r.call(e, n[o]) < u ? i = o + 1 : a = o; } return i; }, j.toArray = function (n) { return n ? j.isArray(n) ? o.call(n) : n.length === +n.length ? j.map(n, j.identity) : j.values(n) : []; }, j.size = function (n) { return n == null ? 0 : n.length === +n.length ? n.length : j.keys(n).length; }, j.first = j.head = j.take = function (n, t, r) { return n == null ? void 0 : t == null || r ? n[0] : t < 0 ? [] : o.call(n, 0, t); }, j.initial = function (n, t, r) { return o.call(n, 0, n.length - (t == null || r ? 1 : t)); }, j.last = function (n, t, r) { return n == null ? void 0 : t == null || r ? n[n.length - 1] : o.call(n, Math.max(n.length - t, 0)); }, j.rest = j.tail = j.drop = function (n, t, r) { return o.call(n, t == null || r ? 1 : t); }, j.compact = function (n) { return j.filter(n, j.identity); }; var M = function (n, t, r) { return t && j.every(n, j.isArray) ? c.apply(r, n) : (A(n, (n) => { j.isArray(n) || j.isArguments(n) ? t ? a.apply(r, n) : M(n, t, r) : r.push(n); }), r); }; j.flatten = function (n, t) { return M(n, t, []); }, j.without = function (n) { return j.difference(n, o.call(arguments, 1)); }, j.partition = function (n, t) { const r = []; const e = []; return A(n, (n) => { (t(n) ? r : e).push(n); }), [r, e]; }, j.uniq = j.unique = function (n, t, r, e) { j.isFunction(t) && (e = r, r = t, t = !1); const u = r ? j.map(n, r, e) : n; const i = []; const a = []; return A(u, (r, e) => { (t ? e && a[a.length - 1] === r : j.contains(a, r)) || (a.push(r), i.push(n[e])); }), i; }, j.union = function () { return j.uniq(j.flatten(arguments, !0)); }, j.intersection = function (n) { const t = o.call(arguments, 1); return j.filter(j.uniq(n), (n) => j.every(t, (t) => j.contains(t, n))); }, j.difference = function (n) { const t = c.apply(e, o.call(arguments, 1)); return j.filter(n, (n) => !j.contains(t, n)); }, j.zip = function () { for (var n = j.max(j.pluck(arguments, 'length').concat(0)), t = new Array(n), r = 0; n > r; r++)t[r] = j.pluck(arguments, `${r}`); return t; }, j.object = function (n, t) { if (n == null) return {}; for (var r = {}, e = 0, u = n.length; u > e; e++)t ? r[n[e]] = t[e] : r[n[e][0]] = n[e][1]; return r; }, j.indexOf = function (n, t, r) { if (n == null) return -1; let e = 0; const u = n.length; if (r) { if (typeof r !== 'number') return e = j.sortedIndex(n, t), n[e] === t ? e : -1; e = r < 0 ? Math.max(0, u + r) : r; } if (y && n.indexOf === y) return n.indexOf(t, r); for (;u > e; e++) if (n[e] === t) return e; return -1; }, j.lastIndexOf = function (n, t, r) { if (n == null) return -1; const e = r != null; if (b && n.lastIndexOf === b) return e ? n.lastIndexOf(t, r) : n.lastIndexOf(t); for (let u = e ? r : n.length; u--;) if (n[u] === t) return u; return -1; }, j.range = function (n, t, r) { arguments.length <= 1 && (t = n || 0, n = 0), r = arguments[2] || 1; for (var e = Math.max(Math.ceil((t - n) / r), 0), u = 0, i = new Array(e); e > u;)i[u++] = n, n += r; return i; }; const R = function () {}; j.bind = function (n, t) { let r; let e; if (_ && n.bind === _) return _.apply(n, o.call(arguments, 1)); if (!j.isFunction(n)) throw new TypeError(); return r = o.call(arguments, 2), e = function () { if (!(this instanceof e)) return n.apply(t, r.concat(o.call(arguments))); R.prototype = n.prototype; const u = new R(); R.prototype = null; const i = n.apply(u, r.concat(o.call(arguments))); return Object(i) === i ? i : u; }; }, j.partial = function (n) { const t = o.call(arguments, 1); return function () { for (var r = 0, e = t.slice(), u = 0, i = e.length; i > u; u++)e[u] === j && (e[u] = arguments[r++]); for (;r < arguments.length;)e.push(arguments[r++]); return n.apply(this, e); }; }, j.bindAll = function (n) { const t = o.call(arguments, 1); if (t.length === 0) throw new Error('bindAll must be passed function names'); return A(t, (t) => { n[t] = j.bind(n[t], n); }), n; }, j.memoize = function (n, t) { const r = {}; return t || (t = j.identity), function () { const e = t.apply(this, arguments); return j.has(r, e) ? r[e] : r[e] = n.apply(this, arguments); }; }, j.delay = function (n, t) { const r = o.call(arguments, 2); return setTimeout(() => n.apply(null, r), t); }, j.defer = function (n) { return j.delay.apply(j, [n, 1].concat(o.call(arguments, 1))); }, j.throttle = function (n, t, r) { let e; let u; let i; let a = null; let o = 0; r || (r = {}); const c = function () { o = r.leading === !1 ? 0 : j.now(), a = null, i = n.apply(e, u), e = u = null; }; return function () { const l = j.now(); o || r.leading !== !1 || (o = l); const f = t - (l - o); return e = this, u = arguments, f <= 0 ? (clearTimeout(a), a = null, o = l, i = n.apply(e, u), e = u = null) : a || r.trailing === !1 || (a = setTimeout(c, f)), i; }; }, j.debounce = function (n, t, r) { let e; let u; let i; let a; let o; var c = function () { const l = j.now() - a; t > l ? e = setTimeout(c, t - l) : (e = null, r || (o = n.apply(i, u), i = u = null)); }; return function () { i = this, u = arguments, a = j.now(); const l = r && !e; return e || (e = setTimeout(c, t)), l && (o = n.apply(i, u), i = u = null), o; }; }, j.once = function (n) { let t; let r = !1; return function () { return r ? t : (r = !0, t = n.apply(this, arguments), n = null, t); }; }, j.wrap = function (n, t) { return j.partial(t, n); }, j.compose = function () { const n = arguments; return function () { for (var t = arguments, r = n.length - 1; r >= 0; r--)t = [n[r].apply(this, t)]; return t[0]; }; }, j.after = function (n, t) { return function () { return --n < 1 ? t.apply(this, arguments) : void 0; }; }, j.keys = function (n) { if (!j.isObject(n)) return []; if (w) return w(n); const t = []; for (const r in n)j.has(n, r) && t.push(r); return t; }, j.values = function (n) { for (var t = j.keys(n), r = t.length, e = new Array(r), u = 0; r > u; u++)e[u] = n[t[u]]; return e; }, j.pairs = function (n) { for (var t = j.keys(n), r = t.length, e = new Array(r), u = 0; r > u; u++)e[u] = [t[u], n[t[u]]]; return e; }, j.invert = function (n) { for (var t = {}, r = j.keys(n), e = 0, u = r.length; u > e; e++)t[n[r[e]]] = r[e]; return t; }, j.functions = j.methods = function (n) { const t = []; for (const r in n)j.isFunction(n[r]) && t.push(r); return t.sort(); }, j.extend = function (n) { return A(o.call(arguments, 1), (t) => { if (t) for (const r in t)n[r] = t[r]; }), n; }, j.pick = function (n) { const t = {}; const r = c.apply(e, o.call(arguments, 1)); return A(r, (r) => { r in n && (t[r] = n[r]); }), t; }, j.omit = function (n) { const t = {}; const r = c.apply(e, o.call(arguments, 1)); for (const u in n)j.contains(r, u) || (t[u] = n[u]); return t; }, j.defaults = function (n) { return A(o.call(arguments, 1), (t) => { if (t) for (const r in t)n[r] === void 0 && (n[r] = t[r]); }), n; }, j.clone = function (n) { return j.isObject(n) ? j.isArray(n) ? n.slice() : j.extend({}, n) : n; }, j.tap = function (n, t) { return t(n), n; }; var S = function (n, t, r, e) { if (n === t) return n !== 0 || 1 / n == 1 / t; if (n == null || t == null) return n === t; n instanceof j && (n = n._wrapped), t instanceof j && (t = t._wrapped); const u = l.call(n); if (u != l.call(t)) return !1; switch (u) { case '[object String]': return n == String(t); case '[object Number]': return n != +n ? t != +t : n == 0 ? 1 / n == 1 / t : n == +t; case '[object Date]': case '[object Boolean]': return +n == +t; case '[object RegExp]': return n.source == t.source && n.global == t.global && n.multiline == t.multiline && n.ignoreCase == t.ignoreCase; } if (typeof n !== 'object' || typeof t !== 'object') return !1; for (let i = r.length; i--;) if (r[i] == n) return e[i] == t; const a = n.constructor; const o = t.constructor; if (a !== o && !(j.isFunction(a) && a instanceof a && j.isFunction(o) && o instanceof o) && 'constructor' in n && 'constructor' in t) return !1; r.push(n), e.push(t); let c = 0; let f = !0; if (u == '[object Array]') { if (c = n.length, f = c == t.length) for (;c-- && (f = S(n[c], t[c], r, e));); } else { for (var s in n) if (j.has(n, s) && (c++, !(f = j.has(t, s) && S(n[s], t[s], r, e)))) break; if (f) { for (s in t) if (j.has(t, s) && !c--) break; f = !c; } } return r.pop(), e.pop(), f; }; j.isEqual = function (n, t) { return S(n, t, [], []); }, j.isEmpty = function (n) { if (n == null) return !0; if (j.isArray(n) || j.isString(n)) return n.length === 0; for (const t in n) if (j.has(n, t)) return !1; return !0; }, j.isElement = function (n) { return !(!n || n.nodeType !== 1); }, j.isArray = x || function (n) { return l.call(n) == '[object Array]'; }, j.isObject = function (n) { return n === Object(n); }, A(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], (n) => { j[`is${n}`] = function (t) { return l.call(t) == `[object ${n}]`; }; }), j.isArguments(arguments) || (j.isArguments = function (n) { return !(!n || !j.has(n, 'callee')); }), typeof /./ !== 'function' && (j.isFunction = function (n) { return typeof n === 'function'; }), j.isFinite = function (n) { return isFinite(n) && !isNaN(parseFloat(n)); }, j.isNaN = function (n) { return j.isNumber(n) && n != +n; }, j.isBoolean = function (n) { return n === !0 || n === !1 || l.call(n) == '[object Boolean]'; }, j.isNull = function (n) { return n === null; }, j.isUndefined = function (n) { return n === void 0; }, j.has = function (n, t) { return f.call(n, t); }, j.noConflict = function () { return n._ = t, this; }, j.identity = function (n) { return n; }, j.constant = function (n) { return function () { return n; }; }, j.property = function (n) { return function (t) { return t[n]; }; }, j.matches = function (n) { return function (t) { if (t === n) return !0; for (const r in n) if (n[r] !== t[r]) return !1; return !0; }; }, j.times = function (n, t, r) { for (var e = Array(Math.max(0, n)), u = 0; n > u; u++)e[u] = t.call(r, u); return e; }, j.random = function (n, t) { return t == null && (t = n, n = 0), n + Math.floor(Math.random() * (t - n + 1)); }, j.now = Date.now || function () { return (new Date()).getTime(); }; const T = { + escape: { + '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', + }, + }; T.unescape = j.invert(T.escape); const I = { escape: new RegExp(`[${j.keys(T.escape).join('')}]`, 'g'), unescape: new RegExp(`(${j.keys(T.unescape).join('|')})`, 'g') }; j.each(['escape', 'unescape'], (n) => { j[n] = function (t) { return t == null ? '' : (`${t}`).replace(I[n], (t) => T[n][t]); }; }), j.result = function (n, t) { if (n == null) return void 0; const r = n[t]; return j.isFunction(r) ? r.call(n) : r; }, j.mixin = function (n) { A(j.functions(n), (t) => { const r = j[t] = n[t]; j.prototype[t] = function () { const n = [this._wrapped]; return a.apply(n, arguments), z.call(this, r.apply(j, n)); }; }); }; let N = 0; j.uniqueId = function (n) { const t = `${++N}`; return n ? n + t : t; }, j.templateSettings = { evaluate: /<%([\s\S]+?)%>/g, interpolate: /<%=([\s\S]+?)%>/g, escape: /<%-([\s\S]+?)%>/g }; const q = /(.)^/; const B = { + "'": "'", '\\': '\\', '\r': 'r', '\n': 'n', ' ': 't', '\u2028': 'u2028', '\u2029': 'u2029', + }; const D = /\\|'|\r|\n|\t|\u2028|\u2029/g; j.template = function (n, t, r) { let e; r = j.defaults({}, r, j.templateSettings); const u = new RegExp(`${[(r.escape || q).source, (r.interpolate || q).source, (r.evaluate || q).source].join('|')}|$`, 'g'); let i = 0; let a = "__p+='"; n.replace(u, (t, r, e, u, o) => (a += n.slice(i, o).replace(D, (n) => `\\${B[n]}`), r && (a += `'+\n((__t=(${r}))==null?'':_.escape(__t))+\n'`), e && (a += `'+\n((__t=(${e}))==null?'':__t)+\n'`), u && (a += `';\n${u}\n__p+='`), i = o + t.length, t)), a += "';\n", r.variable || (a = `with(obj||{}){\n${a}}\n`), a = `${"var __t,__p='',__j=Array.prototype.join," + "print=function(){__p+=__j.call(arguments,'');};\n"}${a}return __p;\n`; try { e = new Function(r.variable || 'obj', '_', a); } catch (o) { throw o.source = a, o; } if (t) return e(t, j); const c = function (n) { return e.call(this, n, j); }; return c.source = `function(${r.variable || 'obj'}){\n${a}}`, c; }, j.chain = function (n) { return j(n).chain(); }; var z = function (n) { return this._chain ? j(n).chain() : n; }; j.mixin(j), A(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (n) => { const t = e[n]; j.prototype[n] = function () { const r = this._wrapped; return t.apply(r, arguments), n != 'shift' && n != 'splice' || r.length !== 0 || delete r[0], z.call(this, r); }; }), A(['concat', 'join', 'slice'], (n) => { const t = e[n]; j.prototype[n] = function () { return z.call(this, t.apply(this._wrapped, arguments)); }; }), j.extend(j.prototype, { chain() { return this._chain = !0, this; }, value() { return this._wrapped; } }), typeof define === 'function' && define.amd && define('underscore', [], () => j); +}).call(this); diff --git a/packages/mindplot/lib/components/model/FeatureModel.js b/packages/mindplot/src/components/model/FeatureModel.js similarity index 91% rename from packages/mindplot/lib/components/model/FeatureModel.js rename to packages/mindplot/src/components/model/FeatureModel.js index 6ba78c88..ac93b60c 100644 --- a/packages/mindplot/lib/components/model/FeatureModel.js +++ b/packages/mindplot/src/components/model/FeatureModel.js @@ -17,17 +17,6 @@ */ const FeatureModel = new Class(/** @lends FeatureModel */{ - Static: { - _nextUUID() { - if (!$defined(FeatureModel._uuid)) { - FeatureModel._uuid = 0; - } - - FeatureModel._uuid += 1; - return FeatureModel._uuid; - }, - }, - /** * @constructs * @param type @@ -88,4 +77,13 @@ const FeatureModel = new Class(/** @lends FeatureModel */{ }, }); +FeatureModel._nextUUID = function _nextUUID() { + if (!$defined(FeatureModel._uuid)) { + FeatureModel._uuid = 0; + } + + FeatureModel._uuid += 1; + return FeatureModel._uuid; +}; + export default FeatureModel; diff --git a/packages/mindplot/lib/components/model/IMindmap.js b/packages/mindplot/src/components/model/IMindmap.js similarity index 100% rename from packages/mindplot/lib/components/model/IMindmap.js rename to packages/mindplot/src/components/model/IMindmap.js diff --git a/packages/mindplot/lib/components/model/INodeModel.js b/packages/mindplot/src/components/model/INodeModel.js similarity index 88% rename from packages/mindplot/lib/components/model/INodeModel.js rename to packages/mindplot/src/components/model/INodeModel.js index f94c555e..c8ac8556 100644 --- a/packages/mindplot/lib/components/model/INodeModel.js +++ b/packages/mindplot/src/components/model/INodeModel.js @@ -1,3 +1,11 @@ +/* eslint-disable no-shadow */ +/* eslint-disable no-throw-literal */ +/* eslint-disable no-unused-vars */ +/* eslint-disable no-eval */ +/* eslint-disable radix */ +/* eslint-disable no-restricted-globals */ +/* eslint-disable no-param-reassign */ +/* eslint-disable no-underscore-dangle */ /* * Copyright [2015] [wisemapping] * @@ -15,6 +23,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import coreJs from '@wisemapping/core-js'; +import _ from '../../../../../libraries/underscore-min'; + +const core = coreJs(); const INodeModel = new Class( /** @lends INodeModel */ { @@ -23,7 +35,7 @@ const INodeModel = new Class( * @param mindmap */ initialize(mindmap) { - $assert(mindmap && mindmap.getBranches, 'mindmap can not be null'); + core.Function.$assert(mindmap && mindmap.getBranches, 'mindmap can not be null'); this._mindmap = mindmap; }, @@ -34,10 +46,10 @@ const INodeModel = new Class( /** */ setId(id) { - if ($defined(id) && id > INodeModel._uuid) { + if (core.Function.$defined(id) && id > INodeModel._uuid) { INodeModel._uuid = id; } - if (!$defined(id)) { + if (!core.Function.$defined(id)) { id = INodeModel._nextUUID(); } @@ -66,8 +78,8 @@ const INodeModel = new Class( /** */ setPosition(x, y) { - $assert(!isNaN(parseInt(x)), `x position is not valid:${x}`); - $assert(!isNaN(parseInt(y)), `y position is not valid:${y}`); + core.Function.$assert(!isNaN(parseInt(x)), `x position is not valid:${x}`); + core.Function.$assert(!isNaN(parseInt(y)), `y position is not valid:${y}`); this.putProperty('position', `{x:${parseInt(x)},y:${parseInt(y)}}`); }, @@ -142,7 +154,7 @@ const INodeModel = new Class( /** */ setOrder(value) { - $assert( + core.Function.$assert( (typeof value === 'number' && isFinite(value)) || value == null, 'Order must be null or a number', ); @@ -227,7 +239,7 @@ const INodeModel = new Class( /** */ areChildrenShrunken() { const result = this.getProperty('shrunken'); - return $defined(result) ? result : false; + return core.Function.$defined(result) ? result : false; }, /** @@ -262,7 +274,7 @@ const INodeModel = new Class( * @see mindplot.model.IMindmap.connect */ connectTo(parent) { - $assert(parent, 'parent can not be null'); + core.Function.$assert(parent, 'parent can not be null'); const mindmap = this.getMindmap(); mindmap.connect(parent, this); }, @@ -302,7 +314,7 @@ const INodeModel = new Class( // console.log("Before:" + mindmap.inspect()); const parent = this.getParent(); - if ($defined(parent)) { + if (core.Function.$defined(parent)) { parent.removeChild(this); } else { // If it has not parent, it must be an isolate topic ... @@ -344,12 +356,7 @@ const INodeModel = new Class( /** */ inspect() { - let result = `{ type: ${ - this.getType() - } , id: ${ - this.getId() - } , text: ${ - this.getText()}`; + let result = `{ type: ${this.getType()} , id: ${this.getId()} , text: ${this.getText()}`; const children = this.getChildren(); if (children.length > 0) { @@ -410,8 +417,8 @@ INodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220; /** * @todo: This method must be implemented. (unascribed) */ -INodeModel._nextUUID = function () { - if (!$defined(INodeModel._uuid)) { +INodeModel._nextUUID = () => { + if (!core.Function.$defined(INodeModel._uuid)) { INodeModel._uuid = 0; } diff --git a/packages/mindplot/lib/components/model/IconModel.js b/packages/mindplot/src/components/model/IconModel.js similarity index 96% rename from packages/mindplot/lib/components/model/IconModel.js rename to packages/mindplot/src/components/model/IconModel.js index bdc9723d..279be526 100644 --- a/packages/mindplot/lib/components/model/IconModel.js +++ b/packages/mindplot/src/components/model/IconModel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const FeatureModel = require('./FeatureModel').default; +import FeatureModel from './FeatureModel'; const IconModel = new Class(/** @lends IconModel */{ Extends: FeatureModel, diff --git a/packages/mindplot/lib/components/model/LinkModel.js b/packages/mindplot/src/components/model/LinkModel.js similarity index 97% rename from packages/mindplot/lib/components/model/LinkModel.js rename to packages/mindplot/src/components/model/LinkModel.js index 84ba3df5..588e20b0 100644 --- a/packages/mindplot/lib/components/model/LinkModel.js +++ b/packages/mindplot/src/components/model/LinkModel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const FeatureModel = require('./FeatureModel').default; +import FeatureModel from './FeatureModel'; const LinkModel = new Class(/** @lends LinkModel */{ Extends: FeatureModel, diff --git a/packages/mindplot/lib/components/model/Mindmap.js b/packages/mindplot/src/components/model/Mindmap.js similarity index 94% rename from packages/mindplot/lib/components/model/Mindmap.js rename to packages/mindplot/src/components/model/Mindmap.js index 0e47f556..fe4074b2 100644 --- a/packages/mindplot/lib/components/model/Mindmap.js +++ b/packages/mindplot/src/components/model/Mindmap.js @@ -15,11 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const IMindmap = require('./IMindmap').default; -const INodeModel = require('./INodeModel').default; -const NodeModel = require('./NodeModel').default; -const RelationshipModel = require('./RelationshipModel').default; -const ModelCodeName = require('../persistence/ModelCodeName').default; +import IMindmap from './IMindmap'; +import INodeModel from './INodeModel'; +import NodeModel from './NodeModel'; +import RelationshipModel from './RelationshipModel'; +import ModelCodeName from '../persistence/ModelCodeName'; const Mindmap = new Class(/** @lends Mindmap */{ Extends: IMindmap, diff --git a/packages/mindplot/lib/components/model/NodeModel.js b/packages/mindplot/src/components/model/NodeModel.js similarity index 98% rename from packages/mindplot/lib/components/model/NodeModel.js rename to packages/mindplot/src/components/model/NodeModel.js index 2e913d49..6933ea22 100644 --- a/packages/mindplot/lib/components/model/NodeModel.js +++ b/packages/mindplot/src/components/model/NodeModel.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const INodeModel = require('./INodeModel').default; -const TopicFeature = require('../TopicFeature').default; +import INodeModel from './INodeModel'; +import TopicFeature from '../TopicFeature'; const NodeModel = new Class(/** @lends NodeModel */{ Extends: INodeModel, diff --git a/packages/mindplot/lib/components/model/NoteModel.js b/packages/mindplot/src/components/model/NoteModel.js similarity index 96% rename from packages/mindplot/lib/components/model/NoteModel.js rename to packages/mindplot/src/components/model/NoteModel.js index eb7858e0..eb0751ff 100644 --- a/packages/mindplot/lib/components/model/NoteModel.js +++ b/packages/mindplot/src/components/model/NoteModel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const FeatureModel = require('./FeatureModel').default; +import FeatureModel from './FeatureModel'; const NoteModel = new Class(/** @lends NoteModel */{ Extends: FeatureModel, diff --git a/packages/mindplot/lib/components/model/RelationshipModel.js b/packages/mindplot/src/components/model/RelationshipModel.js similarity index 92% rename from packages/mindplot/lib/components/model/RelationshipModel.js rename to packages/mindplot/src/components/model/RelationshipModel.js index d6580ce3..5d6b44e2 100644 --- a/packages/mindplot/lib/components/model/RelationshipModel.js +++ b/packages/mindplot/src/components/model/RelationshipModel.js @@ -15,20 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ConnectionLine = require('../ConnectionLine').default; +import ConnectionLine from '../ConnectionLine'; const RelationshipModel = new Class( /** @lends RelationshipModel */ { - Static: { - _nextUUID() { - if (!$defined(RelationshipModel._uuid)) { - RelationshipModel._uuid = 0; - } - RelationshipModel._uuid += 1; - return RelationshipModel._uuid; - }, - }, - /** * @constructs * @param sourceTopicId @@ -145,4 +135,12 @@ const RelationshipModel = new Class( }, ); +RelationshipModel._nextUUID = function _nextUUID() { + if (!$defined(RelationshipModel._uuid)) { + RelationshipModel._uuid = 0; + } + RelationshipModel._uuid += 1; + return RelationshipModel._uuid; +}; + export default RelationshipModel; diff --git a/packages/mindplot/src/components/model/index.js b/packages/mindplot/src/components/model/index.js new file mode 100644 index 00000000..76dca648 --- /dev/null +++ b/packages/mindplot/src/components/model/index.js @@ -0,0 +1,21 @@ +import featureModel from './FeatureModel'; +import iconModel from './IconModel'; +import iMindmap from './IMindmap'; +import iNodeModel from './INodeModel'; +import linkModel from './LinkModel'; +import noteModel from './NoteModel'; +import mindmap from './Mindmap'; +import nodeModel from './NodeModel'; +import relationshipModel from './RelationshipModel'; + +export default { + FeatureModel: featureModel, + IconModel: iconModel, + IMindmap: iMindmap, + INodeModel: iNodeModel, + LinkModel: linkModel, + NoteModel: noteModel, + Mindmap: mindmap, + NodeModel: nodeModel, + RelationshipModel: relationshipModel, +}; diff --git a/packages/mindplot/lib/components/persistence/Beta2PelaMigrator.js b/packages/mindplot/src/components/persistence/Beta2PelaMigrator.js similarity index 93% rename from packages/mindplot/lib/components/persistence/Beta2PelaMigrator.js rename to packages/mindplot/src/components/persistence/Beta2PelaMigrator.js index 4c30b672..db6fe335 100644 --- a/packages/mindplot/lib/components/persistence/Beta2PelaMigrator.js +++ b/packages/mindplot/src/components/persistence/Beta2PelaMigrator.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ModelCodeName = require('./ModelCodeName').default; -const XMLSerializer_Pela = require('./XMLSerializer_Pela').default; +import ModelCodeName from './ModelCodeName'; +import XMLSerializer_Pela from './XMLSerializer_Pela'; const Beta2PelaMigrator = new Class({ initialize(betaSerializer) { diff --git a/packages/mindplot/lib/components/persistence/ModelCodeName.js b/packages/mindplot/src/components/persistence/ModelCodeName.js similarity index 100% rename from packages/mindplot/lib/components/persistence/ModelCodeName.js rename to packages/mindplot/src/components/persistence/ModelCodeName.js diff --git a/packages/mindplot/lib/components/persistence/Pela2TangoMigrator.js b/packages/mindplot/src/components/persistence/Pela2TangoMigrator.js similarity index 95% rename from packages/mindplot/lib/components/persistence/Pela2TangoMigrator.js rename to packages/mindplot/src/components/persistence/Pela2TangoMigrator.js index 341e6fb7..0240c7f1 100644 --- a/packages/mindplot/lib/components/persistence/Pela2TangoMigrator.js +++ b/packages/mindplot/src/components/persistence/Pela2TangoMigrator.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const XMLSerializer_Tango = require('./XMLSerializer_Tango').default; -const ModelCodeName = require('./ModelCodeName').default; +import XMLSerializer_Tango from './XMLSerializer_Tango'; +import ModelCodeName from './ModelCodeName'; const Pela2TangoMigrator = new Class({ initialize(pelaSerializer) { diff --git a/packages/mindplot/lib/components/persistence/XMLSerializerFactory.js b/packages/mindplot/src/components/persistence/XMLSerializerFactory.js similarity index 87% rename from packages/mindplot/lib/components/persistence/XMLSerializerFactory.js rename to packages/mindplot/src/components/persistence/XMLSerializerFactory.js index c7918015..d35c706c 100644 --- a/packages/mindplot/lib/components/persistence/XMLSerializerFactory.js +++ b/packages/mindplot/src/components/persistence/XMLSerializerFactory.js @@ -15,12 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ModelCodeName = require('./ModelCodeName').default; -const Beta2PelaMigrator = require('./Beta2PelaMigrator').default; -const Pela2TangoMigrator = require('./Pela2TangoMigrator').default; -const XMLSerializer_Beta = require('./XMLSerializer_Beta').default; -const XMLSerializer_Pela = require('./XMLSerializer_Pela').default; -const XMLSerializer_Tango = require('./XMLSerializer_Tango').default; +import ModelCodeName from './ModelCodeName'; +import Beta2PelaMigrator from './Beta2PelaMigrator'; +import Pela2TangoMigrator from './Pela2TangoMigrator'; +import XMLSerializer_Beta from './XMLSerializer_Beta'; +import XMLSerializer_Pela from './XMLSerializer_Pela'; +import XMLSerializer_Tango from './XMLSerializer_Tango'; /** * @class mindplot.persistence.XMLSerializerFactory diff --git a/packages/mindplot/lib/components/persistence/XMLSerializer_Beta.js b/packages/mindplot/src/components/persistence/XMLSerializer_Beta.js similarity index 87% rename from packages/mindplot/lib/components/persistence/XMLSerializer_Beta.js rename to packages/mindplot/src/components/persistence/XMLSerializer_Beta.js index 7f6f0539..95366151 100644 --- a/packages/mindplot/lib/components/persistence/XMLSerializer_Beta.js +++ b/packages/mindplot/src/components/persistence/XMLSerializer_Beta.js @@ -14,16 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import Core from '@wisemapping/core-js'; +import ModelCodeName from './ModelCodeName'; +import Mindmap from '../model/Mindmap'; +import INodeModel from '../model/INodeModel'; +import TopicFeature from '../TopicFeature'; const core = Core(); -const ModelCodeName = require('./ModelCodeName').default; -const Mindmap = require('../model/Mindmap').default; -const INodeModel = require('../model/INodeModel').default; -const TopicFeature = require('../TopicFeature').default; const XMLSerializer_Beta = new Class({ - toXML(mindmap) { $assert(mindmap, 'Can not save a null mindmap'); @@ -97,8 +96,13 @@ const XMLSerializer_Beta = new Class({ const fontStyle = topic.getFontStyle(); font += `${fontStyle || ''};`; - if ($defined(fontFamily) || $defined(fontSize) || $defined(fontColor) - || $defined(fontWeight) || $defined(fontStyle)) { + if ( + $defined(fontFamily) + || $defined(fontSize) + || $defined(fontColor) + || $defined(fontWeight) + || $defined(fontStyle) + ) { parentTopic.setAttribute('fontStyle', font); } @@ -171,10 +175,18 @@ const XMLSerializer_Beta = new Class({ // Is a valid object ? const { documentElement } = dom; - $assert(documentElement.nodeName != 'parsererror', `Error while parsing: '${documentElement.childNodes[0].nodeValue}`); + $assert( + documentElement.nodeName != 'parsererror', + `Error while parsing: '${documentElement.childNodes[0].nodeValue}`, + ); // Is a wisemap?. - $assert(documentElement.tagName == XMLSerializer_Beta.MAP_ROOT_NODE, `This seem not to be a map document. Root Tag: '${documentElement.tagName},',HTML:${dom.innerHTML},XML:${core.Utils.innerXML(dom)}`); + $assert( + documentElement.tagName == XMLSerializer_Beta.MAP_ROOT_NODE, + `This seem not to be a map document. Root Tag: '${documentElement.tagName},',HTML:${ + dom.innerHTML + },XML:${core.Utils.innerXML(dom)}`, + ); // Start the loading process ... let version = documentElement.getAttribute('version'); @@ -194,7 +206,9 @@ const XMLSerializer_Beta = new Class({ }, _deserializeNode(domElem, mindmap) { - const type = (domElem.getAttribute('central') != null) ? INodeModel.CENTRAL_TOPIC_TYPE : INodeModel.MAIN_TOPIC_TYPE; + const type = domElem.getAttribute('central') != null + ? INodeModel.CENTRAL_TOPIC_TYPE + : INodeModel.MAIN_TOPIC_TYPE; const topic = mindmap.createNode(type); // Load attributes... @@ -264,7 +278,13 @@ const XMLSerializer_Beta = new Class({ for (let i = 0; i < children.length; i++) { const child = children[i]; if (child.nodeType == 1) { - $assert(child.tagName == 'topic' || child.tagName == 'icon' || child.tagName == 'link' || child.tagName == 'note', `Illegal node type:${child.tagName}`); + $assert( + child.tagName == 'topic' + || child.tagName == 'icon' + || child.tagName == 'link' + || child.tagName == 'note', + `Illegal node type:${child.tagName}`, + ); if (child.tagName == 'topic') { const childTopic = this._deserializeNode(child, mindmap); childTopic.connectTo(topic); diff --git a/packages/mindplot/lib/components/persistence/XMLSerializer_Pela.js b/packages/mindplot/src/components/persistence/XMLSerializer_Pela.js similarity index 94% rename from packages/mindplot/lib/components/persistence/XMLSerializer_Pela.js rename to packages/mindplot/src/components/persistence/XMLSerializer_Pela.js index 8893547b..b263c5cf 100644 --- a/packages/mindplot/lib/components/persistence/XMLSerializer_Pela.js +++ b/packages/mindplot/src/components/persistence/XMLSerializer_Pela.js @@ -15,14 +15,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import Core from '@wisemapping/core-js'; +import web2d from '@wisemapping/web2d'; +import Mindmap from '../model/Mindmap'; +import INodeModel, { TopicShape } from '../model/INodeModel'; +import TopicFeature from '../TopicFeature'; +import ConnectionLine from '../ConnectionLine'; const core = Core(); -const Mindmap = require('../model/Mindmap').default; -const INodeModel = require('../model/INodeModel').default; -const { TopicShape } = require('../model/INodeModel'); -const TopicFeature = require('../TopicFeature').default; -const ConnectionLine = require('../ConnectionLine').default; /** * @class @@ -90,7 +90,7 @@ const XMLSerializer_Pela = new Class( parentTopic.setAttribute('position', `${pos.x},${pos.y}`); const order = topic.getOrder(); - if (typeof order === 'number' && isFinite(order)) parentTopic.setAttribute('order', order); + if (typeof order === 'number' && isFinite(order)) { parentTopic.setAttribute('order', order); } } const text = topic.getText(); @@ -105,19 +105,14 @@ const XMLSerializer_Pela = new Class( if (shape == TopicShape.IMAGE) { parentTopic.setAttribute( 'image', - `${topic.getImageSize().width - },${ + `${topic.getImageSize().width},${ topic.getImageSize().height - }:${ - topic.getImageUrl()}`, + }:${topic.getImageUrl()}`, ); } } - if ( - topic.areChildrenShrunken() - && topic.getType() != INodeModel.CENTRAL_TOPIC_TYPE - ) { + if (topic.areChildrenShrunken() && topic.getType() != INodeModel.CENTRAL_TOPIC_TYPE) { parentTopic.setAttribute('shrink', 'true'); } @@ -216,10 +211,7 @@ const XMLSerializer_Pela = new Class( const lineType = relationship.getLineType(); result.setAttribute('lineType', lineType); - if ( - lineType == ConnectionLine.CURVED - || lineType == ConnectionLine.SIMPLE_CURVED - ) { + if (lineType == ConnectionLine.CURVED || lineType == ConnectionLine.SIMPLE_CURVED) { if ($defined(relationship.getSrcCtrlPoint())) { const srcPoint = relationship.getSrcCtrlPoint(); result.setAttribute( @@ -475,10 +467,10 @@ const XMLSerializer_Pela = new Class( const model = mindmap.createRelationship(srcId, destId); model.setLineType(lineType); if ($defined(srcCtrlPoint) && srcCtrlPoint != '') { - model.setSrcCtrlPoint(core.Point.fromString(srcCtrlPoint)); + model.setSrcCtrlPoint(web2d.Point.fromString(srcCtrlPoint)); } if ($defined(destCtrlPoint) && destCtrlPoint != '') { - model.setDestCtrlPoint(core.Point.fromString(destCtrlPoint)); + model.setDestCtrlPoint(web2d.Point.fromString(destCtrlPoint)); } model.setEndArrow('false'); model.setStartArrow('true'); diff --git a/packages/mindplot/lib/components/persistence/XMLSerializer_Tango.js b/packages/mindplot/src/components/persistence/XMLSerializer_Tango.js similarity index 94% rename from packages/mindplot/lib/components/persistence/XMLSerializer_Tango.js rename to packages/mindplot/src/components/persistence/XMLSerializer_Tango.js index ac7e29c5..543b9cf6 100644 --- a/packages/mindplot/lib/components/persistence/XMLSerializer_Tango.js +++ b/packages/mindplot/src/components/persistence/XMLSerializer_Tango.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const XMLSerializer_Pela = require('./XMLSerializer_Pela').default; +import XMLSerializer_Pela from './XMLSerializer_Pela'; /** * This serializer works exactly the same way as for the former version Pela diff --git a/packages/mindplot/src/components/persistence/index.js b/packages/mindplot/src/components/persistence/index.js new file mode 100644 index 00000000..2c75d466 --- /dev/null +++ b/packages/mindplot/src/components/persistence/index.js @@ -0,0 +1,17 @@ +import beta2PelaMigrator from './Beta2PelaMigrator'; +import modelCodeName from './ModelCodeName'; +import pela2TangoMigrator from './Pela2TangoMigrator'; +import xmlSerializerBeta from './XMLSerializer_Beta'; +import xmlSerializerPela from './XMLSerializer_Pela'; +import xmlSerializerTango from './XMLSerializer_Tango'; +import xmlSerializerFactory from './XMLSerializerFactory'; + +export default { + Beta2PelaMigrator: beta2PelaMigrator, + ModelCodeName: modelCodeName, + Pela2TangoMigrator: pela2TangoMigrator, + XMLSerializer_Beta: xmlSerializerBeta, + XMLSerializer_Pela: xmlSerializerPela, + XMLSerializer_Tango: xmlSerializerTango, + XMLSerializerFactory: xmlSerializerFactory, +}; diff --git a/packages/mindplot/lib/components/util/FadeEffect.js b/packages/mindplot/src/components/util/FadeEffect.js similarity index 96% rename from packages/mindplot/lib/components/util/FadeEffect.js rename to packages/mindplot/src/components/util/FadeEffect.js index 395faaac..dcab59ee 100644 --- a/packages/mindplot/lib/components/util/FadeEffect.js +++ b/packages/mindplot/src/components/util/FadeEffect.js @@ -17,7 +17,7 @@ */ // FIXME: this Class should be reimplemented -const Events = require('../Events').default; +import Events from '../Events'; const FadeEffect = new Class(/** @lends FadeEffect */{ Extends: Events, diff --git a/packages/mindplot/lib/components/util/Shape.js b/packages/mindplot/src/components/util/Shape.js similarity index 80% rename from packages/mindplot/lib/components/util/Shape.js rename to packages/mindplot/src/components/util/Shape.js index b9353522..0aa4f3e4 100644 --- a/packages/mindplot/lib/components/util/Shape.js +++ b/packages/mindplot/src/components/util/Shape.js @@ -15,25 +15,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Core = require('@wismapping/core-js'); +import web2d from '@wisemapping/web2d'; +import coreJs from '@wisemapping/core-js'; +import { TopicShape } from '../model/INodeModel'; +import TopicConfig from '../TopicConfig'; -const core = Core(); -const { TopicShape } = require('../model/INodeModel'); +const core = coreJs(); const Shape = { isAtRight(sourcePoint, targetPoint) { - $assert(sourcePoint, 'Source can not be null'); - $assert(targetPoint, 'Target can not be null'); + core.Function.$assert(sourcePoint, 'Source can not be null'); + core.Function.$assert(targetPoint, 'Target can not be null'); return sourcePoint.x < targetPoint.x; }, calculateRectConnectionPoint(rectCenterPoint, rectSize, isAtRight) { - $assert(rectCenterPoint, 'rectCenterPoint can not be null'); - $assert(rectSize, 'rectSize can not be null'); - $assert($defined(isAtRight), 'isRight can not be null'); + core.Function.$assert(rectCenterPoint, 'rectCenterPoint can not be null'); + core.Function.$assert(rectSize, 'rectSize can not be null'); + core.Function.$assert(core.Function.$defined(isAtRight), 'isRight can not be null'); // Node is placed at the right ? - const result = new core.Point(); + const result = new web2d.Point(); // This is used fix a minor difference ...z const correctionHardcode = 2; @@ -55,13 +57,12 @@ const Shape = { calculateRelationShipPointCoordinates(topic, controlPoint) { const size = topic.getSize(); const position = topic.getPosition(); - let m; const yGap = position.y - controlPoint.y; const xGap = position.x - controlPoint.x; const disable = Math.abs(yGap) < 5 || Math.abs(xGap) < 5 || Math.abs(yGap - xGap) < 5; - let y; let - x; + let y; + let x; const gap = 5; if (controlPoint.y > position.y + size.height / 2) { y = position.y + size.height / 2 + gap; @@ -87,7 +88,7 @@ const Shape = { y = !disable ? position.y - (yGap / xGap) * (position.x - x) : position.y; } - return new core.Point(x, y); + return new web2d.Point(x, y); }, calculateDefaultControlPoints(srcPos, tarPos) { @@ -108,24 +109,24 @@ const Shape = { const y2 = m * (x2 - tarPos.x) + tarPos.y; return [ - new core.Point(-srcPos.x + x1, -srcPos.y + y1), - new core.Point(-tarPos.x + x2, -tarPos.y + y2), + new web2d.Point(-srcPos.x + x1, -srcPos.y + y1), + new web2d.Point(-tarPos.x + x2, -tarPos.y + y2), ]; }, workoutIncomingConnectionPoint(targetNode, sourcePosition) { - $assert(sourcePosition, 'sourcePoint can not be null'); + core.Function.$assert(sourcePosition, 'sourcePoint can not be null'); const pos = targetNode.getPosition(); const size = targetNode.getSize(); const isAtRight = Shape.isAtRight(sourcePosition, pos); const result = Shape.calculateRectConnectionPoint(pos, size, isAtRight); - if (targetNode.getShapeType() == TopicShape.LINE) { + if (targetNode.getShapeType() === TopicShape.LINE) { result.y += targetNode.getSize().height / 2; } // Move a little the position... - const offset = Topic.CONNECTOR_WIDTH / 2; + const offset = TopicConfig.CONNECTOR_WIDTH / 2; if (!isAtRight) { result.x += offset; } else { diff --git a/packages/mindplot/src/components/util/index.js b/packages/mindplot/src/components/util/index.js new file mode 100644 index 00000000..0dedb597 --- /dev/null +++ b/packages/mindplot/src/components/util/index.js @@ -0,0 +1,7 @@ +import fadeEffect from './FadeEffect'; +import shape from './Shape'; + +export default { + FadeEffect: fadeEffect, + Shape: shape, +}; diff --git a/packages/mindplot/lib/components/widget/ColorPalettePanel.js b/packages/mindplot/src/components/widget/ColorPalettePanel.js similarity index 98% rename from packages/mindplot/lib/components/widget/ColorPalettePanel.js rename to packages/mindplot/src/components/widget/ColorPalettePanel.js index 90806f54..f928a654 100644 --- a/packages/mindplot/lib/components/widget/ColorPalettePanel.js +++ b/packages/mindplot/src/components/widget/ColorPalettePanel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ToolbarPaneItem = require('./ToolbarPaneItem').default; +import ToolbarPaneItem from './ToolbarPaneItem'; const ColorPalettePanel = new Class({ Extends: ToolbarPaneItem, diff --git a/packages/mindplot/lib/components/widget/FloatingTip.js b/packages/mindplot/src/components/widget/FloatingTip.js similarity index 94% rename from packages/mindplot/lib/components/widget/FloatingTip.js rename to packages/mindplot/src/components/widget/FloatingTip.js index 58584ad5..af6ed756 100644 --- a/packages/mindplot/lib/components/widget/FloatingTip.js +++ b/packages/mindplot/src/components/widget/FloatingTip.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Options = require('../Options').default; -const Events = require('../Events').default; +import Options from '../Options'; +import Events from '../Events'; const FloatingTip = new Class({ Implements: [Options, Events], diff --git a/packages/mindplot/lib/components/widget/FontFamilyPanel.js b/packages/mindplot/src/components/widget/FontFamilyPanel.js similarity index 95% rename from packages/mindplot/lib/components/widget/FontFamilyPanel.js rename to packages/mindplot/src/components/widget/FontFamilyPanel.js index 80581898..4696dafc 100644 --- a/packages/mindplot/lib/components/widget/FontFamilyPanel.js +++ b/packages/mindplot/src/components/widget/FontFamilyPanel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ListToolbarPanel = require('./ListToolbarPanel').default; +import ListToolbarPanel from './ListToolbarPanel'; const FontFamilyPanel = new Class({ Extends: ListToolbarPanel, diff --git a/packages/mindplot/lib/components/widget/FontSizePanel.js b/packages/mindplot/src/components/widget/FontSizePanel.js similarity index 95% rename from packages/mindplot/lib/components/widget/FontSizePanel.js rename to packages/mindplot/src/components/widget/FontSizePanel.js index 2307b1b6..1ee6dd02 100644 --- a/packages/mindplot/lib/components/widget/FontSizePanel.js +++ b/packages/mindplot/src/components/widget/FontSizePanel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ListToolbarPanel = require('./ListToolbarPanel').default; +import ListToolbarPanel from './ListToolbarPanel'; const FontSizePanel = new Class({ Extends: ListToolbarPanel, diff --git a/packages/mindplot/lib/components/widget/IMenu.js b/packages/mindplot/src/components/widget/IMenu.js similarity index 97% rename from packages/mindplot/lib/components/widget/IMenu.js rename to packages/mindplot/src/components/widget/IMenu.js index e530c28a..d592baba 100644 --- a/packages/mindplot/lib/components/widget/IMenu.js +++ b/packages/mindplot/src/components/widget/IMenu.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const PersistenceManager = require('../PersistenceManager').default; +import PersistenceManager from '../PersistenceManager'; const IMenu = new Class({ diff --git a/packages/mindplot/lib/components/widget/IconPanel.js b/packages/mindplot/src/components/widget/IconPanel.js similarity index 94% rename from packages/mindplot/lib/components/widget/IconPanel.js rename to packages/mindplot/src/components/widget/IconPanel.js index 9282a883..0586a723 100644 --- a/packages/mindplot/lib/components/widget/IconPanel.js +++ b/packages/mindplot/src/components/widget/IconPanel.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ToolbarPaneItem = require('./ToolbarPaneItem').default; -const ImageIcon = require('../ImageIcon').default; +import ToolbarPaneItem from './ToolbarPaneItem'; +import ImageIcon from '../ImageIcon'; const IconPanel = new Class({ Extends: ToolbarPaneItem, diff --git a/packages/mindplot/lib/components/widget/KeyboardShortcutTooltip.js b/packages/mindplot/src/components/widget/KeyboardShortcutTooltip.js similarity index 97% rename from packages/mindplot/lib/components/widget/KeyboardShortcutTooltip.js rename to packages/mindplot/src/components/widget/KeyboardShortcutTooltip.js index e14fc13d..03cfd3cf 100644 --- a/packages/mindplot/lib/components/widget/KeyboardShortcutTooltip.js +++ b/packages/mindplot/src/components/widget/KeyboardShortcutTooltip.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const FloatingTip = require('./FloatingTip').default; +import FloatingTip from './FloatingTip'; const KeyboardShortcutTooltip = new Class({ Extends: FloatingTip, diff --git a/packages/mindplot/lib/components/widget/LinkEditor.js b/packages/mindplot/src/components/widget/LinkEditor.js similarity index 98% rename from packages/mindplot/lib/components/widget/LinkEditor.js rename to packages/mindplot/src/components/widget/LinkEditor.js index 99bea08d..0459787e 100644 --- a/packages/mindplot/lib/components/widget/LinkEditor.js +++ b/packages/mindplot/src/components/widget/LinkEditor.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const BootstrapDialog = require('../libraries/bootstrap/BootstrapDialog').default; +import BootstrapDialog from '../libraries/bootstrap/BootstrapDialog'; const LinkEditor = new Class(/** @lends LinkEditor */{ Extends: BootstrapDialog, diff --git a/packages/mindplot/lib/components/widget/LinkIconTooltip.js b/packages/mindplot/src/components/widget/LinkIconTooltip.js similarity index 95% rename from packages/mindplot/lib/components/widget/LinkIconTooltip.js rename to packages/mindplot/src/components/widget/LinkIconTooltip.js index d8527c8e..f8314da7 100644 --- a/packages/mindplot/lib/components/widget/LinkIconTooltip.js +++ b/packages/mindplot/src/components/widget/LinkIconTooltip.js @@ -15,14 +15,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const FloatingTip = require('./FloatingTip').default; +import FloatingTip from './FloatingTip'; const LinkIconTooltip = new Class({ Extends: FloatingTip, initialize(linkIcon) { $assert(linkIcon, 'linkIcon can not be null'); - const nativeElement = $(linkIcon.getImage()._peer._native); + const nativeElement = $(linkIcon.getImage().peer._native); this.parent(nativeElement, { // Content can also be a function of the target element! content: this._buildContent(linkIcon), diff --git a/packages/mindplot/lib/components/widget/ListToolbarPanel.js b/packages/mindplot/src/components/widget/ListToolbarPanel.js similarity index 96% rename from packages/mindplot/lib/components/widget/ListToolbarPanel.js rename to packages/mindplot/src/components/widget/ListToolbarPanel.js index acbcc11b..31714d72 100644 --- a/packages/mindplot/lib/components/widget/ListToolbarPanel.js +++ b/packages/mindplot/src/components/widget/ListToolbarPanel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ToolbarPaneItem = require('./ToolbarPaneItem').default; +import ToolbarPaneItem from './ToolbarPaneItem'; const ListToolbarPanel = new Class({ Extends: ToolbarPaneItem, diff --git a/packages/mindplot/lib/components/widget/Menu.js b/packages/mindplot/src/components/widget/Menu.js similarity index 96% rename from packages/mindplot/lib/components/widget/Menu.js rename to packages/mindplot/src/components/widget/Menu.js index 5e628fa3..84d7a341 100644 --- a/packages/mindplot/lib/components/widget/Menu.js +++ b/packages/mindplot/src/components/widget/Menu.js @@ -15,15 +15,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const BootstrapDialog = require('../libraries/bootstrap/BootstrapDialog').default; -const IMenu = require('./IMenu').default; -const FontFamilyPanel = require('./FontFamilyPanel').default; -const FontSizePanel = require('./FontSizePanel').default; -const TopicShapePanel = require('./TopicShapePanel').default; -const IconPanel = require('./IconPanel').default; -const ColorPalettePanel = require('./ColorPalettePanel').default; -const ToolbarItem = require('./ToolbarItem').default; -const KeyboardShortcutTooltip = require('./KeyboardShortcutTooltip').default; +import BootstrapDialog from '../libraries/bootstrap/BootstrapDialog'; +import IMenu from './IMenu'; +import FontFamilyPanel from './FontFamilyPanel'; +import FontSizePanel from './FontSizePanel'; +import TopicShapePanel from './TopicShapePanel'; +import IconPanel from './IconPanel'; +import ColorPalettePanel from './ColorPalettePanel'; +import ToolbarItem from './ToolbarItem'; +import KeyboardShortcutTooltip from './KeyboardShortcutTooltip'; const Menu = new Class({ Extends: IMenu, diff --git a/packages/mindplot/lib/components/widget/ModalDialogNotifier.js b/packages/mindplot/src/components/widget/ModalDialogNotifier.js similarity index 100% rename from packages/mindplot/lib/components/widget/ModalDialogNotifier.js rename to packages/mindplot/src/components/widget/ModalDialogNotifier.js diff --git a/packages/mindplot/lib/components/widget/NoteEditor.js b/packages/mindplot/src/components/widget/NoteEditor.js similarity index 96% rename from packages/mindplot/lib/components/widget/NoteEditor.js rename to packages/mindplot/src/components/widget/NoteEditor.js index 2575a43b..f9230591 100644 --- a/packages/mindplot/lib/components/widget/NoteEditor.js +++ b/packages/mindplot/src/components/widget/NoteEditor.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const BootstrapDialog = require('../libraries/bootstrap/BootstrapDialog').default; +import BootstrapDialog from '../libraries/bootstrap/BootstrapDialog'; const NoteEditor = new Class({ Extends: BootstrapDialog, diff --git a/packages/mindplot/lib/components/widget/ToolbarItem.js b/packages/mindplot/src/components/widget/ToolbarItem.js similarity index 97% rename from packages/mindplot/lib/components/widget/ToolbarItem.js rename to packages/mindplot/src/components/widget/ToolbarItem.js index 8f741e22..72cb40b9 100644 --- a/packages/mindplot/lib/components/widget/ToolbarItem.js +++ b/packages/mindplot/src/components/widget/ToolbarItem.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const Events = require('../Events').default; +import Events from '../Events'; const ToolbarItem = new Class({ Implements: Events, // FIXME: should be extends? diff --git a/packages/mindplot/lib/components/widget/ToolbarNotifier.js b/packages/mindplot/src/components/widget/ToolbarNotifier.js similarity index 100% rename from packages/mindplot/lib/components/widget/ToolbarNotifier.js rename to packages/mindplot/src/components/widget/ToolbarNotifier.js diff --git a/packages/mindplot/lib/components/widget/ToolbarPaneItem.js b/packages/mindplot/src/components/widget/ToolbarPaneItem.js similarity index 96% rename from packages/mindplot/lib/components/widget/ToolbarPaneItem.js rename to packages/mindplot/src/components/widget/ToolbarPaneItem.js index dddb7f04..10a03cec 100644 --- a/packages/mindplot/lib/components/widget/ToolbarPaneItem.js +++ b/packages/mindplot/src/components/widget/ToolbarPaneItem.js @@ -15,8 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ToolbarItem = require('./ToolbarItem').default; -const FloatingTip = require('./FloatingTip').default; +import ToolbarItem from './ToolbarItem'; +import FloatingTip from './FloatingTip'; const ToolbarPaneItem = new Class({ Extends: ToolbarItem, diff --git a/packages/mindplot/lib/components/widget/TopicShapePanel.js b/packages/mindplot/src/components/widget/TopicShapePanel.js similarity index 96% rename from packages/mindplot/lib/components/widget/TopicShapePanel.js rename to packages/mindplot/src/components/widget/TopicShapePanel.js index 23d5cc15..a706fbd2 100644 --- a/packages/mindplot/lib/components/widget/TopicShapePanel.js +++ b/packages/mindplot/src/components/widget/TopicShapePanel.js @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const ListToolbarPanel = require('./ListToolbarPanel').default; +import ListToolbarPanel from './ListToolbarPanel'; const TopicShapePanel = new Class({ Extends: ListToolbarPanel, diff --git a/packages/mindplot/lib/components/widget/colorPalette.css b/packages/mindplot/src/components/widget/colorPalette.css similarity index 100% rename from packages/mindplot/lib/components/widget/colorPalette.css rename to packages/mindplot/src/components/widget/colorPalette.css diff --git a/packages/mindplot/lib/components/widget/colorPalette.html b/packages/mindplot/src/components/widget/colorPalette.html similarity index 100% rename from packages/mindplot/lib/components/widget/colorPalette.html rename to packages/mindplot/src/components/widget/colorPalette.html diff --git a/packages/mindplot/src/components/widget/index.js b/packages/mindplot/src/components/widget/index.js new file mode 100644 index 00000000..f498c470 --- /dev/null +++ b/packages/mindplot/src/components/widget/index.js @@ -0,0 +1,37 @@ +import colorPalettePanel from './ColorPalettePanel'; +import floatingTip from './FloatingTip'; +import fontFamilyPanel from './FontFamilyPanel'; +import fontSizePanel from './FontSizePanel'; +import iconPanel from './IconPanel'; +import iMenu from './IMenu'; +import keyboardShortcutTooltip from './KeyboardShortcutTooltip'; +import linkEditor from './LinkEditor'; +import linkIconTooltip from './LinkIconTooltip'; +import listToolbarPanel from './ListToolbarPanel'; +import menu from './Menu'; +import modalDialogNotifier from './ModalDialogNotifier'; +import noteEditor from './NoteEditor'; +import toolbarItem from './ToolbarItem'; +import toolbarNotifier from './ToolbarNotifier'; +import toolbarPanelItem from './ToolbarPaneItem'; +import topicShapePanel from './TopicShapePanel'; + +export default { + ColorPalettePanel: colorPalettePanel, + FloatingTip: floatingTip, + FontFamilyPanel: fontFamilyPanel, + FontSizePanel: fontSizePanel, + IconPanel: iconPanel, + IMenu: iMenu, + KeyboardShortcutTooltip: keyboardShortcutTooltip, + LinkEditor: linkEditor, + LinkIconTooltip: linkIconTooltip, + ListToolbarPanel: listToolbarPanel, + Menu: menu, + ModalDialogNotifier: modalDialogNotifier, + NoteEditor: noteEditor, + ToolbarItem: toolbarItem, + ToolbarNotifier: toolbarNotifier, + ToolbarPaneItem: toolbarPanelItem, + TopicShapePanel: topicShapePanel, +}; diff --git a/packages/mindplot/src/mindplot.js b/packages/mindplot/src/mindplot.js new file mode 100644 index 00000000..69ede71a --- /dev/null +++ b/packages/mindplot/src/mindplot.js @@ -0,0 +1,26 @@ +import '@libraries/mootools-core-1.4.5'; +import $ from '@libraries/jquery-2.1.0'; +import _ from '@libraries/underscore-min'; + +import coreJs from '@wisemapping/core-js'; + +import commands from '@commands'; +import layout from '@layout'; +import models from '@model'; +import persistence from '@persistence'; +import widget from '@widget'; +import component from '@components'; + +global.$ = $; +global.JQuery = $; +global._ = _; +global.core = coreJs(); + +export default { + commands, + layout, + models, + persistence, + widget, + ...component, +}; diff --git a/packages/mindplot/test/playground/BalancedTestSuite.js b/packages/mindplot/test/playground/BalancedTestSuite.js deleted file mode 100644 index 6ee10063..00000000 --- a/packages/mindplot/test/playground/BalancedTestSuite.js +++ /dev/null @@ -1,500 +0,0 @@ -/* - * Copyright [2015] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * 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. - */ -const TestSuite = require('./TestSuite').default; - -const Mindplot = require('../../lib/mindplot'); -const mindplot = Mindplot(); - -const BalancedTestSuite = new Class({ - Extends: TestSuite, - - initialize: function () { - $('#balancedTest').css('display', 'block'); - - this.testBalanced(); - this.testBalancedPredict(); - this.testBalancedNodeDragPredict(); - }, - - testBalanced: function () { - console.log('testBalanced:'); - var position = { x: 0, y: 0 }; - var plotsize = { width: 1000, height: 200 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 1, 0); - manager.layout(); - manager.plot('testBalanced1', plotsize); - - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 2, 1); - manager.layout(); - manager.plot('testBalanced2', plotsize); - - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 3, 2); - manager.layout(); - manager.plot('testBalanced3', plotsize); - - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 4, 3); - manager.layout(); - manager.plot('testBalanced4', plotsize); - - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 5, 4); - manager.layout(); - manager.plot('testBalanced5', plotsize); - - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 6, 5); - manager.layout(); - manager.plot('testBalanced6', plotsize); - - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - manager.connectNode(3, 7, 0); - manager.connectNode(7, 8, 0); - manager.connectNode(7, 9, 1); - manager.layout(); - manager.plot('testBalanced7', plotsize); - - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - manager.addNode(12, TestSuite.NODE_SIZE, position); - manager.connectNode(6, 10, 0); - manager.connectNode(10, 11, 0); - manager.connectNode(10, 12, 1); - manager.layout(); - manager.plot('testBalanced8', plotsize); - - manager.addNode(13, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 13, 4); - manager.layout(); - manager.plot('testBalanced9', { width: 1000, height: 400 }); - - // Check orders have shifted accordingly - $assert(manager.find(5).getOrder() == 6, 'Node 5 should have order 6'); - - manager.addNode(14, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 14, 5); - manager.layout(); - manager.plot('testBalanced10', { width: 1000, height: 400 }); - - // Check orders have shifted accordingly - $assert(manager.find(6).getOrder() == 7, 'Node 6 should have order 7'); - - manager.addNode(15, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 15, 4); - manager.layout(); - manager.plot('testBalanced11', { width: 1000, height: 400 }); - - // Check orders have shifted accordingly - $assert(manager.find(13).getOrder() == 6, 'Node 13 should have order 6'); - $assert(manager.find(5).getOrder() == 8, 'Node 5 should have order 8'); - - manager.addNode(16, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 16, 25); - manager.layout(); - manager.plot('testBalanced12', { width: 1000, height: 400 }); - - // Check orders have shifted accordingly - $assert(manager.find(16).getOrder() == 9, 'Node 16 should have order 9'); - - manager.addNode(17, TestSuite.NODE_SIZE, position); - manager.addNode(18, TestSuite.NODE_SIZE, position); - manager.addNode(19, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 17, 11); - manager.connectNode(0, 18, 13); - manager.connectNode(0, 19, 10); - manager.layout(); - manager.plot('testBalanced13', { width: 1000, height: 400 }); - - // Check that everything is ok - $assert( - manager.find(1).getPosition().x > manager.find(0).getPosition().x, - 'even order nodes must be at right of central topic' - ); - $assert( - manager.find(3).getPosition().x > manager.find(0).getPosition().x, - 'even order nodes must be at right of central topic' - ); - $assert( - manager.find(5).getPosition().x > manager.find(0).getPosition().x, - 'even order nodes must be at right of central topic' - ); - $assert( - manager.find(2).getPosition().x < manager.find(0).getPosition().x, - 'odd order nodes must be at right of central topic' - ); - $assert( - manager.find(4).getPosition().x < manager.find(0).getPosition().x, - 'odd order nodes must be at right of central topic' - ); - $assert( - manager.find(6).getPosition().x < manager.find(0).getPosition().x, - 'odd order nodes must be at right of central topic' - ); - $assert( - manager.find(7).getPosition().x > manager.find(3).getPosition().x, - 'children of 1st level even order nodes must be to the right' - ); - $assert( - manager.find(8).getPosition().x > manager.find(7).getPosition().x, - 'children of 1st level even order nodes must be to the right' - ); - $assert( - manager.find(9).getPosition().x > manager.find(7).getPosition().x, - 'children of 1st level even order nodes must be to the right' - ); - $assert( - manager.find(10).getPosition().x < manager.find(6).getPosition().x, - 'children of 1st level odd order nodes must be to the left' - ); - $assert( - manager.find(11).getPosition().x < manager.find(10).getPosition().x, - 'children of 1st level odd order nodes must be to the left' - ); - $assert( - manager.find(12).getPosition().x < manager.find(10).getPosition().x, - 'children of 1st level odd order nodes must be to the left' - ); - - console.log('OK!\n\n'); - }, - - testBalancedPredict: function () { - console.log('testBalancedPredict:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - - manager.connectNode(0, 1, 0); - manager.connectNode(0, 2, 1); - manager.connectNode(0, 3, 2); - manager.connectNode(0, 4, 3); - manager.connectNode(0, 5, 4); - manager.connectNode(4, 7, 0); - manager.connectNode(4, 8, 1); - manager.connectNode(8, 9, 0); - manager.connectNode(3, 10, 0); - manager.connectNode(3, 11, 1); - - manager.layout(); - - // Graph 1 - var graph1 = manager.plot('testBalancedPredict1', { width: 1000, height: 400 }); - - console.log('\tAdded as child of node 0 and dropped at (165, -70):'); - var prediction1a = manager.predict(0, null, { x: 165, y: -70 }); - this._plotPrediction(graph1, prediction1a); - $assert( - prediction1a.position.y < manager.find(1).getPosition().y && - prediction1a.position.x == manager.find(1).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1a.order == 0, 'Prediction order should be 0'); - - console.log('\tAdded as child of node 0 and dropped at (165, -10):'); - var prediction1b = manager.predict(0, null, { x: 165, y: -10 }); - this._plotPrediction(graph1, prediction1b); - $assert( - prediction1b.position.y > manager.find(1).getPosition().y && - prediction1b.position.y < manager.find(3).getPosition().y && - prediction1b.position.x == manager.find(1).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1b.order == 2, 'Prediction order should be 2'); - - console.log('\tAdded as child of node 0 and dropped at (145, 15):'); - var prediction1c = manager.predict(0, null, { x: 145, y: 15 }); - this._plotPrediction(graph1, prediction1c); - $assert( - prediction1c.position.y > manager.find(3).getPosition().y && - prediction1c.position.y < manager.find(5).getPosition().y && - prediction1c.position.x == manager.find(3).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1c.order == 4, 'Prediction order should be 4'); - - console.log('\tAdded as child of node 0 and dropped at (145, 70):'); - var prediction1d = manager.predict(0, null, { x: 145, y: 70 }); - this._plotPrediction(graph1, prediction1d); - $assert( - prediction1d.position.y > manager.find(5).getPosition().y && - prediction1d.position.x == manager.find(5).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1d.order == 6, 'Prediction order should be 6'); - - // Graph 2 - var graph2 = manager.plot('testBalancedPredict2', { width: 1000, height: 400 }); - - console.log('\tAdded as child of node 0 and dropped at (-145, -50):'); - var prediction2a = manager.predict(0, null, { x: -145, y: -50 }); - this._plotPrediction(graph2, prediction2a); - $assert( - prediction2a.position.y < manager.find(2).getPosition().y && - prediction2a.position.x == manager.find(2).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction2a.order == 1, 'Prediction order should be 1'); - - console.log('\tAdded as child of node 0 and dropped at (-145, -10):'); - var prediction2b = manager.predict(0, null, { x: -145, y: -10 }); - this._plotPrediction(graph2, prediction2b); - $assert( - prediction2b.position.y > manager.find(2).getPosition().y && - prediction2b.position.y < manager.find(4).getPosition().y && - prediction2b.position.x == manager.find(2).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction2b.order == 3, 'Prediction order should be 3'); - - console.log('\tAdded as child of node 0 and dropped at (-145, 40):'); - var prediction2c = manager.predict(0, null, { x: -145, y: 400 }); - this._plotPrediction(graph2, prediction2c); - $assert( - prediction2c.position.y > manager.find(4).getPosition().y && - prediction2c.position.x == manager.find(4).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction2c.order == 5, 'Prediction order should be 5'); - - // Graph 3 - console.log('\tPredict nodes added with no position:'); - var graph3 = manager.plot('testBalancedPredict3', { width: 1000, height: 400 }); - var prediction3 = manager.predict(0, null, null); - this._plotPrediction(graph3, prediction3); - $assert( - prediction3.position.y > manager.find(4).getPosition().y && - prediction3.position.x == manager.find(4).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction3.order == 5, 'Prediction order should be 5'); - - console.log('\tPredict nodes added with no position:'); - manager.addNode(6, TestSuite.NODE_SIZE, prediction3.position); - manager.connectNode(0, 6, prediction3.order); - manager.layout(); - var graph4 = manager.plot('testBalancedPredict4', { width: 1000, height: 400 }); - var prediction4 = manager.predict(0, null, null); - this._plotPrediction(graph4, prediction4); - $assert( - prediction4.position.y > manager.find(5).getPosition().y && - prediction4.position.x == manager.find(5).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction4.order == 6, 'Prediction order should be 6'); - - console.log('\tPredict nodes added only a root node:'); - manager.removeNode(1).removeNode(2).removeNode(3).removeNode(4).removeNode(5); - manager.layout(); - var graph5 = manager.plot('testBalancedPredict5', { width: 1000, height: 400 }); - var prediction5a = manager.predict(0, null, null); - var prediction5b = manager.predict(0, null, { x: 40, y: 100 }); - this._plotPrediction(graph5, prediction5a); - this._plotPrediction(graph5, prediction5b); - $assert( - prediction5a.position.x > manager.find(0).getPosition().x && - prediction5a.position.y == manager.find(0).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction5a.order == 0, 'Prediction order should be 0'); - $assert( - prediction5a.position.x == prediction5b.position.x && - prediction5a.position.y == prediction5b.position.y, - 'Both predictions should be the same' - ); - $assert(prediction5a.order == prediction5b.order, 'Both predictions should be the same'); - - console.log('OK!\n\n'); - }, - - testBalancedNodeDragPredict: function () { - console.log('testBalancedNodeDragPredict:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Graph 1 - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.layout(); - var graph1 = manager.plot('testBalancedNodeDragPredict1', { width: 800, height: 400 }); - - var prediction1a = manager.predict(0, 1, { x: 50, y: 50 }); - this._plotPrediction(graph1, prediction1a); - $assert( - prediction1a.position.x == manager.find(1).getPosition().x && - prediction1a.position.y == manager.find(1).getPosition().y, - 'Prediction position should be the same as node 1' - ); - $assert( - prediction1a.order == manager.find(1).getOrder(), - 'Prediction order should be the same as node 1' - ); - - var prediction1b = manager.predict(0, 1, { x: 50, y: -50 }); - this._plotPrediction(graph1, prediction1b); - $assert( - prediction1b.position.x == manager.find(1).getPosition().x && - prediction1b.position.y == manager.find(1).getPosition().y, - 'Prediction position should be the same as node 1' - ); - $assert( - prediction1b.order == manager.find(1).getOrder(), - 'Prediction order should be the same as node 1' - ); - - var prediction1c = manager.predict(0, 1, { x: -50, y: 50 }); - this._plotPrediction(graph1, prediction1c); - $assert( - prediction1c.position.x < manager.find(0).getPosition().x && - prediction1c.position.y == manager.find(0).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1c.order == 1, 'Prediction order should be the same as node 1'); - - var prediction1d = manager.predict(0, 1, { x: -50, y: -50 }); - this._plotPrediction(graph1, prediction1d); - $assert( - prediction1d.position.x < manager.find(0).getPosition().x && - prediction1d.position.y == manager.find(0).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1d.order == 1, 'Prediction order should be the same as node 1'); - - // Graph 2 - manager.disconnectNode(1); - manager.connectNode(0, 1, 1); - manager.layout(); - var graph2 = manager.plot('testBalancedNodeDragPredict2', { width: 800, height: 400 }); - - var prediction2a = manager.predict(0, 1, { x: 50, y: 50 }); - this._plotPrediction(graph2, prediction2a); - $assert( - prediction2a.position.x > manager.find(0).getPosition().x && - prediction2a.position.y == manager.find(0).getPosition().y, - 'Prediction is positioned incorrectly' - ); - $assert(prediction2a.order == 0, 'Prediction order should be 0'); - - var prediction2b = manager.predict(0, 1, { x: 50, y: -50 }); - this._plotPrediction(graph2, prediction2b); - $assert( - prediction2b.position.x > manager.find(0).getPosition().x && - prediction2b.position.y == manager.find(0).getPosition().y, - 'Prediction is positioned incorrectly' - ); - $assert(prediction2b.order == 0, 'Prediction order should be 0'); - - var prediction2c = manager.predict(0, 1, { x: -50, y: 50 }); - this._plotPrediction(graph2, prediction2c); - $assert( - prediction2c.position.x == manager.find(1).getPosition().x && - prediction2c.position.y == manager.find(1).getPosition().y, - 'Prediction position should be the same as node 1' - ); - $assert( - prediction2c.order == manager.find(1).getOrder(), - 'Prediction order should be the same as node 1' - ); - - var prediction2d = manager.predict(0, 1, { x: -50, y: -50 }); - this._plotPrediction(graph2, prediction2d); - $assert( - prediction2d.position.x == manager.find(1).getPosition().x && - prediction2d.position.y == manager.find(1).getPosition().y, - 'Prediction position should be the same as node 1' - ); - $assert( - prediction2d.order == manager.find(1).getOrder(), - 'Prediction order should be the same as node 1' - ); - - // Graph 3 - manager.disconnectNode(1); - manager.connectNode(0, 1, 0); - manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2); - manager.layout(); - var graph3 = manager.plot('testBalancedNodeDragPredict3', { width: 800, height: 400 }); - - var prediction3a = manager.predict(0, 1, { x: 50, y: 50 }); - this._plotPrediction(graph3, prediction3a); - $assert( - prediction3a.position.x == manager.find(2).getPosition().x && - prediction3a.position.y > manager.find(2).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction3a.order == 4, 'Prediction order should be 4'); - - var prediction3b = manager.predict(0, 1, { x: 50, y: -50 }); - this._plotPrediction(graph3, prediction3b); - $assert( - prediction3b.position.x == manager.find(1).getPosition().x && - prediction3b.position.y == manager.find(1).getPosition().y && - prediction3b.order == manager.find(1).getOrder(), - 'Prediction should be the exact same as dragged node' - ); - - var prediction3c = manager.predict(0, 1, { x: -50, y: 50 }); - this._plotPrediction(graph3, prediction3c); - $assert( - prediction3c.position.x < manager.find(0).getPosition().x && - prediction3c.position.y == manager.find(0).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction3c.order == 1, 'Prediction order should be 1'); - - var prediction3d = manager.predict(0, 1, { x: -50, y: -50 }); - this._plotPrediction(graph3, prediction3d); - $assert( - prediction3d.position.x < manager.find(0).getPosition().x && - prediction3d.position.y == manager.find(0).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction3d.order == 1, 'Prediction order should be 1'); - - var prediction3e = manager.predict(0, 1, { x: 50, y: 0 }); - this._plotPrediction(graph3, prediction3e); - $assert( - prediction3e.position.x == manager.find(1).getPosition().x && - prediction3e.position.y == manager.find(1).getPosition().y, - 'Prediction position should be the same as node 1' - ); - $assert( - prediction3e.order == manager.find(1).getOrder(), - 'Prediction order should be the same as node 1' - ); - - console.log('OK!\n\n'); - }, -}); - -export default BalancedTestSuite; diff --git a/packages/mindplot/test/playground/FreeTestSuite.js b/packages/mindplot/test/playground/FreeTestSuite.js deleted file mode 100644 index 25ba6484..00000000 --- a/packages/mindplot/test/playground/FreeTestSuite.js +++ /dev/null @@ -1,558 +0,0 @@ -/* - * Copyright [2015] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * 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. - */ -const TestSuite = require('./TestSuite').default; -const Mindplot = require('../../lib/mindplot'); -const mindplot = Mindplot(); - -const FreeTestSuite = new Class({ - Extends: TestSuite, - - initialize: function () { - $('#freeTest').css('display', 'block'); - - this.testFreePosition(); - this.testFreePredict(); - this.testReconnectFreeNode(); - this.testSiblingOverlapping(); - this.testRootNodeChildrenPositioning(); - this.testBalancedFreePredict(); - this.testFreeReorder(); - this.testFreeOverlap(); - }, - - testFreePosition: function () { - console.log('testFreePosition:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - manager.addNode(12, TestSuite.NODE_SIZE, position); - manager.addNode(13, TestSuite.NODE_SIZE, position); - manager.addNode(14, TestSuite.NODE_SIZE, position); - manager.addNode(15, TestSuite.NODE_SIZE, position); - manager.addNode(16, TestSuite.NODE_SIZE, position); - manager.addNode(17, TestSuite.NODE_SIZE, position); - manager.addNode(18, TestSuite.NODE_SIZE, position); - manager.addNode(19, TestSuite.NODE_SIZE, position); - manager.addNode(20, TestSuite.NODE_SIZE, position); - manager.addNode(21, TestSuite.NODE_SIZE, position); - manager.addNode(22, TestSuite.NODE_SIZE, position); - - manager.connectNode(0, 1, 0).connectNode(0, 2, 1).connectNode(0, 3, 2).connectNode(0, 4, 3); - manager.connectNode(4, 21, 0).connectNode(4, 22, 0); - manager.connectNode(1, 5, 0); - manager.connectNode(5, 6, 0).connectNode(6, 8, 0).connectNode(8, 9, 0); - manager.connectNode(5, 7, 1).connectNode(7, 10, 0); - manager - .connectNode(3, 11, 0) - .connectNode(11, 14, 0) - .connectNode(14, 18, 0) - .connectNode(14, 19, 1) - .connectNode(14, 20, 2); - manager - .connectNode(3, 12, 1) - .connectNode(12, 15, 0) - .connectNode(12, 16, 1) - .connectNode(12, 17, 2); - manager.connectNode(3, 13, 2); - - manager.layout(); - manager.plot('testFreePosition1', { width: 1400, height: 600 }); - - console.log('\tmove node 12 to (300,30):'); - manager.moveNode(12, { x: 300, y: 30 }); - manager.layout(true); - manager.plot('testFreePosition2', { width: 1400, height: 600 }); - this._assertFreePosition(manager, 12, { x: 300, y: 30 }); - - console.log('\tmove node 13 to (340,180):'); - var node13Pos = { x: 340, y: 180 }; - manager.moveNode(13, node13Pos); - manager.layout(true); - manager.plot('testFreePosition3', { width: 1400, height: 600 }); - this._assertFreePosition(manager, 13, node13Pos); - - console.log('\tmove node 11 to (250,-50):'); - manager.moveNode(11, { x: 250, y: -50 }); - manager.layout(true); - manager.plot('testFreePosition4', { width: 1400, height: 600 }); - this._assertFreePosition(manager, 11, { x: 250, y: -50 }); - $assert( - manager.find(13).getPosition().x == node13Pos.x && - manager.find(13).getPosition().y == node13Pos.y, - "Node 13 shouldn't have moved" - ); - - console.log('\tmove node 7 to (350,-190):'); - manager.moveNode(7, { x: 350, y: -190 }); - manager.layout(true); - manager.plot('testFreePosition5', { width: 1400, height: 600 }); - this._assertFreePosition(manager, 7, { x: 350, y: -190 }); - - console.log('\tadd node 23 to 12:'); - manager.addNode(23, TestSuite.NODE_SIZE, position); - manager.connectNode(12, 23, 3); - manager.layout(true); - manager.plot('testFreePosition6', { width: 1400, height: 600 }); - this._assertFreePosition(manager, null, null); - - console.log('\tmove node 4 to (-300, 190):'); - manager.moveNode(4, { x: -300, y: 190 }); - manager.layout(true); - manager.plot('testFreePosition7', { width: 1400, height: 600 }); - this._assertFreePosition(manager, 4, { x: -300, y: 190 }); - - console.log('\tadd node 24 to 3:'); - manager.addNode(24, TestSuite.NODE_SIZE, position); - manager.connectNode(3, 24, 3); - manager.layout(true); - manager.plot('testFreePosition8', { width: 1400, height: 600 }); - this._assertFreePosition(manager, null, null); - - console.log('\tadd node 25 to 17:'); - manager.addNode(25, TestSuite.NODE_SIZE, position); - manager.connectNode(17, 25, 0); - manager.layout(true); - manager.plot('testFreePosition9', { width: 1400, height: 600 }); - this._assertFreePosition(manager, null, null); - - console.log('OK!\n\n'); - }, - - testFreePredict: function () { - console.log('testFreePredict:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - - manager.connectNode(0, 1, 0); - manager.connectNode(0, 2, 1); - manager.connectNode(0, 3, 2); - manager.connectNode(3, 4, 0); - manager.connectNode(3, 5, 1); - manager.connectNode(3, 6, 2); - manager.connectNode(5, 7, 0); - manager.connectNode(5, 8, 1); - manager.connectNode(5, 11, 2); - manager.connectNode(2, 9, 0); - manager.connectNode(2, 10, 1); - - manager.layout(); - var graph = manager.plot('testFreePredict1', { width: 1000, height: 400 }); - - var pos1 = { x: 370, y: 80 }; - var predict1 = manager.predict(5, 11, pos1, true); - this._plotPrediction(graph, predict1); - $assert( - predict1.position.x == pos1.x && predict1.position.y == pos1.y, - 'free predict should return the same position' - ); - - var pos2 = { x: -200, y: 80 }; - var predict2 = manager.predict(0, 2, pos2, true); - this._plotPrediction(graph, predict2); - $assert( - predict2.position.x == pos2.x && predict2.position.y == pos2.y, - 'free predict should return the same position' - ); - - var pos3 = { x: 200, y: 30 }; - var node5 = manager.find(5); - var predict3 = manager.predict(3, 5, pos3, true); - this._plotPrediction(graph, predict3); - $assert( - predict3.position.x == node5.getPosition().x && predict3.position.y == pos3.y, - 'free predict should return the x-coordinate of the node' - ); - - var pos4 = { x: -100, y: 45 }; - var node10 = manager.find(10); - var predict4 = manager.predict(2, 10, pos4, true); - this._plotPrediction(graph, predict4); - $assert( - predict4.position.x == node10.getPosition().x && predict4.position.y == pos4.y, - 'free predict should return the x-coordinate of the node' - ); - - console.log('OK!\n\n'); - }, - - testReconnectFreeNode: function () { - console.log('testReconnectFreeNode:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - - manager.connectNode(0, 1, 0); - manager.connectNode(0, 2, 1); - manager.connectNode(0, 3, 2); - manager.connectNode(3, 4, 0); - manager.connectNode(3, 5, 1); - manager.connectNode(3, 6, 2); - manager.connectNode(5, 7, 0); - manager.connectNode(5, 8, 1); - manager.connectNode(5, 11, 2); - manager.connectNode(2, 9, 0); - manager.connectNode(2, 10, 1); - - manager.layout(); - manager.plot('testReconnectFreeNode1', { width: 1000, height: 400 }); - - console.log('\tmove node 5'); - manager.moveNode(5, { x: 250, y: 30 }); - manager.layout(); - manager.plot('testReconnectFreeNode2', { width: 1000, height: 400 }); - this._assertFreePosition(manager, 5, { x: 250, y: 30 }); - - console.log('\treconnect node 5 to node 2'); - manager.disconnectNode(5); - manager.connectNode(2, 5, 2); - manager.layout(); - manager.plot('testReconnectFreeNode3', { width: 1000, height: 400 }); - $assert( - manager.find(5).getPosition().y > manager.find(10).getPosition().y && - manager.find(5).getPosition().x == manager.find(10).getPosition().x, - 'Node 5 is incorrectly positioned' - ); - $assert(manager.find(5).getOrder() == 2, 'Node 5 should have order 2'); - - console.log('\tmove node 8'); - manager.moveNode(8, { x: -370, y: 60 }); - manager.layout(); - manager.plot('testReconnectFreeNode4', { width: 1000, height: 400 }); - this._assertFreePosition(manager, 8, { x: -370, y: 60 }); - - console.log('\treconnect node 5 to node 10'); - manager.disconnectNode(5); - manager.connectNode(10, 5, 0); - manager.layout(); - manager.plot('testReconnectFreeNode5', { width: 1000, height: 400 }); - $assert( - manager.find(5).getPosition().y == manager.find(10).getPosition().y && - manager.find(5).getPosition().x < manager.find(10).getPosition().x, - 'Node 5 is incorrectly positioned' - ); - $assert(manager.find(5).getOrder() == 0, 'Node 5 should have order 0'); - - console.log('reconnect node 5 to node 3'); - manager.disconnectNode(5); - manager.connectNode(3, 5, 2); - manager.layout(); - manager.plot('testReconnectFreeNode6', { width: 1000, height: 400 }); - $assert( - manager.find(5).getPosition().y > manager.find(6).getPosition().y && - manager.find(5).getPosition().x == manager.find(6).getPosition().x, - 'Node 5 is incorrectly positioned' - ); - $assert(manager.find(5).getOrder() == 2, 'Node 5 should have order 2'); - - console.log('\tmove node 8'); - manager.moveNode(8, { x: 370, y: 30 }); - manager.layout(); - manager.plot('testReconnectFreeNode7', { width: 1000, height: 400 }); - this._assertFreePosition(manager, 8, { x: 370, y: 30 }); - - console.log('OK!\n\n'); - }, - - testSiblingOverlapping: function () { - console.log('testSiblingOverlapping:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0); - manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(1, 3, 1); - manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 2); - manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 3); - manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 4); - manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(1, 7, 5); - manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(1, 8, 6); - manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(0, 9, 4); - manager.layout(); - manager.plot('testSiblingOverlapping1', { width: 800, height: 600 }); - - console.log('\tmove node 2'); - manager.moveNode(2, { x: 250, y: -30 }); - manager.layout(); - manager.plot('testSiblingOverlapping2', { width: 800, height: 600 }); - this._assertFreePosition(manager, 2, { x: 250, y: -30 }); - - console.log('\tmove node 7'); - manager.moveNode(7, { x: 250, y: 100 }); - manager.layout(); - manager.plot('testSiblingOverlapping3', { width: 800, height: 600 }); - this._assertFreePosition(manager, 7, { x: 250, y: 100 }); - - console.log('OK!\n\n'); - }, - - testRootNodeChildrenPositioning: function () { - console.log('testRootNodeChildrenPositioning:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 1); - manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 2); - manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(0, 4, 3); - manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(0, 5, 4); - manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(0, 6, 5); - manager.layout(); - manager.plot('testRootNodeChildrenPositioning1', { width: 800, height: 600 }); - - console.log('\tmove node 1'); - manager.moveNode(1, { x: 150, y: 0 }); - manager.layout(); - manager.plot('testRootNodeChildrenPositioning2', { width: 800, height: 600 }); - this._assertFreePosition(manager, 1, { x: 150, y: 0 }); - - console.log('\tmove node 4'); - manager.moveNode(4, { x: -140, y: 30 }); - manager.layout(); - manager.plot('testRootNodeChildrenPositioning3', { width: 800, height: 600 }); - this._assertFreePosition(manager, 4, { x: -140, y: 30 }); - - console.log('\tmove node 2'); - manager.moveNode(2, { x: -150, y: -50 }); - manager.layout(); - manager.plot('testRootNodeChildrenPositioning4', { width: 800, height: 600 }); - this._assertFreePosition(manager, 2, { x: -150, y: -50 }); - - //TODO(gb): fix this. It's not working - // console.log("\tmove node 6"); - // manager.moveNode(6, {x:-150, y:-50}); - // manager.layout(); - // manager.plot("testRootNodeChildrenPositioning5", {width:800, height:600}); - // this._assertFreePosition(manager, 6, {x:-150, y:-50}); - - console.log('OK!\n\n'); - }, - - testBalancedFreePredict: function () { - console.log('testBalancedFreePredict:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.layout(); - var graph1 = manager.plot('testBalancedFreePredict1', { width: 800, height: 400 }); - - var predict1 = manager.predict(0, 1, { x: 70, y: 0 }, true); - this._plotPrediction(graph1, predict1); - $assert( - predict1.position.x == manager.find(1).getPosition().x, - 'Prediction x pos should be the same as node 1' - ); - - console.log('OK!\n\n'); - }, - - testFreeReorder: function () { - console.log('testFreeReorder:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 0); - manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 1); - manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 2); - - manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2); - manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(2, 7, 0); - manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(2, 8, 1); - manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(2, 9, 2); - manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(2, 10, 3); - - manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 4); - manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(3, 11, 0); - manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(3, 12, 1); - manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(3, 13, 2); - manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(3, 14, 3); - manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(3, 15, 4); - manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(3, 16, 5); - - manager.layout(); - manager.moveNode(14, { x: 270, y: -160 }); - manager.layout(); - manager.plot('testFreeReorder1', { width: 800, height: 1200 }); - $assert( - manager.find(14).getPosition().y > manager.find(10).getPosition().y, - 'Node 14 should be below branch 2' - ); - - console.log('OK!\n\n'); - }, - - testFreeOverlap: function () { - console.log('testFreeOverlap:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 0); - manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 1); - manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 2); - - manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2); - manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(2, 7, 0); - manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(2, 8, 1); - manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(2, 9, 2); - manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(2, 10, 3); - - manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 4); - manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(3, 11, 0); - manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(3, 12, 1); - manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(3, 13, 2); - manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(3, 14, 3); - manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(3, 15, 4); - manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(3, 16, 5); - - manager.layout(); - manager.plot('testFreeOverlap1', { width: 800, height: 1200 }); - - manager.moveNode(14, { x: 270, y: 7 }); - manager.layout(); - manager.plot('testFreeOverlap2', { width: 800, height: 1200 }); - $assert( - manager.find(2).getPosition().y > manager.find(1).getPosition().y, - 'Branches 1 and 2 are overlapping' - ); - - console.log('OK!\n\n'); - }, - - _assertFreePosition: function (manager, id, position) { - if (id != null && position.x != null && position.y != null) { - var node = manager.find(id); - $assert( - node.getPosition().x == position.x && node.getPosition().y == position.y, - 'Freely moved node ' + - id + - ' is not left at free position (' + - position.x + - ',' + - position.y + - '). ' + - 'Actual position: (' + - node.getPosition().x + - ',' + - node.getPosition().y + - ')' - ); - } - - var treeSet = manager._treeSet; - _.each( - treeSet._rootNodes, - function (rootNode) { - var heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode); - this._assertBranchCollision(treeSet, rootNode, heightById); - }, - this - ); - }, - - _assertBranchCollision: function (treeSet, node, heightById) { - var children = treeSet.getChildren(node); - var childOfRootNode = treeSet._rootNodes.contains(node); - - _.each( - children, - function (child) { - var height = heightById[child.getId()]; - var siblings = treeSet.getSiblings(child); - if (childOfRootNode) { - siblings = siblings.filter(function (sibling) { - return child.getOrder() % 2 == sibling.getOrder() % 2; - }); - } - _.each( - siblings, - function (sibling) { - this._branchesOverlap(child, sibling, heightById); - }, - this - ); - }, - this - ); - - _.each( - children, - function (child) { - this._assertBranchCollision(treeSet, child, heightById); - }, - this - ); - }, - - _branchesOverlap: function (branchA, branchB, heightById) { - var topA = branchA.getPosition().y - heightById[branchA.getId()] / 2; - var bottomA = branchA.getPosition().y + heightById[branchA.getId()] / 2; - var topB = branchB.getPosition().y - heightById[branchB.getId()] / 2; - var bottomB = branchB.getPosition().y + heightById[branchB.getId()] / 2; - - $assert( - topA >= bottomB || bottomA <= topB, - 'Branches ' + branchA.getId() + ' and ' + branchB.getId() + ' overlap' - ); - }, -}); - -export default FreeTestSuite; diff --git a/packages/mindplot/test/playground/SymmetricTestSuite.js b/packages/mindplot/test/playground/SymmetricTestSuite.js deleted file mode 100644 index a505ce6b..00000000 --- a/packages/mindplot/test/playground/SymmetricTestSuite.js +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright [2015] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * 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. - */ -const TestSuite = require('./TestSuite').default; -const Mindplot = require('../../lib/mindplot'); -const mindplot = Mindplot(); - -const SymmetricTestSuite = new Class({ - Extends: TestSuite, - - initialize: function () { - $('#symmetricTest').css('display', 'block'); - - this.testSymmetry(); - this.testSymmetricPredict(); - this.testSymmetricDragPredict(); - }, - - testSymmetry: function () { - console.log('testSymmetry:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - manager.addNode(12, TestSuite.NODE_SIZE, position); - manager.addNode(13, TestSuite.NODE_SIZE, position); - manager.addNode(14, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 14, 0); - manager.connectNode(14, 13, 0); - manager.connectNode(13, 1, 0); - manager.connectNode(13, 2, 1); - manager.connectNode(13, 3, 2); - manager.connectNode(13, 4, 3); - manager.connectNode(13, 5, 4); - manager.connectNode(1, 6, 0); - manager.connectNode(1, 7, 1); - manager.connectNode(7, 8, 0); - manager.connectNode(8, 9, 0); - manager.connectNode(5, 10, 0); - manager.connectNode(6, 11, 0); - manager.connectNode(6, 12, 1); - - manager.layout(); - manager.plot('testSymmetry', { width: 1600, height: 400 }); - - // All nodes should be positioned symmetrically with respect to their common ancestors - $assert( - manager.find(14).getPosition().y == manager.find(13).getPosition().y, - 'Symmetry is not respected' - ); - $assert( - manager.find(5).getPosition().y == manager.find(10).getPosition().y, - 'Symmetry is not respected' - ); - $assert( - manager.find(11).getPosition().y - manager.find(6).getPosition().y == - -(manager.find(12).getPosition().y - manager.find(6).getPosition().y), - 'Symmetry is not respected' - ); - $assert( - manager.find(8).getPosition().y - manager.find(1).getPosition().y == - -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), - 'Symmetry is not respected' - ); - $assert( - manager.find(9).getPosition().y - manager.find(1).getPosition().y == - -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), - 'Symmetry is not respected' - ); - - console.log('OK!\n\n'); - }, - - testSymmetricPredict: function () { - console.log('testSymmetricPredict:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - - manager.connectNode(0, 1, 0); - manager.connectNode(0, 2, 1); - manager.connectNode(0, 3, 2); - manager.connectNode(3, 4, 0); - manager.connectNode(3, 5, 1); - manager.connectNode(3, 6, 2); - manager.connectNode(5, 7, 0); - manager.connectNode(5, 8, 1); - manager.connectNode(5, 11, 2); - manager.connectNode(2, 9, 0); - manager.connectNode(2, 10, 1); - - manager.layout(); - - // Graph - var graph1 = manager.plot('testSymmetricPredict1', { width: 1000, height: 400 }); - - console.log('\tAdded as child of node 9 and dropped at (-280, 45):'); - var prediction1a = manager.predict(9, null, { x: -280, y: 45 }); - this._plotPrediction(graph1, prediction1a); - $assert( - prediction1a.position.x < manager.find(9).getPosition().x && - prediction1a.position.y == manager.find(9).getPosition().y, - 'Prediction incorrectly positioned' - ); - $assert(prediction1a.order == 0, 'Prediction order should be 0'); - - console.log('\tAdded as child of node 1 and dropped at (155, -90):'); - var prediction1b = manager.predict(1, null, { x: -155, y: -90 }); - this._plotPrediction(graph1, prediction1b); - $assert( - prediction1b.position.x > manager.find(1).getPosition().x && - prediction1b.position.y == manager.find(1).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1b.order == 0, 'Prediction order should be 0'); - - // Graph 2 - var graph2 = manager.plot('testSymmetricPredict2', { width: 1000, height: 400 }); - - console.log('\tAdded as child of node 5 and dropped at (380, -30):'); - var prediction2d = manager.predict(5, null, { x: 380, y: -30 }); - this._plotPrediction(graph2, prediction2d); - - // Prediction calculator error - $assert( - prediction2d.position.y < manager.find(7).getPosition().y && - prediction2d.position.x == manager.find(7).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction2d.order == 0, 'Prediction order should be 0'); - - console.log('\tAdded as child of node 5 and dropped at (375, 15):'); - var prediction2a = manager.predict(5, null, { x: 375, y: 15 }); - this._plotPrediction(graph2, prediction2a); - - $assert( - prediction2a.position.y > manager.find(7).getPosition().y && - prediction2a.position.y < manager.find(8).getPosition().y && - prediction2a.position.x == manager.find(7).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction2a.order == 1, 'Prediction order should be 1'); - - console.log('\tAdded as child of node 5 and dropped at (375, 45):'); - var prediction2b = manager.predict(5, null, { x: 375, y: 45 }); - this._plotPrediction(graph2, prediction2b); - $assert( - prediction2b.position.y > manager.find(8).getPosition().y && - prediction2b.position.y < manager.find(11).getPosition().y && - prediction2b.position.x == manager.find(7).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction2b.order == 2, 'Prediction order should be 2'); - - console.log('\tAdded as child of node 5 and dropped at (375, 45):'); - var prediction2c = manager.predict(5, null, { x: 375, y: 65 }); - this._plotPrediction(graph2, prediction2c); - $assert( - prediction2c.position.y > manager.find(11).getPosition().y && - prediction2c.position.x == manager.find(11).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction2c.order == 3, 'Prediction order should be 3'); - - // Graph 3 - var graph3 = manager.plot('testSymmetricPredict3', { width: 1000, height: 400 }); - - console.log('\tAdded as child of node 3 and dropped at (280, 45):'); - var prediction3a = manager.predict(3, null, { x: 280, y: 45 }); - this._plotPrediction(graph3, prediction3a); - $assert( - prediction3a.position.y > manager.find(5).getPosition().y && - prediction3a.position.y < manager.find(6).getPosition().y && - prediction3a.position.x == manager.find(5).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction3a.order == 2, 'Prediction order should be 2'); - - console.log('\tAdded as child of node 3 and dropped at (255, 110):'); - var prediction3b = manager.predict(3, null, { x: 255, y: 110 }); - this._plotPrediction(graph3, prediction3b); - $assert( - prediction3b.position.y > manager.find(6).getPosition().y && - prediction3b.position.x == manager.find(6).getPosition().x, - 'Prediction incorrectly positioned' - ); - $assert(prediction3b.order == 3, 'Prediction order should be 3'); - - // Graph 4 - console.log('\tAdded as child of node 2 and dropped at (-260, 0):'); - var graph4 = manager.plot('testSymmetricPredict4', { width: 1000, height: 400 }); - var prediction4 = manager.predict(2, null, { x: -260, y: 0 }); - this._plotPrediction(graph4, prediction4); - $assert( - prediction4.position.y > manager.find(9).getPosition().y && - prediction4.position.y < manager.find(10).getPosition().y && - prediction4.position.x == manager.find(9).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction4.order == 1, 'Prediction order should be 1'); - - // Graph 5 - console.log('\tPredict nodes added with no position:'); - var graph5 = manager.plot('testSymmetricPredict5', { width: 1000, height: 400 }); - var prediction5a = manager.predict(1, null, null); - this._plotPrediction(graph5, prediction5a); - $assert( - prediction5a.position.y == manager.find(1).getPosition().y && - prediction5a.position.x > manager.find(1).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction5a.order == 0, 'Prediction order should be 0'); - - var prediction5b = manager.predict(2, null, null); - this._plotPrediction(graph5, prediction5b); - $assert( - prediction5b.position.y > manager.find(10).getPosition().y && - prediction5b.position.x < manager.find(2).getPosition().x && - prediction5b.position.x == manager.find(10).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction5b.order == 2, 'Prediction order should be 2'); - - var prediction5c = manager.predict(3, null, null); - this._plotPrediction(graph5, prediction5c); - $assert( - prediction5c.position.y > manager.find(6).getPosition().y && - prediction5c.position.x > manager.find(3).getPosition().x && - prediction5c.position.x == manager.find(6).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction5c.order == 3, 'Prediction order should be 3'); - - var prediction5d = manager.predict(10, null, null); - this._plotPrediction(graph5, prediction5d); - $assert( - prediction5d.position.y == manager.find(10).getPosition().y && - prediction5d.position.x < manager.find(10).getPosition().x, - 'Prediction is incorrectly positioned' - ); - $assert(prediction5d.order == 0, 'Prediction order should be 0'); - - console.log('OK!\n\n'); - }, - - testSymmetricDragPredict: function () { - console.log('testSymmetricDragPredict:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1); - manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0); - manager.layout(); - - // Graph 1 - var graph1 = manager.plot('testSymmetricDragPredict1', { width: 1000, height: 400 }); - - var prediction1a = manager.predict(1, 2, { x: -250, y: -20 }); - this._plotPrediction(graph1, prediction1a); - $assert( - prediction1a.position.x == manager.find(2).getPosition().x && - prediction1a.position.y == manager.find(2).getPosition().y, - 'Prediction position should be the same as node 2' - ); - $assert( - prediction1a.order == manager.find(2).getOrder(), - 'Predicition order should be the same as node 2' - ); - - var prediction1b = manager.predict(1, 2, { x: -250, y: 20 }); - this._plotPrediction(graph1, prediction1b); - $assert( - prediction1b.position.x == manager.find(2).getPosition().x && - prediction1b.position.y == manager.find(2).getPosition().y, - 'Prediction position should be the same as node 2' - ); - $assert( - prediction1b.order == manager.find(2).getOrder(), - 'Predicition order should be the same as node 2' - ); - - var prediction1c = manager.predict(0, 2, { x: -100, y: -20 }); - this._plotPrediction(graph1, prediction1c); - $assert( - prediction1c.position.x == manager.find(1).getPosition().x && - prediction1c.position.y < manager.find(1).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1c.order == 1, 'Prediction order should be 1'); - - var prediction1d = manager.predict(0, 2, { x: -100, y: 20 }); - this._plotPrediction(graph1, prediction1d); - $assert( - prediction1d.position.x == manager.find(1).getPosition().x && - prediction1d.position.y > manager.find(1).getPosition().y, - 'Prediction is incorrectly positioned' - ); - $assert(prediction1d.order == 3, 'Prediction order should be 3'); - - var prediction1e = manager.predict(1, 2, { x: -250, y: 0 }); - this._plotPrediction(graph1, prediction1e); - $assert( - prediction1e.position.x == manager.find(2).getPosition().x && - prediction1e.position.y == manager.find(2).getPosition().y, - 'Prediction position should be the same as node 2' - ); - $assert( - prediction1e.order == manager.find(2).getOrder(), - 'Predicition order should be the same as node 2' - ); - - console.log('OK!\n\n'); - }, -}); - -export default SymmetricTestSuite; diff --git a/packages/mindplot/test/playground/TestSuite.js b/packages/mindplot/test/playground/TestSuite.js deleted file mode 100644 index 963af45b..00000000 --- a/packages/mindplot/test/playground/TestSuite.js +++ /dev/null @@ -1,589 +0,0 @@ -/* - * Copyright [2015] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * 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. - */ -const Mindplot = require('../../lib/mindplot'); -const mindplot = Mindplot(); - -const TestSuite = new Class({ - Extends: mindplot.layout.ChildrenSorterStrategy, - - initialize: function () { - $('#basicTest').css('display', 'block'); - // this.testAligned(); - this.testBaselineAligned1(); - this.testBaselineAligned2(); - this.testEvents(); - this.testEventsComplex(); - this.testDisconnect(); - this.testReconnect(); - this.testRemoveNode(); - this.testSize(); - this.testReconnectSingleNode(); - }, - - testAligned: function () { - console.log('testAligned:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0); - manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(2, 3, 0); - manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(3, 4, 0); - manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(0, 5, 2); - manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(0, 6, 4); - manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(0, 7, 6); - - manager.layout(); - manager.plot('testAligned', { width: 1200, height: 200 }); - - // Child nodes should be vertically aligned - $assert( - manager.find(1).getPosition().y == manager.find(2).getPosition().y, - 'Child nodes are not vertically aligned' - ); - $assert( - manager.find(1).getPosition().y == manager.find(3).getPosition().y, - 'Child nodes are not vertically aligned' - ); - $assert( - manager.find(1).getPosition().y == manager.find(4).getPosition().y, - 'Child nodes are not vertically aligned' - ); - - // Siblings should be horizontally aligned - $assert( - manager.find(1).getPosition().x == manager.find(5).getPosition().x, - 'Sibling nodes are not horizontally aligned' - ); - $assert( - manager.find(1).getPosition().x == manager.find(6).getPosition().x, - 'Sibling nodes are not horizontally aligned' - ); - $assert( - manager.find(1).getPosition().x == manager.find(7).getPosition().x, - 'Sibling nodes are not horizontally aligned' - ); - - console.log('OK!\n\n'); - }, - - testBaselineAligned1: function () { - console.log('testBaselineAligned1:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(1, 3, 0); - manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(3, 5, 0); - manager.addNode(6, { width: 140, height: 130 }, position).connectNode(3, 6, 1); - manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(6, 7, 0); - manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(7, 8, 0); - manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(7, 9, 1); - manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(7, 10, 2); - manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(7, 11, 3); - manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(7, 12, 4); - manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(7, 13, 5); - manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(7, 14, 6); - manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(7, 15, 7); - manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(7, 16, 8); - manager.addNode(17, TestSuite.NODE_SIZE, position).connectNode(7, 17, 9); - manager.addNode(29, TestSuite.NODE_SIZE, position).connectNode(6, 29, 1); - manager.addNode(30, TestSuite.NODE_SIZE, position).connectNode(6, 30, 2); - manager.addNode(31, { width: 100, height: 50 }, position).connectNode(6, 31, 3); - - manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 1); - manager.addNode(18, { width: 80, height: 70 }, position).connectNode(4, 18, 0); - manager.addNode(19, TestSuite.NODE_SIZE, position).connectNode(18, 19, 0); - manager.addNode(20, TestSuite.NODE_SIZE, position).connectNode(19, 20, 0); - manager.addNode(21, TestSuite.NODE_SIZE, position).connectNode(20, 21, 0); - - manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 1); - manager.addNode(22, TestSuite.NODE_SIZE, position).connectNode(2, 22, 0); - manager.addNode(24, TestSuite.NODE_SIZE, position).connectNode(22, 24, 0); - - manager.addNode(23, { width: 80, height: 50 }, position).connectNode(2, 23, 1); - manager.addNode(25, { width: 80, height: 40 }, position).connectNode(23, 25, 0); - manager.addNode(26, { width: 80, height: 80 }, position).connectNode(25, 26, 0); - manager.addNode(27, TestSuite.NODE_SIZE, position).connectNode(26, 27, 0); - manager.addNode(28, { width: 80, height: 80 }, position).connectNode(27, 28, 0); - - // manager.layout(); - // manager.plot("testBaselineAligned1", {width:1600,height:800}); - - console.log('OK!\n\n'); - }, - - testBaselineAligned2: function () { - console.log('testBaselineAligned2:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); - manager.addNode(2, { width: 130, height: 200 }, position).connectNode(1, 2, 0); - manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(2, 3, 0); - manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(2, 4, 1); - manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(2, 5, 2); - manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(2, 6, 3); - - manager.layout(); - manager.plot('testBaselineAligned2', { width: 1600, height: 800 }); - - console.log('OK!\n\n'); - }, - - testEvents: function () { - console.log('testEvents:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, { x: 0, y: 60 }); - manager.connectNode(0, 1, 0); - manager.connectNode(0, 2, 1); - manager.connectNode(1, 3, 0); - - var events = []; - manager.addEvent('change', function (event) { - console.log( - '\tUpdated nodes: {id:' + - event.getId() + - ', order: ' + - event.getOrder() + - ',position: {' + - event.getPosition().x + - ',' + - event.getPosition().y + - '}' - ); - events.push(event); - }); - manager.layout(true); - manager.plot('testEvents1', { width: 800, height: 200 }); - - console.log('\t--- Layout without changes should not affect the tree ---'); - events.empty(); - manager.layout(true); - manager.plot('testEvents2', { width: 800, height: 200 }); - - // Check no events where fired - $assert(events.length == 0, 'Unnecessary tree updated.'); - - console.log('OK!\n\n'); - }, - - testEventsComplex: function () { - console.log('testEventsComplex:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, { x: 0, y: 60 }); - manager.connectNode(0, 1, 0); - manager.connectNode(0, 2, 1); - manager.connectNode(0, 3, 2); - manager.connectNode(3, 4, 0); - manager.connectNode(3, 5, 1); - - var events = []; - manager.addEvent('change', function (event) { - console.log( - '\tUpdated nodes: {id:' + - event.getId() + - ', order: ' + - event.getOrder() + - ',position: {' + - event.getPosition().x + - ',' + - event.getPosition().y + - '}' - ); - events.push(event); - }); - - manager.layout(true); - manager.plot('testEventsComplex1', { width: 800, height: 200 }); - - console.log('\t--- Connect a new node ---'); - - events.empty(); - manager.connectNode(3, 6, 2); - manager.layout(true); - manager.plot('testEventsComplex2', { width: 800, height: 200 }); - - // Check only 4 nodes were repositioned - - console.log(events.length); - - $assert(events.length == 4, 'Only 4 nodes should be repositioned.'); - - console.log('OK!\n\n'); - }, - - testDisconnect: function () { - console.log('testDisconnect:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 1, 0); - manager.connectNode(1, 2, 0); - manager.connectNode(1, 3, 1); - manager.connectNode(1, 4, 2); - manager.connectNode(4, 5, 0); - manager.connectNode(5, 6, 0); - manager.connectNode(5, 7, 1); - - var events = []; - manager.addEvent('change', function (event) { - var pos = event.getPosition(); - var posStr = pos ? ',position: {' + pos.x + ',' + pos.y : ''; - var node = manager.find(event.getId()); - console.log( - '\tUpdated nodes: {id:' + - event.getId() + - ', order: ' + - event.getOrder() + - posStr + - '}' - ); - events.push(event); - }); - manager.layout(true); - manager.plot('testDisconnect1', { width: 1200, height: 400 }); - - console.log('--- Disconnect node 2 ---'); - events.empty(); - manager.disconnectNode(2); - manager.layout(true); - manager.plot('testDisconnect2', { width: 1200, height: 400 }); - - // Check that orders have been shifted accordingly - $assert(manager.find(2).getOrder() == 0, 'Node 2 should have order 0'); - $assert(manager.find(3).getOrder() == 0, 'Node 3 should now have order 0'); - $assert(manager.find(4).getOrder() == 1, 'Node 4 should have order 1'); - - console.log('--- Disconnect node 4 ---'); - manager.disconnectNode(4); - manager.layout(true); - manager.plot('testDisconnect3', { width: 1200, height: 400 }); - - // Check that nodes 1 and 3 are now vertically aligned - $assert( - manager.find(1).getPosition().y == manager.find(3).getPosition().y, - 'Nodes 1 and 3 should now be vertically aligned' - ); - - console.log('OK!\n\n'); - }, - - testReconnect: function () { - console.log('testReconnect:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - manager.addNode(12, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 1, 0); - manager.connectNode(0, 2, 1); - manager.connectNode(0, 3, 2); - manager.connectNode(0, 4, 3); - manager.connectNode(0, 5, 4); - manager.connectNode(1, 6, 0); - manager.connectNode(1, 7, 1); - manager.connectNode(7, 8, 0); - manager.connectNode(8, 9, 0); - manager.connectNode(5, 10, 0); - manager.connectNode(6, 11, 0); - manager.connectNode(6, 12, 1); - - manager.layout(); - manager.plot('testReconnect1', { width: 1200, height: 400 }); - - // Reconnect node 6 to node 4 - console.log('\tReconnect node 6 to node 4'); - manager.disconnectNode(6); - manager.connectNode(4, 6, 0); - manager.layout(); - manager.plot('testReconnect2', { width: 1200, height: 400 }); - - // Check nodes are left aligned correctly - $assert( - manager.find(1).getPosition().y == manager.find(7).getPosition().y, - 'Nodes 1 and 7 should be vertically aligned' - ); - $assert( - manager.find(4).getPosition().y == manager.find(6).getPosition().y, - 'Nodes 4 and 6 should be vertically aligned' - ); - $assert( - manager.find(4).getPosition().x > manager.find(6).getPosition().x, - 'Node 6 and their children should be to the left of node 4' - ); - $assert( - manager.find(6).getPosition().x > manager.find(11).getPosition().x && - manager.find(11).getPosition().x == manager.find(12).getPosition().x, - 'Nodes 11 and 12 should be to the left of node 6 and horizontally aligned' - ); - - console.log('OK!\n\n'); - }, - - testRemoveNode: function () { - console.log('testRemoveNode:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, TestSuite.NODE_SIZE, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(6, TestSuite.NODE_SIZE, position); - manager.addNode(7, TestSuite.NODE_SIZE, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, TestSuite.NODE_SIZE, position); - - manager.connectNode(0, 1, 0); - manager.connectNode(0, 5, 1); - manager.connectNode(0, 6, 2); - manager.connectNode(0, 7, 3); - manager.connectNode(0, 8, 4); - manager.connectNode(0, 9, 5); - manager.connectNode(1, 2, 0); - manager.connectNode(1, 3, 1); - manager.connectNode(3, 4, 0); - - var events = []; - manager.addEvent('change', function (event) { - var pos = event.getPosition(); - var posStr = pos ? ',position: {' + pos.x + ',' + event.getPosition().y : ''; - events.push(event); - }); - manager.layout(true); - manager.plot('testRemoveNode1', { width: 1000, height: 200 }); - - console.log('\t--- Remove node 3 ---'); - manager.removeNode(3); - manager.layout(true); - manager.plot('testRemoveNode2', { width: 1000, height: 200 }); - - // Check nodes are correctly aligned and node 6 is aligned with the root node - $assert( - manager.find(1).getPosition().y == manager.find(2).getPosition().y, - 'Nodes 1 and 2 should be vertically algined' - ); - $assert( - manager.find(6).getPosition().y == manager.find(0).getPosition().y, - 'Node 6 should be aligned to the root node' - ); - - console.log('\t--- Remove node 6 ---'); - manager.removeNode(6); - manager.layout(true); - manager.plot('testRemoveNode3', { width: 1000, height: 200 }); - - // Check orders were shifted accordingly - $assert(manager.find(8).getOrder() == 2, 'Node 8 should have order 2'); - - console.log('\t--- Remove node 5 ---'); - manager.removeNode(5); - manager.layout(true); - manager.plot('testRemoveNode4', { width: 1000, height: 200 }); - - // Check orders were shifted accordingly - $assert(manager.find(7).getOrder() == 1, 'Node 7 should have order 1'); - $assert(manager.find(9).getOrder() == 3, 'Node 9 should have order 3'); - - console.log('OK!\n\n'); - }, - - testSize: function () { - console.log('testSize:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - manager.addNode(1, { width: 60, height: 60 }, position); - manager.addNode(2, TestSuite.NODE_SIZE, position); - manager.addNode(3, { width: 260, height: 30 }, position); - manager.addNode(4, TestSuite.NODE_SIZE, position); - manager.addNode(5, TestSuite.NODE_SIZE, position); - manager.addNode(7, { width: 80, height: 80 }, position); - manager.addNode(8, TestSuite.NODE_SIZE, position); - manager.addNode(9, { width: 30, height: 30 }, position); - manager.addNode(10, TestSuite.NODE_SIZE, position); - manager.addNode(11, TestSuite.NODE_SIZE, position); - manager.addNode(12, { width: 100, height: 70 }, position); - manager.addNode(13, TestSuite.NODE_SIZE, position); - manager.addNode(14, TestSuite.NODE_SIZE, position); - manager.addNode(15, TestSuite.NODE_SIZE, position); - manager.addNode(16, TestSuite.NODE_SIZE, position); - manager.addNode(17, TestSuite.NODE_SIZE, position); - - manager.connectNode(0, 1, 0); - manager.connectNode(1, 16, 0); - manager.connectNode(0, 2, 1); - manager.connectNode(0, 3, 2); - manager.connectNode(0, 4, 3); - manager.connectNode(0, 5, 4); - manager.connectNode(4, 7, 0); - manager.connectNode(7, 15, 0); - manager.connectNode(7, 17, 1); - manager.connectNode(4, 8, 1); - manager.connectNode(8, 9, 0); - manager.connectNode(3, 10, 0); - manager.connectNode(3, 11, 1); - manager.connectNode(9, 12, 0); - manager.connectNode(9, 13, 1); - manager.connectNode(13, 14, 0); - - manager.layout(); - manager.plot('testSize1', { width: 1400, height: 400 }); - - // Check that all enlarged nodes shift children accordingly - $assert( - manager.find(10).getPosition().x > manager.find(3).getPosition().x && - manager.find(10).getPosition().x == manager.find(11).getPosition().x, - 'Nodes 10 and 11 should be horizontally algined and to the right of enlarged node 3' - ); - var xPosNode7 = manager.find(7).getPosition().x; - var xPosNode8 = manager.find(8).getPosition().x; - - manager.updateNodeSize(4, { width: 100, height: 30 }); - manager.layout(); - manager.plot('testSize2', { width: 1400, height: 400 }); - - // Check that all enlarged nodes shift children accordingly - $assert( - manager.find(2).getPosition().x - manager.find(4).getPosition().x == 10, - 'Node 4 should have been shifted by 10' - ); - $assert( - xPosNode7 - manager.find(7).getPosition().x == 20, - 'Node 7 should have been shifted by 20' - ); - $assert( - xPosNode8 - manager.find(8).getPosition().x == 20, - 'Node 8 should have been shifted by 20' - ); - - var graph2 = manager.plot('testSize3', { width: 1400, height: 400 }); - this._plotPrediction(graph2, manager.predict(0, null, { x: -145, y: 400 })); - this._plotPrediction(graph2, manager.predict(9, null, { x: -330, y: 70 })); - this._plotPrediction(graph2, manager.predict(9, null, { x: -330, y: 120 })); - this._plotPrediction(graph2, manager.predict(0, null, { x: 15, y: 20 })); - //TODO(gb): make asserts - - var graph3 = manager.plot('testSize4', { width: 1400, height: 400 }); - this._plotPrediction(graph3, manager.predict(0, null, null)); - this._plotPrediction(graph3, manager.predict(9, null, null)); - this._plotPrediction(graph3, manager.predict(3, null, null)); - this._plotPrediction(graph3, manager.predict(1, null, null)); - //TODO(gb): make asserts - - var yPosNode2 = manager.find(2).getPosition().y; - manager.updateNodeSize(7, { width: 80, height: 120 }); - manager.layout(); - manager.plot('testSize5', { width: 1400, height: 400 }); - - // Check that all enlarged nodes shift children accordingly - $assert( - yPosNode2 - manager.find(2).getPosition().y == 20, - 'Node 2 should have been shifted by 20' - ); - - console.log('OK!\n\n'); - }, - - testReconnectSingleNode: function () { - console.log('testReconnectSingleNode:'); - var position = { x: 0, y: 0 }; - var manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); - - // Prepare a sample graph ... - manager.addNode(1, TestSuite.NODE_SIZE, position); - manager.connectNode(0, 1, 0); - manager.layout(); - var graph = manager.plot('testReconnectSingleNode1', { width: 1000, height: 400 }); - var prediction = manager.predict(0, null, { x: -50, y: 0 }); - this._plotPrediction(graph, prediction); - - // Check prediction is to the left of the root node - $assert( - prediction.position.x < manager.find(0).getPosition().x, - 'Prediction should be to the left of the root node' - ); - $assert(prediction.order == 1, 'Prediction should have order 1'); - - manager.disconnectNode(1); - manager.connectNode(0, 1, 1); - manager.layout(); - manager.plot('testReconnectSingleNode2', { width: 1000, height: 400 }); - - // Check reconnected node is to the left of the root node - $assert( - manager.find(1).getPosition().x < manager.find(0).getPosition().x, - 'Node 1 should now be to the left of the root node' - ); - $assert(manager.find(1).getOrder() == 1, 'Node 1 should now have order 0'); - }, - - _plotPrediction: function (canvas, prediction) { - var position = prediction.position; - var order = prediction.order; - console.log( - '\t\tprediction {order:' + - order + - ', position: (' + - position.x + - ',' + - position.y + - ')}' - ); - var cx = position.x + canvas.width / 2 - TestSuite.NODE_SIZE.width / 2; - var cy = position.y + canvas.height / 2 - TestSuite.NODE_SIZE.height / 2; - canvas.rect(cx, cy, TestSuite.NODE_SIZE.width, TestSuite.NODE_SIZE.height); - }, -}); - -(TestSuite.NODE_SIZE = { width: 80, height: 30 }), - (TestSuite.ROOT_NODE_SIZE = { width: 120, height: 40 }); - -export default TestSuite; diff --git a/packages/mindplot/test/playground/context-loader.js b/packages/mindplot/test/playground/context-loader.js deleted file mode 100644 index dadf1a1c..00000000 --- a/packages/mindplot/test/playground/context-loader.js +++ /dev/null @@ -1,11 +0,0 @@ -const TestSuite = require('./TestSuite').default; -const BalancedTestSuite = require('./BalancedTestSuite').default; -const SymmetricTestSuite = require('./SymmetricTestSuite').default; -const FreeTestSuite = require('./FreeTestSuite').default; - -window.addEventListener('DOMContentLoaded', function () { - var basicTest = new TestSuite(); - var balancedTest = new BalancedTestSuite(); - var symmetricTest = new SymmetricTestSuite(); - var freeTest = new FreeTestSuite(); -}); diff --git a/packages/mindplot/test/playground/index.html b/packages/mindplot/test/playground/index.html index ec4feeba..b039afec 100644 --- a/packages/mindplot/test/playground/index.html +++ b/packages/mindplot/test/playground/index.html @@ -1,16 +1,22 @@ - - - - Document - - -
-

Mindplot Playground

- -
- - + + + + + Mindplot Playground + + + +
+

Mindplot Playground

+ +
+ + + \ No newline at end of file diff --git a/packages/mindplot/test/playground/layout/BalancedTestSuite.js b/packages/mindplot/test/playground/layout/BalancedTestSuite.js new file mode 100644 index 00000000..1f50a718 --- /dev/null +++ b/packages/mindplot/test/playground/layout/BalancedTestSuite.js @@ -0,0 +1,499 @@ +/* + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * 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. + */ +import TestSuite from './TestSuite'; +import mindplot from '../../../src/mindplot'; + +const BalancedTestSuite = new Class({ + Extends: TestSuite, + + initialize() { + $('#balancedTest').css('display', 'block'); + + this.testBalanced(); + this.testBalancedPredict(); + this.testBalancedNodeDragPredict(); + }, + + testBalanced() { + console.log('testBalanced:'); + const position = { x: 0, y: 0 }; + const plotsize = { width: 1000, height: 200 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 1, 0); + manager.layout(); + manager.plot('testBalanced1', plotsize); + + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 2, 1); + manager.layout(); + manager.plot('testBalanced2', plotsize); + + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 3, 2); + manager.layout(); + manager.plot('testBalanced3', plotsize); + + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 4, 3); + manager.layout(); + manager.plot('testBalanced4', plotsize); + + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 5, 4); + manager.layout(); + manager.plot('testBalanced5', plotsize); + + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 6, 5); + manager.layout(); + manager.plot('testBalanced6', plotsize); + + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + manager.connectNode(3, 7, 0); + manager.connectNode(7, 8, 0); + manager.connectNode(7, 9, 1); + manager.layout(); + manager.plot('testBalanced7', plotsize); + + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + manager.addNode(12, TestSuite.NODE_SIZE, position); + manager.connectNode(6, 10, 0); + manager.connectNode(10, 11, 0); + manager.connectNode(10, 12, 1); + manager.layout(); + manager.plot('testBalanced8', plotsize); + + manager.addNode(13, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 13, 4); + manager.layout(); + manager.plot('testBalanced9', { width: 1000, height: 400 }); + + // Check orders have shifted accordingly + $assert(manager.find(5).getOrder() == 6, 'Node 5 should have order 6'); + + manager.addNode(14, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 14, 5); + manager.layout(); + manager.plot('testBalanced10', { width: 1000, height: 400 }); + + // Check orders have shifted accordingly + $assert(manager.find(6).getOrder() == 7, 'Node 6 should have order 7'); + + manager.addNode(15, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 15, 4); + manager.layout(); + manager.plot('testBalanced11', { width: 1000, height: 400 }); + + // Check orders have shifted accordingly + $assert(manager.find(13).getOrder() == 6, 'Node 13 should have order 6'); + $assert(manager.find(5).getOrder() == 8, 'Node 5 should have order 8'); + + manager.addNode(16, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 16, 25); + manager.layout(); + manager.plot('testBalanced12', { width: 1000, height: 400 }); + + // Check orders have shifted accordingly + $assert(manager.find(16).getOrder() == 9, 'Node 16 should have order 9'); + + manager.addNode(17, TestSuite.NODE_SIZE, position); + manager.addNode(18, TestSuite.NODE_SIZE, position); + manager.addNode(19, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 17, 11); + manager.connectNode(0, 18, 13); + manager.connectNode(0, 19, 10); + manager.layout(); + manager.plot('testBalanced13', { width: 1000, height: 400 }); + + // Check that everything is ok + $assert( + manager.find(1).getPosition().x > manager.find(0).getPosition().x, + 'even order nodes must be at right of central topic', + ); + $assert( + manager.find(3).getPosition().x > manager.find(0).getPosition().x, + 'even order nodes must be at right of central topic', + ); + $assert( + manager.find(5).getPosition().x > manager.find(0).getPosition().x, + 'even order nodes must be at right of central topic', + ); + $assert( + manager.find(2).getPosition().x < manager.find(0).getPosition().x, + 'odd order nodes must be at right of central topic', + ); + $assert( + manager.find(4).getPosition().x < manager.find(0).getPosition().x, + 'odd order nodes must be at right of central topic', + ); + $assert( + manager.find(6).getPosition().x < manager.find(0).getPosition().x, + 'odd order nodes must be at right of central topic', + ); + $assert( + manager.find(7).getPosition().x > manager.find(3).getPosition().x, + 'children of 1st level even order nodes must be to the right', + ); + $assert( + manager.find(8).getPosition().x > manager.find(7).getPosition().x, + 'children of 1st level even order nodes must be to the right', + ); + $assert( + manager.find(9).getPosition().x > manager.find(7).getPosition().x, + 'children of 1st level even order nodes must be to the right', + ); + $assert( + manager.find(10).getPosition().x < manager.find(6).getPosition().x, + 'children of 1st level odd order nodes must be to the left', + ); + $assert( + manager.find(11).getPosition().x < manager.find(10).getPosition().x, + 'children of 1st level odd order nodes must be to the left', + ); + $assert( + manager.find(12).getPosition().x < manager.find(10).getPosition().x, + 'children of 1st level odd order nodes must be to the left', + ); + + console.log('OK!\n\n'); + }, + + testBalancedPredict() { + console.log('testBalancedPredict:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + + manager.connectNode(0, 1, 0); + manager.connectNode(0, 2, 1); + manager.connectNode(0, 3, 2); + manager.connectNode(0, 4, 3); + manager.connectNode(0, 5, 4); + manager.connectNode(4, 7, 0); + manager.connectNode(4, 8, 1); + manager.connectNode(8, 9, 0); + manager.connectNode(3, 10, 0); + manager.connectNode(3, 11, 1); + + manager.layout(); + + // Graph 1 + const graph1 = manager.plot('testBalancedPredict1', { width: 1000, height: 400 }); + + console.log('\tAdded as child of node 0 and dropped at (165, -70):'); + const prediction1a = manager.predict(0, null, { x: 165, y: -70 }); + this._plotPrediction(graph1, prediction1a); + $assert( + prediction1a.position.y < manager.find(1).getPosition().y + && prediction1a.position.x == manager.find(1).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1a.order == 0, 'Prediction order should be 0'); + + console.log('\tAdded as child of node 0 and dropped at (165, -10):'); + const prediction1b = manager.predict(0, null, { x: 165, y: -10 }); + this._plotPrediction(graph1, prediction1b); + $assert( + prediction1b.position.y > manager.find(1).getPosition().y + && prediction1b.position.y < manager.find(3).getPosition().y + && prediction1b.position.x == manager.find(1).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1b.order == 2, 'Prediction order should be 2'); + + console.log('\tAdded as child of node 0 and dropped at (145, 15):'); + const prediction1c = manager.predict(0, null, { x: 145, y: 15 }); + this._plotPrediction(graph1, prediction1c); + $assert( + prediction1c.position.y > manager.find(3).getPosition().y + && prediction1c.position.y < manager.find(5).getPosition().y + && prediction1c.position.x == manager.find(3).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1c.order == 4, 'Prediction order should be 4'); + + console.log('\tAdded as child of node 0 and dropped at (145, 70):'); + const prediction1d = manager.predict(0, null, { x: 145, y: 70 }); + this._plotPrediction(graph1, prediction1d); + $assert( + prediction1d.position.y > manager.find(5).getPosition().y + && prediction1d.position.x == manager.find(5).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1d.order == 6, 'Prediction order should be 6'); + + // Graph 2 + const graph2 = manager.plot('testBalancedPredict2', { width: 1000, height: 400 }); + + console.log('\tAdded as child of node 0 and dropped at (-145, -50):'); + const prediction2a = manager.predict(0, null, { x: -145, y: -50 }); + this._plotPrediction(graph2, prediction2a); + $assert( + prediction2a.position.y < manager.find(2).getPosition().y + && prediction2a.position.x == manager.find(2).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction2a.order == 1, 'Prediction order should be 1'); + + console.log('\tAdded as child of node 0 and dropped at (-145, -10):'); + const prediction2b = manager.predict(0, null, { x: -145, y: -10 }); + this._plotPrediction(graph2, prediction2b); + $assert( + prediction2b.position.y > manager.find(2).getPosition().y + && prediction2b.position.y < manager.find(4).getPosition().y + && prediction2b.position.x == manager.find(2).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction2b.order == 3, 'Prediction order should be 3'); + + console.log('\tAdded as child of node 0 and dropped at (-145, 40):'); + const prediction2c = manager.predict(0, null, { x: -145, y: 400 }); + this._plotPrediction(graph2, prediction2c); + $assert( + prediction2c.position.y > manager.find(4).getPosition().y + && prediction2c.position.x == manager.find(4).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction2c.order == 5, 'Prediction order should be 5'); + + // Graph 3 + console.log('\tPredict nodes added with no position:'); + const graph3 = manager.plot('testBalancedPredict3', { width: 1000, height: 400 }); + const prediction3 = manager.predict(0, null, null); + this._plotPrediction(graph3, prediction3); + $assert( + prediction3.position.y > manager.find(4).getPosition().y + && prediction3.position.x == manager.find(4).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction3.order == 5, 'Prediction order should be 5'); + + console.log('\tPredict nodes added with no position:'); + manager.addNode(6, TestSuite.NODE_SIZE, prediction3.position); + manager.connectNode(0, 6, prediction3.order); + manager.layout(); + const graph4 = manager.plot('testBalancedPredict4', { width: 1000, height: 400 }); + const prediction4 = manager.predict(0, null, null); + this._plotPrediction(graph4, prediction4); + $assert( + prediction4.position.y > manager.find(5).getPosition().y + && prediction4.position.x == manager.find(5).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction4.order == 6, 'Prediction order should be 6'); + + console.log('\tPredict nodes added only a root node:'); + manager.removeNode(1).removeNode(2).removeNode(3).removeNode(4) + .removeNode(5); + manager.layout(); + const graph5 = manager.plot('testBalancedPredict5', { width: 1000, height: 400 }); + const prediction5a = manager.predict(0, null, null); + const prediction5b = manager.predict(0, null, { x: 40, y: 100 }); + this._plotPrediction(graph5, prediction5a); + this._plotPrediction(graph5, prediction5b); + $assert( + prediction5a.position.x > manager.find(0).getPosition().x + && prediction5a.position.y == manager.find(0).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction5a.order == 0, 'Prediction order should be 0'); + $assert( + prediction5a.position.x == prediction5b.position.x + && prediction5a.position.y == prediction5b.position.y, + 'Both predictions should be the same', + ); + $assert(prediction5a.order == prediction5b.order, 'Both predictions should be the same'); + + console.log('OK!\n\n'); + }, + + testBalancedNodeDragPredict() { + console.log('testBalancedNodeDragPredict:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Graph 1 + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.layout(); + const graph1 = manager.plot('testBalancedNodeDragPredict1', { width: 800, height: 400 }); + + const prediction1a = manager.predict(0, 1, { x: 50, y: 50 }); + this._plotPrediction(graph1, prediction1a); + $assert( + prediction1a.position.x == manager.find(1).getPosition().x + && prediction1a.position.y == manager.find(1).getPosition().y, + 'Prediction position should be the same as node 1', + ); + $assert( + prediction1a.order == manager.find(1).getOrder(), + 'Prediction order should be the same as node 1', + ); + + const prediction1b = manager.predict(0, 1, { x: 50, y: -50 }); + this._plotPrediction(graph1, prediction1b); + $assert( + prediction1b.position.x == manager.find(1).getPosition().x + && prediction1b.position.y == manager.find(1).getPosition().y, + 'Prediction position should be the same as node 1', + ); + $assert( + prediction1b.order == manager.find(1).getOrder(), + 'Prediction order should be the same as node 1', + ); + + const prediction1c = manager.predict(0, 1, { x: -50, y: 50 }); + this._plotPrediction(graph1, prediction1c); + $assert( + prediction1c.position.x < manager.find(0).getPosition().x + && prediction1c.position.y == manager.find(0).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1c.order == 1, 'Prediction order should be the same as node 1'); + + const prediction1d = manager.predict(0, 1, { x: -50, y: -50 }); + this._plotPrediction(graph1, prediction1d); + $assert( + prediction1d.position.x < manager.find(0).getPosition().x + && prediction1d.position.y == manager.find(0).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1d.order == 1, 'Prediction order should be the same as node 1'); + + // Graph 2 + manager.disconnectNode(1); + manager.connectNode(0, 1, 1); + manager.layout(); + const graph2 = manager.plot('testBalancedNodeDragPredict2', { width: 800, height: 400 }); + + const prediction2a = manager.predict(0, 1, { x: 50, y: 50 }); + this._plotPrediction(graph2, prediction2a); + $assert( + prediction2a.position.x > manager.find(0).getPosition().x + && prediction2a.position.y == manager.find(0).getPosition().y, + 'Prediction is positioned incorrectly', + ); + $assert(prediction2a.order == 0, 'Prediction order should be 0'); + + const prediction2b = manager.predict(0, 1, { x: 50, y: -50 }); + this._plotPrediction(graph2, prediction2b); + $assert( + prediction2b.position.x > manager.find(0).getPosition().x + && prediction2b.position.y == manager.find(0).getPosition().y, + 'Prediction is positioned incorrectly', + ); + $assert(prediction2b.order == 0, 'Prediction order should be 0'); + + const prediction2c = manager.predict(0, 1, { x: -50, y: 50 }); + this._plotPrediction(graph2, prediction2c); + $assert( + prediction2c.position.x == manager.find(1).getPosition().x + && prediction2c.position.y == manager.find(1).getPosition().y, + 'Prediction position should be the same as node 1', + ); + $assert( + prediction2c.order == manager.find(1).getOrder(), + 'Prediction order should be the same as node 1', + ); + + const prediction2d = manager.predict(0, 1, { x: -50, y: -50 }); + this._plotPrediction(graph2, prediction2d); + $assert( + prediction2d.position.x == manager.find(1).getPosition().x + && prediction2d.position.y == manager.find(1).getPosition().y, + 'Prediction position should be the same as node 1', + ); + $assert( + prediction2d.order == manager.find(1).getOrder(), + 'Prediction order should be the same as node 1', + ); + + // Graph 3 + manager.disconnectNode(1); + manager.connectNode(0, 1, 0); + manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2); + manager.layout(); + const graph3 = manager.plot('testBalancedNodeDragPredict3', { width: 800, height: 400 }); + + const prediction3a = manager.predict(0, 1, { x: 50, y: 50 }); + this._plotPrediction(graph3, prediction3a); + $assert( + prediction3a.position.x == manager.find(2).getPosition().x + && prediction3a.position.y > manager.find(2).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction3a.order == 4, 'Prediction order should be 4'); + + const prediction3b = manager.predict(0, 1, { x: 50, y: -50 }); + this._plotPrediction(graph3, prediction3b); + $assert( + prediction3b.position.x == manager.find(1).getPosition().x + && prediction3b.position.y == manager.find(1).getPosition().y + && prediction3b.order == manager.find(1).getOrder(), + 'Prediction should be the exact same as dragged node', + ); + + const prediction3c = manager.predict(0, 1, { x: -50, y: 50 }); + this._plotPrediction(graph3, prediction3c); + $assert( + prediction3c.position.x < manager.find(0).getPosition().x + && prediction3c.position.y == manager.find(0).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction3c.order == 1, 'Prediction order should be 1'); + + const prediction3d = manager.predict(0, 1, { x: -50, y: -50 }); + this._plotPrediction(graph3, prediction3d); + $assert( + prediction3d.position.x < manager.find(0).getPosition().x + && prediction3d.position.y == manager.find(0).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction3d.order == 1, 'Prediction order should be 1'); + + const prediction3e = manager.predict(0, 1, { x: 50, y: 0 }); + this._plotPrediction(graph3, prediction3e); + $assert( + prediction3e.position.x == manager.find(1).getPosition().x + && prediction3e.position.y == manager.find(1).getPosition().y, + 'Prediction position should be the same as node 1', + ); + $assert( + prediction3e.order == manager.find(1).getOrder(), + 'Prediction order should be the same as node 1', + ); + + console.log('OK!\n\n'); + }, +}); + +export default BalancedTestSuite; diff --git a/packages/mindplot/test/playground/layout/FreeTestSuite.js b/packages/mindplot/test/playground/layout/FreeTestSuite.js new file mode 100644 index 00000000..78403d9e --- /dev/null +++ b/packages/mindplot/test/playground/layout/FreeTestSuite.js @@ -0,0 +1,555 @@ +/* + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * 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. + */ +import TestSuite from './TestSuite'; +import mindplot from '../../../src/mindplot'; + +const FreeTestSuite = new Class({ + Extends: TestSuite, + + initialize() { + $('#freeTest').css('display', 'block'); + + this.testFreePosition(); + this.testFreePredict(); + this.testReconnectFreeNode(); + this.testSiblingOverlapping(); + this.testRootNodeChildrenPositioning(); + this.testBalancedFreePredict(); + this.testFreeReorder(); + this.testFreeOverlap(); + }, + + testFreePosition() { + console.log('testFreePosition:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + manager.addNode(12, TestSuite.NODE_SIZE, position); + manager.addNode(13, TestSuite.NODE_SIZE, position); + manager.addNode(14, TestSuite.NODE_SIZE, position); + manager.addNode(15, TestSuite.NODE_SIZE, position); + manager.addNode(16, TestSuite.NODE_SIZE, position); + manager.addNode(17, TestSuite.NODE_SIZE, position); + manager.addNode(18, TestSuite.NODE_SIZE, position); + manager.addNode(19, TestSuite.NODE_SIZE, position); + manager.addNode(20, TestSuite.NODE_SIZE, position); + manager.addNode(21, TestSuite.NODE_SIZE, position); + manager.addNode(22, TestSuite.NODE_SIZE, position); + + manager.connectNode(0, 1, 0).connectNode(0, 2, 1).connectNode(0, 3, 2).connectNode(0, 4, 3); + manager.connectNode(4, 21, 0).connectNode(4, 22, 0); + manager.connectNode(1, 5, 0); + manager.connectNode(5, 6, 0).connectNode(6, 8, 0).connectNode(8, 9, 0); + manager.connectNode(5, 7, 1).connectNode(7, 10, 0); + manager + .connectNode(3, 11, 0) + .connectNode(11, 14, 0) + .connectNode(14, 18, 0) + .connectNode(14, 19, 1) + .connectNode(14, 20, 2); + manager + .connectNode(3, 12, 1) + .connectNode(12, 15, 0) + .connectNode(12, 16, 1) + .connectNode(12, 17, 2); + manager.connectNode(3, 13, 2); + + manager.layout(); + manager.plot('testFreePosition1', { width: 1400, height: 600 }); + + console.log('\tmove node 12 to (300,30):'); + manager.moveNode(12, { x: 300, y: 30 }); + manager.layout(true); + manager.plot('testFreePosition2', { width: 1400, height: 600 }); + this._assertFreePosition(manager, 12, { x: 300, y: 30 }); + + console.log('\tmove node 13 to (340,180):'); + const node13Pos = { x: 340, y: 180 }; + manager.moveNode(13, node13Pos); + manager.layout(true); + manager.plot('testFreePosition3', { width: 1400, height: 600 }); + this._assertFreePosition(manager, 13, node13Pos); + + console.log('\tmove node 11 to (250,-50):'); + manager.moveNode(11, { x: 250, y: -50 }); + manager.layout(true); + manager.plot('testFreePosition4', { width: 1400, height: 600 }); + this._assertFreePosition(manager, 11, { x: 250, y: -50 }); + $assert( + manager.find(13).getPosition().x == node13Pos.x + && manager.find(13).getPosition().y == node13Pos.y, + "Node 13 shouldn't have moved", + ); + + console.log('\tmove node 7 to (350,-190):'); + manager.moveNode(7, { x: 350, y: -190 }); + manager.layout(true); + manager.plot('testFreePosition5', { width: 1400, height: 600 }); + this._assertFreePosition(manager, 7, { x: 350, y: -190 }); + + console.log('\tadd node 23 to 12:'); + manager.addNode(23, TestSuite.NODE_SIZE, position); + manager.connectNode(12, 23, 3); + manager.layout(true); + manager.plot('testFreePosition6', { width: 1400, height: 600 }); + this._assertFreePosition(manager, null, null); + + console.log('\tmove node 4 to (-300, 190):'); + manager.moveNode(4, { x: -300, y: 190 }); + manager.layout(true); + manager.plot('testFreePosition7', { width: 1400, height: 600 }); + this._assertFreePosition(manager, 4, { x: -300, y: 190 }); + + console.log('\tadd node 24 to 3:'); + manager.addNode(24, TestSuite.NODE_SIZE, position); + manager.connectNode(3, 24, 3); + manager.layout(true); + manager.plot('testFreePosition8', { width: 1400, height: 600 }); + this._assertFreePosition(manager, null, null); + + console.log('\tadd node 25 to 17:'); + manager.addNode(25, TestSuite.NODE_SIZE, position); + manager.connectNode(17, 25, 0); + manager.layout(true); + manager.plot('testFreePosition9', { width: 1400, height: 600 }); + this._assertFreePosition(manager, null, null); + + console.log('OK!\n\n'); + }, + + testFreePredict() { + console.log('testFreePredict:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + + manager.connectNode(0, 1, 0); + manager.connectNode(0, 2, 1); + manager.connectNode(0, 3, 2); + manager.connectNode(3, 4, 0); + manager.connectNode(3, 5, 1); + manager.connectNode(3, 6, 2); + manager.connectNode(5, 7, 0); + manager.connectNode(5, 8, 1); + manager.connectNode(5, 11, 2); + manager.connectNode(2, 9, 0); + manager.connectNode(2, 10, 1); + + manager.layout(); + const graph = manager.plot('testFreePredict1', { width: 1000, height: 400 }); + + const pos1 = { x: 370, y: 80 }; + const predict1 = manager.predict(5, 11, pos1, true); + this._plotPrediction(graph, predict1); + $assert( + predict1.position.x == pos1.x && predict1.position.y == pos1.y, + 'free predict should return the same position', + ); + + const pos2 = { x: -200, y: 80 }; + const predict2 = manager.predict(0, 2, pos2, true); + this._plotPrediction(graph, predict2); + $assert( + predict2.position.x == pos2.x && predict2.position.y == pos2.y, + 'free predict should return the same position', + ); + + const pos3 = { x: 200, y: 30 }; + const node5 = manager.find(5); + const predict3 = manager.predict(3, 5, pos3, true); + this._plotPrediction(graph, predict3); + $assert( + predict3.position.x == node5.getPosition().x && predict3.position.y == pos3.y, + 'free predict should return the x-coordinate of the node', + ); + + const pos4 = { x: -100, y: 45 }; + const node10 = manager.find(10); + const predict4 = manager.predict(2, 10, pos4, true); + this._plotPrediction(graph, predict4); + $assert( + predict4.position.x == node10.getPosition().x && predict4.position.y == pos4.y, + 'free predict should return the x-coordinate of the node', + ); + + console.log('OK!\n\n'); + }, + + testReconnectFreeNode() { + console.log('testReconnectFreeNode:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + + manager.connectNode(0, 1, 0); + manager.connectNode(0, 2, 1); + manager.connectNode(0, 3, 2); + manager.connectNode(3, 4, 0); + manager.connectNode(3, 5, 1); + manager.connectNode(3, 6, 2); + manager.connectNode(5, 7, 0); + manager.connectNode(5, 8, 1); + manager.connectNode(5, 11, 2); + manager.connectNode(2, 9, 0); + manager.connectNode(2, 10, 1); + + manager.layout(); + manager.plot('testReconnectFreeNode1', { width: 1000, height: 400 }); + + console.log('\tmove node 5'); + manager.moveNode(5, { x: 250, y: 30 }); + manager.layout(); + manager.plot('testReconnectFreeNode2', { width: 1000, height: 400 }); + this._assertFreePosition(manager, 5, { x: 250, y: 30 }); + + console.log('\treconnect node 5 to node 2'); + manager.disconnectNode(5); + manager.connectNode(2, 5, 2); + manager.layout(); + manager.plot('testReconnectFreeNode3', { width: 1000, height: 400 }); + $assert( + manager.find(5).getPosition().y > manager.find(10).getPosition().y + && manager.find(5).getPosition().x == manager.find(10).getPosition().x, + 'Node 5 is incorrectly positioned', + ); + $assert(manager.find(5).getOrder() == 2, 'Node 5 should have order 2'); + + console.log('\tmove node 8'); + manager.moveNode(8, { x: -370, y: 60 }); + manager.layout(); + manager.plot('testReconnectFreeNode4', { width: 1000, height: 400 }); + this._assertFreePosition(manager, 8, { x: -370, y: 60 }); + + console.log('\treconnect node 5 to node 10'); + manager.disconnectNode(5); + manager.connectNode(10, 5, 0); + manager.layout(); + manager.plot('testReconnectFreeNode5', { width: 1000, height: 400 }); + $assert( + manager.find(5).getPosition().y == manager.find(10).getPosition().y + && manager.find(5).getPosition().x < manager.find(10).getPosition().x, + 'Node 5 is incorrectly positioned', + ); + $assert(manager.find(5).getOrder() == 0, 'Node 5 should have order 0'); + + console.log('reconnect node 5 to node 3'); + manager.disconnectNode(5); + manager.connectNode(3, 5, 2); + manager.layout(); + manager.plot('testReconnectFreeNode6', { width: 1000, height: 400 }); + $assert( + manager.find(5).getPosition().y > manager.find(6).getPosition().y + && manager.find(5).getPosition().x == manager.find(6).getPosition().x, + 'Node 5 is incorrectly positioned', + ); + $assert(manager.find(5).getOrder() == 2, 'Node 5 should have order 2'); + + console.log('\tmove node 8'); + manager.moveNode(8, { x: 370, y: 30 }); + manager.layout(); + manager.plot('testReconnectFreeNode7', { width: 1000, height: 400 }); + this._assertFreePosition(manager, 8, { x: 370, y: 30 }); + + console.log('OK!\n\n'); + }, + + testSiblingOverlapping() { + console.log('testSiblingOverlapping:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0); + manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(1, 3, 1); + manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 2); + manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 3); + manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 4); + manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(1, 7, 5); + manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(1, 8, 6); + manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(0, 9, 4); + manager.layout(); + manager.plot('testSiblingOverlapping1', { width: 800, height: 600 }); + + console.log('\tmove node 2'); + manager.moveNode(2, { x: 250, y: -30 }); + manager.layout(); + manager.plot('testSiblingOverlapping2', { width: 800, height: 600 }); + this._assertFreePosition(manager, 2, { x: 250, y: -30 }); + + console.log('\tmove node 7'); + manager.moveNode(7, { x: 250, y: 100 }); + manager.layout(); + manager.plot('testSiblingOverlapping3', { width: 800, height: 600 }); + this._assertFreePosition(manager, 7, { x: 250, y: 100 }); + + console.log('OK!\n\n'); + }, + + testRootNodeChildrenPositioning() { + console.log('testRootNodeChildrenPositioning:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 1); + manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 2); + manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(0, 4, 3); + manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(0, 5, 4); + manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(0, 6, 5); + manager.layout(); + manager.plot('testRootNodeChildrenPositioning1', { width: 800, height: 600 }); + + console.log('\tmove node 1'); + manager.moveNode(1, { x: 150, y: 0 }); + manager.layout(); + manager.plot('testRootNodeChildrenPositioning2', { width: 800, height: 600 }); + this._assertFreePosition(manager, 1, { x: 150, y: 0 }); + + console.log('\tmove node 4'); + manager.moveNode(4, { x: -140, y: 30 }); + manager.layout(); + manager.plot('testRootNodeChildrenPositioning3', { width: 800, height: 600 }); + this._assertFreePosition(manager, 4, { x: -140, y: 30 }); + + console.log('\tmove node 2'); + manager.moveNode(2, { x: -150, y: -50 }); + manager.layout(); + manager.plot('testRootNodeChildrenPositioning4', { width: 800, height: 600 }); + this._assertFreePosition(manager, 2, { x: -150, y: -50 }); + + // TODO(gb): fix this. It's not working + // console.log("\tmove node 6"); + // manager.moveNode(6, {x:-150, y:-50}); + // manager.layout(); + // manager.plot("testRootNodeChildrenPositioning5", {width:800, height:600}); + // this._assertFreePosition(manager, 6, {x:-150, y:-50}); + + console.log('OK!\n\n'); + }, + + testBalancedFreePredict() { + console.log('testBalancedFreePredict:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.layout(); + const graph1 = manager.plot('testBalancedFreePredict1', { width: 800, height: 400 }); + + const predict1 = manager.predict(0, 1, { x: 70, y: 0 }, true); + this._plotPrediction(graph1, predict1); + $assert( + predict1.position.x == manager.find(1).getPosition().x, + 'Prediction x pos should be the same as node 1', + ); + + console.log('OK!\n\n'); + }, + + testFreeReorder() { + console.log('testFreeReorder:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 0); + manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 1); + manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 2); + + manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2); + manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(2, 7, 0); + manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(2, 8, 1); + manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(2, 9, 2); + manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(2, 10, 3); + + manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 4); + manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(3, 11, 0); + manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(3, 12, 1); + manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(3, 13, 2); + manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(3, 14, 3); + manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(3, 15, 4); + manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(3, 16, 5); + + manager.layout(); + manager.moveNode(14, { x: 270, y: -160 }); + manager.layout(); + manager.plot('testFreeReorder1', { width: 800, height: 1200 }); + $assert( + manager.find(14).getPosition().y > manager.find(10).getPosition().y, + 'Node 14 should be below branch 2', + ); + + console.log('OK!\n\n'); + }, + + testFreeOverlap() { + console.log('testFreeOverlap:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 0); + manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(1, 5, 1); + manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(1, 6, 2); + + manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 2); + manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(2, 7, 0); + manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(2, 8, 1); + manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(2, 9, 2); + manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(2, 10, 3); + + manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(0, 3, 4); + manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(3, 11, 0); + manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(3, 12, 1); + manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(3, 13, 2); + manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(3, 14, 3); + manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(3, 15, 4); + manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(3, 16, 5); + + manager.layout(); + manager.plot('testFreeOverlap1', { width: 800, height: 1200 }); + + manager.moveNode(14, { x: 270, y: 7 }); + manager.layout(); + manager.plot('testFreeOverlap2', { width: 800, height: 1200 }); + $assert( + manager.find(2).getPosition().y > manager.find(1).getPosition().y, + 'Branches 1 and 2 are overlapping', + ); + + console.log('OK!\n\n'); + }, + + _assertFreePosition(manager, id, position) { + if (id != null && position.x != null && position.y != null) { + const node = manager.find(id); + $assert( + node.getPosition().x == position.x && node.getPosition().y == position.y, + `Freely moved node ${ + id + } is not left at free position (${ + position.x + },${ + position.y + }). ` + + `Actual position: (${ + node.getPosition().x + },${ + node.getPosition().y + })`, + ); + } + + const treeSet = manager._treeSet; + _.each( + treeSet._rootNodes, + function (rootNode) { + const heightById = rootNode.getSorter().computeChildrenIdByHeights(treeSet, rootNode); + this._assertBranchCollision(treeSet, rootNode, heightById); + }, + this, + ); + }, + + _assertBranchCollision(treeSet, node, heightById) { + const children = treeSet.getChildren(node); + const childOfRootNode = treeSet._rootNodes.contains(node); + + _.each( + children, + function (child) { + const height = heightById[child.getId()]; + let siblings = treeSet.getSiblings(child); + if (childOfRootNode) { + siblings = siblings.filter((sibling) => child.getOrder() % 2 == sibling.getOrder() % 2); + } + _.each( + siblings, + function (sibling) { + this._branchesOverlap(child, sibling, heightById); + }, + this, + ); + }, + this, + ); + + _.each( + children, + function (child) { + this._assertBranchCollision(treeSet, child, heightById); + }, + this, + ); + }, + + _branchesOverlap(branchA, branchB, heightById) { + const topA = branchA.getPosition().y - heightById[branchA.getId()] / 2; + const bottomA = branchA.getPosition().y + heightById[branchA.getId()] / 2; + const topB = branchB.getPosition().y - heightById[branchB.getId()] / 2; + const bottomB = branchB.getPosition().y + heightById[branchB.getId()] / 2; + + $assert( + topA >= bottomB || bottomA <= topB, + `Branches ${branchA.getId()} and ${branchB.getId()} overlap`, + ); + }, +}); + +export default FreeTestSuite; diff --git a/packages/mindplot/test/playground/layout/SymmetricTestSuite.js b/packages/mindplot/test/playground/layout/SymmetricTestSuite.js new file mode 100644 index 00000000..f71414f4 --- /dev/null +++ b/packages/mindplot/test/playground/layout/SymmetricTestSuite.js @@ -0,0 +1,351 @@ +/* + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * 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. + */ +import TestSuite from './TestSuite'; +import mindplot from '../../../src/mindplot'; + +const SymmetricTestSuite = new Class({ + Extends: TestSuite, + + initialize() { + $('#symmetricTest').css('display', 'block'); + + this.testSymmetry(); + this.testSymmetricPredict(); + this.testSymmetricDragPredict(); + }, + + testSymmetry() { + console.log('testSymmetry:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + manager.addNode(12, TestSuite.NODE_SIZE, position); + manager.addNode(13, TestSuite.NODE_SIZE, position); + manager.addNode(14, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 14, 0); + manager.connectNode(14, 13, 0); + manager.connectNode(13, 1, 0); + manager.connectNode(13, 2, 1); + manager.connectNode(13, 3, 2); + manager.connectNode(13, 4, 3); + manager.connectNode(13, 5, 4); + manager.connectNode(1, 6, 0); + manager.connectNode(1, 7, 1); + manager.connectNode(7, 8, 0); + manager.connectNode(8, 9, 0); + manager.connectNode(5, 10, 0); + manager.connectNode(6, 11, 0); + manager.connectNode(6, 12, 1); + + manager.layout(); + manager.plot('testSymmetry', { width: 1600, height: 400 }); + + // All nodes should be positioned symmetrically with respect to their common ancestors + $assert( + manager.find(14).getPosition().y == manager.find(13).getPosition().y, + 'Symmetry is not respected', + ); + $assert( + manager.find(5).getPosition().y == manager.find(10).getPosition().y, + 'Symmetry is not respected', + ); + $assert( + manager.find(11).getPosition().y - manager.find(6).getPosition().y + == -(manager.find(12).getPosition().y - manager.find(6).getPosition().y), + 'Symmetry is not respected', + ); + $assert( + manager.find(8).getPosition().y - manager.find(1).getPosition().y + == -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), + 'Symmetry is not respected', + ); + $assert( + manager.find(9).getPosition().y - manager.find(1).getPosition().y + == -(manager.find(11).getPosition().y - manager.find(1).getPosition().y), + 'Symmetry is not respected', + ); + + console.log('OK!\n\n'); + }, + + testSymmetricPredict() { + console.log('testSymmetricPredict:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + + manager.connectNode(0, 1, 0); + manager.connectNode(0, 2, 1); + manager.connectNode(0, 3, 2); + manager.connectNode(3, 4, 0); + manager.connectNode(3, 5, 1); + manager.connectNode(3, 6, 2); + manager.connectNode(5, 7, 0); + manager.connectNode(5, 8, 1); + manager.connectNode(5, 11, 2); + manager.connectNode(2, 9, 0); + manager.connectNode(2, 10, 1); + + manager.layout(); + + // Graph + const graph1 = manager.plot('testSymmetricPredict1', { width: 1000, height: 400 }); + + console.log('\tAdded as child of node 9 and dropped at (-280, 45):'); + const prediction1a = manager.predict(9, null, { x: -280, y: 45 }); + this._plotPrediction(graph1, prediction1a); + $assert( + prediction1a.position.x < manager.find(9).getPosition().x + && prediction1a.position.y == manager.find(9).getPosition().y, + 'Prediction incorrectly positioned', + ); + $assert(prediction1a.order == 0, 'Prediction order should be 0'); + + console.log('\tAdded as child of node 1 and dropped at (155, -90):'); + const prediction1b = manager.predict(1, null, { x: -155, y: -90 }); + this._plotPrediction(graph1, prediction1b); + $assert( + prediction1b.position.x > manager.find(1).getPosition().x + && prediction1b.position.y == manager.find(1).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1b.order == 0, 'Prediction order should be 0'); + + // Graph 2 + const graph2 = manager.plot('testSymmetricPredict2', { width: 1000, height: 400 }); + + console.log('\tAdded as child of node 5 and dropped at (380, -30):'); + const prediction2d = manager.predict(5, null, { x: 380, y: -30 }); + this._plotPrediction(graph2, prediction2d); + + // Prediction calculator error + $assert( + prediction2d.position.y < manager.find(7).getPosition().y + && prediction2d.position.x == manager.find(7).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction2d.order == 0, 'Prediction order should be 0'); + + console.log('\tAdded as child of node 5 and dropped at (375, 15):'); + const prediction2a = manager.predict(5, null, { x: 375, y: 15 }); + this._plotPrediction(graph2, prediction2a); + + $assert( + prediction2a.position.y > manager.find(7).getPosition().y + && prediction2a.position.y < manager.find(8).getPosition().y + && prediction2a.position.x == manager.find(7).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction2a.order == 1, 'Prediction order should be 1'); + + console.log('\tAdded as child of node 5 and dropped at (375, 45):'); + const prediction2b = manager.predict(5, null, { x: 375, y: 45 }); + this._plotPrediction(graph2, prediction2b); + $assert( + prediction2b.position.y > manager.find(8).getPosition().y + && prediction2b.position.y < manager.find(11).getPosition().y + && prediction2b.position.x == manager.find(7).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction2b.order == 2, 'Prediction order should be 2'); + + console.log('\tAdded as child of node 5 and dropped at (375, 45):'); + const prediction2c = manager.predict(5, null, { x: 375, y: 65 }); + this._plotPrediction(graph2, prediction2c); + $assert( + prediction2c.position.y > manager.find(11).getPosition().y + && prediction2c.position.x == manager.find(11).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction2c.order == 3, 'Prediction order should be 3'); + + // Graph 3 + const graph3 = manager.plot('testSymmetricPredict3', { width: 1000, height: 400 }); + + console.log('\tAdded as child of node 3 and dropped at (280, 45):'); + const prediction3a = manager.predict(3, null, { x: 280, y: 45 }); + this._plotPrediction(graph3, prediction3a); + $assert( + prediction3a.position.y > manager.find(5).getPosition().y + && prediction3a.position.y < manager.find(6).getPosition().y + && prediction3a.position.x == manager.find(5).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction3a.order == 2, 'Prediction order should be 2'); + + console.log('\tAdded as child of node 3 and dropped at (255, 110):'); + const prediction3b = manager.predict(3, null, { x: 255, y: 110 }); + this._plotPrediction(graph3, prediction3b); + $assert( + prediction3b.position.y > manager.find(6).getPosition().y + && prediction3b.position.x == manager.find(6).getPosition().x, + 'Prediction incorrectly positioned', + ); + $assert(prediction3b.order == 3, 'Prediction order should be 3'); + + // Graph 4 + console.log('\tAdded as child of node 2 and dropped at (-260, 0):'); + const graph4 = manager.plot('testSymmetricPredict4', { width: 1000, height: 400 }); + const prediction4 = manager.predict(2, null, { x: -260, y: 0 }); + this._plotPrediction(graph4, prediction4); + $assert( + prediction4.position.y > manager.find(9).getPosition().y + && prediction4.position.y < manager.find(10).getPosition().y + && prediction4.position.x == manager.find(9).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction4.order == 1, 'Prediction order should be 1'); + + // Graph 5 + console.log('\tPredict nodes added with no position:'); + const graph5 = manager.plot('testSymmetricPredict5', { width: 1000, height: 400 }); + const prediction5a = manager.predict(1, null, null); + this._plotPrediction(graph5, prediction5a); + $assert( + prediction5a.position.y == manager.find(1).getPosition().y + && prediction5a.position.x > manager.find(1).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction5a.order == 0, 'Prediction order should be 0'); + + const prediction5b = manager.predict(2, null, null); + this._plotPrediction(graph5, prediction5b); + $assert( + prediction5b.position.y > manager.find(10).getPosition().y + && prediction5b.position.x < manager.find(2).getPosition().x + && prediction5b.position.x == manager.find(10).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction5b.order == 2, 'Prediction order should be 2'); + + const prediction5c = manager.predict(3, null, null); + this._plotPrediction(graph5, prediction5c); + $assert( + prediction5c.position.y > manager.find(6).getPosition().y + && prediction5c.position.x > manager.find(3).getPosition().x + && prediction5c.position.x == manager.find(6).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction5c.order == 3, 'Prediction order should be 3'); + + const prediction5d = manager.predict(10, null, null); + this._plotPrediction(graph5, prediction5d); + $assert( + prediction5d.position.y == manager.find(10).getPosition().y + && prediction5d.position.x < manager.find(10).getPosition().x, + 'Prediction is incorrectly positioned', + ); + $assert(prediction5d.order == 0, 'Prediction order should be 0'); + + console.log('OK!\n\n'); + }, + + testSymmetricDragPredict() { + console.log('testSymmetricDragPredict:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 1); + manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0); + manager.layout(); + + // Graph 1 + const graph1 = manager.plot('testSymmetricDragPredict1', { width: 1000, height: 400 }); + + const prediction1a = manager.predict(1, 2, { x: -250, y: -20 }); + this._plotPrediction(graph1, prediction1a); + $assert( + prediction1a.position.x == manager.find(2).getPosition().x + && prediction1a.position.y == manager.find(2).getPosition().y, + 'Prediction position should be the same as node 2', + ); + $assert( + prediction1a.order == manager.find(2).getOrder(), + 'Predicition order should be the same as node 2', + ); + + const prediction1b = manager.predict(1, 2, { x: -250, y: 20 }); + this._plotPrediction(graph1, prediction1b); + $assert( + prediction1b.position.x == manager.find(2).getPosition().x + && prediction1b.position.y == manager.find(2).getPosition().y, + 'Prediction position should be the same as node 2', + ); + $assert( + prediction1b.order == manager.find(2).getOrder(), + 'Predicition order should be the same as node 2', + ); + + const prediction1c = manager.predict(0, 2, { x: -100, y: -20 }); + this._plotPrediction(graph1, prediction1c); + $assert( + prediction1c.position.x == manager.find(1).getPosition().x + && prediction1c.position.y < manager.find(1).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1c.order == 1, 'Prediction order should be 1'); + + const prediction1d = manager.predict(0, 2, { x: -100, y: 20 }); + this._plotPrediction(graph1, prediction1d); + $assert( + prediction1d.position.x == manager.find(1).getPosition().x + && prediction1d.position.y > manager.find(1).getPosition().y, + 'Prediction is incorrectly positioned', + ); + $assert(prediction1d.order == 3, 'Prediction order should be 3'); + + const prediction1e = manager.predict(1, 2, { x: -250, y: 0 }); + this._plotPrediction(graph1, prediction1e); + $assert( + prediction1e.position.x == manager.find(2).getPosition().x + && prediction1e.position.y == manager.find(2).getPosition().y, + 'Prediction position should be the same as node 2', + ); + $assert( + prediction1e.order == manager.find(2).getOrder(), + 'Predicition order should be the same as node 2', + ); + + console.log('OK!\n\n'); + }, +}); + +export default SymmetricTestSuite; diff --git a/packages/mindplot/test/playground/layout/TestSuite.js b/packages/mindplot/test/playground/layout/TestSuite.js new file mode 100644 index 00000000..79b9c104 --- /dev/null +++ b/packages/mindplot/test/playground/layout/TestSuite.js @@ -0,0 +1,592 @@ +/* + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * 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. + */ +import mindplot from '../../../src/mindplot'; + +const TestSuite = new Class({ + Extends: mindplot.layout.ChildrenSorterStrategy, + + initialize() { + $('#basicTest').css('display', 'block'); + // this.testAligned(); + this.testBaselineAligned1(); + this.testBaselineAligned2(); + this.testEvents(); + this.testEventsComplex(); + this.testDisconnect(); + this.testReconnect(); + this.testRemoveNode(); + this.testSize(); + this.testReconnectSingleNode(); + }, + + testAligned() { + console.log('testAligned:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(1, 2, 0); + manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(2, 3, 0); + manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(3, 4, 0); + manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(0, 5, 2); + manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(0, 6, 4); + manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(0, 7, 6); + + manager.layout(); + manager.plot('testAligned', { width: 1200, height: 200 }); + + // Child nodes should be vertically aligned + $assert( + manager.find(1).getPosition().y == manager.find(2).getPosition().y, + 'Child nodes are not vertically aligned', + ); + $assert( + manager.find(1).getPosition().y == manager.find(3).getPosition().y, + 'Child nodes are not vertically aligned', + ); + $assert( + manager.find(1).getPosition().y == manager.find(4).getPosition().y, + 'Child nodes are not vertically aligned', + ); + + // Siblings should be horizontally aligned + $assert( + manager.find(1).getPosition().x == manager.find(5).getPosition().x, + 'Sibling nodes are not horizontally aligned', + ); + $assert( + manager.find(1).getPosition().x == manager.find(6).getPosition().x, + 'Sibling nodes are not horizontally aligned', + ); + $assert( + manager.find(1).getPosition().x == manager.find(7).getPosition().x, + 'Sibling nodes are not horizontally aligned', + ); + + console.log('OK!\n\n'); + }, + + testBaselineAligned1() { + console.log('testBaselineAligned1:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(1, 3, 0); + manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(3, 5, 0); + manager.addNode(6, { width: 140, height: 130 }, position).connectNode(3, 6, 1); + manager.addNode(7, TestSuite.NODE_SIZE, position).connectNode(6, 7, 0); + manager.addNode(8, TestSuite.NODE_SIZE, position).connectNode(7, 8, 0); + manager.addNode(9, TestSuite.NODE_SIZE, position).connectNode(7, 9, 1); + manager.addNode(10, TestSuite.NODE_SIZE, position).connectNode(7, 10, 2); + manager.addNode(11, TestSuite.NODE_SIZE, position).connectNode(7, 11, 3); + manager.addNode(12, TestSuite.NODE_SIZE, position).connectNode(7, 12, 4); + manager.addNode(13, TestSuite.NODE_SIZE, position).connectNode(7, 13, 5); + manager.addNode(14, TestSuite.NODE_SIZE, position).connectNode(7, 14, 6); + manager.addNode(15, TestSuite.NODE_SIZE, position).connectNode(7, 15, 7); + manager.addNode(16, TestSuite.NODE_SIZE, position).connectNode(7, 16, 8); + manager.addNode(17, TestSuite.NODE_SIZE, position).connectNode(7, 17, 9); + manager.addNode(29, TestSuite.NODE_SIZE, position).connectNode(6, 29, 1); + manager.addNode(30, TestSuite.NODE_SIZE, position).connectNode(6, 30, 2); + manager.addNode(31, { width: 100, height: 50 }, position).connectNode(6, 31, 3); + + manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(1, 4, 1); + manager.addNode(18, { width: 80, height: 70 }, position).connectNode(4, 18, 0); + manager.addNode(19, TestSuite.NODE_SIZE, position).connectNode(18, 19, 0); + manager.addNode(20, TestSuite.NODE_SIZE, position).connectNode(19, 20, 0); + manager.addNode(21, TestSuite.NODE_SIZE, position).connectNode(20, 21, 0); + + manager.addNode(2, TestSuite.NODE_SIZE, position).connectNode(0, 2, 1); + manager.addNode(22, TestSuite.NODE_SIZE, position).connectNode(2, 22, 0); + manager.addNode(24, TestSuite.NODE_SIZE, position).connectNode(22, 24, 0); + + manager.addNode(23, { width: 80, height: 50 }, position).connectNode(2, 23, 1); + manager.addNode(25, { width: 80, height: 40 }, position).connectNode(23, 25, 0); + manager.addNode(26, { width: 80, height: 80 }, position).connectNode(25, 26, 0); + manager.addNode(27, TestSuite.NODE_SIZE, position).connectNode(26, 27, 0); + manager.addNode(28, { width: 80, height: 80 }, position).connectNode(27, 28, 0); + + // manager.layout(); + // manager.plot("testBaselineAligned1", {width:1600,height:800}); + + console.log('OK!\n\n'); + }, + + testBaselineAligned2() { + console.log('testBaselineAligned2:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position).connectNode(0, 1, 0); + manager.addNode(2, { width: 130, height: 200 }, position).connectNode(1, 2, 0); + manager.addNode(3, TestSuite.NODE_SIZE, position).connectNode(2, 3, 0); + manager.addNode(4, TestSuite.NODE_SIZE, position).connectNode(2, 4, 1); + manager.addNode(5, TestSuite.NODE_SIZE, position).connectNode(2, 5, 2); + manager.addNode(6, TestSuite.NODE_SIZE, position).connectNode(2, 6, 3); + + manager.layout(); + manager.plot('testBaselineAligned2', { width: 1600, height: 800 }); + + console.log('OK!\n\n'); + }, + + testEvents() { + console.log('testEvents:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, { x: 0, y: 60 }); + manager.connectNode(0, 1, 0); + manager.connectNode(0, 2, 1); + manager.connectNode(1, 3, 0); + + const events = []; + manager.addEvent('change', (event) => { + console.log( + `\tUpdated nodes: {id:${ + event.getId() + }, order: ${ + event.getOrder() + },position: {${ + event.getPosition().x + },${ + event.getPosition().y + }}`, + ); + events.push(event); + }); + manager.layout(true); + manager.plot('testEvents1', { width: 800, height: 200 }); + + console.log('\t--- Layout without changes should not affect the tree ---'); + events.empty(); + manager.layout(true); + manager.plot('testEvents2', { width: 800, height: 200 }); + + // Check no events where fired + $assert(events.length == 0, 'Unnecessary tree updated.'); + + console.log('OK!\n\n'); + }, + + testEventsComplex() { + console.log('testEventsComplex:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, { x: 0, y: 60 }); + manager.connectNode(0, 1, 0); + manager.connectNode(0, 2, 1); + manager.connectNode(0, 3, 2); + manager.connectNode(3, 4, 0); + manager.connectNode(3, 5, 1); + + const events = []; + manager.addEvent('change', (event) => { + console.log( + `\tUpdated nodes: {id:${ + event.getId() + }, order: ${ + event.getOrder() + },position: {${ + event.getPosition().x + },${ + event.getPosition().y + }}`, + ); + events.push(event); + }); + + manager.layout(true); + manager.plot('testEventsComplex1', { width: 800, height: 200 }); + + console.log('\t--- Connect a new node ---'); + + events.empty(); + manager.connectNode(3, 6, 2); + manager.layout(true); + manager.plot('testEventsComplex2', { width: 800, height: 200 }); + + // Check only 4 nodes were repositioned + + console.log(events.length); + + $assert(events.length == 4, 'Only 4 nodes should be repositioned.'); + + console.log('OK!\n\n'); + }, + + testDisconnect() { + console.log('testDisconnect:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 1, 0); + manager.connectNode(1, 2, 0); + manager.connectNode(1, 3, 1); + manager.connectNode(1, 4, 2); + manager.connectNode(4, 5, 0); + manager.connectNode(5, 6, 0); + manager.connectNode(5, 7, 1); + + const events = []; + manager.addEvent('change', (event) => { + const pos = event.getPosition(); + const posStr = pos ? `,position: {${pos.x},${pos.y}` : ''; + const node = manager.find(event.getId()); + console.log( + `\tUpdated nodes: {id:${ + event.getId() + }, order: ${ + event.getOrder() + }${posStr + }}`, + ); + events.push(event); + }); + manager.layout(true); + manager.plot('testDisconnect1', { width: 1200, height: 400 }); + + console.log('--- Disconnect node 2 ---'); + events.empty(); + manager.disconnectNode(2); + manager.layout(true); + manager.plot('testDisconnect2', { width: 1200, height: 400 }); + + // Check that orders have been shifted accordingly + $assert(manager.find(2).getOrder() == 0, 'Node 2 should have order 0'); + $assert(manager.find(3).getOrder() == 0, 'Node 3 should now have order 0'); + $assert(manager.find(4).getOrder() == 1, 'Node 4 should have order 1'); + + console.log('--- Disconnect node 4 ---'); + manager.disconnectNode(4); + manager.layout(true); + manager.plot('testDisconnect3', { width: 1200, height: 400 }); + + // Check that nodes 1 and 3 are now vertically aligned + $assert( + manager.find(1).getPosition().y == manager.find(3).getPosition().y, + 'Nodes 1 and 3 should now be vertically aligned', + ); + + console.log('OK!\n\n'); + }, + + testReconnect() { + console.log('testReconnect:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + manager.addNode(12, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 1, 0); + manager.connectNode(0, 2, 1); + manager.connectNode(0, 3, 2); + manager.connectNode(0, 4, 3); + manager.connectNode(0, 5, 4); + manager.connectNode(1, 6, 0); + manager.connectNode(1, 7, 1); + manager.connectNode(7, 8, 0); + manager.connectNode(8, 9, 0); + manager.connectNode(5, 10, 0); + manager.connectNode(6, 11, 0); + manager.connectNode(6, 12, 1); + + manager.layout(); + manager.plot('testReconnect1', { width: 1200, height: 400 }); + + // Reconnect node 6 to node 4 + console.log('\tReconnect node 6 to node 4'); + manager.disconnectNode(6); + manager.connectNode(4, 6, 0); + manager.layout(); + manager.plot('testReconnect2', { width: 1200, height: 400 }); + + // Check nodes are left aligned correctly + $assert( + manager.find(1).getPosition().y == manager.find(7).getPosition().y, + 'Nodes 1 and 7 should be vertically aligned', + ); + $assert( + manager.find(4).getPosition().y == manager.find(6).getPosition().y, + 'Nodes 4 and 6 should be vertically aligned', + ); + $assert( + manager.find(4).getPosition().x > manager.find(6).getPosition().x, + 'Node 6 and their children should be to the left of node 4', + ); + $assert( + manager.find(6).getPosition().x > manager.find(11).getPosition().x + && manager.find(11).getPosition().x == manager.find(12).getPosition().x, + 'Nodes 11 and 12 should be to the left of node 6 and horizontally aligned', + ); + + console.log('OK!\n\n'); + }, + + testRemoveNode() { + console.log('testRemoveNode:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, TestSuite.NODE_SIZE, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(6, TestSuite.NODE_SIZE, position); + manager.addNode(7, TestSuite.NODE_SIZE, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, TestSuite.NODE_SIZE, position); + + manager.connectNode(0, 1, 0); + manager.connectNode(0, 5, 1); + manager.connectNode(0, 6, 2); + manager.connectNode(0, 7, 3); + manager.connectNode(0, 8, 4); + manager.connectNode(0, 9, 5); + manager.connectNode(1, 2, 0); + manager.connectNode(1, 3, 1); + manager.connectNode(3, 4, 0); + + const events = []; + manager.addEvent('change', (event) => { + const pos = event.getPosition(); + const posStr = pos ? `,position: {${pos.x},${event.getPosition().y}` : ''; + events.push(event); + }); + manager.layout(true); + manager.plot('testRemoveNode1', { width: 1000, height: 200 }); + + console.log('\t--- Remove node 3 ---'); + manager.removeNode(3); + manager.layout(true); + manager.plot('testRemoveNode2', { width: 1000, height: 200 }); + + // Check nodes are correctly aligned and node 6 is aligned with the root node + $assert( + manager.find(1).getPosition().y == manager.find(2).getPosition().y, + 'Nodes 1 and 2 should be vertically algined', + ); + $assert( + manager.find(6).getPosition().y == manager.find(0).getPosition().y, + 'Node 6 should be aligned to the root node', + ); + + console.log('\t--- Remove node 6 ---'); + manager.removeNode(6); + manager.layout(true); + manager.plot('testRemoveNode3', { width: 1000, height: 200 }); + + // Check orders were shifted accordingly + $assert(manager.find(8).getOrder() == 2, 'Node 8 should have order 2'); + + console.log('\t--- Remove node 5 ---'); + manager.removeNode(5); + manager.layout(true); + manager.plot('testRemoveNode4', { width: 1000, height: 200 }); + + // Check orders were shifted accordingly + $assert(manager.find(7).getOrder() == 1, 'Node 7 should have order 1'); + $assert(manager.find(9).getOrder() == 3, 'Node 9 should have order 3'); + + console.log('OK!\n\n'); + }, + + testSize() { + console.log('testSize:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + manager.addNode(1, { width: 60, height: 60 }, position); + manager.addNode(2, TestSuite.NODE_SIZE, position); + manager.addNode(3, { width: 260, height: 30 }, position); + manager.addNode(4, TestSuite.NODE_SIZE, position); + manager.addNode(5, TestSuite.NODE_SIZE, position); + manager.addNode(7, { width: 80, height: 80 }, position); + manager.addNode(8, TestSuite.NODE_SIZE, position); + manager.addNode(9, { width: 30, height: 30 }, position); + manager.addNode(10, TestSuite.NODE_SIZE, position); + manager.addNode(11, TestSuite.NODE_SIZE, position); + manager.addNode(12, { width: 100, height: 70 }, position); + manager.addNode(13, TestSuite.NODE_SIZE, position); + manager.addNode(14, TestSuite.NODE_SIZE, position); + manager.addNode(15, TestSuite.NODE_SIZE, position); + manager.addNode(16, TestSuite.NODE_SIZE, position); + manager.addNode(17, TestSuite.NODE_SIZE, position); + + manager.connectNode(0, 1, 0); + manager.connectNode(1, 16, 0); + manager.connectNode(0, 2, 1); + manager.connectNode(0, 3, 2); + manager.connectNode(0, 4, 3); + manager.connectNode(0, 5, 4); + manager.connectNode(4, 7, 0); + manager.connectNode(7, 15, 0); + manager.connectNode(7, 17, 1); + manager.connectNode(4, 8, 1); + manager.connectNode(8, 9, 0); + manager.connectNode(3, 10, 0); + manager.connectNode(3, 11, 1); + manager.connectNode(9, 12, 0); + manager.connectNode(9, 13, 1); + manager.connectNode(13, 14, 0); + + manager.layout(); + manager.plot('testSize1', { width: 1400, height: 400 }); + + // Check that all enlarged nodes shift children accordingly + $assert( + manager.find(10).getPosition().x > manager.find(3).getPosition().x + && manager.find(10).getPosition().x == manager.find(11).getPosition().x, + 'Nodes 10 and 11 should be horizontally algined and to the right of enlarged node 3', + ); + const xPosNode7 = manager.find(7).getPosition().x; + const xPosNode8 = manager.find(8).getPosition().x; + + manager.updateNodeSize(4, { width: 100, height: 30 }); + manager.layout(); + manager.plot('testSize2', { width: 1400, height: 400 }); + + // Check that all enlarged nodes shift children accordingly + $assert( + manager.find(2).getPosition().x - manager.find(4).getPosition().x == 10, + 'Node 4 should have been shifted by 10', + ); + $assert( + xPosNode7 - manager.find(7).getPosition().x == 20, + 'Node 7 should have been shifted by 20', + ); + $assert( + xPosNode8 - manager.find(8).getPosition().x == 20, + 'Node 8 should have been shifted by 20', + ); + + const graph2 = manager.plot('testSize3', { width: 1400, height: 400 }); + this._plotPrediction(graph2, manager.predict(0, null, { x: -145, y: 400 })); + this._plotPrediction(graph2, manager.predict(9, null, { x: -330, y: 70 })); + this._plotPrediction(graph2, manager.predict(9, null, { x: -330, y: 120 })); + this._plotPrediction(graph2, manager.predict(0, null, { x: 15, y: 20 })); + // TODO(gb): make asserts + + const graph3 = manager.plot('testSize4', { width: 1400, height: 400 }); + this._plotPrediction(graph3, manager.predict(0, null, null)); + this._plotPrediction(graph3, manager.predict(9, null, null)); + this._plotPrediction(graph3, manager.predict(3, null, null)); + this._plotPrediction(graph3, manager.predict(1, null, null)); + // TODO(gb): make asserts + + const yPosNode2 = manager.find(2).getPosition().y; + manager.updateNodeSize(7, { width: 80, height: 120 }); + manager.layout(); + manager.plot('testSize5', { width: 1400, height: 400 }); + + // Check that all enlarged nodes shift children accordingly + $assert( + yPosNode2 - manager.find(2).getPosition().y == 20, + 'Node 2 should have been shifted by 20', + ); + + console.log('OK!\n\n'); + }, + + testReconnectSingleNode() { + console.log('testReconnectSingleNode:'); + const position = { x: 0, y: 0 }; + const manager = new mindplot.layout.LayoutManager(0, TestSuite.ROOT_NODE_SIZE); + + // Prepare a sample graph ... + manager.addNode(1, TestSuite.NODE_SIZE, position); + manager.connectNode(0, 1, 0); + manager.layout(); + const graph = manager.plot('testReconnectSingleNode1', { width: 1000, height: 400 }); + const prediction = manager.predict(0, null, { x: -50, y: 0 }); + this._plotPrediction(graph, prediction); + + // Check prediction is to the left of the root node + $assert( + prediction.position.x < manager.find(0).getPosition().x, + 'Prediction should be to the left of the root node', + ); + $assert(prediction.order == 1, 'Prediction should have order 1'); + + manager.disconnectNode(1); + manager.connectNode(0, 1, 1); + manager.layout(); + manager.plot('testReconnectSingleNode2', { width: 1000, height: 400 }); + + // Check reconnected node is to the left of the root node + $assert( + manager.find(1).getPosition().x < manager.find(0).getPosition().x, + 'Node 1 should now be to the left of the root node', + ); + $assert(manager.find(1).getOrder() == 1, 'Node 1 should now have order 0'); + }, + + _plotPrediction(canvas, prediction) { + if(!canvas) { + console.warn('no canvas in _plotPrediction. Remove this method if plot() not in use'); + return; + } + const { position } = prediction; + const { order } = prediction; + console.log( + `\t\tprediction {order:${ + order + }, position: (${ + position.x + },${ + position.y + })}`, + ); + const cx = position.x + canvas.width / 2 - TestSuite.NODE_SIZE.width / 2; + const cy = position.y + canvas.height / 2 - TestSuite.NODE_SIZE.height / 2; + canvas.rect(cx, cy, TestSuite.NODE_SIZE.width, TestSuite.NODE_SIZE.height); + }, +}); + +(TestSuite.NODE_SIZE = { width: 80, height: 30 }), +(TestSuite.ROOT_NODE_SIZE = { width: 120, height: 40 }); + +export default TestSuite; diff --git a/packages/mindplot/test/playground/layout/context-loader.js b/packages/mindplot/test/playground/layout/context-loader.js new file mode 100644 index 00000000..17bf7399 --- /dev/null +++ b/packages/mindplot/test/playground/layout/context-loader.js @@ -0,0 +1,11 @@ +import TestSuite from './TestSuite'; +import BalancedTestSuite from './BalancedTestSuite'; +import SymmetricTestSuite from './SymmetricTestSuite'; +import FreeTestSuite from './FreeTestSuite'; + +window.addEventListener('DOMContentLoaded', () => { + new TestSuite(); + new BalancedTestSuite(); + new SymmetricTestSuite(); + new FreeTestSuite(); +}); diff --git a/packages/mindplot/test/playground/layout.html b/packages/mindplot/test/playground/layout/index.html similarity index 100% rename from packages/mindplot/test/playground/layout.html rename to packages/mindplot/test/playground/layout/index.html diff --git a/packages/mindplot/test/playground/lib/raphael-min.js b/packages/mindplot/test/playground/layout/lib/raphael-min.js similarity index 100% rename from packages/mindplot/test/playground/lib/raphael-min.js rename to packages/mindplot/test/playground/layout/lib/raphael-min.js diff --git a/packages/mindplot/test/playground/layout/lib/raphael-plugins.js b/packages/mindplot/test/playground/layout/lib/raphael-plugins.js new file mode 100644 index 00000000..c823c9a6 --- /dev/null +++ b/packages/mindplot/test/playground/layout/lib/raphael-plugins.js @@ -0,0 +1,29 @@ +Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) { + color = color || '#999'; + let path = ['M', x, y, 'L', x + w, y, x + w, y + h, x, y + h, x, y]; + const rowHeight = h / hv; + const columnWidth = w / wv; + for (var i = 0; i < hv + 1; i++) { + var offset = y + i * rowHeight; + path = this.path(['M', x, offset, 'L', x + w, y + i * rowHeight]); + if (offset == 0 || offset == h) { + path.attr({ stroke: '#000' }); + } else if (offset == h / 2) { + path.attr({ stroke: '#c00' }); + } else { + path.attr({ stroke: '#999' }); + } + } + for (var i = 0; i < wv + 1; i++) { + var offset = x + i * columnWidth; + path = this.path(['M', offset, y, 'L', x + i * columnWidth, y + h]); + if (offset == 0 || offset == w) { + path.attr({ stroke: '#000' }); + } else if (offset == w / 2) { + path.attr({ stroke: '#c00' }); + } else { + path.attr({ stroke: '#999' }); + } + } + return this.path; +}; diff --git a/packages/mindplot/test/playground/sample.xml b/packages/mindplot/test/playground/layout/sample.xml similarity index 100% rename from packages/mindplot/test/playground/sample.xml rename to packages/mindplot/test/playground/layout/sample.xml diff --git a/packages/mindplot/test/playground/layout/utils.js b/packages/mindplot/test/playground/layout/utils.js new file mode 100755 index 00000000..655292ab --- /dev/null +++ b/packages/mindplot/test/playground/layout/utils.js @@ -0,0 +1,59 @@ +/* eslint-disable func-names */ +/* + * Copyright [2015] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * 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. + */ + +Grid = function (parent, colums, rows) { + const cellSize = '10px'; + this._parent = parent; + this._container = this._createContainer(); + const tbody = $(this._container.firstChild.firstChild); + for (let i = 0; i < rows; i++) { + const trElement = $(''); + for (let j = 0; j < colums; j++) { + const tdElement = $(''); + tdElement.css({ + width: cellSize, + height: cellSize, + borderWidth: '1px', + borderStyle: 'dashed', + borderColor: 'lightsteelblue', + }); + trElement.append(tdElement); + } + tbody.append(trElement); + } +}; + +Grid.prototype.setPosition = function (x, y) { + this._container.style.left = x; + this._container.style.top = y; +}; + +Grid.prototype.render = function () { + $(this._parent).append(this._container); +}; + +Grid.prototype._createContainer = function () { + const result = window.document.createElement('div'); + result.style.tableLayout = 'fixed'; + result.style.borderCollapse = 'collapse'; + result.style.emptyCells = 'show'; + result.style.position = 'absolute'; + result.innerHTML = '
'; + return result; +}; diff --git a/packages/mindplot/test/playground/lib/raphael-plugins.js b/packages/mindplot/test/playground/lib/raphael-plugins.js deleted file mode 100644 index f3a06f4a..00000000 --- a/packages/mindplot/test/playground/lib/raphael-plugins.js +++ /dev/null @@ -1,29 +0,0 @@ -Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) { - color = color || "#999"; - var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y], - rowHeight = h / hv, - columnWidth = w / wv; - for (var i = 0; i < hv + 1; i++) { - var offset = y + i * rowHeight; - path = this.path(["M", x, offset, "L", x + w, y + i * rowHeight]); - if (offset == 0 || offset == h) { - path.attr({stroke: "#000"}); - } else if (offset == h/2) { - path.attr({stroke: "#c00"}) - } else { - path.attr({stroke: "#999"}) - } - } - for (var i = 0; i < wv + 1; i++) { - var offset = x + i * columnWidth; - path = this.path(["M", offset, y, "L", x + i * columnWidth, y + h]); - if (offset == 0 || offset == w) { - path.attr({stroke: "#000"}); - } else if (offset == w/2) { - path.attr({stroke: "#c00"}) - } else { - path.attr({stroke: "#999"}) - } - } - return this.path; -}; \ No newline at end of file diff --git a/packages/mindplot/test/playground/map-render/bootstrap/BootstrapDialog.Request.js b/packages/mindplot/test/playground/map-render/bootstrap/BootstrapDialog.Request.js new file mode 100644 index 00000000..4f12b859 --- /dev/null +++ b/packages/mindplot/test/playground/map-render/bootstrap/BootstrapDialog.Request.js @@ -0,0 +1,49 @@ +BootstrapDialog.Request = new Class({ + + Extends: BootstrapDialog, + + initialize: function(url, title, options) { + this.parent(title, options); + this.requestOptions = {}; + this.requestOptions.cache = false; + var me = this; + this.requestOptions.fail = function(xhr) { + // Intercept form requests ... + console.log("Failure:"); + console.log(xhr); + }; + + this.requestOptions.success = function() { + // Intercept form requests ... + var forms = me._native.find('form'); + _.each(forms, function(form) { + $(form).on('submit', function(event) { + // Intercept form ... + me.requestOptions.url = form.action; + me.requestOptions.method = form.method ? form.method : 'post'; + $.ajax(me.requestOptions); + event.stopPropagation(); + return false; + }); + }); + }; + + this._native.find('.modal-body').load(url, function () { + me.acceptButton.unbind('click').click(function () { + submitDialogForm(); + }); + me._native.on('hidden.bs.modal', function () { + $(this).remove(); + }); + me.show(); + }); + }, + + onDialogShown: function() { + if (typeof(onDialogShown) == "function") { + onDialogShown(); + } + } + + +}); diff --git a/packages/mindplot/test/playground/map-render/bootstrap/BootstrapDialog.js b/packages/mindplot/test/playground/map-render/bootstrap/BootstrapDialog.js new file mode 100644 index 00000000..83f37aef --- /dev/null +++ b/packages/mindplot/test/playground/map-render/bootstrap/BootstrapDialog.js @@ -0,0 +1,111 @@ +var BootstrapDialog = new Class({ + Implements: Options, + + options: { + cancelButton: false, + closeButton: false, + acceptButton: true, + removeButton:false, + errorMessage: false, + onEventData:{} + }, + + initialize: function (title, options) { + this.setOptions(options); + this.options.onEventData.dialog = this; + this._native = $('').append(''); + var content = $(''); + var header = this._buildHeader(title); + if (header) { + content.append(header); + } + var body = $(''); + if(this.options.errorMessage){ + var error = $('
'); + error.hide(); + body.append(error); + } + content.append(body); + var footer = this._buildFooter(); + if (footer) { + content.append(footer); + } + this._native.find(".modal-dialog").append(content); + this._native.on('hidden.bs.modal', function() { + $(this).remove(); + }); + this._native.on('shown.bs.modal', this.onDialogShown); + }, + + _buildFooter: function() { + var footer = null; + if (this.options.acceptButton || this.options.removeButton || this.options.cancelButton) { + footer = $('