! Example with custom markers.
! Author: Francois Tonneau

size 12 7

set font ss join round lwidth 0.03 hei 0.30

! We define a scaling factor to make the size of custom markers comparable to
! the standard size, which is about equal to character height (0.7 times 1).

custom_marker_scaling = 0.7

! GLE lets us define markers in terms of custom subroutines that accept two
! parameters. When called with the 'msize' option, the first parameter will
! determine marker size. When called with the 'mdata dk' option, the second
! parameter will determine a marker property of our choice (say, a rotation
! angle) based on the values from dataset dk. Inside the subroutine, we put
! graphical commands to draw the marker we want.

! Here we define three subroutines to draw custom markers. We employ only one
! parameter (the one related to marker size), but we need to declare two, so
! we put 'datum' as an empty placeholder (any other name would do). The color
! drawn in each subroutine is that of the marker fill; edge color will be
! determined at run time by the line color used when plotting a dataset.

sub draw_blue_circle weight datum
    local radius = custom_marker_scaling * weight/2
    circle radius fill cadetblue
end sub

sub draw_beige_square weight datum
    local width = custom_marker_scaling * weight
    box width width justify cc fill goldenrod
end sub

sub draw_red_triangle weight datum
    local width = custom_marker_scaling * weight
    rmove -width/2 width/3
    begin path stroke fill tomato
        rline  width    0
        rline -width/2 -width
        closepath
    end path
end sub

! We define markers in terms of our subroutines:

define marker blue_circle  draw_blue_circle
define marker beige_square draw_beige_square
define marker red_triangle draw_red_triangle

! These markers can now be used to plot data:

amove 2 1.5
begin graph
    size 5 5
    fullsize
    xaxis min 0 max 4.5 ftick 0 dticks 1
    yaxis min 0 max 80 ftick 0 dticks 20
    subticks off
    side lwidth 0.02
    labels dist 0.2
    xtitle "Pellets per min" dist 0.3 color black
    ytitle "Lever presses per min" dist 0.3 color black

    data "markers.dat"

    d1 line color #004e58 marker fcircle      msize 0.25
    d2 line color #004e58 marker blue_circle  msize 0.25
    d3 line color brown   marker beige_square msize 0.22
    d4 line color brown   marker red_triangle msize 0.28
end graph

! We end with the legend, using an empty text as fake row to provide vertical
! spacing -- another useful trick.

amove 7.45 5.0
write "Group:"

begin key
    absolute 7.2 2.5 nobox compact llen 1.0
    line color #004e58 marker fcircle      msize 0.25 text "Normals"
    line color #004e58 marker blue_circle  msize 0.25 text "Sham-lesioned"
    text
    line color brown   marker beige_square msize 0.22 text "Non-obese VMH"
    line color brown   marker red_triangle msize 0.28 text "Obese VMH"
end key

! Done. We have learned how to define markers in terms of subroutines.

