Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private getLayout(): HierarchyPointNode> {
// create a hierarchical representation of the data - don't include collapsed nodes
const treeHierarchy = hierarchy(this.dataset, node => Array.isArray(node.children) && node.expanded ? node.children : []);
// create our layout
const layout = tree>()
.nodeSize([this.nodeWidth, this.nodeHeight])
.separation(this.getNodeSpacing.bind(this));
// process the data with the layout
const treeLayout = layout(treeHierarchy);
// calculate the vertical spacing
const verticalSpacing = this.verticalSpacing === undefined ? this.nodeHeight : this.verticalSpacing;
// set the vertical spacing
treeLayout.each(data => data.y = data.depth * (this.nodeHeight + verticalSpacing));
return treeLayout;
}
this.options.minHeight,
this.options.leafNodeHeight * this.root.leaves().length
);
// if (!this.root.x0) {
this.root.x0 = height / 2;
this.root.y0 = 0;
// }
this.svg
.transition()
.duration(this.options.transitionDuration)
.attr("width", width + this.margins.left + this.margins.right)
.attr("height", height + this.margins.top + this.margins.bottom);
d3Tree().size([height, width])(this.root);
source = source || this.root;
// compute scales for nodes
let nodeScale = scaleLinear()
.domain(this.range)
.range([4, 20]);
let linkScale = scaleLinear()
.domain(this.range)
.range([1, 20]);
let fontScale = scaleLinear()
.domain(this.range)
.range([this.options.smallerFont, this.options.largerFont]);
let link = this.pathContainer
.selectAll(".link")
layout: () => {
const layout = tree().size([1, 1]);
return input => {
const root = layout(input);
root.descendants().forEach(node => {
const hold = node.x;
node.x = node.y;
node.y = hold;
});
return root;
};
},
getXScale: ({width, margin}, root) => {
() =>
d3Tree()
.size([2 * Math.PI, innerRadius])
.separation((a, b) => (a.parent === b.parent ? 1 : 2.4) / a.depth),
[innerRadius]
export function TREE_LAYOUT(rootNode: StateVisNode) {
let root = hierarchy(rootNode);
let tree = d3tree();
return updateNodes(tree(root));
}
renderTree() {
let {
width,
nodes,
name,
allowScaleWidth,
selectedNodeId,
onRenderedBeyondWidth,
toWiden
} = this.props;
if (nodes.length > 0) {
let horizontalSpaceBetweenLeaves = toWiden
? WIDE_HORIZONTAL_SPACES
: NARROW_HORIZONTAL_SPACES;
const treeFn = tree().nodeSize([
horizontalSpaceBetweenLeaves,
verticalSpaceBetweenNodes
]); //.size([width - 50, height - 50])
let root = stratifyFn(nodes).sort((a, b) =>
a.data.name.localeCompare(b.data.name)
);
let svgHeight =
verticalSpaceBetweenNodes * root.height + nodeRadius * 6;
treeFn(root);
let nodesXValue = root.descendants().map(node => node.x);
let maxX = Math.max(...nodesXValue);
let minX = Math.min(...nodesXValue);
let svgTempWidth =
constructor() {
super();
ITree.call(this);
Utility.SimpleSelectionMixin.call(this);
this._drawStartPos = "origin";
this._d3LayoutCluster = d3Cluster();
this._d3LayoutTree = d3Tree();
}