Skip to content

Commit

Permalink
feat: Individual height of nodes depending of content
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikGartner committed Jan 5, 2016
1 parent 2b26e5b commit 6d9aa8a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ class TreeBuilder {
};
})
.attr('x', function(d) {
return d.x - nodeSize[0] / 2 + 'px';
return d.x - d.cWidth / 2 + 'px';
})
.attr('y', function(d) {
return d.y - nodeSize[1] / 2 + 'px';
return d.y - d.cHeight / 2 + 'px';
})
.attr('width', function(d) {
return d.cWidth + 'px';
})
.attr('height', function(d) {
return d.cHeight + 'px';
})
.attr('width', nodeSize[0] + 'px')
.attr('height', nodeSize[1] + 'px')
.attr('id', function(d) {
return d.id;
})
Expand Down Expand Up @@ -239,7 +243,7 @@ class TreeBuilder {
static _nodeSize(nodes, width, textRenderer) {
var maxWidth = 0;
var maxHeight = 0;
_.forEach(nodes, function(n) {
_.map(nodes, function(n) {
var container = document.createElement('div');
container.style.marginLeft = '5px';
container.style.paddingTop = '5px';
Expand All @@ -248,11 +252,14 @@ class TreeBuilder {

var text = textRenderer(n.name, n.extra, n.textClass);
container.innerHTML = text;

document.body.appendChild(container);

maxHeight = Math.max(maxHeight, container.offsetHeight);
maxWidth = Math.max(maxWidth, container.clientWidth);
var height = container.offsetHeight;
document.body.removeChild(container);

maxHeight = Math.max(maxHeight, height);
n.cHeight = height;
n.cWidth = width;
});
return [width, maxHeight];
}
Expand Down

0 comments on commit 6d9aa8a

Please sign in to comment.