; $Id: davegr2d__resetmiscgrattribs.pro,v 1.4 2005/02/08 17:17:34 azuah Exp $
;###############################################################################
;
; CLASS NAME:
;   DaveGr2D
;
; PURPOSE:
;   The DaveGr2D class extends the DaveGr class to better handle
;   plotting of 2D data ie area and surface plots.
;
; CATEGORY:
;   Data Browser
;
; SUPERCLASSES:
;   DaveGr
;
; PUBLIC METHODS:
;   Display
;   Get
;   ReserMiscGrAttribs
;   Set
;
; AUTHOR:
;   Richard Tumanjong Azuah
;   NIST Center for Neutron Research
;   100 Bureau Drive, Gaithersburg, MD 20899
;   United States
;   azuah@nist.gov; (301) 9755604
;   Dec, 2002
;
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used or if the code in this file is
;  included in another product.
;
;###############################################################################



;===============================================================================
; DaveGr2D::ResetMiscGrAttribs
;
; PURPOSE:
;   Private method to initialize/update various axes graph attributes
;   so they are consistent with the data.
;
; PARAMETERS:
;
; KEYWORDS:
;   limits [in] - If set, then update only the limits (minimum,
;                 maximum and major tick interval)
;
;   index [in] - index specifying type of axis to modify.
;
pro DaveGr2D::resetMiscGrAttribs, limits=limits, index=index

message,/reset

nData = self->count()
if (nData le 0) then begin ; no data present
    xmin = 0.0
    xmax = 1.0
    ymin = 0.0
    ymax = 1.0
    zmin = 0.0
    zmax = 1.0
endif else begin
    if (not self->get(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,zmin=zmin,zmax=zmax)) then begin
        if (!debug) then print, !error_state.msg
        return
    endif
endelse

if (keyword_set(limits)) then begin
    self.xMiscAttribs.useCustomFlag = 0
    self.yMiscAttribs.useCustomFlag = 0
    self.zMiscAttribs.useCustomFlag = 0

    xmin = xmin*self.xMiscAttribs.scaleFactor
    xmax = xmax*self.xMiscAttribs.scaleFactor
    ymin = ymin*self.yMiscAttribs.scaleFactor
    ymax = ymax*self.yMiscAttribs.scaleFactor
    zmin = zmin*self.xMiscAttribs.scaleFactor
    zmax = zmax*self.xMiscAttribs.scaleFactor
    ;; X
    self.xMiscAttribs.minimum = xmin
    self.xMiscAttribs.maximum = xmax
    ;; Y
    self.yMiscAttribs.minimum = ymin
    self.yMiscAttribs.maximum = ymax
    ;; Z
    self.zMiscAttribs.minimum = zmin
    self.zMiscAttribs.maximum = zmax   
    ;; tick interval - set nos of major ticks to 5 (including end points) by default
    self.xMiscAttribs.tickInterval = (xmax-xmin)*0.25 ; 5 major ticks ie end points + 3 middle ones
    self.yMiscAttribs.tickInterval = (ymax-ymin)*0.25 ; 5 major ticks ie end points + 3 middle ones
    self.zMiscAttribs.tickInterval = (zmax-zmin)*0.25 ; 5 major ticks ie end points + 3 middle ones
    return
endif

if (n_elements(index) le 0) then index=-1


if (index eq 0 || index eq -1) then begin ; do x-axis
    ;; scalefactor
    self.xMiscAttribs.scaleFactor = 1.0

    ;; min & max
    self.xMiscAttribs.minimum = xmin
    self.xMiscAttribs.maximum = xmax

    ;; tick interval - set nos of major ticks to 5 (including end points) by default
    self.xMiscAttribs.tickInterval = (xmax-xmin)*0.25 ; 5 major ticks ie end points + 3 middle ones

    ;; flag to indicate whether custom user settings (min, max, tick
    ;; interval) should be used 
    self.xMiscAttribs.useCustomFlag = 0 ; don't use custom

    ;; log/linear axis
    self.xMiscAttribs.logFlag = 0 ; linear

    ;; Nos of decimals to display - 2 by default
    self.xMiscAttribs.decimalPlaces = 2

    ;; tick direction for primary axis- inwards/outwards
    self.xMiscAttribs.tickDir = 0 ; inwards

    ;; tick length (as percentage of axis length)
    self.xMiscAttribs.tickLen = 2.5

    ;; Nos of minor ticks between major ticks
    self.xMiscAttribs.minorTicks = 4
endif

if (index eq 1 || index eq -1) then begin ; do y-axis
    ;; scalefactor
    self.yMiscAttribs.scaleFactor = 1.0

    ;; min & max
    self.yMiscAttribs.minimum = ymin
    self.yMiscAttribs.maximum = ymax

    ;; tick interval - set nos of major ticks to 5 (including end points) by default
    self.yMiscAttribs.tickInterval = (ymax-ymin)*0.25 ; 5 major ticks ie end points + 3 middle ones

    ;; flag to indicate whether custom user settings (min, max, tick
    ;; interval) should be used 
    self.yMiscAttribs.useCustomFlag = 0 ; don't use custom

    ;; log/linear axis
    self.yMiscAttribs.logFlag = 0 ; linear

    ;; Nos of decimals to display - 2 by default
    self.yMiscAttribs.decimalPlaces = 2

    ;; tick direction for primary axis- inwards/outwards
    self.yMiscAttribs.tickDir = 0 ; inwards

    ;; tick length (as percentage of axis length)
    self.yMiscAttribs.tickLen = 2.5

    ;; Nos of minor ticks between major ticks
    self.yMiscAttribs.minorTicks = 4
endif


if (index eq 2 || index eq -1) then begin ; do z-axis 
    ;; scalefactor
    self.zMiscAttribs.scaleFactor = 1.0

    ;; min and max
    self.zMiscAttribs.minimum = zmin
    self.zMiscAttribs.maximum = zmax

    ;; tick interval - set nos of major ticks to 5 (including end points) by default
    self.zMiscAttribs.tickInterval = (zmax-zmin)*0.25 ; 5 major ticks ie end points + 3 middle ones

    ;; flag to indicate whether custom user settings (min, max, tick
    ;; interval) should be used 
    self.zMiscAttribs.useCustomFlag = 0 ; don't use custom

    ;; log/linear axis
    self.zMiscAttribs.logFlag = 0 ; linear

    ;; Nos of decimals to display - 2 by default
    self.zMiscAttribs.decimalPlaces = 2

    ;; tick direction for primary axis- inwards/outwards
    self.zMiscAttribs.tickDir = 0 ; inwards

    ;; tick length (as percentage of axis length)
    self.zMiscAttribs.tickLen = 2.5

    ;; Nos of minor ticks between major ticks
    self.zMiscAttribs.minorTicks = 4
endif

end
