;+ ; NAME: ; qBar ; PURPOSE: ; Make bar graph or histogram plot ; CATEGORY: ; Widget ; CALLING SEQUENCE: ; qBar, array [, /histogram, xtitle=xtitle, ytitle=ytitle, title=title] ; INPUTS: ; array array; type: any ; array for which a bargraph or histogram is to be made ; OPTIONAL INPUT PARAMETERS: ; /histogram if set, the IDL histogram is called with argument 'array' ; The output from histogram is plotted as bargraph ; title =title scalar; type: string; default: BIN ; main plot title (at top of plot) ; xtitle=xtitle scalar; type: string ; title for x-axis ; ytitle=ytitle scalar; type: string ; title for y-axis ; OUTPUTS: ; (plot in widget) ; CALLS: ; bargraph, IsDisplay, qBar_Print ; RESTRICTIONS: ; The average and median are calculated over the bins actually ; displayed. Note that this will only be part of the total ; distribution depending on how the minimum and maximum bin ; values are selected. ; PROCEDURE: ; href=bargraph= does the actual plotting ; MODIFICATION HISTORY: ; APR-2000, Paul Hick (UCSD/CASS) ; SEP-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added max keyword to IDL histogram calls ;- pro qBar_Redraw, state @compile_opt.pro ; On error, return to caller widget_control, state.draw , get_uvalue=array, get_value=wnr widget_control, state.zmin , get_value=zmin widget_control, state.zmax , get_value=zmax widget_control, state.zbin , get_value=zbin widget_control, state.xtitle, get_value=xtitle widget_control, state.ytitle, get_value=ytitle widget_control, state.title , get_value=title widget_control, state.charsize, get_value=charsize widget_control, state.average, get_uvalue=average widget_control, state.median , get_uvalue=median widget_control, state.maximum, get_uvalue=maximum widget_control, state.hatch, get_uvalue=hatch case widget_info(state.histogram, /valid_id) of 0: begin catch, ierror if ierror eq 0 then a = histogram(float(array),min=zmin,max=zmax,bin=zbin, /nan) catch, /cancel end 1: begin widget_control, state.histogram, get_uvalue=set case set of 0: a = array 1: begin catch, ierror if ierror eq 0 then a = histogram(float(array),min=zmin,max=zmax,bin=zbin, /nan) catch, /cancel end endcase end endcase if IsDisplay() then begin wold = !d.window if wold ne wnr then wset, wnr endif if IsType(a, /defined) then bargraph, a, minbin=zmin, bin=zbin, $ xtitle=xtitle[0], ytitle=ytitle[0], title=title[0], $ average=average, median=median, maximum=maximum, hatch=hatch, $ xrange=[zmin,zmax], charsize=charsize if IsDisplay() then wset, wold return & end pro qBar_Event, event @compile_opt.pro ; On error, return to caller widget_control, event.handler, get_uvalue=state, /no_copy redraw = 1B case event.id of ; ID of widget that generated the message event.top : widget_control, event.handler, /destroy ; Intercepts WIDGET_KILL_REQUEST from base widget state.done : widget_control, event.handler, /destroy ; Message from Done widget state.print : begin & qBar_Print, state, event & redraw = 0B & end state.zmin : state.zmax : state.zbin : state.xtitle : state.ytitle : state.title : state.redraw : state.average : widget_control, state.average , set_uvalue=event.select state.median : widget_control, state.median , set_uvalue=event.select state.maximum : widget_control, state.maximum , set_uvalue=event.select state.hatch : widget_control, state.hatch , set_uvalue=event.select state.histogram : widget_control, state.histogram, set_uvalue=event.select else: begin print, tag_names(event, /structure_name) print, event end endcase if widget_info(event.handler,/valid_id) then begin if redraw then qBar_Redraw, state widget_control, event.handler, set_uvalue=state, /no_copy endif return & end pro qBar, array, group=Group, histogram_mode=histogram_mode, $ title=title, xtitle=xtitle, ytitle=ytitle, charsize=charsize, zbin=zbin, zmax=zmax, zmin=zmin @compile_opt.pro ; On error, return to caller ;common qBar_base, base if IsType(array, /undefined) then return InitVar, histogram_mode, /key message, /info, strcompress( xregistered('qBar') ) ;if xregistered('qBar') then begin ; Not tested yet !!!!! ; widget_control, base, get_uvalue=state, /no_copy ; redraw = state.redraw ; widget_control, state.redraw, set_uvalue=array ; widget_control, base, set_uvalue=state, /no_copy ; qBar_Event, {WIDGET_BUTTON, ID:redraw, TOP:base, HANDLER: base, SELECT:1} ; return ;endif case histogram_mode of 0: begin if IsType(zmin, /undefined) then zmin = 0. if IsType(zmax, /undefined) then zmax = float(n_elements(array)) if IsType(zbin, /undefined) then zbin = 1. end 1: begin case IsType(array, /generic_int) of 0: begin if IsType(zmin, /undefined) then zmin = float(min(array, /nan)) if IsType(zmax, /undefined) then zmax = float(max(array, /nan)) if IsType(zbin, /undefined) then zbin = (zmax-zmin)/10. end 1: begin if IsType(zmin, /undefined) then zmin = float(min(array, /nan))-0.5 if IsType(zmax, /undefined) then zmax = float(max(array, /nan))+0.5 if IsType(zbin, /undefined) then zbin = 1.0;(zmax-zmin)/10. end endcase end endcase state = {STATE_QBAR, $ draw : 0L, $ done : 0L, $ print : 0L, $ zmin : 0L, $ zmax : 0L, $ zbin : 0L, $ redraw : 0L, $ xtitle : 0L, $ ytitle : 0L, $ title : 0L, $ charsize: 0L, $ average : 0L, $ median : 0L, $ maximum : 0L, $ hatch : 0L, $ histogram:0L } base = widget_base(title='Bargraph',/column,/tlb_kill_request) state.draw = widget_draw(base, xsize=640,ysize=480, frame=4, uvalue=array) options = widget_base(base, /row) ;state.done = widget_button(options, value='Done' ) state.done = widget_button(options, value=filepath(root=getenv('SSW_SMEI_UCSD'),subdir='image','done.ico'), /bitmap) state.print = widget_button(options, value='Print' ) dummy = widget_label (options,xsize=25,value='') dummy = widget_label (options,xsize=25,value='') state.redraw = widget_button(options , value='Redraw') toggles = widget_base(options, /row, /nonexclusive, frame=2) state.average = widget_button(toggles, value='Average', uvalue=0B) state.median = widget_button(toggles, value='Median' , uvalue=0B) state.maximum = widget_button(toggles, value='Maximum', uvalue=0B) state.hatch = widget_button(toggles, value='Hatch' , uvalue=0B) if not keyword_set(histogram_mode) then $ state.histogram = widget_button(toggles, value='Histogram', uvalue=0B) titles = widget_base(base, /row) state.zmin = cw_field(titles, value=zmin, /floating, title='Min' ,/row,xsize=7, /return_ev) state.zmax = cw_field(titles, value=zmax, /floating, title='Max' ,/row,xsize=7, /return_ev) state.zbin = cw_field(titles, value=zbin, /floating, title='Bin',/row,xsize=7,/return_ev) state.title = cw_field(titles, value=' ', /string, title='Top:' , xsize=18, /return_ev) state.xtitle = cw_field(titles, value=' ', /string, title='X-', xsize=18, /return_ev) state.ytitle = cw_field(titles, value=' ', /string, title='Y-', xsize=18, /return_ev) state.charsize = cw_field(titles, value=1.3, /float , title='CharS', xsize=5, /return_ev) if n_elements(title ) ne 0 then widget_control, state.title , set_value=title if n_elements(xtitle ) ne 0 then widget_control, state.xtitle , set_value=xtitle if n_elements(ytitle ) ne 0 then widget_control, state.ytitle , set_value=ytitle if n_elements(charsize) ne 0 then widget_control, state.charsize, set_value=charsize redraw = state.redraw widget_control, base, set_uvalue=state, /no_copy widget_control, base, /realize qBar_Event, {WIDGET_BUTTON, ID:redraw, TOP:base, HANDLER: base, SELECT:1} xmanager, 'qBar', base, group=Group, /no_block, event_handler='qBar_Event' return & end