def _assign_traversal_positions(self):
    self.label_x = {}
    x = 0
    for root in self.tree.roots:
        for u in self.tree.nodes(root, order='postorder'):
            label_size = len(self.node_labels[u])
            if self.tree.is_leaf(u):
                self.traversal_position[u] = (x + (label_size // 2))
                self.label_x[u] = x
                x += (label_size + 1)
            else:
                coords = [self.traversal_position[c] for c in self.tree.children(u)]
                if (len(coords) == 1):
                    self.traversal_position[u] = coords[0]
                else:
                    a = min(coords)
                    b = max(coords)
                    child_mid = int(round((a + ((b - a) / 2))))
                    self.traversal_position[u] = child_mid
                self.label_x[u] = (self.traversal_position[u] - (label_size // 2))
                sib_x = (- 1)
                sib = closest_left_node(self.tree, u)
                if (sib != NULL):
                    sib_x = self.traversal_position[sib]
                self.label_x[u] = max((sib_x + 1), self.label_x[u])
                x = max(x, ((self.label_x[u] + label_size) + 1))
            assert (self.label_x[u] >= 0)
        x += 1
    self.width = (x - 1)
def _assign_traversal_positions(self):
    self.label_x = {}
    x = 0
    for root in self.tree.roots:
        for u in self.tree.nodes(root, order='postorder'):
            label_size = len(self.node_labels[u])
            if self.tree.is_leaf(u):
                self.traversal_position[u] = (x + (label_size // 2))
                self.label_x[u] = x
                x += (label_size + 1)
            else:
                coords = [self.traversal_position[c] for c in self.tree.children(u)]
                if (len(coords) == 1):
                    self.traversal_position[u] = coords[0]
                else:
                    a = min(coords)
                    b = max(coords)
                    child_mid = int(round((a + ((b - a) / 2))))
                    self.traversal_position[u] = child_mid
                self.label_x[u] = (self.traversal_position[u] - (label_size // 2))
                sib_x = (- 1)
                sib = closest_left_node(self.tree, u)
                if (sib != NULL):
                    sib_x = self.traversal_position[sib]
                self.label_x[u] = max((sib_x + 1), self.label_x[u])
                x = max(x, ((self.label_x[u] + label_size) + 1))
            assert (self.label_x[u] >= 0)
        x += 1
    self.width = (x - 1)