Create legend for plot data
FIXME: Text sizing should be modifiable
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | corner | Corner for legend |
||
character(len=*), | intent(in), | dimension(:,:) | :: | series | Data series in rows [name,textColor,lineStyle,lineColor,markStyle,markColor,boxColor] |
|
real(kind=wp), | intent(in), | optional | dimension(:) | :: | lineWidths | Line widths for the plots |
real(kind=wp), | intent(in), | optional | dimension(:) | :: | markScales | Marker sizes for the plots |
integer, | intent(in), | optional | dimension(:) | :: | markCounts | Marker counts for the plots |
integer, | intent(in), | optional | :: | ncol | Number of columns |
subroutine legend(corner,series,lineWidths,markScales,markCounts,ncol)
!! Create legend for plot data
!!
!! FIXME: Text sizing should be modifiable
character(*),intent(in)::corner
!! Corner for legend
character(*),dimension(:,:),intent(in)::series
!! Data series in rows
!! [name,textColor,lineStyle,lineColor,markStyle,markColor,boxColor]
real(wp),dimension(:),intent(in),optional::lineWidths
!! Line widths for the plots
real(wp),dimension(:),intent(in),optional::markScales
!! Marker sizes for the plots
integer,dimension(:),intent(in),optional::markCounts
!! Marker counts for the plots
integer,intent(in),optional::ncol
!! Number of columns
real(pp)::width,height,xoff,yoff
real(pp)::plotWidth
integer::opt,cornerl
integer::bg_color,bb_color,bb_style,lncol,lnrow
integer,dimension(size(series,1))::opts
real(pp),dimension(size(series,1))::lwidths,mscales
integer,dimension(size(series,1))::mcounts,text_colors
real(pp)::text_offset,text_scale,text_spacing,text_justification
integer,dimension(size(series,1))::box_colors,box_patterns
real(pp),dimension(size(series,1))::box_scales,box_line_widths
integer,dimension(size(series,1))::line_colors,line_styles
integer,dimension(size(series,1))::mark_colors
character(64),dimension(size(series,1))::mark_styles
integer::k
call doLegendBox()
opts = 0
do k=1,size(series,1)
if(series(k,3)/='') opts(k) = ior(opts(k),PL_LEGEND_LINE)
if(series(k,5)/='') opts(k) = ior(opts(k),PL_LEGEND_SYMBOL)
if(series(k,7)/='') opts(k) = ior(opts(k),PL_LEGEND_COLOR_BOX)
end do
call doText()
call doBoxes()
call doLines()
call doMarkers()
call pllegend(width,height,opt,cornerl,xoff,yoff,plotWidth, &
& bg_color,bb_color,bb_style, &
& lnrow,lncol,size(series,1),opts,text_offset, &
& text_scale,text_spacing,text_justification,text_colors,series(:,1), &
& box_colors,box_patterns,box_scales,box_line_widths, &
& line_colors,line_styles,lwidths, &
& mark_colors,mscales,mcounts,mark_styles)
contains
subroutine doLegendBox
opt = PL_LEGEND_BACKGROUND+PL_LEGEND_BOUNDING_BOX
cornerl = getCorner(corner)
xoff = 0.0_pp
yoff = 0.0_pp
plotWidth = 0.05_pp
bg_color = 0
bb_color = 1
bb_style = getLineStyleCode('-')
lncol = 1
if(present(ncol)) lncol = ncol
lnrow = size(series,1)/lncol
end subroutine doLegendBox
subroutine doText
text_offset = 0.3_pp
text_scale = fontScale
text_spacing = 3.0_pp
text_justification = 0.0_pp
do k=1,size(series,1)
text_colors = getColorCode(series(k,2))
end do
end subroutine doText
subroutine doBoxes
do k=1,size(series,1)
box_colors(k) = getColorCode(series(k,7))
end do
box_patterns = 0
box_scales = 0.5_pp
box_line_widths = 0.0_pp
end subroutine doBoxes
subroutine doLines
lwidths = 1.0_pp
if(present(lineWidths)) lwidths = real(lineWidths,pp)
do k=1,size(series,1)
line_colors(k) = getColorCode(series(k,4))
line_styles(k) = getLineStyleCode(series(k,3))
end do
end subroutine doLines
subroutine doMarkers
mcounts = 2
if(present(markCounts)) mcounts = markCounts
mscales = 1.0_pp
if(present(markScales)) mscales = real(markScales,pp)
do k=1,size(series,1)
mark_colors(k) = getColorCode(series(k,6))
mark_styles(k) = getSymbolCode(series(k,5))
end do
end subroutine doMarkers
function getCorner(text) result(code)
character(*),intent(in)::text
integer::code
code = PL_POSITION_INSIDE
if( startsWith(text,'upper') ) code = code+PL_POSITION_TOP
if( startsWith(text,'lower') ) code = code+PL_POSITION_BOTTOM
if( endsWith(text,'right') ) code = code+PL_POSITION_RIGHT
if( endsWith(text,'left' ) ) code = code+PL_POSITION_LEFT
end function getCorner
end subroutine legend