From e1e7b58e371c86a82858df8b99a954447d782b4d Mon Sep 17 00:00:00 2001
From: Tomas Prochazka
Date: Wed, 23 Mar 2016 14:58:32 +0100
Subject: [PATCH 1/7] nodeHeight can now be a function
---
dist/labella-extra.js | 84 ++++++++++---
dist/labella-extra.min.js | 2 +-
dist/labella.js | 97 +++++++++++----
dist/labella.min.js | 2 +-
examples/basic_down.html | 3 +-
examples/basic_left.html | 3 +-
examples/basic_right.html | 3 +-
examples/basic_up.html | 3 +-
examples/with_flex_height.html | 213 +++++++++++++++++++++++++++++++++
examples/with_text.html | 3 +-
examples/with_text2.html | 3 +-
src/core/renderer.js | 110 +++++++++++++----
12 files changed, 458 insertions(+), 68 deletions(-)
create mode 100644 examples/with_flex_height.html
diff --git a/dist/labella-extra.js b/dist/labella-extra.js
index 7dc97fc..3b9f316 100644
--- a/dist/labella-extra.js
+++ b/dist/labella-extra.js
@@ -95,6 +95,7 @@ return /******/ (function(modules) { // webpackBootstrap
// return negative if overlap
+
_createClass(Node, [{
key: 'distanceFrom',
value: function distanceFrom(node) {
@@ -1822,11 +1823,13 @@ return /******/ (function(modules) { // webpackBootstrap
var helper = __webpack_require__(4);
function Renderer(options) {
+ console.log(options.nodeHeight);
this.options = helper.extend({
layerGap: 60,
nodeHeight: 10,
direction: 'down'
}, options);
+ console.log(this.options);
}
function lineTo(point) {
@@ -1859,30 +1862,31 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.getWaypoints = function (node) {
var options = this.options;
+ var nodeHeight = typeof options.nodeHeight === "function" ? options.nodeHeight(node.data) : options.nodeHeight;
var direction = options.direction;
var hops = node.getPathFromRoot();
- var gap = options.nodeHeight + options.layerGap;
+ var gap = nodeHeight + options.layerGap;
if (direction === 'left') {
return [[[0, hops[0].idealPos]]].concat(hops.map(function (hop, level) {
var xPos = gap * (level + 1) * -1;
- return [[xPos + options.nodeHeight, hop.currentPos], [xPos, hop.currentPos]];
+ return [[xPos + nodeHeight, hop.currentPos], [xPos, hop.currentPos]];
}));
} else if (direction === 'right') {
return [[[0, hops[0].idealPos]]].concat(hops.map(function (hop, level) {
var xPos = gap * (level + 1);
- return [[xPos - options.nodeHeight, hop.currentPos], [xPos, hop.currentPos]];
+ return [[xPos - nodeHeight, hop.currentPos], [xPos, hop.currentPos]];
}));
} else if (direction === 'up') {
return [[[hops[0].idealPos, 0]]].concat(hops.map(function (hop, level) {
var yPos = gap * (level + 1) * -1;
- return [[hop.currentPos, yPos + options.nodeHeight], [hop.currentPos, yPos]];
+ return [[hop.currentPos, yPos + nodeHeight], [hop.currentPos, yPos]];
}));
} else {
return [[[hops[0].idealPos, 0]]].concat(hops.map(function (hop, level) {
var yPos = gap * (level + 1);
- return [[hop.currentPos, yPos - options.nodeHeight], [hop.currentPos, yPos]];
+ return [[hop.currentPos, yPos - nodeHeight], [hop.currentPos, yPos]];
}));
}
};
@@ -1890,44 +1894,86 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.layout = function (nodes) {
var options = this.options;
+ if (typeof options.nodeHeight === 'function') {
+ var gaps = [];
+ nodes.forEach(function (node, index) {
+ gaps[index] = options.layerGap + options.nodeHeight(node.data);
+ });
+ }
+
var gap = options.layerGap + options.nodeHeight;
switch (options.direction) {
case 'left':
- nodes.forEach(function (node) {
- var pos = node.getLayerIndex() * gap + options.layerGap;
- node.x = -pos - options.nodeHeight;
+ nodes.forEach(function (node, index) {
+ var pos = 0;
+ if (gaps) {
+ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ } else {
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
+ if (typeof options.nodeHeight === 'function') {
+ node.x = -pos - options.nodeHeight(node.data);
+ } else {
+ node.x = -pos - options.nodeHeight;
+ }
node.y = node.currentPos;
- node.dx = options.nodeHeight;
+ node.dx = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
node.dy = node.width;
});
break;
case 'right':
- nodes.forEach(function (node) {
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function (node, index) {
+ var pos = 0;
+ if (gaps) {
+ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ } else {
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = pos;
node.y = node.currentPos;
- node.dx = options.nodeHeight;
+ node.dx = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
node.dy = node.width;
});
break;
case 'up':
- nodes.forEach(function (node) {
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function (node, index) {
+ var pos = 0;
+ if (gaps) {
+ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ } else {
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = node.currentPos;
- node.y = -pos - options.nodeHeight;
+ if (typeof options.nodeHeight === 'function') {
+ node.y = -pos - options.nodeHeight(node.data);
+ } else {
+ node.y = -pos - options.nodeHeight;
+ }
node.dx = node.width;
- node.dy = options.nodeHeight;
+ node.dy = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
});
break;
default:
case 'down':
- nodes.forEach(function (node) {
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function (node, index) {
+ var pos = 0;
+ if (gaps) {
+ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ } else {
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = node.currentPos;
node.y = pos;
node.dx = node.width;
- node.dy = options.nodeHeight;
+ node.dy = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
+ if (typeof node.dy !== 'number') {
+ console.error('It seems like your nodeHeight function does not' + 'return a number. Instead it returns ' + node.dy + '. A fallback' + 'value has been used instead.');
+ }
});
break;
}
diff --git a/dist/labella-extra.min.js b/dist/labella-extra.min.js
index 6f9e784..f04155f 100644
--- a/dist/labella-extra.min.js
+++ b/dist/labella-extra.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports={Node:n(1),Force:n(2),Distributor:n(3),Renderer:n(10),metrics:n(11),util:n(12)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},u=function(t){var e={},n=i.extend({},s),u=new r,a=[],c=null;return e.nodes=function(t){return arguments.length?(a=t,c=[t],e):a},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,u.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return a.forEach(function(t){t.removeStub()}),c=u.distribute(a),c.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};u.DEFAULT_OPTIONS=s,t.exports=u},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,u=o-1;u>=0;u--)s=s.createStub(t.stubWidth),i[u].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var u=o.concat(),a=s;for(o=[];u.length>2&&a>i;){u.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=u.shift();a-=c.width,a+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}r.push(u),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var h=r.length-1;h>=1;h--)for(var f=r[h],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function u(){var t,e,r,i,a,c,h=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},f=2):("object"!==("undefined"==typeof h?"undefined":n(h))&&"function"!=typeof h||null==h)&&(h={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(a=o(i)))?(a?(a=!1,c=r&&o(r)?r:[]):c=r&&s(r)?r:{},h[e]=u(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new u(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),u=this.pointTree;s>=0&&u[s][0]==t;)s--;var a=this.pointTree.bsearch([e,null]);if(a>=0){for(var c=u.length-1;c>=a&&u[a][0]<=e;)a++;u.slice(s+1,a).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function u(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function a(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new a(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},u.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},a.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(u,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],a=1;at;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var u=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var u=r[s];if(!u.unsatisfiable){var a=u.slack();if((u.equality||e>a)&&(e=a,n=u,o=s,u.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=a,t.exports=n},function(t,e,n){"use strict";function r(t){this.options=c.extend({layerGap:60,nodeHeight:10,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function u(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function a(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var c=n(4);r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=u,r.hCurveBetween=a,r.prototype.getWaypoints=function(t){var e=this.options,n=e.direction,r=t.getPathFromRoot(),i=e.nodeHeight+e.layerGap;return"left"===n?[[[0,r[0].idealPos]]].concat(r.map(function(t,n){var r=i*(n+1)*-1;return[[r+e.nodeHeight,t.currentPos],[r,t.currentPos]]})):"right"===n?[[[0,r[0].idealPos]]].concat(r.map(function(t,n){var r=i*(n+1);return[[r-e.nodeHeight,t.currentPos],[r,t.currentPos]]})):"up"===n?[[[r[0].idealPos,0]]].concat(r.map(function(t,n){var r=i*(n+1)*-1;return[[t.currentPos,r+e.nodeHeight],[t.currentPos,r]]})):[[[r[0].idealPos,0]]].concat(r.map(function(t,n){var r=i*(n+1);return[[t.currentPos,r-e.nodeHeight],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options,n=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t){var r=t.getLayerIndex()*n+e.layerGap;t.x=-r-e.nodeHeight,t.y=t.currentPos,t.dx=e.nodeHeight,t.dy=t.width});break;case"right":t.forEach(function(t){var r=t.getLayerIndex()*n+e.layerGap;t.x=r,t.y=t.currentPos,t.dx=e.nodeHeight,t.dy=t.width});break;case"up":t.forEach(function(t){var r=t.getLayerIndex()*n+e.layerGap;t.x=t.currentPos,t.y=-r-e.nodeHeight,t.dx=t.width,t.dy=e.nodeHeight});break;default:case"down":t.forEach(function(t){var r=t.getLayerIndex()*n+e.layerGap;t.x=t.currentPos,t.y=r,t.dx=t.width,t.dy=e.nodeHeight})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(a(t[t.length-1],e[0])),n=i)return t.width;if(e>r)return e-r}if(s.isDefined(n)){if(r>=n)return t.width;if(i>n)return i-n}return 0})})},u.overDensitySpace=function(t,e,n){var i=arguments.length<=3||void 0===arguments[3]?0:arguments[3];if(0===t.length||!s.isDefined(e)||!s.isDefined(n))return 0;var o=e*n,u=r(t);return s.sum(u,function(t){var e=s.sum(t,function(t){return t.width+i})-i;return o>=e?0:e-o})},u.overlapCount=function(t,e){if(0===t.length)return 0;var n=r(t);return s.sum(n,function(t){for(var n=0,r=0;ri?Math.abs(i):0}return e})/i(e)},u.weightedAllocation=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*t.filter(function(t){return!t.isStub()}).length})},u.weightedAllocatedSpace=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*s.sum(t,function(t){return t.width})})},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=n(4);t.exports={generateNodes:function(t,e){var n=[];e=i.extend({},{minWidth:20,maxWidth:20,minPos:0,maxPos:800},e);for(var o=e.maxPos-e.minPos,s=e.maxWidth-e.minWidth,u=0;t>u;u++)n.push(new r(Math.floor(Math.random()*o)+e.minPos,Math.floor(Math.random()*s)+e.minWidth));return n}}}])});
\ No newline at end of file
+!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports={Node:n(1),Force:n(2),Distributor:n(3),Renderer:n(10),metrics:n(11),util:n(12)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},u=function(t){var e={},n=i.extend({},s),u=new r,a=[],c=null;return e.nodes=function(t){return arguments.length?(a=t,c=[t],e):a},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,u.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return a.forEach(function(t){t.removeStub()}),c=u.distribute(a),c.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};u.DEFAULT_OPTIONS=s,t.exports=u},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,u=o-1;u>=0;u--)s=s.createStub(t.stubWidth),i[u].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var u=o.concat(),a=s;for(o=[];u.length>2&&a>i;){u.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=u.shift();a-=c.width,a+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}r.push(u),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var h=r.length-1;h>=1;h--)for(var f=r[h],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function u(){var t,e,r,i,a,c,h=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},f=2):("object"!==("undefined"==typeof h?"undefined":n(h))&&"function"!=typeof h||null==h)&&(h={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(a=o(i)))?(a?(a=!1,c=r&&o(r)?r:[]):c=r&&s(r)?r:{},h[e]=u(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new u(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),u=this.pointTree;s>=0&&u[s][0]==t;)s--;var a=this.pointTree.bsearch([e,null]);if(a>=0){for(var c=u.length-1;c>=a&&u[a][0]<=e;)a++;u.slice(s+1,a).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function u(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function a(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new a(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},u.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},a.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(u,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],a=1;at;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var u=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var u=r[s];if(!u.unsatisfiable){var a=u.slack();if((u.equality||e>a)&&(e=a,n=u,o=s,u.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=a,t.exports=n},function(t,e,n){"use strict";function r(t){console.log(t.nodeHeight),this.options=c.extend({layerGap:60,nodeHeight:10,direction:"down"},t),console.log(this.options)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function u(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function a(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var c=n(4);r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=u,r.hCurveBetween=a,r.prototype.getWaypoints=function(t){var e=this.options,n="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options;if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var r=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,"function"==typeof e.nodeHeight?t.x=-o-e.nodeHeight(t.data):t.x=-o-e.nodeHeight,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"right":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=o,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"up":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,"function"==typeof e.nodeHeight?t.y=-o-e.nodeHeight(t.data):t.y=-o-e.nodeHeight,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight});break;default:case"down":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,t.y=o,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,"number"!=typeof t.dy&&console.error("It seems like your nodeHeight function does notreturn a number. Instead it returns "+t.dy+". A fallbackvalue has been used instead.")})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(a(t[t.length-1],e[0])),n=i)return t.width;if(e>r)return e-r}if(s.isDefined(n)){if(r>=n)return t.width;if(i>n)return i-n}return 0})})},u.overDensitySpace=function(t,e,n){var i=arguments.length<=3||void 0===arguments[3]?0:arguments[3];if(0===t.length||!s.isDefined(e)||!s.isDefined(n))return 0;var o=e*n,u=r(t);return s.sum(u,function(t){var e=s.sum(t,function(t){return t.width+i})-i;return o>=e?0:e-o})},u.overlapCount=function(t,e){if(0===t.length)return 0;var n=r(t);return s.sum(n,function(t){for(var n=0,r=0;ri?Math.abs(i):0}return e})/i(e)},u.weightedAllocation=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*t.filter(function(t){return!t.isStub()}).length})},u.weightedAllocatedSpace=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*s.sum(t,function(t){return t.width})})},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=n(4);t.exports={generateNodes:function(t,e){var n=[];e=i.extend({},{minWidth:20,maxWidth:20,minPos:0,maxPos:800},e);for(var o=e.maxPos-e.minPos,s=e.maxWidth-e.minWidth,u=0;t>u;u++)n.push(new r(Math.floor(Math.random()*o)+e.minPos,Math.floor(Math.random()*s)+e.minWidth));return n}}}])});
\ No newline at end of file
diff --git a/dist/labella.js b/dist/labella.js
index 69e7271..01e838a 100644
--- a/dist/labella.js
+++ b/dist/labella.js
@@ -92,6 +92,7 @@ return /******/ (function(modules) { // webpackBootstrap
// return negative if overlap
+
_createClass(Node, [{
key: 'distanceFrom',
value: function distanceFrom(node) {
@@ -1814,16 +1815,30 @@ return /******/ (function(modules) { // webpackBootstrap
/* 10 */
/***/ function(module, exports, __webpack_require__) {
- 'use strict';
+ "use strict";
var helper = __webpack_require__(4);
+ var DEFAULT_NODE_HEIGHT = 10;
+
function Renderer(options) {
+ if (typeof options.nodeHeight === "function") {
+ var currentNodeHeightFunction = options.nodeHeight;
+ options.nodeHeight = function (nodeData) {
+ var retValue = currentNodeHeightFunction(nodeData);
+ if (typeof retValue !== "number") {
+ console.error('It seems like your nodeHeight function does NOT ' + 'return a number. Instead it returns ' + retValue + '. A fallback ' + 'value has been used instead. The following console.log shows ' + 'the input data of a node: ');
+ console.log(nodeData);
+ return DEFAULT_NODE_HEIGHT;
+ } else return retValue;
+ };
+ }
this.options = helper.extend({
layerGap: 60,
- nodeHeight: 10,
+ nodeHeight: DEFAULT_NODE_HEIGHT,
direction: 'down'
}, options);
+ console.log(this.options);
}
function lineTo(point) {
@@ -1856,30 +1871,31 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.getWaypoints = function (node) {
var options = this.options;
+ var nodeHeight = typeof options.nodeHeight === "function" ? options.nodeHeight(node.data) : options.nodeHeight;
var direction = options.direction;
var hops = node.getPathFromRoot();
- var gap = options.nodeHeight + options.layerGap;
+ var gap = nodeHeight + options.layerGap;
if (direction === 'left') {
return [[[0, hops[0].idealPos]]].concat(hops.map(function (hop, level) {
var xPos = gap * (level + 1) * -1;
- return [[xPos + options.nodeHeight, hop.currentPos], [xPos, hop.currentPos]];
+ return [[xPos + nodeHeight, hop.currentPos], [xPos, hop.currentPos]];
}));
} else if (direction === 'right') {
return [[[0, hops[0].idealPos]]].concat(hops.map(function (hop, level) {
var xPos = gap * (level + 1);
- return [[xPos - options.nodeHeight, hop.currentPos], [xPos, hop.currentPos]];
+ return [[xPos - nodeHeight, hop.currentPos], [xPos, hop.currentPos]];
}));
} else if (direction === 'up') {
return [[[hops[0].idealPos, 0]]].concat(hops.map(function (hop, level) {
var yPos = gap * (level + 1) * -1;
- return [[hop.currentPos, yPos + options.nodeHeight], [hop.currentPos, yPos]];
+ return [[hop.currentPos, yPos + nodeHeight], [hop.currentPos, yPos]];
}));
} else {
return [[[hops[0].idealPos, 0]]].concat(hops.map(function (hop, level) {
var yPos = gap * (level + 1);
- return [[hop.currentPos, yPos - options.nodeHeight], [hop.currentPos, yPos]];
+ return [[hop.currentPos, yPos - nodeHeight], [hop.currentPos, yPos]];
}));
}
};
@@ -1887,44 +1903,83 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.layout = function (nodes) {
var options = this.options;
+ if (typeof options.nodeHeight === 'function') {
+ var gaps = [];
+ nodes.forEach(function (node, index) {
+ gaps[index] = options.layerGap + options.nodeHeight(node.data);
+ });
+ }
+
var gap = options.layerGap + options.nodeHeight;
switch (options.direction) {
case 'left':
- nodes.forEach(function (node) {
- var pos = node.getLayerIndex() * gap + options.layerGap;
- node.x = -pos - options.nodeHeight;
+ nodes.forEach(function (node, index) {
+ var pos = 0;
+ if (gaps) {
+ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ } else {
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
+ if (typeof options.nodeHeight === 'function') {
+ node.x = -pos - options.nodeHeight(node.data);
+ } else {
+ node.x = -pos - options.nodeHeight;
+ }
node.y = node.currentPos;
- node.dx = options.nodeHeight;
+ node.dx = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
node.dy = node.width;
});
break;
case 'right':
- nodes.forEach(function (node) {
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function (node, index) {
+ var pos = 0;
+ if (gaps) {
+ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ } else {
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = pos;
node.y = node.currentPos;
- node.dx = options.nodeHeight;
+ node.dx = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
node.dy = node.width;
});
break;
case 'up':
- nodes.forEach(function (node) {
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function (node, index) {
+ var pos = 0;
+ if (gaps) {
+ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ } else {
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = node.currentPos;
- node.y = -pos - options.nodeHeight;
+ if (typeof options.nodeHeight === 'function') {
+ node.y = -pos - options.nodeHeight(node.data);
+ } else {
+ node.y = -pos - options.nodeHeight;
+ }
node.dx = node.width;
- node.dy = options.nodeHeight;
+ node.dy = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
});
break;
default:
case 'down':
- nodes.forEach(function (node) {
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function (node, index) {
+ var pos = 0;
+ if (gaps) {
+ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ } else {
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = node.currentPos;
node.y = pos;
node.dx = node.width;
- node.dy = options.nodeHeight;
+ node.dy = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
});
break;
}
diff --git a/dist/labella.min.js b/dist/labella.min.js
index 591d8dd..2afae80 100644
--- a/dist/labella.min.js
+++ b/dist/labella.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";t.exports={Node:r(1),Force:r(2),Distributor:r(3),Renderer:r(10)}},function(t,e){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var n=function(){function t(t,e){for(var r=0;r=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var r=new t(this.idealPos,e,this.data);return r.currentPos=this.currentPos,r.child=this,this.parent=r,r}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var r=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-r),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,r){"use strict";var n=r(3),i=r(4),o=r(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},u=function(t){var e={},r=i.extend({},s),u=new n,a=[],c=null;return e.nodes=function(t){return arguments.length?(a=t,c=[t],e):a},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return r;r=i.extend(r,t);var o=i.pick(r,Object.keys(n.DEFAULT_OPTIONS));return i.isDefined(r.minPos)&&i.isDefined(r.maxPos)?o.layerWidth=r.maxPos-r.minPos:o.layerWidth=null,u.options(o),e},e.options(t),e.compute=function(){var t=i.pick(r,Object.keys(o.DEFAULT_OPTIONS));return a.forEach(function(t){t.removeStub()}),c=u.distribute(a),c.map(function(e,n){e.forEach(function(t){t.layerIndex=n}),r.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};u.DEFAULT_OPTIONS=s,t.exports=u},function(t,e,r){"use strict";var n=r(4),i=r(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=n.extend({},o,t),e.options=function(r){return arguments.length?(t=n.extend(t,r),e):t},e.computeRequiredWidth=function(e){return n.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(r){return t.layerWidth?Math.ceil(e.computeRequiredWidth(r)/e.maxWidthPerLayer()):1};var r={simple:function(r){for(var n=e.estimateRequiredLayers(r),i=[],o=0;n>o;o++)i.push([]);return r.forEach(function(e,r){var o=r%n;i[o].push(e);for(var s=e,u=o-1;u>=0;u--)s=s.createStub(t.stubWidth),i[u].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(r){for(var n=[],i=e.maxWidthPerLayer(),o=r.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var u=o.concat(),a=s;for(o=[];u.length>2&&a>i;){u.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=u.shift();a-=c.width,a+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}n.push(u),s=e.computeRequiredWidth(o)}o.length>0&&n.push(o);for(var h=n.length-1;h>=1;h--)for(var l=n[h],f=0;f=0;v--)d=d.createStub(t.stubWidth),n[v].push(d)}return n}};return e.countIdealOverlaps=function(e){var r=new i(t.layerWidth/2);return e.forEach(function(t){r.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=r.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!n.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(r.hasOwnProperty(t.algorithm))return r[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,r){"use strict";var n={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,r){return e[r]=t[r],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)}};n.extend=r(5),t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=n.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&n.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!r)return!1;var o;for(o in t);return void 0===o||n.call(t,o)};t.exports=function u(){var t,e,n,i,a,c,h=arguments[0],l=1,f=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},l=2):("object"!==("undefined"==typeof h?"undefined":r(h))&&"function"!=typeof h||null==h)&&(h={});f>l;++l)if(t=arguments[l],null!=t)for(e in t)n=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(a=o(i)))?(a?(a=!1,c=n&&o(n)?n:[]):c=n&&s(n)?n:{},h[e]=u(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,r){"use strict";function n(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t[0]-e[0];return r>0?1:0==r?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new u(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,r){return t?et.idx?(t.ends.every(function(t){var n=t.end>=e;return n&&r.push(t.result()),n}),o.call(this,t.right,e,r)):void t.starts.map(function(t){r.push(t.result())}):void 0}function s(t,e,r){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var n={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){n[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),u=this.pointTree;s>=0&&u[s][0]==t;)s--;var a=this.pointTree.bsearch([e,null]);if(a>=0){for(var c=u.length-1;c>=a&&u[a][0]<=e;)a++;u.slice(s+1,a).forEach(function(t){var e=t[1];n[e]=!0},this),Object.keys(n).forEach(function(n){var i=this.intervalHash[n];r.push(i.result(t,e))},this)}}function u(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.start-e.start;return r>0?1:0==r?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.end-e.end;return 0>r?1:0==r?0:-1}})}function a(t,e,r,n){if(this.id=e,this.start=t[r],this.end=t[n],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=r(7);n.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var r=new a(t,e,this.startKey,this.endKey);this.pointTree.insert([r.start,e]),this.pointTree.insert([r.end,e]),this.intervalHash[e]=r,this._autoIncrement++,i.call(this,this.root,r)},n.prototype.search=function(t,e){var r=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,r);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,r)}return r},n.prototype.remove=function(t){},u.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},a.prototype.result=function(t,e){var r={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var n=Math.max(this.start,t),i=Math.min(this.end,e),o=i-n;r.rate1=o/(e-t),r.rate2=o/(this.end-this.start)}return r},t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function i(){var t=null,e={},n=arguments;["0","1"].forEach(function(i){var o=n[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":r(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};n.create=function(t,e){return new n(t,e)},n.prototype=new Array,n.prototype.constructor=Array.prototype.constructor,n.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},n.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},n.prototype.remove=function(t){return this.splice(t,1),this},n.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,r=0,n=this.length;n-r>1;){e=Math.floor((r+n)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?r=e:n=e}return 0==r&&this._compare(this[0],t)>0?-1:r},n.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var r=e;if(-1==r||this._compare(this[r],t)<0)return r+1=1&&0==this._compare(this[r-1],t);)r--;return r},n.prototype.keys=function(t,e){var r=[];null==e&&(e=this.bsearch(t));for(var n=e;n>=0&&0==this._compare(this[n],t);)r.push(n),n--;var i=this.length;for(n=e+1;i>n&&0==this._compare(this[n],t);)r.push(n),n++;return r.length?r:null},n.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,r){return 0==r||0!=this._compare(this[r-1],t)?null:r-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},n.prototype.toArray=function(){return this.slice()},n.prototype._filter=function(t,e){return!0},n.compares={number:function(t,e){var r=t-e;return r>0?1:0==r?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},n.prototype._compare=n.compares.string,t.exports=n},function(t,e,r){"use strict";function n(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(u,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var r=t.targetPos-e.targetPos;if(0!==r)return r;var n=t.isStub()-e.isStub();return 0!==n?n:t.index-e.index});for(var r=t.map(n),i=[],a=1;at;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,r){var n=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=n.compute_lm(o,t,r);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),r(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var r=this;t.visitNeighbours(e,function(e,n){n.offset=t.offset+(n===e.right?e.gap:-e.gap),r.addVariable(n),r.populateSplitBlock(n,t)})},t.prototype.traverse=function(t,e,r,n){var i=this;void 0===r&&(r=this.vars[0]),void 0===n&&(n=null),r.visitNeighbours(n,function(n,o){e.push(t(n)),i.traverse(t,e,o,r)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmn;++n){var o=t.vars[n];o.offset+=r,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var r=this.vars[e],n=r.position()-r.desiredPosition;t+=n*n*r.weight}return t},t}();r.Block=s;var u=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var r=new s(t[e]);this.list[e]=r,r.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,r=this.list[e];this.list.length=e,t!==r&&(this.list[t.blockInd]=r,r.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,r=t.right.block,n=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var u=n[s];if(!u.unsatisfiable){var a=u.slack();if((u.equality||e>a)&&(e=a,r=u,o=s,u.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();r.Solver=a,t.exports=r},function(t,e,r){"use strict";function n(t){this.options=c.extend({layerGap:60,nodeHeight:10,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,r){return"C "+t.join(" ")+" "+e.join(" ")+" "+r.join(" ")}function u(t,e){var r=(t[1]+e[1])/2;return s([t[0],r],[e[0],r],e)}function a(t,e){var r=(t[0]+e[0])/2;return s([r,t[1]],[r,e[1]],e)}var c=r(4);n.lineTo=i,n.moveTo=o,n.curveTo=s,n.vCurveBetween=u,n.hCurveBetween=a,n.prototype.getWaypoints=function(t){var e=this.options,r=e.direction,n=t.getPathFromRoot(),i=e.nodeHeight+e.layerGap;return"left"===r?[[[0,n[0].idealPos]]].concat(n.map(function(t,r){var n=i*(r+1)*-1;return[[n+e.nodeHeight,t.currentPos],[n,t.currentPos]]})):"right"===r?[[[0,n[0].idealPos]]].concat(n.map(function(t,r){var n=i*(r+1);return[[n-e.nodeHeight,t.currentPos],[n,t.currentPos]]})):"up"===r?[[[n[0].idealPos,0]]].concat(n.map(function(t,r){var n=i*(r+1)*-1;return[[t.currentPos,n+e.nodeHeight],[t.currentPos,n]]})):[[[n[0].idealPos,0]]].concat(n.map(function(t,r){var n=i*(r+1);return[[t.currentPos,n-e.nodeHeight],[t.currentPos,n]]}))},n.prototype.layout=function(t){var e=this.options,r=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t){var n=t.getLayerIndex()*r+e.layerGap;t.x=-n-e.nodeHeight,t.y=t.currentPos,t.dx=e.nodeHeight,t.dy=t.width});break;case"right":t.forEach(function(t){var n=t.getLayerIndex()*r+e.layerGap;t.x=n,t.y=t.currentPos,t.dx=e.nodeHeight,t.dy=t.width});break;case"up":t.forEach(function(t){var n=t.getLayerIndex()*r+e.layerGap;t.x=t.currentPos,t.y=-n-e.nodeHeight,t.dx=t.width,t.dy=e.nodeHeight});break;default:case"down":t.forEach(function(t){var n=t.getLayerIndex()*r+e.layerGap;t.x=t.currentPos,t.y=n,t.dx=t.width,t.dy=e.nodeHeight})}return t},n.prototype.generatePath=function(t){var e=this.options,r=e.direction,n=this.getWaypoints(t,r),s=[o(n[0][0])];return"left"===r||"right"===r?n.reduce(function(t,e,r){return s.push(a(t[t.length-1],e[0])),r=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},a=function(t){var e={},n=i.extend({},s),a=new r,u=[],h=null;return e.nodes=function(t){return arguments.length?(u=t,h=[t],e):u},e.getLayers=function(){return h},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,a.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return u.forEach(function(t){t.removeStub()}),h=a.distribute(u),h.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};a.DEFAULT_OPTIONS=s,t.exports=a},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,a=o-1;a>=0;a--)s=s.createStub(t.stubWidth),i[a].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var a=o.concat(),u=s;for(o=[];a.length>2&&u>i;){a.sort(function(t,e){return e.overlapCount-t.overlapCount});var h=a.shift();u-=h.width,u+=t.stubWidth,h.overlaps.forEach(function(t){t.overlapCount--}),o.push(h)}r.push(a),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var c=r.length-1;c>=1;c--)for(var f=r[c],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function a(){var t,e,r,i,u,h,c=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof c?(p=c,c=arguments[1]||{},f=2):("object"!==("undefined"==typeof c?"undefined":n(c))&&"function"!=typeof c||null==c)&&(c={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=c[e],i=t[e],c!==i&&(p&&i&&(s(i)||(u=o(i)))?(u?(u=!1,h=r&&o(r)?r:[]):h=r&&s(r)?r:{},c[e]=a(p,h,i)):void 0!==i&&(c[e]=i));return c}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new a(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),a=this.pointTree;s>=0&&a[s][0]==t;)s--;var u=this.pointTree.bsearch([e,null]);if(u>=0){for(var h=a.length-1;h>=u&&a[u][0]<=e;)u++;a.slice(s+1,u).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function a(t){this.idx=t,this.starts=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function u(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var h=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new u(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},a.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},u.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(a,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],u=1;ut;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var a=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var a=r[s];if(!a.unsatisfiable){var u=a.slack();if((a.equality||e>u)&&(e=u,n=a,o=s,a.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=u,t.exports=n},function(t,e,n){"use strict";function r(t){if("function"==typeof t.nodeHeight){var e=t.nodeHeight;t.nodeHeight=function(t){var n=e(t);return"number"!=typeof n?(console.error("It seems like your nodeHeight function does NOT return a number. Instead it returns "+n+". A fallback value has been used instead. The following console.log shows the input data of a node: "),console.log(t),c):n}}this.options=h.extend({layerGap:60,nodeHeight:c,direction:"down"},t),console.log(this.options)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function a(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function u(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var h=n(4),c=10;r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=a,r.hCurveBetween=u,r.prototype.getWaypoints=function(t){var e=this.options,n="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options;if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var r=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,"function"==typeof e.nodeHeight?t.x=-o-e.nodeHeight(t.data):t.x=-o-e.nodeHeight,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"right":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=o,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"up":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,"function"==typeof e.nodeHeight?t.y=-o-e.nodeHeight(t.data):t.y=-o-e.nodeHeight,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight});break;default:case"down":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,t.y=o,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(u(t[t.length-1],e[0])),nLabels should be beautiful.
left |
right |
with text (v) |
- with text (h)
+ with text (h) |
+ with flex height
Please
diff --git a/examples/basic_left.html b/examples/basic_left.html
index ea86c79..df73fad 100644
--- a/examples/basic_left.html
+++ b/examples/basic_left.html
@@ -27,7 +27,8 @@
Labels should be beautiful.
left |
right |
with text (v) |
- with text (h)
+ with text (h) |
+ with flex height
Please
diff --git a/examples/basic_right.html b/examples/basic_right.html
index a6740a6..90c845f 100644
--- a/examples/basic_right.html
+++ b/examples/basic_right.html
@@ -27,7 +27,8 @@
Labels should be beautiful.
left |
right |
with text (v) |
- with text (h)
+ with text (h) |
+ with flex height
Please
diff --git a/examples/basic_up.html b/examples/basic_up.html
index 938a002..b5a9ba0 100644
--- a/examples/basic_up.html
+++ b/examples/basic_up.html
@@ -27,7 +27,8 @@
Labels should be beautiful.
left |
right |
with text (v) |
- with text (h)
+ with text (h) |
+ with flex height
Please
diff --git a/examples/with_flex_height.html b/examples/with_flex_height.html
new file mode 100644
index 0000000..aef31c2
--- /dev/null
+++ b/examples/with_flex_height.html
@@ -0,0 +1,213 @@
+
+
+
+
+
+ Labella.js
+
+
+
+
+
+
+
+
+ Labels should be beautiful.
+
+
+
+
+ See examples:
+ up |
+ down |
+ left |
+ right |
+ with text (v) |
+ with text (h) |
+ with flex height
+
+
You can calculate the height of each node separately based on the content you are about to show.
+
+ Please
+ view source
+ to see how it was implemented.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/with_text.html b/examples/with_text.html
index 3a9a19a..efd1a07 100644
--- a/examples/with_text.html
+++ b/examples/with_text.html
@@ -27,7 +27,8 @@ Labels should be beautiful.
left |
right |
with text (v) |
- with text (h)
+ with text (h) |
+ with flex height
Please
diff --git a/examples/with_text2.html b/examples/with_text2.html
index d51534a..999413f 100644
--- a/examples/with_text2.html
+++ b/examples/with_text2.html
@@ -27,7 +27,8 @@
Labels should be beautiful.
left |
right |
with text (v) |
- with text (h)
+ with text (h) |
+ with flex height
Please
diff --git a/src/core/renderer.js b/src/core/renderer.js
index c53d1e0..194ce0f 100644
--- a/src/core/renderer.js
+++ b/src/core/renderer.js
@@ -1,11 +1,29 @@
const helper = require('./helper.js');
+const DEFAULT_NODE_HEIGHT = 10;
+
function Renderer(options){
+ if(typeof options.nodeHeight === "function"){
+ var currentNodeHeightFunction = options.nodeHeight;
+ options.nodeHeight = function(nodeData){
+ var retValue = currentNodeHeightFunction(nodeData);
+ if(typeof retValue !== "number"){
+ console.error('It seems like your nodeHeight function does NOT ' +
+ 'return a number. Instead it returns ' + retValue + '. A fallback ' +
+ 'value has been used instead. The following console.log shows ' +
+ 'the input data of a node: ');
+ console.log(nodeData);
+ return DEFAULT_NODE_HEIGHT;
+ }
+ else return retValue;
+ };
+ }
this.options = helper.extend({
layerGap: 60,
- nodeHeight: 10,
+ nodeHeight: DEFAULT_NODE_HEIGHT,
direction: 'down'
}, options);
+ console.log(this.options);
}
function lineTo(point){
@@ -46,16 +64,19 @@ Renderer.hCurveBetween = hCurveBetween;
Renderer.prototype.getWaypoints = function(node){
var options = this.options;
+ var nodeHeight = (typeof options.nodeHeight === "function")
+ ? options.nodeHeight(node.data)
+ : options.nodeHeight;
var direction = options.direction;
var hops = node.getPathFromRoot();
- var gap = options.nodeHeight + options.layerGap;
+ var gap = nodeHeight + options.layerGap;
if(direction==='left'){
return [[[0, hops[0].idealPos]]].concat(hops.map(function(hop, level){
var xPos = gap * (level+1) * -1;
return [
- [xPos + options.nodeHeight, hop.currentPos],
+ [xPos + nodeHeight, hop.currentPos],
[xPos, hop.currentPos]
];
}));
@@ -64,7 +85,7 @@ Renderer.prototype.getWaypoints = function(node){
return [[[0, hops[0].idealPos]]].concat(hops.map(function(hop, level){
var xPos = gap * (level+1);
return [
- [xPos - options.nodeHeight, hop.currentPos],
+ [xPos - nodeHeight, hop.currentPos],
[xPos, hop.currentPos]
];
}));
@@ -73,7 +94,7 @@ Renderer.prototype.getWaypoints = function(node){
return [[[hops[0].idealPos, 0]]].concat(hops.map(function(hop, level){
var yPos = gap * (level+1) * -1;
return [
- [hop.currentPos, yPos + options.nodeHeight],
+ [hop.currentPos, yPos + nodeHeight],
[hop.currentPos, yPos]
];
}));
@@ -82,7 +103,7 @@ Renderer.prototype.getWaypoints = function(node){
return [[[hops[0].idealPos, 0]]].concat(hops.map(function(hop, level){
var yPos = gap * (level+1);
return [
- [hop.currentPos, yPos - options.nodeHeight],
+ [hop.currentPos, yPos - nodeHeight],
[hop.currentPos, yPos]
];
}));
@@ -92,44 +113,93 @@ Renderer.prototype.getWaypoints = function(node){
Renderer.prototype.layout = function(nodes){
var options = this.options;
+ if(typeof options.nodeHeight === 'function'){
+ var gaps = [];
+ nodes.forEach(function(node, index){
+ gaps[index] = options.layerGap + options.nodeHeight(node.data);
+ });
+ }
+
var gap = options.layerGap + options.nodeHeight;
switch(options.direction){
case 'left':
- nodes.forEach(function(node){
- var pos = node.getLayerIndex() * gap + options.layerGap;
- node.x = -pos - options.nodeHeight;
+ nodes.forEach(function(node, index){
+ var pos = 0;
+ if(gaps){ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ }
+ else{
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
+ if(typeof options.nodeHeight === 'function'){
+ node.x = -pos - options.nodeHeight(node.data);
+ }
+ else{
+ node.x = -pos - options.nodeHeight;
+ }
node.y = node.currentPos;
- node.dx = options.nodeHeight;
+ node.dx = (typeof options.nodeHeight === 'function')
+ ? options.nodeHeight(node.data)
+ : options.nodeHeight;
node.dy = node.width;
});
break;
case 'right':
- nodes.forEach(function(node){
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function(node, index){
+ var pos = 0;
+ if(gaps){ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ }
+ else{
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = pos;
node.y = node.currentPos;
- node.dx = options.nodeHeight;
+ node.dx = (typeof options.nodeHeight === 'function')
+ ? options.nodeHeight(node.data)
+ : options.nodeHeight;
node.dy = node.width;
});
break;
case 'up':
- nodes.forEach(function(node){
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function(node, index){
+ var pos = 0;
+ if(gaps){ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ }
+ else{
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = node.currentPos;
- node.y = -pos - options.nodeHeight;
+ if(typeof options.nodeHeight === 'function'){
+ node.y = - pos - options.nodeHeight(node.data);
+ }
+ else{
+ node.y = -pos - options.nodeHeight;
+ }
node.dx = node.width;
- node.dy = options.nodeHeight;
+ node.dy = (typeof options.nodeHeight === 'function')
+ ? options.nodeHeight(node.data)
+ : options.nodeHeight;
});
break;
default:
case 'down':
- nodes.forEach(function(node){
- var pos = node.getLayerIndex() * gap + options.layerGap;
+ nodes.forEach(function(node, index){
+ var pos = 0;
+ if(gaps){ //if the nodeHeight is a function
+ pos = node.getLayerIndex() * gaps[index] + options.layerGap;
+ }
+ else{
+ pos = node.getLayerIndex() * gap + options.layerGap;
+ }
node.x = node.currentPos;
node.y = pos;
node.dx = node.width;
- node.dy = options.nodeHeight;
+ node.dy = (typeof options.nodeHeight === 'function')
+ ? options.nodeHeight(node.data)
+ : options.nodeHeight;
});
break;
}
From 6a665aa7f9021a187c4182821435c12cf45d1a91 Mon Sep 17 00:00:00 2001
From: Tomas Prochazka
Date: Wed, 23 Mar 2016 15:21:40 +0100
Subject: [PATCH 2/7] docs, tests, no console.logs
---
README.md | 3 +-
dist/labella.js | 1 -
dist/labella.min.js | 2 +-
docs/Renderer.md | 2 +-
src/core/renderer.js | 1 -
src/core/renderer.spec.js | 80 +++++++++++++++++++++++++++++----------
6 files changed, 64 insertions(+), 25 deletions(-)
diff --git a/README.md b/README.md
index 97a2536..288d9ce 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,8 @@ How about making the labels push each other and find where they can stay with ov
[left](http://twitter.github.io/labella.js/basic_left.html) |
[right](http://twitter.github.io/labella.js/basic_right.html) |
[with text (v)](http://twitter.github.io/labella.js/with_text.html) |
-[with text (h)](http://twitter.github.io/labella.js/with_text2.html)
+[with text (h)](http://twitter.github.io/labella.js/with_text2.html) |
+[with flex height](http://twitter.github.io/labella.js/with_flex_height.html)
* Read the instructions on this page or API reference.
Moreover, if you are looking for a ready-to-use timeline component with Labella's smart labeling instead of building your own timeline from scratch, check out [d3Kit-timeline](https://github.com/kristw/d3kit-timeline).
diff --git a/dist/labella.js b/dist/labella.js
index 01e838a..50bb005 100644
--- a/dist/labella.js
+++ b/dist/labella.js
@@ -1838,7 +1838,6 @@ return /******/ (function(modules) { // webpackBootstrap
nodeHeight: DEFAULT_NODE_HEIGHT,
direction: 'down'
}, options);
- console.log(this.options);
}
function lineTo(point) {
diff --git a/dist/labella.min.js b/dist/labella.min.js
index 2afae80..40931f5 100644
--- a/dist/labella.min.js
+++ b/dist/labella.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports={Node:n(1),Force:n(2),Distributor:n(3),Renderer:n(10)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},a=function(t){var e={},n=i.extend({},s),a=new r,u=[],h=null;return e.nodes=function(t){return arguments.length?(u=t,h=[t],e):u},e.getLayers=function(){return h},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,a.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return u.forEach(function(t){t.removeStub()}),h=a.distribute(u),h.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};a.DEFAULT_OPTIONS=s,t.exports=a},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,a=o-1;a>=0;a--)s=s.createStub(t.stubWidth),i[a].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var a=o.concat(),u=s;for(o=[];a.length>2&&u>i;){a.sort(function(t,e){return e.overlapCount-t.overlapCount});var h=a.shift();u-=h.width,u+=t.stubWidth,h.overlaps.forEach(function(t){t.overlapCount--}),o.push(h)}r.push(a),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var c=r.length-1;c>=1;c--)for(var f=r[c],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function a(){var t,e,r,i,u,h,c=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof c?(p=c,c=arguments[1]||{},f=2):("object"!==("undefined"==typeof c?"undefined":n(c))&&"function"!=typeof c||null==c)&&(c={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=c[e],i=t[e],c!==i&&(p&&i&&(s(i)||(u=o(i)))?(u?(u=!1,h=r&&o(r)?r:[]):h=r&&s(r)?r:{},c[e]=a(p,h,i)):void 0!==i&&(c[e]=i));return c}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new a(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),a=this.pointTree;s>=0&&a[s][0]==t;)s--;var u=this.pointTree.bsearch([e,null]);if(u>=0){for(var h=a.length-1;h>=u&&a[u][0]<=e;)u++;a.slice(s+1,u).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function a(t){this.idx=t,this.starts=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function u(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var h=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new u(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},a.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},u.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(a,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],u=1;ut;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var a=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var a=r[s];if(!a.unsatisfiable){var u=a.slack();if((a.equality||e>u)&&(e=u,n=a,o=s,a.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=u,t.exports=n},function(t,e,n){"use strict";function r(t){if("function"==typeof t.nodeHeight){var e=t.nodeHeight;t.nodeHeight=function(t){var n=e(t);return"number"!=typeof n?(console.error("It seems like your nodeHeight function does NOT return a number. Instead it returns "+n+". A fallback value has been used instead. The following console.log shows the input data of a node: "),console.log(t),c):n}}this.options=h.extend({layerGap:60,nodeHeight:c,direction:"down"},t),console.log(this.options)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function a(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function u(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var h=n(4),c=10;r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=a,r.hCurveBetween=u,r.prototype.getWaypoints=function(t){var e=this.options,n="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options;if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var r=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,"function"==typeof e.nodeHeight?t.x=-o-e.nodeHeight(t.data):t.x=-o-e.nodeHeight,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"right":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=o,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"up":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,"function"==typeof e.nodeHeight?t.y=-o-e.nodeHeight(t.data):t.y=-o-e.nodeHeight,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight});break;default:case"down":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,t.y=o,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(u(t[t.length-1],e[0])),n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},a=function(t){var e={},n=i.extend({},s),a=new r,u=[],h=null;return e.nodes=function(t){return arguments.length?(u=t,h=[t],e):u},e.getLayers=function(){return h},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,a.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return u.forEach(function(t){t.removeStub()}),h=a.distribute(u),h.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};a.DEFAULT_OPTIONS=s,t.exports=a},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,a=o-1;a>=0;a--)s=s.createStub(t.stubWidth),i[a].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var a=o.concat(),u=s;for(o=[];a.length>2&&u>i;){a.sort(function(t,e){return e.overlapCount-t.overlapCount});var h=a.shift();u-=h.width,u+=t.stubWidth,h.overlaps.forEach(function(t){t.overlapCount--}),o.push(h)}r.push(a),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var c=r.length-1;c>=1;c--)for(var f=r[c],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function a(){var t,e,r,i,u,h,c=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof c?(p=c,c=arguments[1]||{},f=2):("object"!==("undefined"==typeof c?"undefined":n(c))&&"function"!=typeof c||null==c)&&(c={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=c[e],i=t[e],c!==i&&(p&&i&&(s(i)||(u=o(i)))?(u?(u=!1,h=r&&o(r)?r:[]):h=r&&s(r)?r:{},c[e]=a(p,h,i)):void 0!==i&&(c[e]=i));return c}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new a(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),a=this.pointTree;s>=0&&a[s][0]==t;)s--;var u=this.pointTree.bsearch([e,null]);if(u>=0){for(var h=a.length-1;h>=u&&a[u][0]<=e;)u++;a.slice(s+1,u).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function a(t){this.idx=t,this.starts=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function u(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var h=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new u(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},a.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},u.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(a,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],u=1;ut;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var a=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var a=r[s];if(!a.unsatisfiable){var u=a.slack();if((a.equality||e>u)&&(e=u,n=a,o=s,a.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=u,t.exports=n},function(t,e,n){"use strict";function r(t){if("function"==typeof t.nodeHeight){var e=t.nodeHeight;t.nodeHeight=function(t){var n=e(t);return"number"!=typeof n?(console.error("It seems like your nodeHeight function does NOT return a number. Instead it returns "+n+". A fallback value has been used instead. The following console.log shows the input data of a node: "),console.log(t),c):n}}this.options=h.extend({layerGap:60,nodeHeight:c,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function a(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function u(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var h=n(4),c=10;r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=a,r.hCurveBetween=u,r.prototype.getWaypoints=function(t){var e=this.options,n="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options;if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var r=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,"function"==typeof e.nodeHeight?t.x=-o-e.nodeHeight(t.data):t.x=-o-e.nodeHeight,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"right":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=o,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"up":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,"function"==typeof e.nodeHeight?t.y=-o-e.nodeHeight(t.data):t.y=-o-e.nodeHeight,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight});break;default:case"down":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,t.y=o,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(u(t[t.length-1],e[0])),n
Date: Wed, 23 Mar 2016 15:28:09 +0100
Subject: [PATCH 3/7] additional tests
---
src/core/renderer.spec.js | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/core/renderer.spec.js b/src/core/renderer.spec.js
index bf3d44f..577f495 100644
--- a/src/core/renderer.spec.js
+++ b/src/core/renderer.spec.js
@@ -102,14 +102,22 @@ describe('Renderer', function(){
});
expect(r.getWaypoints(node)).toEqual([ [ [ 1, 0 ] ], [ [ 10, 20 ], [ 10, 30 ] ], [ [ 1, 50 ], [ 1, 60 ] ] ]);
});
- it('nodeHeight as a function', function(){
+ it('nodeHeight as a function', function(){
+ var r = new Renderer({
+ layerGap: 20,
+ nodeHeight: function(nodeData){return 10;},
+ direction: 'down'
+ });
+ expect(r.getWaypoints(node)).toEqual([ [ [ 1, 0 ] ], [ [ 10, 20 ], [ 10, 30 ] ], [ [ 1, 50 ], [ 1, 60 ] ] ]);
+ });
+ });
+ it('should fallback if the function does not return a number', function(){
var r = new Renderer({
layerGap: 20,
- nodeHeight: function(nodeData){return 10;},
- direction: 'down'
+ nodeHeight: function(nodeData){return "error"},
+ direction: 'left'
});
- expect(r.getWaypoints(node)).toEqual([ [ [ 1, 0 ] ], [ [ 10, 20 ], [ 10, 30 ] ], [ [ 1, 50 ], [ 1, 60 ] ] ]);
- });
+ expect(r.getWaypoints(node)).toEqual([ [ [ 0, 1 ] ], [ [ -20, 10 ], [ -30, 10 ] ], [ [ -50, 1 ], [ -60, 1 ] ] ]);
});
});
});
From 66e09e15b0ad15377fee52b7c2859bda6e99b959 Mon Sep 17 00:00:00 2001
From: Tomas Prochazka
Date: Wed, 23 Mar 2016 20:43:08 +0100
Subject: [PATCH 4/7] cleanup
---
dist/labella-extra.js | 43 +++++++++++++++++----------------
dist/labella-extra.min.js | 2 +-
dist/labella.js | 47 ++++++++++++++++--------------------
dist/labella.min.js | 2 +-
src/core/helper.js | 14 +++++++++++
src/core/helper.spec.js | 13 ++++++++++
src/core/renderer.js | 50 +++++++--------------------------------
7 files changed, 79 insertions(+), 92 deletions(-)
diff --git a/dist/labella-extra.js b/dist/labella-extra.js
index 3b9f316..c98ef0b 100644
--- a/dist/labella-extra.js
+++ b/dist/labella-extra.js
@@ -547,6 +547,17 @@ return /******/ (function(modules) { // webpackBootstrap
return array.map(accessor).reduce(function (prev, current) {
return prev + current;
}, 0);
+ },
+ functor: function functor(v) {
+ return typeof v === "function" ? function (nodeData) {
+ var result = v(nodeData);
+ if (typeof result !== "number") {
+ console.warn('Your nodeHeight function does not return a number.');
+ return 10; //10 because it is a default node height
+ } else return result;
+ } : function () {
+ return v;
+ };
}
};
@@ -1822,14 +1833,14 @@ return /******/ (function(modules) { // webpackBootstrap
var helper = __webpack_require__(4);
+ var DEFAULT_NODE_HEIGHT = 10;
+
function Renderer(options) {
- console.log(options.nodeHeight);
this.options = helper.extend({
layerGap: 60,
- nodeHeight: 10,
+ nodeHeight: DEFAULT_NODE_HEIGHT,
direction: 'down'
}, options);
- console.log(this.options);
}
function lineTo(point) {
@@ -1862,7 +1873,7 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.getWaypoints = function (node) {
var options = this.options;
- var nodeHeight = typeof options.nodeHeight === "function" ? options.nodeHeight(node.data) : options.nodeHeight;
+ var nodeHeight = helper.functor(options.nodeHeight)(node.data);
var direction = options.direction;
var hops = node.getPathFromRoot();
@@ -1894,6 +1905,7 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.layout = function (nodes) {
var options = this.options;
+ var nodeHeightFn = helper.functor(options.nodeHeight);
if (typeof options.nodeHeight === 'function') {
var gaps = [];
nodes.forEach(function (node, index) {
@@ -1913,13 +1925,9 @@ return /******/ (function(modules) { // webpackBootstrap
} else {
pos = node.getLayerIndex() * gap + options.layerGap;
}
- if (typeof options.nodeHeight === 'function') {
- node.x = -pos - options.nodeHeight(node.data);
- } else {
- node.x = -pos - options.nodeHeight;
- }
+ node.x = -pos - nodeHeightFn(node.data);
node.y = node.currentPos;
- node.dx = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
+ node.dx = nodeHeightFn(node.data);
node.dy = node.width;
});
break;
@@ -1934,7 +1942,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
node.x = pos;
node.y = node.currentPos;
- node.dx = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
+ node.dx = nodeHeightFn(node.data);
node.dy = node.width;
});
break;
@@ -1948,13 +1956,9 @@ return /******/ (function(modules) { // webpackBootstrap
pos = node.getLayerIndex() * gap + options.layerGap;
}
node.x = node.currentPos;
- if (typeof options.nodeHeight === 'function') {
- node.y = -pos - options.nodeHeight(node.data);
- } else {
- node.y = -pos - options.nodeHeight;
- }
+ node.y = -pos - nodeHeightFn(node.data);
node.dx = node.width;
- node.dy = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
+ node.dy = nodeHeightFn(node.data);
});
break;
default:
@@ -1970,10 +1974,7 @@ return /******/ (function(modules) { // webpackBootstrap
node.x = node.currentPos;
node.y = pos;
node.dx = node.width;
- node.dy = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
- if (typeof node.dy !== 'number') {
- console.error('It seems like your nodeHeight function does not' + 'return a number. Instead it returns ' + node.dy + '. A fallback' + 'value has been used instead.');
- }
+ node.dy = nodeHeightFn(node.data);
});
break;
}
diff --git a/dist/labella-extra.min.js b/dist/labella-extra.min.js
index f04155f..c088093 100644
--- a/dist/labella-extra.min.js
+++ b/dist/labella-extra.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports={Node:n(1),Force:n(2),Distributor:n(3),Renderer:n(10),metrics:n(11),util:n(12)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},u=function(t){var e={},n=i.extend({},s),u=new r,a=[],c=null;return e.nodes=function(t){return arguments.length?(a=t,c=[t],e):a},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,u.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return a.forEach(function(t){t.removeStub()}),c=u.distribute(a),c.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};u.DEFAULT_OPTIONS=s,t.exports=u},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,u=o-1;u>=0;u--)s=s.createStub(t.stubWidth),i[u].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var u=o.concat(),a=s;for(o=[];u.length>2&&a>i;){u.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=u.shift();a-=c.width,a+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}r.push(u),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var h=r.length-1;h>=1;h--)for(var f=r[h],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function u(){var t,e,r,i,a,c,h=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},f=2):("object"!==("undefined"==typeof h?"undefined":n(h))&&"function"!=typeof h||null==h)&&(h={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(a=o(i)))?(a?(a=!1,c=r&&o(r)?r:[]):c=r&&s(r)?r:{},h[e]=u(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new u(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),u=this.pointTree;s>=0&&u[s][0]==t;)s--;var a=this.pointTree.bsearch([e,null]);if(a>=0){for(var c=u.length-1;c>=a&&u[a][0]<=e;)a++;u.slice(s+1,a).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function u(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function a(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new a(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},u.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},a.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(u,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],a=1;at;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var u=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var u=r[s];if(!u.unsatisfiable){var a=u.slack();if((u.equality||e>a)&&(e=a,n=u,o=s,u.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=a,t.exports=n},function(t,e,n){"use strict";function r(t){console.log(t.nodeHeight),this.options=c.extend({layerGap:60,nodeHeight:10,direction:"down"},t),console.log(this.options)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function u(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function a(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var c=n(4);r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=u,r.hCurveBetween=a,r.prototype.getWaypoints=function(t){var e=this.options,n="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options;if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var r=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,"function"==typeof e.nodeHeight?t.x=-o-e.nodeHeight(t.data):t.x=-o-e.nodeHeight,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"right":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=o,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"up":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,"function"==typeof e.nodeHeight?t.y=-o-e.nodeHeight(t.data):t.y=-o-e.nodeHeight,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight});break;default:case"down":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,t.y=o,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,"number"!=typeof t.dy&&console.error("It seems like your nodeHeight function does notreturn a number. Instead it returns "+t.dy+". A fallbackvalue has been used instead.")})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(a(t[t.length-1],e[0])),n=i)return t.width;if(e>r)return e-r}if(s.isDefined(n)){if(r>=n)return t.width;if(i>n)return i-n}return 0})})},u.overDensitySpace=function(t,e,n){var i=arguments.length<=3||void 0===arguments[3]?0:arguments[3];if(0===t.length||!s.isDefined(e)||!s.isDefined(n))return 0;var o=e*n,u=r(t);return s.sum(u,function(t){var e=s.sum(t,function(t){return t.width+i})-i;return o>=e?0:e-o})},u.overlapCount=function(t,e){if(0===t.length)return 0;var n=r(t);return s.sum(n,function(t){for(var n=0,r=0;ri?Math.abs(i):0}return e})/i(e)},u.weightedAllocation=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*t.filter(function(t){return!t.isStub()}).length})},u.weightedAllocatedSpace=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*s.sum(t,function(t){return t.width})})},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=n(4);t.exports={generateNodes:function(t,e){var n=[];e=i.extend({},{minWidth:20,maxWidth:20,minPos:0,maxPos:800},e);for(var o=e.maxPos-e.minPos,s=e.maxWidth-e.minWidth,u=0;t>u;u++)n.push(new r(Math.floor(Math.random()*o)+e.minPos,Math.floor(Math.random()*s)+e.minWidth));return n}}}])});
\ No newline at end of file
+!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports={Node:n(1),Force:n(2),Distributor:n(3),Renderer:n(10),metrics:n(11),util:n(12)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},u=function(t){var e={},n=i.extend({},s),u=new r,a=[],c=null;return e.nodes=function(t){return arguments.length?(a=t,c=[t],e):a},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,u.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return a.forEach(function(t){t.removeStub()}),c=u.distribute(a),c.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};u.DEFAULT_OPTIONS=s,t.exports=u},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,u=o-1;u>=0;u--)s=s.createStub(t.stubWidth),i[u].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var u=o.concat(),a=s;for(o=[];u.length>2&&a>i;){u.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=u.shift();a-=c.width,a+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}r.push(u),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var h=r.length-1;h>=1;h--)for(var f=r[h],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)},functor:function(t){return"function"==typeof t?function(e){var n=t(e);return"number"!=typeof n?(console.warn("Your nodeHeight function does not return a number."),10):n}:function(){return t}}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function u(){var t,e,r,i,a,c,h=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},f=2):("object"!==("undefined"==typeof h?"undefined":n(h))&&"function"!=typeof h||null==h)&&(h={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(a=o(i)))?(a?(a=!1,c=r&&o(r)?r:[]):c=r&&s(r)?r:{},h[e]=u(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new u(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),u=this.pointTree;s>=0&&u[s][0]==t;)s--;var a=this.pointTree.bsearch([e,null]);if(a>=0){for(var c=u.length-1;c>=a&&u[a][0]<=e;)a++;u.slice(s+1,a).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function u(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function a(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new a(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},u.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},a.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(u,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],a=1;at;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var u=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var u=r[s];if(!u.unsatisfiable){var a=u.slack();if((u.equality||e>a)&&(e=a,n=u,o=s,u.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=a,t.exports=n},function(t,e,n){"use strict";function r(t){this.options=c.extend({layerGap:60,nodeHeight:h,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function u(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function a(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var c=n(4),h=10;r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=u,r.hCurveBetween=a,r.prototype.getWaypoints=function(t){var e=this.options,n=c.functor(e.nodeHeight)(t.data),r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options,n=c.functor(e.nodeHeight);if("function"==typeof e.nodeHeight){var r=[];t.forEach(function(t,n){r[n]=e.layerGap+e.nodeHeight(t.data)})}var i=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=-s-n(t.data),t.y=t.currentPos,t.dx=n(t.data),t.dy=t.width});break;case"right":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=s,t.y=t.currentPos,t.dx=n(t.data),t.dy=t.width});break;case"up":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=-s-n(t.data),t.dx=t.width,t.dy=n(t.data)});break;default:case"down":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=s,t.dx=t.width,t.dy=n(t.data)})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(a(t[t.length-1],e[0])),n=i)return t.width;if(e>r)return e-r}if(s.isDefined(n)){if(r>=n)return t.width;if(i>n)return i-n}return 0})})},u.overDensitySpace=function(t,e,n){var i=arguments.length<=3||void 0===arguments[3]?0:arguments[3];if(0===t.length||!s.isDefined(e)||!s.isDefined(n))return 0;var o=e*n,u=r(t);return s.sum(u,function(t){var e=s.sum(t,function(t){return t.width+i})-i;return o>=e?0:e-o})},u.overlapCount=function(t,e){if(0===t.length)return 0;var n=r(t);return s.sum(n,function(t){for(var n=0,r=0;ri?Math.abs(i):0}return e})/i(e)},u.weightedAllocation=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*t.filter(function(t){return!t.isStub()}).length})},u.weightedAllocatedSpace=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*s.sum(t,function(t){return t.width})})},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=n(4);t.exports={generateNodes:function(t,e){var n=[];e=i.extend({},{minWidth:20,maxWidth:20,minPos:0,maxPos:800},e);for(var o=e.maxPos-e.minPos,s=e.maxWidth-e.minWidth,u=0;t>u;u++)n.push(new r(Math.floor(Math.random()*o)+e.minPos,Math.floor(Math.random()*s)+e.minWidth));return n}}}])});
\ No newline at end of file
diff --git a/dist/labella.js b/dist/labella.js
index 50bb005..78c63a3 100644
--- a/dist/labella.js
+++ b/dist/labella.js
@@ -544,6 +544,17 @@ return /******/ (function(modules) { // webpackBootstrap
return array.map(accessor).reduce(function (prev, current) {
return prev + current;
}, 0);
+ },
+ functor: function functor(v) {
+ return typeof v === "function" ? function (nodeData) {
+ var result = v(nodeData);
+ if (typeof result !== "number") {
+ console.warn('Your nodeHeight function does not return a number.');
+ return 10; //10 because it is a default node height
+ } else return result;
+ } : function () {
+ return v;
+ };
}
};
@@ -1815,24 +1826,13 @@ return /******/ (function(modules) { // webpackBootstrap
/* 10 */
/***/ function(module, exports, __webpack_require__) {
- "use strict";
+ 'use strict';
var helper = __webpack_require__(4);
var DEFAULT_NODE_HEIGHT = 10;
function Renderer(options) {
- if (typeof options.nodeHeight === "function") {
- var currentNodeHeightFunction = options.nodeHeight;
- options.nodeHeight = function (nodeData) {
- var retValue = currentNodeHeightFunction(nodeData);
- if (typeof retValue !== "number") {
- console.error('It seems like your nodeHeight function does NOT ' + 'return a number. Instead it returns ' + retValue + '. A fallback ' + 'value has been used instead. The following console.log shows ' + 'the input data of a node: ');
- console.log(nodeData);
- return DEFAULT_NODE_HEIGHT;
- } else return retValue;
- };
- }
this.options = helper.extend({
layerGap: 60,
nodeHeight: DEFAULT_NODE_HEIGHT,
@@ -1870,7 +1870,7 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.getWaypoints = function (node) {
var options = this.options;
- var nodeHeight = typeof options.nodeHeight === "function" ? options.nodeHeight(node.data) : options.nodeHeight;
+ var nodeHeight = helper.functor(options.nodeHeight)(node.data);
var direction = options.direction;
var hops = node.getPathFromRoot();
@@ -1902,6 +1902,7 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.layout = function (nodes) {
var options = this.options;
+ var nodeHeightFn = helper.functor(options.nodeHeight);
if (typeof options.nodeHeight === 'function') {
var gaps = [];
nodes.forEach(function (node, index) {
@@ -1921,13 +1922,9 @@ return /******/ (function(modules) { // webpackBootstrap
} else {
pos = node.getLayerIndex() * gap + options.layerGap;
}
- if (typeof options.nodeHeight === 'function') {
- node.x = -pos - options.nodeHeight(node.data);
- } else {
- node.x = -pos - options.nodeHeight;
- }
+ node.x = -pos - nodeHeightFn(node.data);
node.y = node.currentPos;
- node.dx = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
+ node.dx = nodeHeightFn(node.data);
node.dy = node.width;
});
break;
@@ -1942,7 +1939,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
node.x = pos;
node.y = node.currentPos;
- node.dx = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
+ node.dx = nodeHeightFn(node.data);
node.dy = node.width;
});
break;
@@ -1956,13 +1953,9 @@ return /******/ (function(modules) { // webpackBootstrap
pos = node.getLayerIndex() * gap + options.layerGap;
}
node.x = node.currentPos;
- if (typeof options.nodeHeight === 'function') {
- node.y = -pos - options.nodeHeight(node.data);
- } else {
- node.y = -pos - options.nodeHeight;
- }
+ node.y = -pos - nodeHeightFn(node.data);
node.dx = node.width;
- node.dy = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
+ node.dy = nodeHeightFn(node.data);
});
break;
default:
@@ -1978,7 +1971,7 @@ return /******/ (function(modules) { // webpackBootstrap
node.x = node.currentPos;
node.y = pos;
node.dx = node.width;
- node.dy = typeof options.nodeHeight === 'function' ? options.nodeHeight(node.data) : options.nodeHeight;
+ node.dy = nodeHeightFn(node.data);
});
break;
}
diff --git a/dist/labella.min.js b/dist/labella.min.js
index 40931f5..10912ed 100644
--- a/dist/labella.min.js
+++ b/dist/labella.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports={Node:n(1),Force:n(2),Distributor:n(3),Renderer:n(10)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},a=function(t){var e={},n=i.extend({},s),a=new r,u=[],h=null;return e.nodes=function(t){return arguments.length?(u=t,h=[t],e):u},e.getLayers=function(){return h},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,a.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return u.forEach(function(t){t.removeStub()}),h=a.distribute(u),h.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};a.DEFAULT_OPTIONS=s,t.exports=a},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,a=o-1;a>=0;a--)s=s.createStub(t.stubWidth),i[a].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var a=o.concat(),u=s;for(o=[];a.length>2&&u>i;){a.sort(function(t,e){return e.overlapCount-t.overlapCount});var h=a.shift();u-=h.width,u+=t.stubWidth,h.overlaps.forEach(function(t){t.overlapCount--}),o.push(h)}r.push(a),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var c=r.length-1;c>=1;c--)for(var f=r[c],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function a(){var t,e,r,i,u,h,c=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof c?(p=c,c=arguments[1]||{},f=2):("object"!==("undefined"==typeof c?"undefined":n(c))&&"function"!=typeof c||null==c)&&(c={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=c[e],i=t[e],c!==i&&(p&&i&&(s(i)||(u=o(i)))?(u?(u=!1,h=r&&o(r)?r:[]):h=r&&s(r)?r:{},c[e]=a(p,h,i)):void 0!==i&&(c[e]=i));return c}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new a(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),a=this.pointTree;s>=0&&a[s][0]==t;)s--;var u=this.pointTree.bsearch([e,null]);if(u>=0){for(var h=a.length-1;h>=u&&a[u][0]<=e;)u++;a.slice(s+1,u).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function a(t){this.idx=t,this.starts=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new h({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function u(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var h=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new u(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},a.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},u.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(a,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],u=1;ut;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var a=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var a=r[s];if(!a.unsatisfiable){var u=a.slack();if((a.equality||e>u)&&(e=u,n=a,o=s,a.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=u,t.exports=n},function(t,e,n){"use strict";function r(t){if("function"==typeof t.nodeHeight){var e=t.nodeHeight;t.nodeHeight=function(t){var n=e(t);return"number"!=typeof n?(console.error("It seems like your nodeHeight function does NOT return a number. Instead it returns "+n+". A fallback value has been used instead. The following console.log shows the input data of a node: "),console.log(t),c):n}}this.options=h.extend({layerGap:60,nodeHeight:c,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function a(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function u(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var h=n(4),c=10;r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=a,r.hCurveBetween=u,r.prototype.getWaypoints=function(t){var e=this.options,n="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options;if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var r=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,"function"==typeof e.nodeHeight?t.x=-o-e.nodeHeight(t.data):t.x=-o-e.nodeHeight,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"right":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=o,t.y=t.currentPos,t.dx="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight,t.dy=t.width});break;case"up":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,"function"==typeof e.nodeHeight?t.y=-o-e.nodeHeight(t.data):t.y=-o-e.nodeHeight,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight});break;default:case"down":t.forEach(function(t,i){var o=0;o=n?t.getLayerIndex()*n[i]+e.layerGap:t.getLayerIndex()*r+e.layerGap,t.x=t.currentPos,t.y=o,t.dx=t.width,t.dy="function"==typeof e.nodeHeight?e.nodeHeight(t.data):e.nodeHeight})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(u(t[t.length-1],e[0])),n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var r=new t(this.idealPos,e,this.data);return r.currentPos=this.currentPos,r.child=this,this.parent=r,r}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var r=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-r),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,r){"use strict";var n=r(3),i=r(4),o=r(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},a=function(t){var e={},r=i.extend({},s),a=new n,u=[],c=null;return e.nodes=function(t){return arguments.length?(u=t,c=[t],e):u},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return r;r=i.extend(r,t);var o=i.pick(r,Object.keys(n.DEFAULT_OPTIONS));return i.isDefined(r.minPos)&&i.isDefined(r.maxPos)?o.layerWidth=r.maxPos-r.minPos:o.layerWidth=null,a.options(o),e},e.options(t),e.compute=function(){var t=i.pick(r,Object.keys(o.DEFAULT_OPTIONS));return u.forEach(function(t){t.removeStub()}),c=a.distribute(u),c.map(function(e,n){e.forEach(function(t){t.layerIndex=n}),r.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};a.DEFAULT_OPTIONS=s,t.exports=a},function(t,e,r){"use strict";var n=r(4),i=r(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=n.extend({},o,t),e.options=function(r){return arguments.length?(t=n.extend(t,r),e):t},e.computeRequiredWidth=function(e){return n.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(r){return t.layerWidth?Math.ceil(e.computeRequiredWidth(r)/e.maxWidthPerLayer()):1};var r={simple:function(r){for(var n=e.estimateRequiredLayers(r),i=[],o=0;n>o;o++)i.push([]);return r.forEach(function(e,r){var o=r%n;i[o].push(e);for(var s=e,a=o-1;a>=0;a--)s=s.createStub(t.stubWidth),i[a].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(r){for(var n=[],i=e.maxWidthPerLayer(),o=r.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var a=o.concat(),u=s;for(o=[];a.length>2&&u>i;){a.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=a.shift();u-=c.width,u+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}n.push(a),s=e.computeRequiredWidth(o)}o.length>0&&n.push(o);for(var h=n.length-1;h>=1;h--)for(var f=n[h],l=0;l=0;v--)d=d.createStub(t.stubWidth),n[v].push(d)}return n}};return e.countIdealOverlaps=function(e){var r=new i(t.layerWidth/2);return e.forEach(function(t){r.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=r.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!n.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(r.hasOwnProperty(t.algorithm))return r[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,r){"use strict";var n={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,r){return e[r]=t[r],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)},functor:function(t){return"function"==typeof t?function(e){var r=t(e);return"number"!=typeof r?(console.warn("Your nodeHeight function does not return a number."),10):r}:function(){return t}}};n.extend=r(5),t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=n.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&n.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!r)return!1;var o;for(o in t);return void 0===o||n.call(t,o)};t.exports=function a(){var t,e,n,i,u,c,h=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},f=2):("object"!==("undefined"==typeof h?"undefined":r(h))&&"function"!=typeof h||null==h)&&(h={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)n=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(u=o(i)))?(u?(u=!1,c=n&&o(n)?n:[]):c=n&&s(n)?n:{},h[e]=a(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,r){"use strict";function n(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t[0]-e[0];return r>0?1:0==r?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new a(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,r){return t?et.idx?(t.ends.every(function(t){var n=t.end>=e;return n&&r.push(t.result()),n}),o.call(this,t.right,e,r)):void t.starts.map(function(t){r.push(t.result())}):void 0}function s(t,e,r){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var n={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){n[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),a=this.pointTree;s>=0&&a[s][0]==t;)s--;var u=this.pointTree.bsearch([e,null]);if(u>=0){for(var c=a.length-1;c>=u&&a[u][0]<=e;)u++;a.slice(s+1,u).forEach(function(t){var e=t[1];n[e]=!0},this),Object.keys(n).forEach(function(n){var i=this.intervalHash[n];r.push(i.result(t,e))},this)}}function a(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.start-e.start;return r>0?1:0==r?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.end-e.end;return 0>r?1:0==r?0:-1}})}function u(t,e,r,n){if(this.id=e,this.start=t[r],this.end=t[n],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=r(7);n.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var r=new u(t,e,this.startKey,this.endKey);this.pointTree.insert([r.start,e]),this.pointTree.insert([r.end,e]),this.intervalHash[e]=r,this._autoIncrement++,i.call(this,this.root,r)},n.prototype.search=function(t,e){var r=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,r);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,r)}return r},n.prototype.remove=function(t){},a.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},u.prototype.result=function(t,e){var r={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var n=Math.max(this.start,t),i=Math.min(this.end,e),o=i-n;r.rate1=o/(e-t),r.rate2=o/(this.end-this.start)}return r},t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function i(){var t=null,e={},n=arguments;["0","1"].forEach(function(i){var o=n[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":r(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};n.create=function(t,e){return new n(t,e)},n.prototype=new Array,n.prototype.constructor=Array.prototype.constructor,n.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},n.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},n.prototype.remove=function(t){return this.splice(t,1),this},n.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,r=0,n=this.length;n-r>1;){e=Math.floor((r+n)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?r=e:n=e}return 0==r&&this._compare(this[0],t)>0?-1:r},n.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var r=e;if(-1==r||this._compare(this[r],t)<0)return r+1=1&&0==this._compare(this[r-1],t);)r--;return r},n.prototype.keys=function(t,e){var r=[];null==e&&(e=this.bsearch(t));for(var n=e;n>=0&&0==this._compare(this[n],t);)r.push(n),n--;var i=this.length;for(n=e+1;i>n&&0==this._compare(this[n],t);)r.push(n),n++;return r.length?r:null},n.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,r){return 0==r||0!=this._compare(this[r-1],t)?null:r-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},n.prototype.toArray=function(){return this.slice()},n.prototype._filter=function(t,e){return!0},n.compares={number:function(t,e){var r=t-e;return r>0?1:0==r?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},n.prototype._compare=n.compares.string,t.exports=n},function(t,e,r){"use strict";function n(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(a,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var r=t.targetPos-e.targetPos;if(0!==r)return r;var n=t.isStub()-e.isStub();return 0!==n?n:t.index-e.index});for(var r=t.map(n),i=[],u=1;ut;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,r){var n=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=n.compute_lm(o,t,r);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),r(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var r=this;t.visitNeighbours(e,function(e,n){n.offset=t.offset+(n===e.right?e.gap:-e.gap),r.addVariable(n),r.populateSplitBlock(n,t)})},t.prototype.traverse=function(t,e,r,n){var i=this;void 0===r&&(r=this.vars[0]),void 0===n&&(n=null),r.visitNeighbours(n,function(n,o){e.push(t(n)),i.traverse(t,e,o,r)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmn;++n){var o=t.vars[n];o.offset+=r,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var r=this.vars[e],n=r.position()-r.desiredPosition;t+=n*n*r.weight}return t},t}();r.Block=s;var a=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var r=new s(t[e]);this.list[e]=r,r.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,r=this.list[e];this.list.length=e,t!==r&&(this.list[t.blockInd]=r,r.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,r=t.right.block,n=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var a=n[s];if(!a.unsatisfiable){var u=a.slack();if((a.equality||e>u)&&(e=u,r=a,o=s,a.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();r.Solver=u,t.exports=r},function(t,e,r){"use strict";function n(t){this.options=c.extend({layerGap:60,nodeHeight:h,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,r){return"C "+t.join(" ")+" "+e.join(" ")+" "+r.join(" ")}function a(t,e){var r=(t[1]+e[1])/2;return s([t[0],r],[e[0],r],e)}function u(t,e){var r=(t[0]+e[0])/2;return s([r,t[1]],[r,e[1]],e)}var c=r(4),h=10;n.lineTo=i,n.moveTo=o,n.curveTo=s,n.vCurveBetween=a,n.hCurveBetween=u,n.prototype.getWaypoints=function(t){var e=this.options,r=c.functor(e.nodeHeight)(t.data),n=e.direction,i=t.getPathFromRoot(),o=r+e.layerGap;return"left"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[n+r,t.currentPos],[n,t.currentPos]]})):"right"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1);return[[n-r,t.currentPos],[n,t.currentPos]]})):"up"===n?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[t.currentPos,n+r],[t.currentPos,n]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1);return[[t.currentPos,n-r],[t.currentPos,n]]}))},n.prototype.layout=function(t){var e=this.options,r=c.functor(e.nodeHeight);if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var i=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=-s-r(t.data),t.y=t.currentPos,t.dx=r(t.data),t.dy=t.width});break;case"right":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=s,t.y=t.currentPos,t.dx=r(t.data),t.dy=t.width});break;case"up":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=-s-r(t.data),t.dx=t.width,t.dy=r(t.data)});break;default:case"down":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=s,t.dx=t.width,t.dy=r(t.data)})}return t},n.prototype.generatePath=function(t){var e=this.options,r=e.direction,n=this.getWaypoints(t,r),s=[o(n[0][0])];return"left"===r||"right"===r?n.reduce(function(t,e,r){return s.push(u(t[t.length-1],e[0])),r prev + current), 0);
+ },
+ functor(v) {
+ return typeof v === "function"
+ ? function(nodeData){
+ var result = v(nodeData);
+ if(typeof result !== "number"){
+ console.warn('Your nodeHeight function does not return a number.');
+ return 10; //10 because it is a default node height
+ }
+ else return result;
+ }
+ : function() {
+ return v;
+ };
}
};
diff --git a/src/core/helper.spec.js b/src/core/helper.spec.js
index 6032890..06143e6 100644
--- a/src/core/helper.spec.js
+++ b/src/core/helper.spec.js
@@ -46,4 +46,17 @@ describe('helper', function(){
});
});
+ describe('#functor(nodeHeight)', function(){
+ it('should always return a function', function(){
+ var result = helper.functor(10);
+ expect(typeof result).toEqual('function');
+ var result2 = helper.functor(function(){return 10;});
+ expect(typeof result2).toEqual('function');
+ });
+ it('should return a function that always returns a number', function(){
+ var result2 = helper.functor(function(){return 'string';});
+ expect(typeof result2()).toEqual('number');
+ });
+ });
+
});
\ No newline at end of file
diff --git a/src/core/renderer.js b/src/core/renderer.js
index d4dd6f2..84a3bdd 100644
--- a/src/core/renderer.js
+++ b/src/core/renderer.js
@@ -3,21 +3,6 @@ const helper = require('./helper.js');
const DEFAULT_NODE_HEIGHT = 10;
function Renderer(options){
- if(typeof options.nodeHeight === "function"){
- var currentNodeHeightFunction = options.nodeHeight;
- options.nodeHeight = function(nodeData){
- var retValue = currentNodeHeightFunction(nodeData);
- if(typeof retValue !== "number"){
- console.error('It seems like your nodeHeight function does NOT ' +
- 'return a number. Instead it returns ' + retValue + '. A fallback ' +
- 'value has been used instead. The following console.log shows ' +
- 'the input data of a node: ');
- console.log(nodeData);
- return DEFAULT_NODE_HEIGHT;
- }
- else return retValue;
- };
- }
this.options = helper.extend({
layerGap: 60,
nodeHeight: DEFAULT_NODE_HEIGHT,
@@ -63,9 +48,7 @@ Renderer.hCurveBetween = hCurveBetween;
Renderer.prototype.getWaypoints = function(node){
var options = this.options;
- var nodeHeight = (typeof options.nodeHeight === "function")
- ? options.nodeHeight(node.data)
- : options.nodeHeight;
+ var nodeHeight = helper.functor(options.nodeHeight)(node.data);
var direction = options.direction;
var hops = node.getPathFromRoot();
@@ -112,6 +95,7 @@ Renderer.prototype.getWaypoints = function(node){
Renderer.prototype.layout = function(nodes){
var options = this.options;
+ var nodeHeightFn = helper.functor(options.nodeHeight);
if(typeof options.nodeHeight === 'function'){
var gaps = [];
nodes.forEach(function(node, index){
@@ -131,16 +115,9 @@ Renderer.prototype.layout = function(nodes){
else{
pos = node.getLayerIndex() * gap + options.layerGap;
}
- if(typeof options.nodeHeight === 'function'){
- node.x = -pos - options.nodeHeight(node.data);
- }
- else{
- node.x = -pos - options.nodeHeight;
- }
+ node.x = -pos - nodeHeightFn(node.data);
node.y = node.currentPos;
- node.dx = (typeof options.nodeHeight === 'function')
- ? options.nodeHeight(node.data)
- : options.nodeHeight;
+ node.dx = nodeHeightFn(node.data);
node.dy = node.width;
});
break;
@@ -155,9 +132,7 @@ Renderer.prototype.layout = function(nodes){
}
node.x = pos;
node.y = node.currentPos;
- node.dx = (typeof options.nodeHeight === 'function')
- ? options.nodeHeight(node.data)
- : options.nodeHeight;
+ node.dx = nodeHeightFn(node.data);
node.dy = node.width;
});
break;
@@ -171,16 +146,9 @@ Renderer.prototype.layout = function(nodes){
pos = node.getLayerIndex() * gap + options.layerGap;
}
node.x = node.currentPos;
- if(typeof options.nodeHeight === 'function'){
- node.y = - pos - options.nodeHeight(node.data);
- }
- else{
- node.y = -pos - options.nodeHeight;
- }
+ node.y = -pos - nodeHeightFn(node.data);
node.dx = node.width;
- node.dy = (typeof options.nodeHeight === 'function')
- ? options.nodeHeight(node.data)
- : options.nodeHeight;
+ node.dy = nodeHeightFn(node.data);
});
break;
default:
@@ -196,9 +164,7 @@ Renderer.prototype.layout = function(nodes){
node.x = node.currentPos;
node.y = pos;
node.dx = node.width;
- node.dy = (typeof options.nodeHeight === 'function')
- ? options.nodeHeight(node.data)
- : options.nodeHeight;
+ node.dy = nodeHeightFn(node.data);
});
break;
}
From c12dcc79bb1acfac85bfc25df1cdec385e3ac92d Mon Sep 17 00:00:00 2001
From: Tomas Prochazka
Date: Thu, 24 Mar 2016 22:22:28 +0100
Subject: [PATCH 5/7] removing the type check from functor
---
dist/labella.js | 8 +-------
dist/labella.min.js | 2 +-
src/core/helper.js | 9 +--------
3 files changed, 3 insertions(+), 16 deletions(-)
diff --git a/dist/labella.js b/dist/labella.js
index 78c63a3..c84aaea 100644
--- a/dist/labella.js
+++ b/dist/labella.js
@@ -546,13 +546,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, 0);
},
functor: function functor(v) {
- return typeof v === "function" ? function (nodeData) {
- var result = v(nodeData);
- if (typeof result !== "number") {
- console.warn('Your nodeHeight function does not return a number.');
- return 10; //10 because it is a default node height
- } else return result;
- } : function () {
+ return typeof v === "function" ? v : function () {
return v;
};
}
diff --git a/dist/labella.min.js b/dist/labella.min.js
index 10912ed..582d055 100644
--- a/dist/labella.min.js
+++ b/dist/labella.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";t.exports={Node:r(1),Force:r(2),Distributor:r(3),Renderer:r(10)}},function(t,e){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var n=function(){function t(t,e){for(var r=0;r=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var r=new t(this.idealPos,e,this.data);return r.currentPos=this.currentPos,r.child=this,this.parent=r,r}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var r=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-r),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,r){"use strict";var n=r(3),i=r(4),o=r(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},a=function(t){var e={},r=i.extend({},s),a=new n,u=[],c=null;return e.nodes=function(t){return arguments.length?(u=t,c=[t],e):u},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return r;r=i.extend(r,t);var o=i.pick(r,Object.keys(n.DEFAULT_OPTIONS));return i.isDefined(r.minPos)&&i.isDefined(r.maxPos)?o.layerWidth=r.maxPos-r.minPos:o.layerWidth=null,a.options(o),e},e.options(t),e.compute=function(){var t=i.pick(r,Object.keys(o.DEFAULT_OPTIONS));return u.forEach(function(t){t.removeStub()}),c=a.distribute(u),c.map(function(e,n){e.forEach(function(t){t.layerIndex=n}),r.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};a.DEFAULT_OPTIONS=s,t.exports=a},function(t,e,r){"use strict";var n=r(4),i=r(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=n.extend({},o,t),e.options=function(r){return arguments.length?(t=n.extend(t,r),e):t},e.computeRequiredWidth=function(e){return n.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(r){return t.layerWidth?Math.ceil(e.computeRequiredWidth(r)/e.maxWidthPerLayer()):1};var r={simple:function(r){for(var n=e.estimateRequiredLayers(r),i=[],o=0;n>o;o++)i.push([]);return r.forEach(function(e,r){var o=r%n;i[o].push(e);for(var s=e,a=o-1;a>=0;a--)s=s.createStub(t.stubWidth),i[a].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(r){for(var n=[],i=e.maxWidthPerLayer(),o=r.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var a=o.concat(),u=s;for(o=[];a.length>2&&u>i;){a.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=a.shift();u-=c.width,u+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}n.push(a),s=e.computeRequiredWidth(o)}o.length>0&&n.push(o);for(var h=n.length-1;h>=1;h--)for(var f=n[h],l=0;l=0;v--)d=d.createStub(t.stubWidth),n[v].push(d)}return n}};return e.countIdealOverlaps=function(e){var r=new i(t.layerWidth/2);return e.forEach(function(t){r.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=r.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!n.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(r.hasOwnProperty(t.algorithm))return r[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,r){"use strict";var n={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,r){return e[r]=t[r],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)},functor:function(t){return"function"==typeof t?function(e){var r=t(e);return"number"!=typeof r?(console.warn("Your nodeHeight function does not return a number."),10):r}:function(){return t}}};n.extend=r(5),t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=n.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&n.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!r)return!1;var o;for(o in t);return void 0===o||n.call(t,o)};t.exports=function a(){var t,e,n,i,u,c,h=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},f=2):("object"!==("undefined"==typeof h?"undefined":r(h))&&"function"!=typeof h||null==h)&&(h={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)n=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(u=o(i)))?(u?(u=!1,c=n&&o(n)?n:[]):c=n&&s(n)?n:{},h[e]=a(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,r){"use strict";function n(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t[0]-e[0];return r>0?1:0==r?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new a(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,r){return t?et.idx?(t.ends.every(function(t){var n=t.end>=e;return n&&r.push(t.result()),n}),o.call(this,t.right,e,r)):void t.starts.map(function(t){r.push(t.result())}):void 0}function s(t,e,r){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var n={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){n[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),a=this.pointTree;s>=0&&a[s][0]==t;)s--;var u=this.pointTree.bsearch([e,null]);if(u>=0){for(var c=a.length-1;c>=u&&a[u][0]<=e;)u++;a.slice(s+1,u).forEach(function(t){var e=t[1];n[e]=!0},this),Object.keys(n).forEach(function(n){var i=this.intervalHash[n];r.push(i.result(t,e))},this)}}function a(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.start-e.start;return r>0?1:0==r?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.end-e.end;return 0>r?1:0==r?0:-1}})}function u(t,e,r,n){if(this.id=e,this.start=t[r],this.end=t[n],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=r(7);n.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var r=new u(t,e,this.startKey,this.endKey);this.pointTree.insert([r.start,e]),this.pointTree.insert([r.end,e]),this.intervalHash[e]=r,this._autoIncrement++,i.call(this,this.root,r)},n.prototype.search=function(t,e){var r=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,r);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,r)}return r},n.prototype.remove=function(t){},a.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},u.prototype.result=function(t,e){var r={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var n=Math.max(this.start,t),i=Math.min(this.end,e),o=i-n;r.rate1=o/(e-t),r.rate2=o/(this.end-this.start)}return r},t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function i(){var t=null,e={},n=arguments;["0","1"].forEach(function(i){var o=n[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":r(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};n.create=function(t,e){return new n(t,e)},n.prototype=new Array,n.prototype.constructor=Array.prototype.constructor,n.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},n.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},n.prototype.remove=function(t){return this.splice(t,1),this},n.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,r=0,n=this.length;n-r>1;){e=Math.floor((r+n)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?r=e:n=e}return 0==r&&this._compare(this[0],t)>0?-1:r},n.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var r=e;if(-1==r||this._compare(this[r],t)<0)return r+1=1&&0==this._compare(this[r-1],t);)r--;return r},n.prototype.keys=function(t,e){var r=[];null==e&&(e=this.bsearch(t));for(var n=e;n>=0&&0==this._compare(this[n],t);)r.push(n),n--;var i=this.length;for(n=e+1;i>n&&0==this._compare(this[n],t);)r.push(n),n++;return r.length?r:null},n.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,r){return 0==r||0!=this._compare(this[r-1],t)?null:r-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},n.prototype.toArray=function(){return this.slice()},n.prototype._filter=function(t,e){return!0},n.compares={number:function(t,e){var r=t-e;return r>0?1:0==r?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},n.prototype._compare=n.compares.string,t.exports=n},function(t,e,r){"use strict";function n(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(a,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var r=t.targetPos-e.targetPos;if(0!==r)return r;var n=t.isStub()-e.isStub();return 0!==n?n:t.index-e.index});for(var r=t.map(n),i=[],u=1;ut;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,r){var n=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=n.compute_lm(o,t,r);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),r(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var r=this;t.visitNeighbours(e,function(e,n){n.offset=t.offset+(n===e.right?e.gap:-e.gap),r.addVariable(n),r.populateSplitBlock(n,t)})},t.prototype.traverse=function(t,e,r,n){var i=this;void 0===r&&(r=this.vars[0]),void 0===n&&(n=null),r.visitNeighbours(n,function(n,o){e.push(t(n)),i.traverse(t,e,o,r)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmn;++n){var o=t.vars[n];o.offset+=r,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var r=this.vars[e],n=r.position()-r.desiredPosition;t+=n*n*r.weight}return t},t}();r.Block=s;var a=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var r=new s(t[e]);this.list[e]=r,r.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,r=this.list[e];this.list.length=e,t!==r&&(this.list[t.blockInd]=r,r.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,r=t.right.block,n=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var a=n[s];if(!a.unsatisfiable){var u=a.slack();if((a.equality||e>u)&&(e=u,r=a,o=s,a.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();r.Solver=u,t.exports=r},function(t,e,r){"use strict";function n(t){this.options=c.extend({layerGap:60,nodeHeight:h,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,r){return"C "+t.join(" ")+" "+e.join(" ")+" "+r.join(" ")}function a(t,e){var r=(t[1]+e[1])/2;return s([t[0],r],[e[0],r],e)}function u(t,e){var r=(t[0]+e[0])/2;return s([r,t[1]],[r,e[1]],e)}var c=r(4),h=10;n.lineTo=i,n.moveTo=o,n.curveTo=s,n.vCurveBetween=a,n.hCurveBetween=u,n.prototype.getWaypoints=function(t){var e=this.options,r=c.functor(e.nodeHeight)(t.data),n=e.direction,i=t.getPathFromRoot(),o=r+e.layerGap;return"left"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[n+r,t.currentPos],[n,t.currentPos]]})):"right"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1);return[[n-r,t.currentPos],[n,t.currentPos]]})):"up"===n?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[t.currentPos,n+r],[t.currentPos,n]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1);return[[t.currentPos,n-r],[t.currentPos,n]]}))},n.prototype.layout=function(t){var e=this.options,r=c.functor(e.nodeHeight);if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var i=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=-s-r(t.data),t.y=t.currentPos,t.dx=r(t.data),t.dy=t.width});break;case"right":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=s,t.y=t.currentPos,t.dx=r(t.data),t.dy=t.width});break;case"up":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=-s-r(t.data),t.dx=t.width,t.dy=r(t.data)});break;default:case"down":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=s,t.dx=t.width,t.dy=r(t.data)})}return t},n.prototype.generatePath=function(t){var e=this.options,r=e.direction,n=this.getWaypoints(t,r),s=[o(n[0][0])];return"left"===r||"right"===r?n.reduce(function(t,e,r){return s.push(u(t[t.length-1],e[0])),r=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var r=new t(this.idealPos,e,this.data);return r.currentPos=this.currentPos,r.child=this,this.parent=r,r}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var r=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-r),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,r){"use strict";var n=r(3),i=r(4),o=r(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},a=function(t){var e={},r=i.extend({},s),a=new n,u=[],c=null;return e.nodes=function(t){return arguments.length?(u=t,c=[t],e):u},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return r;r=i.extend(r,t);var o=i.pick(r,Object.keys(n.DEFAULT_OPTIONS));return i.isDefined(r.minPos)&&i.isDefined(r.maxPos)?o.layerWidth=r.maxPos-r.minPos:o.layerWidth=null,a.options(o),e},e.options(t),e.compute=function(){var t=i.pick(r,Object.keys(o.DEFAULT_OPTIONS));return u.forEach(function(t){t.removeStub()}),c=a.distribute(u),c.map(function(e,n){e.forEach(function(t){t.layerIndex=n}),r.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};a.DEFAULT_OPTIONS=s,t.exports=a},function(t,e,r){"use strict";var n=r(4),i=r(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=n.extend({},o,t),e.options=function(r){return arguments.length?(t=n.extend(t,r),e):t},e.computeRequiredWidth=function(e){return n.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(r){return t.layerWidth?Math.ceil(e.computeRequiredWidth(r)/e.maxWidthPerLayer()):1};var r={simple:function(r){for(var n=e.estimateRequiredLayers(r),i=[],o=0;n>o;o++)i.push([]);return r.forEach(function(e,r){var o=r%n;i[o].push(e);for(var s=e,a=o-1;a>=0;a--)s=s.createStub(t.stubWidth),i[a].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(r){for(var n=[],i=e.maxWidthPerLayer(),o=r.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var a=o.concat(),u=s;for(o=[];a.length>2&&u>i;){a.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=a.shift();u-=c.width,u+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}n.push(a),s=e.computeRequiredWidth(o)}o.length>0&&n.push(o);for(var h=n.length-1;h>=1;h--)for(var l=n[h],f=0;f=0;v--)d=d.createStub(t.stubWidth),n[v].push(d)}return n}};return e.countIdealOverlaps=function(e){var r=new i(t.layerWidth/2);return e.forEach(function(t){r.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=r.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!n.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(r.hasOwnProperty(t.algorithm))return r[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,r){"use strict";var n={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,r){return e[r]=t[r],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)},functor:function(t){return"function"==typeof t?t:function(){return t}}};n.extend=r(5),t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=n.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&n.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!r)return!1;var o;for(o in t);return void 0===o||n.call(t,o)};t.exports=function a(){var t,e,n,i,u,c,h=arguments[0],l=1,f=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},l=2):("object"!==("undefined"==typeof h?"undefined":r(h))&&"function"!=typeof h||null==h)&&(h={});f>l;++l)if(t=arguments[l],null!=t)for(e in t)n=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(u=o(i)))?(u?(u=!1,c=n&&o(n)?n:[]):c=n&&s(n)?n:{},h[e]=a(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,r){"use strict";function n(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t[0]-e[0];return r>0?1:0==r?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new a(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,r){return t?et.idx?(t.ends.every(function(t){var n=t.end>=e;return n&&r.push(t.result()),n}),o.call(this,t.right,e,r)):void t.starts.map(function(t){r.push(t.result())}):void 0}function s(t,e,r){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var n={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){n[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),a=this.pointTree;s>=0&&a[s][0]==t;)s--;var u=this.pointTree.bsearch([e,null]);if(u>=0){for(var c=a.length-1;c>=u&&a[u][0]<=e;)u++;a.slice(s+1,u).forEach(function(t){var e=t[1];n[e]=!0},this),Object.keys(n).forEach(function(n){var i=this.intervalHash[n];r.push(i.result(t,e))},this)}}function a(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.start-e.start;return r>0?1:0==r?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.end-e.end;return 0>r?1:0==r?0:-1}})}function u(t,e,r,n){if(this.id=e,this.start=t[r],this.end=t[n],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=r(7);n.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var r=new u(t,e,this.startKey,this.endKey);this.pointTree.insert([r.start,e]),this.pointTree.insert([r.end,e]),this.intervalHash[e]=r,this._autoIncrement++,i.call(this,this.root,r)},n.prototype.search=function(t,e){var r=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,r);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,r)}return r},n.prototype.remove=function(t){},a.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},u.prototype.result=function(t,e){var r={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var n=Math.max(this.start,t),i=Math.min(this.end,e),o=i-n;r.rate1=o/(e-t),r.rate2=o/(this.end-this.start)}return r},t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function i(){var t=null,e={},n=arguments;["0","1"].forEach(function(i){var o=n[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":r(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};n.create=function(t,e){return new n(t,e)},n.prototype=new Array,n.prototype.constructor=Array.prototype.constructor,n.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},n.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},n.prototype.remove=function(t){return this.splice(t,1),this},n.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,r=0,n=this.length;n-r>1;){e=Math.floor((r+n)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?r=e:n=e}return 0==r&&this._compare(this[0],t)>0?-1:r},n.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var r=e;if(-1==r||this._compare(this[r],t)<0)return r+1=1&&0==this._compare(this[r-1],t);)r--;return r},n.prototype.keys=function(t,e){var r=[];null==e&&(e=this.bsearch(t));for(var n=e;n>=0&&0==this._compare(this[n],t);)r.push(n),n--;var i=this.length;for(n=e+1;i>n&&0==this._compare(this[n],t);)r.push(n),n++;return r.length?r:null},n.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,r){return 0==r||0!=this._compare(this[r-1],t)?null:r-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},n.prototype.toArray=function(){return this.slice()},n.prototype._filter=function(t,e){return!0},n.compares={number:function(t,e){var r=t-e;return r>0?1:0==r?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},n.prototype._compare=n.compares.string,t.exports=n},function(t,e,r){"use strict";function n(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(a,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var r=t.targetPos-e.targetPos;if(0!==r)return r;var n=t.isStub()-e.isStub();return 0!==n?n:t.index-e.index});for(var r=t.map(n),i=[],u=1;ut;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,r){var n=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=n.compute_lm(o,t,r);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),r(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var r=this;t.visitNeighbours(e,function(e,n){n.offset=t.offset+(n===e.right?e.gap:-e.gap),r.addVariable(n),r.populateSplitBlock(n,t)})},t.prototype.traverse=function(t,e,r,n){var i=this;void 0===r&&(r=this.vars[0]),void 0===n&&(n=null),r.visitNeighbours(n,function(n,o){e.push(t(n)),i.traverse(t,e,o,r)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmn;++n){var o=t.vars[n];o.offset+=r,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var r=this.vars[e],n=r.position()-r.desiredPosition;t+=n*n*r.weight}return t},t}();r.Block=s;var a=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var r=new s(t[e]);this.list[e]=r,r.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,r=this.list[e];this.list.length=e,t!==r&&(this.list[t.blockInd]=r,r.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,r=t.right.block,n=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var a=n[s];if(!a.unsatisfiable){var u=a.slack();if((a.equality||e>u)&&(e=u,r=a,o=s,a.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();r.Solver=u,t.exports=r},function(t,e,r){"use strict";function n(t){this.options=c.extend({layerGap:60,nodeHeight:h,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,r){return"C "+t.join(" ")+" "+e.join(" ")+" "+r.join(" ")}function a(t,e){var r=(t[1]+e[1])/2;return s([t[0],r],[e[0],r],e)}function u(t,e){var r=(t[0]+e[0])/2;return s([r,t[1]],[r,e[1]],e)}var c=r(4),h=10;n.lineTo=i,n.moveTo=o,n.curveTo=s,n.vCurveBetween=a,n.hCurveBetween=u,n.prototype.getWaypoints=function(t){var e=this.options,r=c.functor(e.nodeHeight)(t.data),n=e.direction,i=t.getPathFromRoot(),o=r+e.layerGap;return"left"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[n+r,t.currentPos],[n,t.currentPos]]})):"right"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1);return[[n-r,t.currentPos],[n,t.currentPos]]})):"up"===n?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[t.currentPos,n+r],[t.currentPos,n]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1);return[[t.currentPos,n-r],[t.currentPos,n]]}))},n.prototype.layout=function(t){var e=this.options,r=c.functor(e.nodeHeight);if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var i=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=-s-r(t.data),t.y=t.currentPos,t.dx=r(t.data),t.dy=t.width});break;case"right":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=s,t.y=t.currentPos,t.dx=r(t.data),t.dy=t.width});break;case"up":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=-s-r(t.data),t.dx=t.width,t.dy=r(t.data)});break;default:case"down":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=s,t.dx=t.width,t.dy=r(t.data)})}return t},n.prototype.generatePath=function(t){var e=this.options,r=e.direction,n=this.getWaypoints(t,r),s=[o(n[0][0])];return"left"===r||"right"===r?n.reduce(function(t,e,r){return s.push(u(t[t.length-1],e[0])),r
Date: Thu, 24 Mar 2016 22:29:28 +0100
Subject: [PATCH 6/7] fixing unit tests
---
src/core/helper.spec.js | 4 ----
src/core/renderer.spec.js | 8 --------
2 files changed, 12 deletions(-)
diff --git a/src/core/helper.spec.js b/src/core/helper.spec.js
index 06143e6..9d955cb 100644
--- a/src/core/helper.spec.js
+++ b/src/core/helper.spec.js
@@ -53,10 +53,6 @@ describe('helper', function(){
var result2 = helper.functor(function(){return 10;});
expect(typeof result2).toEqual('function');
});
- it('should return a function that always returns a number', function(){
- var result2 = helper.functor(function(){return 'string';});
- expect(typeof result2()).toEqual('number');
- });
});
});
\ No newline at end of file
diff --git a/src/core/renderer.spec.js b/src/core/renderer.spec.js
index 577f495..c2a7b89 100644
--- a/src/core/renderer.spec.js
+++ b/src/core/renderer.spec.js
@@ -111,14 +111,6 @@ describe('Renderer', function(){
expect(r.getWaypoints(node)).toEqual([ [ [ 1, 0 ] ], [ [ 10, 20 ], [ 10, 30 ] ], [ [ 1, 50 ], [ 1, 60 ] ] ]);
});
});
- it('should fallback if the function does not return a number', function(){
- var r = new Renderer({
- layerGap: 20,
- nodeHeight: function(nodeData){return "error"},
- direction: 'left'
- });
- expect(r.getWaypoints(node)).toEqual([ [ [ 0, 1 ] ], [ [ -20, 10 ], [ -30, 10 ] ], [ [ -50, 1 ], [ -60, 1 ] ] ]);
- });
});
});
From 7d81c684613e07591786fed78cd838ce1299274c Mon Sep 17 00:00:00 2001
From: Tomas Prochazka
Date: Fri, 25 Mar 2016 15:32:49 +0100
Subject: [PATCH 7/7] node as a param instead of nodeData
---
dist/labella-extra.js | 8 +-------
dist/labella-extra.min.js | 2 +-
dist/labella.js | 16 ++++++++--------
dist/labella.min.js | 2 +-
docs/Renderer.md | 2 +-
examples/with_flex_height.html | 27 +++++++++++++--------------
src/core/renderer.js | 16 ++++++++--------
7 files changed, 33 insertions(+), 40 deletions(-)
diff --git a/dist/labella-extra.js b/dist/labella-extra.js
index c98ef0b..5870ae1 100644
--- a/dist/labella-extra.js
+++ b/dist/labella-extra.js
@@ -549,13 +549,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, 0);
},
functor: function functor(v) {
- return typeof v === "function" ? function (nodeData) {
- var result = v(nodeData);
- if (typeof result !== "number") {
- console.warn('Your nodeHeight function does not return a number.');
- return 10; //10 because it is a default node height
- } else return result;
- } : function () {
+ return typeof v === "function" ? v : function () {
return v;
};
}
diff --git a/dist/labella-extra.min.js b/dist/labella-extra.min.js
index c088093..7f6f6cd 100644
--- a/dist/labella-extra.min.js
+++ b/dist/labella-extra.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports={Node:n(1),Force:n(2),Distributor:n(3),Renderer:n(10),metrics:n(11),util:n(12)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},u=function(t){var e={},n=i.extend({},s),u=new r,a=[],c=null;return e.nodes=function(t){return arguments.length?(a=t,c=[t],e):a},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,u.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return a.forEach(function(t){t.removeStub()}),c=u.distribute(a),c.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};u.DEFAULT_OPTIONS=s,t.exports=u},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,u=o-1;u>=0;u--)s=s.createStub(t.stubWidth),i[u].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var u=o.concat(),a=s;for(o=[];u.length>2&&a>i;){u.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=u.shift();a-=c.width,a+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}r.push(u),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var h=r.length-1;h>=1;h--)for(var f=r[h],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)},functor:function(t){return"function"==typeof t?function(e){var n=t(e);return"number"!=typeof n?(console.warn("Your nodeHeight function does not return a number."),10):n}:function(){return t}}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function u(){var t,e,r,i,a,c,h=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},f=2):("object"!==("undefined"==typeof h?"undefined":n(h))&&"function"!=typeof h||null==h)&&(h={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(a=o(i)))?(a?(a=!1,c=r&&o(r)?r:[]):c=r&&s(r)?r:{},h[e]=u(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new u(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),u=this.pointTree;s>=0&&u[s][0]==t;)s--;var a=this.pointTree.bsearch([e,null]);if(a>=0){for(var c=u.length-1;c>=a&&u[a][0]<=e;)a++;u.slice(s+1,a).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function u(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function a(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new a(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},u.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},a.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(u,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],a=1;at;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var u=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var u=r[s];if(!u.unsatisfiable){var a=u.slack();if((u.equality||e>a)&&(e=a,n=u,o=s,u.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=a,t.exports=n},function(t,e,n){"use strict";function r(t){this.options=c.extend({layerGap:60,nodeHeight:h,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function u(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function a(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var c=n(4),h=10;r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=u,r.hCurveBetween=a,r.prototype.getWaypoints=function(t){var e=this.options,n=c.functor(e.nodeHeight)(t.data),r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options,n=c.functor(e.nodeHeight);if("function"==typeof e.nodeHeight){var r=[];t.forEach(function(t,n){r[n]=e.layerGap+e.nodeHeight(t.data)})}var i=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=-s-n(t.data),t.y=t.currentPos,t.dx=n(t.data),t.dy=t.width});break;case"right":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=s,t.y=t.currentPos,t.dx=n(t.data),t.dy=t.width});break;case"up":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=-s-n(t.data),t.dx=t.width,t.dy=n(t.data)});break;default:case"down":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=s,t.dx=t.width,t.dy=n(t.data)})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(a(t[t.length-1],e[0])),n=i)return t.width;if(e>r)return e-r}if(s.isDefined(n)){if(r>=n)return t.width;if(i>n)return i-n}return 0})})},u.overDensitySpace=function(t,e,n){var i=arguments.length<=3||void 0===arguments[3]?0:arguments[3];if(0===t.length||!s.isDefined(e)||!s.isDefined(n))return 0;var o=e*n,u=r(t);return s.sum(u,function(t){var e=s.sum(t,function(t){return t.width+i})-i;return o>=e?0:e-o})},u.overlapCount=function(t,e){if(0===t.length)return 0;var n=r(t);return s.sum(n,function(t){for(var n=0,r=0;ri?Math.abs(i):0}return e})/i(e)},u.weightedAllocation=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*t.filter(function(t){return!t.isStub()}).length})},u.weightedAllocatedSpace=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*s.sum(t,function(t){return t.width})})},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=n(4);t.exports={generateNodes:function(t,e){var n=[];e=i.extend({},{minWidth:20,maxWidth:20,minPos:0,maxPos:800},e);for(var o=e.maxPos-e.minPos,s=e.maxWidth-e.minWidth,u=0;t>u;u++)n.push(new r(Math.floor(Math.random()*o)+e.minPos,Math.floor(Math.random()*s)+e.minWidth));return n}}}])});
\ No newline at end of file
+!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";t.exports={Node:n(1),Force:n(2),Distributor:n(3),Renderer:n(10),metrics:n(11),util:n(12)}},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var n=new t(this.idealPos,e,this.data);return n.currentPos=this.currentPos,n.child=this,this.parent=n,n}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var n=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-n),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,n){"use strict";var r=n(3),i=n(4),o=n(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},u=function(t){var e={},n=i.extend({},s),u=new r,a=[],c=null;return e.nodes=function(t){return arguments.length?(a=t,c=[t],e):a},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return n;n=i.extend(n,t);var o=i.pick(n,Object.keys(r.DEFAULT_OPTIONS));return i.isDefined(n.minPos)&&i.isDefined(n.maxPos)?o.layerWidth=n.maxPos-n.minPos:o.layerWidth=null,u.options(o),e},e.options(t),e.compute=function(){var t=i.pick(n,Object.keys(o.DEFAULT_OPTIONS));return a.forEach(function(t){t.removeStub()}),c=u.distribute(a),c.map(function(e,r){e.forEach(function(t){t.layerIndex=r}),n.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};u.DEFAULT_OPTIONS=s,t.exports=u},function(t,e,n){"use strict";var r=n(4),i=n(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=r.extend({},o,t),e.options=function(n){return arguments.length?(t=r.extend(t,n),e):t},e.computeRequiredWidth=function(e){return r.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(n){return t.layerWidth?Math.ceil(e.computeRequiredWidth(n)/e.maxWidthPerLayer()):1};var n={simple:function(n){for(var r=e.estimateRequiredLayers(n),i=[],o=0;r>o;o++)i.push([]);return n.forEach(function(e,n){var o=n%r;i[o].push(e);for(var s=e,u=o-1;u>=0;u--)s=s.createStub(t.stubWidth),i[u].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(n){for(var r=[],i=e.maxWidthPerLayer(),o=n.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var u=o.concat(),a=s;for(o=[];u.length>2&&a>i;){u.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=u.shift();a-=c.width,a+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}r.push(u),s=e.computeRequiredWidth(o)}o.length>0&&r.push(o);for(var h=r.length-1;h>=1;h--)for(var f=r[h],l=0;l=0;v--)d=d.createStub(t.stubWidth),r[v].push(d)}return r}};return e.countIdealOverlaps=function(e){var n=new i(t.layerWidth/2);return e.forEach(function(t){n.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=n.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!r.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(n.hasOwnProperty(t.algorithm))return n[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,n){"use strict";var r={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,n){return e[n]=t[n],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)},functor:function(t){return"function"==typeof t?t:function(){return t}}};r.extend=n(5),t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=r.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&r.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!n)return!1;var o;for(o in t);return void 0===o||r.call(t,o)};t.exports=function u(){var t,e,r,i,a,c,h=arguments[0],f=1,l=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},f=2):("object"!==("undefined"==typeof h?"undefined":n(h))&&"function"!=typeof h||null==h)&&(h={});l>f;++f)if(t=arguments[f],null!=t)for(e in t)r=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(a=o(i)))?(a?(a=!1,c=r&&o(r)?r:[]):c=r&&s(r)?r:{},h[e]=u(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,n){"use strict";function r(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t[0]-e[0];return n>0?1:0==n?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new u(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,n){return t?et.idx?(t.ends.every(function(t){var r=t.end>=e;return r&&n.push(t.result()),r}),o.call(this,t.right,e,n)):void t.starts.map(function(t){n.push(t.result())}):void 0}function s(t,e,n){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var r={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){r[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),u=this.pointTree;s>=0&&u[s][0]==t;)s--;var a=this.pointTree.bsearch([e,null]);if(a>=0){for(var c=u.length-1;c>=a&&u[a][0]<=e;)a++;u.slice(s+1,a).forEach(function(t){var e=t[1];r[e]=!0},this),Object.keys(r).forEach(function(r){var i=this.intervalHash[r];n.push(i.result(t,e))},this)}}function u(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.start-e.start;return n>0?1:0==n?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var n=t.end-e.end;return 0>n?1:0==n?0:-1}})}function a(t,e,n,r){if(this.id=e,this.start=t[n],this.end=t[r],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=n(7);r.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var n=new a(t,e,this.startKey,this.endKey);this.pointTree.insert([n.start,e]),this.pointTree.insert([n.end,e]),this.intervalHash[e]=n,this._autoIncrement++,i.call(this,this.root,n)},r.prototype.search=function(t,e){var n=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,n);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,n)}return n},r.prototype.remove=function(t){},u.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},a.prototype.result=function(t,e){var n={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var r=Math.max(this.start,t),i=Math.min(this.end,e),o=i-r;n.rate1=o/(e-t),n.rate2=o/(this.end-this.start)}return n},t.exports=r},function(t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},r=function i(){var t=null,e={},r=arguments;["0","1"].forEach(function(i){var o=r[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":n(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};r.create=function(t,e){return new r(t,e)},r.prototype=new Array,r.prototype.constructor=Array.prototype.constructor,r.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},r.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},r.prototype.remove=function(t){return this.splice(t,1),this},r.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,n=0,r=this.length;r-n>1;){e=Math.floor((n+r)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?n=e:r=e}return 0==n&&this._compare(this[0],t)>0?-1:n},r.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var n=e;if(-1==n||this._compare(this[n],t)<0)return n+1=1&&0==this._compare(this[n-1],t);)n--;return n},r.prototype.keys=function(t,e){var n=[];null==e&&(e=this.bsearch(t));for(var r=e;r>=0&&0==this._compare(this[r],t);)n.push(r),r--;var i=this.length;for(r=e+1;i>r&&0==this._compare(this[r],t);)n.push(r),r++;return n.length?n:null},r.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,n){return 0==n||0!=this._compare(this[n-1],t)?null:n-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},r.prototype.toArray=function(){return this.slice()},r.prototype._filter=function(t,e){return!0},r.compares={number:function(t,e){var n=t-e;return n>0?1:0==n?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},r.prototype._compare=r.compares.string,t.exports=r},function(t,e,n){"use strict";function r(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(u,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var n=t.targetPos-e.targetPos;if(0!==n)return n;var r=t.isStub()-e.isStub();return 0!==r?r:t.index-e.index});for(var n=t.map(r),i=[],a=1;at;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,n){var r=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=r.compute_lm(o,t,n);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),n(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var n=this;t.visitNeighbours(e,function(e,r){r.offset=t.offset+(r===e.right?e.gap:-e.gap),n.addVariable(r),n.populateSplitBlock(r,t)})},t.prototype.traverse=function(t,e,n,r){var i=this;void 0===n&&(n=this.vars[0]),void 0===r&&(r=null),n.visitNeighbours(r,function(r,o){e.push(t(r)),i.traverse(t,e,o,n)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmr;++r){var o=t.vars[r];o.offset+=n,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var n=this.vars[e],r=n.position()-n.desiredPosition;t+=r*r*n.weight}return t},t}();n.Block=s;var u=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var n=new s(t[e]);this.list[e]=n,n.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,n=this.list[e];this.list.length=e,t!==n&&(this.list[t.blockInd]=n,n.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,n=t.right.block,r=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var u=r[s];if(!u.unsatisfiable){var a=u.slack();if((u.equality||e>a)&&(e=a,n=u,o=s,u.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();n.Solver=a,t.exports=n},function(t,e,n){"use strict";function r(t){this.options=c.extend({layerGap:60,nodeHeight:h,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,n){return"C "+t.join(" ")+" "+e.join(" ")+" "+n.join(" ")}function u(t,e){var n=(t[1]+e[1])/2;return s([t[0],n],[e[0],n],e)}function a(t,e){var n=(t[0]+e[0])/2;return s([n,t[1]],[n,e[1]],e)}var c=n(4),h=10;r.lineTo=i,r.moveTo=o,r.curveTo=s,r.vCurveBetween=u,r.hCurveBetween=a,r.prototype.getWaypoints=function(t){var e=this.options,n=c.functor(e.nodeHeight)(t.data),r=e.direction,i=t.getPathFromRoot(),o=n+e.layerGap;return"left"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[r+n,t.currentPos],[r,t.currentPos]]})):"right"===r?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var r=o*(e+1);return[[r-n,t.currentPos],[r,t.currentPos]]})):"up"===r?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1)*-1;return[[t.currentPos,r+n],[t.currentPos,r]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var r=o*(e+1);return[[t.currentPos,r-n],[t.currentPos,r]]}))},r.prototype.layout=function(t){var e=this.options,n=c.functor(e.nodeHeight);if("function"==typeof e.nodeHeight){var r=[];t.forEach(function(t,n){r[n]=e.layerGap+e.nodeHeight(t.data)})}var i=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=-s-n(t.data),t.y=t.currentPos,t.dx=n(t.data),t.dy=t.width});break;case"right":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=s,t.y=t.currentPos,t.dx=n(t.data),t.dy=t.width});break;case"up":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=-s-n(t.data),t.dx=t.width,t.dy=n(t.data)});break;default:case"down":t.forEach(function(t,o){var s=0;s=r?t.getLayerIndex()*r[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=s,t.dx=t.width,t.dy=n(t.data)})}return t},r.prototype.generatePath=function(t){var e=this.options,n=e.direction,r=this.getWaypoints(t,n),s=[o(r[0][0])];return"left"===n||"right"===n?r.reduce(function(t,e,n){return s.push(a(t[t.length-1],e[0])),n=i)return t.width;if(e>r)return e-r}if(s.isDefined(n)){if(r>=n)return t.width;if(i>n)return i-n}return 0})})},u.overDensitySpace=function(t,e,n){var i=arguments.length<=3||void 0===arguments[3]?0:arguments[3];if(0===t.length||!s.isDefined(e)||!s.isDefined(n))return 0;var o=e*n,u=r(t);return s.sum(u,function(t){var e=s.sum(t,function(t){return t.width+i})-i;return o>=e?0:e-o})},u.overlapCount=function(t,e){if(0===t.length)return 0;var n=r(t);return s.sum(n,function(t){for(var n=0,r=0;ri?Math.abs(i):0}return e})/i(e)},u.weightedAllocation=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*t.filter(function(t){return!t.isStub()}).length})},u.weightedAllocatedSpace=function(t){if(0===t.length)return 0;var e=r(t);return s.sum(e,function(t,e){return e*s.sum(t,function(t){return t.width})})},t.exports=u},function(t,e,n){"use strict";var r=n(1),i=n(4);t.exports={generateNodes:function(t,e){var n=[];e=i.extend({},{minWidth:20,maxWidth:20,minPos:0,maxPos:800},e);for(var o=e.maxPos-e.minPos,s=e.maxWidth-e.minWidth,u=0;t>u;u++)n.push(new r(Math.floor(Math.random()*o)+e.minPos,Math.floor(Math.random()*s)+e.minWidth));return n}}}])});
\ No newline at end of file
diff --git a/dist/labella.js b/dist/labella.js
index c84aaea..b8a6b6c 100644
--- a/dist/labella.js
+++ b/dist/labella.js
@@ -1864,7 +1864,7 @@ return /******/ (function(modules) { // webpackBootstrap
Renderer.prototype.getWaypoints = function (node) {
var options = this.options;
- var nodeHeight = helper.functor(options.nodeHeight)(node.data);
+ var nodeHeight = helper.functor(options.nodeHeight)(node);
var direction = options.direction;
var hops = node.getPathFromRoot();
@@ -1900,7 +1900,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (typeof options.nodeHeight === 'function') {
var gaps = [];
nodes.forEach(function (node, index) {
- gaps[index] = options.layerGap + options.nodeHeight(node.data);
+ gaps[index] = options.layerGap + options.nodeHeight(node);
});
}
@@ -1916,9 +1916,9 @@ return /******/ (function(modules) { // webpackBootstrap
} else {
pos = node.getLayerIndex() * gap + options.layerGap;
}
- node.x = -pos - nodeHeightFn(node.data);
+ node.x = -pos - nodeHeightFn(node);
node.y = node.currentPos;
- node.dx = nodeHeightFn(node.data);
+ node.dx = nodeHeightFn(node);
node.dy = node.width;
});
break;
@@ -1933,7 +1933,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
node.x = pos;
node.y = node.currentPos;
- node.dx = nodeHeightFn(node.data);
+ node.dx = nodeHeightFn(node);
node.dy = node.width;
});
break;
@@ -1947,9 +1947,9 @@ return /******/ (function(modules) { // webpackBootstrap
pos = node.getLayerIndex() * gap + options.layerGap;
}
node.x = node.currentPos;
- node.y = -pos - nodeHeightFn(node.data);
+ node.y = -pos - nodeHeightFn(node);
node.dx = node.width;
- node.dy = nodeHeightFn(node.data);
+ node.dy = nodeHeightFn(node);
});
break;
default:
@@ -1965,7 +1965,7 @@ return /******/ (function(modules) { // webpackBootstrap
node.x = node.currentPos;
node.y = pos;
node.dx = node.width;
- node.dy = nodeHeightFn(node.data);
+ node.dy = nodeHeightFn(node);
});
break;
}
diff --git a/dist/labella.min.js b/dist/labella.min.js
index 582d055..3f2511b 100644
--- a/dist/labella.min.js
+++ b/dist/labella.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.labella=e():t.labella=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";t.exports={Node:r(1),Force:r(2),Distributor:r(3),Renderer:r(10)}},function(t,e){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var n=function(){function t(t,e){for(var r=0;r=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var r=new t(this.idealPos,e,this.data);return r.currentPos=this.currentPos,r.child=this,this.parent=r,r}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var r=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-r),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,r){"use strict";var n=r(3),i=r(4),o=r(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},a=function(t){var e={},r=i.extend({},s),a=new n,u=[],c=null;return e.nodes=function(t){return arguments.length?(u=t,c=[t],e):u},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return r;r=i.extend(r,t);var o=i.pick(r,Object.keys(n.DEFAULT_OPTIONS));return i.isDefined(r.minPos)&&i.isDefined(r.maxPos)?o.layerWidth=r.maxPos-r.minPos:o.layerWidth=null,a.options(o),e},e.options(t),e.compute=function(){var t=i.pick(r,Object.keys(o.DEFAULT_OPTIONS));return u.forEach(function(t){t.removeStub()}),c=a.distribute(u),c.map(function(e,n){e.forEach(function(t){t.layerIndex=n}),r.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};a.DEFAULT_OPTIONS=s,t.exports=a},function(t,e,r){"use strict";var n=r(4),i=r(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=n.extend({},o,t),e.options=function(r){return arguments.length?(t=n.extend(t,r),e):t},e.computeRequiredWidth=function(e){return n.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(r){return t.layerWidth?Math.ceil(e.computeRequiredWidth(r)/e.maxWidthPerLayer()):1};var r={simple:function(r){for(var n=e.estimateRequiredLayers(r),i=[],o=0;n>o;o++)i.push([]);return r.forEach(function(e,r){var o=r%n;i[o].push(e);for(var s=e,a=o-1;a>=0;a--)s=s.createStub(t.stubWidth),i[a].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(r){for(var n=[],i=e.maxWidthPerLayer(),o=r.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var a=o.concat(),u=s;for(o=[];a.length>2&&u>i;){a.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=a.shift();u-=c.width,u+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}n.push(a),s=e.computeRequiredWidth(o)}o.length>0&&n.push(o);for(var h=n.length-1;h>=1;h--)for(var l=n[h],f=0;f=0;v--)d=d.createStub(t.stubWidth),n[v].push(d)}return n}};return e.countIdealOverlaps=function(e){var r=new i(t.layerWidth/2);return e.forEach(function(t){r.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=r.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!n.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(r.hasOwnProperty(t.algorithm))return r[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,r){"use strict";var n={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,r){return e[r]=t[r],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)},functor:function(t){return"function"==typeof t?t:function(){return t}}};n.extend=r(5),t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=n.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&n.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!r)return!1;var o;for(o in t);return void 0===o||n.call(t,o)};t.exports=function a(){var t,e,n,i,u,c,h=arguments[0],l=1,f=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},l=2):("object"!==("undefined"==typeof h?"undefined":r(h))&&"function"!=typeof h||null==h)&&(h={});f>l;++l)if(t=arguments[l],null!=t)for(e in t)n=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(u=o(i)))?(u?(u=!1,c=n&&o(n)?n:[]):c=n&&s(n)?n:{},h[e]=a(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,r){"use strict";function n(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t[0]-e[0];return r>0?1:0==r?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new a(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,r){return t?et.idx?(t.ends.every(function(t){var n=t.end>=e;return n&&r.push(t.result()),n}),o.call(this,t.right,e,r)):void t.starts.map(function(t){r.push(t.result())}):void 0}function s(t,e,r){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var n={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){n[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),a=this.pointTree;s>=0&&a[s][0]==t;)s--;var u=this.pointTree.bsearch([e,null]);if(u>=0){for(var c=a.length-1;c>=u&&a[u][0]<=e;)u++;a.slice(s+1,u).forEach(function(t){var e=t[1];n[e]=!0},this),Object.keys(n).forEach(function(n){var i=this.intervalHash[n];r.push(i.result(t,e))},this)}}function a(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.start-e.start;return r>0?1:0==r?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.end-e.end;return 0>r?1:0==r?0:-1}})}function u(t,e,r,n){if(this.id=e,this.start=t[r],this.end=t[n],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=r(7);n.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var r=new u(t,e,this.startKey,this.endKey);this.pointTree.insert([r.start,e]),this.pointTree.insert([r.end,e]),this.intervalHash[e]=r,this._autoIncrement++,i.call(this,this.root,r)},n.prototype.search=function(t,e){var r=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,r);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,r)}return r},n.prototype.remove=function(t){},a.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},u.prototype.result=function(t,e){var r={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var n=Math.max(this.start,t),i=Math.min(this.end,e),o=i-n;r.rate1=o/(e-t),r.rate2=o/(this.end-this.start)}return r},t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function i(){var t=null,e={},n=arguments;["0","1"].forEach(function(i){var o=n[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":r(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};n.create=function(t,e){return new n(t,e)},n.prototype=new Array,n.prototype.constructor=Array.prototype.constructor,n.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},n.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},n.prototype.remove=function(t){return this.splice(t,1),this},n.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,r=0,n=this.length;n-r>1;){e=Math.floor((r+n)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?r=e:n=e}return 0==r&&this._compare(this[0],t)>0?-1:r},n.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var r=e;if(-1==r||this._compare(this[r],t)<0)return r+1=1&&0==this._compare(this[r-1],t);)r--;return r},n.prototype.keys=function(t,e){var r=[];null==e&&(e=this.bsearch(t));for(var n=e;n>=0&&0==this._compare(this[n],t);)r.push(n),n--;var i=this.length;for(n=e+1;i>n&&0==this._compare(this[n],t);)r.push(n),n++;return r.length?r:null},n.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,r){return 0==r||0!=this._compare(this[r-1],t)?null:r-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},n.prototype.toArray=function(){return this.slice()},n.prototype._filter=function(t,e){return!0},n.compares={number:function(t,e){var r=t-e;return r>0?1:0==r?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},n.prototype._compare=n.compares.string,t.exports=n},function(t,e,r){"use strict";function n(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(a,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var r=t.targetPos-e.targetPos;if(0!==r)return r;var n=t.isStub()-e.isStub();return 0!==n?n:t.index-e.index});for(var r=t.map(n),i=[],u=1;ut;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,r){var n=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=n.compute_lm(o,t,r);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),r(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var r=this;t.visitNeighbours(e,function(e,n){n.offset=t.offset+(n===e.right?e.gap:-e.gap),r.addVariable(n),r.populateSplitBlock(n,t)})},t.prototype.traverse=function(t,e,r,n){var i=this;void 0===r&&(r=this.vars[0]),void 0===n&&(n=null),r.visitNeighbours(n,function(n,o){e.push(t(n)),i.traverse(t,e,o,r)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmn;++n){var o=t.vars[n];o.offset+=r,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var r=this.vars[e],n=r.position()-r.desiredPosition;t+=n*n*r.weight}return t},t}();r.Block=s;var a=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var r=new s(t[e]);this.list[e]=r,r.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,r=this.list[e];this.list.length=e,t!==r&&(this.list[t.blockInd]=r,r.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,r=t.right.block,n=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var a=n[s];if(!a.unsatisfiable){var u=a.slack();if((a.equality||e>u)&&(e=u,r=a,o=s,a.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();r.Solver=u,t.exports=r},function(t,e,r){"use strict";function n(t){this.options=c.extend({layerGap:60,nodeHeight:h,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,r){return"C "+t.join(" ")+" "+e.join(" ")+" "+r.join(" ")}function a(t,e){var r=(t[1]+e[1])/2;return s([t[0],r],[e[0],r],e)}function u(t,e){var r=(t[0]+e[0])/2;return s([r,t[1]],[r,e[1]],e)}var c=r(4),h=10;n.lineTo=i,n.moveTo=o,n.curveTo=s,n.vCurveBetween=a,n.hCurveBetween=u,n.prototype.getWaypoints=function(t){var e=this.options,r=c.functor(e.nodeHeight)(t.data),n=e.direction,i=t.getPathFromRoot(),o=r+e.layerGap;return"left"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[n+r,t.currentPos],[n,t.currentPos]]})):"right"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1);return[[n-r,t.currentPos],[n,t.currentPos]]})):"up"===n?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[t.currentPos,n+r],[t.currentPos,n]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1);return[[t.currentPos,n-r],[t.currentPos,n]]}))},n.prototype.layout=function(t){var e=this.options,r=c.functor(e.nodeHeight);if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t.data)})}var i=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=-s-r(t.data),t.y=t.currentPos,t.dx=r(t.data),t.dy=t.width});break;case"right":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=s,t.y=t.currentPos,t.dx=r(t.data),t.dy=t.width});break;case"up":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=-s-r(t.data),t.dx=t.width,t.dy=r(t.data)});break;default:case"down":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=s,t.dx=t.width,t.dy=r(t.data)})}return t},n.prototype.generatePath=function(t){var e=this.options,r=e.direction,n=this.getWaypoints(t,r),s=[o(n[0][0])];return"left"===r||"right"===r?n.reduce(function(t,e,r){return s.push(u(t[t.length-1],e[0])),r=this.currentPos-e&&t<=this.currentPos+e}},{key:"positionBefore",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentLeft()-this.width/2-e}},{key:"positionAfter",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?0:arguments[1];return t.currentRight()+this.width/2+e}},{key:"currentRight",value:function(){return this.currentPos+this.width/2}},{key:"currentLeft",value:function(){return this.currentPos-this.width/2}},{key:"idealRight",value:function(){return this.idealPos+this.width/2}},{key:"idealLeft",value:function(){return this.idealPos-this.width/2}},{key:"createStub",value:function(e){var r=new t(this.idealPos,e,this.data);return r.currentPos=this.currentPos,r.child=this,this.parent=r,r}},{key:"removeStub",value:function(){return this.parent&&(this.parent.child=null,this.parent=null),this}},{key:"isStub",value:function(){return!!this.child}},{key:"getPathToRoot",value:function(){for(var t=[],e=this;e;)t.push(e),e=e.parent;return t}},{key:"getPathFromRoot",value:function(){return this.getPathToRoot().reverse()}},{key:"getPathToRootLength",value:function(){for(var t=0,e=this;e;){var r=e.parent?e.parent.currentPos:e.idealPos;t+=Math.abs(e.currentPos-r),e=e.parent}return t}},{key:"getRoot",value:function(){for(var t=this,e=this;e;)t=e,e=e.parent;return t}},{key:"getLayerIndex",value:function(){return this.layerIndex}},{key:"clone",value:function(){var e=new t(this.idealPos,this.width,this.data);return e.currentPos=this.currentPos,e.layerIndex=this.layerIndex,e}}]),t}();t.exports=i},function(t,e,r){"use strict";var n=r(3),i=r(4),o=r(8),s={nodeSpacing:3,minPos:0,maxPos:null,algorithm:"overlap",removeOverlap:!0,density:.85,stubWidth:1},u=function(t){var e={},r=i.extend({},s),u=new n,a=[],c=null;return e.nodes=function(t){return arguments.length?(a=t,c=[t],e):a},e.getLayers=function(){return c},e.options=function(t){if(!arguments.length)return r;r=i.extend(r,t);var o=i.pick(r,Object.keys(n.DEFAULT_OPTIONS));return i.isDefined(r.minPos)&&i.isDefined(r.maxPos)?o.layerWidth=r.maxPos-r.minPos:o.layerWidth=null,u.options(o),e},e.options(t),e.compute=function(){var t=i.pick(r,Object.keys(o.DEFAULT_OPTIONS));return a.forEach(function(t){t.removeStub()}),c=u.distribute(a),c.map(function(e,n){e.forEach(function(t){t.layerIndex=n}),r.removeOverlap&&o(e,t)}),e},e.start=function(){console.log("[warning] force.start() is deprecated. Please use force.compute() instead.")},e};u.DEFAULT_OPTIONS=s,t.exports=u},function(t,e,r){"use strict";var n=r(4),i=r(6),o={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},s=function(t){var e={};t=n.extend({},o,t),e.options=function(r){return arguments.length?(t=n.extend(t,r),e):t},e.computeRequiredWidth=function(e){return n.sum(e,function(e){return e.width+t.nodeSpacing})-t.nodeSpacing},e.maxWidthPerLayer=function(){return t.density*t.layerWidth},e.needToSplit=function(t){return e.estimateRequiredLayers(t)>1},e.estimateRequiredLayers=function(r){return t.layerWidth?Math.ceil(e.computeRequiredWidth(r)/e.maxWidthPerLayer()):1};var r={simple:function(r){for(var n=e.estimateRequiredLayers(r),i=[],o=0;n>o;o++)i.push([]);return r.forEach(function(e,r){var o=r%n;i[o].push(e);for(var s=e,u=o-1;u>=0;u--)s=s.createStub(t.stubWidth),i[u].push(s)}),i},roundRobin:function(t){var e=[];return e},overlap:function(r){for(var n=[],i=e.maxWidthPerLayer(),o=r.concat(),s=e.computeRequiredWidth(o);s>i;){e.countIdealOverlaps(o);var u=o.concat(),a=s;for(o=[];u.length>2&&a>i;){u.sort(function(t,e){return e.overlapCount-t.overlapCount});var c=u.shift();a-=c.width,a+=t.stubWidth,c.overlaps.forEach(function(t){t.overlapCount--}),o.push(c)}n.push(u),s=e.computeRequiredWidth(o)}o.length>0&&n.push(o);for(var h=n.length-1;h>=1;h--)for(var l=n[h],f=0;f=0;v--)d=d.createStub(t.stubWidth),n[v].push(d)}return n}};return e.countIdealOverlaps=function(e){var r=new i(t.layerWidth/2);return e.forEach(function(t){r.add([t.idealLeft(),t.idealRight(),t])}),e.forEach(function(t){var e=r.search(t.idealLeft(),t.idealRight());t.overlaps=e.map(function(t){return t.data[2]}),t.overlapCount=e.length}),e},e.distribute=function(i){if(!i||0===i.length)return[];if("none"==t.algorithm||!n.isDefined(t.algorithm))return[i];if(!e.needToSplit(i))return[i];if(i=i.concat().sort(function(t,e){return t.idealPos-e.idealPos}),"function"==typeof t.algorithm)return t.algorithm(i,t);if(r.hasOwnProperty(t.algorithm))return r[t.algorithm](i);throw"Unknown algorithm: "+t.algorithm},e};s.DEFAULT_OPTIONS=o,t.exports=s},function(t,e,r){"use strict";var n={isDefined:function(t){return null!==t&&void 0!==t},last:function(t){return t.length>0?t[t.length-1]:null},pick:function(t,e){return e.reduce(function(e,r){return e[r]=t[r],e},{})},sum:function(t,e){return t.map(e).reduce(function(t,e){return t+e},0)},functor:function(t){return"function"==typeof t?t:function(){return t}}};n.extend=r(5),t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},s=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e=n.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&n.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!e&&!r)return!1;var o;for(o in t);return void 0===o||n.call(t,o)};t.exports=function u(){var t,e,n,i,a,c,h=arguments[0],l=1,f=arguments.length,p=!1;for("boolean"==typeof h?(p=h,h=arguments[1]||{},l=2):("object"!==("undefined"==typeof h?"undefined":r(h))&&"function"!=typeof h||null==h)&&(h={});f>l;++l)if(t=arguments[l],null!=t)for(e in t)n=h[e],i=t[e],h!==i&&(p&&i&&(s(i)||(a=o(i)))?(a?(a=!1,c=n&&o(n)?n:[]):c=n&&s(n)?n:{},h[e]=u(p,c,i)):void 0!==i&&(h[e]=i));return h}},function(t,e,r){"use strict";function n(t,e){if(e||(e={}),this.startKey=e.startKey||0,this.endKey=e.endKey||1,this.intervalHash={},this.pointTree=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t[0]-e[0];return r>0?1:0==r?0:-1}}),this._autoIncrement=0,!t||"number"!=typeof t)throw new Error("you must specify center index as the 2nd argument.");this.root=new u(t,this)}function i(t,e){return e.end>1,this)),i.call(this,t.left,e)):t.idx>1,this)),i.call(this,t.right,e)):t.insert(e)}function o(t,e,r){return t?et.idx?(t.ends.every(function(t){var n=t.end>=e;return n&&r.push(t.result()),n}),o.call(this,t.right,e,r)):void t.starts.map(function(t){r.push(t.result())}):void 0}function s(t,e,r){if(0>=e-t)throw new Error("end must be greater than start. start: "+t+", end: "+e);var n={},i=[];o.call(this,this.root,t+e>>1,i,!0),i.forEach(function(t){n[t.id]=!0});for(var s=this.pointTree.bsearch([t,null]),u=this.pointTree;s>=0&&u[s][0]==t;)s--;var a=this.pointTree.bsearch([e,null]);if(a>=0){for(var c=u.length-1;c>=a&&u[a][0]<=e;)a++;u.slice(s+1,a).forEach(function(t){var e=t[1];n[e]=!0},this),Object.keys(n).forEach(function(n){var i=this.intervalHash[n];r.push(i.result(t,e))},this)}}function u(t){this.idx=t,this.starts=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.start-e.start;return r>0?1:0==r?0:-1}}),this.ends=new c({compare:function(t,e){if(null==t)return-1;if(null==e)return 1;var r=t.end-e.end;return 0>r?1:0==r?0:-1}})}function a(t,e,r,n){if(this.id=e,this.start=t[r],this.end=t[n],this.data=t,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}var c=r(7);n.prototype.add=function(t,e){if(this.intervalHash[e])throw new Error("id "+e+" is already registered.");if(void 0==e){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;e=this._autoIncrement}var r=new a(t,e,this.startKey,this.endKey);this.pointTree.insert([r.start,e]),this.pointTree.insert([r.end,e]),this.intervalHash[e]=r,this._autoIncrement++,i.call(this,this.root,r)},n.prototype.search=function(t,e){var r=[];if("number"!=typeof t)throw new Error(t+": invalid input");if(void 0==e)o.call(this,this.root,t,r);else{if("number"!=typeof e)throw new Error(t+","+e+": invalid input");s.call(this,t,e,r)}return r},n.prototype.remove=function(t){},u.prototype.insert=function(t){this.starts.insert(t),this.ends.insert(t)},a.prototype.result=function(t,e){var r={id:this.id,data:this.data};if("number"==typeof t&&"number"==typeof e){var n=Math.max(this.start,t),i=Math.min(this.end,e),o=i-n;r.rate1=o/(e-t),r.rate2=o/(this.end-this.start)}return r},t.exports=n},function(t,e){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function i(){var t=null,e={},n=arguments;["0","1"].forEach(function(i){var o=n[i];Array.isArray(o)?t=o:o&&"object"==("undefined"==typeof o?"undefined":r(o))&&(e=o)}),"function"==typeof e.filter&&(this._filter=e.filter),"function"==typeof e.compare?this._compare=e.compare:"string"==typeof e.compare&&i.compares[e.compare]&&(this._compare=i.compares[e.compare]),this._unique=!!e.unique,e.resume&&t?t.forEach(function(t,e){this.push(t)},this):t&&this.insert.apply(this,t)};n.create=function(t,e){return new n(t,e)},n.prototype=new Array,n.prototype.constructor=Array.prototype.constructor,n.prototype.insertOne=function(t){var e=this.bsearch(t);return this._unique&&null!=this.key(t,e)?!1:this._filter(t,e)?(this.splice(e+1,0,t),e+1):!1},n.prototype.insert=function(){return Array.prototype.map.call(arguments,function(t){return this.insertOne(t)},this)},n.prototype.remove=function(t){return this.splice(t,1),this},n.prototype.bsearch=function(t){if(!this.length)return-1;for(var e,r=0,n=this.length;n-r>1;){e=Math.floor((r+n)/2);var i=this[e],o=this._compare(t,i);if(0==o)return e;o>0?r=e:n=e}return 0==r&&this._compare(this[0],t)>0?-1:r},n.prototype.key=function(t,e){null==e&&(e=this.bsearch(t));var r=e;if(-1==r||this._compare(this[r],t)<0)return r+1=1&&0==this._compare(this[r-1],t);)r--;return r},n.prototype.keys=function(t,e){var r=[];null==e&&(e=this.bsearch(t));for(var n=e;n>=0&&0==this._compare(this[n],t);)r.push(n),n--;var i=this.length;for(n=e+1;i>n&&0==this._compare(this[n],t);)r.push(n),n++;return r.length?r:null},n.prototype.unique=function(t){if(t)return this.filter(function(t,e){return 0==e||0!=this._compare(this[e-1],t)},this);var e=0;return this.map(function(t,r){return 0==r||0!=this._compare(this[r-1],t)?null:r-e++},this).forEach(function(t){null!=t&&this.remove(t)},this),this},n.prototype.toArray=function(){return this.slice()},n.prototype._filter=function(t,e){return!0},n.compares={number:function(t,e){var r=t-e;return r>0?1:0==r?0:-1},string:function(t,e){return t>e?1:t==e?0:-1}},n.prototype._compare=n.compares.string,t.exports=n},function(t,e,r){"use strict";function n(t){var e=new s.Variable(t.targetPos);return e.node=t,e}function i(t,e){if(t.length>0){e=o.extend(u,e),t.forEach(function(t,e){t.targetPos=t.parent?t.parent.currentPos:t.idealPos,t.index=e}),t.sort(function(t,e){var r=t.targetPos-e.targetPos;if(0!==r)return r;var n=t.isStub()-e.isStub();return 0!==n?n:t.index-e.index});for(var r=t.map(n),i=[],a=1;at;++t)this.ps.addVariable(this.vars[t]);this.posn=this.ps.getPosn()},t.prototype.compute_lm=function(t,e,r){var n=this,i=t.dfdv();return t.visitNeighbours(e,function(e,o){var s=n.compute_lm(o,t,r);o===e.right?(i+=s*e.left.scale,e.lm=s):(i+=s*e.right.scale,e.lm=-s),r(e)}),i/t.scale},t.prototype.populateSplitBlock=function(t,e){var r=this;t.visitNeighbours(e,function(e,n){n.offset=t.offset+(n===e.right?e.gap:-e.gap),r.addVariable(n),r.populateSplitBlock(n,t)})},t.prototype.traverse=function(t,e,r,n){var i=this;void 0===r&&(r=this.vars[0]),void 0===n&&(n=null),r.visitNeighbours(n,function(n,o){e.push(t(n)),i.traverse(t,e,o,r)})},t.prototype.findMinLM=function(){var t=null;return this.compute_lm(this.vars[0],null,function(e){!e.equality&&(null===t||e.lmn;++n){var o=t.vars[n];o.offset+=r,this.addVariable(o)}this.posn=this.ps.getPosn()},t.prototype.cost=function(){for(var t=0,e=this.vars.length;e--;){var r=this.vars[e],n=r.position()-r.desiredPosition;t+=n*n*r.weight}return t},t}();r.Block=s;var u=function(){function t(t){this.vs=t;var e=t.length;for(this.list=new Array(e);e--;){var r=new s(t[e]);this.list[e]=r,r.blockInd=e}}return t.prototype.cost=function(){for(var t=0,e=this.list.length;e--;)t+=this.list[e].cost();return t},t.prototype.insert=function(t){t.blockInd=this.list.length,this.list.push(t)},t.prototype.remove=function(t){var e=this.list.length-1,r=this.list[e];this.list.length=e,t!==r&&(this.list[t.blockInd]=r,r.blockInd=t.blockInd)},t.prototype.merge=function(t){var e=t.left.block,r=t.right.block,n=t.right.offset-t.left.offset-t.gap;e.vars.lengths;++s){var u=n[s];if(!u.unsatisfiable){var a=u.slack();if((u.equality||e>a)&&(e=a,r=u,o=s,u.equality))break}}return o!==i&&(e=0?this.inactive.push(e):this.bs.merge(e)}}},t.prototype.solve=function(){this.satisfy();for(var t=Number.MAX_VALUE,e=this.bs.cost();Math.abs(t-e)>1e-4;)this.satisfy(),t=e,e=this.bs.cost();return e},t.LAGRANGIAN_TOLERANCE=-1e-4,t.ZERO_UPPERBOUND=-1e-10,t}();r.Solver=a,t.exports=r},function(t,e,r){"use strict";function n(t){this.options=c.extend({layerGap:60,nodeHeight:h,direction:"down"},t)}function i(t){return"L "+t.join(" ")}function o(t){return"M "+t.join(" ")}function s(t,e,r){return"C "+t.join(" ")+" "+e.join(" ")+" "+r.join(" ")}function u(t,e){var r=(t[1]+e[1])/2;return s([t[0],r],[e[0],r],e)}function a(t,e){var r=(t[0]+e[0])/2;return s([r,t[1]],[r,e[1]],e)}var c=r(4),h=10;n.lineTo=i,n.moveTo=o,n.curveTo=s,n.vCurveBetween=u,n.hCurveBetween=a,n.prototype.getWaypoints=function(t){var e=this.options,r=c.functor(e.nodeHeight)(t),n=e.direction,i=t.getPathFromRoot(),o=r+e.layerGap;return"left"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[n+r,t.currentPos],[n,t.currentPos]]})):"right"===n?[[[0,i[0].idealPos]]].concat(i.map(function(t,e){var n=o*(e+1);return[[n-r,t.currentPos],[n,t.currentPos]]})):"up"===n?[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1)*-1;return[[t.currentPos,n+r],[t.currentPos,n]]})):[[[i[0].idealPos,0]]].concat(i.map(function(t,e){var n=o*(e+1);return[[t.currentPos,n-r],[t.currentPos,n]]}))},n.prototype.layout=function(t){var e=this.options,r=c.functor(e.nodeHeight);if("function"==typeof e.nodeHeight){var n=[];t.forEach(function(t,r){n[r]=e.layerGap+e.nodeHeight(t)})}var i=e.layerGap+e.nodeHeight;switch(e.direction){case"left":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=-s-r(t),t.y=t.currentPos,t.dx=r(t),t.dy=t.width});break;case"right":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=s,t.y=t.currentPos,t.dx=r(t),t.dy=t.width});break;case"up":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=-s-r(t),t.dx=t.width,t.dy=r(t)});break;default:case"down":t.forEach(function(t,o){var s=0;s=n?t.getLayerIndex()*n[o]+e.layerGap:t.getLayerIndex()*i+e.layerGap,t.x=t.currentPos,t.y=s,t.dx=t.width,t.dy=r(t)})}return t},n.prototype.generatePath=function(t){var e=this.options,r=e.direction,n=this.getWaypoints(t,r),s=[o(n[0][0])];return"left"===r||"right"===r?n.reduce(function(t,e,r){return s.push(a(t[t.length-1],e[0])),rLabels should be beautiful.
// ---------------------------------------------------
var data = [
- {date: new Date(2015,0,9), name: 'Snape'},
- {date: new Date(2015,0,30), name: 'Lily'},
- {date: new Date(2015,2,1), name: 'Ron'},
- {date: new Date(2015,2,27), name: 'James'},
- {date: new Date(2015,5,5), name: 'Draco'},
- {date: new Date(2015,6,30), name: 'Neville'},
- {date: new Date(2015,6,31), name: 'Harry'},
- {date: new Date(2015,8,19), name: 'Hermione'},
- {date: new Date(2015,11,6), name: 'Hagrid'},
- {date: new Date(2015,11,31), name: 'Voldemort'}
+ {date: new Date(2015,0,9), height: 30, name: 'Snape'},
+ {date: new Date(2015,0,30), height: 30, name: 'Lily'},
+ {date: new Date(2015,2,1), height: 30, name: 'Ron'},
+ {date: new Date(2015,2,27), height: 30, name: 'James'},
+ {date: new Date(2015,5,5), height: 50, name: 'Draco'},
+ {date: new Date(2015,6,30), height: 30, name: 'Neville'},
+ {date: new Date(2015,6,31), height: 30, name: 'Harry'},
+ {date: new Date(2015,8,19), height: 30, name: 'Hermione'},
+ {date: new Date(2015,11,6), height: 30, name: 'Hagrid'},
+ {date: new Date(2015,11,31), height: 30, name: 'Voldemort'}
];
var formatDate = d3.time.format('%b %e');
@@ -146,10 +146,9 @@ Labels should be beautiful.
var renderer = new labella.Renderer({
layerGap: 60,
- //nodeHeight: 30,//nodes[0].data.h,
- nodeHeight: function(nodeData){
- if(nodeData.name === "Draco" || nodeData.name === "Hermione") return 50;
- else return 30;
+ nodeHeight: function(node){
+ console.log(node);
+ return node.data.height;
},
direction: 'bottom'
});
diff --git a/src/core/renderer.js b/src/core/renderer.js
index 84a3bdd..a190ded 100644
--- a/src/core/renderer.js
+++ b/src/core/renderer.js
@@ -48,7 +48,7 @@ Renderer.hCurveBetween = hCurveBetween;
Renderer.prototype.getWaypoints = function(node){
var options = this.options;
- var nodeHeight = helper.functor(options.nodeHeight)(node.data);
+ var nodeHeight = helper.functor(options.nodeHeight)(node);
var direction = options.direction;
var hops = node.getPathFromRoot();
@@ -99,7 +99,7 @@ Renderer.prototype.layout = function(nodes){
if(typeof options.nodeHeight === 'function'){
var gaps = [];
nodes.forEach(function(node, index){
- gaps[index] = options.layerGap + options.nodeHeight(node.data);
+ gaps[index] = options.layerGap + options.nodeHeight(node);
});
}
@@ -115,9 +115,9 @@ Renderer.prototype.layout = function(nodes){
else{
pos = node.getLayerIndex() * gap + options.layerGap;
}
- node.x = -pos - nodeHeightFn(node.data);
+ node.x = -pos - nodeHeightFn(node);
node.y = node.currentPos;
- node.dx = nodeHeightFn(node.data);
+ node.dx = nodeHeightFn(node);
node.dy = node.width;
});
break;
@@ -132,7 +132,7 @@ Renderer.prototype.layout = function(nodes){
}
node.x = pos;
node.y = node.currentPos;
- node.dx = nodeHeightFn(node.data);
+ node.dx = nodeHeightFn(node);
node.dy = node.width;
});
break;
@@ -146,9 +146,9 @@ Renderer.prototype.layout = function(nodes){
pos = node.getLayerIndex() * gap + options.layerGap;
}
node.x = node.currentPos;
- node.y = -pos - nodeHeightFn(node.data);
+ node.y = -pos - nodeHeightFn(node);
node.dx = node.width;
- node.dy = nodeHeightFn(node.data);
+ node.dy = nodeHeightFn(node);
});
break;
default:
@@ -164,7 +164,7 @@ Renderer.prototype.layout = function(nodes){
node.x = node.currentPos;
node.y = pos;
node.dx = node.width;
- node.dy = nodeHeightFn(node.data);
+ node.dy = nodeHeightFn(node);
});
break;
}