Skip to content

Commit

Permalink
Fix aspect ratio of logo image so it is not stretched or squashed
Browse files Browse the repository at this point in the history
Also add two new tests that make sure logo stays the right aspect
ratio whether the canvas is tall/narrow or short/wide.
  • Loading branch information
scottwittenburg committed Dec 19, 2018
1 parent 74761cf commit 97bdd3b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/.last_failure
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
['/data/scott/projects/uvcdat/vcs/tests/test_vcs_boxfill_10x10_numpy.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_flake8.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_line_patterns.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_boxfill_10x10_masked_numpy.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_flipXY.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_isofill_mask_cell_shift.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_fillarea_concave.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_flipNone.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_remove_marker_none_1d.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_settings_color_name_rgba_isofill.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_wmo_w07_marker.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_isoline_numpy.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_1D_in_boxfill.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_1D_with_manyDs.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_meshfill_vertices.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_user_passed_date_as_string.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_isoline_extend_attributes.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_missing_colorname.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_polar_set_opt_param_polar.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_meshfill_vertices_issue.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_boxfill_datawc_time.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_plot_file_var.py', '/data/scott/projects/uvcdat/vcs/tests/test_vcs_large_pattern_hatch.py']
14 changes: 14 additions & 0 deletions tests/test_vcs_draw_logo_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ def testDrawLogoOn(self):
self.x.plot(a, bg=self.bg)
fnm = "test_vcs_draw_logo_on.png"
self.checkImage(fnm)

self.x.clear()
self.x.drawlogoon()
self.x.geometry(800, 400)
self.x.plot(a, bg=self.bg)
fnm = "test_vcs_draw_logo_on_wide.png"
self.checkImage(fnm)

self.x.clear()
self.x.drawlogoon()
self.x.geometry(400, 800)
self.x.plot(a, bg=self.bg)
fnm = "test_vcs_draw_logo_on_tall.png"
self.checkImage(fnm)
Binary file added tests/test_vcs_png_window_resize2_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 36 additions & 6 deletions vcs/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def __init__(self, canvas, renWin=None,
self.plotRenderers = set()
# Maps priorities to renderers
self.text_renderers = {}
self.logoContextArea = None
self.logoContextItem = None
self.logoContextItemPython = None
self.renderer = None
Expand Down Expand Up @@ -576,6 +577,14 @@ def clear(self, render=True):
self.contextView.GetScene().ClearItems()
r, g, b = [c / 255. for c in self.canvas.backgroundcolor]
self.contextView.GetRenderer().SetBackground(r, g, b)

if self.logoContextItem:
self.logoContextArea.ClearItems()
self.contextView.GetScene().RemoveItem(self.logoContextArea)
self.logoContextArea = None
self.logoContextItem = None
self.logoContextItemPython = None

self._animationActorTransforms = {}

self.showGUI(render=False)
Expand Down Expand Up @@ -1653,22 +1662,43 @@ def createLogo(self):
position = [0.895, 0.0]
position2 = [0.10, 0.05]

[renWinWidth, renWinHeight] = self.renWin.GetSize()
vpLowerLeftX = position[0] * renWinWidth
vpLowerLeftY = position[1] * renWinHeight
vpWidth = position2[0] * renWinWidth
vpHeight = position2[1] * renWinHeight

imgAspect = float(imgWidth) / imgHeight
vpAspect = vpWidth / vpHeight

if vpAspect > imgAspect:
# We'll use the full vp height and adjust it's width so that it's
# aspect ratio matches that of the image (so no stretching of the
# image occurs). The image should be centered, so we'll offset
# position x value by half the difference.
vpWidth = vpHeight * imgAspect
halfDiff = ((position2[0] * renWinWidth) - vpWidth) / 2.0
vpLowerLeftX += halfDiff
else:
# Similar to above, but in this case we choose to keep the vp width
# and adjust it's height.
vpHeight = vpWidth / imgAspect
halfDiff = ((position2[1] * renWinHeight) - vpHeight) / 2.0
vpLowerLeftY += halfDiff

view = self.contextView

area = vtk.vtkContextArea()
view.GetScene().AddItem(area)

[renWinWidth, renWinHeight] = self.renWin.GetSize()
dataBounds = vtk.vtkRectd(0.0, 0.0, imgWidth, imgHeight)
screenGeom = vtk.vtkRecti(
int(position[0] * renWinWidth),
int(position[1] * renWinHeight),
int(position2[0] * renWinWidth),
int(position2[1] * renWinHeight))
screenGeom = vtk.vtkRecti(int(vpLowerLeftX), int(vpLowerLeftY),
int(vpWidth), int(vpHeight))

vcs2vtk.configureContextArea(area, dataBounds, screenGeom)
area.GetDrawAreaItem().AddItem(item)

self.logoContextArea = area
self.logoContextItem = item
self.logoContextItemPython = pythonItem

Expand Down

0 comments on commit 97bdd3b

Please sign in to comment.