pro spd_ui_draw_object::addVariables, $
view, $
annotation,$
vars, $
panelInfo, $
loadedData, $
xMajors,$
xAxis,$
labelPos,$
labelMargin,$
varptr=varptr
compile_opt idl2,hidden
zstack = .1
tolerance = 1.0
xpanelConv = panelInfo.xplotpos[1] - panelInfo.xplotpos[0]
ypanelConv = panelInfo.yplotpos[1] - panelInfo.yplotpos[0]
spacing = self->pt2norm(2,1)/ypanelConv
validmask = intarr(n_elements(vars))
linedim = self->getPlotSize(panelInfo.xplotpos,panelInfo.yplotpos,self.lineres)
xpx = linedim[0]
model = obj_new('IDLgrModel')
anno_model = obj_new('IDLgrModel')
xAxis->getProperty, $
tickStyle=tickStyle,$
bottomPlacement=bottomPlacement,$
majorLength=majorLength,$
minorLength=minorLength,$
annotateAxis=annotateAxis,$
placeAnnotation=placeAnnotation,$
margin=margin,$
scaling=xscaling,$
annotateRangeMin=annotateRangeMin,$
annotateRangeMax=annotateRangeMax,$
annotateTextObject=annotateTextObject,$
annotateExponent=annotateExponent,$
showDate=showDate
if n_elements(xMajors) eq 0 then begin
noXMajors = 1
endif else begin
xAxisMajors = xMajors
endelse
if ~annotateRangeMin then begin
if n_elements(xAxisMajors) gt 1 then begin
xAxisMajors = xAxisMajors[1:n_elements(xAxisMajors)-1]
endif else begin
noXMajors = 1
endelse
endif
if ~annotateRangeMax then begin
if n_elements(xAxisMajors) gt 1 then begin
xAxisMajors = xAxisMajors[0:n_elements(xAxisMajors)-2]
endif else begin
noXMajors = 1
endelse
endif
if bottomPlacement && (tickStyle eq 1 || tickStyle eq 2) then begin
tickLoc = self->pt2norm(majorLength > minorLength,1)/ypanelConv
endif else begin
tickLoc = 0
endelse
if annotateAxis && ~placeAnnotation && obj_valid(annotateTextObject) then begin
labelLoc = abs(labelPos)
annotateTextObject->getProperty,size=size
annoLoc = tickLoc + self->pt2norm(size,1)/ypanelConv
endif else begin
annoLoc = tickLoc
labelLoc = 0
endelse
if showDate && ~placeAnnotation && obj_valid(annotateTextObject) then begin
annotateTextObject->getProperty,size=size
dateLoc = tickLoc + 2*self->pt2norm(size,1)/ypanelConv
endif else begin
dateLoc = tickLoc
endelse
yloc = 0. - max([labelloc,annoloc,dateLoc])
varInfoArray = *panelInfo.varInfo
for i = 0,n_elements(vars)-1 do begin
vars[i]->getProperty, $
fieldname=fieldname,$
controlname=controlname,$
text=text,$
format=format,$
minRange=minRange,$
maxRange=maxRange,$
scaling=vscaling,$
useRange=useRange,$
annotateExponent=annotateExponent
text->getProperty,size=size,show=show
if ~show then continue
yloc -= (spacing + self->pt2norm(size,1)/ypanelConv)
xloc = 0. - self->pt2norm(labelMargin,0)/xpanelConv
textObj = self->getTextObject(text,[xloc,yloc,zstack],1,0,justify=1,/enable_formatting)
model->add,textObj
if keyword_set(fieldname) && loadedData->isChild(fieldname) then begin
loadedData->getVarData,name=fieldname,data=yd,isTime=isTime,/duplicate
varInfoArray[i].dataY = yd
varInfoArray[i].isTime = isTime
endif else begin
continue
endelse
if keyword_set(controlname) && loadedData->isChild(controlname) then begin
loadedData->getVarData,name=controlname,data=xd,/duplicate
xrange = [min(*xd,/nan),max(*xd,/nan)]
endif else begin
xd2 = ptr_new(dindgen(n_elements(*yd[0]))/(n_elements(*yd[0])-1))
varInfoArray[i].dataX = xd2
xrange = [0D,1D]
endelse
if userange eq 2 then begin
if panelInfo.locked then begin
xrange = panelInfo.lockedRange
xscaling = panelInfo.lockedScale
endif else begin
xrange = panelInfo.xrange
xscaling = panelInfo.xscale
endelse
vars[i]->setProperty,minrange=xrange[0],maxrange=xrange[1]
endif else if userange eq 1 then begin
xrange = [minRange,maxRange]
xscaling = vscaling
endif
varInfoArray[i].annotateStyle = format
varInfoArray[i].scaling = xscaling
varInfoArray[i].range = xrange
if ptr_valid(xd) then begin
self->xclip,xd,yd,ptr_new(),xrange,xscaling,fail=fail
if fail then begin
self.statusBar->update,'Error: Could not process variable control'
self.historyWin->update,'Error: Could not process variable control'
continue
endif
xdata = (temporary(*xd[0])-xrange[0])/(xrange[1]-xrange[0])
ydata = temporary(*yd[0])
self->makeLineReference,xdata,ydata,xpx,ref=refvar
varInfoArray[i].dataY = ptr_new(temporary(refvar))
endif else begin
xdata = dindgen(n_elements(ydata))/n_elements(ydata)
ydata = temporary(*yd)
self->makeLineReference,xdata,ydata,xpx,ref=refvar
varInfoArray[i].dataY = ptr_new(temporary(refvar))
endelse
textTemp = text->copy()
textTemp->setProperty,value=''
xloc = 1. + self->pt2norm(labelMargin,0)/xpanelconv
textObj = self->getTextObject(textTemp,[xloc,yloc,zstack],1,0,justify=-1,/enable_formatting)
varInfoArray[i].textObj = textObj
anno_model->add,textObj
annotatedata = {timeAxis:isTime,formatid:format,scaling:0,exponent:annotateExponent}
if ~keyword_set(noXMajors) then begin
annotateValues = dblarr(n_elements(xAxisMajors))
annotateAutoExponent=1
for j = 0,n_elements(xAxisMajors)-1 do begin
temp = min(abs(xdata - xAxisMajors[j]),idx,/nan)
if temp lt tolerance then begin
annotateValues[j] = ydata[idx]
endif else begin
annotateValues[j] = !VALUES.D_NAN
endelse
spd_ui_usingexponent,annotateValues[j],annotatedata,type=type
if type ne 0 then begin
annotateAutoExponent=2
endif
endfor
if annotateExponent eq 0 then begin
annotateData.exponent=annotateAutoExponent
endif
for j = 0,n_elements(xAxisMajors)-1 do begin
valueString = formatannotation(0,0,annotatevalues[j],data=annotatedata)
textTemp = text->copy()
textTemp->setProperty,value=valuestring
textObj = self->getTextObject(textTemp,[xAxisMajors[j],yloc,zstack],1,0,/enable_formatting)
model->add,textObj
endfor
endif
validmask[i] = 1
endfor
idx = where(validmask,c)
if c gt 0 then begin
varptr=ptr_new(varInfoArray[idx])
view->add,model
annotation->add,anno_model
endif else begin
varptr=ptr_new()
endelse
end