pro spd_ui_draw_object::addLegend,view,annotation,panelInfo,traceInfoArray
compile_opt idl2,hidden
if ptr_valid(panelInfo.legendInfo) then legendobj = *panelInfo.legendInfo
if obj_valid(legendobj) then begin
legendobj->getProperty, size=textsize, font=textfont, format=textformat, color=textcolor, $
vspacing=spacing, bgcolor=legendbgcolor, framethickness=framethickness, bordercolor=bordercolor, $
enabled=enabled, bottom=lbottom, left=lleft, width=lwidth, height=lheight, bValue=bValue, $
lValue=lValue, wValue=wValue, hValue=hValue, bUnit=bUnit, lUnit=lUnit, wUnit=wUnit, hUnit=hUnut, $
xAxisValue=xAxisValue, xAxisValEnabled=xAxisValEnabled, yAxisValue=yAxisValue, yAxisValEnabled=yAxisValEnabled, $
traces=traces, customtracesset=customtracesset
endif else begin
textsize = 12
textfont = 2
textformat = -1
spacing = 2.
legendbgcolor = [255,255,255]
framethickness = 1
bordercolor = [0,0,0]
endelse
if (enabled eq 0) then begin
hide_val=1
showtext=0
endif else begin
hide_val=0
showtext=1
endelse
zstack = .6
numBias = 10
timeBias = 17
extraBias = 3
nchars = 0
if(xAxisValEnabled eq 1 and yAxisValEnabled eq 1) then nLines = 2+n_elements(traceInfoArray) else $
if(xAxisValEnabled eq 1 or yAxisValEnabled eq 1) then nLines = 1+n_elements(traceInfoArray) else $
if(xAxisValEnabled eq 0 and yAxisValEnabled eq 0) then nLines = n_elements(traceInfoArray)
if panelInfo.xIsTime then begin
bias = timeBias
legendObj->axisIsTime, 'X'
endif else begin
bias = numBias
endelse
text = xAxisValue
bias += extraBias
nChars = nChars > (strlen(text)+bias)
text = yAxisValue
if panelInfo.yIsTime then begin
bias = timeBias
legendObj->axisIsTime, 'Y'
endif else begin
bias = numBias
endelse
bias += extraBias
nChars = nChars > (strlen(text)+bias)
if panelInfo.hasSpec then begin
if panelInfo.zisTime then begin
bias = timeBias
legendObj->axisIsTime, 'Z'
endif else begin
bias = numBias
endelse
bias+= extraBias
endif else begin
if panelInfo.yistime then begin
bias = timeBias
endif else begin
bias = numBias
endelse
bias+= extraBias
endelse
for i = 0,n_elements(traceInfoArray)-1 do begin
nChars = nChars > (strlen(traceInfoArray[i].dataName)+bias)
endfor
xdiv = panelInfo.xplotpos[1]-panelInfo.xplotpos[0]
ydiv = panelInfo.yplotpos[1]-panelInfo.yplotpos[0]
width = self->pt2norm(textsize * nchars/2 + 2*spacing,0)/xdiv
height = self->pt2norm(nlines * textsize + (nlines+1)*spacing,1)/ydiv
if obj_valid(legendObj) then legendObj->getProperty, bottom=legendbottom, left=legendleft, width=legendwidth, height=legendheight
view->getProperty,viewPlane_rect=vpr
if legendleft ne 1 then begin
if width/2D gt vpr[2]+vpr[0]-1D then begin
wbias = width/2D - (vpr[2]+vpr[0]-1D)
endif else begin
wbias = 0D
endelse
wbias += self->pt2norm(2.,0)/xdiv
endif else wbias = 0.
if legendbottom ne 1 then begin
if height/2D gt vpr[3]+vpr[1]-1D then begin
hbias = height/2D - (vpr[3]+vpr[1]-1D)
endif else begin
hbias = 0D
endelse
hbias += self->pt2norm(2.,1)/ydiv
endif else hbias = 0.
if (legendbottom eq 1) then begin
legendObj->getProperty, bValue=bValue, bUnit=bUnit
userBottom = legendObj->ConvertUnit(bValue, bUnit, 0)
userBottom = self->pt2norm(userBottom,1)/ydiv
endif else begin
userBottom = 1.-height/2.
legendObj->setProperty, bValue=self->norm2pt(userBottom,1)*ydiv
endelse
if (legendleft eq 1) then begin
legendObj->getProperty, lValue=lValue, lUnit=lUnit
userLeft = legendObj->ConvertUnit(lValue, lUnit, 0)
userLeft = self->pt2norm(userLeft,0)/xdiv
endif else begin
userLeft = (1.-width/2.)
legendObj->setProperty, lValue=self->norm2pt(userLeft,0)*xdiv
endelse
if (legendwidth eq 1) then begin
legendObj->getProperty, wValue=wValue, wUnit=wUnit
userWidth = legendObj->ConvertUnit(wValue, wUnit, 0)
userWidth = self->pt2norm(userWidth,0)/xdiv
endif else begin
userWidth = width
legendObj->setProperty, wValue=self->norm2pt(userWidth,0)*xdiv
endelse
if (legendheight eq 1) then begin
legendObj->getProperty, hValue=hValue, hUnit=hUnit
userHeight = legendObj->ConvertUnit(hValue, hUnit, 0)
userHeight = self->pt2norm(userHeight,1)/ydiv
endif else begin
userHeight = height
legendObj->setProperty, hValue=self->norm2pt(userHeight,1)*ydiv
endelse
if obj_valid(legendObj) then legendObj->getProperty, xAxisValEnabled=xAxisValEnabled, yAxisValEnabled=yAxisValEnabled
if (~undefined(xAxisValEnabled) and xAxisValEnabled eq 0) then begin
shiftpolygon = self->pt2norm(1*textsize+(1+1)*spacing,1)/ydiv
endif else shiftpolygon = 0
if (~undefined(yAxisValEnabled) and yAxisValEnabled eq 0) then begin
shiftpolyline = self->pt2norm(1*textsize+(1+1)*spacing,1)/ydiv
endif else shiftpolyline = 0
if (xAxisValEnabled eq 1 and yAxisValEnabled eq 0) then shiftpolygon = shiftpolygon+self->pt2norm(1*textsize+(2)*spacing,1)/ydiv
if (yAxisValEnabled eq 1 and xAxisValEnabled eq 0) then shiftpolyline = shiftpolyline+self->pt2norm(1*textsize+(2)*spacing,1)/ydiv
model = obj_new('IDLgrModel',hide=hide_val)
anno_model = obj_new('IDLgrModel',hide=hide_val)
polygon = obj_new('IDLgrPolygon',$
[userLeft,userLeft+userWidth,userLeft+userWidth,userLeft]-wbias,$
[userBottom,userBottom,userBottom+userHeight,userBottom+userHeight]+shiftpolyline-shiftpolygon-hbias,$
[zstack,zstack,zstack,zstack],color=self->convertColor(legendbgcolor),/double,hide=hide_val)
polyline = obj_new('IDLgrPolyline',$
[userLeft,userLeft+userWidth,userLeft+userWidth,userLeft,userLeft]-wbias,$
[userBottom,userBottom,userBottom+userHeight,userBottom+userHeight,userBottom]+shiftpolyline-shiftpolygon-hbias,$
[zstack,zstack,zstack,zstack,zstack]+.00001,color=self->convertColor(bordercolor),/double,thick=framethickness,hide=hide_val)
model->add,polyline
model->add,polygon
xspaceNorm = self->pt2norm(spacing,0)/xdiv
yspaceNorm = self->pt2norm(spacing,1)/ydiv
xcharNorm = self->pt2norm(textsize,0)/xdiv
ycharNorm = self->pt2norm(textsize,1)/ydiv
labelLocation=[userLeft + xspacenorm - wbias,userBottom+userHeight - yspacenorm - ycharnorm - hbias,zstack+.05]
valueLocation=[userLeft+userWidth - xspacenorm - wbias,userBottom+userheight - yspacenorm - ycharnorm - hbias,zstack+.05]
text = xAxisValue
text += ' :'
if(xAxisValEnabled eq 1) then begin
thm_label = obj_new('spd_ui_text',value=text,size=textsize,font=textfont,format=textformat,color=textcolor,show=showtext)
xlabel = self->getTextObject(thm_label,labelLocation,1,0,justify=-1)
model->add,xlabel
thm_value = obj_new('spd_ui_text',value='',size=textsize,font=textfont,format=textformat,color=textcolor,show=showtext)
xvalue = self->getTextObject(thm_value,valueLocation,1,0,justify=1,/enable_formatting)
panelInfo.xobj = xvalue
anno_model->add,xvalue
labelLocation[1] -= (yspacenorm+ycharnorm)
valueLocation[1] -= (yspacenorm+ycharnorm)
endif
text = yAxisValue
text += ' :'
if(yAxisValEnabled eq 1) then begin
thm_label = obj_new('spd_ui_text',value=text,size=textsize,font=textfont,format=textformat,color=textcolor,show=showtext)
ylabel = self->getTextObject(thm_label,labelLocation,1,0,justify=-1)
model->add,ylabel
thm_value = obj_new('spd_ui_text',value='',size=textsize,font=textfont,format=textformat,color=textcolor,show=showtext)
yvalue = self->getTextObject(thm_value,valueLocation,1,0,justify=1,/enable_formatting)
panelInfo.yobj = yvalue
anno_model->add,yvalue
labelLocation[1] -= (yspacenorm+ycharnorm)
valueLocation[1] -= (yspacenorm+ycharnorm)
endif
if ptr_valid(traces) then tracesstruct = *traces
if ~undefined(tracesstruct) then listoftraces=reverse(tracesstruct.traceNames)
for i = n_elements(traceInfoArray)-1,0,-1 do begin
if (customtracesset eq 1 && ~undefined(listoftraces)) then begin
text = listoftraces[i] + ' :'
endif else begin
text = traceInfoArray[i].dataName + ' :'
endelse
c = traceInfoArray[i].color
color_convert, c[0],c[1],c[2],h,l,s, /rgb_hls
threshold = 0.90 - 0.12 * ( 1 - (h/70.-60/70.)^2 > 0 )
color = l le threshold ? traceInfoArray[i].color : [0,0,0]
thm_label = obj_new('spd_ui_text',value=text,size=textsize,font=textfont,color=color,format=textformat,show=showtext)
olabel = self->getTextObject(thm_label,labelLocation,1,0,justify=-1)
model->add,olabel
thm_value = obj_new('spd_ui_text',value='',size=textsize,font=textfont,color=color,format=textformat,show=showtext)
ovalue = self->getTextObject(thm_value,valueLocation,1,0,justify=1,/enable_formatting)
traceInfoArray[i].textobj = ovalue
anno_model->add,ovalue
labelLocation[1] -= (yspacenorm+ycharnorm)
valueLocation[1] -= (yspacenorm+ycharnorm)
endfor
panelInfo.legendModel = model
panelInfo.legendAnnoModel = anno_model
view->add,model
annotation->add,anno_model
end