#!/bin/sh ./myblt

source bltDemo.tcl

set graph .htext.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 10"
option add *graph.elemBackground white
option add *graph.elemRelief raised
option add *graph.legendMapped false
option add *graph.gridMapped true
#option add *graph.invertXY true

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

htext .htext -text {\
This is an example of the barchart widget.  The barchart has 
many components; x and y axis, legend, crosshairs, elements, etc.  
To create a postscript file "bar.ps", press the %%

    set w $htext(widget)

    button $w.print -text {Print} -command {
	$graph postscript output bar.ps -landscape 1 -maxpect 1 -center 1
    } 
    $w append $w.print

%% button.
%%

    barchart $graph  -relief raised -bd 2
    $graph xaxis configure -rotate 90 -command FormatLabel
    $w append $graph -relcavitywidth 1.0 -fill both

%%
Hit the %%

    button $w.quit -text quit -command exit 
    $w append $w.quit 

%% button when you've seen enough.%%

    label $w.logo -bitmap BLT
    $w append $w.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 -0.5 } \
	-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  

table . .htext -fill both -padx 10
	
wm min . 0 0
bind $graph <B1-ButtonRelease> { %W crosshairs toggle }
bind $graph <ButtonPress-3> {
    set info [%W element closest %x %y]
    if { $info == "" } {
        bell
    } else {
        puts stdout "$info"
    }
}
	
proc TurnOnHairs { graph } {
    bind $graph <Any-Motion> {%W crosshairs configure -position @%x,%y}
}
proc TurnOffHairs { graph } {
    bind $graph <Any-Motion> {%W crosshairs configure -position @%x,%y}
}

bind $graph <Enter> { TurnOnHairs %W }
bind $graph <Leave> { TurnOffHairs %W }

proc FormatLabel { w value } {
    # Determine the element name from the value
    set displaylist [$w element show]
    set index [expr round($value)]
    if { $index != $value } {
	return $value 
    }
    incr index -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
