Compute the layout positions

@param node Node to start with
@param depth Depth of the node
@param aoff Angular offset
@param awid Angular width
@param maxdepth Maximum depth (used for radius computations)
422627
public static void computePositions(Node node, int depth, double aoff, double awid, int maxdepth) {
    double r = depth / (maxdepth - 1.);
    node.x = FastMath.sin(aoff + awid * .5) * r;
    node.y = FastMath.cos(aoff + awid * .5) * r;

    double cpos = aoff;
    double cwid = awid / node.weight;
    for(Node c : node.children) {
      computePositions(c, depth + 1, cpos, cwid * c.weight, maxdepth);
      cpos += cwid * c.weight;
    }
  }
745111
public final void setMaxWidth(final int maxWidth) {
        if (maxWidth != -1) {
            Condition.INSTANCE.ensureAtLeast(maxWidth, 1, "The maximum width must be at least 1");
        }

        this.maxWidth = maxWidth;
        requestLayout();
    }
691163
function layoutPositions(layout, options, fn) {
    var nodes = this.nodes();
    var cy = this.cy();
    var layoutEles = options.eles; // nodes & edges

    var getMemoizeKey = function getMemoizeKey(node) {
      return node.id();
    };

    var fnMem = memoize(fn, getMemoizeKey); // memoized version of position function

    layout.emit({
      type: 'layoutstart',
      layout: layout
    });
    layout.animations = [];

    var calculateSpacing = function calculateSpacing(spacing, nodesBb, pos) {
      var center = {
        x: nodesBb.x1 + nodesBb.w / 2,
        y: nodesBb.y1 + nodesBb.h / 2
      };
      var spacingVector = {
        // scale from center of bounding box (not necessarily 0,0)
        x: (pos.x - center.x) * spacing,
        y: (pos.y - center.y) * spacing
      };
      return {
        x: center.x + spacingVector.x,
        y: center.y + spacingVector.y
      };
    };

    var useSpacingFactor = options.spacingFactor && options.spacingFactor !== 1;

    var spacingBb = function spacingBb() {
      if (!useSpacingFactor) {
        return null;
      }

      var bb = makeBoundingBox();

      for (var i = 0; i < nodes.length; i++) {
        var node = nodes[i];
        var pos = fnMem(node, i);
        expandBoundingBoxByPoint(bb, pos.x, pos.y);
      }

      return bb;
    };

    var bb = spacingBb();
    var getFinalPos = memoize(function (node, i) {
      var newPos = fnMem(node, i);

      if (useSpacingFactor) {
        var spacing = Math.abs(options.spacingFactor);
        newPos = calculateSpacing(spacing, bb, newPos);
      }

      if (options.transform != null) {
        newPos = options.transform(node, newPos);
      }

      return newPos;
    }, getMemoizeKey);

    if (options.animate) {
      for (var i = 0; i < nodes.length; i++) {
        var node = nodes[i];
        var newPos = getFinalPos(node, i);
        var animateNode = options.animateFilter == null || options.animateFilter(node, i);

        if (animateNode) {
          var ani = node.animation({
            position: newPos,
            duration: options.animationDuration,
            easing: options.animationEasing
          });
          layout.animations.push(ani);
        } else {
          node.position(newPos);
        }
      }

      if (options.fit) {
        var fitAni = cy.animation({
          fit: {
            boundingBox: layoutEles.boundingBoxAt(getFinalPos),
            padding: options.padding
          },
          duration: options.animationDuration,
          easing: options.animationEasing
        });
        layout.animations.push(fitAni);
      } else if (options.zoom !== undefined && options.pan !== undefined) {
        var zoomPanAni = cy.animation({
          zoom: options.zoom,
          pan: options.pan,
          duration: options.animationDuration,
          easing: options.animationEasing
        });
        layout.animations.push(zoomPanAni);
      }

      layout.animations.forEach(function (ani) {
        return ani.play();
      });
      layout.one('layoutready', options.ready);
      layout.emit({
        type: 'layoutready',
        layout: layout
      });
      Promise$1.all(layout.animations.map(function (ani) {
        return ani.promise();
      })).then(function () {
        layout.one('layoutstop', options.stop);
        layout.emit({
          type: 'layoutstop',
          layout: layout
        });
      });
    } else {
      nodes.positions(getFinalPos);

      if (options.fit) {
        cy.fit(options.eles, options.padding);
      }

      if (options.zoom != null) {
        cy.zoom(options.zoom);
      }

      if (options.pan) {
        cy.pan(options.pan);
      }

      layout.one('layoutready', options.ready);
      layout.emit({
        type: 'layoutready',
        layout: layout
      });
      layout.one('layoutstop', options.stop);
      layout.emit({
        type: 'layoutstop',
        layout: layout
      });
    }

    return this; // chaining
  }
307962
private static <M extends Model> void findDepth(Hierarchy<Cluster<M>> hier, Cluster<M> cluster, int[] size) {
    if(hier.numChildren(cluster) > 0) {
      for(It<Cluster<M>> iter = hier.iterChildren(cluster); iter.valid(); iter.advance()) {
        findDepth(hier, iter.get(), size);
      }
      size[0] += 1; // Depth
    }
    else {
      size[1] += 1; // Leaves
    }
  }
251915
function(newRoot, p) {

            var self = this;

            if (document.documentElement.__transition__) return;

            // Rescale outside angles to match the new layout.
            var enterArc,
                exitArc,
                outsideAngle = d3.scale.linear().domain([0, 2 * Math.PI]);

            function insideArc(d) {
                return p.key > d.key
                    ? {depth: d.depth - 1, x: 0, dx: 0} : p.key < d.key
                    ? {depth: d.depth - 1, x: 2 * Math.PI, dx: 0}
                    : {depth: 0, x: 0, dx: 2 * Math.PI};
            }

            function outsideArc(d) {
                return {
                    depth: d.depth + 1, 
                    x: outsideAngle(d.x), 
                    dx: outsideAngle(d.x + d.dx) - outsideAngle(d.x)
                    };
            }

            function arcTween(b) {
                var i = d3.interpolate(this._current, b);
                this._current = i(0);
                return function(t) {
                    return self.arc(i(t));
                };
            }

            self.center.datum(newRoot);
            //console.log("newRoot");
            //console.log(newRoot);

            // When zooming in, 
            // arcs enter from the outside and exit to the inside.
            // Entering outside arcs start from the old layout.
            if (newRoot === p) {
                enterArc = outsideArc;
                exitArc = insideArc;
                outsideAngle.range([p.x, p.x + p.dx]);
            }

            self.path = self.path.data(self.partition.nodes(newRoot)
                                       .slice(1), function(d) { 
                                           return d.key; 
                                       });

            // When zooming out, 
            // arcs enter from the inside and exit to the outside.
            // Exiting outside arcs transition to the new layout.
            if (newRoot !== p) {
                enterArc = insideArc;
                exitArc = outsideArc;
                outsideAngle.range([p.x, p.x + p.dx]);
            }

            d3.transition()
              .duration(d3.event.altKey ? 7500 : 750)
              .each(function() {
                  self.path.exit().transition()
                      .style("fill-opacity", function(d) { 
                          return d.depth === 1 + (newRoot === p) ? 
                                 1 : 0;
                      })
                      .attrTween("d", function(d) { 
                          return arcTween.call(this, exitArc(d));
                      })
                      .remove();

                  self.path.enter().append("path")
                      .style("fill-opacity", function(d) { 
                          return d.depth === 2 - (newRoot === p) ? 
                                 1 : 0;
                      })
                      .style("fill", function(d) { 
                          return d.fill; 
                      })
                      .on("click", function(d, i) {
                          self.zoomIn(d);
                      })
                      .each(function(d) { 
                          this._current = enterArc(d);
                      });
                  // add the tooltip
                  self.path.append("title")
                      .text(function(d) {
                          return d.name + "\n" + 
                                 self.formatNumber(d.value) + 
                                 " Pageviews\n" +
                                 self.formatPercentage(d.value / self.totalValue) + 
                                 " of total pageviews";
                      });

                  self.path.transition()
                      .style("fill-opacity", 1)
                      .attrTween("d", function(d) { 
                          return arcTween.call(this, 
                                                self.updateArc(d)); 
                      });
              });
        }
722005
@Pure
	private static boolean isOutsideNodeBuildingBounds(AbstractGISTreeSetNode<?, ?> node,
			Rectangle2afp<?, ?, ?, ?, ?, ?> location) {
		final Rectangle2d b2 = getNormalizedNodeBuildingBounds(node, location);
		if (b2 == null) {
			return false;
		}
		return Rectangle2afp.classifiesRectangleRectangle(
				b2.getMinX(), b2.getMinY(), b2.getMaxX(), b2.getMaxY(),
				location.getMinX(), location.getMinY(), location.getMaxX(), location.getMaxY()) != IntersectionType.INSIDE;
	}
1354301
function (targetNode, layoutParam, textStyleModel) {
        for (var node = targetNode; node; node = node.parentNode) {
            var text = node.getModel().get('name');
            var textRect = textStyleModel.getTextRect(text);
            var itemWidth = Math.max(
                textRect.width + TEXT_PADDING * 2,
                layoutParam.emptyItemWidth
            );
            layoutParam.totalWidth += itemWidth + ITEM_GAP;
            layoutParam.renderList.push({node: node, text: text, width: itemWidth});
        }
    }
1314323
public int depth(Tree node) {
        Tree p = node.parent(this);
        if (this == node) {
            return 0;
        }
        if (p == null) {
            return -1;
        }
        int depth = 1;
        while (this != p) {
            p = p.parent(this);
            depth++;
        }
        return depth;
    }
795447
private void preorderTreeDepth(INode root, HashMap<INode, Integer> order, HashMap<INode, Integer> depth) {
        order.clear();
        depth.clear();

        int num = 1;

        Deque<INode> stack = new ArrayDeque<INode>();
        stack.push(root);
        while (!stack.isEmpty()) {
            INode v = stack.pop();

            order.put(v, num++);
            if (!v.hasParent()) {
                depth.put(v, 0);
            } else {
                depth.put(v, depth.get(v.getParent()) + 1);
            }

            for (int i = v.getChildCount() - 1; i >= 0; i--) {
                stack.push(v.getChildAt(i));
            }
        }
    }
1011165
@Override
    public float calculatePriority(int node) {
        CalcShortcutsResult calcShortcutsResult = calcShortcutCount(node);

        // # huge influence: the bigger the less shortcuts gets created and the faster is the preparation
        //
        // every adjNode has an 'original edge' number associated. initially it is r=1
        // when a new shortcut is introduced then r of the associated edges is summed up:
        // r(u,w)=r(u,v)+r(v,w) now we can define
        // originalEdgesCount = σ(v) := sum_{ (u,w) ∈ shortcuts(v) } of r(u, w)
        int originalEdgesCount = calcShortcutsResult.originalEdgesCount;

        // # lowest influence on preparation speed or shortcut creation count
        // (but according to paper should speed up queries)
        //
        // number of already contracted neighbors of v
        int contractedNeighbors = 0;
        int degree = 0;
        CHEdgeIterator iter = remainingEdgeExplorer.setBaseNode(node);
        while (iter.next()) {
            degree++;
            if (iter.isShortcut())
                contractedNeighbors++;
        }

        // from shortcuts we can compute the edgeDifference
        // # low influence: with it the shortcut creation is slightly faster
        //
        // |shortcuts(v)| − |{(u, v) | v uncontracted}| − |{(v, w) | v uncontracted}|
        // meanDegree is used instead of outDegree+inDegree as if one adjNode is in both directions
        // only one bucket memory is used. Additionally one shortcut could also stand for two directions.
        int edgeDifference = calcShortcutsResult.shortcutsCount - degree;

        // according to the paper do a simple linear combination of the properties to get the priority.
        return params.edgeDifferenceWeight * edgeDifference +
                params.originalEdgesCountWeight * originalEdgesCount +
                params.contractedNeighborsWeight * contractedNeighbors;
    }
246500
private static void doLayout(
            final Graphics2D graphics2d, final ScalebarAttributeValues scalebarParams,
            final ScaleBarRenderSettings settings) {
        final Dimension maxLabelSize = getMaxLabelSize(settings);

        int numSubIntervals = 1;
        if (scalebarParams.subIntervals) {
            numSubIntervals = getNbSubIntervals(
                    settings.getScaleUnit(), settings.getIntervalLengthInWorldUnits(),
                    settings.getIntervalUnit());
        }

        settings.setBarSize(getBarSize(settings));
        settings.setLabelDistance(getLabelDistance(settings));
        settings.setLineWidth(getLineWidth(settings));
        settings.setSize(getSize(scalebarParams, settings, maxLabelSize));
        settings.setMaxLabelSize(maxLabelSize);
        settings.setNumSubIntervals(numSubIntervals);

        ScalebarDrawer drawer = scalebarParams.getType().createDrawer(graphics2d, settings);
        drawer.draw();
    }
523982
public void selectAndReveal(INode node) {
		int[] offsetLength = this.locationSearcher.getNodeOffset(node);
		selectAndReveal(offsetLength[0], offsetLength[1]);
	}
1152247
private void setNodeRecrusively(ZooNode zooNode, int depth) {
        try {
            int currDepth = depth + 1;
            List<String> children = zkClient.getChildren(zooNode.getPath());
            if (CollectionUtils.isEmpty(children)) {
                zooNode.setLeaf(true);
                return;
            }
            for (String name : children) {
                ZooNode node = new ZooNode(ZkPathUtil.buildPath(zooNode.getPath(), name), name);
                if (currDepth < 2) {
                    node.setOpen(true);
                }
                zooNode.getChildren().add(node);
                setNodeRecrusively(node, currDepth);
            }
        } catch (NoNodeException e) {
            LOG.warn("Zookeeper path not found" + e.getMessage(), e);
        } catch (Exception e) {
            LOG.error("Zookeeper get children error" + e.getMessage(), e);
        }
    }
1583
function() {
		
		var i, j, l;
		
		// Extract nodes positions
		this.nodes = [];
		for( i = 0 ; i < this.layer.containers.length ; i++) {
			var pos = this.layer.containers[i].terminals[0].getXY();
			
			this.nodes.push({
				layoutPosX: (pos[0]-400)/200,
		      layoutPosY: (pos[1]-400)/200,
		      layoutForceX: 0,
		      layoutForceY: 0
			});
		}
		
		// Spring layout parameters
	   var iterations = 100,
			 maxRepulsiveForceDistance = 6,
			 k = 0.3,
			 c = 0.01;
		
		var d,dx,dy,d2,node,node1,node2;
		
		 // Iterations
	    for (l = 0; l < iterations; l++) {
	    		    
				// Forces on nodes due to node-node repulsions
			   for (i = 0; i < this.nodes.length; i++) {
			   	node1 = this.nodes[i];
			      for (j = i + 1; j < this.nodes.length; j++) {
			      	node2 = this.nodes[j];
						dx = node2.layoutPosX - node1.layoutPosX;
						dy = node2.layoutPosY - node1.layoutPosY;
						d2 = dx * dx + dy * dy;
						if(d2 < 0.01) {
							dx = 0.1 * Math.random() + 0.1;
							dy = 0.1 * Math.random() + 0.1;
							d2 = dx * dx + dy * dy;
						}
						d = Math.sqrt(d2);
						if(d < maxRepulsiveForceDistance) {
							var repulsiveForce = k * k / d;
							node2.layoutForceX += repulsiveForce * dx / d;
							node2.layoutForceY += repulsiveForce * dy / d;
							node1.layoutForceX -= repulsiveForce * dx / d;
							node1.layoutForceY -= repulsiveForce * dy / d;
						}
					}
				}
			
			
			    // Forces on this.nodes due to edge attractions
			    for (i = 0; i < this.edges.length; i++) {
			        var edge = this.edges[i];
					  node1 = this.nodes[ edge[0] ];
			        node2 = this.nodes[ edge[1] ];

			        dx = node2.layoutPosX - node1.layoutPosX;
			        dy = node2.layoutPosY - node1.layoutPosY;
			        d2 = dx * dx + dy * dy;
			        if(d2 < 0.01) {
			         	dx = 0.1 * Math.random() + 0.1;
			            dy = 0.1 * Math.random() + 0.1;
			            d2 = dx * dx + dy * dy;
			        }
			        d = Math.sqrt(d2);
			        if(d > maxRepulsiveForceDistance) {
			                d = maxRepulsiveForceDistance;
			                d2 = d * d;
			        }
			        var attractiveForce = (d2 - k * k) / k;

			        node2.layoutForceX -= attractiveForce * dx / d;
			        node2.layoutForceY -= attractiveForce * dy / d;
			        node1.layoutForceX += attractiveForce * dx / d;
			        node1.layoutForceY += attractiveForce * dy / d;
			    }

			    // Move by the given force
			    for (i = 0; i < this.nodes.length; i++) {
			    	node = this.nodes[i];
			      var xmove = c * node.layoutForceX;
			      var ymove = c * node.layoutForceY;

			      node.layoutPosX += xmove;
			      node.layoutPosY += ymove;
			      node.layoutForceX = 0;
			      node.layoutForceY = 0;
			    }
	    }
	
		 var newPositions = [];
		 for( i = 0 ; i < this.layer.containers.length ; i++) {
			node = this.nodes[i];
			newPositions.push([node.layoutPosX*200+400-40, node.layoutPosY*200+400-20]);
		 }
		 return newPositions;
		
	}
86392
public void setMaxStrokeWidth(float width) {
        maxStrokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, width, getResources().getDisplayMetrics());
    }
1000024
function (nodes, options) {//*//
    var expandedStack = this.simpleExpandAllNodes(nodes, options.fisheye);

    this.endOperation(options.layoutBy);

    /*
     * return the nodes to undo the operation
     */
    return expandedStack;
  }
984925
function revalue(node, depth) {
    var children = node.children,
        v = 0;
    if (children && (n = children.length)) {
      var i = -1,
          n,
          j = depth + 1;
      while (++i < n) v += revalue(children[i], j);
    } else if (value) {
      v = +value.call(hierarchy, d3_layout_hierarchyInline ? node : node.data, depth) || 0;
    }
    if (value) node.value = v;
    return v;
  }