From 87b9886207b57dcb7a065a8b4f491bcde7e6a9d8 Mon Sep 17 00:00:00 2001 From: lingruiluo Date: Mon, 13 Jul 2020 09:56:47 -0400 Subject: [PATCH 1/4] rect works correctly if no rotation;image element needs image_name to be the file path --- jp_doodle/svg_translation.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jp_doodle/svg_translation.py b/jp_doodle/svg_translation.py index a9b8e53..95b9879 100644 --- a/jp_doodle/svg_translation.py +++ b/jp_doodle/svg_translation.py @@ -127,6 +127,12 @@ def line(self, x1, y1, x2, y2, color, lineWidth, **other_arguments_ignored): ) def rect(self, x, y, w, h, color, degrees = None, lineWidth=1, fill=True, **other_arguments_ignored): + if w < 0: + x = x + w + w = abs(w) + if h < 0: + y = y + h + h = abs(h) (x, y) = self.canvas_to_svg_axis(x, y) atts = {} if fill: @@ -174,11 +180,11 @@ def polygon(self, points, color, fill=True, close = True, lineWidth=1, **other_a ) def image(self, x, y, w, h, image_name, **other_arguments_ignored): - # href is hard coded + # href is hard coded: image_name must be the file path (x, y) = self.canvas_to_svg_axis(x, y) self.add_draw_tag( tag_name="image", - href = image_name+".png", + href = image_name, x = x, y = y-h, height = h, From 74a329042c8ffdfcb9815c85ba60f250de9a0344 Mon Sep 17 00:00:00 2001 From: lingruiluo Date: Mon, 13 Jul 2020 09:57:17 -0400 Subject: [PATCH 2/4] change image name to fil path --- notebooks/misc/svg_tests/image test.ipynb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/notebooks/misc/svg_tests/image test.ipynb b/notebooks/misc/svg_tests/image test.ipynb index a16ecd5..e9b5039 100644 --- a/notebooks/misc/svg_tests/image test.ipynb +++ b/notebooks/misc/svg_tests/image test.ipynb @@ -12,13 +12,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "73e866324ddd4a5f904b52540e559d82", + "model_id": "6be65d542e574c5f80d5e2c1bc9073c4", "version_major": 2, "version_minor": 0 }, @@ -39,15 +39,15 @@ "# Scaled the image to byte values.\n", "inverted = (1 - img) * 255\n", "# Load the image to the canvas and name it.\n", - "demo.name_image_array(\"mandrill\", inverted)\n", + "demo.name_image_array(\"mandrill.png\", inverted)\n", "# Draw the image by name.\n", - "demo.named_image(\"mandrill\", 50, 50, 210, 130)\n", + "demo.named_image(\"mandrill.png\", 50, 50, 210, 130)\n", "demo.fit()" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -72,7 +72,7 @@ " 'y': 50,\n", " 'w': 210,\n", " 'h': 130,\n", - " 'image_name': 'mandrill',\n", + " 'image_name': 'mandrill.png',\n", " 'degrees': 0,\n", " 'draw_on_canvas': {},\n", " 'object_index': 0,\n", @@ -82,7 +82,7 @@ " 'sample_pixel': {'x': 160, 'y': 110}}]" ] }, - "execution_count": 6, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -93,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { From efba6c7b0eebbf9c337adb93b3e1e7db0e48133a Mon Sep 17 00:00:00 2001 From: lingruiluo Date: Mon, 13 Jul 2020 09:57:52 -0400 Subject: [PATCH 3/4] negative width and height solved, but rotation still need to be fixed --- notebooks/misc/svg_tests/rect test.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/notebooks/misc/svg_tests/rect test.ipynb b/notebooks/misc/svg_tests/rect test.ipynb index adc9d1e..7af262d 100644 --- a/notebooks/misc/svg_tests/rect test.ipynb +++ b/notebooks/misc/svg_tests/rect test.ipynb @@ -13,13 +13,13 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "2969f09be85a422cb7a2f307374d236d", + "model_id": "88250ecbd820440399d3a90c5cf52a03", "version_major": 2, "version_minor": 0 }, @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -71,7 +71,7 @@ "\t\n", "\t\n", "\t\n", - "\t\n", + "\t\n", "\t\n", "\n" ], From ddfc32f82a78f24862c10f581e65cc1c59dad89b Mon Sep 17 00:00:00 2001 From: lingruiluo Date: Mon, 13 Jul 2020 10:48:19 -0400 Subject: [PATCH 4/4] rotation works correctly --- jp_doodle/svg_translation.py | 5 ++--- notebooks/misc/svg_tests/rect test.ipynb | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/jp_doodle/svg_translation.py b/jp_doodle/svg_translation.py index 95b9879..237c53e 100644 --- a/jp_doodle/svg_translation.py +++ b/jp_doodle/svg_translation.py @@ -144,9 +144,8 @@ def rect(self, x, y, w, h, color, degrees = None, lineWidth=1, fill=True, **othe # svg rect element does not support negative coordinates if degrees: atts['transform'] = "rotate(%s, %s, %s)" %(-degrees, x, y) - else: - atts['x'] = x - atts['y'] = y-h + atts['x'] = x + atts['y'] = y-h style = "" if lineWidth: style += "stroke-width:" + str(lineWidth) diff --git a/notebooks/misc/svg_tests/rect test.ipynb b/notebooks/misc/svg_tests/rect test.ipynb index 7af262d..1fe1e0c 100644 --- a/notebooks/misc/svg_tests/rect test.ipynb +++ b/notebooks/misc/svg_tests/rect test.ipynb @@ -13,13 +13,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "88250ecbd820440399d3a90c5cf52a03", + "model_id": "e1b19d8358734e25a87b19aba5fc2896", "version_major": 2, "version_minor": 0 }, @@ -59,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -69,9 +69,9 @@ "\n", " \n", "\t\n", - "\t\n", + "\t\n", "\t\n", - "\t\n", + "\t\n", "\t\n", "\n" ],