[Thread Prev][Thread Next][Index]

Re: Hide outside labels



Hi Julien & Ansley,
                      I just put Ansley's idea to a Ferret go script 
(see the attachment, label_inside.jnl). As Ansley mensioned in his 
previous mail, it is not that easy to get the labelling automated with
all our requirements satisfied. Even if you are using this go file, you
have to tune few arguments in order to get the plot labels in the 
desired  form. 

    Please find the details inside the jnl file and have a look at the
example given in the jnl file. In case you need any more explanation or
finds any problems with it, please let me know.

With Regards

Jaison

On Wed, 1 Dec 2004, Ansley Manke wrote:

> Hi Julien,
> There's no easy answer for this in terms of Ferret commands; labeling is 
> set up so that
> labels can be placed anywhere in the plot window. 
> 
> The answer will probably be that you'll have to compute the amount of 
> space available
> in the plot box, using symbols like  PPL$XLEN, axis length in inches, 
> and XAXIS_MIN
> and XAXIS_MAX, which are the axis endpoints in user units (e.g. 
> longitude).  Then
> you would compute the distance from your desired location to the edge of 
> the plot box.
> The size of the text and function STRLEN would tell how much of the 
> label will fit, and
> SUBSTRING  shortens the strings as needed.
> 
> Users, does anyone do this general kind of thing?  Does anyone have 
> scripts that compute
> positions on the pages in terms of plot-axis lengths, converting between 
> user units and inches,
> and the size of string labels?  I imagine a few examples would be very 
> helpful.
> 
> Ansley
> 
> Julien Demaria wrote:
> 
> > Ansley,
> >
> > Thanks for your answer,
> >
> > In fact I want use the mode ppl window off, but I need truncate cities 
> > labels too when there are too long and has a part outside the 
> > window... : example : at the end of your example :
> >
> > label 10, 53, -1, 0, 0.12 LONGLONGLABEL
> >
> > I need this because I generate labels from a big list of cities and I 
> > cannot know if each label 'll overlap the window (depending on font, 
> > size, ...).
> >
> > Thanks,
> >
> > Julien
> >
> > At 18:24 30/11/2004, Ansley Manke wrote:
> >
> >> Hi Julien,
> >> You don't say what command you're using to plot your symbols, but 
> >> with either
> >> the PLOT/VS command or POLYGON command,  the PPL WINDOW OFF
> >> command will set Ferret so it doesn't "window" the data, that is, 
> >> clip it to the
> >> edges of the plot box.  Try this example:
> >>
> >>   yes? go basemap x=-60:20 y=20:80 20
> >>   yes? ppl window off
> >>
> >>   yes? let xpts =  {10,15,20,22,25}
> >>   yes? let ypts =  {43,55,49,43,50}
> >>   yes? plot/vs/over/nolab/color=red/sym=26 xpts, ypts
> >>
> >>   yes? let ypts =  {53,65,59,53,60}
> >>   yes? go polymark poly/over/nolab/nokey/line/pal=green xpts, ypts, 
> >> ,circle
> >>
> >> Julien Demaria wrote:
> >>
> >>> Hi,
> >>>
> >>> I need to display a list of cities names on my map with little cross 
> >>> : when a cross is outside my map it is automatically hidden, but the 
> >>> associated label is displayed...
> >>> Are there tricks to automatically hide outside labels ?
> >>>
> >>> Thanks in advance,
> >>>
> >>> Julien
> >>
> >
> 

-- 
___________________________________________________

    Jaison Kurian                           
    Centre for Atmospheric and Oceanic Sciences
    Indian Institute of Science
    B A N G A L O R E   560 012
    Ph: +91-80-3942505
        +91-80-3600450
    Fax:+91-80-3600865
___________________________________________________
\ cancel mode verify
!
! Description : Put labels such that the whole string will be inside the 
! -----------       plot area. IF the string will not fit inside the plot
!                   area, then trim it. Appropriate alignment will be chosen
!                   by the script. There will be little offset in the -ve Y
!                   direction for labels in the upper half of the plot area
!                   for a better clarity. There is no option for "cetre align
!                   or justify" and to "rotate" the string in order to
!                   avoid the complexity.
! Date : 05-DEC-2004
!
! Arguments :
! ----------  
! Mandatory   
!      (real) $1 : x position of label in X-axis units
!    " (real) $2 : y position of label in Y-axis units
!    " (text) $3 : label string in double quotes
! Optional    
!      (real) $4 : font size  (default is 0.12)
!    " (int ) $5 : text color ( between 1 & 18; default is black (1))
!    " (text) $6 : font style (default is SR)
!    " (int ) $7 : x clip => number of charaters to clip(if +ve) or add (if -ve) )
!                                  default is +1
!    " (real) $8 : y clip => y delta over which labelling will be skipped at top and
!                                  bottom of the plot for neatness of plot ; should
!                                  be in yaxis units ; can be +ve or -ve ; default is 1
!    " (int ) $9 : skip labelling if full string doesn't fits inside the plot area
!                        $9 .NE. 0 ==> skip labelling with trimmed string
!                        $9 .EQ. 0 ==> label with the trimmed string  (default)
!
! Usage :
! -------   
!          GO label_inside xpos, ypos, string, [font_size], [color], [font_style], [x_clip], [y_clip], [skip_trimmed]
!
! Example :
! --------
!   go basemap x=-60:20 y=0:80 20
!   let xpts = {-61,-60,-50,-40,-30,-20,-10,  0, 10, 20, 20}
!   let ypts = { 10,  0, 10, 20, 30, 40, 50, 60, 70, 80, 83}
!   plot/vs/over/color=4/nolab/size=0.2/sym=40 xpts, ypts
!   REPEAT/RANGE=1:11:1/NAME=labid ( ;\
!      let xx = xpts[i=`labid`] ;\      ! strongly recommended to use immediate
!      let yy = ypts[i=`labid`] ;\      !  variables to pass arguments within repeat loop
!      go label_inside xx, yy,"WHATEVER MAY BE THE LENGTH OF THE STRING I WILL PUT IT INSIDE THE PLOT AREA", 0.12, 6, AS, 1,1,0 ;\
!     )
!
! NOTE :
! ------
! If you want to get "_" and "^o" in the same string then
!      select font style other than AS 
!      give a "-" sign after "_" like    "mylab_-and^o degrees"
! ref : http://ferret.pmel.noaa.gov/Ferret/Mail_Archives/fu_2003/msg01555.html
!-----------------------------------------------------------------------------------

! put proper names to arguments and/or do a checking 

     let lbl_x             =  $1"<Usage: GO label_inside[.jnl] xpos ypos string [font_size] [color] [font_style] [x_clip] [y_clip] [skip_trimmed]"
     let lbl_y             =  $2"<Usage: GO label_inside[.jnl] xpos ypos string [font_size] [color] [font_style] [x_clip] [y_clip] [skip_trimmed]" 
     define symbol lbl_t   =  $3"<Usage: GO label_inside[.jnl] xpos ypos string [font_size] [color] [font_style] [x_clip] [y_clip] [skip_trimmed]" 

     let lbl_sz             =  $4"0.12"           ! label font size
     let lbl_cl             =  $5"1"              ! label color, default black(1)
     define symbol lbl_stl  =  $6"SR"             ! label font style
     let lbl_skip_trimmed   =  $9"0"              ! allow for skipping trimmed labels
      
     let lbl_len            = STRLEN("($lbl_t)")  ! length of label text
     let lbl_l_max          = 0                   ! initialize, max char for left align 
     let lbl_r_max          = 0                   ! initialize, max char for right align
     let lbl_big            = 0                   ! initialize, biggest of above two
     define symbol do_label = no                  ! initialize
      
! define a cutoff for y when y is near to y_min or y_max of plot area   

     let lbl_y_max  = `(($PPL$YLEN)+($PPL$YORG))/lbl_sz`! maximum charaters along y 
     let lbl_y_len  = `($YAXIS_MAX)-($YAXIS_MIN)`       ! lenth of yax in axis units
     let lbl_y_off  = lbl_y_len/lbl_y_max               ! length of one char along yax 
                                                        !   as y cutoff
     let lbl_yclip  = $8"`lbl_y_off`"                   ! allow for user input
     let lbl_ybig   = `($YAXIS_MAX)` - lbl_yclip        ! max y for labelling
     let lbl_ysml   = `($YAXIS_MIN)` + lbl_yclip        ! min y for labelling
     
! in case label doesn't fit inside the plot area allow user to clip chars

     let lbl_xclip      = $7"1"                         ! how many chars to clip
     let lbl_xclip      = INT(`lbl_xclip`)

! ok..now check wether the labelling is inside the plot area or not

     IF `lbl_x GE ($XAXIS_MIN) AND lbl_x LE ($XAXIS_MAX)` THEN
        IF `lbl_y GE lbl_ysml AND lbl_y LE lbl_ybig` THEN
            define symbol do_label = yes
        ENDIF
     ENDIF
      
! align to "bottom" when label is in upper half of the plot area 

     let lbl_ymid = `($YAXIS_MIN)+($YAXIS_MAX)`/2
     IF `lbl_y GT lbl_ymid` THEN
         let lbl_y = `lbl_y` - 1.5*lbl_y_off
     ENDIF

! determine the alignment : left align is preffered

     let lbl_max_chars = `(($PPL$XLEN)+($PPL$XORG))/lbl_sz`! max chars possible
     let lbl_max_len       = `($XAXIS_MAX)-($XAXIS_MIN)`   ! lenth of xax in axis units
 
     let lbl_l_sz   = ($XAXIS_MAX)-lbl_x                   ! current size for left align
     let lbl_l_max1 = lbl_max_chars * lbl_l_sz/lbl_max_len ! max chars for left align
     let lbl_l_max  = INT(lbl_l_max1)                      !          "
     IF `lbl_len LE lbl_l_max` THEN                        ! if it fits inside the plot
         let align              = -1                       ! then align left (-1)
         define symbol lbl_txt  = ($lbl_t)                 ! use full string
     ELSE                                                  ! if left align doesn't work
         let lbl_r_sz   = lbl_x-($XAXIS_MIN)               ! current size for right align
         let lbl_r_max1 = lbl_max_chars * lbl_r_sz/lbl_max_len ! max chars for right align
         let lbl_r_max  = INT(lbl_r_max1)                  !          "
         IF `lbl_len LE lbl_r_max` THEN              ! if it fits inside the plot
            let align              =  1              ! then align right (1)
            define symbol lbl_txt  = ($lbl_t)        ! use full string
         ELSE                                        ! full text will not fit..trim it
            IF ($do_label) THEN                      ! if point is inside plot area
               IF `(lbl_skip_trimmed) EQ 0` THEN     ! if trimming is allowed
                   define symbol do_label = yes      !  ok ..do it
               ELSE                                  ! if trimming is not allowed
                   define symbol do_label = no       !  don't do the labelling
               ENDIF
            ENDIF
            let lbl_big = MAX(lbl_l_max,lbl_r_max)   ! more space is to left or right?
            IF `lbl_big EQ lbl_l_max` THEN           ! ok..to the left
               let align              = -1           !    then align left(-1)
            ELIF `lbl_big EQ lbl_r_max` THEN         ! no..it is to right
               let align              =  1           !    then align right(1)
            ENDIF
            let lbl_str = SUBSTRING("($lbl_t)",1,`lbl_big-lbl_xclip`) ! trim it to fit inside
            define symbol lbl_txt  = `lbl_str`       ! use the trimmed string to label
         ENDIF       
     ENDIF

! check the color argument

     let lbl_cl_len = STRLEN("`lbl_cl`")      ! wether color is between 1-9 or 10-19
     IF   `lbl_cl_len EQ 1` THEN              ! if it is between 1 and 9
          define symbol lbl_col = 0`lbl_cl`   ! put one "0" before it
     ELIF `lbl_cl_len EQ 2` THEN              ! if it is between 10 and 19
          define symbol lbl_col = `lbl_cl`    ! take it "as is"
     ELSE                                     ! we have only 19 colors !!!!
          say "#### Error in Argument Passed to label_inside.jnl ."
          say "5th Argument color should be between 1 & 19"
          EXIT
     ENDIF

! if it passed all the tests, then do it 

     IF ($do_label) THEN        
        label `lbl_x`, `lbl_y`, `align`, 0, `lbl_sz`, @c0($lbl_col)@($lbl_stl)($lbl_txt)
     ENDIF

! cancel variables/symbols declared within label_inside.jnl

    cancel var    lbl_*
    cancel symbol lbl_*


[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement