def node_repr(self): """Format to visualize the Graph.""" canvas_ = canvas.Canvas() x = 0 evaluation_matrix = self.evaluation_matrix for row in evaluation_matrix: y = 0 x_diff = 0 for node in row: item_ = item.Item(str(node), [x, y]) node.item = item_ x_diff = (item_.bbox[2] - item_.bbox[0] + 4 if item_.bbox[2] - item_.bbox[0] + 4 > x_diff else x_diff) y += item_.bbox[3] - item_.bbox[1] canvas_.add_item(item_) x += x_diff for node in self.all_nodes: for i, plug in enumerate(node._sort_plugs(node.all_outputs())): for connection in node._sort_plugs( node.all_outputs())[plug].connections: dnode = connection.node start = [node.item.position[0] + node.item.bbox[2], node.item.position[1] + 3 + len(node.all_inputs()) + i] end = [dnode.item.position[0], dnode.item.position[1] + 3 + list(dnode._sort_plugs( dnode.all_inputs()).values()).index( connection)] canvas_.add_item(item.Line(start, end), 0) return canvas_.render()
def node_repr(self): """Format to visualize the Graph.""" canvas_ = canvas.Canvas() x = 0 evaluation_matrix = self.evaluation_matrix for row in evaluation_matrix: y = 0 x_diff = 0 for node in row: item_ = item.Item(str(node), [x, y]) node.item = item_ x_diff = (item_.bbox[2] - item_.bbox[0] + 4 if item_.bbox[2] - item_.bbox[0] + 4 > x_diff else x_diff) y += item_.bbox[3] - item_.bbox[1] canvas_.add_item(item_) x += x_diff # Include the input groups if any have been set y_off = 2 locked_items = [] if self.input_groups: for input_group in self.input_groups.values(): y_off += 1 i = item.Item("o {0}".format(input_group.name), [0, y_off]) canvas_.add_item(i) locked_items.append(i) for p in input_group.plugs: y_off += 1 i = item.Item("`-{0}.{1}".format(p.node.name, p.name), [2, y_off]) canvas_.add_item(i) locked_items.append(i) # Move all items down by Y for i in canvas_.items: if i not in locked_items: i.position[0] += 2 i.position[1] += y_off + 1 + int(bool(self.input_groups)) canvas_.add_item(item.Rectangle(x, canvas_.bbox[3] + 1, [0, 0]), 0) # Crop the name of the graph if it is too long name = self.name if len(name) > x - 2: name = name[:x - 2] canvas_.add_item( item.Item("{name:^{x}}".format(name=name, x=x), [0, 1]), 0) canvas_.add_item(item.Rectangle(x, 3, [0, 0]), 0) if self.input_groups: canvas_.add_item(item.Rectangle(x, y_off + 2, [0, 0]), 0) for node in self.all_nodes: for i, plug in enumerate(node._sort_plugs(node.all_outputs())): for connection in node._sort_plugs( node.all_outputs())[plug].connections: dnode = connection.node start = [ node.item.position[0] + node.item.bbox[2], node.item.position[1] + 3 + len(node.all_inputs()) + i, ] end = [ dnode.item.position[0], dnode.item.position[1] + 3 + list(dnode._sort_plugs( dnode.all_inputs()).values()).index(connection), ] canvas_.add_item(item.Line(start, end), 0) return canvas_.render()
def gen_circle_points( radius: int, n: Optional[int] = 1000, terminal_resize: Optional[float] = 1) -> Set[Tuple[int, int]]: """ VS Code resize: 5 / 12 """ result = set() for x in range(0, n + 1): point = 2 * math.pi / n * x result.add( (round(math.cos(point) * radius) + radius, round(math.sin(point) * radius * terminal_resize) + radius)) return result points = gen_circle_points(50, terminal_resize=8 / 16) for i in points: canvas.add_item(item.Item("@", i)) data = list() for i in canvas.render().split("\n"): data.append([*i]) print(data) # print(canvas.render()) # input()