;***********************************************************************; ; Procedure : add_labelbar ; ; wks: graphic ; ; plot: graphic ; ; zone: integer ; ; font_height: numeric ; ; type: string ; ; res: logical ; ; ; ; This procedure adds a labelbar to "plot" (which must be either a ; ; contour or vector plot). The default is to add the labelbar to the ; ; bottom of the plot, unless resources are set to change this. The zone ; ; must be passed in, as well as the font height for the labelbar labels.; ; "type" is the type of plot ("ce", "polar", and so on) so the labelbar ; ; can be positioned differently depending on the plot. ; ; ; ; Eventually we want to move to using the PlotManager labelbar. This is ; ; what the global GSN_OLD_LABELBAR variable is for. If it's set to True,; ; then the PlotManager labelbar is *not* used, and instead, a custom ; ; one via this routine, is created. ; ;***********************************************************************; undef("add_labelbar") procedure add_labelbar(wks:graphic,plot,zone:integer, \ font_height:numeric,type:string,res:logical) local anno, num_res, amres, lbres, labelbar_object, lbar_orient, \ lbar_side, lbar_just, fill_patterns, fill_scales, mono_fill_pat, \ mono_fill_scl, mono_fill_col, levels begin ; ; If lbLabelBarOn is set to False, then don't bother with a labelbar. ; if(check_attr(res,"lbLabelBarOn",False,False)) return end if lbres = True ; hold labelbar resources amres = True ; hold annomanager resources parallel = get_res_value(res,"pmLabelBarParallelPosF",0.5) ; Check for annotation/labelbar resources lbres = get_res_eq(res,(/"lb","vp"/)) amres = get_res_eq(res,"am") set_attr(amres,"amZone",zone) set_attr(amres,"amResizeNotify",True) set_attr(amres,"amParallelPosF",parallel) set_attr(lbres,"lbLabelFontHeightF",font_height) ; Default is horizontal at the bottom. lbar_orient = "horizontal" lbar_side = "bottom" lbar_just = "bottomcenter" if(check_attr(lbres,"lbOrientation","vertical",True).or.\ check_attr(lbres,"lbOrientation",1,True)) then lbar_orient = "vertical" lbar_side = "right" lbar_just = "centerright" end if set_attr(lbres,"lbOrientation",lbar_orient) set_attr(amres,"amSide",lbar_side) set_attr(amres,"amJust",lbar_just) ; ; Determine what the default labelbar width and height should be depending ; on shape of plot (this is for a horizontal labelbar). For example, if ; the plot is square, then make the labelbar the same width as the plot. ; If the plot is 1:2, then make the labelbar .75 * width of the plot. ; ; For a vertical labelbar, make the height the same as the height of the ; plot. ; getvalues plot "vpWidthF" : width ; Width of plot "vpHeightF" : height ; Height of plot end getvalues ratio1 = width/height ratio2 = height/width ratio = min((/ratio1,ratio2/)) ratios = (/0.50, 0.75, 1.00/) ; viewport ratios lwscale = (/0.75, 0.90, 1.00/) wh_ind = ind(ratio.le.ratios) def_lvpwf = lwscale(wh_ind(0)) ; default width scale for labelbar amres = get_res_eq(res,"am") if(lbar_orient.eq."vertical") then if(type.eq."polar") orth = get_res_value(res,"pmLabelBarOrthogonalPosF",0.05) else orth = get_res_value(res,"pmLabelBarOrthogonalPosF",0.03) end if height = get_res_value(res,"pmLabelBarHeightF",height) width = get_res_value(res,"pmLabelBarWidthF",0.2*width) else height = get_res_value(res,"pmLabelBarHeightF",0.3*height) width = get_res_value(res,"pmLabelBarWidthF",def_lvpwf*width) if(zone.eq.2) if(type.eq."polar") orth = get_res_value(res,"pmLabelBarOrthogonalPosF",0.03) else orth = get_res_value(res,"pmLabelBarOrthogonalPosF",0.06) end if else orth = get_res_value(res,"pmLabelBarOrthogonalPosF",0.0) end if end if set_attr(lbres,"vpHeightF",height) set_attr(lbres,"vpWidthF",width) set_attr(amres,"amOrthogonalPosF",orth) class_name = NhlClassName(plot) if(class_name.eq."logLinPlotClass".or.class_name.eq."irregularPlotClass") the_plot = plot@contour else the_plot = plot end if if(class_name.eq."contourPlotClass".or.class_name.eq."logLinPlotClass".or.\ class_name.eq."irregularPlotClass") getvalues the_plot "cnLevels" : levels "cnFillDotSizeF" : dot_size "cnFillColors" : tmp_colors "cnFillPatterns" : tmp_fill_patterns "cnFillPattern" : fill_pattern "cnFillScales" : tmp_fill_scales "cnFillScaleF" : fill_scale "cnFillMode" : fill_mode "cnMonoFillPattern" : mono_fill_pat "cnMonoFillScale" : mono_fill_scl "cnMonoFillColor" : mono_fill_col "cnLabelBarEndStyle" : end_labelbar_style "cnLabelBarEndLabelsOn" : end_labels_on "cnLineLabelFormat" : line_format ; default is "*+^sg" "lbLabelStrings" : lbstrings end getvalues ; ; cnLabelBarEndLabelsOn was deprecated in V5.0, but we still need to ; check for it. It's been replaced by cnLabelBarEndStyle. ; ; The three styles are: ; ; 0 - IncludeOuterBoxes (default) ; 1 - IncludeMinMaxLabels (the equivalent of cnLabelBarEndLabelsOn=True) ; 2 - ExcludeOuterBoxes ; ; If the style is 0 (the default) *and* xxLabelBarEndLabelsOn is ; True, then set the style to 1. If the style is 1 or 2 (the only ; other valid values), then xxLabelBarEndLabelsOn should be set True. ; if(end_labelbar_style.eq.0) then if(end_labels_on) then end_labelbar_style = 1 end if else end_labels_on = True end if if(end_labelbar_style.eq.2) then ; Don't use the first fill color, scale, or pattern. nc2 = dimsizes(tmp_colors) end_labels_on = True colors = tmp_colors(1:nc2-2) fill_scales = tmp_fill_scales(1:nc2-2) fill_patterns = tmp_fill_patterns(1:nc2-2) else colors = tmp_colors fill_scales = tmp_fill_scales fill_patterns = tmp_fill_patterns end if delete(tmp_colors) delete(tmp_fill_scales) delete(tmp_fill_patterns) ; ; Check if the fill mode is "RasterFill". If so, be sure to ; set lbRasterFillOn to True ; if(.not.isatt(lbres,"lbRasterFillOn").and.fill_mode.eq.1) lbres@lbRasterFillOn = True end if ; ; Check if we want different fill patterns or fill scales. If so, we ; have to pass these on to the labelbar. ; lbres@lbMonoFillColor = mono_fill_col if(.not.mono_fill_pat) lbres@lbMonoFillPattern = False lbres@lbFillPatterns = fill_patterns lbres@lbFillDotSizeF = dot_size else lbres@lbFillPattern = fill_pattern end if if(.not.mono_fill_scl) lbres@lbMonoFillScale = False lbres@lbFillScales = fill_scales lbres@lbFillDotSizeF = dot_size else lbres@lbFillScaleF = fill_scale end if else if(class_name.eq."vectorPlotClass") then line_format = "*+^sg" ; VectorPlot doesn't have an equivalent "cnLineLabelFormat" resource getvalues the_plot "vcLevels" : levels "vcLevelColors" : colors "vcLabelBarEndLabelsOn" : end_labels_on "lbLabelStrings" : lbstrings end getvalues else line_format = "*+^sg" ; StreamlinePlot doesn't have an equivalent "cnLineLabelFormat" resource ;---Better be a streamline plot! getvalues the_plot "stLevels" : levels "stLevelColors" : colors "stLabelBarEndLabelsOn" : end_labels_on "lbLabelStrings" : lbstrings end getvalues end if end if ; ; Vector and Streamline don't have the xxLabelBarEndStyle resource ; implemented yet. So, based on setting of xxLabelBarEndLabelsOn, ; we can set the style. ; if(.not.isvar("end_labelbar_style")) then if(end_labels_on) then end_labelbar_style = 1 else end_labelbar_style = 0 end if end if ; ; If user set cn/vcLabelBarEndLabelsOn to True or the LabelBarStyle ; resource to 1, then we need to add min/max labels. Use lbstrings (rather ; than actual min/max of data) because the labels will already be ; formatted correctly. ; nlev = dimsizes(levels) if(end_labels_on.and.end_labelbar_style.eq.1.and. \ (lbstrings(0).eq."".or.lbstrings(nlev+1).eq."")) then print("Warning:add_labelbar: invalid end labels, turning them off.") end_labels_on = False end if if(end_labels_on) then if(end_labelbar_style.eq.1) then newlevels = new(nlev+2,typeof(levels)) newlevels(1:nlev) = levels newlevels(0) = stringtoxxx(lbstrings(0),typeof(newlevels)) newlevels(nlev+1) = stringtoxxx(lbstrings(nlev+1),typeof(newlevels)) delete(levels) levels = newlevels delete(newlevels) end if set_attr(lbres,"lbLabelAlignment","ExternalEdges") end if if(line_format.ne."*+^sg") then lbres@lbLabelStrings = lbstrings end if levels = fix_zero_contour(levels) labelbar_object = create_labelbar(wks,dimsizes(colors),colors,levels,lbres) anno = NhlAddAnnotation(plot,labelbar_object) attsetvalues_check(anno,amres) ; Set annotation resources. delete(levels) return end