pro spd_ui_draw_object::makeXYAxisModel, $
dir,$
xrange,$
yrange,$
scaling,$
axisSettings,$
plotDim1,$
plotdim2,$
color,$
thick,$
bgcolor,$
useIstime=useIsTime,$
gridmodel=gridmodel,$
model=model,$
majors=majorTickValues,$
minorNum=numMinorTicks,$
isTimeAxis=isTimeAxis,$
labelPos=labelPos,$
fail=fail
compile_opt idl2,hidden
fail = 1
noMajor = 0
noMinor = 0
numMinorTicks = 0
annotateEdgeMargin = .01
gridEdgeMargin = .01
axisSettings->getProperty,$
annotateOrientation=annotateOrientation,$
placeAnnotation=placeAnnotation,$
annotateAxis=annotateAxis,$
isTimeAxis=isTimeAxis,$
annotateMajorTicks=annotateMajorTicks,$
annotateRangeMin=annotateRangeMin,$
annotateRangeMax=annotateRangeMax,$
annotateStyle=annotateStyle,$
annotateTextObject=annotateTextObject,$
annotateExponent=annotateExponent,$
majorTickAuto=majorTickAuto,$
minorTickAuto=minorTickAuto,$
firstTickAuto=firstTickAuto,$
majorLength=majorLength,$
minorLength=minorLength,$
bottomPlacement=bottomPlacement,$
topPlacement=topPlacement,$
tickStyle=tickStyle,$
numMajorTicks=numMajorTicks,$
numMinorTicks=numMinorTicks,$
lineAtZero=lineAtZero,$
majorGrid=majorGrid,$
minorGrid=minorGrid,$
margin=margin,$
showLabels=showLabels,$
labels=labels,$
orientation=orientation,$
stackLabels=stackLabels,$
placeLabel=placeLabel,$
lazylabels=lazylabels, $
titleobj=titleobj, $
subtitleobj=subtitleobj, $
titleorientation=titleorientation, $
placetitle=placetitle, $
titlemargin=titlemargin, $
showtitle=showtitle, $
lazytitles=lazytitles, $
autoTicks=autoTicks,$
logMinorTickType=logMinorTickType
if n_elements(useIsTime) gt 0 && useIsTime ge 0 then begin
isTimeAxis = useIsTime
endif
xrange = double(xrange)
yrange = double(yrange)
plotdim1 = double(plotdim1)
roundingfactor = 1d-15
axiszstack = .25D
gridzstack = .07D
linezstack = .08D
AnnotationDepth = .05D
tickSpacing = axisSettings->getTickSpacing()
location1 = [0.,0.,axiszstack]
if dir eq 0 then begin
range = xrange
location2 = [0.,1.,axiszstack]
tickconversion = 1./(plotdim1[1]-plotdim1[0])
endif else begin
range=yrange
location2 = [1.,0.,axiszstack]
tickconversion = 1./(plotdim1[1]-plotdim1[0])
endelse
majTicklen = self->pt2norm(majorLength,~dir)*tickConversion
minTicklen = self->pt2norm(minorLength,~dir)*tickConversion
model = obj_new('IDLgrModel')
gridmodel = obj_new('IDLgrModel')
tickNum = -1
if ~finite(range[1]) || ~finite(range[0]) then begin
range = [0D,1D]
endif
self->placeMajorTicks,$
isTimeAxis,$
range,$
scaling,$
majorTickAuto,$
autoticks,$
numMajorTicks,$
tickSpacing[0],$
tickSpacing[1],$
majorTickValues=majorTickValues,$
majorTickInterval=tickSpacingMajor,$
minorTickNum=minorTickNumRecommended,$
logMinorTickType=logMinorTickType,$
ticksFixed=ticksFixed,$
fail=placefail
if placefail then begin
nomajor = 1
nominor = 1
endif
numMajorTicks = n_elements(majorTickValues)
if n_elements(minorTickNumRecommended) gt 0 && $
keyword_set(autoTicks) && $
minorTickNumRecommended ge 0 then begin
numMinorTicks = minorTickNumRecommended
endif
if (numMinorTicks + 1) le 0 then begin
ok = error_message('ERROR: The current settings will result in the creation of less than or equal to 0 minor ticks. Draw Operation Failed',/center)
nomajor = 1
nominor = 1
endif
if ~nomajor && ~nominor then begin
tickSpacingMinor = tickSpacingMajor/(numMinorTicks+1)
endif
if numMinorTicks eq 0 || nominor eq 1 then begin
noMinor = 1
endif else begin
majorTickValuesForMinors = majorTickValues[bsort(majorTickValues)]
if numMajorTicks gt 2 then begin
if majorTickValuesForMinors[1] - majorTickValuesForMinors[0] lt tickSpacingMajor then begin
majorTickValuesForMinors[0] = majorTickValuesForMinors[1] - tickSpacingMajor
endif
if numMajorTicks gt 2 && majorTickValuesForMinors[numMajorTicks-1] - majorTickValuesForMinors[numMajorTicks-2] lt tickSpacingMajor then begin
majorTickValuesForMinors[numMajorTicks-1] = majorTickValuesForMinors[numMajorTicks-2] + tickSpacingMajor
endif
majorTickValuesForMinors = [majorTickValuesForMinors[0] - tickSpacingMajor,majorTickValuesForMinors,majorTickValuesForMinors[n_elements(majorTickValuesForMinors)-1]+tickSpacingMajor]
endif
self->makeMinorTicks,range,scaling,numMinorTicks,majorTickValuesForMinors,tickSpacingMajor,logMinorTickType,minorValues=minorTickValues,fail=fail
if fail then begin
nominor = 1
endif
endelse
if (n_elements(majorTickValues) gt self.maxTickNum || n_elements(minorTickValues) gt self.maxTickNum*2) && (noMinor eq 0 && noMajor eq 0) then begin
ok = error_message('ERROR: The current settings will result in the creation of ' + strcompress(string(n_elements(majorTickValues)),/remove_all) + ' major ticks and ' + strcompress(string(n_elements(minorTickValues)),/remove_all) + ' minor ticks. Draw operation failed.',/center)
nomajor = 1
nominor = 1
endif
if topPlacement then topTickLen = majTickLen else topTickLen = 0.
if bottomPlacement then bottomTickLen = majTickLen else bottomTickLen = 0.
if ~noMajor then begin
if tickStyle eq 1 || tickStyle eq 2 then begin
majorAxis1 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location1,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
tickLen = bottomTickLen, $
tickDir=1,$
minor=0,$
subticklen=0.0,$
major=tickNum,$
tickValues=majorTickValues)
majorAxis2 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location2,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
tickLen = topTickLen, $
tickDir=0,$
minor=0,$
subticklen=0.0,$
major=ticknum,$
tickValues=majorTickValues)
model->add,majorAxis1
model->add,majorAxis2
endif
if tickStyle eq 0 || tickStyle eq 2 then begin
majorAxis1 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location1,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
tickLen = bottomTickLen, $
tickDir=0,$
minor=0, $
subticklen=0.0,$
major=ticknum,$
tickValues=majorTickValues)
majorAxis2 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location2,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
tickLen = topTickLen, $
tickDir=1,$
minor=0,$
subticklen=0.0,$
major=ticknum,$
tickValues=majorTickValues)
model->add,majorAxis1
model->add,majorAxis2
endif
endif else begin
majorAxis1 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location1,$
color=self->convertColor(color),$
thick=thick,$
subticklen=0.0,$
/exact,$
/notext,$
minor=0,$
major=0)
majorAxis2 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location2,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
subticklen=0.0,$
minor=0,$
major=0)
model->add,majorAxis1
model->add,majorAxis2
endelse
if topPlacement then topTickLen = minTickLen else topTickLen = 0.
if bottomPlacement then bottomTickLen = minTickLen else bottomTickLen = 0.
if ~noMinor then begin
if tickStyle eq 1 || tickStyle eq 2 then begin
minorAxis1 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location1,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
tickLen = bottomTickLen, $
tickDir=1,$
minor=0,$
subticklen=0.0,$
major=ticknum,$
tickValues=minorTickValues)
minorAxis2 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location2,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
tickLen = topTickLen, $
tickDir=0,$
minor=0,$
subticklen=0.0,$
major=ticknum,$
tickValues=minorTickValues)
model->add,minorAxis1
model->add,minorAxis2
endif
if tickStyle eq 0 || tickStyle eq 2 then begin
minorAxis1 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location1,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
tickLen = bottomTickLen, $
tickDir=0,$
minor=0, $
subticklen=0.0,$
major=ticknum,$
tickValues=minorTickValues,$
log=log)
minorAxis2 = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=location2,$
color=self->convertColor(color),$
thick=thick,$
/exact,$
/notext,$
tickLen = topTickLen, $
tickDir=1,$
minor=0,$
subticklen=0.0,$
major=ticknum,$
tickValues=minorTickValues)
model->add,minorAxis1
model->add,minorAxis2
endif
endif
if annotateAxis then begin
noAnno = 0
if range[1] eq range[0] && ~annotateMajorTicks then begin
self.statusBar->update,'Max and Min range are the same: Annotating major ticks.'
self.historyWin->update,'Max and Min range are the same: Annotating major ticks.'
annotateMajorTicks=1
endif
if annotateMajorTicks then begin
if ~noMajor then begin
majorAxis1->getProperty,tickValues=annotateValues
endif else begin
noAnno = 1
annotateValues = [0,1]
self.historyWin->update,'Cannot annotate major ticks, because no major ticks being drawn'
endelse
endif else begin
if tickSpacing[3] gt range[1] then begin
self.statusBar->update,'"Align Annotations At:" is larger than maximum range. No annotations will be drawn.'
self.historyWin->update,'"Align Annotations At:" is larger than maximum range. No annotations will be drawn.'
annotateValues = [0,1]
noAnno = 1
endif else if tickSpacing[4] le 0 then begin
self.statusBar->update,'"Annotate Every" is less than 0. No annotations will be drawn.'
self.historyWin->update,'"Annotate Every" is less than 0. No annotations will be drawn.'
annotateValues = [0,1]
noAnno = 1
endif else if tickSpacing[4] gt (range[1]-range[0]) then begin
self.statusBar->update,'"Annotate Every" is greater than range span. No annotations will be drawn.'
self.historyWin->update,'"Annotate Every" is greater than range span. No annotations will be drawn.'
annotateValues = [0,1]
noAnno = 1
endif else begin
annotateStart = tickSpacing[3]
annotateInterval = tickSpacing[4]
if annotateStart lt range[0] then begin
annotateStartNum = floor((range[0] - annotateStart) / annotateInterval,/l64)
annotateStart += annotateStartNum*annotateInterval
endif else begin
annotateStartNum = floor((annotateStart - range[0]) / annotateInterval,/l64) + 1
annotateStart -= annotateStartNum*annotateInterval
endelse
annotateNum = floor((range[1] - annotateStart) / annotateInterval,/l64)
annotateStart = (annotateStart - range[0]) / (range[1]-range[0])
annotateInterval = annotateInterval/(range[1]-range[0])
if annotateNum gt self.maxTickNum then begin
self.statusBar->update,'ERROR: The current settings will result in the creation of ' + strcompress(string(annotateNum),/remove_all) + ' annotations. Draw operation failed.'
self.historyWin->update,'ERROR: The current settings will result in the creation of ' + strcompress(string(annotateNum),/remove_all) + ' annotations. Draw operation failed.'
return
endif
annotateValues = dindgen(annotateNum + 2) * annotateInterval + annotateStart
idx = where(annotateValues ge annotateEdgeMargin and annotateValues le (1-annotateEdgeMargin),c)
if c gt 0 then begin
annotateValues = [0,annotateValues[idx],1]
endif else begin
annotateValues = [0,1]
endelse
endelse
endelse
if ~annotateRangeMax && ~noAnno then begin
if n_elements(annotateValues) eq 1 then begin
noAnno = 1
endif else begin
annotateValues = annotateValues[0:n_elements(annotateValues)-2]
endelse
endif
if ~annotateRangeMin && ~noAnno then begin
if n_elements(annotateValues) eq 1 then begin
noAnno = 1
endif else begin
annotateValues = annotateValues[1:*]
endelse
endif
if ~noAnno then begin
if n_elements(annotateValues) gt self.maxTickNum then begin
ok = error_message('ERROR: The current settings will result in the creation of ' + strcompress(string(n_elements(annotateValues)),/remove_all) + ' annotations. Draw operation failed.',/center)
return
endif
data = {timeAxis:isTimeAxis,formatid:AnnotateStyle,scaling:scaling,range:range,exponent:annotateExponent,maxexplen:-1,negexp:0}
if placeAnnotation eq 1 then begin
annoPos = 1
endif else begin
annoPos = 0
endelse
if tickStyle eq 1 || tickStyle eq 2 then begin
AnnoColor = bgcolor
if placeAnnotation eq 1 then begin
AnnoDir = 0
AnnoLoc = location2
AnnoLen = topTickLen
endif else begin
AnnoDir = 1
AnnoLoc = location1
AnnoLen = bottomTickLen
endelse
endif else if tickStyle eq 0 then begin
AnnoColor = color
AnnoLen = 0
if placeAnnotation eq 1 then begin
AnnoDir = 1
AnnoLoc = location2
endif else begin
AnnoDir = 0
AnnoLoc = location1
endelse
endif else begin
self.statusBar->update,'Error: Illegal tickstyle'
return
endelse
if annotateOrientation eq 1 then begin
annoBaseLine = [0,1,0]
annoUpDir = [-1,0,0]
if dir eq 1 then begin
if annoPos eq 0 then begin
annoAlign = [.5,0.]
endif else begin
annoAlign = [.5,1.]
endelse
endif else begin
if AnnoPos eq 0 then begin
annoAlign = [1.,.5]
endif else begin
annoAlign = [0.,.5]
endelse
endelse
endif else begin
annoBaseLine = [1,0,0]
annoUpDir = [0,1,0]
endelse
labFont = annotateTextObject->getGrFont()
annoLoc[2] = AnnotationDepth
annotateTextObject->getProperty,color=labcolor,size=size
if size le 0 then begin
size = 1D
fontshow = 0
endif else begin
fontshow = 1
endelse
labFont->setProperty,size=self->getZoom()*size
if ticksFixed && data.exponent eq 0 then begin
data.exponent = 2
endif else if ~isTimeAxis && data.exponent eq 0 && (scaling eq 0 || scaling eq 1) then begin
for i = 0,n_elements(annotateValues)-1 do begin
if data.range[1]-data.range[0] eq 0 then begin
val = data.range[0]
endif else begin
val = (annotateValues[i] + data.range[0]/(data.range[1]-data.range[0]))*(data.range[1]-data.range[0])
relativecuttoff = (data.range[1]-data.range[0])*roundingfactor
if val le relativecuttoff && val ge -relativecuttoff then begin
val = 0
endif
endelse
if scaling eq 1 then begin
val = 10^val
endif
if scaling ne 0 && data.exponent eq 0 && majorTickAuto && annotateMajorTicks then begin
if scaling eq 1 then begin
data.exponent= 2
endif else begin
data.exponent= 3
endelse
endif else begin
spd_ui_usingexponent,val,data,type=type
if type ne 0 && scaling eq 0 then begin
data.exponent = 2
break
endif else if type ne 0 && scaling eq 1 then begin
data.exponent = 3
break
endif
endelse
endfor
endif
if ~isTimeAxis && data.exponent ne 1 then begin
negexp = 0
maxexplen = 0
for i = 0,n_elements(annotateValues)-1 do begin
axistmp=''
indextmp=''
annotation=formatannotation(axistmp,indextmp,annotateValues[i],data=data)
exppos = strpos(annotation,'!U')
if exppos ne -1 then begin
expstr = strmid(annotation,exppos+2)
explen = strlen(expstr)
if explen gt maxexplen then begin
maxexplen = explen
endif
negstr = strmid(expstr,0,1)
if negstr eq '-' then negexp = 1
endif
endfor
data.maxexplen = maxexplen
data.negexp = negexp
endif
annaxis = OBJ_NEW('IDLgrAxis',dir,$
range=[0D,1D],$
location=AnnoLoc,$
alpha_channel = 1.0,$
thick=thick,$
color=AnnoColor,$
/exact,$
tickLen = AnnoLen, $
tickDir=AnnoDir,$
textPos=AnnoPos,$
minor=0,$
subticklen=0.0,$
major=-1,$
tickValues=annotateValues,$
/use_text_color, $
tickfrmtdata=data,$
tickformat='formatannotation',$
textBaseline=annoBaseLine,$
textupdir=annoUpDir,$
textAlignments=annoAlign)
annaxis->getProperty,tickText=tickObj
tickObj->setProperty,font=labFont,color=self->convertColor(labcolor),alpha_channel=1.0,hide=~fontshow,/enable_formatting
model->add,annaxis
endif
endif
if lineatzero && $
0. gt range[0] && $
0. lt range[1] then begin
if dir eq 0 then begin
locationx = replicate((0-range[0])/(range[1]-range[0]),2)
locationy = [0D,1D]
endif else begin
locationx = [0D,1D]
locationy = replicate((0-range[0])/(range[1]-range[0]),2)
endelse
locationz = [linezstack,linezstack]
line = obj_new('IDLgrPolyline',locationx,locationy,locationz,$
color = self->convertColor([0,0,0]),/double)
model->add,line
endif
majorGridShow = 0
if obj_valid(majorGrid) && obj_isa(majorgrid,'spd_ui_line_style') && ~noMajor then begin
majorGrid->getProperty,id=gridstyle,$
color=gridcolor,$
show=majorgridshow,$
thickness=gridthick,$
opacity=opacity
if majorgridshow && range[1] ne range[0] then begin
tickValues = majorTickValues
normGridThick = self->pt2norm(gridthick,dir)/(2D*(plotDim2[1]-plotDim2[0]))
if n_elements(tickValues) gt 1 then begin
for i = 1,n_elements(tickvalues)-1 do begin
if dir eq 0 then begin
gridx = [tickvalues[i],tickvalues[i]]
gridy = [0D,1D]
endif else begin
gridx = [0D,1D]
gridy = [tickvalues[i],tickvalues[i]]
endelse
if tickvalues[i] lt 0+gridEdgeMargin || tickvalues[i] gt 1-gridEdgeMargin then begin
lineshow=0
endif else begin
lineshow=1
endelse
gridz = [gridzstack,gridzstack]
if lineshow then begin
gridline = obj_new('IDLgrPolyline',$
gridx,gridy,gridz,alpha=opacity,$
linestyle=gridstyle,thick=gridthick,$
color=self->convertColor(gridColor),/double)
gridmodel->add,gridline
endif
endfor
endif
endif
endif
if obj_valid(minorGrid) && obj_isa(minorgrid,'spd_ui_line_style') && ~noMinor then begin
minorGrid->getProperty,id=gridstyle,$
color=gridcolor,$
show=gridshow,$
thickness=gridthick,$
opacity=opacity
if gridshow && range[1] ne range[0] then begin
tickValues = minorTickValues
for i = 0,n_elements(tickvalues)-1 do begin
if n_elements(majorTickValues) gt 0 && majorGridShow then begin
val = min(abs(majorTickValues - tickvalues[i]))
if val lt .01 then continue
endif
if dir eq 0 then begin
gridx = [tickvalues[i],tickvalues[i]]
gridy = [0D,1D]
endif else begin
gridx = [0D,1D]
gridy = [tickvalues[i],tickvalues[i]]
endelse
if tickvalues[i] lt 0+gridEdgeMargin || tickvalues[i] gt 1-gridEdgeMargin then begin
lineshow=0
endif else begin
lineshow=1
endelse
gridz = [gridzstack,gridzstack]
if lineshow then begin
gridline = obj_new('IDLgrPolyline',$
gridx,gridy,gridz,alpha=opacity,$
linestyle=gridstyle,thick=gridthick,$
xcoord_conv=xconv,ycoord_conv=yconv,$
color=self->convertColor(gridColor),/double)
gridmodel->add,gridline
endif
endfor
endif
endif
axisSettings->getProperty,blacklabels=blacklabels
self->addAxisLabels,model,labels,margin,placeLabel,dir,orientation,stacklabels,showlabels,self->pt2norm(1.,~dir)/(plotDim1[1]-plotDim1[0]),self->pt2norm(1.,dir)/(plotDim2[1]-plotDim2[0]),lazylabels,blacklabels,labelPos=labelPos
self->addAxisTitle,model,titleobj,subtitleobj,titlemargin,placetitle,dir, titleorientation, showtitle,self->pt2norm(1.,~dir)/(plotDim1[1]-plotDim1[0]),self->pt2norm(1.,dir)/(plotDim2[1]-plotDim2[0]), lazytitles
fail = 0
end