Re: Drawing order for polymarkers

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri, 18 Sep 2009 15:35:12 -0600 (MDT)

I started a basic "draw order" page to show how to control the order
that certain plot elements are drawn.


Of particular interest may be the fourth example, which shows how to
control the draw order of individual primitives. I know this is a
topic that has tripped up other folks and myself included.

Dave Brown showed me how to fine tune the draw order of individual
primitives (polylines, polygons, markers) by adding them to a special
object. It probably won't make sense unless you understand the
internal workings of NCL, but it works.

Note: two of these examples require a fix to gsn_code.ncl that is not
available in V5.1.1. We can't give this code out to V5.1.1 folks
because it won't work unless you have a new "ncl" as well; work-around
scripts are provided.


On Thu, 17 Sep 2009, Dave Allured wrote:

> Thanks for working on this, Mary and NCL team.
> I think a web page dedicated solely to drawing order would be
> beneficial. Your e-mail could be the first draft. Much of this
> information is spread across many places in current NCL
> documentation, some not found at all. Getting the big picture on
> layering without becoming an expert on HLU, transforms, etc. would
> be good.
> --Dave
> Mary Haley wrote:
>> [We have been iterating offline about this quite a bit, and Dave Brown
>> found a bug in gsn_csm_xxx functions we need to fix with regard to
>> "tfPolyDrawOrder" not being applied to map objects.]
>> [Lengthy explanation follows!]
>> When you run Dave's script, the map outlines are appearing on top of
>> the polygons, which is actually what should happen, though it may be
>> unexpected.
>> Here's an attempt at an explanation:
>> - The "mpOutlineDrawOrder" resource defaults to "PostDraw".
>> - The "tfPolyDrawOrder" resource also defaults to "PostDraw" (it
>> was being set explicitly to this value in Dave's script, which is
>> fine).
>> - When two draw order resources have the same value, there's
>> still a pecking order that gets applied to what gets drawn first.
>> According to the "tfPolyDrawOrder" documentation at:
>> any primitives (in this case, the polygons) that are drawn during
>> the "PostDraw" phase are drawn before "PostDraw" elements
>> belonging to the "transform" object (which is the map in this
>> case).
>> This simply means that the map outlines will be drawn after the
>> polygons.
>> I believe the only way to get the map outlines to be drawn before the
>> polygons is to set the "mpOutlineDrawOrder" resource to "Draw", so
>> they are drawn in an earlier phase.
>> This whole thing brings up the bigger and complicated issue of trying
>> to control the order that all the elements of a plot get drawn, like
>> filled map areas, map outlines, primitives, contour lines, contour
>> labels, etc.
>> In my opinion, it is easier to control the order which things are
>> drawn using draw order resources, of which there are 11 (not counting
>> "tfPolyDrawOrder"):
>> cnFillDrawOrder
>> cnLabelDrawOrder
>> cnLineDrawOrder
>> mpFillDrawOrder
>> mpGridAndLimbDrawOrder
>> mpLabelDrawOrder
>> mpOutlineDrawOrder
>> mpPerimDrawOrder
>> stStreamlineDrawOrder
>> vcVectorDrawOrder
>> xyCurveDrawOrder
>> There's only three phases that these items can be drawn in: "PreDraw",
>> "Draw", and "PostDraw". As mentioned above, when plot elements are set
>> to be drawn during the same phase, there's an internal draw order that
>> applies. If you don't like this ordering, then you may have to change
>> the draw order resources so the elements are drawn in different
>> phases.
>> We have it on our list to see if there's a way we can make this
>> easier. Dave Allured has also suggested a resource setting that allows
>> you to force primitives to be drawn dead last, like a "PostPostDraw".
>> :-)
>> --Mary
>> On Wed, 16 Sep 2009, Dave Allured wrote:
>>> Rick and Adam,
>>> I tested both of your suggestions -- with and without tfPolyDrawList.
>>> In both cases, all documented settings for tfPolyDrawOrder seem to be
>>> ignored. Please see two attached test scripts. I am using NCL 5.1.1
>>> on Mac OS 10.5 PPC.
>>> I was not specific enough in my original message. I need to control
>>> polymarker/polygon drawing order with respect to other plot elements
>>> in the base plot. I would like to use tfPolyDrawOrder, not the other
>>> DrawOrder resources, because the latter sometimes come with cascading
>>> side effects.
>>> Am I doing something wrong? If not, would it be possible to get
>>> tfPolyDrawOrder working as documented in conjunction with gsn base
>>> plot functions? These are the particular base functions that I need
>>> currently:
>>> gsn_csm_contour_map_ce
>>> gsn_csm_vector_scalar_map_ce
>>> gsn_csm_contour (as overlay)
>>> Thanks for your help.
>>> --Dave
>>> Rick Brownrigg wrote on Sept 10:
>>>> Thanks for that pointer, Adam -- I was unaware of these resources.
>>>> It looks like if finer grain control over which
>>>> lines/markers/polygons get drawn first/last can be controlled with a
>>>> related resource: "tfPolyDrawList". The following snippet draws two
>>>> filled and overlapping boxes over a map of US:
>>>> boxes = new((/2/), graphic)
>>>> bRes=True
>>>> bRes_at_gsFillColor = "green"
>>>> x = (/-110, -90, -90, -110/)
>>>> y = (/40, 40, 30, 30/)
>>>> boxes(1) = gsn_add_polygon(wks, plot, x, y, bRes)
>>>> bRes_at_gsFillColor = "red"
>>>> x = (/-100, -80, -80, -100/)
>>>> y = (/35, 35, 25, 25/)
>>>> boxes(0) = gsn_add_polygon(wks, plot, x, y, bRes)
>>>> dummy = new(1,graphic)
>>>> NhlAddPrimitive(plot, boxes, dummy)
>>>> In this case, the green box is drawn last. Reordering the
>>>> assignments in "boxes" causes the red polygon to be drawn last.
>>>> FWIW...
>>>> Rick
>>>> On Sep 10, 2009, at 9:22 AM, Adam Phillips wrote:
>>>>> Hi Dave,
>>>>> I just became aware of this resource recently:
>>>>> res_at_tfPolyDrawOrder = "PreDraw" ; Draw any attached
>>>>> primitives
>>>>> ;
>>>>> before rest of plot.
>>>>> So give tfPolyDrawOrder a shot and let us know if that solves your
>>>>> problem..
>>>>> Best regards,
>>>>> Adam
>>>>> Dave Allured wrote:
>>>>>> NCL team,
>>>>>> I need to control the drawing order of polylines and polymarkers.
>>>>>> In a typical case, the base plot is made with
>>>>>> gsn_csm_vector_scalar_map_ce, plus an overlay made with
>>>>>> gsn_csm_contour.
>>>>>> I find a number of DrawOrder resources, but none seem to apply to
>>>>>> objects made with gsn_add_poly* functions. In general, what is the
>>>>>> right way to control drawing order for these? I'm using NCL 5.1.1.
>>>>>> Thanks for your help.
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
Received on Fri Sep 18 2009 - 15:35:12 MDT

This archive was generated by hypermail 2.2.0 : Fri Sep 18 2009 - 15:36:15 MDT