#!/bin/sh ./myblt

source bltDemo.tcl

set graph .htext.graph
set htext .htext

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 }
}

set name [string trimleft $graph "."]
option add *Radiobutton.relief flat
option add *Button.padX 5
option add *$name*markerFont "Helvetica 14 bold"
option add *$name*xTitle "Simulator"
option add *$name*yTitle "Time (hrs)"
option add *$name*title "Comparison of Simulators"
option add *$name*xCommand FormatX
option add *$name*elemBackground white
option add *$name*elemRelief raised
option add *$name*elemActiveForeground "black"
option add *$name*elemActiveStipple pattern1

set name [string trimleft $htext "."]

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

htext .htext -text {
    Bars can be displayed in one of the following modes:
    %%
        radiobutton $htext.stacked -text stacked -variable barMode \
	    -value "stacked" -command {
            $graph configure -barmode $barMode
        } 
        $htext append $htext.stacked
    %%         %% 
        radiobutton $htext.aligned -text aligned -variable barMode \
	    -value "aligned" -command {
            $graph configure -barmode $barMode
        } 
        $htext append $htext.aligned
    %%        %%
        radiobutton $htext.normal -text normal -variable barMode \
            -value "normal" -command {
            $graph configure -barmode $barMode
        } 
        $htext append $htext.normal
    %% 
    %%
	barchart $graph 
	$graph xaxis configure
	$htext append $graph 
    %%
    Hit the %%
	button $htext.quit -text Quit -command { exit }
	$htext append $htext.quit 
    %% button when you've seen enough.%%
	label $htext.logo -bitmap BLT
	$htext append $htext.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]

set labels { "Read In" "Setup" "Load" "Solve" "Other" }
set colors { green orange violetred dodgerblue red tan mediumorchid cyan }
set stipples { 
    pattern1 pattern2 
    pattern6 pattern7 pattern8 pattern9 hobbes 
    pattern3 pattern4 pattern5 
}

vector X Y0 Y1 Y2 Y3 Y4

set names { A1 B1 A2 B2 C1 D1 C2 A3 E1 }

X set { 1 2 3 4 5 6 7 8 9 }
Y0 set { 
    0.729111111  0.002250000  0.09108333  0.006416667  0.026509167 
    0.007027778  0.1628611    0.06405278  0.08786667  
}
Y1 set {
    0.003120278	 0.004638889  0.01113889  0.048888889  0.001814722
    0.291388889  0.0503500    0.13876389  0.04513333 
}
Y2 set {
    11.534444444 3.879722222  4.54444444  4.460277778  2.334055556 
    1.262194444  1.8009444    4.12194444  3.24527778  
}
Y3 set {
    1.015750000  0.462888889  0.49394444  0.429166667  1.053694444
    0.466111111  1.4152500    2.17538889  2.55294444 
}
Y4 set {
    0.022018611  0.516333333  0.54772222  0.177638889  0.021703889 
    0.134305556  0.5189278    0.07957222  0.41155556  
}

proc FormatX { w value } {
    # Determine the element name from the value
    set index [expr round($value)]
    if { $index != $value } {
	return $value 
    }
    incr index -1
    global names
    set name [lindex $names $index]
    return $name
}


set barMode stacked
$graph configure -barmode $barMode
set count 0
for { set i 0 } { $i < 5 } { incr i } {
    set ydata Y$i 
    set label [lindex $labels $i]
    set color [lindex $colors $i]
    set stipple [lindex $stipples $i]
    $graph element create $ydata \
	-ydata $ydata  \
	-xdata X \
        -fg ${color}1 \
        -bg ${color}3 \
	-label $label
    incr count
}

table . .htext -fill both
	
wm min . 0 0

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