Skip to content

Commit

Permalink
BUG #1740: plotting with bg=0 produces labels off
Browse files Browse the repository at this point in the history
This also fixes BUG #78 in cdat-web.
For both bugs, VTKPlots.configureEvent is not called to reposition the labels.
  • Loading branch information
danlipsa committed Mar 1, 2016
1 parent 39a367c commit 2136c2e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Packages/vcs/Lib/VTKPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def createRenWin(self, *args, **kargs):
if not self.bg:
self.createDefaultInteractor(self.renderer)
self.renWin.AddRenderer(self.renderer)
self.renWin.AddObserver("ModifiedEvent", self.configureEvent)
if self.bg:
self.renWin.SetOffScreenRendering(True)
if "open" in kargs and kargs["open"]:
Expand All @@ -357,7 +358,7 @@ def createRenderer(self, *args, **kargs):
return ren

def update(self, *args, **kargs):
self._lastSize = -1
self._lastSize = None
if self.renWin:
if self.get3DPlot():
plots_args = []
Expand Down Expand Up @@ -1076,9 +1077,11 @@ def png(self, file, width=None, height=None,
if width is not None and height is not None:
if self.renWin.GetSize() != (width, height):
user_dims = (self.canvas.bgX, self.canvas.bgY, sz[0], sz[1])
self.renWin.SetSize(width, height)
# We need to set canvas.bgX and canvas.bgY before we do renWin.SetSize
# otherwise, canvas.bgX,canvas.bgY will win
self.canvas.bgX = width
self.canvas.bgY = height
self.renWin.SetSize(width, height)
self.configureEvent(None, None)
else:
user_dims = None
Expand Down
5 changes: 5 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ cdat_add_test(vcs_test_meshfill_zoom_flip
"${BASELINE_DIR}/vcs_test_meshfill_zoom_flip.png"
flip
)
cdat_add_test(vcs_test_isofill_labels_off.png
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/vcs_test_isofill_labels_off.py
"${BASELINE_DIR}/vcs_test_isofill_labels_off.png"
)
cdat_add_test(vcs_test_meshfill_zoom_flip
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/vcs_test_meshfill_zoom.py
Expand Down
39 changes: 39 additions & 0 deletions testing/vcs/vcs_test_isofill_labels_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python
import cdms2
import os
import sys
import vcs

# Test that the image is created properly when we call plot with bg = 0 and
# then we save a png. If the default png size is bigger than the screen size,
# the image was not resized properly

pth = os.path.join(os.path.dirname(__file__), "..")
sys.path.append(pth)
import checkimage

cdmsfile = cdms2.open(os.path.join(vcs.sample_data, 'clt.nc'))
clt = cdmsfile('clt')
clt = clt(latitude=(-90.0, 90.0),squeeze=1,longitude=(-180.0, 175.0),time=('1979-01', '1988-12'),)

x = vcs.init()
x.setantialiasing(0)
x.drawlogooff()

gmIsofill = vcs.getisofill('a_robinson_isofill')
args = []
args.append(clt)
gmIsofill.datawc_calendar = 135441
gmIsofill.datawc_timeunits = 'days since 2000'
gmIsofill.projection = 'robinson'
kwargs = {}
kwargs[ 'cdmsfile' ] = cdmsfile.id
#kwargs[ 'bg' ] = 1
args.append( gmIsofill )
x.plot( *args, **kwargs)
fileName = os.path.basename(__file__)
fileName = os.path.splitext(fileName)[0]
fileName = fileName + '.png'
x.png(fileName)
ret = checkimage.check_result_image(fileName, sys.argv[1], checkimage.defaultThreshold)
sys.exit(ret)

0 comments on commit 2136c2e

Please sign in to comment.