@antv/hierarchy
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -82,3 +82,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var hierarchy = __webpack_require__(1); | ||
var hierarchy = __webpack_require__(2); | ||
@@ -107,2 +107,74 @@ var Layout = function () { | ||
/* 1 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var separateTree = __webpack_require__(3); | ||
var VALID_DIRECTIONS = ['LR', // left to right | ||
'RL', // right to left | ||
'TB', // top to bottom | ||
'BT', // bottom to top | ||
'H', // horizontal | ||
'V' // vertical | ||
]; | ||
var HORIZONTAL_DIRECTIONS = ['LR', 'RL', 'H']; | ||
var isHorizontal = function isHorizontal(direction) { | ||
return HORIZONTAL_DIRECTIONS.indexOf(direction) > -1; | ||
}; | ||
var DEFAULT_DIRECTION = VALID_DIRECTIONS[0]; | ||
module.exports = function (root, options, layoutAlgrithm) { | ||
var direction = options.direction || DEFAULT_DIRECTION; | ||
options.isHorizontal = isHorizontal(direction); | ||
if (direction && VALID_DIRECTIONS.indexOf(direction) === -1) { | ||
throw new TypeError('Invalid direction: ' + direction); | ||
} | ||
if (direction === VALID_DIRECTIONS[0]) { | ||
// LR | ||
layoutAlgrithm(root, options); | ||
} else if (direction === VALID_DIRECTIONS[1]) { | ||
// RL | ||
layoutAlgrithm(root, options); | ||
root.right2left(); | ||
} else if (direction === VALID_DIRECTIONS[2]) { | ||
// TB | ||
layoutAlgrithm(root, options); | ||
} else if (direction === VALID_DIRECTIONS[3]) { | ||
// BT | ||
layoutAlgrithm(root, options); | ||
root.bottom2top(); | ||
} else if (direction === VALID_DIRECTIONS[4] || direction === VALID_DIRECTIONS[5]) { | ||
// H or V | ||
// separate into left and right trees | ||
var _separateTree = separateTree(root, options), | ||
left = _separateTree.left, | ||
right = _separateTree.right; | ||
// do layout for left and right trees | ||
layoutAlgrithm(left, options); | ||
layoutAlgrithm(right, options); | ||
options.isHorizontal ? left.right2left() : left.bottom2top(); | ||
// combine left and right trees | ||
right.translate(left.x - right.x, left.y - right.y); | ||
// translate root | ||
root.x = left.x; | ||
root.y = right.y; | ||
var bb = root.getBoundingBox(); | ||
if (options.isHorizontal) { | ||
if (bb.top < 0) { | ||
root.translate(0, -bb.top); | ||
} | ||
} else { | ||
if (bb.left < 0) { | ||
root.translate(-bb.left, 0); | ||
} | ||
} | ||
} | ||
root.translate(-(root.x + root.width / 2 + root.hgap), -(root.y + root.height / 2 + root.vgap)); | ||
return root; | ||
}; | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, exports) { | ||
@@ -208,2 +280,3 @@ | ||
getBoundingBox: function getBoundingBox() { | ||
// BBox for just one tree node | ||
var bb = { | ||
@@ -287,78 +360,6 @@ left: Number.MAX_VALUE, | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var separateTree = __webpack_require__(3); | ||
var VALID_DIRECTIONS = ['LR', // left to right | ||
'RL', // right to left | ||
'TB', // top to bottom | ||
'BT', // bottom to top | ||
'H', // horizontal | ||
'V' // vertical | ||
]; | ||
var HORIZONTAL_DIRECTIONS = ['LR', 'RL', 'H']; | ||
var isHorizontal = function isHorizontal(direction) { | ||
return HORIZONTAL_DIRECTIONS.indexOf(direction) > -1; | ||
}; | ||
var DEFAULT_DIRECTION = VALID_DIRECTIONS[0]; | ||
module.exports = function (root, options, layoutAlgrithm) { | ||
var direction = options.direction || DEFAULT_DIRECTION; | ||
options.isHorizontal = isHorizontal(direction); | ||
if (direction && VALID_DIRECTIONS.indexOf(direction) === -1) { | ||
throw new TypeError('Invalid direction: ' + direction); | ||
} | ||
if (direction === VALID_DIRECTIONS[0]) { | ||
// LR | ||
layoutAlgrithm(root, options); | ||
} else if (direction === VALID_DIRECTIONS[1]) { | ||
// RL | ||
layoutAlgrithm(root, options); | ||
root.right2left(); | ||
} else if (direction === VALID_DIRECTIONS[2]) { | ||
// TB | ||
layoutAlgrithm(root, options); | ||
} else if (direction === VALID_DIRECTIONS[3]) { | ||
// BT | ||
layoutAlgrithm(root, options); | ||
root.bottom2top(); | ||
} else if (direction === VALID_DIRECTIONS[4] || direction === VALID_DIRECTIONS[5]) { | ||
// H or V | ||
// separate into left and right trees | ||
var _separateTree = separateTree(root, options), | ||
left = _separateTree.left, | ||
right = _separateTree.right; | ||
// do layout for left and right trees | ||
layoutAlgrithm(left, options); | ||
layoutAlgrithm(right, options); | ||
options.isHorizontal ? left.right2left() : left.bottom2top(); | ||
// combine left and right trees | ||
right.translate(left.x - right.x, left.y - right.y); | ||
// translate root | ||
root.x = left.x; | ||
root.y = right.y; | ||
var bb = root.getBoundingBox(); | ||
if (options.isHorizontal) { | ||
if (bb.top < 0) { | ||
root.translate(0, -bb.top); | ||
} | ||
} else { | ||
if (bb.left < 0) { | ||
root.translate(-bb.left, 0); | ||
} | ||
} | ||
} | ||
root.translate(-(root.x + root.width / 2 + root.hgap), -(root.y + root.height / 2 + root.vgap)); | ||
return root; | ||
}; | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
var hierarchy = __webpack_require__(1); | ||
var hierarchy = __webpack_require__(2); | ||
@@ -412,3 +413,4 @@ module.exports = function (root, options) { | ||
dendrogram: __webpack_require__(7), | ||
indented: __webpack_require__(9) | ||
indented: __webpack_require__(9), | ||
mindmap: __webpack_require__(11) | ||
}; | ||
@@ -430,3 +432,3 @@ | ||
var nonLayeredTidyTree = __webpack_require__(6); | ||
var doTreeLayout = __webpack_require__(2); | ||
var doTreeLayout = __webpack_require__(1); | ||
@@ -445,3 +447,2 @@ var CompactBoxTreeLayout = function (_TreeLayout) { | ||
var root = doTreeLayout(me.rootNode, me.options, nonLayeredTidyTree); | ||
root.translate(-(root.x + root.width / 2 + root.hgap), -(root.y + root.height / 2 + root.vgap)); | ||
return root; | ||
@@ -466,10 +467,6 @@ }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
// wrap tree node | ||
var WrappedTree = function WrappedTree(w, h, y) { | ||
function WrappedTree(w, h, y) { | ||
var c = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; | ||
_classCallCheck(this, WrappedTree); | ||
var me = this; | ||
@@ -505,3 +502,3 @@ // size | ||
me.mser = 0; | ||
}; | ||
} | ||
@@ -738,3 +735,3 @@ WrappedTree.fromNode = function (root, isHorizontal) { | ||
var dendrogram = __webpack_require__(8); | ||
var doTreeLayout = __webpack_require__(2); | ||
var doTreeLayout = __webpack_require__(1); | ||
@@ -981,2 +978,93 @@ var DendrogramLayout = function (_TreeLayout) { | ||
/***/ }), | ||
/* 11 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var TreeLayout = __webpack_require__(0); | ||
var mindmap = __webpack_require__(12); | ||
var doTreeLayout = __webpack_require__(1); | ||
var MindmapLayout = function (_TreeLayout) { | ||
_inherits(MindmapLayout, _TreeLayout); | ||
function MindmapLayout() { | ||
_classCallCheck(this, MindmapLayout); | ||
return _possibleConstructorReturn(this, _TreeLayout.apply(this, arguments)); | ||
} | ||
MindmapLayout.prototype.execute = function execute() { | ||
var me = this; | ||
var root = doTreeLayout(me.rootNode, me.options, mindmap); | ||
return root; | ||
}; | ||
return MindmapLayout; | ||
}(TreeLayout); | ||
var DEFAULT_OPTIONS = {}; | ||
function mindmapLayout(root, options) { | ||
options = Object.assign({}, DEFAULT_OPTIONS, options); | ||
return new MindmapLayout(root, options).execute(); | ||
} | ||
module.exports = mindmapLayout; | ||
/***/ }), | ||
/* 12 */ | ||
/***/ (function(module, exports) { | ||
function secondWalk(node) { | ||
if (node.isLeaf()) { | ||
node.totalHeight = node.height; | ||
} | ||
var totalHeight = 0; | ||
node.children.forEach(function (c) { | ||
totalHeight += secondWalk(c); | ||
}); | ||
node.totalHeight = Math.max(node.height, totalHeight); | ||
return node.totalHeight; | ||
} | ||
module.exports = function (root) { | ||
root.parent = { | ||
x: 0, | ||
width: 0, | ||
height: 0, | ||
y: 0 | ||
}; | ||
// first walk | ||
root.BFTraverse(function (node) { | ||
node.x = node.parent.x + node.parent.width; // simply get x | ||
}); | ||
root.parent = null; | ||
// second walk | ||
secondWalk(root); // assign sub tree totalHeight | ||
// separating nodes | ||
root.startY = 0; | ||
root.y = root.totalHeight / 2; | ||
root.eachNode(function (node) { | ||
var children = node.children; | ||
var len = children.length; | ||
if (len) { | ||
var first = children[0]; | ||
first.startY = node.startY; | ||
first.y = first.startY + first.totalHeight / 2; | ||
for (var i = 1; i < len; i++) { | ||
var c = children[i]; | ||
c.startY = children[i - 1].startY + children[i - 1].totalHeight; | ||
c.y = c.startY + c.totalHeight / 2; | ||
} | ||
} | ||
}); | ||
}; | ||
/***/ }) | ||
@@ -983,0 +1071,0 @@ /******/ ]); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Hierarchy=e():t.Hierarchy=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,n){var r=n(1),o=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);this.options=n,this.rootNode=r(e,n)}return t.prototype.execute=function(){throw new Error("please override this method")},t}();t.exports=o},function(t,e){function n(t,e){var r=this;if(r.vgap=r.hgap=0,t instanceof n)return t;r.data=t;var o=e.getHGap(t),i=e.getVGap(t);return r.width=e.getWidth(t),r.height=e.getHeight(t),r.id=e.getId(t),r.x=r.y=0,r.depth=0,r.children||(r.children=[]),r.addGap(o,i),r}var r={getId:function(t){return t.id||t.name},getHGap:function(t){return t.hgap||18},getVGap:function(t){return t.vgap||18},getChildren:function(t){return t.children},getHeight:function(t){return t.height||36},getWidth:function(t){var e=t.name||" ";return t.width||18*e.split("").length}};Object.assign(n.prototype,{isRoot:function(){return 0===this.depth},isLeaf:function(){return 0===this.children.length},addGap:function(t,e){this.hgap+=t,this.vgap+=e,this.width+=2*t,this.height+=2*e},eachNode:function(t){for(var e=[this],n=void 0;n=e.pop();)t(n),e=e.concat(n.children)},DFTraverse:function(t){this.eachNode(t)},BFTraverse:function(t){for(var e=[this],n=void 0;n=e.shift();)t(n),e=e.concat(n.children)},getBoundingBox:function(){var t={left:Number.MAX_VALUE,top:Number.MAX_VALUE,width:0,height:0};return this.eachNode(function(e){t.left=Math.min(t.left,e.x),t.top=Math.min(t.top,e.y),t.width=Math.max(t.width,e.x+e.width),t.height=Math.max(t.height,e.y+e.height)}),t},translate:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.eachNode(function(n){n.x+=t,n.y+=e})},right2left:function(){var t=this.getBoundingBox();this.eachNode(function(e){e.x=e.x-2*(e.x-t.left)-e.width}),this.translate(t.width,0)},bottom2top:function(){var t=this.getBoundingBox();this.eachNode(function(e){e.y=e.y-2*(e.y-t.top)-e.height}),this.translate(0,t.height)}}),t.exports=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments[2],i=new n(t,e=Object.assign({},r,e)),c=[i],a=void 0;if(!o&&!t.collapsed)for(;a=c.pop();)if(!a.data.collapsed){var f=e.getChildren(a.data),u=f?f.length:0;if(a.children=new Array(u),f&&u)for(var h=0;h<u;h++){var l=new n(f[h],e);a.children[h]=l,c.push(l),l.parent=a,l.depth=a.depth+1}}return i}},function(t,e,n){var r=n(3),o=["LR","RL","TB","BT","H","V"],i=["LR","RL","H"],c=o[0];t.exports=function(t,e,n){var a=e.direction||c;if(e.isHorizontal=function(t){return i.indexOf(t)>-1}(a),a&&-1===o.indexOf(a))throw new TypeError("Invalid direction: "+a);if(a===o[0])n(t,e);else if(a===o[1])n(t,e),t.right2left();else if(a===o[2])n(t,e);else if(a===o[3])n(t,e),t.bottom2top();else if(a===o[4]||a===o[5]){var f=r(t,e),u=f.left,h=f.right;n(u,e),n(h,e),e.isHorizontal?u.right2left():u.bottom2top(),h.translate(u.x-h.x,u.y-h.y),t.x=u.x,t.y=h.y;var l=t.getBoundingBox();e.isHorizontal?l.top<0&&t.translate(0,-l.top):l.left<0&&t.translate(-l.left,0)}return t.translate(-(t.x+t.width/2+t.hgap),-(t.y+t.height/2+t.vgap)),t}},function(t,e,n){var r=n(1);t.exports=function(t,e){for(var n=r(t.data,e,!0),o=r(t.data,e,!0),i=t.children.length,c=Math.round(i/2),a=e.getSide||function(t,e){return e<c?"right":"left"},f=0;f<i;f++){var u=t.children[f];"right"===a(u,f)?o.children.push(u):n.children.push(u)}return n.eachNode(function(t){t.isRoot()||(t.side="left")}),o.eachNode(function(t){t.isRoot()||(t.side="right")}),{left:n,right:o}}},function(t,e,n){var r={compactBox:n(5),dendrogram:n(7),indented:n(9)};t.exports=r},function(t,e,n){var r=n(0),o=n(6),i=n(2),c=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.execute=function(){var t=i(this.rootNode,this.options,o);return t.translate(-(t.x+t.width/2+t.hgap),-(t.y+t.height/2+t.vgap)),t},e}(r),a={};t.exports=function(t,e){return e=Object.assign({},a,e),new c(t,e).execute()}},function(t,e){function n(t,e,r){r?t.y+=e:t.x+=e,t.children.forEach(function(t){n(t,e,r)})}function r(t,e){var n=e?t.y:t.x;return t.children.forEach(function(t){n=Math.min(r(t,e),n)}),n}function o(t,e,n){n?e.y=t.x:e.x=t.x,t.c.forEach(function(t,r){o(t,e.children[r],n)})}function i(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;e?(t.x=n,n+=t.width):(t.y=n,n+=t.height),t.children.forEach(function(t){i(t,e,n)})}var c=function t(e,n,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var i=this;i.w=e||0,i.h=n||0,i.y=r||0,i.x=0,i.c=o||[],i.cs=o.length,i.prelim=0,i.mod=0,i.shift=0,i.change=0,i.tl=null,i.tr=null,i.el=null,i.er=null,i.msel=0,i.mser=0};c.fromNode=function(t,e){if(!t)return null;var n=[];return t.children.forEach(function(t){n.push(c.fromNode(t,e))}),e?new c(t.height,t.width,t.x,n):new c(t.width,t.height,t.y,n)},t.exports=function(t){function e(t){if(0!==t.cs){e(t.c[0]);for(var n=h(f(t.c[0].el),0,null),r=1;r<t.cs;++r){e(t.c[r]);var o=f(t.c[r].er);!function(t,e,n){var r=t.c[e-1],o=r.mod,i=t.c[e],c=i.mod;for(;null!==r&&null!==i;){f(r)>n.low&&(n=n.nxt);var a=o+r.prelim+r.w-(c+i.prelim);a>0&&(c+=a,function(t,e,n,r){t.c[e].mod+=r,t.c[e].msel+=r,t.c[e].mser+=r,function(t,e,n,r){if(n!==e-1){var o=e-n;t.c[n+1].shift+=r/o,t.c[e].shift-=r/o,t.c[e].change-=r-r/o}}(t,e,n,r)}(t,e,n.index,a));var u=f(r),h=f(i);u<=h&&null!==(r=function(t){return 0===t.cs?t.tr:t.c[t.cs-1]}(r))&&(o+=r.mod),u>=h&&null!==(i=function(t){return 0===t.cs?t.tl:t.c[0]}(i))&&(c+=i.mod)}!r&&i?function(t,e,n,r){var o=t.c[0].el;o.tl=n;var i=r-n.mod-t.c[0].msel;o.mod+=i,o.prelim-=i,t.c[0].el=t.c[e].el,t.c[0].msel=t.c[e].msel}(t,e,i,c):r&&!i&&function(t,e,n,r){var o=t.c[e].er;o.tr=n;var i=r-n.mod-t.c[e].mser;o.mod+=i,o.prelim-=i,t.c[e].er=t.c[e-1].er,t.c[e].mser=t.c[e-1].mser}(t,e,r,o)}(t,r,n),n=h(o,r,n)}!function(t){t.prelim=(t.c[0].prelim+t.c[0].mod+t.c[t.cs-1].mod+t.c[t.cs-1].prelim+t.c[t.cs-1].w)/2-t.w/2}(t),a(t)}else a(t)}function a(t){0===t.cs?(t.el=t,t.er=t,t.msel=t.mser=0):(t.el=t.c[0].el,t.msel=t.c[0].msel,t.er=t.c[t.cs-1].er,t.mser=t.c[t.cs-1].mser)}function f(t){return t.y+t.h}function u(t,e){e+=t.mod,t.x=t.prelim+e,function(t){for(var e=0,n=0,r=0;r<t.cs;r++)e+=t.c[r].shift,n+=e+t.c[r].change,t.c[r].mod+=n}(t);for(var n=0;n<t.cs;n++)u(t.c[n],e)}function h(t,e,n){for(;null!==n&&t>=n.low;)n=n.nxt;return{low:t,index:e,nxt:n}}var l=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).isHorizontal;i(t,l);var s=c.fromNode(t,l);return e(s),u(s,0),o(s,t,l),function(t,e){n(t,-r(t,e),e)}(t,l),t}},function(t,e,n){var r=n(0),o=n(8),i=n(2),c=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.execute=function(){return this.rootNode.width=0,i(this.rootNode,this.options,o)},e}(r),a={};t.exports=function(t,e){return e=Object.assign({},a,e),new c(t,e).execute()}},function(t,e){function n(t,e,r){r?(e.x=t.x,e.y=t.y):(e.x=t.y,e.y=t.x),t.children.forEach(function(t,o){n(t,e.children[o],r)})}var r=function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var r=this;r.x=r.y=0,r.leftChild=r.rightChild=null,r.height=e||0,r.children=n},o={isHorizontal:!0,nodeSep:20,nodeSize:20,rankSep:200,subTreeSep:10};t.exports=function(t){function e(t){if(!t)return null;t.width=0,t.depth&&t.depth>f&&(f=t.depth);var n=t.children,o=n.length,i=new r(t.height,[]);return n.forEach(function(t,n){var r=e(t);i.children.push(r),0===n&&(i.leftChild=r),n===o-1&&(i.rightChild=r)}),i.originNode=t,i.isLeaf=t.isLeaf(),i}function i(t){if(t.isLeaf||0===t.children.length)t.drawingDepth=f;else{var e=t.children.map(function(t){return i(t)}),n=Math.min.apply(null,e);t.drawingDepth=n-1}return t.drawingDepth}function c(t){t.x=t.drawingDepth*a.rankSep,t.isLeaf?(t.y=0,u&&(t.y=u.y+u.height+a.nodeSep,t.originNode.parent!==u.originNode.parent&&(t.y+=a.subTreeSep)),u=t):(t.children.forEach(function(t){c(t)}),t.y=(t.leftChild.y+t.rightChild.y)/2)}var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};a=Object.assign({},o,a);var f=0,u=void 0,h=e(t);return i(h),c(h),n(h,t,a.isHorizontal),t}},function(t,e,n){var r=n(0),o=n(10),i=n(3),c=["LR","RL","H"],a=c[0],f=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.execute=function(){var t=this.options,e=this.rootNode;t.isHorizontal=!0;var n=t.indent,r=t.direction||a;if(r&&-1===c.indexOf(r))throw new TypeError("Invalid direction: "+r);if(r===c[0])o(e,n);else if(r===c[1])o(e,n),e.right2left();else if(r===c[2]){var f=i(e,t),u=f.left,h=f.right;o(u,n),u.right2left(),o(h,n);var l=u.getBoundingBox();h.translate(l.width,0),e.x=h.x-e.width/2}return e},e}(r),u={};t.exports=function(t,e){return e=Object.assign({},u,e),new f(t,e).execute()}},function(t,e){t.exports=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,n=null;t.eachNode(function(t){!function(t,e,n){t.x+=n*t.depth,t.y=e?e.y+e.height:0}(t,n,e),n=t})}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Hierarchy=e():t.Hierarchy=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,n){var r=n(2),o=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);this.options=n,this.rootNode=r(e,n)}return t.prototype.execute=function(){throw new Error("please override this method")},t}();t.exports=o},function(t,e,n){var r=n(3),o=["LR","RL","TB","BT","H","V"],i=["LR","RL","H"],c=o[0];t.exports=function(t,e,n){var a=e.direction||c;if(e.isHorizontal=function(t){return i.indexOf(t)>-1}(a),a&&-1===o.indexOf(a))throw new TypeError("Invalid direction: "+a);if(a===o[0])n(t,e);else if(a===o[1])n(t,e),t.right2left();else if(a===o[2])n(t,e);else if(a===o[3])n(t,e),t.bottom2top();else if(a===o[4]||a===o[5]){var f=r(t,e),u=f.left,h=f.right;n(u,e),n(h,e),e.isHorizontal?u.right2left():u.bottom2top(),h.translate(u.x-h.x,u.y-h.y),t.x=u.x,t.y=h.y;var l=t.getBoundingBox();e.isHorizontal?l.top<0&&t.translate(0,-l.top):l.left<0&&t.translate(-l.left,0)}return t.translate(-(t.x+t.width/2+t.hgap),-(t.y+t.height/2+t.vgap)),t}},function(t,e){function n(t,e){var r=this;if(r.vgap=r.hgap=0,t instanceof n)return t;r.data=t;var o=e.getHGap(t),i=e.getVGap(t);return r.width=e.getWidth(t),r.height=e.getHeight(t),r.id=e.getId(t),r.x=r.y=0,r.depth=0,r.children||(r.children=[]),r.addGap(o,i),r}var r={getId:function(t){return t.id||t.name},getHGap:function(t){return t.hgap||18},getVGap:function(t){return t.vgap||18},getChildren:function(t){return t.children},getHeight:function(t){return t.height||36},getWidth:function(t){var e=t.name||" ";return t.width||18*e.split("").length}};Object.assign(n.prototype,{isRoot:function(){return 0===this.depth},isLeaf:function(){return 0===this.children.length},addGap:function(t,e){this.hgap+=t,this.vgap+=e,this.width+=2*t,this.height+=2*e},eachNode:function(t){for(var e=[this],n=void 0;n=e.pop();)t(n),e=e.concat(n.children)},DFTraverse:function(t){this.eachNode(t)},BFTraverse:function(t){for(var e=[this],n=void 0;n=e.shift();)t(n),e=e.concat(n.children)},getBoundingBox:function(){var t={left:Number.MAX_VALUE,top:Number.MAX_VALUE,width:0,height:0};return this.eachNode(function(e){t.left=Math.min(t.left,e.x),t.top=Math.min(t.top,e.y),t.width=Math.max(t.width,e.x+e.width),t.height=Math.max(t.height,e.y+e.height)}),t},translate:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.eachNode(function(n){n.x+=t,n.y+=e})},right2left:function(){var t=this.getBoundingBox();this.eachNode(function(e){e.x=e.x-2*(e.x-t.left)-e.width}),this.translate(t.width,0)},bottom2top:function(){var t=this.getBoundingBox();this.eachNode(function(e){e.y=e.y-2*(e.y-t.top)-e.height}),this.translate(0,t.height)}}),t.exports=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments[2],i=new n(t,e=Object.assign({},r,e)),c=[i],a=void 0;if(!o&&!t.collapsed)for(;a=c.pop();)if(!a.data.collapsed){var f=e.getChildren(a.data),u=f?f.length:0;if(a.children=new Array(u),f&&u)for(var h=0;h<u;h++){var l=new n(f[h],e);a.children[h]=l,c.push(l),l.parent=a,l.depth=a.depth+1}}return i}},function(t,e,n){var r=n(2);t.exports=function(t,e){for(var n=r(t.data,e,!0),o=r(t.data,e,!0),i=t.children.length,c=Math.round(i/2),a=e.getSide||function(t,e){return e<c?"right":"left"},f=0;f<i;f++){var u=t.children[f];"right"===a(u,f)?o.children.push(u):n.children.push(u)}return n.eachNode(function(t){t.isRoot()||(t.side="left")}),o.eachNode(function(t){t.isRoot()||(t.side="right")}),{left:n,right:o}}},function(t,e,n){var r={compactBox:n(5),dendrogram:n(7),indented:n(9),mindmap:n(11)};t.exports=r},function(t,e,n){var r=n(0),o=n(6),i=n(1),c=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.execute=function(){return i(this.rootNode,this.options,o)},e}(r),a={};t.exports=function(t,e){return e=Object.assign({},a,e),new c(t,e).execute()}},function(t,e){function n(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],o=this;o.w=t||0,o.h=e||0,o.y=n||0,o.x=0,o.c=r||[],o.cs=r.length,o.prelim=0,o.mod=0,o.shift=0,o.change=0,o.tl=null,o.tr=null,o.el=null,o.er=null,o.msel=0,o.mser=0}function r(t,e,n){n?t.y+=e:t.x+=e,t.children.forEach(function(t){r(t,e,n)})}function o(t,e){var n=e?t.y:t.x;return t.children.forEach(function(t){n=Math.min(o(t,e),n)}),n}function i(t,e,n){n?e.y=t.x:e.x=t.x,t.c.forEach(function(t,r){i(t,e.children[r],n)})}function c(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;e?(t.x=n,n+=t.width):(t.y=n,n+=t.height),t.children.forEach(function(t){c(t,e,n)})}n.fromNode=function(t,e){if(!t)return null;var r=[];return t.children.forEach(function(t){r.push(n.fromNode(t,e))}),e?new n(t.height,t.width,t.x,r):new n(t.width,t.height,t.y,r)},t.exports=function(t){function e(t){if(0!==t.cs){e(t.c[0]);for(var n=h(f(t.c[0].el),0,null),r=1;r<t.cs;++r){e(t.c[r]);var o=f(t.c[r].er);!function(t,e,n){var r=t.c[e-1],o=r.mod,i=t.c[e],c=i.mod;for(;null!==r&&null!==i;){f(r)>n.low&&(n=n.nxt);var a=o+r.prelim+r.w-(c+i.prelim);a>0&&(c+=a,function(t,e,n,r){t.c[e].mod+=r,t.c[e].msel+=r,t.c[e].mser+=r,function(t,e,n,r){if(n!==e-1){var o=e-n;t.c[n+1].shift+=r/o,t.c[e].shift-=r/o,t.c[e].change-=r-r/o}}(t,e,n,r)}(t,e,n.index,a));var u=f(r),h=f(i);u<=h&&null!==(r=function(t){return 0===t.cs?t.tr:t.c[t.cs-1]}(r))&&(o+=r.mod),u>=h&&null!==(i=function(t){return 0===t.cs?t.tl:t.c[0]}(i))&&(c+=i.mod)}!r&&i?function(t,e,n,r){var o=t.c[0].el;o.tl=n;var i=r-n.mod-t.c[0].msel;o.mod+=i,o.prelim-=i,t.c[0].el=t.c[e].el,t.c[0].msel=t.c[e].msel}(t,e,i,c):r&&!i&&function(t,e,n,r){var o=t.c[e].er;o.tr=n;var i=r-n.mod-t.c[e].mser;o.mod+=i,o.prelim-=i,t.c[e].er=t.c[e-1].er,t.c[e].mser=t.c[e-1].mser}(t,e,r,o)}(t,r,n),n=h(o,r,n)}!function(t){t.prelim=(t.c[0].prelim+t.c[0].mod+t.c[t.cs-1].mod+t.c[t.cs-1].prelim+t.c[t.cs-1].w)/2-t.w/2}(t),a(t)}else a(t)}function a(t){0===t.cs?(t.el=t,t.er=t,t.msel=t.mser=0):(t.el=t.c[0].el,t.msel=t.c[0].msel,t.er=t.c[t.cs-1].er,t.mser=t.c[t.cs-1].mser)}function f(t){return t.y+t.h}function u(t,e){e+=t.mod,t.x=t.prelim+e,function(t){for(var e=0,n=0,r=0;r<t.cs;r++)e+=t.c[r].shift,n+=e+t.c[r].change,t.c[r].mod+=n}(t);for(var n=0;n<t.cs;n++)u(t.c[n],e)}function h(t,e,n){for(;null!==n&&t>=n.low;)n=n.nxt;return{low:t,index:e,nxt:n}}var l=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).isHorizontal;c(t,l);var s=n.fromNode(t,l);return e(s),u(s,0),i(s,t,l),function(t,e){r(t,-o(t,e),e)}(t,l),t}},function(t,e,n){var r=n(0),o=n(8),i=n(1),c=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.execute=function(){return this.rootNode.width=0,i(this.rootNode,this.options,o)},e}(r),a={};t.exports=function(t,e){return e=Object.assign({},a,e),new c(t,e).execute()}},function(t,e){function n(t,e,r){r?(e.x=t.x,e.y=t.y):(e.x=t.y,e.y=t.x),t.children.forEach(function(t,o){n(t,e.children[o],r)})}var r=function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var r=this;r.x=r.y=0,r.leftChild=r.rightChild=null,r.height=e||0,r.children=n},o={isHorizontal:!0,nodeSep:20,nodeSize:20,rankSep:200,subTreeSep:10};t.exports=function(t){function e(t){if(!t)return null;t.width=0,t.depth&&t.depth>f&&(f=t.depth);var n=t.children,o=n.length,i=new r(t.height,[]);return n.forEach(function(t,n){var r=e(t);i.children.push(r),0===n&&(i.leftChild=r),n===o-1&&(i.rightChild=r)}),i.originNode=t,i.isLeaf=t.isLeaf(),i}function i(t){if(t.isLeaf||0===t.children.length)t.drawingDepth=f;else{var e=t.children.map(function(t){return i(t)}),n=Math.min.apply(null,e);t.drawingDepth=n-1}return t.drawingDepth}function c(t){t.x=t.drawingDepth*a.rankSep,t.isLeaf?(t.y=0,u&&(t.y=u.y+u.height+a.nodeSep,t.originNode.parent!==u.originNode.parent&&(t.y+=a.subTreeSep)),u=t):(t.children.forEach(function(t){c(t)}),t.y=(t.leftChild.y+t.rightChild.y)/2)}var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};a=Object.assign({},o,a);var f=0,u=void 0,h=e(t);return i(h),c(h),n(h,t,a.isHorizontal),t}},function(t,e,n){var r=n(0),o=n(10),i=n(3),c=["LR","RL","H"],a=c[0],f=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.execute=function(){var t=this.options,e=this.rootNode;t.isHorizontal=!0;var n=t.indent,r=t.direction||a;if(r&&-1===c.indexOf(r))throw new TypeError("Invalid direction: "+r);if(r===c[0])o(e,n);else if(r===c[1])o(e,n),e.right2left();else if(r===c[2]){var f=i(e,t),u=f.left,h=f.right;o(u,n),u.right2left(),o(h,n);var l=u.getBoundingBox();h.translate(l.width,0),e.x=h.x-e.width/2}return e},e}(r),u={};t.exports=function(t,e){return e=Object.assign({},u,e),new f(t,e).execute()}},function(t,e){t.exports=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,n=null;t.eachNode(function(t){!function(t,e,n){t.x+=n*t.depth,t.y=e?e.y+e.height:0}(t,n,e),n=t})}},function(t,e,n){var r=n(0),o=n(12),i=n(1),c=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.execute=function(){return i(this.rootNode,this.options,o)},e}(r),a={};t.exports=function(t,e){return e=Object.assign({},a,e),new c(t,e).execute()}},function(t,e){function n(t){t.isLeaf()&&(t.totalHeight=t.height);var e=0;return t.children.forEach(function(t){e+=n(t)}),t.totalHeight=Math.max(t.height,e),t.totalHeight}t.exports=function(t){t.parent={x:0,width:0,height:0,y:0},t.BFTraverse(function(t){t.x=t.parent.x+t.parent.width}),t.parent=null,n(t),t.startY=0,t.y=t.totalHeight/2,t.eachNode(function(t){var e=t.children,n=e.length;if(n){var r=e[0];r.startY=t.startY,r.y=r.startY+r.totalHeight/2;for(var o=1;o<n;o++){var i=e[o];i.startY=e[o-1].startY+e[o-1].totalHeight,i.y=i.startY+i.totalHeight/2}}})}}])}); |
@@ -23,3 +23,2 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var root = doTreeLayout(me.rootNode, me.options, nonLayeredTidyTree); | ||
root.translate(-(root.x + root.width / 2 + root.hgap), -(root.y + root.height / 2 + root.vgap)); | ||
return root; | ||
@@ -26,0 +25,0 @@ }; |
@@ -5,5 +5,6 @@ | ||
dendrogram: require('./dendrogram'), | ||
indented: require('./indented') | ||
indented: require('./indented'), | ||
mindmap: require('./mindmap') | ||
}; | ||
module.exports = hierarchy; |
@@ -99,2 +99,3 @@ /* eslint-disable no-cond-assign */ | ||
getBoundingBox: function getBoundingBox() { | ||
// BBox for just one tree node | ||
var bb = { | ||
@@ -101,0 +102,0 @@ left: Number.MAX_VALUE, |
@@ -1,9 +0,5 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
// wrap tree node | ||
var WrappedTree = function WrappedTree(w, h, y) { | ||
function WrappedTree(w, h, y) { | ||
var c = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; | ||
_classCallCheck(this, WrappedTree); | ||
var me = this; | ||
@@ -39,3 +35,3 @@ // size | ||
me.mser = 0; | ||
}; | ||
} | ||
@@ -42,0 +38,0 @@ WrappedTree.fromNode = function (root, isHorizontal) { |
{ | ||
"name": "@antv/hierarchy", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "layout algorithms for visualizing hierarchical data", | ||
@@ -5,0 +5,0 @@ "main": "build/hierarchy.js", |
@@ -9,3 +9,2 @@ const TreeLayout = require('./layout/base'); | ||
const root = doTreeLayout(me.rootNode, me.options, nonLayeredTidyTree); | ||
root.translate(-(root.x + root.width / 2 + root.hgap), -(root.y + root.height / 2 + root.vgap)); | ||
return root; | ||
@@ -12,0 +11,0 @@ } |
@@ -5,5 +5,6 @@ | ||
dendrogram: require('./dendrogram'), | ||
indented: require('./indented') | ||
indented: require('./indented'), | ||
mindmap: require('./mindmap') | ||
}; | ||
module.exports = hierarchy; |
@@ -102,2 +102,3 @@ /* eslint-disable no-cond-assign */ | ||
getBoundingBox() { | ||
// BBox for just one tree node | ||
const bb = { | ||
@@ -104,0 +105,0 @@ left: Number.MAX_VALUE, |
// wrap tree node | ||
class WrappedTree { | ||
constructor(w, h, y, c = []) { | ||
const me = this; | ||
function WrappedTree(w, h, y, c = []) { | ||
const me = this; | ||
// size | ||
me.w = w || 0; | ||
me.h = h || 0; | ||
me.w = w || 0; | ||
me.h = h || 0; | ||
// position | ||
me.y = y || 0; | ||
me.x = 0; | ||
me.y = y || 0; | ||
me.x = 0; | ||
// children | ||
me.c = c || []; | ||
me.cs = c.length; | ||
me.c = c || []; | ||
me.cs = c.length; | ||
// modified | ||
me.prelim = 0; | ||
me.mod = 0; | ||
me.shift = 0; | ||
me.change = 0; | ||
me.prelim = 0; | ||
me.mod = 0; | ||
me.shift = 0; | ||
me.change = 0; | ||
// left/right tree | ||
me.tl = null; | ||
me.tr = null; | ||
me.tl = null; | ||
me.tr = null; | ||
// extreme left/right tree | ||
me.el = null; | ||
me.er = null; | ||
me.el = null; | ||
me.er = null; | ||
// modified left/right tree | ||
me.msel = 0; | ||
me.mser = 0; | ||
} | ||
me.msel = 0; | ||
me.mser = 0; | ||
} | ||
WrappedTree.fromNode = (root, isHorizontal) => { | ||
@@ -37,0 +36,0 @@ if (!root) return null; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
190415
52
2748