Tk Source Code

Check-in [9bfc06dc]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Some cleaning up
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-510
Files: files | file ages | folders
SHA3-256: 9bfc06dc2956d3a5370a6cc16ffd93db81a2fe86abe4068168b5c9794e9da4bb
User & Date: dkf 2018-11-01 11:39:50
Context
2018-11-02
08:43
Cleaning up the script bindings further. [table] is gone; [grid] replaces it. check-in: 76212b98 user: dkf tags: tip-510
2018-11-01
11:39
Some cleaning up check-in: 9bfc06dc user: dkf tags: tip-510
09:20
Change name of rbcInt.c to less-confusing rbcMain.c check-in: 2a3d8d6e user: dkf tags: tip-510
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/rbc/rbcMain.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
26
27
28
29
30
31
32

33
34
35
36
37

38
39
40
41
42
43




44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59




60
61
62
63

64

65
66
67
68
69
70
/*
 * rbcInt.c --
 *
 *      This file constructs the basic functionality of the
 *      rbc commands.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"

/*
 * -----------------------------------------------------------------------
 *
 * Rbc_Init --
 *
 *      This procedure is invoked to initialize the "rbc" commands.
 *
................................................................................
 *
 * Side effects:
 *      Creates the new commands and adds a new entry into a global Tcl
 *      associative array.
 *
 * ------------------------------------------------------------------------
 */

MODULE_SCOPE int
Rbc_Init(
    Tcl_Interp * interp)
{                               /* Base interpreter to return results to. */
    Tcl_Namespace  *nsPtr;


    nsPtr = Tcl_CreateNamespace(interp, "::rbc", NULL, NULL);
    if (nsPtr == NULL) {
        return TCL_ERROR;
    }





    if (Tcl_Export(interp, nsPtr, "vector", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "graph", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "stripchart", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "barchart", 0) != TCL_OK) {
        return TCL_ERROR;
    }





    RbcVectorInit(interp);
    RbcGraphInit(interp);

    if (Tcl_PkgProvide(interp, "rbc", RBC_VERSION) == TCL_ERROR) {

        return TCL_ERROR;

    }

    return TCL_OK;
}

/* vim: set ts=4 sw=4 sts=4 ff=unix et : */
|

|
<










|







 







>


|

<
>

<




>
>
>
>



<



<



<




>
>
>
>



<
>
|
>
|
<
|

|

1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
25
26
27
28
29
30
31
32
33
34
35
36

37
38

39
40
41
42
43
44
45
46
47
48
49

50
51
52

53
54
55

56
57
58
59
60
61
62
63
64
65
66

67
68
69
70

71
72
73
74
/*
 * rbcMain.c --
 *
 *      This file constructs the basic functionality of the rbc commands.

 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "rbcInt.h"
 
/*
 * -----------------------------------------------------------------------
 *
 * Rbc_Init --
 *
 *      This procedure is invoked to initialize the "rbc" commands.
 *
................................................................................
 *
 * Side effects:
 *      Creates the new commands and adds a new entry into a global Tcl
 *      associative array.
 *
 * ------------------------------------------------------------------------
 */

MODULE_SCOPE int
Rbc_Init(
    Tcl_Interp *interp)
{                               /* Base interpreter to return results to. */

    Tcl_Namespace *nsPtr = Tcl_CreateNamespace(interp, "::rbc", NULL, NULL);


    if (nsPtr == NULL) {
        return TCL_ERROR;
    }

    /*
     * Export our public API.
     */

    if (Tcl_Export(interp, nsPtr, "vector", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "graph", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "stripchart", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    if (Tcl_Export(interp, nsPtr, "barchart", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    /*
     * Create the implementations of our API.
     */

    RbcVectorInit(interp);
    RbcGraphInit(interp);


    /*
     * Finalize the provision of the package.
     */


    return Tcl_PkgProvide(interp, "rbc", RBC_VERSION);
}
 
/* vim: set ts=4 sw=4 sts=4 ff=unix et : */

Changes to library/rbc/graph.tcl.

1
2



3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
..
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
...
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349

350

351
352
353
354
355
356
357
...
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
...
486
487
488
489
490
491
492

493

494
495
496
497
498
499
500
501
namespace eval ::rbc {}
set ::rbc::library [file normalize [file dirname [info script]]]






proc Rbc_ActiveLegend { graph } {
    $graph legend bind all <Enter> [list rbc::ActivateLegend $graph ]
    $graph legend bind all <Leave> [list rbc::DeactivateLegend $graph]
    $graph legend bind all <ButtonPress-1> [list rbc::HighlightLegend $graph]
}

proc Rbc_Crosshairs { graph } {
    rbc::Crosshairs $graph 
}

proc Rbc_ResetCrosshairs { graph state } {
    rbc::Crosshairs $graph "Any-Motion" $state
}

proc Rbc_ZoomStack { graph } {
    rbc::ZoomStack $graph
}

proc Rbc_PrintKey { graph } {
    rbc::PrintKey $graph
}

proc Rbc_ClosestPoint { graph } {
    rbc::ClosestPoint $graph

}

#
# The following procedures that reside in the "rbc" namespace are
# supposed to be private.
#

................................................................................
    bind crosshairs-$graph <Leave>   {
	%W crosshairs off
    }
    bind crosshairs-$graph <Enter>   {
	%W crosshairs on
    }
    $graph crosshairs configure -color red
    if { $state == "on" } {
	rbc::AddBindTag $graph crosshairs-$graph
    } elseif { $state == "off" } {
	rbc::RemoveBindTag $graph crosshairs-$graph
    }
}

proc rbc::InitStack { graph } {
    global zoomInfo
    set zoomInfo($graph,interval) 100
    set zoomInfo($graph,afterId) 0
    set zoomInfo($graph,A,x) {}
    set zoomInfo($graph,A,y) {}
    set zoomInfo($graph,B,x) {}
    set zoomInfo($graph,B,y) {}
    set zoomInfo($graph,stack) {}
    set zoomInfo($graph,corner) A
}

proc rbc::ZoomStack { graph {start "ButtonPress-1"} {reset "ButtonPress-3"} } {

    global zoomInfo zoomMod
    
    rbc::InitStack $graph
    
    if { [info exists zoomMod] } {
	set modifier $zoomMod
    } else {
	set modifier ""
................................................................................
	    rbc::ResetZoom %W 
	}
    }
    rbc::AddBindTag $graph zoom-$graph
}

proc rbc::PrintKey { graph {event "Shift-ButtonRelease-3"} } {
    bind print-$graph <$event>  { Rbc_PostScriptDialog %W }
    rbc::AddBindTag $graph print-$graph
}

proc rbc::ClosestPoint { graph {event "Control-ButtonPress-2"} } {
    bind closest-point-$graph <$event>  {
	rbc::FindElement %W %x %y
    }
    rbc::AddBindTag $graph closest-point-$graph
}

proc rbc::AddBindTag { widget tag } {
    set oldTagList [bindtags $widget]
    if { [lsearch $oldTagList $tag] < 0 } {
	bindtags $widget [linsert $oldTagList 0  $tag]
    }
}

proc rbc::RemoveBindTag { widget tag } {
    set oldTagList [bindtags $widget]
    set index [lsearch $oldTagList $tag]
    if { $index >= 0 } {
	bindtags $widget [lreplace $oldTagList $index $index]
    }
}

proc rbc::FindElement { graph x y } {
    if ![$graph element closest $x $y info -interpolate yes] {
	beep
	return
    }
    # --------------------------------------------------------------
    # find(name)		- element Id
    # find(index)		- index of closest point
    # find(x) find(y)		- coordinates of closest point
................................................................................
    set nx [lindex $coords 0]
    set ny [lindex $coords 1]

    $graph marker create line -coords "$nx $ny $info(x) $info(y)" \
	-name line.$markerName 

    rbc::FlashPoint $graph $info(name) $info(index) 10
    rbc::FlashPoint $graph $info(name) [expr $info(index) + 1] 10
}

proc rbc::FlashPoint { graph name index count } {
    if { $count & 1 } {
        $graph element deactivate $name 
    } else {
        $graph element activate $name $index
    }
    incr count -1
    if { $count > 0 } {
	after 200 rbc::FlashPoint $graph $name $index $count
	update
    } else {
	eval $graph marker delete [$graph marker names "rbcClosest_*"]
    }
}

proc rbc::GetCoords { graph x y index } {
    global zoomInfo
    if { [$graph cget -invertxy] } {
	set zoomInfo($graph,$index,x) $y
	set zoomInfo($graph,$index,y) $x
    } else {
	set zoomInfo($graph,$index,x) $x
	set zoomInfo($graph,$index,y) $y
    }
}

proc rbc::MarkPoint { graph index } {
    global zoomInfo
    set x [$graph xaxis invtransform $zoomInfo($graph,$index,x)]
    set y [$graph yaxis invtransform $zoomInfo($graph,$index,y)]
    set marker "zoomText_$index"
    set text [format "x=%.4g\ny=%.4g" $x $y] 

    if [$graph marker exists $marker] {
     	$graph marker configure $marker -coords { $x $y } -text $text 
................................................................................
    	$graph marker create text -coords { $x $y } -name $marker \
   	    -font *lucida*-r-*-10-* \
	    -text $text -anchor center -bg {} -justify left
    }
}

proc rbc::DestroyZoomTitle { graph } {
    global zoomInfo

    if { $zoomInfo($graph,corner) == "A" } {
	catch { $graph marker delete "zoomTitle" }
    }
}

proc rbc::PopZoom { graph } {
    global zoomInfo

    set zoomStack $zoomInfo($graph,stack)
    if { [llength $zoomStack] > 0 } {

	set cmd [lindex $zoomStack 0]
	set zoomInfo($graph,stack) [lrange $zoomStack 1 end]
	eval $cmd
	rbc::ZoomTitleLast $graph
	#busy hold $graph
	event generate $graph <Configure>
	update idletasks
	#busy release $graph

	after 2000 "rbc::DestroyZoomTitle $graph"
    } else {
	catch { $graph marker delete "zoomTitle" }
    }
}

# Push the old axis limits on the stack and set the new ones

proc rbc::PushZoom { graph } {
    global zoomInfo
    eval $graph marker delete [$graph marker names "zoom*"]
    if { [info exists zoomInfo($graph,afterId)] } {
	after cancel $zoomInfo($graph,afterId)
    }
    set x1 $zoomInfo($graph,A,x)
    set y1 $zoomInfo($graph,A,y)
    set x2 $zoomInfo($graph,B,x)
    set y2 $zoomInfo($graph,B,y)
................................................................................
	return
    }
    set cmd {}
    foreach margin { xaxis yaxis x2axis y2axis } {
	foreach axis [$graph $margin use] {
	    set min [$graph axis cget $axis -min] 
	    set max [$graph axis cget $axis -max]
	    set c [list $graph axis configure $axis -min $min -max $max]
	    append cmd "$c\n"
	}
    }
    set zoomInfo($graph,stack) [linsert $zoomInfo($graph,stack) 0 $cmd]


    foreach margin { xaxis x2axis } {
	foreach axis [$graph $margin use] {
	    set min [$graph axis invtransform $axis $x1]
	    set max [$graph axis invtransform $axis $x2]
	    if { $min > $max } { 
		$graph axis configure $axis -min $max -max $min
................................................................................
	    if { $min > $max } { 
		$graph axis configure $axis -min $max -max $min
	    } else {
		$graph axis configure $axis -min $min -max $max
	    }
	}
    }
    #busy hold $graph 
    event generate $graph <Configure>
    update idletasks
    #busy release $graph
}

#
# This routine terminates either an existing zoom, or pops back to
# the previous zoom level (if no zoom is in progress).
#

proc rbc::ResetZoom { graph } {
    global zoomInfo 

    if { ![info exists zoomInfo($graph,corner)] } {
	rbc::InitStack $graph 
    }
    eval $graph marker delete [$graph marker names "zoom*"]

    if { $zoomInfo($graph,corner) == "A" } {
	# Reset the whole axis
	rbc::PopZoom $graph
    } else {
	global zoomMod

................................................................................

option add *zoomTitle.font	  -*-helvetica-medium-R-*-*-18-*-*-*-*-*-*-* 
option add *zoomTitle.shadow	  yellow4
option add *zoomTitle.foreground  yellow1
option add *zoomTitle.coords	  "-Inf Inf"

proc rbc::ZoomTitleNext { graph } {
    global zoomInfo

    set level [expr [llength $zoomInfo($graph,stack)] + 1]
    if { [$graph cget -invertxy] } {
	set coords "-Inf -Inf"
    } else {
	set coords "-Inf Inf"
    }
    $graph marker create text -name "zoomTitle" -text "Zoom #$level" \
	-coords $coords -bindtags "" -anchor nw
}

proc rbc::ZoomTitleLast { graph } {
    global zoomInfo

    set level [llength $zoomInfo($graph,stack)]
    if { $level > 0 } {
     	$graph marker create text -name "zoomTitle" -anchor nw \
	    -text "Zoom #$level" 
    }
}


proc rbc::SetZoomPoint { graph x y } {

    global zoomInfo zoomMod

    if { ![info exists zoomInfo($graph,corner)] } {
	rbc::InitStack $graph
    }
    rbc::GetCoords $graph $x $y $zoomInfo($graph,corner)
    if { [info exists zoomMod] } {
	set modifier $zoomMod
    } else {
................................................................................

option add *zoomOutline.dashes		4	
option add *zoomTitle.anchor		nw
option add *zoomOutline.lineWidth	2
option add *zoomOutline.xor		yes

proc rbc::MarchingAnts { graph offset } {
    global zoomInfo

    incr offset
    if { [$graph marker exists zoomOutline] } {
	$graph marker configure zoomOutline -dashoffset $offset 
	set interval $zoomInfo($graph,interval)
	set id [after $interval [list rbc::MarchingAnts $graph $offset]]
	set zoomInfo($graph,afterId) $id
    }
}

proc rbc::Box { graph } {
    global zoomInfo

    if { $zoomInfo($graph,A,x) > $zoomInfo($graph,B,x) } { 
	set x1 [$graph xaxis invtransform $zoomInfo($graph,B,x)]
	set y1 [$graph yaxis invtransform $zoomInfo($graph,B,y)]
	set x2 [$graph xaxis invtransform $zoomInfo($graph,A,x)]
	set y2 [$graph yaxis invtransform $zoomInfo($graph,A,y)]
    } else {
................................................................................
}

proc rbc::ResetPostScript { graph } {
    foreach var { center landscape maxpect preview decorations padx 
	pady paperwidth paperheight width height colormode } {
	global $graph.$var
	set old [$graph postscript cget -$var]

	if { [catch {$graph postscript configure -$var [set $graph.$var]}] != 0 } {

	    $graph postscript configure -$var $old
	    set $graph.$var $old
	}
    }
    $graph postscript output "out.ps"
    puts stdout "wrote file \"out.ps\"."
    flush stdout
}
|
|
>
>
>
|

>
|
|
|
|
|
<
|
|
|
<
|
|
|
<
|
|
|
<
|
|
|
<
|
|
>







 







|

|





|











>
|







 







|












|
|












|







 







|










|


|




|










|







 







|







|

<

>
|
<
<

|


<
>
|








|
|







 







|
|



<







 







|


|








|




|







 







|
>
|










|










>
|
>







 







|











|







 







>
|
>








1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16

17
18
19

20
21
22

23
24
25

26
27
28
29
30
31
32
33
34
35
..
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219

220
221
222


223
224
225
226

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
...
249
250
251
252
253
254
255
256
257
258
259
260

261
262
263
264
265
266
267
...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
...
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
namespace eval ::rbc {
    variable library [file normalize [file dirname [info script]]]
    variable legacyAPI true
    variable zoomInfo
    array set zoomInfo {}
}

if {$::rbc::legacyAPI} {
    proc Rbc_ActiveLegend { graph } {
	$graph legend bind all <Enter> [list rbc::ActivateLegend $graph ]
	$graph legend bind all <Leave> [list rbc::DeactivateLegend $graph]
	$graph legend bind all <ButtonPress-1> [list rbc::HighlightLegend $graph]
    }

    proc Rbc_Crosshairs { graph } {
	rbc::Crosshairs $graph 
    }

    proc Rbc_ResetCrosshairs { graph state } {
	rbc::Crosshairs $graph "Any-Motion" $state
    }

    proc Rbc_ZoomStack { graph } {
	rbc::ZoomStack $graph
    }

    proc Rbc_PrintKey { graph } {
	rbc::PrintKey $graph
    }

    proc Rbc_ClosestPoint { graph } {
	rbc::ClosestPoint $graph
    }
}

#
# The following procedures that reside in the "rbc" namespace are
# supposed to be private.
#

................................................................................
    bind crosshairs-$graph <Leave>   {
	%W crosshairs off
    }
    bind crosshairs-$graph <Enter>   {
	%W crosshairs on
    }
    $graph crosshairs configure -color red
    if { $state eq "on" } {
	rbc::AddBindTag $graph crosshairs-$graph
    } elseif { $state eq "off" } {
	rbc::RemoveBindTag $graph crosshairs-$graph
    }
}

proc rbc::InitStack { graph } {
    variable zoomInfo
    set zoomInfo($graph,interval) 100
    set zoomInfo($graph,afterId) 0
    set zoomInfo($graph,A,x) {}
    set zoomInfo($graph,A,y) {}
    set zoomInfo($graph,B,x) {}
    set zoomInfo($graph,B,y) {}
    set zoomInfo($graph,stack) {}
    set zoomInfo($graph,corner) A
}

proc rbc::ZoomStack { graph {start "ButtonPress-1"} {reset "ButtonPress-3"} } {
    variable zoomInfo
    global zoomMod
    
    rbc::InitStack $graph
    
    if { [info exists zoomMod] } {
	set modifier $zoomMod
    } else {
	set modifier ""
................................................................................
	    rbc::ResetZoom %W 
	}
    }
    rbc::AddBindTag $graph zoom-$graph
}

proc rbc::PrintKey { graph {event "Shift-ButtonRelease-3"} } {
    bind print-$graph <$event> { Rbc_PostScriptDialog %W }
    rbc::AddBindTag $graph print-$graph
}

proc rbc::ClosestPoint { graph {event "Control-ButtonPress-2"} } {
    bind closest-point-$graph <$event>  {
	rbc::FindElement %W %x %y
    }
    rbc::AddBindTag $graph closest-point-$graph
}

proc rbc::AddBindTag { widget tag } {
    set oldTagList [bindtags $widget]
    if {$tag ni $oldTagList} {
	bindtags $widget [linsert $oldTagList 0 $tag]
    }
}

proc rbc::RemoveBindTag { widget tag } {
    set oldTagList [bindtags $widget]
    set index [lsearch $oldTagList $tag]
    if { $index >= 0 } {
	bindtags $widget [lreplace $oldTagList $index $index]
    }
}

proc rbc::FindElement { graph x y } {
    if {![$graph element closest $x $y info -interpolate yes]} {
	beep
	return
    }
    # --------------------------------------------------------------
    # find(name)		- element Id
    # find(index)		- index of closest point
    # find(x) find(y)		- coordinates of closest point
................................................................................
    set nx [lindex $coords 0]
    set ny [lindex $coords 1]

    $graph marker create line -coords "$nx $ny $info(x) $info(y)" \
	-name line.$markerName 

    rbc::FlashPoint $graph $info(name) $info(index) 10
    rbc::FlashPoint $graph $info(name) [expr {$info(index) + 1}] 10
}

proc rbc::FlashPoint { graph name index count } {
    if { $count & 1 } {
        $graph element deactivate $name 
    } else {
        $graph element activate $name $index
    }
    incr count -1
    if { $count > 0 } {
	after 200 [list rbc::FlashPoint $graph $name $index $count]
	update
    } else {
	$graph marker delete {*}[$graph marker names "rbcClosest_*"]
    }
}

proc rbc::GetCoords { graph x y index } {
    variable zoomInfo
    if { [$graph cget -invertxy] } {
	set zoomInfo($graph,$index,x) $y
	set zoomInfo($graph,$index,y) $x
    } else {
	set zoomInfo($graph,$index,x) $x
	set zoomInfo($graph,$index,y) $y
    }
}

proc rbc::MarkPoint { graph index } {
    variable zoomInfo
    set x [$graph xaxis invtransform $zoomInfo($graph,$index,x)]
    set y [$graph yaxis invtransform $zoomInfo($graph,$index,y)]
    set marker "zoomText_$index"
    set text [format "x=%.4g\ny=%.4g" $x $y] 

    if [$graph marker exists $marker] {
     	$graph marker configure $marker -coords { $x $y } -text $text 
................................................................................
    	$graph marker create text -coords { $x $y } -name $marker \
   	    -font *lucida*-r-*-10-* \
	    -text $text -anchor center -bg {} -justify left
    }
}

proc rbc::DestroyZoomTitle { graph } {
    variable zoomInfo

    if { $zoomInfo($graph,corner) == "A" } {
	catch { $graph marker delete "zoomTitle" }
    }
}

proc rbc::PopZoom { graph } {
    namespace upvar ::rbc zoomInfo($graph,stack) zoomStack


    if { [llength $zoomStack] > 0 } {
	set zoomStack [lassign $zoomStack cmd]
	uplevel #0 $cmd


	rbc::ZoomTitleLast $graph
	#tk busy hold $graph
	event generate $graph <Configure>
	update idletasks

	#tk busy forget $graph
	after 2000 [list rbc::DestroyZoomTitle $graph]
    } else {
	catch { $graph marker delete "zoomTitle" }
    }
}

# Push the old axis limits on the stack and set the new ones

proc rbc::PushZoom { graph } {
    variable zoomInfo
    $graph marker delete {*}[$graph marker names "zoom*"]
    if { [info exists zoomInfo($graph,afterId)] } {
	after cancel $zoomInfo($graph,afterId)
    }
    set x1 $zoomInfo($graph,A,x)
    set y1 $zoomInfo($graph,A,y)
    set x2 $zoomInfo($graph,B,x)
    set y2 $zoomInfo($graph,B,y)
................................................................................
	return
    }
    set cmd {}
    foreach margin { xaxis yaxis x2axis y2axis } {
	foreach axis [$graph $margin use] {
	    set min [$graph axis cget $axis -min] 
	    set max [$graph axis cget $axis -max]
	    append cmd [list $graph axis configure $axis -min $min -max $max] \
		"\n"
	}
    }
    set zoomInfo($graph,stack) [linsert $zoomInfo($graph,stack) 0 $cmd]


    foreach margin { xaxis x2axis } {
	foreach axis [$graph $margin use] {
	    set min [$graph axis invtransform $axis $x1]
	    set max [$graph axis invtransform $axis $x2]
	    if { $min > $max } { 
		$graph axis configure $axis -min $max -max $min
................................................................................
	    if { $min > $max } { 
		$graph axis configure $axis -min $max -max $min
	    } else {
		$graph axis configure $axis -min $min -max $max
	    }
	}
    }
    #tk busy hold $graph 
    event generate $graph <Configure>
    update idletasks
    #tk busy forget $graph
}

#
# This routine terminates either an existing zoom, or pops back to
# the previous zoom level (if no zoom is in progress).
#

proc rbc::ResetZoom { graph } {
    variable zoomInfo

    if { ![info exists zoomInfo($graph,corner)] } {
	rbc::InitStack $graph 
    }
    $graph marker delete {*}[$graph marker names "zoom*"]

    if { $zoomInfo($graph,corner) == "A" } {
	# Reset the whole axis
	rbc::PopZoom $graph
    } else {
	global zoomMod

................................................................................

option add *zoomTitle.font	  -*-helvetica-medium-R-*-*-18-*-*-*-*-*-*-* 
option add *zoomTitle.shadow	  yellow4
option add *zoomTitle.foreground  yellow1
option add *zoomTitle.coords	  "-Inf Inf"

proc rbc::ZoomTitleNext { graph } {
    variable zoomInfo

    set level [expr {[llength $zoomInfo($graph,stack)] + 1}]
    if { [$graph cget -invertxy] } {
	set coords "-Inf -Inf"
    } else {
	set coords "-Inf Inf"
    }
    $graph marker create text -name "zoomTitle" -text "Zoom #$level" \
	-coords $coords -bindtags "" -anchor nw
}

proc rbc::ZoomTitleLast { graph } {
    variable zoomInfo

    set level [llength $zoomInfo($graph,stack)]
    if { $level > 0 } {
     	$graph marker create text -name "zoomTitle" -anchor nw \
	    -text "Zoom #$level" 
    }
}


proc rbc::SetZoomPoint { graph x y } {
    variable zoomInfo
    global zoomMod

    if { ![info exists zoomInfo($graph,corner)] } {
	rbc::InitStack $graph
    }
    rbc::GetCoords $graph $x $y $zoomInfo($graph,corner)
    if { [info exists zoomMod] } {
	set modifier $zoomMod
    } else {
................................................................................

option add *zoomOutline.dashes		4	
option add *zoomTitle.anchor		nw
option add *zoomOutline.lineWidth	2
option add *zoomOutline.xor		yes

proc rbc::MarchingAnts { graph offset } {
    variable zoomInfo

    incr offset
    if { [$graph marker exists zoomOutline] } {
	$graph marker configure zoomOutline -dashoffset $offset 
	set interval $zoomInfo($graph,interval)
	set id [after $interval [list rbc::MarchingAnts $graph $offset]]
	set zoomInfo($graph,afterId) $id
    }
}

proc rbc::Box { graph } {
    variable zoomInfo

    if { $zoomInfo($graph,A,x) > $zoomInfo($graph,B,x) } { 
	set x1 [$graph xaxis invtransform $zoomInfo($graph,B,x)]
	set y1 [$graph yaxis invtransform $zoomInfo($graph,B,y)]
	set x2 [$graph xaxis invtransform $zoomInfo($graph,A,x)]
	set y2 [$graph yaxis invtransform $zoomInfo($graph,A,y)]
    } else {
................................................................................
}

proc rbc::ResetPostScript { graph } {
    foreach var { center landscape maxpect preview decorations padx 
	pady paperwidth paperheight width height colormode } {
	global $graph.$var
	set old [$graph postscript cget -$var]
	if {[catch {
	    $graph postscript configure -$var [set $graph.$var]
	}]} {
	    $graph postscript configure -$var $old
	    set $graph.$var $old
	}
    }
    $graph postscript output "out.ps"
    puts stdout "wrote file \"out.ps\"."
    flush stdout
}