From 5d5f15cf5dfa68b0d4ee701e74dd442d60c19ab4 Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Fri, 21 Jan 2022 10:12:17 +0100 Subject: [PATCH 1/6] :tada: Change default socket to vertical --- pyflow/blocks/block.py | 14 ++++++-------- pyflow/core/edge.py | 4 ++-- pyflow/core/socket.py | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pyflow/blocks/block.py b/pyflow/blocks/block.py index 94a41d17..3d228797 100644 --- a/pyflow/blocks/block.py +++ b/pyflow/blocks/block.py @@ -147,18 +147,16 @@ def paint( def get_socket_pos(self, socket: Socket) -> Tuple[float]: """Get a socket position to place them on the block sides.""" if socket.socket_type == "input": - x = 0 + y = 0 sockets = self.sockets_in else: - x = self.width + y = self.height sockets = self.sockets_out - y_offset = self.title_widget.height() + 2 * socket.radius - if len(sockets) < 2: - y = y_offset - else: - side_lenght = self.height - y_offset - 2 * socket.radius - self.edge_size - y = y_offset + side_lenght * sockets.index(socket) / (len(sockets) - 1) + # Sockets are evenly spaced out on the whole block width + space_between_sockets = self.width / (len(sockets) + 1) + x = space_between_sockets * (sockets.index(socket) + 1) + return x, y def update_sockets(self): diff --git a/pyflow/core/edge.py b/pyflow/core/edge.py index d3fc31dd..fe8e05fa 100644 --- a/pyflow/core/edge.py +++ b/pyflow/core/edge.py @@ -139,8 +139,8 @@ def update_path(self): elif self.path_type == "bezier": sx, sy = self.source.x(), self.source.y() dx, dy = self.destination.x(), self.destination.y() - mid_dist = (dx - sx) / 2 - path.cubicTo(sx + mid_dist, sy, dx - mid_dist, dy, dx, dy) + mid_dist = (dy - sy) / 2 + path.cubicTo(sx, sy + mid_dist, dx, dy - mid_dist, dx, dy) else: raise NotImplementedError(f"Unknowed path type: {self.path_type}") self.setPath(path) diff --git a/pyflow/core/socket.py b/pyflow/core/socket.py index a90e8eba..e370f825 100644 --- a/pyflow/core/socket.py +++ b/pyflow/core/socket.py @@ -118,7 +118,7 @@ def paint( painter.setPen(self._pen) r = self.radius if self.flow_type == "exe": - angles = [0, 2 * math.pi / 3, -2 * math.pi / 3] + angles = [-math.pi / 6, -5 * math.pi / 6, math.pi / 2] right_triangle_points = [ QPoint(int(r * math.cos(angle)), int(r * math.sin(angle))) for angle in angles From e48806b4181bce40dbeca447cf9e6230e9bed470 Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Fri, 21 Jan 2022 10:30:30 +0100 Subject: [PATCH 2/6] :tada: Make ipynb conversion vertical --- pyflow/scene/from_ipynb_conversion.py | 83 +++++++++++----------- pyflow/scene/ipynb_conversion_constants.py | 11 +-- 2 files changed, 44 insertions(+), 50 deletions(-) diff --git a/pyflow/scene/from_ipynb_conversion.py b/pyflow/scene/from_ipynb_conversion.py index c5c79cfc..a88fa91f 100644 --- a/pyflow/scene/from_ipynb_conversion.py +++ b/pyflow/scene/from_ipynb_conversion.py @@ -69,17 +69,6 @@ def get_blocks_data( else: raise TypeError("A cell's source is not of the right type") - text_width = DEFAULT_TEXT_WIDTH - if use_theme_font: - text_width: float = ( - max(fontmetrics.boundingRect(line).width() for line in text) - if len(text) > 0 - else 0 - ) - block_width: float = min( - max(text_width + MARGIN_X, BLOCK_MIN_WIDTH), BLOCK_MAX_WIDTH - ) - lineSpacing = DEFAULT_LINE_SPACING lineHeight = DEFAULT_LINE_HEIGHT @@ -93,7 +82,7 @@ def get_blocks_data( block_data = { "id": next_block_id, "block_type": BLOCK_TYPE_TO_NAME[block_type], - "width": block_width, + "width": BLOCK_WIDTH, "height": block_height, "position": [ next_block_x_pos, @@ -104,14 +93,15 @@ def get_blocks_data( if block_type == "code": block_data["source"] = "".join(text) - next_block_y_pos = 0 - next_block_x_pos += block_width + MARGIN_BETWEEN_BLOCKS_X if len(blocks_data) > 0 and is_title(blocks_data[-1]): block_title: OrderedDict = blocks_data.pop() block_data["title"] = block_title["text"] # Revert position effect of the markdown block + next_block_y_pos -= ( + block_data["position"][1] - block_title["position"][1] + ) block_data["position"] = block_title["position"] elif block_type == "markdown": block_data.update( @@ -119,12 +109,13 @@ def get_blocks_data( "text": "".join(text), } ) - next_block_y_pos += block_height + MARGIN_BETWEEN_BLOCKS_Y + + next_block_y_pos += block_height + MARGIN_BETWEEN_BLOCKS_Y blocks_data.append(block_data) next_block_id += 1 - adujst_markdown_blocks_width(blocks_data) + # adujst_markdown_blocks_width(blocks_data) return blocks_data @@ -143,26 +134,26 @@ def is_title(block_data: OrderedDict) -> bool: return True -def adujst_markdown_blocks_width(blocks_data: OrderedDict) -> None: - """ - Modify the markdown blocks width (in place) - For them to match the width of block of code below - """ - i: int = len(blocks_data) - 1 - - while i >= 0: - if blocks_data[i]["block_type"] == BLOCK_TYPE_TO_NAME["code"]: - block_width: float = blocks_data[i]["width"] - i -= 1 - - while ( - i >= 0 - and blocks_data[i]["block_type"] == BLOCK_TYPE_TO_NAME["markdown"] - ): - blocks_data[i]["width"] = block_width - i -= 1 - else: - i -= 1 +# def adujst_markdown_blocks_width(blocks_data: OrderedDict) -> None: +# """ +# Modify the markdown blocks width (in place) +# For them to match the width of block of code below +# """ +# i: int = len(blocks_data) - 1 + +# while i >= 0: +# if blocks_data[i]["block_type"] == BLOCK_TYPE_TO_NAME["code"]: +# block_width: float = blocks_data[i]["width"] +# i -= 1 + +# while ( +# i >= 0 +# and blocks_data[i]["block_type"] == BLOCK_TYPE_TO_NAME["markdown"] +# ): +# blocks_data[i]["width"] = block_width +# i -= 1 +# else: +# i -= 1 def get_edges_data(blocks_data: OrderedDict) -> OrderedDict: @@ -183,8 +174,12 @@ def get_edges_data(blocks_data: OrderedDict) -> OrderedDict: socket_id_out: int = greatest_block_id + 2 * i + 2 socket_id_in: int = greatest_block_id + 2 * i + 1 - block["sockets"].append(get_output_socket_data(socket_id_out, block["width"])) - block["sockets"].append(get_input_socket_data(socket_id_in)) + block["sockets"].append( + get_output_socket_data(socket_id_out, block["width"], block["height"]) + ) + block["sockets"].append( + get_input_socket_data(socket_id_in, block["width"], block["height"]) + ) if i >= 1: edges_data.append( @@ -202,16 +197,20 @@ def get_edges_data(blocks_data: OrderedDict) -> OrderedDict: return edges_data -def get_input_socket_data(socket_id: int) -> OrderedDict: +def get_input_socket_data( + socket_id: int, block_width: int, block_height: int +) -> OrderedDict: """Returns the input socket's data with the corresponding id.""" return { "id": socket_id, "type": "input", - "position": [0.0, SOCKET_HEIGHT], + "position": [block_width / 2, 0], } -def get_output_socket_data(socket_id: int, block_width: int) -> OrderedDict: +def get_output_socket_data( + socket_id: int, block_width: int, block_height: int +) -> OrderedDict: """ Returns the input socket's data with the corresponding id and at the correct relative position with respect to the block @@ -219,7 +218,7 @@ def get_output_socket_data(socket_id: int, block_width: int) -> OrderedDict: return { "id": socket_id, "type": "output", - "position": [block_width, SOCKET_HEIGHT], + "position": [block_width / 2, block_height], } diff --git a/pyflow/scene/ipynb_conversion_constants.py b/pyflow/scene/ipynb_conversion_constants.py index f37f3f06..d3d601d9 100644 --- a/pyflow/scene/ipynb_conversion_constants.py +++ b/pyflow/scene/ipynb_conversion_constants.py @@ -5,18 +5,13 @@ from typing import Dict -MARGIN_X: float = 75 -MARGIN_BETWEEN_BLOCKS_X: float = 50 -MARGIN_Y: float = 60 -MARGIN_BETWEEN_BLOCKS_Y: float = 5 -BLOCK_MIN_WIDTH: float = 400 -BLOCK_MAX_WIDTH: float = 1000 +MARGIN_Y: float = 120 +MARGIN_BETWEEN_BLOCKS_Y: float = 20 +BLOCK_WIDTH: float = 600 TITLE_MAX_LENGTH: int = 60 -SOCKET_HEIGHT: float = 44.0 DEFAULT_LINE_SPACING = 2 DEFAULT_LINE_HEIGHT = 10 -DEFAULT_TEXT_WIDTH = 618 BLOCK_TYPE_TO_NAME: Dict[str, str] = { "code": "CodeBlock", From eff8b7560d3f4e2f93ba2813a8d951024da1de1f Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Fri, 21 Jan 2022 10:37:20 +0100 Subject: [PATCH 3/6] :art: Make the mnisty example vertical --- examples/mnist.ipyg | 104 ++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/examples/mnist.ipyg b/examples/mnist.ipyg index a32f151a..98f53d36 100644 --- a/examples/mnist.ipyg +++ b/examples/mnist.ipyg @@ -6,12 +6,12 @@ "title": "Load MNIST dataset", "block_type": "CodeBlock", "splitter_pos": [ - 131, + 137, 0 ], "position": [ - -1008.1875, - 107.19140625000023 + -211.7736206054691, + -75.79580688476543 ], "width": 618, "height": 184, @@ -27,8 +27,8 @@ "id": 2039122756520, "type": "input", "position": [ - 0.0, - 48.0 + 309.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -41,8 +41,8 @@ "id": 2039122756664, "type": "output", "position": [ - 618.0, - 48.0 + 309.0, + 184.0 ], "metadata": { "color": "#FF55FFF0", @@ -60,12 +60,12 @@ "title": "Evaluation", "block_type": "CodeBlock", "splitter_pos": [ - 75, - 75 + 78, + 78 ], "position": [ - 2201.3125, - 289.8164062500002 + 147.74591064453216, + 1429.3799743652335 ], "width": 909, "height": 203, @@ -81,8 +81,8 @@ "id": 2039123154696, "type": "input", "position": [ - 0.0, - 48.0 + 454.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -95,8 +95,8 @@ "id": 2039123154840, "type": "output", "position": [ - 909.0, - 48.0 + 454.5, + 203.0 ], "metadata": { "color": "#FF55FFF0", @@ -115,11 +115,11 @@ "block_type": "CodeBlock", "splitter_pos": [ 0, - 281 + 287 ], "position": [ - 2250.3125, - -73.18359374999977 + -213.56268310546818, + 1421.7393493652344 ], "width": 323, "height": 334, @@ -135,8 +135,8 @@ "id": 2039123391400, "type": "input", "position": [ - 0.0, - 48.0 + 161.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -149,8 +149,8 @@ "id": 2039123391544, "type": "output", "position": [ - 323.0, - 48.0 + 161.5, + 334.0 ], "metadata": { "color": "#FF55FFF0", @@ -168,12 +168,12 @@ "title": "Training", "block_type": "CodeBlock", "splitter_pos": [ - 85, - 229 + 87, + 233 ], "position": [ - 1059.374999999999, - 101.00390625000023 + 1.179504394530909, + 934.3252868652344 ], "width": 1049, "height": 367, @@ -189,8 +189,8 @@ "id": 2039123184808, "type": "input", "position": [ - 0.0, - 48.0 + 524.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -203,8 +203,8 @@ "id": 2039123184952, "type": "output", "position": [ - 1049.0, - 48.0 + 524.5, + 367.0 ], "metadata": { "color": "#FF55FFF0", @@ -222,12 +222,12 @@ "title": "Build Keras CNN", "block_type": "CodeBlock", "splitter_pos": [ - 253, + 259, 0 ], "position": [ - 397.1875, - 118.62890625000023 + 25.03887939453091, + 520.9541931152345 ], "width": 580, "height": 306, @@ -243,8 +243,8 @@ "id": 2039123244520, "type": "input", "position": [ - 0.0, - 48.0 + 290.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -257,8 +257,8 @@ "id": 2039123244664, "type": "output", "position": [ - 580.0, - 48.0 + 290.0, + 306.0 ], "metadata": { "color": "#FF55FFF0", @@ -277,11 +277,11 @@ "block_type": "CodeBlock", "splitter_pos": [ 0, - 277 + 283 ], "position": [ - -264.1875, - -205.80859374999977 + -413.21112060546864, + 216.01669311523452 ], "width": 320, "height": 330, @@ -297,8 +297,8 @@ "id": 2039171274936, "type": "input", "position": [ - 0.0, - 48.0 + 160.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -311,8 +311,8 @@ "id": 2039171275080, "type": "output", "position": [ - 320.0, - 48.0 + 160.0, + 330.0 ], "metadata": { "color": "#FF55FFF0", @@ -330,12 +330,12 @@ "title": "Normalize dataset", "block_type": "CodeBlock", "splitter_pos": [ - 73, - 73 + 76, + 76 ], "position": [ - -321.1875, - 166.19140625000023 + 6.476379394530795, + 216.01669311523463 ], "width": 619, "height": 199, @@ -351,8 +351,8 @@ "id": 2039123194072, "type": "input", "position": [ - 0.0, - 48.0 + 309.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -365,8 +365,8 @@ "id": 2039123194216, "type": "output", "position": [ - 619.0, - 48.0 + 309.5, + 199.0 ], "metadata": { "color": "#FF55FFF0", From 12079f61d8cb9fa3009d5a6d2210fe66fd3dde49 Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Fri, 21 Jan 2022 10:41:26 +0100 Subject: [PATCH 4/6] :wrench: Give block data instead of block height and width --- pyflow/scene/from_ipynb_conversion.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pyflow/scene/from_ipynb_conversion.py b/pyflow/scene/from_ipynb_conversion.py index a88fa91f..d4b3cc0a 100644 --- a/pyflow/scene/from_ipynb_conversion.py +++ b/pyflow/scene/from_ipynb_conversion.py @@ -175,10 +175,10 @@ def get_edges_data(blocks_data: OrderedDict) -> OrderedDict: socket_id_in: int = greatest_block_id + 2 * i + 1 block["sockets"].append( - get_output_socket_data(socket_id_out, block["width"], block["height"]) + get_output_socket_data(socket_id_out, block) ) block["sockets"].append( - get_input_socket_data(socket_id_in, block["width"], block["height"]) + get_input_socket_data(socket_id_in, block) ) if i >= 1: @@ -197,10 +197,12 @@ def get_edges_data(blocks_data: OrderedDict) -> OrderedDict: return edges_data -def get_input_socket_data( - socket_id: int, block_width: int, block_height: int -) -> OrderedDict: - """Returns the input socket's data with the corresponding id.""" +def get_input_socket_data(socket_id: int, block_data: OrderedDict) -> OrderedDict: + """Returns the input socket's data with the corresponding id + and at the correct relative position with respect to the block.""" + + block_width = block_data["width"] + return { "id": socket_id, "type": "input", @@ -208,13 +210,15 @@ def get_input_socket_data( } -def get_output_socket_data( - socket_id: int, block_width: int, block_height: int -) -> OrderedDict: +def get_output_socket_data(socket_id: int, block_data: OrderedDict) -> OrderedDict: """ Returns the input socket's data with the corresponding id - and at the correct relative position with respect to the block + and at the correct relative position with respect to the block. """ + + block_width = block_data["width"] + block_height = block_data["height"] + return { "id": socket_id, "type": "output", From 3ad3edf111189b2bbe2a67ab96b5cfb97d1578b7 Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Fri, 21 Jan 2022 18:39:20 +0100 Subject: [PATCH 5/6] :sparkles: Remove leftover function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mathïs Fédérico <60117466+MathisFederico@users.noreply.github.com> --- pyflow/scene/from_ipynb_conversion.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/pyflow/scene/from_ipynb_conversion.py b/pyflow/scene/from_ipynb_conversion.py index d4b3cc0a..1921bb57 100644 --- a/pyflow/scene/from_ipynb_conversion.py +++ b/pyflow/scene/from_ipynb_conversion.py @@ -134,26 +134,6 @@ def is_title(block_data: OrderedDict) -> bool: return True -# def adujst_markdown_blocks_width(blocks_data: OrderedDict) -> None: -# """ -# Modify the markdown blocks width (in place) -# For them to match the width of block of code below -# """ -# i: int = len(blocks_data) - 1 - -# while i >= 0: -# if blocks_data[i]["block_type"] == BLOCK_TYPE_TO_NAME["code"]: -# block_width: float = blocks_data[i]["width"] -# i -= 1 - -# while ( -# i >= 0 -# and blocks_data[i]["block_type"] == BLOCK_TYPE_TO_NAME["markdown"] -# ): -# blocks_data[i]["width"] = block_width -# i -= 1 -# else: -# i -= 1 def get_edges_data(blocks_data: OrderedDict) -> OrderedDict: From dfb1621420a433b041418c736530d236b74557af Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Fri, 21 Jan 2022 18:51:55 +0100 Subject: [PATCH 6/6] :art: Make all examples and tests vertical --- examples/linear_classifier.ipyg | 118 ++++++++-------- pyflow/scene/from_ipynb_conversion.py | 8 +- tests/assets/example_graph1.ipyg | 14 +- tests/assets/flow_test.ipyg | 194 +++++++++++++------------- tests/assets/simple_flow.ipyg | 84 +++++------ 5 files changed, 207 insertions(+), 211 deletions(-) diff --git a/examples/linear_classifier.ipyg b/examples/linear_classifier.ipyg index 4e3eb925..c9e8274c 100644 --- a/examples/linear_classifier.ipyg +++ b/examples/linear_classifier.ipyg @@ -7,11 +7,11 @@ "block_type": "MarkdownBlock", "splitter_pos": [ 0, - 200 + 206 ], "position": [ - -940.0, - -467.0 + 126.71874999999943, + -276.99999999999966 ], "width": 677, "height": 253, @@ -31,11 +31,11 @@ "block_type": "CodeBlock", "splitter_pos": [ 0, - 272 + 278 ], "position": [ - 53.875000000000085, - 212.25 + -424.40624999999943, + 438.49999999999994 ], "width": 439, "height": 325, @@ -51,8 +51,8 @@ "id": 2034686483184, "type": "input", "position": [ - 0.0, - 40.0 + 219.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -65,8 +65,8 @@ "id": 2034686483328, "type": "output", "position": [ - 439.0, - 40.0 + 219.5, + 325.0 ], "metadata": { "color": "#FF55FFF0", @@ -84,12 +84,12 @@ "title": "Generate some data to plot", "block_type": "CodeBlock", "splitter_pos": [ - 189, - 85 + 193, + 87 ], "position": [ - -929.7499999999999, - -121.31250000000003 + 121.03124999999955, + 29.078125 ], "width": 706, "height": 327, @@ -105,8 +105,8 @@ "id": 2034723534592, "type": "input", "position": [ - 0.0, - 40.0 + 353.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -119,8 +119,8 @@ "id": 2034723534736, "type": "output", "position": [ - 706.0, - 40.0 + 353.0, + 327.0 ], "metadata": { "color": "#FF55FFF0", @@ -139,8 +139,8 @@ "block_type": "SliderBlock", "splitter_pos": [], "position": [ - -890.625, - 258.50000000000006 + -632.03125, + 203.81250000000028 ], "width": 618, "height": 184, @@ -156,8 +156,8 @@ "id": 2034723678672, "type": "input", "position": [ - 0.0, - 42.0 + 309.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -170,8 +170,8 @@ "id": 2034723678816, "type": "output", "position": [ - 618.0, - 42.0 + 309.0, + 184.0 ], "metadata": { "color": "#FF55FFF0", @@ -190,8 +190,8 @@ "block_type": "SliderBlock", "splitter_pos": [], "position": [ - -901.1874999999999, - 471.8750000000001 + -592.9062499999998, + -27.109374999999375 ], "width": 618, "height": 184, @@ -207,8 +207,8 @@ "id": 2034723715680, "type": "input", "position": [ - 0.0, - 42.0 + 309.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -221,8 +221,8 @@ "id": 2034723715824, "type": "output", "position": [ - 618.0, - 42.0 + 309.0, + 184.0 ], "metadata": { "color": "#FF55FFF0", @@ -241,11 +241,11 @@ "block_type": "CodeBlock", "splitter_pos": [ 0, - 276 + 282 ], "position": [ - 782.4375000000001, - -676.0000000000001 + 232.51562500000023, + 813.7656249999991 ], "width": 434, "height": 329, @@ -261,8 +261,8 @@ "id": 2034879163840, "type": "input", "position": [ - 0.0, - 40.0 + 217.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -275,8 +275,8 @@ "id": 2034879163984, "type": "output", "position": [ - 434.0, - 40.0 + 217.0, + 329.0 ], "metadata": { "color": "#FF55FFF0", @@ -295,11 +295,11 @@ "block_type": "CodeBlock", "splitter_pos": [ 0, - 220 + 226 ], "position": [ - 611.6875000000001, - 251.81250000000006 + -547.0624999999991, + 842.5156249999998 ], "width": 685, "height": 273, @@ -315,8 +315,8 @@ "id": 2034879287152, "type": "input", "position": [ - 0.0, - 40.0 + 342.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -329,8 +329,8 @@ "id": 2034879197248, "type": "output", "position": [ - 685.0, - 40.0 + 342.5, + 273.0 ], "metadata": { "color": "#FF55FFF0", @@ -348,12 +348,12 @@ "title": "Create a new linear model", "block_type": "CodeBlock", "splitter_pos": [ - 90, - 85 + 93, + 88 ], "position": [ - -160.3125, - -374.50000000000006 + 68.203125, + 428.2343749999996 ], "width": 840, "height": 228, @@ -369,8 +369,8 @@ "id": 2034886211472, "type": "input", "position": [ - 0.0, - 40.0 + 420.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -383,8 +383,8 @@ "id": 2034886211616, "type": "output", "position": [ - 840.0, - 40.0 + 420.0, + 228.0 ], "metadata": { "color": "#FF55FFF0", @@ -403,11 +403,11 @@ "block_type": "CodeBlock", "splitter_pos": [ 0, - 278 + 284 ], "position": [ - 767.1875000000002, - -279.9375 + 708.8281250000007, + 810.0624999999995 ], "width": 816, "height": 331, @@ -423,8 +423,8 @@ "id": 2136886540752, "type": "input", "position": [ - 0.0, - 40.0 + 408.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -437,8 +437,8 @@ "id": 2136886540896, "type": "output", "position": [ - 816.0, - 40.0 + 408.0, + 331.0 ], "metadata": { "color": "#FF55FFF0", diff --git a/pyflow/scene/from_ipynb_conversion.py b/pyflow/scene/from_ipynb_conversion.py index 1921bb57..d105de48 100644 --- a/pyflow/scene/from_ipynb_conversion.py +++ b/pyflow/scene/from_ipynb_conversion.py @@ -154,12 +154,8 @@ def get_edges_data(blocks_data: OrderedDict) -> OrderedDict: socket_id_out: int = greatest_block_id + 2 * i + 2 socket_id_in: int = greatest_block_id + 2 * i + 1 - block["sockets"].append( - get_output_socket_data(socket_id_out, block) - ) - block["sockets"].append( - get_input_socket_data(socket_id_in, block) - ) + block["sockets"].append(get_output_socket_data(socket_id_out, block)) + block["sockets"].append(get_input_socket_data(socket_id_in, block)) if i >= 1: edges_data.append( diff --git a/tests/assets/example_graph1.ipyg b/tests/assets/example_graph1.ipyg index c3743874..26e9b6a0 100644 --- a/tests/assets/example_graph1.ipyg +++ b/tests/assets/example_graph1.ipyg @@ -6,12 +6,12 @@ "title": "test1", "block_type": "CodeBlock", "splitter_pos": [ - 292, + 304, 0 ], "position": [ - 1192.0, - 292.79999999999995 + -75.57812499999977, + -37.27812499999999 ], "width": 707, "height": 351, @@ -27,8 +27,8 @@ "id": 1523350963536, "type": "input", "position": [ - 0.0, - 45.0 + 353.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -41,8 +41,8 @@ "id": 1523350963680, "type": "output", "position": [ - 707.0, - 45.0 + 353.5, + 351.0 ], "metadata": { "color": "#FF55FFF0", diff --git a/tests/assets/flow_test.ipyg b/tests/assets/flow_test.ipyg index 710be340..1c09ba19 100644 --- a/tests/assets/flow_test.ipyg +++ b/tests/assets/flow_test.ipyg @@ -6,12 +6,12 @@ "title": "Test flow 5", "block_type": "CodeBlock", "splitter_pos": [ - 203, + 209, 0 ], "position": [ - 126.0, - -202.0 + -164.52734374999994, + 768.8857536315913 ], "width": 316, "height": 256, @@ -27,8 +27,8 @@ "id": 2047509615672, "type": "input", "position": [ - 0.0, - 48.0 + 158.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -41,8 +41,8 @@ "id": 2047509615816, "type": "output", "position": [ - 316.0, - 48.0 + 158.0, + 256.0 ], "metadata": { "color": "#FF55FFF0", @@ -60,12 +60,12 @@ "title": "Test flow 1", "block_type": "CodeBlock", "splitter_pos": [ - 187, + 193, 0 ], "position": [ - -616.0, - -200.0 + -391.3906250000001, + 162.97559738159168 ], "width": 302, "height": 240, @@ -81,8 +81,8 @@ "id": 2047509976840, "type": "input", "position": [ - 0.0, - 48.0 + 151.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -95,8 +95,8 @@ "id": 2047509976984, "type": "output", "position": [ - 302.0, - 48.0 + 151.0, + 240.0 ], "metadata": { "color": "#FF55FFF0", @@ -114,12 +114,12 @@ "title": "Test flow 2", "block_type": "CodeBlock", "splitter_pos": [ - 154, + 160, 0 ], "position": [ - -616.75, - 99.75 + -155.32421875000017, + -91.4736213684082 ], "width": 300, "height": 207, @@ -135,8 +135,8 @@ "id": 2047510055816, "type": "input", "position": [ - 0.0, - 48.0 + 150.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -149,8 +149,8 @@ "id": 2047510055960, "type": "output", "position": [ - 300.0, - 48.0 + 150.0, + 207.0 ], "metadata": { "color": "#FF55FFF0", @@ -168,12 +168,12 @@ "title": "Test flow 3", "block_type": "CodeBlock", "splitter_pos": [ - 191, + 197, 0 ], "position": [ - -249.0, - -202.0 + -151.34375000000006, + 461.26856613159157 ], "width": 300, "height": 244, @@ -189,8 +189,8 @@ "id": 2047510350296, "type": "input", "position": [ - 0.0, - 48.0 + 150.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -203,8 +203,8 @@ "id": 2047510350440, "type": "output", "position": [ - 300.0, - 48.0 + 150.0, + 244.0 ], "metadata": { "color": "#FF55FFF0", @@ -222,12 +222,12 @@ "title": "Test flow 4", "block_type": "CodeBlock", "splitter_pos": [ - 165, + 171, 0 ], "position": [ - -255.0, - 98.0 + 67.26562499999983, + 189.97950363159168 ], "width": 300, "height": 218, @@ -243,8 +243,8 @@ "id": 2047510395352, "type": "input", "position": [ - 0.0, - 48.0 + 150.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -257,8 +257,8 @@ "id": 2047510395496, "type": "output", "position": [ - 300.0, - 48.0 + 150.0, + 218.0 ], "metadata": { "color": "#FF55FFF0", @@ -276,12 +276,12 @@ "title": "Test flow 6", "block_type": "CodeBlock", "splitter_pos": [ - 202, + 208, 0 ], "position": [ - 522.0, - -202.0 + -347.1406249999997, + 1105.7998161315913 ], "width": 300, "height": 255, @@ -297,8 +297,8 @@ "id": 2047510594184, "type": "input", "position": [ - 0.0, - 48.0 + 150.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -311,8 +311,8 @@ "id": 2047510594328, "type": "output", "position": [ - 300.0, - 48.0 + 150.0, + 255.0 ], "metadata": { "color": "#FF55FFF0", @@ -330,12 +330,12 @@ "title": "Test flow 7", "block_type": "CodeBlock", "splitter_pos": [ - 211, + 217, 0 ], "position": [ - 504.75, - 76.75 + 31.117187500000142, + 1094.0224723815913 ], "width": 300, "height": 264, @@ -351,8 +351,8 @@ "id": 2047511621208, "type": "input", "position": [ - 0.0, - 48.0 + 150.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -365,8 +365,8 @@ "id": 2047511621352, "type": "output", "position": [ - 300.0, - 48.0 + 150.0, + 264.0 ], "metadata": { "color": "#FF55FFF0", @@ -384,12 +384,12 @@ "title": "Test flow 8", "block_type": "CodeBlock", "splitter_pos": [ - 204, + 210, 0 ], "position": [ - 924.75, - -199.0 + -193.41406249999972, + 1538.487316131591 ], "width": 364, "height": 257, @@ -405,8 +405,8 @@ "id": 2047511819896, "type": "input", "position": [ - 0.0, - 48.0 + 182.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -419,8 +419,8 @@ "id": 2047511820040, "type": "output", "position": [ - 364.0, - 48.0 + 182.0, + 257.0 ], "metadata": { "color": "#FF55FFF0", @@ -439,11 +439,11 @@ "block_type": "MarkdownBlock", "splitter_pos": [ 0, - 130 + 136 ], "position": [ - -292.5, - 432.5 + -360.859375, + 1949.7724723815913 ], "width": 347, "height": 183, @@ -462,12 +462,12 @@ "title": "Test no connection 1", "block_type": "CodeBlock", "splitter_pos": [ - 199, + 205, 0 ], "position": [ - 181.0, - 376.5 + 85.140625, + 1926.272472381592 ], "width": 347, "height": 252, @@ -483,8 +483,8 @@ "id": 2047515371992, "type": "input", "position": [ - 0.0, - 48.0 + 173.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -497,8 +497,8 @@ "id": 2047515372136, "type": "output", "position": [ - 347.0, - 48.0 + 173.5, + 252.0 ], "metadata": { "color": "#FF55FFF0", @@ -516,12 +516,12 @@ "title": "Test input only 1", "block_type": "CodeBlock", "splitter_pos": [ - 250, + 256, 0 ], "position": [ - -238.75, - 670.0 + -344.609375, + 2168.522472381592 ], "width": 304, "height": 303, @@ -537,8 +537,8 @@ "id": 2047515583688, "type": "input", "position": [ - 0.0, - 48.0 + 152.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -551,8 +551,8 @@ "id": 2047515583832, "type": "output", "position": [ - 304.0, - 48.0 + 152.0, + 303.0 ], "metadata": { "color": "#FF55FFF0", @@ -570,12 +570,12 @@ "title": "Test input only 2", "block_type": "CodeBlock", "splitter_pos": [ - 236, + 242, 0 ], "position": [ - 176.25, - 663.75 + -368.3593749999999, + 2598.5224723815913 ], "width": 350, "height": 289, @@ -591,8 +591,8 @@ "id": 2047516569320, "type": "input", "position": [ - 0.0, - 48.0 + 175.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -605,8 +605,8 @@ "id": 2047516569464, "type": "output", "position": [ - 350.0, - 48.0 + 175.0, + 289.0 ], "metadata": { "color": "#FF55FFF0", @@ -624,12 +624,12 @@ "title": "Test output only 1", "block_type": "CodeBlock", "splitter_pos": [ - 209, + 215, 0 ], "position": [ - 179.0, - 988.0 + 85.640625, + 2231.522472381592 ], "width": 326, "height": 262, @@ -645,8 +645,8 @@ "id": 2047517407272, "type": "input", "position": [ - 0.0, - 48.0 + 163.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -659,8 +659,8 @@ "id": 2047517407416, "type": "output", "position": [ - 326.0, - 48.0 + 163.0, + 262.0 ], "metadata": { "color": "#FF55FFF0", @@ -678,12 +678,12 @@ "title": "Test output only 2", "block_type": "CodeBlock", "splitter_pos": [ - 202, + 208, 0 ], "position": [ - 582.0, - 992.0 + 104.89062500000011, + 2603.022472381592 ], "width": 300, "height": 255, @@ -699,8 +699,8 @@ "id": 2047520152456, "type": "input", "position": [ - 0.0, - 48.0 + 150.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -713,8 +713,8 @@ "id": 2047520152600, "type": "output", "position": [ - 300.0, - 48.0 + 150.0, + 255.0 ], "metadata": { "color": "#FF55FFF0", @@ -733,11 +733,11 @@ "block_type": "MarkdownBlock", "splitter_pos": [ 0, - 131 + 137 ], "position": [ - -438.75, - -438.75 + -370.39062500000006, + -378.5087776184082 ], "width": 445, "height": 184, diff --git a/tests/assets/simple_flow.ipyg b/tests/assets/simple_flow.ipyg index d92d2057..50651d28 100644 --- a/tests/assets/simple_flow.ipyg +++ b/tests/assets/simple_flow.ipyg @@ -10,8 +10,8 @@ 0 ], "position": [ - -1008.1875, - 107.19140625000023 + 21.8125, + -326.8085937499998 ], "width": 618, "height": 184, @@ -27,8 +27,8 @@ "id": 2039122756520, "type": "input", "position": [ - 0.0, - 35.0 + 309.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -41,8 +41,8 @@ "id": 2039122756664, "type": "output", "position": [ - 618.0, - 35.0 + 309.0, + 184.0 ], "metadata": { "color": "#FF55FFF0", @@ -64,8 +64,8 @@ 78 ], "position": [ - 2201.3125, - 289.8164062500002 + 336.07812500000045, + 1137.47265625 ], "width": 909, "height": 203, @@ -81,8 +81,8 @@ "id": 2039123154696, "type": "input", "position": [ - 0.0, - 35.0 + 454.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -95,8 +95,8 @@ "id": 2039123154840, "type": "output", "position": [ - 909.0, - 35.0 + 454.5, + 203.0 ], "metadata": { "color": "#FF55FFF0", @@ -118,8 +118,8 @@ 139 ], "position": [ - 2250.3125, - -73.18359374999977 + -46.562499999999545, + 1094.78515625 ], "width": 323, "height": 334, @@ -135,8 +135,8 @@ "id": 2039123391400, "type": "input", "position": [ - 0.0, - 35.0 + 161.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -149,8 +149,8 @@ "id": 2039123391544, "type": "output", "position": [ - 323.0, - 35.0 + 161.5, + 334.0 ], "metadata": { "color": "#FF55FFF0", @@ -172,8 +172,8 @@ 0 ], "position": [ - 1059.374999999999, - 101.00390625000023 + -31.62500000000091, + 611.0039062500002 ], "width": 1049, "height": 367, @@ -189,8 +189,8 @@ "id": 2039123184808, "type": "input", "position": [ - 0.0, - 35.0 + 524.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -203,8 +203,8 @@ "id": 2039123184952, "type": "output", "position": [ - 1049.0, - 35.0 + 524.5, + 367.0 ], "metadata": { "color": "#FF55FFF0", @@ -226,8 +226,8 @@ 129 ], "position": [ - 397.1875, - 118.62890625000023 + 262.1875, + 246.62890625000023 ], "width": 580, "height": 306, @@ -243,8 +243,8 @@ "id": 2039123244520, "type": "input", "position": [ - 0.0, - 35.0 + 290.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -257,8 +257,8 @@ "id": 2039123244664, "type": "output", "position": [ - 580.0, - 35.0 + 290.0, + 306.0 ], "metadata": { "color": "#FF55FFF0", @@ -280,8 +280,8 @@ 70 ], "position": [ - -264.1875, - -205.80859374999977 + -154.1875, + -37.80859374999977 ], "width": 320, "height": 330, @@ -297,8 +297,8 @@ "id": 2039171274936, "type": "input", "position": [ - 0.0, - 35.0 + 160.0, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -311,8 +311,8 @@ "id": 2039171275080, "type": "output", "position": [ - 320.0, - 35.0 + 160.0, + 330.0 ], "metadata": { "color": "#FF55FFF0", @@ -334,8 +334,8 @@ 0 ], "position": [ - -321.1875, - 166.19140625000023 + 242.8125, + -19.808593749999773 ], "width": 619, "height": 199, @@ -351,8 +351,8 @@ "id": 2039123194072, "type": "input", "position": [ - 0.0, - 35.0 + 309.5, + 0.0 ], "metadata": { "color": "#FF55FFF0", @@ -365,8 +365,8 @@ "id": 2039123194216, "type": "output", "position": [ - 619.0, - 35.0 + 309.5, + 199.0 ], "metadata": { "color": "#FF55FFF0",