Skip to content

Commit bf352fd

Browse files
committed
Merge pull request #839 from UV-CDAT/issue_826_EzTemplate_cleanup
Issue 826 ez template cleanup Thanks Charles. I will give it a try now.
2 parents 1c31b2b + 1395462 commit bf352fd

15 files changed

Lines changed: 284 additions & 14 deletions

Packages/vcs/Lib/Canvas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,7 +3687,7 @@ def set_convert_labels(copy_mthd,test=0):
36873687

36883688
# Now executes output commands
36893689
for cc in cmds.keys():
3690-
c=string.lower(cc)
3690+
c=cc.lower()
36913691
if type(cmds[cc])!=type(''):
36923692
args=tuple(cmds[cc])
36933693
else:
@@ -5513,7 +5513,7 @@ def gif(self, filename='noname.gif', merge='r', orientation=None, geometry='1600
55135513
""" % (self._dotdir)
55145514
if orientation is None:
55155515
orientation=self.orientation()[0]
5516-
g = string.split(geometry,'x')
5516+
g = geometry.split('x')
55175517
f1 = f1=float(g[0]) / 1100.0 * 100.0
55185518
f2 = f2=float(g[1]) / 849.85 * 100.0
55195519
geometry = "%4.1fx%4.1f" % (f2,f1)
@@ -5562,7 +5562,7 @@ def gs(self, filename='noname.gs', device='png256', orientation=None, resolution
55625562
""" % (self._dotdir)
55635563
if orientation is None:
55645564
orientation=self.orientation()[0]
5565-
r = string.split(resolution,'x')
5565+
r = resolution.split('x')
55665566
f1 = f1=float(r[0]) / 1100.0 * 100.0
55675567
f2 = f2=float(r[1]) / 849.85 * 100.0
55685568
resolution = "%4.1fx%4.1f" % (f2,f1)

Packages/vcs/Lib/Pboxeslines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# Template text (Pbl) Class. #
3333
# #
3434
#############################################################################
35-
class Pbl:
35+
class Pbl(object):
3636
'''
3737
Class: Pbl # Template text
3838

Packages/vcs/Lib/VTKPlots.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,9 @@ def pdf(self, file, width=None, height=None, units=None):
12321232
def svg(self, file, width=None, height=None, units=None):
12331233
return self.vectorGraphics("svg", file, width, height, units)
12341234

1235+
def gif(self,filename='noname.gif', merge='r', orientation=None, geometry='1600x1200'):
1236+
raise RuntimeError("gif method not implemented in VTK backend yet")
1237+
12351238
def png(self, file, width=None,height=None,units=None,draw_white_background = True, **args ):
12361239

12371240
if self.renWin is None:

Packages/vcs/Lib/template.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,24 +1069,24 @@ def reset(self,sub_name,v1,v2,ov1=None,ov2=None):
10691069
ov=getattr(v,sub_name+'1')
10701070
if ov1 is not None:
10711071
delta=(ov-ov1)*ratio
1072-
setattr(v,sub_name+'1',v1+delta)
1072+
setattr(v,sub_name+'1',min(1,max(0,v1+delta)))
10731073
delta=0.
10741074
if sub_name+'2' in subattr:
10751075
ov=getattr(v,sub_name+'2')
10761076
if ov2 is not None:
10771077
delta=(ov-ov2)*ratio
1078-
setattr(v,sub_name+'2',v2+delta)
1078+
setattr(v,sub_name+'2',min(1,max(0,v2+delta)))
10791079
delta=0.
10801080
if sub_name in subattr:
10811081
ov=getattr(v,sub_name)
10821082
if ov1 is not None:
10831083
delta=(ov-ov1)*ratio
1084-
setattr(v,sub_name,v1+delta)
1084+
setattr(v,sub_name,min(1,max(0,v1+delta)))
10851085
if a[-1]=='2':
10861086
ov=getattr(v,sub_name+'2')
10871087
if ov2 is not None:
10881088
delta=(ov-ov2)*ratio
1089-
setattr(v,sub_name,v2+delta)
1089+
setattr(v,sub_name,min(1,max(0,v2+delta)))
10901090
except Exception,err:
10911091
pass
10921092

Packages/vcsaddons/Lib/Multi.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def clean(self):
229229
self.x.removeP(t)
230230
self.template_names=[]
231231

232-
def get(self,column=None,row=None,legend=None,font=True,fontlimit=0.):
232+
def get(self,column=None,row=None,legend=None,font=True,fontlimit=0.8):
233233
"""
234234
Returns a template to use in vcs
235235
Usage:
@@ -337,10 +337,10 @@ def get(self,column=None,row=None,legend=None,font=True,fontlimit=0.):
337337
dx=self.legend.stretch
338338
dy=self.legend.thickness
339339
## print x1,x2,y1,y2,dx,dy
340-
t.legend.x1=x1+(x2-x1)*(1.-dx)/2.
341-
t.legend.x2=x2-(x2-x1)*(1.-dx)/2.
342-
t.legend.y1=y1+(y2-y1)*(1.-dy)/2.
343-
t.legend.y2=y2-(y2-y1)*(1.-dy)/2.
340+
t.legend.x1=min(1,max(0,x1+(x2-x1)*(1.-dx)/2.))
341+
t.legend.x2=min(1,max(0,x2-(x2-x1)*(1.-dx)/2.))
342+
t.legend.y1=min(1,max(0,y1+(y2-y1)*(1.-dy)/2.))
343+
t.legend.y2=min(1,max(0,y2-(y2-y1)*(1.-dy)/2.))
344344
return t
345345

346346
def preview(self,out='EZTemplate_Multi',bg=1):
@@ -386,7 +386,8 @@ def preview(self,out='EZTemplate_Multi',bg=1):
386386

387387

388388
self.x.postscript(out)
389-
self.x.gif(out)
389+
self.x.pdf(out)
390+
self.x.png(out)
390391

391392

392393

testing/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (CDAT_BUILD_VCS_LEGACY)
66
add_subdirectory(vcs_legacy)
77
endif()
88
add_subdirectory(vcs)
9+
add_subdirectory(vcsaddons)
910
add_subdirectory(dv3d)
1011
add_subdirectory(cdutil)
1112
add_subdirectory(cdms2)

testing/vcsaddons/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
set(BASELINE_DIR "${UVCDAT_GIT_TESTDATA_DIR}/baselines/vcsaddons")
2+
3+
add_test(vcs_addons_preview_2x2
4+
${CMAKE_INSTALL_PREFIX}/bin/python
5+
${cdat_SOURCE_DIR}/testing/vcsaddons/test_vcsaddons_preview_2x2.py
6+
${BASELINE_DIR}/test_vcsaddons_preview_2x2.png
7+
)
8+
add_test(vcs_addons_test_12_plot_one_leg_per_row
9+
${CMAKE_INSTALL_PREFIX}/bin/python
10+
${cdat_SOURCE_DIR}/testing/vcsaddons/test_12_plot_one_leg_per_row.py
11+
${BASELINE_DIR}/test_12_plot_one_leg_per_row.png
12+
)
13+
add_test(vcs_addons_test_12_plot_one_leg_per_row_right
14+
${CMAKE_INSTALL_PREFIX}/bin/python
15+
${cdat_SOURCE_DIR}/testing/vcsaddons/test_12_plot_one_leg_per_row_right.py
16+
${BASELINE_DIR}/test_12_plot_one_leg_per_row_right.png
17+
)
18+
add_test(vcs_addons_test_EzTemplate_12_plots_margins_thickness
19+
${CMAKE_INSTALL_PREFIX}/bin/python
20+
${cdat_SOURCE_DIR}/testing/vcsaddons/test_EzTemplate_12_plots_margins_thickness.py
21+
${BASELINE_DIR}/test_EzTemplate_12_plots_margins_thickness.png
22+
)
23+
add_test(vcs_addons_test_EzTemplate_12_plots_legd_direction
24+
${CMAKE_INSTALL_PREFIX}/bin/python
25+
${cdat_SOURCE_DIR}/testing/vcsaddons/test_EzTemplate_12_plots_legd_direction.py
26+
${BASELINE_DIR}/test_EzTemplate_12_plots_legd_direction.png
27+
)
28+
add_test(vcs_addons_test_EzTemplate_12_plots_mix_glb_local
29+
${CMAKE_INSTALL_PREFIX}/bin/python
30+
${cdat_SOURCE_DIR}/testing/vcsaddons/test_EzTemplate_12_plots_mix_glb_local.py
31+
${BASELINE_DIR}/test_EzTemplate_12_plots_mix_glb_local.png
32+
)
33+
add_test(vcs_addons_test_EzTemplate_12_plots_spacing
34+
${CMAKE_INSTALL_PREFIX}/bin/python
35+
${cdat_SOURCE_DIR}/testing/vcsaddons/test_EzTemplate_12_plots_spacing.py
36+
${BASELINE_DIR}/test_EzTemplate_12_plots_spacing.png
37+
)
38+
39+
if (CDAT_DOWNLOAD_SAMPLE_DATA)
40+
add_test(vcs_addons_EzTemplate_2x2
41+
${CMAKE_INSTALL_PREFIX}/bin/python
42+
${cdat_SOURCE_DIR}/testing/vcsaddons/test_vcs_addons_EzTemplate_2x2.py
43+
${BASELINE_DIR}/test_vcs_addons_EzTemplate_2x2.png
44+
)
45+
endif()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys,os
2+
src = sys.argv[1]
3+
pth = os.path.join(os.path.dirname(__file__),"..")
4+
sys.path.append(pth)
5+
import checkimage
6+
import EzTemplate,vcs
7+
## 12 plot one legend per row
8+
9+
## Initialize VCS
10+
x=vcs.init()
11+
12+
bg = True
13+
M=EzTemplate.Multi(rows=4,columns=3)
14+
M.legend.stretch=2.5 # 250% of width (for middle one)
15+
for i in range(12):
16+
t=M.get(legend='local')
17+
if i%3 !=1:
18+
t.legend.priority=0 # Turn off legend
19+
fnm = "test_12_plot_one_leg_per_row.png"
20+
M.preview(fnm,bg=bg)
21+
print "fnm:",fnm
22+
print "src:",src
23+
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
24+
if not bg:
25+
raw_input("Press Enter")
26+
sys.exit(ret)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys,os
2+
src = sys.argv[1]
3+
pth = os.path.join(os.path.dirname(__file__),"..")
4+
sys.path.append(pth)
5+
import checkimage
6+
import EzTemplate,vcs
7+
import cdms,EzTemplate,vcs,sys
8+
## 12 plots 1 legend per row on the right
9+
## Initialize VCS
10+
x=vcs.init()
11+
bg=True
12+
M=EzTemplate.Multi(rows=4,columns=3)
13+
M.legend.direction='vertical'
14+
for i in range(12):
15+
t=M.get(legend='local')
16+
if i%3 !=2:
17+
t.legend.priority=0 # Turn off legend
18+
fnm = "test_12_plot_one_leg_per_row_right.png"
19+
M.preview(fnm,bg=bg)
20+
print "fnm:",fnm
21+
print "src:",src
22+
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
23+
if not bg:
24+
raw_input("Press Enter")
25+
sys.exit(ret)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys,os
2+
src = sys.argv[1]
3+
pth = os.path.join(os.path.dirname(__file__),"..")
4+
sys.path.append(pth)
5+
import checkimage
6+
import EzTemplate,vcs
7+
## 12 plot one legend per row
8+
9+
## Initialize VCS
10+
x=vcs.init()
11+
12+
bg = True
13+
M=EzTemplate.Multi(rows=4,columns=3)
14+
M.margins.top=.25
15+
M.margins.bottom=.25
16+
M.margins.left=.25
17+
M.margins.right=.25
18+
19+
M.legend.direction='vertical'
20+
## The legend uses the right margin for display are
21+
## We need to "shrink it"
22+
M.legend.thickness=.05
23+
for i in range(12):
24+
t=M.get()
25+
26+
fnm = "test_EzTemplate_12_plots_legd_direction.png"
27+
M.preview(fnm,bg=bg)
28+
print "fnm:",fnm
29+
print "src:",src
30+
ret = checkimage.check_result_image(fnm,src,checkimage.defaultThreshold)
31+
if not bg:
32+
raw_input("Press Enter")
33+
sys.exit(ret)

0 commit comments

Comments
 (0)