proc mkwPlot {} {
#$Header: /home/cvsroot/tcldb/wisql/Tlib/mkwPlot,v 1.4 1998/07/02 23:46:30 de Exp $

	global DataCount Data Pcolours
	global X Y Vdata UserLabels

	if {![info exists X]} {
		return
	}
        set i 0
        while {1} {
                set err [catch {winfo children .wPlot$i}]
                if {$err} {break}
                incr i
        }

	set w .wPlot$i
	catch {destroy $w}
	toplevel $w


	wm title $w "Wisql Plot"

	frame $w.f1 -background black
	frame $w.f2 -background bisque -relief ridge

	set path $w.f1.g
	graph $path -title "Wisql Plot $i" -height 300  -width 750 -plotbackground black -border 2 -relief sunken  -background antiquewhite -shadow {black 0} -foreground black
	$path crosshairs configure -hide 0 -color gray
	$path legend configure -shadow {black 0}

	frame $w.f2.p -background papayawhip -relief groove

#       Try setting up zoom box bindings, then overwrite with our
#       preference
        set zoomMod ""
        Blt_ZoomStack $path
#
#       scaling launch menu
        set ysm $w.f2.ys.m
        menubutton $w.f2.ys -text "Y Scale" -menu $ysm -background gray75 -activebackground gray75 -activeforeground magenta2 -border 2 -relief raised
        menu $ysm -tearoff 0 -background gray75

#       axis choosing menu
        set alm $w.f2.ya.m
        menubutton $w.f2.ya -text "Y Axis" -menu $alm -background gray75 -activebackground gray75 -activeforeground magenta2 -border 2 -relief raised
        menu $alm -tearoff 0 -background gray75


#	get xvector, x col name
	set xcol ""
	set gtitle "Series Count"
	set xnam $UserLabels(X)
	catch {set xv $X}
	set xds $Vdata($xv)
	if {$xnam == ""} {
	set xnam [keylget Data($xds) $xv]
	}
	$path xaxis configure -title $xnam -hide 0 -color black -min {} -max {} -titleshadow {black 0} -tickshadow {black 0}

#	get y vectors and col names
	set yis [lsort -integer [array names Y]] 
	foreach yi $yis {
		set y $Y($yi)
		set ynam $UserLabels(Y$yi)
		set yds $Vdata($y)
		if {$ynam == ""} {
		set ynam [keylget Data($yds) $y]
		}
        	$alm add command -label "$ynam" -command "showY $path $y" \
			-background gray75 -activebackground gray75 \
			-foreground $Pcolours($yi) -activeforeground magenta2 
        	$ysm add command -label "$ynam" -command "scaleY $path $y"\
			 -background gray75 -activebackground gray75 \
			 -foreground $Pcolours($yi) -activeforeground magenta2

        	$path axis create $y -color black -min {} -max {} -tickshadow {black 0} -titleshadow {black 0} -title "$ynam"
		set err [catch {$path element create $y -xdata $xv  -ydata $y -color $Pcolours($yi) -mapy $y -mapx x -label "$ynam" -smooth linear -symbol none} res]
		if {$err} {
			puts stderr "ERROR creating element $y:\n $res"
		}
	}
	set y1 $Y([lindex $yis 0])
	set y2 ""
	catch {set y2 $Y([lindex $yis 1])}
	$path yaxis use $y1
	if {$y2 != ""} {
		$path y2axis use $y2
	}

	pack $path -side top -expand true -fill both

	pack $w.f1 -side top -expand true -fill both

	button $w.f2.quit -text "QUIT" -command "destroy $w"  -background white -foreground red \

        set m $w.f2.pt.m
        menubutton $w.f2.pt -text "Plot Type" -background azure -menu $m -relief raised -border 2 \
		-activebackground azure -activeforeground orange
        menu $m -background azure
        $m add radio -command "plotType -1 LIN $path" -label Line -background azure  -activebackground azure -activeforeground orange
        $m add radio -command "plotType -1 STP $path" -label Step -background azure  -activebackground azure -activeforeground orange
        $m add radio -command "plotType -1 SPL $path" -label Spline -background azure  -activebackground azure -activeforeground orange
        $m add radio -command "plotType -1 PTS $path" -label Points -background azure  -activebackground azure -activeforeground orange
	button $w.f2.post -text PostScript -background lavender  -command "psPlot $path"  -activebackground lavender -activeforeground magenta2

	pack $w.f2.quit -side right
	pack $w.f2.p -side right -padx 20

	pack $w.f2.post -side left 
	pack $w.f2.pt -side left -padx 20
	pack $w.f2.ys -side left -padx 20
	pack $w.f2.ya -side left -padx 20

	pack $w.f2 -side top -expand true -fill x

}



