Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw rectangle fix #409

Closed
wants to merge 1 commit into from
Closed

Draw rectangle fix #409

wants to merge 1 commit into from

Conversation

emilroz
Copy link
Member

@emilroz emilroz commented Dec 3, 2020

Not sure about the cause or how to reproduce as it's been reported to us via support channel. In some conditions it's possible to run into the following issue:

Traceback (most recent call last):

  File "./script", line 2361, in <module>

    run_script()

  File "./script", line 2347, in run_script

    file_annotation = export_figure(conn, script_params)

  File "./script", line 2303, in export_figure

    return fig_export.build_figure()

  File "./script", line 977, in build_figure

    self.add_panels_to_page(panels_json, image_ids, page)

  File "./script", line 1803, in add_panels_to_page

    image, pil_img = self.draw_panel(panel, page, i)

  File "./script", line 1634, in draw_panel

    self.paste_image(pil_img, img_name, panel, page, dpi)

  File "./script", line 2055, in paste_image

    ShapeToPilExport(pil_img, panel, crop)

  File "./script", line 522, in __init__

    super(ShapeToPilExport, self).__init__(panel)

  File "./script", line 187, in __init__

    getattr(self, 'draw_%s' % s['type'].lower(), lambda s: None)(s)

  File "./script", line 641, in draw_rectangle

    stroke_width = scale_to_export_dpi(shape.get('strokeWidth', 2))

  File "./script", line 111, in scale_to_export_dpi

    return pixels * 300//72

TypeError: unsupported operand type(s) for //: 'str' and 'int'

A fixed proposed here address it directly in the Export script. Not sure if it's possible to fix it earlier at the Figure_JSON level.

@@ -638,7 +638,7 @@ def draw_rectangle(self, shape):
p.append(p[0])
points = p

stroke_width = scale_to_export_dpi(shape.get('strokeWidth', 2))
stroke_width = scale_to_export_dpi(int(shape.get('strokeWidth', 2)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like scale_to_export_dpi can take floats. Does that lead to weirdness?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @joshmoore. Yes, we do allow floats. The UI allows you to choose 0.25, 0.5, 0.75, 1, 2...
I see that scale_to_export_dpi(shape.get('strokeWidth', 2)) occurs in a few other places too, so they'll need the same fix too.
I should probably review scale_to_export_dpi(pixels) to do it's own casting of pixels to float but that might change the return type (int to float) in some cases so I'd want to check the impact of that.

@jburel
Copy link
Member

jburel commented Feb 21, 2021

Replaced by #426

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants