#!/users/mgd/packages/swarm/blt2.3/bin/bltwish
#!../bltwish

source bltDemo.tcl

set graph .graph

bitmap define pattern1 { {4 4} {01 02 04 08} }
bitmap define pattern2 { {4 4} {08 04 02 01} }
bitmap define pattern3 { {2 2} {01 02 } }
bitmap define pattern4 { {4 4} {0f 00 00 00} }
bitmap define pattern5 { {4 4} {01 01 01 01} }
bitmap define pattern6 { {2 2} {01 00 } }
bitmap define pattern7 { {4 4} {0f 01 01 01} }
bitmap define pattern8 { {8 8} {ff 00 ff 00 ff 00 ff 00 } }
bitmap define pattern9 { {4 4} {03 03 0c 0c} }
bitmap define hobbes { {25 25} {
   00 00 00 00 00 00 00 00 00 c0 03 00 78 e0 07 00 fc f8 07 00 cc 07 04 00
   0c f0 0b 00 7c 1c 06 00 38 00 00 00 e0 03 10 00 e0 41 11 00 20 40 11 00
   e0 07 10 00 e0 c1 17 00 10 e0 2f 00 20 e0 6f 00 18 e0 2f 00 20 c6 67 00
   18 84 2b 00 20 08 64 00 70 f0 13 00 80 01 08 00 00 fe 07 00 00 00 00 00
   00 00 00 00 }
}

option add *graph.xTitle "X Axis Label"
option add *graph.yTitle "Y Axis Label"
option add *graph.title "A Simple Barchart"
option add *graph.xFont *Times-Medium-R*12*
option add *graph.elemBackground white
option add *graph.elemRelief raised

set visual [winfo screenvisual .] 
if { $visual != "staticgray" && $visual != "grayscale" } {
    option add *print.background yellow
    option add *quit.background red
}

htext .header -text {
This is an example of the barchart widget.  To create a postscript 
file "bar.ps", press the %% 
button $htext(widget).print -text {Print} -command {
  $graph postscript output bar.ps 
} 
$htext(widget) append $htext(widget).print
%% button.}

barchart $graph -invert true 
$graph xaxis configure -command FormatLabel -descending true
$graph legend configure -hide yes

htext .footer -text {Hit the %%
button $htext(widget).quit -text quit -command exit
$htext(widget) append $htext(widget).quit 
%% button when you've seen enough.%%
label $htext(widget).logo -bitmap BLT
$htext(widget) append $htext(widget).logo -padx 20
%%}

set names { One Two Three Four Five Six Seven Eight }
if { $visual == "staticgray" || $visual == "grayscale" } {
    set fgcolors { white white white white white white white white }
    set bgcolors { black black black black black black black black }
} else {
    set fgcolors { red green blue purple orange brown cyan navy }
    set bgcolors { green blue purple orange brown cyan navy red }
}
set numColors [llength $names]

for { set i 0} { $i < $numColors } { incr i } {
    $graph element create [lindex $names $i] \
	-data { $i+1 $i+1 } \
	-fg [lindex $fgcolors $i] \
	-bg [lindex $bgcolors $i] \
	-stipple pattern[expr $i+1]  \
	-relief raised \
	-bd 2 
}

$graph element create Nine \
    -data { 9 -1.0 } \
    -fg red  \
    -relief sunken 
$graph element create Ten \
    -data { 10 2 } \
    -fg seagreen \
    -stipple hobbes \
    -background palegreen 
$graph element create Eleven \
    -data { 11 3.3 } \
    -fg blue  

#    -coords { -Inf Inf  } 

$graph marker create bitmap \
    -coords { 11 3.3 } \
    -bitmap @bitmaps/sharky.bm \
    -name bitmap \
    -bg {} 

table . \
    .header 0,0 -padx .25i \
    .graph 1,0 -fill both \
    .footer 2,0 -padx .25i  

table configure . r0 r2 -resize none

wm min . 0 0

proc FormatLabel { w value } {
    # Determine the element name from the value
    set displaylist [$w element show]
    set index [expr round($value)-1]
    set name [lindex $displaylist $index]
    if { $name == "" } { 
	return $name
    }
    # Return the element label
    set info [$w element configure $name -label]
    return [lindex $info 4]
}

Blt_ZoomStack $graph
Blt_Crosshairs $graph
Blt_ActiveLegend $graph
Blt_ClosestPoint $graph

