#!../bltwish

source bltDemo.tcl

proc random {{max 1.0} {min 0.0}} {
    global randomSeed

    set randomSeed [expr (7141*$randomSeed+54773) % 259200]
    set num  [expr $randomSeed/259200.0*($max-$min)+$min]
    return $num
}
set randomSeed 14823


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 *Barchart.title		"A Simple Barchart"
option add *Barchart.relief 		raised
option add *Barchart.borderWidth 	2
option add *Barchart.plotBackground 	white
option add *Barchart.baseline   	57.299

option add *Element.borderWidth		2
option add *Element.Background		white
option add *Element.Relief		raised

option add *x.Title			"X Axis"
option add *x.Font			*Times-Medium-R*10*
option add *y.Title			"Y Axis"
option add *LineMarker.Foreground	yellow

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 .header -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 
    } 
    $w append $w.print

%% button.  
}
barchart $graph 
$graph xaxis configure -rotate 90 -stepsize 0

htext .footer -text {    Hit the %%
    set im [image create photo -file ./images/stopsign.gif]
    button $htext(widget).quit -image $im -command { exit }
    $htext(widget) append $htext(widget).quit -pady 2
%% button when you've seen enough. %%
    label $htext(widget).logo -bitmap BLT
    $htext(widget) append $htext(widget).logo 
%%}

set attributes { 
    red		pattern1
    orange	pattern2
    yellow	pattern3
    green	pattern4
    blue	pattern5
    cyan	pattern6
    magenta	pattern7
    violetred	pattern8
    purple	pattern9
    lightblue 	hobbes	
}

set count 0
foreach { color stipple } $attributes {
    $graph pen create pen$count -fg ${color}1 -bg ${color}4 -stipple $stipple
    lappend styles [list pen$count $count $count]
    incr count
}


vector x y w
for { set i 0 } { $i <= 100 } { incr i } {
    set value [random 90.0]
    w append [expr round($value/10.0) % $count]
    x append $i
    y append $value+10.0
}

$graph element create data -label {} \
    -xdata x -ydata y -weight w -styles $styles

table . \
    0,0 .header -fill x  \
    1,0 .graph -fill both \
    2,0 .footer -fill x

table configure . r0 r2 -resize none
	
wm min . 0 0

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

