Tk Source Code

Check-in [1008d171]
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:(Partial) implementation for TIP #510: Add Rbc to Tk, from René Zaumseil.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-510
Files: files | file ages | folders
SHA3-256: 1008d171bd2cbf59a6790e9fad14459bfd1d81ea49da7349b1da601602e9f9ea
User & Date: fvogel 2018-06-25 10:16:42
Context
2018-06-26
21:21
Add file library/rbc/graph.tcl provided by René Zaumseil check-in: f2524760 user: fvogel tags: tip-510
2018-06-25
10:16
(Partial) implementation for TIP #510: Add Rbc to Tk, from René Zaumseil. check-in: 1008d171 user: fvogel tags: tip-510
2018-06-18
07:49
Sync unix/tcl.m4 with Tcl version, and re-generate unix configure script check-in: f4ff72ef user: jan.nijtmans tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added doc/rbc/graph.n.md.












































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
[NAME]: #NAME
[SYNOPSIS]: #SYNOPSIS
[DESCRIPTION]: #DESCRIPTION
[INTRODUCTION]: #INTRODUCTION
[SYNTAX]: #SYNTAX
[EXAMPLE]: #EXAMPLE
[GRAPH OPERATIONS]: #GRAPHOPERATIONS
[GRAPH COMPONENTS]: #GRAPHCOMPONENTS
[AXIS COMPONENTS]: #AXISCOMPONENTS
[CROSSHAIRS COMPONENT]: #CROSSHAIRSCOMPONENT
[ELEMENT COMPONENTS]: #ELEMENTCOMPONENTS
[GRID COMPONENT]: #GRIDCOMPONENT
[LEGEND COMPONENT]: #LEGENDCOMPONENT
[PEN COMPONENTS]: #PENCOMPONENTS
[POSTSCRIPT COMPONENT]: #POSTSCRIPTCOMPONENT
[MARKER COMPONENTS]: #MARKERCOMPONENTS
[BITMAP MARKERS]: #BITMAPMARKERS
[IMAGE MARKERS]: #IMAGEMARKERS
[LINE MARKERS]: #LINEMARKERS
[POLYGON MARKERS]: #POLYGONMARKERS
[TEXT MARKERS]: #TEXTMARKERS
[WINDOW MARKERS]: #WINDOWMARKERS
[GRAPH COMPONENT BINDINGS]: #GRAPHCOMPONENTBINDINGS
[C LANGUAGE API]: #CLANGUAGEAPI
[SPEED TIPS]: #SPEEDTIPS
[LIMITATIONS]: #LIMITATIONS
[KEYWORDS]: #KEYWORDS

# graph(n) -- 2D graph for plotting X-Y coordinate data

   [NAME][]

     rbc::graph --

   [SYNOPSIS][]

   [DESCRIPTION][]

   [INTRODUCTION][]

        axis 
        crosshairs 
        element 
        grid 
        legend 
        marker 
        pen 
        postscript 

   [SYNTAX][]

   [EXAMPLE][] 

   [GRAPH OPERATIONS][]

        pathName axis operation ?arg?... 
        pathName bar elemName ?option value?... 
        pathName cget option 
        pathName configure ?option value?...

            -aspect width/height 
            -background color 
            -borderwidth pixels 
            -bottommargin pixels 
            -bufferelements boolean 
            -cursor cursor 
            -font fontName 
            -halo pixels 
            -height pixels 
            -invertxy boolean 
            -justify justify 
            -leftmargin pixels 
            -plotbackground color 
            -plotborderwidth pixels 
            -plotpadx pad 
            -plotpady pad 
            -plotrelief relief 
            -relief relief 
            -rightmargin pixels 
            -takefocus focus 
            -tile image 
            -title text 
            -topmargin pixels 
            -width pixels 

        pathName crosshairs operation ?arg? 
        pathName element operation ?arg?... 
        pathName extents item 
        pathName grid operation ?arg?... 
        pathName invtransform winX winY 
        pathName inside x y 
        pathName legend operation ?arg?... 
        pathName line operation arg... 
        pathName marker operation ?arg?... 
        pathName postscript operation ?arg?... 
        pathName snap ?switches? outputName

            -format format

                photo 
                wmf 
                emf 

            -height size 
            -width size 

        pathName transform x y 
        pathName xaxis operation ?arg?... 
        pathName x2axis operation ?arg?... 
        pathName yaxis operation ?arg?... 
        pathName y2axis operation ?arg?... 

   [GRAPH COMPONENTS][]

   [AXIS COMPONENTS][]

        pathName axis bind tagName ?sequence? ?command? 
        pathName axis cget axisName option 
        pathName axis configure axisName ?axisName?... ?option value?...

            -bindtags tagList 
            -color color 
            -command prefix 
            -descending boolean 
            -hide boolean 
            -justify justify 
            -limits formatStr 
            -linewidth pixels 
            -logscale boolean 
            -loose boolean 
            -majorticks majorList 
            -max value 
            -min value 
            -minorticks minorList 
            -rotate theta 
            -scrollcommand command 
            -scrollmax value 
            -scrollmin value 
            -showticks boolean 
            -stepsize value 
            -subdivisions number 
            -tickfont fontName 
            -ticklength pixels 
            -title text 
            -titlealternate boolean 
            -titlecolor color 
            -titlefont fontName 

        pathName axis create axisName ?option value?... 
        pathName axis delete ?axisName?... 
        pathName axis invtransform axisName value 
        pathName axis limits axisName 
        pathName axis names ?pattern?... 
        pathName axis transform axisName value 
        pathName axis view axisName 

        pathName axis cget option 
        pathName axis configure ?option value?... 
        pathName axis invtransform value 
        pathName axis limits 
        pathName axis transform value 
        pathName axis use ?axisName? 

   [CROSSHAIRS COMPONENT][]

        pathName crosshairs cget option 
        pathName crosshairs configure ?option value?...

            -color color 
            -dashes dashList 
            -hide boolean 
            -linewidth pixels 
            -position pos 

        pathName crosshairs off 
        pathName crosshairs on 
        pathName crosshairs toggle 

   [ELEMENT COMPONENTS][]

        pathName element activate elemName ?index?... 
        pathName element bind tagName ?sequence? ?command? 
        pathName element cget elemName option 
        pathName element closest x y varName ?option value?... ?elemName?...

            -along direction

                x 
                y 
                both 

            -halo pixels 
            -interpolate string

                no 
                yes 

        pathName element configure elemName ?elemName... ?option value?...

            -activepen penName 
            -bindtags tagList 
            -color color 
            -dashes dashList 
            -data coordList 
            -fill color 
            -hide boolean 
            -label text 
            -linewidth pixels 
            -mapx xAxis 
            -mapy yAxis 
            -offdash color 
            -outline color 
            -pen penname 
            -outlinewidth pixels 
            -pixels pixels 
            -scalesymbols boolean 
            -smooth smooth 
            -styles styleList 
            -symbol symbol 
            -trace direction 
            -weights wVec 
            -xdata xVec 
            -ydata yVec 

        pathName element create elemName ?option value?... 
        pathName element deactivate elemName ?elemName?... 
        pathName element delete ?elemName?... 
        pathName element exists elemName 
        pathName element names ?pattern?... 
        pathName element show ?nameList? 
        pathName element type elemName 

   [GRID COMPONENT][]

        pathName grid cget option 
        pathName grid configure ?option value?...

            -color color 
            -dashes dashList 
            -hide boolean 
            -linewidth pixels 
            -mapx xAxis 
            -mapy yAxis 
            -minor boolean 

            -raised boolean 

        pathName grid off 
        pathName grid on 
        pathName grid toggle 

   [LEGEND COMPONENT][]

        pathName legend activate pattern... 
        pathName legend bind tagName ?sequence? ?command? 
        pathName legend cget option 
        pathName legend configure ?option value?...

            -activebackground color 
            -activeborderwidth pixels 
            -activeforeground color 
            -activerelief relief 
            -anchor anchor

                left or right 
                top or bottom 
                @x,y 
                plotarea 

            -background color 
            -bindtags tagList 
            -borderwidth pixels 
            -font fontName 
            -foreground color 
            -hide boolean 
            -ipadx pad 
            -ipady pad 
            -padx pad 
            -pady pad 
            -position pos 
            -raised boolean 
            -relief relief 

        pathName legend deactivate pattern... 
        pathName legend get pos 

   [PEN COMPONENTS][]

        pathName pen cget penName option 
        pathName pen configure penName ?penName... ?option value?...

            -color color 
            -dashes dashList 
            -fill color 
            -linewidth pixels 
            -offdash color 
            -outline color 
            -outlinewidth pixels 
            -pixels pixels 
            -symbol symbol 
            -type elemType 

        pathName pen create penName ?option value?... 
        pathName pen delete ?penName?... 
        pathName pen names ?pattern?... 

   [POSTSCRIPT COMPONENT][]

        pathName postscript cget option 
        pathName postscript configure ?option value?...

            -center boolean 
            -colormap varName 
            -colormode mode 
            -fontmap varName 
            -decorations boolean 
            -height pixels 
            -landscape boolean 
            -maxpect boolean 
            -padx pad 
            -pady pad 
            -paperheight pixels 
            -paperwidth pixels 
            -width pixels 

        pathName postscript output ?fileName? ?option value?... 

   [MARKER COMPONENTS][]

        pathName marker after markerId ?afterId? 
        pathName marker before markerId ?beforeId? 
        pathName marker bind tagName ?sequence? ?command? 
        pathName marker cget option 
        pathName marker configure markerId ?option value?...

            -bindtags tagList 
            -coords coordList 
            -element elemName 
            -hide boolean 
            -mapx xAxis 
            -mapy yAxis 
            -name markerId 
            -under boolean 
            -xoffset pixels 
            -yoffset pixels 

        pathName marker create type ?option value?... 
        pathName marker delete ?name?... 
        pathName marker exists markerId 
        pathName marker names ?pattern? 
        pathName marker type markerId 

   [BITMAP MARKERS][]

        -background color 
        -bitmap bitmap 
        -fill color 
        -foreground color 
        -mask mask 
        -outline color 
        -rotate theta 

   [IMAGE MARKERS][]

        -anchor anchor 
        -image image 

   [LINE MARKERS][]

        -dashes dashList 
        -fill color 
        -linewidth pixels 
        -outline color 
        -stipple bitmap 

   [POLYGON MARKERS][]

        -dashes dashList 
        -fill color 
        -linewidth pixels 
        -outline color 
        -stipple bitmap 

   [TEXT MARKERS][]

        -anchor anchor 
        -background color 
        -font fontName 
        -fill color 
        -foreground color 
        -justify justify 
        -outline color 
        -padx pad 
        -pady pad 
        -rotate theta 
        -text text 

   [WINDOW MARKERS][]

        -anchor anchor 
        -height pixels 
        -width pixels 
        -window pathName 

   [GRAPH COMPONENT BINDINGS][]

   [C LANGUAGE API][]

   [SPEED TIPS][]

   [LIMITATIONS][]

   [KEYWORDS][]

## NAME <a name="NAME"></a>

graph - 2D graph for plotting X-Y coordinate data.

## SYNOPSIS <a name="SYNOPSIS"></a>

**graph** *pathName ?option value?...*

## DESCRIPTION <a name="DESCRIPTION"></a>

The graph command creates a graph for plotting two-dimensional data (X-Y coordinates). It has many configurable components: coordinate axes, elements, legend, grid lines, cross hairs, etc. They allow you to customize the look and feel of the graph.

## INTRODUCTION <a name="INTRODUCTION"></a>

The graph command creates a new window for plotting two-dimensional data (X-Y coordinates). Data points are plotted in a rectangular area displayed in the center of the new window. This is the plotting area. The coordinate axes are drawn in the margins around the plotting area. By default, the legend is displayed in the right margin. The title is displayed in top margin.

The graph widget is composed of several components: coordinate axes, data elements, legend, grid, cross hairs, pens, postscript, and annotation markers.

**axis**
    The graph has four standard axes (x, x2, y, and y2), but you can create and display any number of axes. Axes control what region of data is displayed and how the data is scaled. Each axis consists of the axis line, title, major and minor ticks, and tick labels. Tick labels display the value at each major tick.

**crosshairs**
    Cross hairs are used to position the mouse pointer relative to the X and Y coordinate axes. Two perpendicular lines, intersecting at the current location of the mouse, extend across the plotting area to the coordinate axes.

**element**
    An element represents a set of data points. Elements can be plotted with a symbol at each data point and lines connecting the points. The appearance of the element, such as its symbol, line width, and color is configurable.

**grid**
    Extends the major and minor ticks of the X-axis and/or Y-axis across the plotting area.

**legend**
    The legend displays the name and symbol of each data element. The legend can be drawn in any margin or in the plotting area.

**marker**
    Markers are used annotate or highlight areas of the graph. For example, you could use a polygon marker to fill an area under a curve, or a text marker to label a particular data point. Markers come in various forms: text strings, bitmaps, connected line segments, images, polygons, or embedded widgets.

**pen**
    Pens define attributes (both symbol and line style) for elements. Data elements use pens to specify how they should be drawn. A data element may use many pens at once. Here, the particular pen used for a data point is determined from each element's weight vector (see the element's -weight and -style options).

**postscript**
    The widget can generate encapsulated PostScript output. This component has several options to configure how the PostScript is generated.

## SYNTAX <a name="SYNTAX"></a>

**graph** *pathName ?option value?...*

The graph command creates a new window pathName and makes it into a graph widget. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist. Additional options may be specified on the command line or in the option database to configure aspects of the graph such as its colors and font. See the configure operation below for the exact details about what option and value pairs are valid.

If successful, graph returns the path name of the widget. It also creates a new Tcl command by the same name. You can use this command to invoke various operations that query or modify the graph. The general form is:

**pathName** *operation ?arg?...*

Both operation and its arguments determine the exact behavior of the command. The operations available for the graph are described in the section.

The command can also be used to access components of the graph.

**pathName component** *operation ?arg?...*

The operation, now located after the name of the component, is the function to be performed on that component. Each component has its own set of operations that manipulate that component. They will be described below in their own sections.

## EXAMPLE <a name="EXAMPLE"></a>

The graph command creates a new graph.

`
# Create a new graph.  Plotting area is black.
graph .g -plotbackground black
`

A new Tcl command .g is also created. This command can be used to query and modify the graph. For example, to change the title of the graph to "My Plot", you use the new command and the graph's configure operation.

 # Change the title.
	.g configure -title "My Plot"

A graph has several components. To access a particular component you use the component's name. For example, to add data elements, you use the new command and the element component.

 # Create a new element named "line1"
	.g element create line1 \
	-xdata { 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 } \
	-ydata { 26.18 50.46 72.85 93.31 111.86 128.47 143.14 
		155.85 166.60 175.38 }

The element's X-Y coordinates are specified using lists of numbers. Alternately, BLT vectors could be used to hold the X-Y coordinates.

 # Create two vectors and add them to the graph.
vector xVec yVec
xVec set { 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 }
yVec set { 26.18 50.46 72.85 93.31 111.86 128.47 143.14 155.85 
	166.60 175.38 }
	.g element create line1 -xdata xVec -ydata yVec

The advantage of using vectors is that when you modify one, the graph is automatically redrawn to reflect the new values.

 # Change the y coordinate of the first point.
set yVector(0) 25.18

An element named e1 is now created in .b. It is automatically added to the display list of elements. You can use this list to control in what order elements are displayed. To query or reset the element display list, you use the element's show operation.

 # Get the current display list 
set elemList [.b element show]
 # Remove the first element so it won't be displayed.
	.b element show [lrange $elemList 0 end]

The element will be displayed by as many bars as there are data points (in this case there are ten). The bars will be drawn centered at the x-coordinate of the data point. All the bars will have the same attributes (colors, stipple, etc). The width of each bar is by default one unit. You can change this with using the -barwidth option.

 # Change the X-Y coordinates of the first point.
set xVec(0) 0.18
set yVec(0) 25.18

An element named line1 is now created in .g. By default, the element's label in the legend will be also line1. You can change the label, or specify no legend entry, again using the element's configure operation.

 # Don't display "line1" in the legend.
	.g element configure line1 -label ""

You can configure more than just the element's label. An element has many attributes such as symbol type and size, dashed or solid lines, colors, line width, etc.

.g element configure line1 -symbol square -color red \
	-dashes { 2 4 2 } -linewidth 2 -pixels 2c

Four coordinate axes are automatically created: x, x2, y, and y2. And by default, elements are mapped onto the axes x and y. This can be changed with the -mapx and -mapy options.

 # Map "line1" on the alternate Y-axis "y2".
	.g element configure line1 -mapy y2

Axes can be configured in many ways too. For example, you change the scale of the Y-axis from linear to log using the axis component.

 # Y-axis is log scale.
	.g axis configure y -logscale yes

One important way axes are used is to zoom in on a particular data region. Zooming is done by simply specifying new axis limits using the -min and -max configuration options.

.g axis configure x -min 1.0 -max 1.5
	.g axis configure y -min 12.0 -max 55.15

To zoom interactively, you link the axis configure operations with some user interaction (such as pressing the mouse button), using the bind command. To convert between screen and graph coordinates, use the invtransform operation.

 # Click the button to set a new minimum 
bind .g <ButtonPress-1> { 
    %W axis configure x -min [%W axis invtransform x %x]
    %W axis configure x -min [%W axis invtransform x %y]
}

By default, the limits of the axis are determined from data values. To reset back to the default limits, set the -min and -max options to the empty value.

 # Reset the axes to autoscale again.
	.g axis configure x -min {} -max {}
	.g axis configure y -min {} -max {}

By default, the legend is drawn in the right margin. You can change this or any legend configuration options using the legend component.

 # Configure the legend font, color, and relief
	.g legend configure -position left -relief raised \
	-font fixed -fg blue

To prevent the legend from being displayed, turn on the -hide option.

 # Don't display the legend.
	.g legend configure -hide yes\fR

The graph widget has simple drawing procedures called markers. They can be used to highlight or annotate data in the graph. The types of markers available are bitmaps, images, polygons, lines, or windows. Markers can be used, for example, to mark or brush points. In this example, is a text marker that labels the data first point. Markers are created using the marker component.

 # Create a label for the first data point of "line1".
	.g marker create text -name first_marker -coords { 0.2 26.18 } \
	-text "start" -anchor se -xoffset -10 -yoffset -10

This creates a text marker named first_marker. It will display the text "start" near the coordinates of the first data point. The -anchor, -xoffset, and -yoffset options are used to display the marker above and to the left of the data point, so that the data point isn't covered by the marker. By default, markers are drawn last, on top of data. You can change this with the -under option.

 # Draw the label before elements are drawn.
	.g marker configure first_marker -under yes

You can add cross hairs or grid lines using the crosshairs and grid components.

 # Display both cross hairs and grid lines.
	.g crosshairs configure -hide no -color red
	.g grid configure -hide no -dashes { 2 2 }
 # Set up a binding to reposition the crosshairs.
bind .g <Motion> {
    .g crosshairs configure -position @%x,%y
}

The crosshairs are repositioned as the mouse pointer is moved in the graph. The pointer X-Y coordinates define the center of the crosshairs.

Finally, to get hardcopy of the graph, use the postscript component.

 # Print the graph into file "file.ps"
	.g postscript output file.ps -maxpect yes -decorations no

This generates a file file.ps containing the encapsulated PostScript of the graph. The option -maxpect says to scale the plot to the size of the page. Turning off the -decorations option denotes that no borders or color backgrounds should be drawn (i.e. the background of the margins, legend, and plotting area will be white).

## GRAPH OPERATIONS <a name="GRAPHOPERATIONS"></a>

pathName axis operation ?arg?...
    See the section.

pathName bar elemName ?option value?...
    Creates a new barchart element elemName. It's an error if an element elemName already exists. See the manual for barchart for details about what option and value pairs are valid.

pathName cget option
    Returns the current value of the configuration option given by option. Option may be any option described below for the configure operation.

pathName configure ?option value?...
    Queries or modifies the configuration options of the graph. If option isn't specified, a list describing the current options for pathName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the option option is set to value. The following options are valid.

    -aspect width/height
        Force a fixed aspect ratio of width/height, a floating point number.

    -background color
        Sets the background color. This includes the margins and legend, but not the plotting area.

    -borderwidth pixels
        Sets the width of the 3-D border around the outside edge of the widget. The -relief option determines if the border is to be drawn. The default is 2.

    -bottommargin pixels
        If non-zero, overrides the computed size of the margin extending below the X-coordinate axis. If pixels is 0, the automatically computed size is used. The default is 0.

    -bufferelements boolean
        Indicates whether an internal pixmap to buffer the display of data elements should be used. If boolean is true, data elements are drawn to an internal pixmap. This option is especially useful when the graph is redrawn frequently while the remains data unchanged (for example, moving a marker across the plot). See the section. The default is 1.

    -cursor cursor
        Specifies the widget's cursor. The default cursor is crosshair.

    -font fontName
        Specifies the font of the graph title. The default is *-Helvetica-Bold-R-Normal-*-18-180-*.

    -halo pixels
        Specifies a maximum distance to consider when searching for the closest data point (see the element's closest operation below). Data points further than pixels away are ignored. The default is 0.5i.

    -height pixels
        Specifies the requested height of widget. The default is 4i.

    -invertxy boolean
        Indicates whether the placement X-axis and Y-axis should be inverted. If boolean is true, the X and Y axes are swapped. The default is 0.

    -justify justify
        Specifies how the title should be justified. This matters only when the title contains more than one line of text. Justify must be left, right, or center. The default is center.

    -leftmargin pixels
        If non-zero, overrides the computed size of the margin extending from the left edge of the window to the Y-coordinate axis. If pixels is 0, the automatically computed size is used. The default is 0.

    -plotbackground color
        Specifies the background color of the plotting area. The default is white.

    -plotborderwidth pixels
        Sets the width of the 3-D border around the plotting area. The -plotrelief option determines if a border is drawn. The default is 2.

    -plotpadx pad
        Sets the amount of padding to be added to the left and right sides of the plotting area. Pad can be a list of one or two screen distances. If pad has two elements, the left side of the plotting area entry is padded by the first distance and the right side by the second. If pad is just one distance, both the left and right sides are padded evenly. The default is 8.

    -plotpady pad
        Sets the amount of padding to be added to the top and bottom of the plotting area. Pad can be a list of one or two screen distances. If pad has two elements, the top of the plotting area is padded by the first distance and the bottom by the second. If pad is just one distance, both the top and bottom are padded evenly. The default is 8.

    -plotrelief relief
        Specifies the 3-D effect for the plotting area. Relief specifies how the interior of the plotting area should appear relative to rest of the graph; for example, raised means the plot should appear to protrude from the graph, relative to the surface of the graph. The default is sunken.

    -relief relief
        Specifies the 3-D effect for the graph widget. Relief specifies how the graph should appear relative to widget it is packed into; for example, raised means the graph should appear to protrude. The default is flat.

    -rightmargin pixels
        If non-zero, overrides the computed size of the margin extending from the plotting area to the right edge of the window. By default, the legend is drawn in this margin. If pixels is 0, the automatically computed size is used. The default is 0.

    -takefocus focus
        Provides information used when moving the focus from window to window via keyboard traversal (e.g., Tab and Shift-Tab). If focus is 0, this means that this window should be skipped entirely during keyboard traversal. 1 means that the this window should always receive the input focus. An empty value means that the traversal scripts make the decision whether to focus on the window. The default is "".

    -tile image
        Specifies a tiled background for the widget. If image isn't "", the background is tiled using image. Otherwise, the normal background color is drawn (see the -background option). Image must be an image created using the Tk image command. The default is "".

    -title text
        Sets the title to text. If text is "", no title will be displayed.

    -topmargin pixels
        If non-zero, overrides the computed size of the margin above the x2 axis. If pixels is 0, the automatically computed size is used. The default is 0.

    -width pixels
        Specifies the requested width of the widget. The default is 5i.

pathName crosshairs operation ?arg?
    See the section.

pathName element operation ?arg?...
    See the section.

pathName extents item
    Returns the size of a particular item in the graph. Item must be either leftmargin, rightmargin, topmargin, bottommargin, plotwidth, or plotheight.

pathName grid operation ?arg?...
    See the section.

pathName invtransform winX winY
    Performs an inverse coordinate transformation, mapping window coordinates back to graph coordinates, using the standard X-axis and Y-axis. Returns a list of containing the X-Y graph coordinates.

pathName inside x y
    Returns 1 is the designated screen coordinate (x and y) is inside the plotting area and 0 otherwise.

pathName legend operation ?arg?...
    See the section.

pathName line operation arg...
    The operation is the same as element.

pathName marker operation ?arg?...
    See the section.

pathName postscript operation ?arg?...
    See the section.

pathName snap ?switches? outputName
    Takes a snapshot of the graph, saving the output in outputName. The following switches are available.

    -format format
        Specifies how the snapshot is output. Format may be one of the following listed below. The default is photo.

        photo
            Saves a Tk photo image. OutputName represents the name of a Tk photo image that must already have been created.

        wmf
            Saves an Aldus Placeable Metafile. OutputName represents the filename where the metafile is written. If outputName is CLIPBOARD, then output is written directly to the Windows clipboard. This format is available only under Microsoft Windows.

        emf
            Saves an Enhanced Metafile. OutputName represents the filename where the metafile is written. If outputName is CLIPBOARD, then output is written directly to the Windows clipboard. This format is available only under Microsoft Windows.

    -height size
        Specifies the height of the graph. Size is a screen distance. The graph will be redrawn using this dimension, rather than its current window height.

    -width size
        Specifies the width of the graph. Size is a screen distance. The graph will be redrawn using this dimension, rather than its current window width.

pathName transform x y
    Performs a coordinate transformation, mapping graph coordinates to window coordinates, using the standard X-axis and Y-axis. Returns a list containing the X-Y screen coordinates.

pathName xaxis operation ?arg?...

pathName x2axis operation ?arg?...

pathName yaxis operation ?arg?...

pathName y2axis operation ?arg?...
    See the section.

## GRAPH COMPONENTS <a name="GRAPHCOMPONENTS"></a>

A graph is composed of several components: coordinate axes, data elements, legend, grid, cross hairs, postscript, and annotation markers. Instead of one big set of configuration options and operations, the graph is partitioned, where each component has its own configuration options and operations that specifically control that aspect or part of the graph.

## AXIS COMPONENTS <a name="AXISCOMPONENTS"></a>

Four coordinate axes are automatically created: two X-coordinate axes (x and x2) and two Y-coordinate axes (y, and y2). By default, the axis x is located in the bottom margin, y in the left margin, x2 in the top margin, and y2 in the right margin.

An axis consists of the axis line, title, major and minor ticks, and tick labels. Major ticks are drawn at uniform intervals along the axis. Each tick is labeled with its coordinate value. Minor ticks are drawn at uniform intervals within major ticks.

The range of the axis controls what region of data is plotted. Data points outside the minimum and maximum limits of the axis are not plotted. By default, the minimum and maximum limits are determined from the data, but you can reset either limit.

You can have several axes. To create an axis, invoke the axis component and its create operation.

 # Create a new axis called "tempAxis"
	.g axis create tempAxis

You map data elements to an axis using the element's -mapy and -mapx configuration options. They specify the coordinate axes an element is mapped onto.

 # Now map the tempAxis data to this axis.
	.g element create "e1" -xdata $x -ydata $y -mapy tempAxis

Any number of axes can be displayed simultaneously. They are drawn in the margins surrounding the plotting area. The default axes x and y are drawn in the bottom and left margins. The axes x2 and y2 are drawn in top and right margins. By default, only x and y are shown. Note that the axes can have different scales.

To display a different axis or more than one axis, you invoke one of the following components: xaxis, yaxis, x2axis, and y2axis. Each component has a use operation that designates the axis (or axes) to be drawn in that corresponding margin: xaxis in the bottom, yaxis in the left, x2axis in the top, and y2axis in the right.

 # Display the axis tempAxis in the left margin.
	.g yaxis use tempAxis

The use operation takes a list of axis names as its last argument. This is the list of axes to be drawn in this margin.

You can configure axes in many ways. The axis scale can be linear or logarithmic. The values along the axis can either monotonically increase or decrease. If you need custom tick labels, you can specify a Tcl procedure to format the label any way you wish. You can control how ticks are drawn, by changing the major tick interval or the number of minor ticks. You can define non-uniform tick intervals, such as for time-series plots.

pathName axis bind tagName ?sequence? ?command?
    Associates command with tagName such that whenever the event sequence given by sequence occurs for an axis with this tag, command will be invoked. The syntax is similar to the bind command except that it operates on graph axes, rather than widgets. See the bind manual entry for complete details on sequence and the substitutions performed on command before invoking it.

    If all arguments are specified then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is + then command augments an existing binding rather than replacing it. If no command argument is provided then the command currently associated with tagName and sequence (it's an error occurs if there's no such binding) is returned. If both command and sequence are missing then a list of all the event sequences for which bindings have been defined for tagName.

pathName axis cget axisName option
    Returns the current value of the option given by option for axisName. Option may be any option described below for the axis configure operation.

pathName axis configure axisName ?axisName?... ?option value?...
    Queries or modifies the configuration options of axisName. Several axes can be changed. If option isn't specified, a list describing all the current options for axisName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the axis option option is set to value. The following options are valid for axes.

    -bindtags tagList
        Specifies the binding tags for the axis. TagList is a list of binding tag names. The tags and their order will determine how events for axes are handled. Each tag in the list matching the current event sequence will have its Tcl command executed. Implicitly the name of the element is always the first tag in the list. The default value is all.

    -color color
        Sets the color of the axis and tick labels. The default is black.

    -command prefix
        Specifies a Tcl command to be invoked when formatting the axis tick labels. Prefix is a string containing the name of a Tcl proc and any extra arguments for the procedure. This command is invoked for each major tick on the axis. Two additional arguments are passed to the procedure: the pathname of the widget and the current the numeric value of the tick. The procedure returns the formatted tick label. If "" is returned, no label will appear next to the tick. You can get the standard tick labels again by setting prefix to "". The default is "".

        Please note that this procedure is invoked while the graph is redrawn. You may query configuration options. But do not them, because this can have unexpected results.

    -descending boolean
        Indicates whether the values along the axis are monotonically increasing or decreasing. If boolean is true, the axis values will be decreasing. The default is 0.

    -hide boolean
        Indicates if the axis is displayed. If boolean is false the axis will be displayed. Any element mapped to the axis is displayed regardless. The default value is 0.

    -justify justify
        Specifies how the axis title should be justified. This matters only when the axis title contains more than one line of text. Justify must be left, right, or center. The default is center.

    -limits formatStr
        Specifies a printf-like description to format the minimum and maximum limits of the axis. The limits are displayed at the top/bottom or left/right sides of the plotting area. FormatStr is a list of one or two format descriptions. If one description is supplied, both the minimum and maximum limits are formatted in the same way. If two, the first designates the format for the minimum limit, the second for the maximum. If "" is given as either description, then the that limit will not be displayed. The default is "".

    -linewidth pixels
        Sets the width of the axis and tick lines. The default is 1 pixel.

    -logscale boolean
        Indicates whether the scale of the axis is logarithmic or linear. If boolean is true, the axis is logarithmic. The default scale is linear.

    -loose boolean
        Indicates whether the limits of the axis should fit the data points tightly, at the outermost data points, or loosely, at the outer tick intervals. If the axis limit is set with the -min or -max option, the axes are displayed tightly. If boolean is true, the axis range is "loose". The default is 0.

    -majorticks majorList
        Specifies where to display major axis ticks. You can use this option to display ticks at non-uniform intervals. MajorList is a list of axis coordinates designating the location of major ticks. No minor ticks are drawn. If majorList is "", major ticks will be automatically computed. The default is "".

    -max value
        Sets the maximum limit of axisName. Any data point greater than value is not displayed. If value is "", the maximum limit is calculated using the largest data value. The default is "".

    -min value
        Sets the minimum limit of axisName. Any data point less than value is not displayed. If value is "", the minimum limit is calculated using the smallest data value. The default is "".

    -minorticks minorList
        Specifies where to display minor axis ticks. You can use this option to display minor ticks at non-uniform intervals. MinorList is a list of real values, ranging from 0.0 to 1.0, designating the placement of a minor tick. No minor ticks are drawn if the -majortick option is also set. If minorList is "", minor ticks will be automatically computed. The default is "".

    -rotate theta
        Specifies the how many degrees to rotate the axis tick labels. Theta is a real value representing the number of degrees to rotate the tick labels. The default is 0.0 degrees.

    -scrollcommand command
        Specify the prefix for a command used to communicate with scrollbars for this axis, such as .sbar set.

    -scrollmax value
        Sets the maximum limit of the axis scroll region. If value is "", the maximum limit is calculated using the largest data value. The default is "".

    -scrollmin value
        Sets the minimum limit of axis scroll region. If value is "", the minimum limit is calculated using the smallest data value. The default is "".

    -showticks boolean
        Indicates whether axis ticks should be drawn. If boolean is true, ticks are drawn. If false, only the axis line is drawn. The default is 1.

    -stepsize value
        Specifies the interval between major axis ticks. If value isn't a valid interval (must be less than the axis range), the request is ignored and the step size is automatically calculated.

    -subdivisions number
        Indicates how many minor axis ticks are to be drawn. For example, if number is two, only one minor tick is drawn. If number is one, no minor ticks are displayed. The default is 2.

    -tickfont fontName
        Specifies the font for axis tick labels. The default is *-Courier-Bold-R-Normal-*-100-*.

    -ticklength pixels
        Sets the length of major and minor ticks (minor ticks are half the length of major ticks). If pixels is less than zero, the axis will be inverted with ticks drawn pointing towards the plot. The default is 0.1i.

    -title text
        Sets the title of the axis. If text is "", no axis title will be displayed.

    -titlealternate boolean
        Indicates to display the axis title in its alternate location. Normally the axis title is centered along the axis. This option places the axis either to the right (horizontal axes) or above (vertical axes) the axis. The default is 0.

    -titlecolor color
        Sets the color of the axis title. The default is black.

    -titlefont fontName
        Specifies the font for axis title. The default is *-Helvetica-Bold-R-Normal-*-14-140-*.

        Axis configuration options may be also be set by the option command. The resource class is Axis. The resource names are the names of the axes (such as x or x2).

        option add *Graph.Axis.Color  blue
        option add *Graph.x.LogScale  true
        option add *Graph.x2.LogScale false

pathName axis create axisName ?option value?...
    Creates a new axis by the name axisName. No axis by the same name can already exist. Option and value are described in above in the axis configure operation.

pathName axis delete ?axisName?...
    Deletes the named axes. An axis is not really deleted until it is not longer in use, so it's safe to delete axes mapped to elements.

pathName axis invtransform axisName value
    Performs the inverse transformation, changing the screen coordinate value to a graph coordinate, mapping the value mapped to axisName. Returns the graph coordinate.

pathName axis limits axisName
    Returns a list of the minimum and maximum limits for axisName. The order of the list is min max.

pathName axis names ?pattern?...
    Returns a list of axes matching zero or more patterns. If no pattern argument is give, the names of all axes are returned.

pathName axis transform axisName value
    Transforms the coordinate value to a screen coordinate by mapping the it to axisName. Returns the transformed screen coordinate.

pathName axis view axisName
    Change the viewable area of this axis. Use as an argument to a scrollbar's "-command".

The default axes are x, y, x2, and y2. But you can display more than four axes simultaneously. You can also swap in a different axis with use operation of the special axis components: xaxis, x2axis, yaxis, and y2axis.

.g create axis temp
	.g create axis time
	...
	.g xaxis use temp
	.g yaxis use time

Only the axes specified for use are displayed on the screen.

The xaxis, x2axis, yaxis, and y2axis components operate on an axis location rather than a specific axis like the more general axis component does. They implicitly control the axis that is currently using to that location. By default, xaxis uses the x axis, yaxis uses y, x2axis uses x2, and y2axis uses y2. When more than one axis is displayed in a margin, it represents the first axis displayed.

The following operations are available for axes. They mirror exactly the operations of the axis component. The axis argument must be xaxis, x2axis, yaxis, or y2axis. This feature is deprecated since more than one axis can now be used a margin. You should only use the xaxis, x2axis, yaxis, and y2axis components with the use operation. For all other operations, use the general axis component instead.

pathName axis cget option

pathName axis configure ?option value?...

pathName axis invtransform value

pathName axis limits

pathName axis transform value

pathName axis use ?axisName?
    Designates the axis axisName is to be displayed at this location. AxisName can not be already in use at another location. This command returns the name of the axis currently using this location.

## CROSSHAIRS COMPONENT <a name="CROSSHAIRSCOMPONENT"></a>

Cross hairs consist of two intersecting lines (one vertical and one horizontal) drawn completely across the plotting area. They are used to position the mouse in relation to the coordinate axes. Cross hairs differ from line markers in that they are implemented using XOR drawing primitives. This means that they can be quickly drawn and erased without redrawing the entire graph. Note that crosshair are enabled by calling Blt_Crosshairs and turned off by calling Blt_ResetCrosshairs. Similarly call Blt_ZoomStack for zooming.

The following operations are available for cross hairs:

pathName crosshairs cget option
    Returns the current value of the cross hairs configuration option given by option. Option may be any option described below for the cross hairs configure operation.

pathName crosshairs configure ?option value?...
    Queries or modifies the configuration options of the cross hairs. If option isn't specified, a list describing all the current options for the cross hairs is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the cross hairs option option is set to value. The following options are available for cross hairs.

    -color color
        Sets the color of the cross hairs. The default is black.

    -dashes dashList
        Sets the dash style of the cross hairs. DashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the cross hair lines. Each number must be between 1 and 255. If dashList is "", the cross hairs will be solid lines.

    -hide boolean
        Indicates whether cross hairs are drawn. If boolean is true, cross hairs are not drawn. The default is yes.

    -linewidth pixels
        Set the width of the cross hair lines. The default is 1.

    -position pos
        Specifies the screen position where the cross hairs intersect. Pos must be in the form "@x,y", where x and y are the window coordinates of the intersection.

        Cross hairs configuration options may be also be set by the option command. The resource name and class are crosshairs and Crosshairs respectively.

        option add *Graph.Crosshairs.LineWidth 2
        option add *Graph.Crosshairs.Color     red

pathName crosshairs off
    Turns off the cross hairs.

pathName crosshairs on
    Turns on the display of the cross hairs.

pathName crosshairs toggle
    Toggles the current state of the cross hairs, alternately mapping and unmapping the cross hairs.

## ELEMENT COMPONENTS <a name="ELEMENTCOMPONENTS"></a>

A data element represents a set of data. It contains x and y vectors containing the coordinates of the data points. Elements can be displayed with a symbol at each data point and lines connecting the points. Elements also control the appearance of the data, such as the symbol type, line width, color etc.

When new data elements are created, they are automatically added to a list of displayed elements. The display list controls what elements are drawn and in what order.

The following operations are available for elements.

pathName element activate elemName ?index?...
    Specifies the data points of element elemName to be drawn using active foreground and background colors. ElemName is the name of the element and index is a number representing the index of the data point. If no indices are present then all data points become active.

pathName element bind tagName ?sequence? ?command?
    Associates command with tagName such that whenever the event sequence given by sequence occurs for an element with this tag, command will be invoked. The syntax is similar to the bind command except that it operates on graph elements, rather than widgets. See the bind manual entry for complete details on sequence and the substitutions performed on command before invoking it.

    If all arguments are specified then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is + then command augments an existing binding rather than replacing it. If no command argument is provided then the command currently associated with tagName and sequence (it's an error occurs if there's no such binding) is returned. If both command and sequence are missing then a list of all the event sequences for which bindings have been defined for tagName.

pathName element cget elemName option
    Returns the current value of the element configuration option given by option. Option may be any of the options described below for the element configure operation.

pathName element closest x y varName ?option value?... ?elemName?...
    Searches for the data point closest to the window coordinates x and y. By default, all elements are searched. Hidden elements (see the -hide option is false) are ignored. You can limit the search by specifying only the elements you want to be considered. ElemName must be the name of an element that is not be hidden. VarName is the name of a Tcl array variable and will contain the search results: the name of the closest element, the index of the closest data point, and the graph coordinates of the point. Returns 0, if no data point within the threshold distance can be found, otherwise 1 is returned. The following option-value pairs are available.

    -along direction
        Search for the closest element using the following criteria:

        x
            Find closest element vertically from the given X-coordinate.

        y
            Find the closest element horizontally from the given Y-coordinate.

        both
            Find the closest element for the given point (using both the X and Y coordinates).

    -halo pixels
        Specifies a threshold distance where selected data points are ignored. Pixels is a valid screen distance, such as 2 or 1.2i. If this option isn't specified, then it defaults to the value of the graph's -halo option.

    -interpolate string
        Indicates whether to consider projections that lie along the line segments connecting data points when searching for the closest point. The default value is 0. The values for string are described below.

        no
            Search only for the closest data point.

        yes
            Search includes projections that lie along the line segments connecting the data points.

pathName element configure elemName ?elemName... ?option value?...
    Queries or modifies the configuration options for elements. Several elements can be modified at the same time. If option isn't specified, a list describing all the current options for elemName is returned. If option is specified, but not value, then a list describing the option option is returned. If one or more option and value pairs are specified, then for each pair, the element option option is set to value. The following options are valid for elements.

    -activepen penName
        Specifies pen to use to draw active element. If penName is "", no active elements will be drawn. The default is activeLine.

    -bindtags tagList
        Specifies the binding tags for the element. TagList is a list of binding tag names. The tags and their order will determine how events are handled for elements. Each tag in the list matching the current event sequence will have its Tcl command executed. Implicitly the name of the element is always the first tag in the list. The default value is all.

    -color color
        Sets the color of the traces connecting the data points.

    -dashes dashList
        Sets the dash style of element line. DashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the element line. Each number must be between 1 and 255. If dashList is "", the lines will be solid.

    -data coordList
        Specifies the X-Y coordinates of the data. CoordList is a list of numeric expressions representing the X-Y coordinate pairs of each data point.

    -fill color
        Sets the interior color of symbols. If color is "", then the interior of the symbol is transparent. If color is defcolor, then the color will be the same as the -color option. The default is defcolor.

    -hide boolean
        Indicates whether the element is displayed. The default is no.

    -label text
        Sets the element's label in the legend. If text is "", the element will have no entry in the legend. The default label is the element's name.

    -linewidth pixels
        Sets the width of the connecting lines between data points. If pixels is 0, no connecting lines will be drawn between symbols. The default is 0.

    -mapx xAxis
        Selects the X-axis to map the element's X-coordinates onto. XAxis must be the name of an axis. The default is x.

    -mapy yAxis
        Selects the Y-axis to map the element's Y-coordinates onto. YAxis must be the name of an axis. The default is y.

    -offdash color
        Sets the color of the stripes when traces are dashed (see the -dashes option). If color is "", then the "off" pixels will represent gaps instead of stripes. If color is defcolor, then the color will be the same as the -color option. The default is defcolor.

    -outline color
        Sets the color or the outline around each symbol. If color is "", then no outline is drawn. If color is defcolor, then the color will be the same as the -color option. The default is defcolor.

    -pen penname
        Set the pen to use for this element.

    -outlinewidth pixels
        Sets the width of the outline bordering each symbol. If pixels is 0, no outline will be drawn. The default is 1.

    -pixels pixels
        Sets the size of symbols. If pixels is 0, no symbols will be drawn. The default is 0.125i.

    -scalesymbols boolean
        If boolean is true, the size of the symbols drawn for elemName will change with scale of the X-axis and Y-axis. At the time this option is set, the current ranges of the axes are saved as the normalized scales (i.e scale factor is 1.0) and the element is drawn at its designated size (see the -pixels option). As the scale of the axes change, the symbol will be scaled according to the smaller of the X-axis and Y-axis scales. If boolean is false, the element's symbols are drawn at the designated size, regardless of axis scales. The default is 0.

    -smooth smooth
        Specifies how connecting line segments are drawn between data points. Smooth can be either linear, step, natural, or quadratic. If smooth is linear, a single line segment is drawn, connecting both data points. When smooth is step, two line segments are drawn. The first is a horizontal line segment that steps the next X-coordinate. The second is a vertical line, moving to the next Y-coordinate. Both natural and quadratic generate multiple segments between data points. If natural, the segments are generated using a cubic spline. If quadratic, a quadratic spline is used. The default is linear.

    -styles styleList
        Specifies what pen to use based on the range of weights given. StyleList is a list of style specifications. Each style specification, in turn, is a list consisting of a pen name, and optionally a minimum and maximum range. Data points whose weight (see the -weight option) falls in this range, are drawn with this pen. If no range is specified it defaults to the index of the pen in the list. Note that this affects only symbol attributes. Line attributes, such as line width, dashes, etc. are ignored.

    -symbol symbol
        Specifies the symbol for data points. Symbol can be either square, circle, diamond, plus, cross, splus, scross, triangle, "" (where no symbol is drawn), or a bitmap. Bitmaps are specified as "source ?mask?", where source is the name of the bitmap, and mask is the bitmap's optional mask. The default is circle.

    -trace direction
        Indicates whether connecting lines between data points (whose X-coordinate values are either increasing or decreasing) are drawn. Direction must be increasing, decreasing, or both. For example, if direction is increasing, connecting lines will be drawn only between those data points where X-coordinate values are monotonically increasing. If direction is both, connecting lines will be draw between all data points. The default is both.

    -weights wVec
        Specifies the weights of the individual data points. This, with the list pen styles (see the -styles option), controls how data points are drawn. WVec is the name of a BLT vector or a list of numeric expressions representing the weights for each data point.

    -xdata xVec
        Specifies the X-coordinates of the data. XVec is the name of a BLT vector or a list of numeric expressions.

    -ydata yVec
        Specifies the Y-coordinates of the data. YVec is the name of a BLT vector or a list of numeric expressions.

        Element configuration options may also be set by the option command. The resource class is Element. The resource name is the name of the element.

        option add *Graph.Element.symbol line
        option add *Graph.e1.symbol line

pathName element create elemName ?option value?...
    Creates a new element elemName. It's an error is an element elemName already exists. If additional arguments are present, they specify options valid for the element configure operation.

pathName element deactivate elemName ?elemName?...
    Deactivates all the elements matching pattern. Elements whose names match any of the patterns given are redrawn using their normal colors.

pathName element delete ?elemName?...
    Deletes all the named elements. The graph is automatically redrawn.

pathName element exists elemName
    Returns 1 if an element elemName currently exists and 0 otherwise.

pathName element names ?pattern?...
    Returns the elements matching one or more pattern. If no pattern is given, the names of all elements is returned.

pathName element show ?nameList?
    Queries or modifies the element display list. The element display list designates the elements drawn and in what order. NameList is a list of elements to be displayed in the order they are named. If there is no nameList argument, the current display list is returned.

pathName element type elemName
    Returns the type of elemName. If the element is a bar element, the commands returns the string "bar", otherwise it returns "line".

## GRID COMPONENT <a name="GRIDCOMPONENT"></a>

Grid lines extend from the major and minor ticks of each axis horizontally or vertically across the plotting area. The following operations are available for grid lines.

pathName grid cget option
    Returns the current value of the grid line configuration option given by option. Option may be any option described below for the grid configure operation.

pathName grid configure ?option value?...
    Queries or modifies the configuration options for grid lines. If option isn't specified, a list describing all the current grid options for pathName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the grid line option option is set to value. The following options are valid for grid lines.

    -color color
        Sets the color of the grid lines. The default is black.

    -dashes dashList
        Sets the dash style of the grid lines. DashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the grid lines. Each number must be between 1 and 255. If dashList is "", the grid will be solid lines.

    -hide boolean
        Indicates whether the grid should be drawn. If boolean is true, grid lines are not shown. The default is yes.

    -linewidth pixels
        Sets the width of grid lines. The default width is 1.

    -mapx xAxis
        Specifies the X-axis to display grid lines. XAxis must be the name of an axis or "" for no grid lines. The default is "".

    -mapy yAxis
        Specifies the Y-axis to display grid lines. YAxis must be the name of an axis or "" for no grid lines. The default is y.

    -minor boolean
        Indicates whether the grid lines should be drawn for minor ticks. If boolean is true, the lines will appear at minor tick intervals. The default is 1.

        Grid configuration options may also be set by the option command. The resource name and class are grid and Grid respectively.

        option add *Graph.grid.LineWidth 2
        option add *Graph.Grid.Color     black

        -raised boolean
            Grid is to be raised or drawn over elements.

pathName grid off
    Turns off the display the grid lines.

pathName grid on
    Turns on the display the grid lines.

pathName grid toggle
    Toggles the display of the grid.

## LEGEND COMPONENT <a name="LEGENDCOMPONENT"></a>

The legend displays a list of the data elements. Each entry consists of the element's symbol and label. The legend can appear in any margin (the default location is in the right margin). It can also be positioned anywhere within the plotting area.

The following operations are valid for the legend.

pathName legend activate pattern...
    Selects legend entries to be drawn using the active legend colors and relief. All entries whose element names match pattern are selected. To be selected, the element name must match only one pattern.

pathName legend bind tagName ?sequence? ?command?
    Associates command with tagName such that whenever the event sequence given by sequence occurs for a legend entry with this tag, command will be invoked. Implicitly the element names in the entry are tags. The syntax is similar to the bind command except that it operates on legend entries, rather than widgets. See the bind manual entry for complete details on sequence and the substitutions performed on command before invoking it.

    If all arguments are specified then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is + then command augments an existing binding rather than replacing it. If no command argument is provided then the command currently associated with tagName and sequence (it's an error occurs if there's no such binding) is returned. If both command and sequence are missing then a list of all the event sequences for which bindings have been defined for tagName.

pathName legend cget option
    Returns the current value of a legend configuration option. Option may be any option described below in the legend configure operation.

pathName legend configure ?option value?...
    Queries or modifies the configuration options for the legend. If option isn't specified, a list describing the current legend options for pathName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the legend option option is set to value. The following options are valid for the legend.

    -activebackground color
        Sets the background color for active legend entries. All legend entries marked active (see the legend activate operation) are drawn using this background color.

    -activeborderwidth pixels
        Sets the width of the 3-D border around the outside edge of the active legend entries. The default is 2.

    -activeforeground color
        Sets the foreground color for active legend entries. All legend entries marked as active (see the legend activate operation) are drawn using this foreground color.

    -activerelief relief
        Specifies the 3-D effect desired for active legend entries. Relief denotes how the interior of the entry should appear relative to the legend; for example, raised means the entry should appear to protrude from the legend, relative to the surface of the legend. The default is flat.

    -anchor anchor
        Tells how to position the legend relative to the positioning point for the legend. This is dependent on the value of the -position option. The default is center.

        left or right
            The anchor describes how to position the legend vertically.

        top or bottom
            The anchor describes how to position the legend horizontally.

        @x,y
            The anchor specifies how to position the legend relative to the positioning point. For example, if anchor is center then the legend is centered on the point; if anchor is n then the legend will be drawn such that the top center point of the rectangular region occupied by the legend will be at the positioning point.

        plotarea
            The anchor specifies how to position the legend relative to the plotting area. For example, if anchor is center then the legend is centered in the plotting area; if anchor is ne then the legend will be drawn such that occupies the upper right corner of the plotting area.

    -background color
        Sets the background color of the legend. If color is "", the legend background with be transparent.

    -bindtags tagList
        Specifies the binding tags for legend entries. TagList is a list of binding tag names. The tags and their order will determine how events are handled for legend entries. Each tag in the list matching the current event sequence will have its Tcl command executed. The default value is all.

    -borderwidth pixels
        Sets the width of the 3-D border around the outside edge of the legend (if such border is being drawn; the relief option determines this). The default is 2 pixels.

    -font fontName
        FontName specifies a font to use when drawing the labels of each element into the legend. The default is *-Helvetica-Bold-R-Normal-*-12-120-*.

    -foreground color
        Sets the foreground color of the text drawn for the element's label. The default is black.

    -hide boolean
        Indicates whether the legend should be displayed. If boolean is true, the legend will not be draw. The default is no.

    -ipadx pad
        Sets the amount of internal padding to be added to the width of each legend entry. Pad can be a list of one or two screen distances. If pad has two elements, the left side of the legend entry is padded by the first distance and the right side by the second. If pad is just one distance, both the left and right sides are padded evenly. The default is 2.

    -ipady pad
        Sets an amount of internal padding to be added to the height of each legend entry. Pad can be a list of one or two screen distances. If pad has two elements, the top of the entry is padded by the first distance and the bottom by the second. If pad is just one distance, both the top and bottom of the entry are padded evenly. The default is 2.

    -padx pad
        Sets the padding to the left and right exteriors of the legend. Pad can be a list of one or two screen distances. If pad has two elements, the left side of the legend is padded by the first distance and the right side by the second. If pad has just one distance, both the left and right sides are padded evenly. The default is 4.

    -pady pad
        Sets the padding above and below the legend. Pad can be a list of one or two screen distances. If pad has two elements, the area above the legend is padded by the first distance and the area below by the second. If pad is just one distance, both the top and bottom areas are padded evenly. The default is 0.

    -position pos
        Specifies where the legend is drawn. The -anchor option also affects where the legend is positioned. If pos is left, left, top, or bottom, the legend is drawn in the specified margin. If pos is plotarea, then the legend is drawn inside the plotting area at a particular anchor. If pos is in the form "@x,y", where x and y are the window coordinates, the legend is drawn in the plotting area at the specified coordinates. The default is right.

    -raised boolean
        Indicates whether the legend is above or below the data elements. This matters only if the legend is in the plotting area. If boolean is true, the legend will be drawn on top of any elements that may overlap it. The default is no.

    -relief relief
        Specifies the 3-D effect for the border around the legend. Relief specifies how the interior of the legend should appear relative to the graph; for example, raised means the legend should appear to protrude from the graph, relative to the surface of the graph. The default is sunken.

        Legend configuration options may also be set by the option command. The resource name and class are legend and Legend respectively.

        option add *Graph.legend.Foreground blue
        option add *Graph.Legend.Relief     raised

pathName legend deactivate pattern...
    Selects legend entries to be drawn using the normal legend colors and relief. All entries whose element names match pattern are selected. To be selected, the element name must match only one pattern.

pathName legend get pos
    Returns the name of the element whose entry is at the screen position pos in the legend. Pos must be in the form "@x,y", where x and y are window coordinates. If the given coordinates do not lie over a legend entry, "" is returned.

## PEN COMPONENTS <a name="PENCOMPONENTS"></a>

Pens define attributes (both symbol and line style) for elements. Pens mirror the configuration options of data elements that pertain to how symbols and lines are drawn. Data elements use pens to determine how they are drawn. A data element may use several pens at once. In this case, the pen used for a particular data point is determined from each element's weight vector (see the element's -weight and -style options).

One pen, called activeLine, is automatically created. It's used as the default active pen for elements. So you can change the active attributes for all elements by simply reconfiguring this pen.

.g pen configure "activeLine" -color green

You can create and use several pens. To create a pen, invoke the pen component and its create operation.

.g pen create myPen

You map pens to a data element using either the element's -pen or -activepen options.

.g element create "line1" -xdata $x -ydata $tempData \
    -pen myPen

An element can use several pens at once. This is done by specifying the name of the pen in the element's style list (see the -styles option).

.g element configure "line1" -styles { myPen 2.0 3.0 }

This says that any data point with a weight between 2.0 and 3.0 is to be drawn using the pen myPen. All other points are drawn with the element's default attributes.

The following operations are available for pen components.

pathName pen cget penName option
    Returns the current value of the option given by option for penName. Option may be any option described below for the pen configure operation.

pathName pen configure penName ?penName... ?option value?...
    Queries or modifies the configuration options of penName. Several pens can be modified at once. If option isn't specified, a list describing the current options for penName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the pen option option is set to value. The following options are valid for pens.

    -color color
        Sets the color of the traces connecting the data points.

    -dashes dashList
        Sets the dash style of element line. DashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the element line. Each number must be between 1 and 255. If dashList is "", the lines will be solid.

    -fill color
        Sets the interior color of symbols. If color is "", then the interior of the symbol is transparent. If color is defcolor, then the color will be the same as the -color option. The default is defcolor.

    -linewidth pixels
        Sets the width of the connecting lines between data points. If pixels is 0, no connecting lines will be drawn between symbols. The default is 0.

    -offdash color
        Sets the color of the stripes when traces are dashed (see the -dashes option). If color is "", then the "off" pixels will represent gaps instead of stripes. If color is defcolor, then the color will be the same as the -color option. The default is defcolor.

    -outline color
        Sets the color or the outline around each symbol. If color is "", then no outline is drawn. If color is defcolor, then the color will be the same as the -color option. The default is defcolor.

    -outlinewidth pixels
        Sets the width of the outline bordering each symbol. If pixels is 0, no outline will be drawn. The default is 1.

    -pixels pixels
        Sets the size of symbols. If pixels is 0, no symbols will be drawn. The default is 0.125i.

    -symbol symbol
        Specifies the symbol for data points. Symbol can be either square, circle, diamond, plus, cross, splus, scross, triangle, "" (where no symbol is drawn), or a bitmap. Bitmaps are specified as "source ?mask?", where source is the name of the bitmap, and mask is the bitmap's optional mask. The default is circle.

    -type elemType
        Specifies the type of element the pen is to be used with. This option should only be employed when creating the pen. This is for those that wish to mix different types of elements (bars and lines) on the same graph. The default type is "line".

        Pen configuration options may be also be set by the option command. The resource class is Pen. The resource names are the names of the pens.

        option add *Graph.Pen.Color  blue
        option add *Graph.activeLine.color  green

pathName pen create penName ?option value?...
    Creates a new pen by the name penName. No pen by the same name can already exist. Option and value are described in above in the pen configure operation.

pathName pen delete ?penName?...
    Deletes the named pens. A pen is not really deleted until it is not longer in use, so it's safe to delete pens mapped to elements.

pathName pen names ?pattern?...
    Returns a list of pens matching zero or more patterns. If no pattern argument is give, the names of all pens are returned.

## POSTSCRIPT COMPONENT <a name="POSTSCRIPTCOMPONENT"></a>

The graph can generate encapsulated PostScript output. There are several configuration options you can specify to control how the plot will be generated. You can change the page dimensions and borders. The plot itself can be scaled, centered, or rotated to landscape. The PostScript output can be written directly to a file or returned through the interpreter.

The following postscript operations are available.

pathName postscript cget option
    Returns the current value of the postscript option given by option. Option may be any option described below for the postscript configure operation.

pathName postscript configure ?option value?...
    Queries or modifies the configuration options for PostScript generation. If option isn't specified, a list describing the current postscript options for pathName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the postscript option option is set to value. The following postscript options are available.

    -center boolean
        Indicates whether the plot should be centered on the PostScript page. If boolean is false, the plot will be placed in the upper left corner of the page. The default is 1.

    -colormap varName
        VarName must be the name of a global array variable that specifies a color mapping from the X color name to PostScript. Each element of varName must consist of PostScript code to set a particular color value (e.g. ``1.0 1.0 0.0 setrgbcolor''). When generating color information in PostScript, the array variable varName is checked if an element of the name as the color exists. If so, it uses its value as the PostScript command to set the color. If this option hasn't been specified, or if there isn't an entry in varName for a given color, then it uses the red, green, and blue intensities from the X color.

    -colormode mode
        Specifies how to output color information. Mode must be either color (for full color output), gray (convert all colors to their gray-scale equivalents) or mono (convert foreground colors to black and background colors to white). The default mode is color.

    -fontmap varName
        VarName must be the name of a global array variable that specifies a font mapping from the X font name to PostScript. Each element of varName must consist of a Tcl list with one or two elements; the name and point size of a PostScript font. When outputting PostScript commands for a particular font, the array variable varName is checked to see if an element by the specified font exists. If there is such an element, then the font information contained in that element is used in the PostScript output. (If the point size is omitted from the list, the point size of the X font is used). Otherwise the X font is examined in an attempt to guess what PostScript font to use. This works only for fonts whose foundry property is Adobe (such as Times, Helvetica, Courier, etc.). If all of this fails then the font defaults to Helvetica-Bold.

    -decorations boolean
        Indicates whether PostScript commands to generate color backgrounds and 3-D borders will be output. If boolean is false, the background will be white and no 3-D borders will be generated. The default is 1.

    -height pixels
        Sets the height of the plot. This lets you print the graph with a height different from the one drawn on the screen. If pixels is 0, the height is the same as the widget's height. The default is 0.

    -landscape boolean
        If boolean is true, this specifies the printed area is to be rotated 90 degrees. In non-rotated output the X-axis of the printed area runs along the short dimension of the page (``portrait'' orientation); in rotated output the X-axis runs along the long dimension of the page (``landscape'' orientation). Defaults to 0.

    -maxpect boolean
        Indicates to scale the plot so that it fills the PostScript page. The aspect ratio of the graph is still retained. The default is 0.

    -padx pad
        Sets the horizontal padding for the left and right page borders. The borders are exterior to the plot. Pad can be a list of one or two screen distances. If pad has two elements, the left border is padded by the first distance and the right border by the second. If pad has just one distance, both the left and right borders are padded evenly. The default is 1i.

    -pady pad
        Sets the vertical padding for the top and bottom page borders. The borders are exterior to the plot. Pad can be a list of one or two screen distances. If pad has two elements, the top border is padded by the first distance and the bottom border by the second. If pad has just one distance, both the top and bottom borders are padded evenly. The default is 1i.

    -paperheight pixels
        Sets the height of the postscript page. This can be used to select between different page sizes (letter, A4, etc). The default height is 11.0i.

    -paperwidth pixels
        Sets the width of the postscript page. This can be used to select between different page sizes (letter, A4, etc). The default width is 8.5i.

    -width pixels
        Sets the width of the plot. This lets you generate a plot of a width different from that of the widget. If pixels is 0, the width is the same as the widget's width. The default is 0.

        Postscript configuration options may be also be set by the option command. The resource name and class are postscript and Postscript respectively.

        option add *Graph.postscript.Decorations false
        option add *Graph.Postscript.Landscape   true

pathName postscript output ?fileName? ?option value?...
    Outputs a file of encapsulated PostScript. If a fileName argument isn't present, the command returns the PostScript. If any option-value pairs are present, they set configuration options controlling how the PostScript is generated. Option and value can be anything accepted by the postscript configure operation above.

## MARKER COMPONENTS <a name="MARKERCOMPONENTS"></a>

Markers are simple drawing procedures used to annotate or highlight areas of the graph. Markers have various types: text strings, bitmaps, images, connected lines, windows, or polygons. They can be associated with a particular element, so that when the element is hidden or un-hidden, so is the marker. By default, markers are the last items drawn, so that data elements will appear in behind them. You can change this by configuring the -under option.

Markers, in contrast to elements, don't affect the scaling of the coordinate axes. They can also have elastic coordinates (specified by -Inf and Inf respectively) that translate into the minimum or maximum limit of the axis. For example, you can place a marker so it always remains in the lower left corner of the plotting area, by using the coordinates -Inf,-Inf.

The following operations are available for markers.

pathName marker after markerId ?afterId?
    Changes the order of the markers, drawing the first marker after the second. If no second afterId argument is specified, the marker is placed at the end of the display list. This command can be used to control how markers are displayed since markers are drawn in the order of this display list.

pathName marker before markerId ?beforeId?
    Changes the order of the markers, drawing the first marker before the second. If no second beforeId argument is specified, the marker is placed at the beginning of the display list. This command can be used to control how markers are displayed since markers are drawn in the order of this display list.

pathName marker bind tagName ?sequence? ?command?
    Associates command with tagName such that whenever the event sequence given by sequence occurs for a marker with this tag, command will be invoked. The syntax is similar to the bind command except that it operates on graph markers, rather than widgets. See the bind manual entry for complete details on sequence and the substitutions performed on command before invoking it.

    If all arguments are specified then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is + then command augments an existing binding rather than replacing it. If no command argument is provided then the command currently associated with tagName and sequence (it's an error occurs if there's no such binding) is returned. If both command and sequence are missing then a list of all the event sequences for which bindings have been defined for tagName.

pathName marker cget option
    Returns the current value of the marker configuration option given by option. Option may be any option described below in the configure operation.

pathName marker configure markerId ?option value?...
    Queries or modifies the configuration options for markers. If option isn't specified, a list describing the current options for markerId is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the marker option option is set to value.

    The following options are valid for all markers. Each type of marker also has its own type-specific options. They are described in the sections below.

    -bindtags tagList
        Specifies the binding tags for the marker. TagList is a list of binding tag names. The tags and their order will determine how events for markers are handled. Each tag in the list matching the current event sequence will have its Tcl command executed. Implicitly the name of the marker is always the first tag in the list. The default value is all.

    -coords coordList
        Specifies the coordinates of the marker. CoordList is a list of graph coordinates. The number of coordinates required is dependent on the type of marker. Text, image, and window markers need only two coordinates (an X-Y coordinate). Bitmap markers can take either two or four coordinates (if four, they represent the corners of the bitmap). Line markers need at least four coordinates, polygons at least six. If coordList is "", the marker will not be displayed. The default is "".

    -element elemName
        Links the marker with the element elemName. The marker is drawn only if the element is also currently displayed (see the element's show operation). If elemName is "", the marker is always drawn. The default is "".

    -hide boolean
        Indicates whether the marker is drawn. If boolean is true, the marker is not drawn. The default is no.

    -mapx xAxis
        Specifies the X-axis to map the marker's X-coordinates onto. XAxis must the name of an axis. The default is x.

    -mapy yAxis
        Specifies the Y-axis to map the marker's Y-coordinates onto. YAxis must the name of an axis. The default is y.

    -name markerId
        Changes the identifier for the marker. The identifier markerId can not already be used by another marker. If this option isn't specified, the marker's name is uniquely generated.

    -under boolean
        Indicates whether the marker is drawn below/above data elements. If boolean is true, the marker is be drawn underneath the data element symbols and lines. Otherwise, the marker is drawn on top of the element. The default is 0.

    -xoffset pixels
        Specifies a screen distance to offset the marker horizontally. Pixels is a valid screen distance, such as 2 or 1.2i. The default is 0.

    -yoffset pixels
        Specifies a screen distance to offset the markers vertically. Pixels is a valid screen distance, such as 2 or 1.2i. The default is 0.

        Marker configuration options may also be set by the option command. The resource class is either BitmapMarker, ImageMarker, LineMarker, PolygonMarker, TextMarker, or WindowMarker, depending on the type of marker. The resource name is the name of the marker.

        option add *Graph.TextMarker.Foreground white
        option add *Graph.BitmapMarker.Foreground white
        option add *Graph.m1.Background     blue

pathName marker create type ?option value?...
    Creates a marker of the selected type. Type may be either text, line, bitmap, image, polygon, or window. This command returns the marker identifier, used as the markerId argument in the other marker-related commands. If the -name option is used, this overrides the normal marker identifier. If the name provided is already used for another marker, the new marker will replace the old.

pathName marker delete ?name?...
    Removes one of more markers. The graph will automatically be redrawn without the marker.\fR.

pathName marker exists markerId
    Returns 1 if the marker markerId exists and 0 otherwise.

pathName marker names ?pattern?
    Returns the names of all the markers that currently exist. If pattern is supplied, only those markers whose names match it will be returned.

pathName marker type markerId
    Returns the type of the marker given by markerId, such as line or text. If markerId is not a valid a marker identifier, "" is returned.

## BITMAP MARKERS <a name="BITMAPMARKERS"></a>

A bitmap marker displays a bitmap. The size of the bitmap is controlled by the number of coordinates specified. If two coordinates, they specify the position of the top-left corner of the bitmap. The bitmap retains its normal width and height. If four coordinates, the first and second pairs of coordinates represent the corners of the bitmap. The bitmap will be stretched or reduced as necessary to fit into the bounding rectangle.

Bitmap markers are created with the marker's create operation in the form:

    pathName marker create bitmap ?option value?...

There may be many option-value pairs, each sets a configuration options for the marker. These same option-value pairs may be used with the marker's configure operation.

The following options are specific to bitmap markers:

-background color
    Same as the -fill option.

-bitmap bitmap
    Specifies the bitmap to be displayed. If bitmap is "", the marker will not be displayed. The default is "".

-fill color
    Sets the background color of the bitmap. If color is the empty string, no background will be transparent. The default background color is "".

-foreground color
    Same as the -outline option.

-mask mask
    Specifies a mask for the bitmap to be displayed. This mask is a bitmap itself, denoting the pixels that are transparent. If mask is "", all pixels of the bitmap will be drawn. The default is "".

-outline color
    Sets the foreground color of the bitmap. The default value is black.

-rotate theta
    Sets the rotation of the bitmap. Theta is a real number representing the angle of rotation in degrees. The marker is first rotated and then placed according to its anchor position. The default rotation is 0.0.

IMAGE MARKERS
A image marker displays an image. Image markers are created with the marker's create operation in the form:

    pathName marker create image ?option value?...

There may be many option-value pairs, each sets a configuration option for the marker. These same option-value pairs may be used with the marker's configure operation.

The following options are specific to image markers:

-anchor anchor
    Anchor tells how to position the image relative to the positioning point for the image. For example, if anchor is center then the image is centered on the point; if anchor is n then the image will be drawn such that the top center point of the rectangular region occupied by the image will be at the positioning point. This option defaults to center.

-image image
    Specifies the image to be drawn. If image is "", the marker will not be drawn. The default is "".

LINE MARKERS
A line marker displays one or more connected line segments. Line markers are created with marker's create operation in the form:

    pathName marker create line ?option value?...

There may be many option-value pairs, each sets a configuration option for the marker. These same option-value pairs may be used with the marker's configure operation.

The following options are specific to line markers:

-dashes dashList
    Sets the dash style of the line. DashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the line. Each number must be between 1 and 255. If dashList is "", the marker line will be solid.

-fill color
    Sets the background color of the line. This color is used with striped lines (see the -fdashes option). If color is the empty string, no background color is drawn (the line will be dashed, not striped). The default background color is "".

-linewidth pixels
    Sets the width of the lines. The default width is 0.

-outline color
    Sets the foreground color of the line. The default value is black.

-stipple bitmap
    Specifies a stipple pattern used to draw the line, rather than a solid line. Bitmap specifies a bitmap to use as the stipple pattern. If bitmap is "", then the line is drawn in a solid fashion. The default is "".

## POLYGON MARKERS <a name="POLYGONMARKERS"></a>

A polygon marker displays a closed region described as two or more connected line segments. It is assumed the first and last points are connected. Polygon markers are created using the marker create operation in the form:

    pathName marker create polygon ?option value?...

There may be many option-value pairs, each sets a configuration option for the marker. These same option-value pairs may be used with the marker configure command to change the marker's configuration. The following options are supported for polygon markers:

-dashes dashList
    Sets the dash style of the outline of the polygon. DashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the outline. Each number must be between 1 and 255. If dashList is "", the outline will be a solid line.

-fill color
    Sets the fill color of the polygon. If color is "", then the interior of the polygon is transparent. The default is white.

-linewidth pixels
    Sets the width of the outline of the polygon. If pixels is zero, no outline is drawn. The default is 0.

-outline color
    Sets the color of the outline of the polygon. If the polygon is stippled (see the -stipple option), then this represents the foreground color of the stipple. The default is black.

-stipple bitmap
    Specifies that the polygon should be drawn with a stippled pattern rather than a solid color. Bitmap specifies a bitmap to use as the stipple pattern. If bitmap is "", then the polygon is filled with a solid color (if the -fill option is set). The default is "".

## TEXT MARKERS <a name="TEXTMARKERS"></a>

A text marker displays a string of characters on one or more lines of text. Embedded newlines cause line breaks. They may be used to annotate regions of the graph. Text markers are created with the create operation in the form:

    pathName marker create text ?option value?...

There may be many option-value pairs, each sets a configuration option for the text marker. These same option-value pairs may be used with the marker's configure operation.

The following options are specific to text markers:

-anchor anchor
    Anchor tells how to position the text relative to the positioning point for the text. For example, if anchor is center then the text is centered on the point; if anchor is n then the text will be drawn such that the top center point of the rectangular region occupied by the text will be at the positioning point. This default is center.

-background color
    Same as the -fill option.

-font fontName
    Specifies the font of the text. The default is *-Helvetica-Bold-R-Normal-*-120-*.

-fill color
    Sets the background color of the text. If color is the empty string, no background will be transparent. The default background color is "".

-foreground color
    Same as the -outline option.

-justify justify
    Specifies how the text should be justified. This matters only when the marker contains more than one line of text. Justify must be left, right, or center. The default is center.

-outline color
    Sets the color of the text. The default value is black.

-padx pad
    Sets the padding to the left and right exteriors of the text. Pad can be a list of one or two screen distances. If pad has two elements, the left side of the text is padded by the first distance and the right side by the second. If pad has just one distance, both the left and right sides are padded evenly. The default is 4.

-pady pad
    Sets the padding above and below the text. Pad can be a list of one or two screen distances. If pad has two elements, the area above the text is padded by the first distance and the area below by the second. If pad is just one distance, both the top and bottom areas are padded evenly. The default is 4.

-rotate theta
    Specifies the number of degrees to rotate the text. Theta is a real number representing the angle of rotation. The marker is first rotated along its center and is then drawn according to its anchor position. The default is 0.0.

-text text
    Specifies the text of the marker. The exact way the text is displayed may be affected by other options such as -anchor or -rotate.

## WINDOW MARKERS <a name="WINDOWMARKERS"></a>

A window marker displays a widget at a given position. Window markers are created with the marker's create operation in the form:

    pathName marker create window ?option value?...

There may be many option-value pairs, each sets a configuration option for the marker. These same option-value pairs may be used with the marker's configure command.

The following options are specific to window markers:

-anchor anchor
    Anchor tells how to position the widget relative to the positioning point for the widget. For example, if anchor is center then the widget is centered on the point; if anchor is n then the widget will be displayed such that the top center point of the rectangular region occupied by the widget will be at the positioning point. This option defaults to center.

-height pixels
    Specifies the height to assign to the marker's window. If this option isn't specified, or if it is specified as "", then the window is given whatever height the widget requests internally.

-width pixels
    Specifies the width to assign to the marker's window. If this option isn't specified, or if it is specified as "", then the window is given whatever width the widget requests internally.

-window pathName
    Specifies the widget to be managed by the graph. PathName must be a child of the graph widget.

## GRAPH COMPONENT BINDINGS <a name="GRAPHCOMPONENTBINDINGS"></a>

Specific graph components, such as elements, markers and legend entries, can have a command trigger when event occurs in them, much like canvas items in Tk's canvas widget. Not all event sequences are valid. The only binding events that may be specified are those related to the mouse and keyboard (such as Enter, Leave, ButtonPress, Motion, and KeyPress).

Only one element or marker can be picked during an event. This means, that if the mouse is directly over both an element and a marker, only the uppermost component is selected. This isn't true for legend entries. Both a legend entry and an element (or marker) binding commands will be invoked if both items are picked.

It is possible for multiple bindings to match a particular event. This could occur, for example, if one binding is associated with the element name and another is associated with one of the element's tags (see the -bindtags option). When this occurs, all of the matching bindings are invoked. A binding associated with the element name is invoked first, followed by one binding for each of the element's bindtags. If there are multiple matching bindings for a single tag, then only the most specific binding is invoked. A continue command in a binding script terminates that script, and a break command terminates that script and skips any remaining scripts for the event, just as for the bind command.

The -bindtags option for these components controls addition tag names which can be matched. Implicitly elements and markers always have tags matching their names. Setting the value of the -bindtags option doesn't change this.
C LANGUAGE API
You can manipulate data elements from the C language. There may be situations where it is too expensive to translate the data values from ASCII strings. Or you might want to read data in a special file format.

Data can manipulated from the C language using BLT vectors. You specify the X-Y data coordinates of an element as vectors and manipulate the vector from C. The graph will be redrawn automatically after the vectors are updated.

From Tcl, create the vectors and configure the element to use them.

vector X Y
	.g element configure line1 -xdata X -ydata Y

To set data points from C, you pass the values as arrays of doubles using the Blt_ResetVector call. The vector is reset with the new data and at the next idle point (when Tk re-enters its event loop), the graph will be redrawn automatically.

 #include <tcl.h>
 #include <blt.h>

 register int i;
 Blt_Vector *xVec, *yVec;
 double x[50], y[50];

 /* Get the BLT vectors "X" and "Y" (created above from Tcl) */
 if ((Blt_GetVector(interp, "X", &xVec) != TCL_OK) ||
    (Blt_GetVector(interp, "Y", &yVec) != TCL_OK)) {
    return TCL_ERROR;
 }

 for (i = 0; i < 50; i++) {
    x[i] = i * 0.02;
    y[i] = sin(x[i]);
 }	

 /* Put the data into BLT vectors */
 if ((Blt_ResetVector(xVec, x, 50, 50, TCL_VOLATILE) != TCL_OK) ||
    (Blt_ResetVector(yVec, y, 50, 50, TCL_VOLATILE) != TCL_OK)) {
   return TCL_ERROR;
 }

See the vector manual page for more details.

## SPEED TIPS <a name="SPEEDTIPS"></a>

There may be cases where the graph needs to be drawn and updated as quickly as possible. If drawing speed becomes a big problem, here are a few tips to speed up displays.

    Try to minimize the number of data points. The more data points the looked at, the more work the graph must do.

    If your data is generated as floating point values, the time required to convert the data values to and from ASCII strings can be significant, especially when there any many data points. You can avoid the redundant string-to-decimal conversions using the C API to BLT vectors.

    Data elements without symbols are drawn faster than with symbols. Set the data element's -symbol option to none. If you need to draw symbols, try using the simple symbols such as splus and scross.

    Don't stipple or dash the element. Solid lines are much faster.

    If you update data elements frequently, try turning off the widget's -bufferelements option. When the graph is first displayed, it draws data elements into an internal pixmap. The pixmap acts as a cache, so that when the graph needs to be redrawn again, and the data elements or coordinate axes haven't changed, the pixmap is simply copied to the screen. This is especially useful when you are using markers to highlight points and regions on the graph. But if the graph is updated frequently, changing either the element data or coordinate axes, the buffering becomes redundant.

## LIMITATIONS <a name="LIMITATIONS"></a>

Auto-scale routines do not use requested min/max limits as boundaries when the axis is logarithmically scaled.

The PostScript output generated for polygons with more than 1500 points may exceed the limits of some printers (See PostScript Language Reference Manual, page 568). The work-around is to break the polygon into separate pieces.

## KEYWORDS <a name="KEYWORDS"></a>

graph, widget

## COPYRIGHT

&copy; 1995-1997 Roger E. Critchlow Jr.

&copy; 2001 George A. Howlett.

&copy; 2018 René Zaumseil <[email protected]>


Added doc/rbc/man.macros.
































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
'\" The definitions below are for supplemental macros used in Tcl/Tk
'\" manual entries.
'\"
'\" .AP type name in/out ?indent?
'\"	Start paragraph describing an argument to a library procedure.
'\"	type is type of argument (int, etc.), in/out is either "in", "out",
'\"	or "in/out" to describe whether procedure reads or modifies arg,
'\"	and indent is equivalent to second arg of .IP (shouldn't ever be
'\"	needed;  use .AS below instead)
'\"
'\" .AS ?type? ?name?
'\"	Give maximum sizes of arguments for setting tab stops.  Type and
'\"	name are examples of largest possible arguments that will be passed
'\"	to .AP later.  If args are omitted, default tab stops are used.
'\"
'\" .BS
'\"	Start box enclosure.  From here until next .BE, everything will be
'\"	enclosed in one large box.
'\"
'\" .BE
'\"	End of box enclosure.
'\"
'\" .CS
'\"	Begin code excerpt.
'\"
'\" .CE
'\"	End code excerpt.
'\"
'\" .VS ?version? ?br?
'\"	Begin vertical sidebar, for use in marking newly-changed parts
'\"	of man pages.  The first argument is ignored and used for recording
'\"	the version when the .VS was added, so that the sidebars can be
'\"	found and removed when they reach a certain age.  If another argument
'\"	is present, then a line break is forced before starting the sidebar.
'\"
'\" .VE
'\"	End of vertical sidebar.
'\"
'\" .DS
'\"	Begin an indented unfilled display.
'\"
'\" .DE
'\"	End of indented unfilled display.
'\"
'\" .SO
'\"	Start of list of standard options for a Tk widget.  The
'\"	options follow on successive lines, in four columns separated
'\"	by tabs.
'\"
'\" .SE
'\"	End of list of standard options for a Tk widget.
'\"
'\" .OP cmdName dbName dbClass
'\"	Start of description of a specific option.  cmdName gives the
'\"	option's name as specified in the class command, dbName gives
'\"	the option's name in the option database, and dbClass gives
'\"	the option's class in the option database.
'\"
'\" .UL arg1 arg2
'\"	Print arg1 underlined, then print arg2 normally.
'\"
'\" RCS: @(#) $Id: man.macros,v 1.3 2001/02/17 07:46:19 ghowlett Exp $
'\"
'\"	# Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
.if t .wh -1.3i ^B
.nr ^l \n(.l
.ad b
'\"	# Start an argument description
.de AP
.ie !"\\$4"" .TP \\$4
.el \{\
.   ie !"\\$2"" .TP \\n()Cu
.   el          .TP 15
.\}
.ta \\n()Au \\n()Bu
.ie !"\\$3"" \{\
\&\\$1	\\fI\\$2\\fP	(\\$3)
.\".b
.\}
.el \{\
.br
.ie !"\\$2"" \{\
\&\\$1	\\fI\\$2\\fP
.\}
.el \{\
\&\\fI\\$1\\fP
.\}
.\}
..
'\"	# define tabbing values for .AP
.de AS
.nr )A 10n
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
.nr )B \\n()Au+15n
.\"
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
.nr )C \\n()Bu+\\w'(in/out)'u+2n
..
.AS Tcl_Interp Tcl_CreateInterp in/out
'\"	# BS - start boxed text
'\"	# ^y = starting y location
'\"	# ^b = 1
.de BS
.br
.mk ^y
.nr ^b 1u
.if n .nf
.if n .ti 0
.if n \l'\\n(.lu\(ul'
.if n .fi
..
'\"	# BE - end boxed text (draw box now)
.de BE
.nf
.ti 0
.mk ^t
.ie n \l'\\n(^lu\(ul'
.el \{\
.\"	Draw four-sided box normally, but don't draw top of
.\"	box if the box started on an earlier page.
.ie !\\n(^b-1 \{\
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.el \}\
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.\}
.fi
.br
.nr ^b 0
..
'\"	# VS - start vertical sidebar
'\"	# ^Y = starting y location
'\"	# ^v = 1 (for troff;  for nroff this doesn't matter)
.de VS
.if !"\\$2"" .br
.mk ^Y
.ie n 'mc \s12\(br\s0
.el .nr ^v 1u
..
'\"	# VE - end of vertical sidebar
.de VE
.ie n 'mc
.el \{\
.ev 2
.nf
.ti 0
.mk ^t
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
.sp -1
.fi
.ev
.\}
.nr ^v 0
..
'\"	# Special macro to handle page bottom:  finish off current
'\"	# box/sidebar if in box/sidebar mode, then invoked standard
'\"	# page bottom macro.
.de ^B
.ev 2
'ti 0
'nf
.mk ^t
.if \\n(^b \{\
.\"	Draw three-sided box if this is the box's first page,
.\"	draw two sides but no top otherwise.
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.\}
.if \\n(^v \{\
.nr ^x \\n(^tu+1v-\\n(^Yu
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
.\}
.bp
'fi
.ev
.if \\n(^b \{\
.mk ^y
.nr ^b 2
.\}
.if \\n(^v \{\
.mk ^Y
.\}
..
'\"	# DS - begin display
.de DS
.RS
.nf
.sp
..
'\"	# DE - end display
.de DE
.fi
.RE
.sp
..
'\"	# SO - start of list of standard options
.de SO
.SH "STANDARD OPTIONS"
.LP
.nf
.ta 4c 8c 12c
.ft B
..
'\"	# SE - end of list of standard options
.de SE
.fi
.ft R
.LP
See the \\fBoptions\\fR manual entry for details on the standard options.
..
'\"	# OP - start of full description for a single option
.de OP
.LP
.nf
.ta 4c
Command-Line Name:	\\fB\\$1\\fR
Database Name:	\\fB\\$2\\fR
Database Class:	\\fB\\$3\\fR
.fi
.IP
..
'\"	# CS - begin code excerpt
.de CS
.RS
.nf
.ta .25i .5i .75i 1i
.ft CW
.sp
..
'\"	# CE - end code excerpt
.de CE
.fi
.RE
.ft R
.sp
..
.de UL
\\$1\l'|0\(ul'\\$2
..

Added doc/rbc/stripchart.n.














































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
'\" Copyright 1991-1997 by Bell Labs Innovations for Lucent Technologies.
'\"
'\" Permission to use, copy, modify, and distribute this software and its
'\" documentation for any purpose and without fee is hereby granted, provided
'\" that the above copyright notice appear in all copies and that both that the
'\" copyright notice and warranty disclaimer appear in supporting documentation,
'\" and that the names of Lucent Technologies any of their entities not be used
'\" in advertising or publicity pertaining to distribution of the software
'\" without specific, written prior permission.
'\"
'\" Lucent Technologies disclaims all warranties with regard to this software,
'\" including all implied warranties of merchantability and fitness.  In no event
'\" shall Lucent Technologies be liable for any special, indirect or
'\" consequential damages or any damages whatsoever resulting from loss of use,
'\" data or profits, whether in an action of contract, negligence or other
'\" tortuous action, arising out of or in connection with the use or performance
'\" of this software.  
'\"
'\" Stripchart widget created by Sani Nassif and George Howlett.
'\"
'\" The definitions below are for supplemental macros used in Tcl/Tk
'\" manual entries.
'\"
'\" .AP type name in/out ?indent?
'\"	Start paragraph describing an argument to a library procedure.
'\"	type is type of argument (int, etc.), in/out is either "in", "out",
'\"	or "in/out" to describe whether procedure reads or modifies arg,
'\"	and indent is equivalent to second arg of .IP (shouldn't ever be
'\"	needed;  use .AS below instead)
'\"
'\" .AS ?type? ?name?
'\"	Give maximum sizes of arguments for setting tab stops.  Type and
'\"	name are examples of largest possible arguments that will be passed
'\"	to .AP later.  If args are omitted, default tab stops are used.
'\"
'\" .BS
'\"	Start box enclosure.  From here until next .BE, everything will be
'\"	enclosed in one large box.
'\"
'\" .BE
'\"	End of box enclosure.
'\"
'\" .CS
'\"	Begin code excerpt.
'\"
'\" .CE
'\"	End code excerpt.
'\"
'\" .VS ?version? ?br?
'\"	Begin vertical sidebar, for use in marking newly-changed parts
'\"	of man pages.  The first argument is ignored and used for recording
'\"	the version when the .VS was added, so that the sidebars can be
'\"	found and removed when they reach a certain age.  If another argument
'\"	is present, then a line break is forced before starting the sidebar.
'\"
'\" .VE
'\"	End of vertical sidebar.
'\"
'\" .DS
'\"	Begin an indented unfilled display.
'\"
'\" .DE
'\"	End of indented unfilled display.
'\"
'\" .SO
'\"	Start of list of standard options for a Tk widget.  The
'\"	options follow on successive lines, in four columns separated
'\"	by tabs.
'\"
'\" .SE
'\"	End of list of standard options for a Tk widget.
'\"
'\" .OP cmdName dbName dbClass
'\"	Start of description of a specific option.  cmdName gives the
'\"	option's name as specified in the class command, dbName gives
'\"	the option's name in the option database, and dbClass gives
'\"	the option's class in the option database.
'\"
'\" .UL arg1 arg2
'\"	Print arg1 underlined, then print arg2 normally.
'\"
'\" RCS: @(#) $Id: man.macros,v 1.3 2001/02/17 07:46:19 ghowlett Exp $
'\"
'\"	# Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
.if t .wh -1.3i ^B
.nr ^l \n(.l
.ad b
'\"	# Start an argument description
.de AP
.ie !"\\$4"" .TP \\$4
.el \{\
.   ie !"\\$2"" .TP \\n()Cu
.   el          .TP 15
.\}
.ta \\n()Au \\n()Bu
.ie !"\\$3"" \{\
\&\\$1	\\fI\\$2\\fP	(\\$3)
.\".b
.\}
.el \{\
.br
.ie !"\\$2"" \{\
\&\\$1	\\fI\\$2\\fP
.\}
.el \{\
\&\\fI\\$1\\fP
.\}
.\}
..
'\"	# define tabbing values for .AP
.de AS
.nr )A 10n
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
.nr )B \\n()Au+15n
.\"
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
.nr )C \\n()Bu+\\w'(in/out)'u+2n
..
.AS Tcl_Interp Tcl_CreateInterp in/out
'\"	# BS - start boxed text
'\"	# ^y = starting y location
'\"	# ^b = 1
.de BS
.br
.mk ^y
.nr ^b 1u
.if n .nf
.if n .ti 0
.if n \l'\\n(.lu\(ul'
.if n .fi
..
'\"	# BE - end boxed text (draw box now)
.de BE
.nf
.ti 0
.mk ^t
.ie n \l'\\n(^lu\(ul'
.el \{\
.\"	Draw four-sided box normally, but don't draw top of
.\"	box if the box started on an earlier page.
.ie !\\n(^b-1 \{\
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.el \}\
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.\}
.fi
.br
.nr ^b 0
..
'\"	# VS - start vertical sidebar
'\"	# ^Y = starting y location
'\"	# ^v = 1 (for troff;  for nroff this doesn't matter)
.de VS
.if !"\\$2"" .br
.mk ^Y
.ie n 'mc \s12\(br\s0
.el .nr ^v 1u
..
'\"	# VE - end of vertical sidebar
.de VE
.ie n 'mc
.el \{\
.ev 2
.nf
.ti 0
.mk ^t
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
.sp -1
.fi
.ev
.\}
.nr ^v 0
..
'\"	# Special macro to handle page bottom:  finish off current
'\"	# box/sidebar if in box/sidebar mode, then invoked standard
'\"	# page bottom macro.
.de ^B
.ev 2
'ti 0
'nf
.mk ^t
.if \\n(^b \{\
.\"	Draw three-sided box if this is the box's first page,
.\"	draw two sides but no top otherwise.
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.\}
.if \\n(^v \{\
.nr ^x \\n(^tu+1v-\\n(^Yu
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
.\}
.bp
'fi
.ev
.if \\n(^b \{\
.mk ^y
.nr ^b 2
.\}
.if \\n(^v \{\
.mk ^Y
.\}
..
'\"	# DS - begin display
.de DS
.RS
.nf
.sp
..
'\"	# DE - end display
.de DE
.fi
.RE
.sp
..
'\"	# SO - start of list of standard options
.de SO
.SH "STANDARD OPTIONS"
.LP
.nf
.ta 4c 8c 12c
.ft B
..
'\"	# SE - end of list of standard options
.de SE
.fi
.ft R
.LP
See the \\fBoptions\\fR manual entry for details on the standard options.
..
'\"	# OP - start of full description for a single option
.de OP
.LP
.nf
.ta 4c
Command-Line Name:	\\fB\\$1\\fR
Database Name:	\\fB\\$2\\fR
Database Class:	\\fB\\$3\\fR
.fi
.IP
..
'\"	# CS - begin code excerpt
.de CS
.RS
.nf
.ta .25i .5i .75i 1i
.ft CW
.sp
..
'\"	# CE - end code excerpt
.de CE
.fi
.RE
.ft R
.sp
..
.de UL
\\$1\l'|0\(ul'\\$2
..
.TH stripchart n 2.4 BLT "BLT Built-In Commands"
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
stripchart \-  2D strip chart for plotting x and y coordinate data.
.SH SYNOPSIS
\fBstripchart\fI \fIpathName \fR?\fIoption value\fR?...
.BE
.SH DESCRIPTION
The \fBstripchart\fR command creates a strip chart for plotting
two-dimensional data (x,y coordinates). It has many configurable
components: coordinate axes, elements, legend, grid lines, cross
hairs, etc.  They allow you to customize the look and feel of the
strip chart.
.PP
The \fBstripchart\fR is essentially the same as the \fBgraph\fR
widget.  It works almost exactly the very same way.  
.PP
The use of a strip chart differs in that the X-axis typically refers
to time points.  Data values are added at intervals.  The strip chart
lets you automatically maintain a view of the most recent time points.
The axis options \fB\-shiftby\fR and \fB\-autorange\fR control this.
You can specify different line styles for data points (see the 
\fB\-styles\fR option).  
.SH INTRODUCTION
The \fBstripchart\fR command creates a new window for plotting
two-dimensional data (x,y coordinates).  Data points are plotted in a
box displayed in the center of the new window.  This is the
\fIplotting area\fR.  The coordinate axes are displayed in the
margins around the plotting area.  By default, the legend is displayed
in the right margin.  The title is displayed in top margin.
.PP
A strip chart is composed of several components: coordinate axes, data
elements, legend, grid, cross hairs, pens, postscript, and annotation
markers. 
.TP 1i
\f(CWaxis\fR 
The stripchart widget can display up to four coordinate axes (two
X-coordinate and two Y-coordinate axes), but you can create and use
any number of axes. Axes control what region of data is displayed and
how the data is scaled. Each axis consists of the axis line, title,
major and minor ticks, and tick labels. Tick labels display the value
of each major tick.
.TP 1i
\f(CWcrosshairs\fR
Cross hairs are used to finely position the mouse pointer in relation
to the coordinate axes. Two perpendicular lines are drawn across the
plotting area, intersecting at the current location of the mouse
pointer.
.TP 1i
\f(CWelement\fR 
An element represents a set of data points. Elements can be plotted 
with a symbol at each data point and lines connecting the points. 
The appearance of the element, such as its symbol, line width, and 
color is configurable.
.TP 1i
\f(CWgrid\fR
Extends the major and minor ticks of the X\-axis and/or Y\-axis across the 
plotting area. 
.TP 1i
\f(CWlegend\fR 
The legend displays the name and symbol of each data element. 
The legend can be drawn in any margin or in the plotting area.
.TP 1i
\f(CWmarker\fR
Markers are used annotate or highlight areas of the graph. For 
example, you could use a polygon marker to fill an area under a 
curve, or a text marker to label a particular data point. Markers 
come in various forms: text strings, bitmaps, connected line 
segments, images, polygons, or embedded widgets.
.TP 1i
\f(CWpen\fR 
Pens define attributes (both symbol and line style) for elements. 
Data elements use pens to specify how they should be drawn.  A data 
element may use many pens at once.  Here, the particular pen 
used for a data point is determined from each element's weight 
vector (see the element's \fB\-weight\fR and \fB\-style\fR options).  
.TP 1i
\f(CWpostscript\fR
The widget can generate encapsulated PostScript output. This component
has several options to configure how the PostScript is generated.
.SH SYNTAX
.DS
\fBstripchart \fIpathName \fR?\fIoption value\fR?...
.DE
The \fBstripchart\fR command creates a new window \fIpathName\fR and makes
it into a \fBstripchart\fR widget.  At the time this command is invoked, there
must not exist a window named \fIpathName\fR, but \fIpathName\fR's
parent must exist.  Additional options may may be specified on the
command line or in the option database to configure aspects of the
strip chart such as its colors and font.  See the \fBconfigure\fR operation
below for the exact details as to what \fIoption\fR and \fIvalue\fR
pairs are valid.
.PP
If successful, \fBstripchart\fR returns the path name of the widget.  It
also creates a new Tcl command by the same name.  You can use this
command to perform various operations that query or modify the graph.
The general form is:
.DS
\fIpathName \fIoperation\fR \fR?\fIarg\fR?...
.DE
Both \fIoperation\fR and its arguments determine the exact behavior of
the command.  The operations available for the strip chart are described in 
the 
.SB "STRIPCHART OPERATIONS"
section.
.PP
The command can also be used to access components of the strip chart.
.DS
\fIpathName component operation\fR ?\fIarg\fR?...
.DE
The operation, now located after the name of the component, is the
function to be performed on that component. Each component has its own
set of operations that manipulate that component.  They will be
described below in their own sections.
.SH EXAMPLE
The \fBstripchart\fR command creates a new strip chart.  
.CS
# Create a new strip chart.  Plotting area is black.
stripchart .s -plotbackground black
.CE
A new Tcl command \f(CW.s\fR is also created.  This command can be used
to query and modify the strip chart.  For example, to change the title of
the strip chart to "My Plot", you use the new command and the widget's
\fBconfigure\fR operation.
.CS
# Change the title.
\&.s configure \-title "My Plot"
.CE
A strip chart has several components. To access a particular component you
use the component's name. For example, to add data elements, you use 
the new command and the \fBelement\fR component.
.CS
# Create a new element named "line1"
\&.s element create line1 \\
	\-xdata { 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 } \\
	\-ydata { 26.18 50.46 72.85 93.31 111.86 128.47 143.14 
		155.85 166.60 175.38 }
.CE
The element's X and Y coordinates are specified using lists of
numbers.  Alternately, BLT vectors could be used to hold the X\-Y
coordinates.
.CS
# Create two vectors and add them to the strip chart.
vector xVec yVec
xVec set { 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 }
yVec set { 26.18 50.46 72.85 93.31 111.86 128.47 143.14 155.85 
	166.60 175.38 }
\&.s element create line1 \-xdata xVec \-ydata yVec
.CE
The advantage of using vectors is that when you modify one, the graph
is automatically redrawn to display the new values.
.CS
# Change the X\-Y coordinates of the first point.
set xVec(0) 0.18
set yVec(0) 25.18
.CE
An element named \f(CWline1\fR is now created in \f(CW.s\fR.  By
default, the element's label in the legend will be also \f(CWline1\fR.
You can change the label, or specify no legend entry, again using the
element's \fBconfigure\fR operation.
.CS
# Don't display "line1" in the legend.
\&.s element configure line1 -label ""
.CE
You can configure more than just the element's label.  An element has
many attributes such as symbol type and size, dashed or solid lines,
colors, line width, etc.
.CS
\&.s element configure line1 -symbol square -color red \\
	-dashes { 2 4 2 } -linewidth 2 -pixels 2c
.CE
Four coordinate axes are automatically created: \f(CWx\fR, \f(CWx2\fR,
\f(CWy\fR, and \f(CWy2\fR.  And by default, elements are mapped onto the
axes \f(CWx\fR and \f(CWy\fR.  This can be changed with the \fB\-mapx\fR
and \fB\-mapy\fR options.
.CS
# Map "line1" on the alternate Y-axis "y2".
\&.s element configure line1 -mapy y2
.CE
Axes can be configured in many ways too.  For example, you change the
scale of the Y-axis from linear to log using the \fBaxis\fR operation.
.CS
# Y-axis is log scale.
\&.s axis configure y -logscale yes
.CE
Axis limits are reset by simply specifying new axis
limits using the \fB\-min\fR and \fB\-max\fR configuration options.
.CS
\&.s axis configure x -min 1.0 -max 1.5
\&.s axis configure y -min 12.0 -max 55.15
.CE
By default, the limits of the axis are determined from data values.
To reset back to the default limits, set the \fB\-min\fR and
\fB\-max\fR options to the empty value.
.CS
# Reset the axes to autoscale again.
\&.s axis configure x -min {} -max {}
\&.s axis configure y -min {} -max {}
.CE
It's common with strip charts to automatically maintain a view of
the most recent time points.  You can do this my setting the 
\fB\-autorange\fR option.
.CS
\&.s axis configure x -autorange 20.0
.CE
If the time points are added in X-coordinates 1.0 unit, only the last
twenty time points will be displayed.  As more data
is added, the view will march along.
.PP
Sometimes the rate of data is so high that changing the axis limits
with each additional time point is prohibitive.  You can use the
\fB\-shiftby\fR option to define an increment to shift the view
when needed.  
.CS
\&.s axis configure x -shiftby 15.0
.CE
When the view is shifted, it will allow a range of 15
new time points to be added until the axis limits are recomputed.
.PP
By default, the legend is displayed in the right margin.  You can
change this or any other legend configuration options using the
\fBlegend\fR component.
.CS
# Configure the legend font, color, and relief
\&.s legend configure -position left -relief raised \\
	-font fixed -fg blue
.CE
To prevent the legend from being displayed, turn on the \fB\-hide\fR
option.
.CS
# Don't display the legend.
\&.s legend configure -hide yes\fR
.CE
The \fBstripchart\fR widget has simple drawing procedures called markers.
They can be used to highlight or annotate data in the strip chart. The types
of markers available are bitmaps, images, polygons, lines, or windows.
Markers can be used, for example, to mark or brush points.  Here 
is a text marker which labels the data first point.  Markers
are created using the \fBmarker\fR operation.
.CS
# Create a label for the first data point of "line1".
\&.s marker create text \-name first_marker \-coords { 0.2 26.18 } \\
	\-text "start" \-anchor se \-xoffset -10 \-yoffset -10
.CE
This creates a text marker named \f(CWfirst_marker\fR.  It will display
the text "start" near the coordinates of the first data point.  The
\fB\-anchor\fR, \fB\-xoffset\fR, and \fB\-yoffset\fR options are used
to display the marker above and to the left of the data point, so that
the actual data point isn't covered by the marker.  By default,
markers are drawn last, on top of data.  You can change this with the
\fB\-under\fR option.
.CS
# Draw the label before elements are drawn.
\&.s marker configure first_marker -under yes
.CE
You can add cross hairs or grid lines using the \fBcrosshairs\fR and
\fBgrid\fR operations.
.CS
# Display both cross hairs and grid lines.
\&.s crosshairs configure \-hide no \-color red
\&.s grid configure \-hide no \-dashes { 2 2 }
.CE
Finally, to get hardcopy of the strip chart, use the \fBpostscript\fR
operation.
.CS
# Print the strip chart into file "file.ps"
\&.s postscript output file.ps \-maxpect yes \-decorations no
.CE
This generates a file \f(CWfile.ps\fR containing the encapsulated
PostScript of the strip chart.  The option \fB\-maxpect\fR says to scale the
plot to the size of the page.  Turning off the \fB\-decorations\fR
option indicates that no borders or color backgrounds should be
displayed (i.e. the background of the margins, legend, and plotting
area will be white).
.SH "STRIPCHART OPERATIONS"
.TP
\fIpathName \fBaxis \fIoperation\fR ?\fIarg\fR?...
See the 
.SB "AXIS COMPONENTS"
section.
.TP
\fIpathName \fBbar \fIelemName \fR?\fIoption value\fR?...
Creates a new barchart element \fIelemName\fR.  It's an
error if an element \fIelemName\fR already exists.  
See the manual for \fBbarchart\fR for details about
what \fIoption\fR and \fIvalue\fR pairs are valid.
.TP
\fIpathName \fBcget\fR \fIoption\fR
Returns the current value of the stripchart configuration option given by
\fIoption\fR.  \fIOption\fR may be any option described
below for the \fBconfigure\fR operation.
.TP
\fIpathName \fBconfigure \fR?\fIoption value\fR?...
Queries or modifies the configuration options of the strip chart.  If
\fIoption\fR isn't specified, a list describing all of the current
options for \fIpathName\fR is returned.  If \fIoption\fR is specified,
but not \fIvalue\fR, then a list describing \fIoption\fR is returned.
If one or more \fIoption\fR and \fIvalue\fR pairs are specified, then
for each pair, the stripchart option \fIoption\fR is set to \fIvalue\fR.
The following options are valid for the stripchart.
.RS
.TP
\fB\-background \fIcolor\fR
Sets the background color. This includes the margins and
legend, but not the plotting area.
.TP
\fB\-borderwidth \fIpixels\fR
Sets the width of the 3\-D border around the outside edge of the widget.  The
\fB\-relief\fR option determines if the border is to be drawn.  The
default is \f(CW2\fR.
.TP
\fB\-bottommargin \fIpixels\fR
Specifies the size of the margin below the X\-coordinate axis.  If
\fIpixels\fR is \f(CW0\fR, the size of the margin is selected automatically.
The default is \f(CW0\fR.
.TP
\fB\-bufferelements \fIboolean\fR
Indicates whether to draw elements into a pixmap before displaying
them on the screen.  The advantage of buffering elements is when markers
are used heavily.  Markers can be moved and redrawn without requiring
every element to be redrawn again.  The disadvantage is that it takes
slightly longer to draw the graph. If \fIboolean\fR is true, data elements are
drawn to an internal pixmap.  The option should be turned off if the plot
is updated frequently. See the
.SB "SPEED TIPS"
section.
The default is \f(CW1\fR.
.TP
\fB\-buffergraph \fIboolean\fR
Indicates whether to draw the graph into a pixmap first.
If \fIboolean\fR is true, the entire graph is drawn into a pixmap and then
copied onto the screen.  This reduces flashing.  If false, the graph is 
drawn directly into the window.  Especially under Windows, turning off the 
option can be helpful when the stripchart is updated frequently.  Turning 
off this option also turns \fB\-bufferelements\fR off. See the
.SB "SPEED TIPS"
section.
The default is \f(CW1\fR.
.TP
\fB\-cursor \fIcursor\fR
Specifies the widget's cursor.  The default
cursor is \f(CWcrosshair\fR.
.TP
\fB\-font \fIfontName\fR 
Specifies the title font. The default is
\f(CW*-Helvetica-Bold-R-Normal-*-18-180-*\fR.
.TP
\fB\-halo \fIpixels\fR 
Specifies a maximum distance to consider when searching for the
closest data point (see the element's \fBclosest\fR operation below).
Data points further than \fIpixels\fR away are ignored.  The default is
\f(CW0.5i\fR.
.TP
\fB\-height \fIpixels\fR
Specifies the requested height of widget.  The default is
\f(CW4i\fR.
.TP
\fB\-invertxy \fIboolean\fR
Indicates whether the placement X\-axis and Y\-axis should be inverted.  If
\fIboolean\fR is true, the X and Y axes are swapped.  The default is
\f(CW0\fR.
.TP
\fB\-justify \fIjustify\fR
Specifies how the title should be justified.  This matters only when
the title contains more than one line of text. \fIJustify\fR must be
\f(CWleft\fR, \f(CWright\fR, or \f(CWcenter\fR.  The default is
\f(CWcenter\fR.
.TP
\fB\-leftmargin \fIpixels\fR
Sets the size of the margin from the left edge of the window to 
the Y\-coordinate axis.  If \fIpixels\fR is \f(CW0\fR, the size is
calculated automatically.  The default is \f(CW0\fR.
.TP
\fB\-plotbackground \fIcolor\fR
Specifies the background color of the plotting area.  The default is
\f(CWwhite\fR.
.TP
\fB\-plotborderwidth \fIpixels\fR
Sets the width of the 3-D border around the plotting area.  The
\fB\-plotrelief\fR option determines if a border is drawn.  The
default is \f(CW2\fR.
.TP
\fB\-plotpadx \fIpad\fR
Sets the amount of padding to be added to the left and right sides of
the plotting area.  \fIPad\fR can be a list of one or two screen
distances.  If \fIpad\fR has two elements, the left side of the
plotting area entry is padded by the first distance and the right side
by the second.  If \fIpad\fR is just one distance, both the left and
right sides are padded evenly.  The default is \f(CW8\fR.
.TP
\fB\-plotpady \fIpad\fR
Sets the amount of padding to be added to the top and bottom of the
plotting area.  \fIPad\fR can be a list of one or two screen
distances.  If \fIpad\fR has two elements, the top of the plotting
area is padded by the first distance and the bottom by the second.  If
\fIpad\fR is just one distance, both the top and bottom are padded
evenly.  The default is \f(CW8\fR.
.TP
\fB\-plotrelief \fIrelief\fR
Specifies the 3-D effect for the plotting area.  \fIRelief\fR
indicates how the interior of the plotting area should appear relative
to rest of the strip chart; for example, \f(CWraised\fR means the plot should
appear to protrude from the strip chart, relative to the surface of the
strip chart.  The default is \f(CWsunken\fR.
.TP
\fB\-relief \fIrelief\fR
Specifies the 3-D effect for the widget.  \fIRelief\fR
indicates how the strip chart should appear relative to widget it is packed
into; for example, \f(CWraised\fR means the strip chart should
appear to protrude.  The default is \f(CWflat\fR.
.TP
\fB\-rightmargin \fIpixels\fR
Sets the size of margin from the plotting area to the right edge of
the window.  By default, the legend is displayed in this margin.  If
\fIpixels\fR is than 1, the margin size is selected automatically.
.TP
\fB\-takefocus\fR \fIfocus\fR 
Provides information used when moving the focus from window to window
via keyboard traversal (e.g., Tab and Shift-Tab).  If \fIfocus\fR is
\f(CW0\fR, this means that this window should be skipped entirely during
keyboard traversal.  \f(CW1\fR means that the this window should always
receive the input focus.  An empty value means that the traversal
scripts make the decision whether to focus on the window.
The default is \f(CW""\fR.
.TP
\fB\-tile \fIimage\fR 
Specifies a tiled background.  If \fIimage\fR isn't
\f(CW""\fR, the background is tiled using \fIimage\fR.
Otherwise, the normal background color is drawn (see the
\fB\-background\fR option).  \fIImage\fR must be an image created
using the Tk \fBimage\fR command.  The default is \f(CW""\fR.
.TP
\fB\-title \fItext\fR 
Sets the title to \fItext\fR. If \fItext\fR is \f(CW""\fR,
no title will be displayed.
.TP
\fB\-topmargin \fIpixels\fR
Specifies the size of the margin above the x2 axis.  If \fIpixels\fR
is \f(CW0\fR, the margin size is calculated automatically.
.TP
\fB\-width \fIpixels\fR
Specifies the requested width of the widget.  The default is
\f(CW5i\fR.
.RE
.TP
\fIpathName \fBcrosshairs \fIoperation \fR?\fIarg\fR?
See the 
.SB "CROSSHAIRS COMPONENT"
section.
.TP
\fIpathName \fBelement \fIoperation \fR?\fIarg\fR?...
See the 
.SB "ELEMENT COMPONENTS"
section.
.TP
\fIpathName \fBextents \fIitem\fR 
Returns the size of a particular item in the strip chart.  \fIItem\fR must
be either \f(CWleftmargin\fR, \f(CWrightmargin\fR, \f(CWtopmargin\fR,
\f(CWbottommargin\fR, \f(CWplotwidth\fR, or \f(CWplotheight\fR.
.TP
\fIpathName \fBgrid \fIoperation \fR?\fIarg\fR?...
See the 
.SB "GRID COMPONENT"
section.
.TP
\fIpathName \fBinvtransform \fIwinX winY\fR 
Performs an inverse coordinate transformation, mapping window
coordinates back to graph coordinates, using the standard X\-axis and Y\-axis.
Returns a list of containing the graph coordinates.
.TP
\fIpathName \fBlegend \fIoperation \fR?\fIarg\fR?...
See the 
.SB "LEGEND COMPONENT"
section.
.TP
\fIpathName \fBline \fIelemName\fR ?\fIoption value\fR?...
The operation is the same as \fBelement\fR.
.TP
\fIpathName \fBmarker \fIoperation \fR?\fIarg\fR?...
See the 
.SB "MARKER COMPONENTS"
section.
.TP
\fIpathName\fR \fBmetafile\fR ?\fIfileName\fR?
\fIThis operation is for Window platforms only\fR.  
Creates a Windows enhanced metafile of the stripchart.
If present, \fIfileName\fR is the file name of the new metafile.
Otherwise, the metafile is automatically added to the clipboard.
.TP
\fIpathName \fBpostscript \fIoperation \fR?\fIarg\fR?...
See the 
.SB "POSTSCRIPT COMPONENT"
section.
.TP
\fIpathName \fBsnap \fIphotoName\fR
Takes a snapshot of the strip chart and stores the contents in the photo
image \fIphotoName\fR.  \fIPhotoName\fR is the name of a Tk photo
image that must already exist.
.TP
\fIpathName \fBtransform \fIx y\fR 
Performs a coordinate transformation, mapping graph coordinates to
window coordinates, using the standard X\-axis and Y\-axis.
Returns a list containing the X\-Y screen coordinates.
.TP
\fIpathName \fBxaxis \fIoperation\fR ?\fIarg\fR?...
.TP
\fIpathName \fBx2axis \fIoperation\fR ?\fIarg\fR?... 
.TP
\fIpathName \fByaxis \fIoperation\fR ?\fIarg\fR?... 
.TP
\fIpathName \fBy2axis \fIoperation\fR ?\fIarg\fR?... 
See the 
.SB "AXIS COMPONENTS"
section.
.SH "STRIPCHART COMPONENTS"
A strip chart is composed of several components: coordinate axes, data
elements, legend, grid, cross hairs, postscript, and annotation
markers. Instead of one big set of configuration options and
operations, the strip chart is partitioned, where each component has its own
configuration options and operations that specifically control that
aspect or part of the strip chart. 
.SS "AXIS COMPONENTS"
Four coordinate axes are automatically created: two X\-coordinate axes
(\f(CWx\fR and \f(CWx2\fR) and two Y\-coordinate axes (\f(CWy\fR, and
\f(CWy2\fR).  By default, the axis \f(CWx\fR is located in the bottom
margin, \f(CWy\fR in the left margin, \f(CWx2\fR in the top margin, and
\f(CWy2\fR in the right margin.
.PP
An axis consists of the axis line, title, major and minor ticks, and
tick labels.  Major ticks are drawn at uniform intervals along the
axis.  Each tick is labeled with its coordinate value.  Minor ticks
are drawn at uniform intervals within major ticks.  
.PP
The range of the axis controls what region of data is plotted.
Data points outside the minimum and maximum limits of the axis are
not plotted.  By default, the minimum and maximum limits are
determined from the data, but you can reset either limit.
.PP
You can create and use several axes. To create an axis, invoke
the axis component and its create operation.
.CS
# Create a new axis called "temperature"
\&.s axis create temperature
.CE
You map data elements to an axis using the element's \-mapy and \-mapx
configuration options. They specify the coordinate axes an element
is mapped onto.
.CS
# Now map the temperature data to this axis.
\&.s element create "temp" \-xdata $x \-ydata $tempData \\
    \-mapy temperature
.CE
While you can have many axes, only four axes can be displayed
simultaneously.  They are drawn in each of the margins surrounding the
plotting area.  The axes x and y are drawn in the bottom and left
margins. The axes x2 and y2 are drawn in top and right margins.
Only x and y are shown by default. Note that the axes can have
different scales.
.PP
To display a different axis, you invoke one of the following
components: \fBxaxis\fR, \fByaxis\fR, \fBx2axis\fR, and \fBy2axis\fR.
The \fBuse\fR operation designates the axis to be drawn in the
corresponding margin: \fBxaxis\fR in the bottom, \fByaxis\fR in the left, 
\fBx2axis\fR in the top, and \fBy2axis\fR in the right.
.CS
# Display the axis temperature in the left margin.
\&.s yaxis use temperature
.CE
.PP
You can configure axes in many ways. The axis scale can be linear or
logarithmic.  The values along the axis can either monotonically
increase or decrease.  If you need custom tick labels, you can specify
a Tcl procedure to format the label as you wish.  You can
control how ticks are drawn, by changing the major tick interval
or the number of minor ticks.  You can define non-uniform tick intervals,
such as for time-series plots.
.PP
.TP
\fIpathName \fBaxis \fBcget \fIaxisName \fIoption\fR
Returns the current value of the option given by \fIoption\fR for
\fIaxisName\fR.  \fIOption\fR may be any option described below
for the axis \fBconfigure\fR operation.
.TP
\fIpathName \fBaxis \fBconfigure \fIaxisName \fR?\fIoption value\fR?...
Queries or modifies the configuration options of \fIaxisName\fR.  If
\fIoption\fR isn't specified, a list describing all the current
options for \fIaxisName\fR is returned.  If \fIoption\fR is specified, but
not \fIvalue\fR, then a list describing \fIoption\fR is
returned.  If one or more \fIoption\fR and \fIvalue\fR pairs are
specified, then for each pair, the axis option \fIoption\fR is set to
\fIvalue\fR.  
The following options are valid for axes.
.RS
.TP
\fB\-autorange \fIrange\fR 
Sets the range of values for the axis to \fIrange\fR.  The axis limits
are automatically reset  to display the most recent data points in this range.  
If \fIrange\fR is 0.0, the range is
determined from the limits of the data.  If \fB\-min\fR or \fB-max\fR
are specified, they override this option.  The default is \f(CW0.0\fR.
.TP
\fB\-color \fIcolor\fR
Sets the color of the axis and tick labels.
The default is \f(CWblack\fR.
.TP
\fB\-command \fIprefix\fR
Specifies a Tcl command to be invoked when formatting the axis tick
labels. \fIPrefix\fR is a string containing the name of a Tcl proc and
any extra arguments for the procedure.  This command is invoked for each
major tick on the axis.  Two additional arguments are passed to the
procedure: the pathname of the widget and the current the numeric
value of the tick.  The procedure returns the formatted tick label.  If
\f(CW""\fR is returned, no label will appear next to the tick.  You can
get the standard tick labels again by setting \fIprefix\fR to
\f(CW""\fR.  The default is \f(CW""\fR.
.sp 1
Please note that this procedure is invoked while the strip chart is redrawn.
You may query the configuration options.  But do not reset them, because 
this can have unexpected results.
.TP
\fB\-descending \fIboolean\fR 
Indicates whether the values along the axis are monotonically increasing or
decreasing.  If \fIboolean\fR is true, the axis values will be
decreasing.  The default is \f(CW0\fR.
.TP
\fB\-hide \fIboolean\fR
Indicates whether the axis is displayed. 
.TP
\fB\-justify \fIjustify\fR
Specifies how the axis title should be justified.  This matters only
when the axis title contains more than one line of text. \fIJustify\fR
must be \f(CWleft\fR, \f(CWright\fR, or \f(CWcenter\fR.  The default is
\f(CWcenter\fR.
.TP
\fB\-limits \fIformatStr\fR
Specifies a printf-like description to format the minimum and maximum
limits of the axis.  The limits are displayed at the top/bottom or
left/right sides of the plotting area.  \fIFormatStr\fR is a list of
one or two format descriptions.  If one description is supplied, both
the minimum and maximum limits are formatted in the same way.  If two,
the first designates the format for the minimum limit, the second for
the maximum.  If \f(CW""\fR is given as either description, then 
the that limit will not be displayed.  The default is \f(CW""\fR.
.TP
\fB\-linewidth \fIpixels\fR
Sets the width of the axis and tick lines.  The default is \f(CW1\fR
pixel.
.TP
\fB\-logscale \fIboolean\fR
Indicates whether the scale of the axis is logarithmic or linear.  If
\fIboolean\fR is true, the axis is logarithmic.  The default scale is
linear.
.TP
\fB\-loose \fIboolean\fR
Indicates whether the limits of the axis should fit the data points tightly,
at the outermost data points, or loosely, at the outer tick intervals.
This is relevant only when the axis limit is automatically calculated.
If \fIboolean\fR is true, the axis range is "loose".
The default is \f(CW0\fR.
.TP
\fB\-majorticks \fImajorList\fR
Specifies where to display major axis ticks.  You can use this option
to display ticks at non-uniform intervals.  \fIMajorList\fR is a list
of axis coordinates designating the location of major ticks.  No
minor ticks are drawn.  If \fImajorList\fR is \f(CW""\fR, 
major ticks will be automatically computed. The default is \f(CW""\fR.
.TP
\fB\-max \fIvalue\fR
Sets the maximum limit of \fIaxisName\fR.  Any data point greater 
than \fIvalue\fR is not displayed.  If \fIvalue\fR is \f(CW""\fR, 
the maximum limit is calculated using the largest data value.
The default is \f(CW""\fR.
.TP
\fB\-min \fIvalue\fR
Sets the minimum limit of \fIaxisName\fR. Any data point less than 
\fIvalue\fR is not displayed.  If \fIvalue\fR is \f(CW""\fR,
the minimum limit is calculated using the smallest data value.
The default is \f(CW""\fR.
.TP
\fB\-minorticks \fIminorList\fR
Specifies where to display minor axis ticks.  You can use this option
to display minor ticks at non-uniform intervals. \fIMinorList\fR is a
list of real values, ranging from 0.0 to 1.0, designating the placement of
a minor tick.  No minor ticks are drawn if the \fB\-majortick\fR
option is also set.  If \fIminorList\fR is \f(CW""\fR, minor ticks will
be automatically computed. The default is \f(CW""\fR.
.TP
\fB\-rotate \fItheta\fR
Specifies the how many degrees to rotate the axis tick labels.
\fITheta\fR is a real value representing the number of degrees
to rotate the tick labels.  The default is \f(CW0.0\fR degrees.
.TP
\fB\-shiftby \fIvalue\fR
Specifies how much to automatically shift the range of the axis.
When the new data exceeds the current axis maximum, the maximum
is increased in increments of \fIvalue\fR.  You can use this
option to prevent the axis limits from being recomputed
at each new time point. If \fIvalue\fR is 0.0, then no automatic
shifting is done. The default is \f(CW0.0\fR.
.TP
\fB\-showticks \fIboolean\fR
Indicates whether axis ticks should be drawn. If \fIboolean\fR is
true, ticks are drawn.  If false, only the
axis line is drawn. The default is \f(CW1\fR.
.TP
\fB\-stepsize \fIvalue\fR
Specifies the interval between major axis ticks.  If \fIvalue\fR isn't
a valid interval (must be less than the axis range), 
the request is ignored and the step size is automatically calculated.
.TP
\fB\-subdivisions \fInumber\fR 
Indicates how many minor axis ticks are
to be drawn.  For example, if \fInumber\fR is two, only one minor
tick is drawn.  If \fInumber\fR is one, no minor ticks are
displayed.  The default is \f(CW2\fR.
.TP
\fB\-tickfont \fIfontName\fR 
Specifies the font for axis tick labels. The default is
\f(CW*-Courier-Bold-R-Normal-*-100-*\fR.
.TP
\fB\-ticklength \fIpixels\fR
Sets the length of major and minor ticks (minor ticks are half the
length of major ticks). If \fIpixels\fR is less than zero, the axis
will be inverted with ticks drawn pointing towards the plot.  The
default is \f(CW0.1i\fR.
.TP
\fB\-title \fItext\fR
Sets the title of the axis. If \fItext\fR is 
\f(CW""\fR, no axis title will be displayed.  
.TP
\fB\-titlecolor \fIcolor\fR
Sets the color of the axis title. The default is \f(CWblack\fR.
.TP
\fB\-titlefont \fIfontName\fR 
Specifies the font for axis title. The default is
\f(CW*-Helvetica-Bold-R-Normal-*-14-140-*\fR.
.PP
Axis configuration options may be also be set by the \fBoption\fR
command.  The resource class is \f(CWAxis\fR.  The resource names
are the names of the axes (such as \f(CWx\fR or \f(CWx2\fR).
.CS
option add *Stripchart.Axis.Color  blue
option add *Stripchart.x.LogScale  true
option add *Stripchart.x2.LogScale false
.CE
.RE
.TP
\fIpathName \fBaxis \fBcreate \fIaxisName \fR?\fIoption value\fR?...
Creates a new axis by the name \fIaxisName\fR.  No axis by the same
name can already exist. \fIOption\fR and \fIvalue\fR are described 
in above in the axis \fBconfigure\fR operation.
.TP
\fIpathName \fBaxis \fBdelete \fR?\fIaxisName\fR?...
Deletes the named axes. An axis is not really
deleted until it is not longer in use, so it's safe to delete
axes mapped to elements.
.TP
\fIpathName \fBaxis invtransform \fIaxisName value\fR
Performs the inverse transformation, changing the screen coordinate
\fIvalue\fR to a graph coordinate, mapping the value mapped to
\fIaxisName\fR.  Returns the graph coordinate.
.TP
\fIpathName \fBaxis limits \fIaxisName\fR
Returns a list of the minimum and maximum limits for \fIaxisName\fR.  The order
of the list is \f(CWmin max\fR.
.TP
\fIpathName \fBaxis names \fR?\fIpattern\fR?...
Returns a list of axes matching zero or more patterns.  If no
\fIpattern\fR argument is give, the names of all axes are returned.
.TP
\fIpathName \fBaxis transform \fIaxisName value\fR
Transforms the coordinate \fIvalue\fR to a screen coordinate by mapping
the it to \fIaxisName\fR.  Returns the transformed screen coordinate.
.PP
Only four axes can be displayed simultaneously.  By default, they are
\f(CWx\fR, \f(CWy\fR, \f(CWx2\fR, and \f(CWy2\fR.  You can swap in a different
axis with \fBuse\fR operation of the special axis components:
\fBxaxis\fR, \fBx2axis\fR, \fByaxis\fR, and \fBy2axis\fR.
.CS
\&.g create axis temp
\&.g create axis time
\&...
\&.g xaxis use temp
\&.g yaxis use time
.CE
Only the axes specified for use are displayed on the screen.
.PP
The \fBxaxis\fR, \fBx2axis\fR, \fByaxis\fR, and \fBy2axis\fR
components operate on an axis location rather than a specific axis
like the more general \fBaxis\fR component does.  The \fBxaxis\fR
component manages the X-axis located in the bottom margin (whatever
axis that happens to be).  Likewise, \fByaxis\fR uses the Y-axis in
the left margin, \fBx2axis\fR the top X-axis, and \fBy2axis\fR the
right Y-axis.
.PP
They implicitly control the axis that is currently using to that
location.  By default, \fBxaxis\fR uses the \f(CWx\fR axis, \fByaxis\fR
uses \f(CWy\fR, \fBx2axis\fR uses \f(CWx2\fR, and \fBy2axis\fR uses
\f(CWy2\fR.  These components can be more convenient to use than always
determining what axes are current being displayed by the graph.
.PP
The following operations are available for axes. They mirror exactly
the operations of the \fBaxis\fR component.  The \fIaxis\fR argument
must be \fBxaxis\fR, \fBx2axis\fR, \fByaxis\fR, or \fBy2axis\fR.
.TP
\fIpathName \fIaxis \fBcget \fIoption\fR
.TP
\fIpathName \fIaxis \fBconfigure \fR?\fIoption value\fR?...
.TP
\fIpathName \fIaxis\fB invtransform \fIvalue\fR
.TP
\fIpathName \fIaxis \fBlimits\fR
.TP
\fIpathName \fIaxis\fB transform \fIvalue\fR
.TP
\fIpathName \fIaxis\fB use \fR?\fIaxisName\fR?  
Designates the axis \fIaxisName\fR is to be displayed at this
location.  \fIAxisName\fR can not be already in use at another location.  
This command returns the name of the axis currently using this location.
.SS "CROSSHAIRS COMPONENT"
Cross hairs consist of two intersecting lines (one vertical and one horizontal)
drawn completely across the plotting area.  They are used to position
the mouse in relation to the coordinate axes.  Cross hairs differ from line
markers in that they are implemented using XOR drawing primitives.
This means that they can be quickly drawn and erased without redrawing
the entire strip chart.
.PP
The following operations are available for cross hairs:
.TP
\fIpathName \fBcrosshairs cget \fIoption\fR
Returns the current value of the cross hairs configuration option
given by \fIoption\fR.  \fIOption\fR may be any option
described below for the cross hairs \fBconfigure\fR operation.
.TP
\fIpathName \fBcrosshairs configure \fR?\fIoption value\fR?...  
Queries or modifies the configuration options of the cross hairs.  If
\fIoption\fR isn't specified, a list describing all the current
options for the cross hairs is returned.  If \fIoption\fR is specified,
but not \fIvalue\fR, then a list describing \fIoption\fR is returned.
If one or more \fIoption\fR and \fIvalue\fR pairs are specified, then
for each pair, the cross hairs option \fIoption\fR is set to
\fIvalue\fR.
The following options are available for cross hairs.
.RS
.TP
\fB\-color \fIcolor\fR 
Sets the color of the cross hairs.  The default is \f(CWblack\fR.
.TP
\fB\-dashes \fIdashList\fR
Sets the dash style of the cross hairs. \fIDashList\fR is a list of up
to 11 numbers that alternately represent the lengths of the dashes
and gaps on the cross hair lines.  Each number must be between 1 and
255.  If \fIdashList\fR is \f(CW""\fR, the cross hairs will be solid
lines.
.TP
\fB\-hide \fIboolean\fR
Indicates whether cross hairs are drawn. If \fIboolean\fR is true,
cross hairs are not drawn.  The default is \f(CWyes\fR.
.TP
\fB\-linewidth \fIpixels\fR
Set the width of the cross hair lines.  The default is \f(CW1\fR.
.TP
\fB\-position \fIpos\fR 
Specifies the screen position where the cross hairs intersect.
\fIPos\fR must be in the form "\[email protected],y\fR", where \fIx\fR and \fIy\fR
are the window coordinates of the intersection.
.PP
Cross hairs configuration options may be also be set by the
\fBoption\fR command.  The resource name and class are
\f(CWcrosshairs\fR and \f(CWCrosshairs\fR respectively.
.CS
option add *Stripchart.Crosshairs.LineWidth 2
option add *Stripchart.Crosshairs.Color     red
.CE
.RE
.TP
\fIpathName \fBcrosshairs off\fR
Turns of the cross hairs. 
.TP
\fIpathName \fBcrosshairs on\fR
Turns on the display of the cross hairs.
.TP
\fIpathName \fBcrosshairs toggle\fR 
Toggles the current state of the cross hairs, alternately mapping and
unmapping the cross hairs.
.SS "ELEMENT COMPONENTS"
A data element represents a set of data.  It contains x and y vectors
containing the coordinates of the data points.  Elements can be
displayed with a symbol at each data point and lines connecting the
points.  Elements also control the appearance of the data, such as the
symbol type, line width, color etc.
.PP
When new data elements are created, they are automatically added to a
list of displayed elements.   The display list controls what elements
are drawn and in what order.  
.PP
The following operations are available for elements.
.TP
\fIpathName \fBelement activate \fIelemName \fR?\fIindex\fR?...
Specifies the data points of element \fIelemName\fR to be drawn
using active foreground and background colors.  \fIElemName\fR is the
name of the element and \fIindex\fR is a number representing the index
of the data point. If no indices are present then all data points
become active.
.TP
\fIpathName \fBelement cget \fIelemName \fIoption\fR
Returns the current value of the element configuration option given by 
\fIoption\fR.  \fIOption\fR may be any option described below
for the element \fBconfigure\fR operation.
.TP
\fIpathName \fBelement closest \fIx y\fR \fIvarName\fR ?\fIoption value\fR?... ?\fIelemName\fR?...
Finds the data point closest to the window coordinates \fIx\fR and
\fIy\fR in the element \fIelemName\fR.  \fIElemName\fR is the name of
an element, that must not be hidden.  If no elements are specified,
then all visible elements are searched.  It returns via the array
variable \fIvarName\fR the name of the closest element, the index of
its closest point, and the graph coordinates of the point. Returns
\f(CW0\fR, if no data point within the threshold distance can be found,
otherwise \f(CW1\fR is returned.  The following
\fIoption\fR\-\fIvalue\fR pairs are available.
.RS
.TP
\fB\-halo \fIpixels\fR
Specifies a threshold distance where selected data points are ignored.
\fIPixels\fR is a valid screen distance, such as \f(CW2\fR or \f(CW1.2i\fR.
If this option isn't specified, then it defaults to the value of the
stripchart's \fB\-halo\fR option.
.TP
\fB\-interpolate \fIboolean\fR
Indicates that both the data points and interpolated points along
the line segment formed should be considered.  If \fIboolean\fR 
is true, the closest line segment will be selected instead of the
closest point. If this option isn't specified, \fIboolean\fR defaults 
to \f(CW0\fR.
.RE
.TP
\fIpathName \fBelement configure \fIelemName \fR?\fIoption value\fR?...
Queries or modifies the configuration options for elements.  If
\fIoption\fR isn't specified, a list describing all the current
options for \fIelemName\fR is returned.  If \fIoption\fR is specified,
but not \fIvalue\fR, then a list describing the option \fIoption\fR is
returned.  If one or more \fIoption\fR and \fIvalue\fR pairs are
specified, then for each pair, the element option \fIoption\fR is set
to \fIvalue\fR.  The following options are valid for elements.
.RS
.TP
\fB\-activepen \fIpenName\fR
Specifies pen to use to draw active element.  If \fIpenName\fR is
\f(CW""\fR, no active elements will be drawn.  The default is 
\f(CWactiveLine\fR.
.TP
\fB\-color \fIcolor\fR 
Sets the color of the traces connecting the data points.  
.TP
\fB\-dashes \fIdashList\fR
Sets the dash style of element line. \fIDashList\fR is a list of up to
11 numbers that alternately represent the lengths of the dashes and
gaps on the element line.  Each number must be between 1 and 255.  If
\fIdashList\fR is \f(CW""\fR, the lines will be solid.
.TP
\fB\-data \fIcoordList\fR
Specifies the X\-Y coordinates of the data.  \fICoordList\fR is a
list of numeric expressions representing the X\-Y coordinate pairs
of each data point.
.TP
\fB\-fill \fIcolor\fR 
Sets the interior color of symbols.  If \fIcolor\fR is \f(CW""\fR, then
the interior of the symbol is transparent.  If \fIcolor\fR is
\f(CWdefcolor\fR, then the color will be the same as the \fB\-color\fR
option.  The default is \f(CWdefcolor\fR.
.TP
\fB\-hide \fIboolean\fR
Indicates whether the element is displayed.  The default is \f(CWno\fR.
.TP
\fB\-label \fItext\fR
Sets the element's label in the legend.  If \fItext\fR
is \f(CW""\fR, the element will have no entry in the legend.
The default label is the element's name.
.TP
\fB\-linewidth \fIpixels\fR 
Sets the width of the connecting lines between data points.  If
\fIpixels\fR is \f(CW0\fR, no connecting lines will be drawn between
symbols.  The default is \f(CW0\fR.
.TP
\fB\-mapx \fIxAxis\fR
Selects the X\-axis to map the element's X\-coordinates onto.
\fIXAxis\fR must be the name of an axis.  The default is \f(CWx\fR.
.TP
\fB\-mapy \fIyAxis\fR
Selects the Y\-axis to map the element's Y\-coordinates onto.
\fIYAxis\fR must be the name of an axis. The default is \f(CWy\fR.
.TP
\fB\-offdash \fIcolor\fR
Sets the color of the stripes when traces are dashed (see the
\fB\-dashes\fR option).  If \fIcolor\fR is \f(CW""\fR, then the "off"
pixels will represent gaps instead of stripes.  If \fIcolor\fR is
\f(CWdefcolor\fR, then the color will be the same as the \fB\-color\fR
option.  The default is \f(CWdefcolor\fR.
.TP
\fB\-outline \fIcolor\fR 
Sets the color or the outline around each symbol.  If \fIcolor\fR is
\f(CW""\fR, then no outline is drawn. If \fIcolor\fR is \f(CWdefcolor\fR,
then the color will be the same as the \fB\-color\fR option.  The
default is \f(CWdefcolor\fR.
.TP
\fB\-outlinewidth \fIpixels\fR 
Sets the width of the outline bordering each symbol.  If \fIpixels\fR
is \f(CW0\fR, no outline will be drawn. The default is \f(CW1\fR.
.TP
\fB\-pixels \fIpixels\fR
Sets the size of symbols.  If \fIpixels\fR is \f(CW0\fR, no symbols will
be drawn.  The default is \f(CW0.125i\fR.
.TP
\fB\-scalesymbols \fIboolean\fR 
If \fIboolean\fR is true, the size of the symbols
drawn for \fIelemName\fR will change with scale of the X\-axis and Y\-axis.
At the time this option is set, the current ranges of the axes are
saved as the normalized scales (i.e scale factor is 1.0) and the
element is drawn at its designated size (see the \fB\-pixels\fR
option).  As the scale of the axes change, the symbol will be scaled
according to the smaller of the X\-axis and Y\-axis scales.  If \fIboolean\fR
is false, the element's symbols are drawn at the designated size,
regardless of axis scales.  The default is \f(CW0\fR.
.TP
\fB\-smooth \fIsmooth\fR 
Specifies how connecting line segments are drawn between data points.
\fISmooth\fR can be either \f(CWlinear\fR, \f(CWstep\fR, \f(CWnatural\fR, or
\f(CWquadratic\fR.  If \fIsmooth\fR is \f(CWlinear\fR, a single line
segment is drawn, connecting both data points. When \fIsmooth\fR is
\f(CWstep\fR, two line segments are drawn. The first is a horizontal
line segment which steps the next x-coordinate.  The second is a
vertical line, moving to the next y-coordinate.  Both \fInatural\fR and
\fIquadratic\fR generate multiple segments between data points.  If
\fInatural\fR, the segments are generated using a cubic spline.  If
\fIquadratic\fR, a quadratic spline is used.  The default is
\fIlinear\fR.
.TP
\fB\-styles \fIstyleList\fR 
Specifies what pen to use based upon the range of weights given.
\fIStyleList\fR is a list of style specifications. Each style
specification, in turn, is a list consisting of a pen name, and
optionally a minimum and maximum range.  Data points whose weight (see
the \fB\-weight\fR option) falls in this range, are drawn with this
pen.  If no range is specified it defaults to the number of the pen in
the list. 
.TP
\fB\-symbol \fIsymbol\fR 
Specifies the symbol for data points.  \fISymbol\fR can be either
\f(CWsquare\fR, \f(CWcircle\fR, \f(CWdiamond\fR, \f(CWplus\fR, \f(CWcross\fR,
\f(CWsplus\fR, \f(CWscross\fR, \f(CWtriangle\fR, \f(CW""\fR (where no symbol
is drawn), or a bitmap.  Bitmaps are specified as "\fIsource\fR
?\fImask\fR?", where \fIsource\fR is the name of the bitmap, and
\fImask\fR is the bitmap's optional mask.  The default is
\f(CWcircle\fR.
.TP
\fB\-weights \fIwVec\fR 
Specifies the weights of the individual data points.  This, in
conjunction with the list pen styles (see the \fB\-styles\fR option)
controls how data points are drawn.  \fIWVec\fR is the name of a BLT
vector or a list of numeric expressions representing the weights for
each data point.
.TP
\fB\-xdata \fIxVec\fR 
Specifies the x-coordinates of the data.  \fIXVec\fR is the name of
a BLT vector or a list of numeric expressions.
.TP
\fB\-ydata \fIyVec\fR 
Specifies the y-coordinates of the data.  \fIYVec\fR is the name of
a BLT vector or a list of numeric expressions.
.PP
Element configuration options may also be set by the \fBoption\fR
command.  The resource class is \f(CWElement\fR. The resource name is
the name of the element.
.CS
option add *Stripchart.Element.symbol line
option add *Stripchart.e1.symbol line
.CE
.RE
.TP
\fIpathName \fBelement create \fIelemName\fR ?\fIoption value\fR?...
Creates a new element \fIelemName\fR.  It's an error is
an element \fIelemName\fR already exists.  If
additional arguments are present, they specify options valid for 
element \fBconfigure\fR operation.
.TP
\fIpathName \fBelement deactivate \fIelemName\fR ?\fIelemName\fR?...
Deactivates all the elements matching \fIpattern\fR.
Elements whose names match any of the patterns given are redrawn using
their normal colors.
.TP
\fIpathName \fBelement delete\fR ?\fIelemName\fR?...
Deletes all the named elements.  The graph is automatically redrawn.
.TP
\fIpathName \fBelement exists \fIelemName\fR
Returns \f(CW1\fR if an element \fIelemName\fR currently exists and \f(CW0\fR otherwise.
.TP
\fIpathName \fBelement names \fR?\fIpattern\fR?...  
Returns the elements matching one or more pattern.  If no
\fIpattern\fR is given, the names of all elements is returned.
.TP
\fIpathName \fBelement show\fR ?\fInameList\fR?  
Queries or modifies the element display list.  The element display
list designates the elements drawn and in what
order. \fINameList\fR is a list of elements to be displayed in the
order they are named.  If there is no \fInameList\fR argument,
the current display list is returned.
.TP
\fIpathName \fBelement type\fR \fIelemName\fR
Returns the type of \fIelemName\fR. 
If the element is a bar element, the commands returns the string
\f(CW"bar"\fR, otherwise it returns \f(CW"line"\fR.
.CE
.SS "GRID COMPONENT"
Grid lines extend from the major and minor ticks of each axis
horizontally or vertically across the plotting area.  The following
operations are available for grid lines.
.TP
\fIpathName \fBgrid cget \fIoption\fR
Returns the current value of the grid line configuration option given by 
\fIoption\fR.  \fIOption\fR may be any option described below
for the grid \fBconfigure\fR operation.
.TP
\fIpathName \fBgrid configure\fR ?\fIoption value\fR?...
Queries or modifies the configuration options for grid lines.  If
\fIoption\fR isn't specified, a list describing all the current
grid options for \fIpathName\fR is returned.  If \fIoption\fR is specified,
but not \fIvalue\fR, then a list describing \fIoption\fR is
returned.  If one or more \fIoption\fR and \fIvalue\fR pairs are
specified, then for each pair, the grid line option \fIoption\fR is set to
\fIvalue\fR.  The following options are valid for grid lines.
.RS
.TP
\fB\-color \fIcolor\fR 
Sets the color of the grid lines.  The default is \f(CWblack\fR.
.TP
\fB\-dashes \fIdashList\fR
Sets the dash style of the grid lines. \fIDashList\fR is a list of up
to 11 numbers that alternately represent the lengths of the dashes
and gaps on the grid lines.  Each number must be between 1 and 255.
If \fIdashList\fR is \f(CW""\fR, the grid will be solid lines.
.TP
\fB\-hide \fIboolean\fR
Indicates whether the grid should be drawn. If \fIboolean\fR
is true, grid lines are not shown. The default is \f(CWyes\fR.
.TP
\fB\-linewidth \fIpixels\fR
Sets the width of grid lines.  The default width is \f(CW1\fR.
.TP
\fB\-mapx \fIxAxis\fR
Specifies the X\-axis to display grid lines.  \fIXAxis\fR
must be the name of an axis.  The default is \f(CWx\fR.
.TP
\fB\-mapy \fIyAxis\fR
Specifies the Y\-axis to display grid lines.  \fIYAxis\fR
must be the name of an axis. The default is \f(CWy\fR.
.TP
\fB\-minor \fIboolean\fR
Indicates whether the grid lines should be drawn for minor ticks. 
If \fIboolean\fR is true, the lines will appear at
minor tick intervals.  The default is \f(CW1\fR.
.PP
Grid configuration options may also be set by the 
\fBoption\fR command.  The resource name and class are \f(CWgrid\fR and 
\f(CWGrid\fR respectively. 
.CS
option add *Stripchart.grid.LineWidth 2
option add *Stripchart.Grid.Color     black
.CE
.RE
.TP
\fIpathName \fBgrid off\fR
Turns off the display the grid lines.
.TP
\fIpathName \fBgrid on\fR
Turns on the display the grid lines.
.TP
\fIpathName \fBgrid toggle\fR
Toggles the display of the grid.  
.SS "LEGEND COMPONENT"
The legend displays a list of the data elements.  Each entry consists
of the element's symbol and label.  The legend can appear in any
margin (the default location is in the right margin).  It
can also be positioned anywhere within the plotting area.
.PP
The following operations are valid for the legend.
.TP
\fIpathName \fBlegend activate \fIpattern\fR...
Selects legend entries to be drawn using the active legend colors and relief.
All entries whose element names match \fIpattern\fR  are selected.  To
be selected, the element name must match only one \fIpattern\fR. 
.TP
\fIpathName \fBlegend cget \fIoption\fR
Returns the current value of a legend configuration option.
\fIOption\fR may be any option described below in the
legend \fBconfigure\fR operation.
.TP
\fIpathName \fBlegend configure \fR?\fIoption value\fR?...
Queries or modifies the configuration options for the legend.  If
\fIoption\fR isn't specified, a list describing the current
legend options for \fIpathName\fR is returned.  If \fIoption\fR is
specified, but not \fIvalue\fR, then a list describing \fIoption\fR is
returned.  If one or more \fIoption\fR and \fIvalue\fR pairs are
specified, then for each pair, the legend option \fIoption\fR is set
to \fIvalue\fR.  The following options are valid for the legend.
.RS
.TP
\fB\-activebackground \fIcolor\fR
Sets the background color for active legend entries.  All legend
entries marked active (see the legend \fBactivate\fR operation) are
drawn using this background color.
.TP
\fB\-activeborderwidth \fIpixels\fR
Sets the width of the 3-D border around the outside edge of the active legend
entries.  The default is \f(CW2\fR.
.TP
\fB\-activeforeground \fIcolor\fR
Sets the foreground color for active legend entries.  All legend
entries marked as active (see the legend \fBactivate\fR operation) are
drawn using this foreground color.
.TP
\fB\-activerelief \fIrelief\fR 
Specifies the 3-D effect desired for active legend entries.
\fIRelief\fR denotes how the interior of the entry should appear
relative to the legend; for example, \f(CWraised\fR means the entry
should appear to protrude from the legend, relative to the surface of
the legend.  The default is \f(CWflat\fR.
.TP
\fB\-anchor \fIanchor\fR
Tells how to position the legend relative to the positioning point for
the legend.  This is dependent on the value of the \fB\-position\fR
option.  The default is \f(CWcenter\fR.
.RS
.TP 1.25i
\f(CWleft\fR or \f(CWright\fR
The anchor describes how to position the legend vertically.  
.TP
\f(CWtop\fR or \f(CWbottom\fR
The anchor describes how to position the legend horizontally.  
.TP
\f([email protected],y\fR
The anchor specifies how to position the legend relative to the
positioning point. For example, if \fIanchor\fR is \f(CWcenter\fR then
the legend is centered on the point; if \fIanchor\fR is \f(CWn\fR then
the legend will be drawn such that the top center point of the
rectangular region occupied by the legend will be at the positioning
point.
.TP
\f(CWplotarea\fR
The anchor specifies how to position the legend relative to the
plotting area. For example, if \fIanchor\fR is \f(CWcenter\fR then the
legend is centered in the plotting area; if \fIanchor\fR is \f(CWne\fR
then the legend will be drawn such that occupies the upper right
corner of the plotting area.
.RE
.TP
\fB\-background \fIcolor\fR
Sets the background color of the legend. If \fIcolor\fR is \f(CW""\fR,
the legend background with be transparent.
.TP
\fB\-borderwidth \fIpixels\fR
Sets the width of the 3-D border around the outside edge of the legend (if
such border is being drawn; the \fBrelief\fR option determines this).
The default is \f(CW2\fR pixels.
.TP
\fB\-font \fIfontName\fR 
\fIFontName\fR specifies a font to use when drawing the labels of each
element into the legend.  The default is
\f(CW*-Helvetica-Bold-R-Normal-*-12-120-*\fR.
.TP
\fB\-foreground \fIcolor\fR 
Sets the foreground color of the text drawn for the element's label.
The default is \f(CWblack\fR.
.TP
\fB\-hide \fIboolean\fR
Indicates whether the legend should be displayed. If \fIboolean\fR is
true, the legend will not be draw.  The default is \f(CWno\fR.
.TP
\fB\-ipadx \fIpad\fR 
Sets the amount of internal padding to be added to the width of each
legend entry.  \fIPad\fR can be a list of one or two screen distances.  If
\fIpad\fR has two elements, the left side of the legend entry is
padded by the first distance and the right side by the second.  If
\fIpad\fR is just one distance, both the left and right sides are padded
evenly.  The default is \f(CW2\fR.
.TP
\fB\-ipady \fIpad\fR
Sets an amount of internal padding to be added to the height of each
legend entry.  \fIPad\fR can be a list of one or two screen distances.  If
\fIpad\fR has two elements, the top of the entry is padded by the
first distance and the bottom by the second.  If \fIpad\fR is just
one distance, both the top and bottom of the entry are padded evenly.
The default is \f(CW2\fR.
.TP
\fB\-padx \fIpad\fR
Sets the padding to the left and right exteriors of the legend.
\fIPad\fR can be a list of one or two screen distances.  If \fIpad\fR
has two elements, the left side of the legend is padded by the first
distance and the right side by the second.  If \fIpad\fR has just one
distance, both the left and right sides are padded evenly.  The
default is \f(CW4\fR.
.TP
\fB\-pady \fIpad\fR
Sets the padding above and below the legend.  \fIPad\fR can be a list
of one or two screen distances.  If \fIpad\fR has two elements, the area above
the legend is padded by the first distance and the area below by the
second.  If \fIpad\fR is just one distance, both the top and
bottom areas are padded evenly.  The default is \f(CW0\fR.
.TP
\fB\-position \fIpos\fR
Specifies where the legend is drawn. The
\fB\-anchor\fR option also affects where the legend is positioned.  If
\fIpos\fR is \f(CWleft\fR, \f(CWleft\fR, \f(CWtop\fR, or \f(CWbottom\fR, the
legend is drawn in the specified margin.  If \fIpos\fR is
\f(CWplotarea\fR, then the legend is drawn inside the plotting area at a
particular anchor.  If \fIpos\fR is in the form "\[email protected],y\fR", where
\fIx\fR and \fIy\fR are the window coordinates, the legend is drawn in
the plotting area at the specified coordinates.  The default is
\f(CWright\fR.
.TP
\fB\-raised \fIboolean\fR
Indicates whether the legend is above or below the data elements.  This
matters only if the legend is in the plotting area.  If \fIboolean\fR
is true, the legend will be drawn on top of any elements that may
overlap it. The default is \f(CWno\fR.
.TP
\fB\-relief \fIrelief\fR
Specifies the 3-D effect for the border around the legend.
\fIRelief\fR specifies how the interior of the legend should appear
relative to the strip chart; for example, \f(CWraised\fR means the legend
should appear to protrude from the strip chart, relative to the surface of
the strip chart.  The default is \f(CWsunken\fR.
.PP
Legend configuration options may also be set by the \fBoption\fR
command.  The resource name and class are \f(CWlegend\fR and
\f(CWLegend\fR respectively.
.CS
option add *Stripchart.legend.Foreground blue
option add *Stripchart.Legend.Relief     raised
.CE
.RE
.TP
\fIpathName \fBlegend deactivate \fIpattern\fR...
Selects legend entries to be drawn using the normal legend colors and
relief.  All entries whose element names match \fIpattern\fR are
selected.  To be selected, the element name must match only one
\fIpattern\fR.
.TP
\fIpathName \fBlegend get \fIpos\fR
Returns the name of the element whose entry is at the screen position
\fIpos\fR in the legend.  \fIPos\fR must be in the form "\[email protected],y\fR",
where \fIx\fR and \fIy\fR are window coordinates.  If the given
coordinates do not lie over a legend entry, \f(CW""\fR is returned.
.SS "PEN COMPONENTS"
Pens define attributes (both symbol and line style) for elements.
Pens mirror the configuration options of data elements that pertain to
how symbols and lines are drawn.  Data elements use pens to determine
how they are drawn.  A data element may use several pens at once.  In
this case, the pen used for a particular data point is determined from
each element's weight vector (see the element's \fB\-weight\fR and
\fB\-style\fR options).
.PP
One pen, called \f(CWactiveLine\fR, is automatically created.
It's used as the default active pen for elements. So you can change
the active attributes for all elements by simply reconfiguring this
pen.
.CS
\&.s pen configure "activeLine" -color green
.CE
You can create and use any number of pens. To create a pen, invoke
the pen component and its create operation.
.CS
\&.s pen create myPen
.CE
You map pens to a data element using either the element's 
\fB\-pen\fR or \fB\-activepen\fR options.
.CS
\&.s element create "line1" -xdata $x -ydata $tempData \\
    -pen myPen
.CE
An element can use several pens at once. This is done by specifying
the name of the pen in the element's style list (see the
\fB\-styles\fR option).
.CS
\&.s element configure "line1" -styles { myPen 2.0 3.0 }
.CE
This says that any data point with a weight between 2.0 and 3.0
is to be drawn using the pen \f(CWmyPen\fR.  All other points
are drawn with the element's default attributes.
.PP
The following operations are available for pen components.
.PP
.TP
\fIpathName \fBpen \fBcget \fIpenName \fIoption\fR
Returns the current value of the option given by \fIoption\fR for
\fIpenName\fR.  \fIOption\fR may be any option described below
for the pen \fBconfigure\fR operation.
.TP
\fIpathName \fBpen \fBconfigure \fIpenName \fR?\fIoption value\fR?...
Queries or modifies the configuration options of \fIpenName\fR.  If
\fIoption\fR isn't specified, a list describing the current
options for \fIpenName\fR is returned.  If \fIoption\fR is specified, but
not \fIvalue\fR, then a list describing \fIoption\fR is
returned.  If one or more \fIoption\fR and \fIvalue\fR pairs are
specified, then for each pair, the pen option \fIoption\fR is set to
\fIvalue\fR.  
The following options are valid for pens.
.RS
.TP
\fB\-color \fIcolor\fR 
Sets the color of the traces connecting the data points.  
.TP
\fB\-dashes \fIdashList\fR
Sets the dash style of element line. \fIDashList\fR is a list of up to
11 numbers that alternately represent the lengths of the dashes and
gaps on the element line.  Each number must be between 1 and 255.  If
\fIdashList\fR is \f(CW""\fR, the lines will be solid.
.TP
\fB\-fill \fIcolor\fR 
Sets the interior color of symbols.  If \fIcolor\fR is \f(CW""\fR, then
the interior of the symbol is transparent.  If \fIcolor\fR is
\f(CWdefcolor\fR, then the color will be the same as the \fB\-color\fR
option.  The default is \f(CWdefcolor\fR.
.TP
\fB\-linewidth \fIpixels\fR 
Sets the width of the connecting lines between data points.  If
\fIpixels\fR is \f(CW0\fR, no connecting lines will be drawn between
symbols.  The default is \f(CW0\fR.
.TP
\fB\-offdash \fIcolor\fR
Sets the color of the stripes when traces are dashed (see the
\fB\-dashes\fR option).  If \fIcolor\fR is \f(CW""\fR, then the "off"
pixels will represent gaps instead of stripes.  If \fIcolor\fR is
\f(CWdefcolor\fR, then the color will be the same as the \fB\-color\fR
option.  The default is \f(CWdefcolor\fR.
.TP
\fB\-outline \fIcolor\fR 
Sets the color or the outline around each symbol.  If \fIcolor\fR is
\f(CW""\fR, then no outline is drawn. If \fIcolor\fR is \f(CWdefcolor\fR,
then the color will be the same as the \fB\-color\fR option.  The
default is \f(CWdefcolor\fR.
.TP
\fB\-outlinewidth \fIpixels\fR 
Sets the width of the outline bordering each symbol.  If \fIpixels\fR
is \f(CW0\fR, no outline will be drawn. The default is \f(CW1\fR.
.TP
\fB\-pixels \fIpixels\fR
Sets the size of symbols.  If \fIpixels\fR is \f(CW0\fR, no symbols will
be drawn.  The default is \f(CW0.125i\fR.
.TP
\fB\-symbol \fIsymbol\fR 
Specifies the symbol for data points.  \fISymbol\fR can be either
\f(CWsquare\fR, \f(CWcircle\fR, \f(CWdiamond\fR, \f(CWplus\fR, \f(CWcross\fR,
\f(CWsplus\fR, \f(CWscross\fR, \f(CWtriangle\fR, \f(CW""\fR (where no symbol
is drawn), or a bitmap.  Bitmaps are specified as "\fIsource\fR
?\fImask\fR?", where \fIsource\fR is the name of the bitmap, and
\fImask\fR is the bitmap's optional mask.  The default is
\f(CWcircle\fR.
.TP
\fB\-type \fIelemType\fR 
Specifies the type of element the pen is to be used with.
This option should only be employed when creating the pen.  This
is for those that wish to mix different types of elements (bars and
lines) on the same graph.  The default type is "line".
.PP
Pen configuration options may be also be set by the \fBoption\fR
command.  The resource class is \f(CWPen\fR.  The resource names
are the names of the pens.
.CS
option add *Stripchart.Pen.Color  blue
option add *Stripchart.activeLine.color  green
.CE
.RE
.TP
\fIpathName \fBpen \fBcreate \fIpenName \fR?\fIoption value\fR?...
Creates a new pen by the name \fIpenName\fR.  No pen by the same
name can already exist. \fIOption\fR and \fIvalue\fR are described 
in above in the pen \fBconfigure\fR operation.
.TP
\fIpathName \fBpen \fBdelete \fR?\fIpenName\fR?...
Deletes the named pens. A pen is not really
deleted until it is not longer in use, so it's safe to delete
pens mapped to elements.
.TP
\fIpathName \fBpen names \fR?\fIpattern\fR?...
Returns a list of pens matching zero or more patterns.  If no
\fIpattern\fR argument is give, the names of all pens are returned.
.SS "POSTSCRIPT COMPONENT"
The strip chart can generate encapsulated PostScript output.  There
are several configuration options you can specify to control how the
plot is generated.  You can change the page dimensions and
borders.  The plot itself can be scaled, centered, or rotated to
landscape.  The PostScript output can be written directly to a file or
returned through the interpreter.
.PP
The following postscript operations are available.
.TP
\fIpathName \fBpostscript cget \fIoption\fR 
Returns the current value of the postscript option given by
\fIoption\fR.  \fIOption\fR may be any option described
below for the postscript \fBconfigure\fR operation.
.TP
\fIpathName \fBpostscript configure \fR?\fIoption value\fR?...
Queries or modifies the configuration options for PostScript
generation.  If \fIoption\fR isn't specified, a list describing 
the current postscript options for \fIpathName\fR is returned.  If
\fIoption\fR is specified, but not \fIvalue\fR, then a list describing
\fIoption\fR is returned.  If one or more \fIoption\fR and \fIvalue\fR
pairs are specified, then for each pair, the postscript option
\fIoption\fR is set to \fIvalue\fR.  The following postscript options
are available.
.RS
.TP
\fB\-center \fIboolean\fR
Indicates whether the plot should be centered on the PostScript page.  If
\fIboolean\fR is false, the plot will be placed in the upper left
corner of the page.  The default is \f(CW1\fR.
.TP
\fB\-colormap \fIvarName\fR
\fIVarName\fR must be the name of a global array variable that
specifies a color mapping from the X color name to PostScript.  Each
element of \fIvarName\fR must consist of PostScript code to set a
particular color value (e.g. ``\f(CW1.0 1.0 0.0 setrgbcolor\fR'').  When
outputting color information in PostScript, the array variable \fIvarName\fR 
is checked to see if an element of the name of the color exists. If so, 
it uses the value of the element as the PostScript
command to set the color.  If this option hasn't been specified, or if
there isn't an entry in \fIvarName\fR for a given color, then it uses
the red, green, and blue intensities from the X color.
.TP
\fB\-colormode \fImode\fR
Specifies how to output color information.  \fIMode\fR must be either
\f(CWcolor\fR (for full color output), \f(CWgray\fR (convert all colors to
their gray-scale equivalents) or \f(CWmono\fR (convert foreground colors
to black and background colors to white).  The default mode is
\f(CWcolor\fR. 
.TP
\fB\-fontmap \fIvarName\fR
\fIVarName\fR must be the name of a global array variable that
specifies a font mapping from the X font name to PostScript.  Each
element of \fIvarName\fR must consist of a Tcl list with one or two
elements, which are the name and point size of a PostScript font.
When outputting PostScript commands for a particular font, the 
array variable \fIvarName\fR is checked to see an element of the specified 
font exists.  If there is such an element, then the font
information contained in that element is used in the PostScript
output.  (If the point size is omitted from the list, the point size
of the X font is used).  Otherwise the X font is examined in an
attempt to guess what PostScript font to use.  This works only for
fonts whose foundry property is \fIAdobe\fR (such as Times, Helvetica,
Courier, etc.).  If all of this fails then the font defaults to
\f(CWHelvetica-Bold\fR.
.TP
\fB\-decorations \fIboolean\fR
Indicates if PostScript commands to generate color backgrounds and 3-D
borders should be output.  If \fIboolean\fR is false, the background will 
be white and no 3-D borders will be generated. The
default is \f(CW1\fR.
.TP
\fB\-height \fIpixels\fR
Sets the height of the plot.  This lets you plot the stripchart with a
height different from the one displayed on the screen.  If
\fIpixels\fR is 0, the height is the same as the displayed height.
The default is \f(CW0\fR.
.TP
\fB\-landscape \fIboolean\fR
If \fIboolean\fR is true, this specifies the printed area is to be
rotated 90 degrees.  In non-rotated output the X-axis of the printed
area runs along the short dimension of the page (``portrait''
orientation); in rotated output the X-axis runs along the long
dimension of the page (``landscape'' orientation).  Defaults to
\f(CW0\fR.
.TP
\fB\-maxpect \fIboolean\fR
Indicates to scale the the plot so that it fills the PostScript page.
The aspect ratio of the strip chart is still retained.  The default is
\f(CW0\fR.
.TP
\fB\-padx \fIpad\fR
Sets the horizontal padding for the left and right page borders.  The
borders are exterior to the plot.  \fIPad\fR can be a list of one or
two screen distances.  If \fIpad\fR has two elements, the left border is padded
by the first distance and the right border by the second.  If
\fIpad\fR has just one distance, both the left and right borders are
padded evenly.  The default is \f(CW1i\fR.
.TP
\fB\-pady \fIpad\fR 
Sets the vertical padding for the top and bottom page borders. The
borders are exterior to the plot.  \fIPad\fR can be a list of one or
two screen distances.  If \fIpad\fR has two elements, the top border is padded
by the first distance and the bottom border by the second.  If
\fIpad\fR has just one distance, both the top and bottom borders are
padded evenly.  The default is \f(CW1i\fR.
.TP
\fB\-paperheight \fIpixels\fR
Sets the height of the postscript page.  This can be used to select
between different page sizes (letter, A4, etc).  The default height is
\f(CW11.0i\fR.
.TP
\fB\-paperwidth \fIpixels\fR
Sets the width of the postscript page.  This can be used to select
between different page sizes (letter, A4, etc).  The default width is
\f(CW8.5i\fR.
.TP
\fB\-width \fIpixels\fR
Sets the width of the plot.  This lets you plot the strip chart with a
width different from the one drawn on the screen.  If \fIpixels\fR
is 0, the width is the same as the widget's width.  The default is
\f(CW0\fR.
.PP
Postscript configuration options may be also be set by the
\fBoption\fR command.  The resource name and class are
\f(CWpostscript\fR and \f(CWPostscript\fR respectively.
.CS
option add *Stripchart.postscript.Decorations false
option add *Stripchart.Postscript.Landscape   true
.CE
.RE
.TP
\fIpathName \fBpostscript output \fR?\fIfileName\fR? ?\fIoption value\fR?...
Outputs a file of encapsulated PostScript.  If a
\fIfileName\fR argument isn't present, the command returns the
PostScript. If any \fIoption-value\fR pairs are present, they set
configuration options controlling how the PostScript is generated.
\fIOption\fR and \fIvalue\fR can be anything accepted by the
postscript \fBconfigure\fR operation above.
.SS "MARKER COMPONENTS"
Markers are simple drawing procedures used to annotate or highlight
areas of the strip chart.  Markers have various types: text strings,
bitmaps, images, connected lines, windows, or polygons.  They can be
associated with a particular element, so that when the element is
hidden or un-hidden, so is the marker.  By default, markers are the
last items drawn, so that data elements will appear in
behind them.  You can change this by configuring the \fB\-under\fR
option.
.PP
Markers, in contrast to elements, don't affect the scaling of the
coordinate axes.  They can also have \fIelastic\fR coordinates
(specified by \f(CW-Inf\fR and \f(CWInf\fR respectively) that translate
into the minimum or maximum limit of the axis.  For example, you can
place a marker so it always remains in the lower left corner of the
plotting area, by using the coordinates \f(CW-Inf\fR,\f(CW-Inf\fR.
.PP
The following operations are available for markers.
.TP
\fIpathName \fBmarker after \fImarkerId\fR ?\fIafterId\fR?
Changes the order of the markers, drawing the first
marker after the second.  If no second \fIafterId\fR argument is
specified, the marker is placed at the end of the display list.  This
command can be used to control how markers are displayed since markers
are drawn in the order of this display list.
.TP
\fIpathName \fBmarker before \fImarkerId\fR ?\fIbeforeId\fR?
Changes the order of the markers, drawing the first
marker before the second.  If no second \fIbeforeId\fR argument is
specified, the marker is placed at the beginning of the display list.
This command can be used to control how markers are displayed since
markers are drawn in the order of this display list.
.TP
\fIpathName \fBmarker cget \fIoption\fR
Returns the current value of the marker configuration option given by
\fIoption\fR.  \fIOption\fR may be any option described
below in the \fBconfigure\fR operation.
.TP
\fIpathName \fBmarker configure \fImarkerId\fR ?\fIoption value\fR?...
Queries or modifies the configuration options for markers.  If
\fIoption\fR isn't specified, a list describing the current
options for \fImarkerId\fR is returned.  If \fIoption\fR is specified,
but not \fIvalue\fR, then a list describing \fIoption\fR is returned.
If one or more \fIoption\fR and \fIvalue\fR pairs are specified, then
for each pair, the marker option \fIoption\fR is set to \fIvalue\fR.
.sp
The following options are valid for all markers.
Each type of marker also has its own type-specific options.  
They are described in the sections below.
.RS
.TP
\fB\-coords \fIcoordList\fR
Specifies the coordinates of the marker.  \fICoordList\fR is 
a list of graph coordinates.  The number of coordinates required
is dependent on the type of marker.  Text, image, and window markers
need only two coordinates (an X\-Y coordinate).   Bitmap markers
can take either two or four coordinates (if four, they represent the
corners of the bitmap). Line markers
need at least four coordinates, polygons at least six.
If \fIcoordList\fR is \f(CW""\fR, the marker will not be displayed.
The default is \f(CW""\fR.
.TP
\fB\-element \fIelemName\fR
Links the marker with the element \fIelemName\fR.  The marker is
drawn only if the element is also currently displayed (see the
element's \fBshow\fR operation).  If \fIelemName\fR is \f(CW""\fR, the
marker is always drawn.  The default is \f(CW""\fR.
.TP
\fB\-hide \fIboolean\fR 
Indicates whether the marker is drawn. If \fIboolean\fR is true,
the marker is not drawn.  The default is \f(CWno\fR.
.TP
\fB\-mapx \fIxAxis\fR 
Specifies the X\-axis to map the marker's X\-coordinates onto.
\fIXAxis\fR must the name of an axis.  The default is \f(CWx\fR.
.TP
\fB\-mapy \fIyAxis\fR
Specifies the Y\-axis to map the marker's Y\-coordinates onto.
\fIYAxis\fR must the name of an axis.  The default is \f(CWy\fR.
.TP
\fB\-name \fImarkerId\fR
Changes the identifier for the marker.  The identifier \fImarkerId\fR 
can not already be used by another marker.  If this option
isn't specified, the marker's name is uniquely generated.
.TP
\fB\-under \fIboolean\fR
Indicates whether the marker is drawn below/above data
elements.  If \fIboolean\fR is true, the marker is be drawn
underneath the data element symbols and lines.  Otherwise, the marker is
drawn on top of the element.  The default is \f(CW0\fR.
.TP
\fB\-xoffset \fIpixels\fR
Specifies a screen distance to offset the marker horizontally. 
\fIPixels\fR is a valid screen distance, such as \f(CW2\fR or \f(CW1.2i\fR.
The default is \f(CW0\fR.
.TP
\fB\-yoffset \fIpixels\fR
Specifies a screen distance to offset the markers vertically.
\fIPixels\fR is a valid screen distance, such as \f(CW2\fR or \f(CW1.2i\fR.
The default is \f(CW0\fR.
.PP
Marker configuration options may also be set by the \fBoption\fR command.
The resource class is either \f(CWBitmapMarker\fR,  \f(CWImageMarker\fR, 
\f(CWLineMarker\fR, \f(CWPolygonMarker\fR, \f(CWTextMarker\fR, or \f(CWWindowMarker\fR,
depending on the type of marker.  The resource name is the name of the
marker.
.CS
option add *Stripchart.TextMarker.Foreground white
option add *Stripchart.BitmapMarker.Foreground white
option add *Stripchart.m1.Background     blue
.CE
.RE
.TP
\fIpathName \fBmarker create \fItype\fR ?\fIoption value\fR?...
Creates a marker of the selected type. \fIType\fR may be either
\f(CWtext\fR, \f(CWline\fR, \f(CWbitmap\fR, \f(CWimage\fR, \f(CWpolygon\fR, or
\f(CWwindow\fR.  This command returns the marker identifier, 
used as the \fImarkerId\fR argument in the other marker-related
commands.  If the \fB\-name\fR option is used, this overrides the
normal marker identifier.  If the name provided is already used for
another marker, the new marker will replace the old.
.TP
\fIpathName \fBmarker delete\fR ?\fIname\fR?...
Removes one of more markers.  The graph will automatically be redrawn
without the marker.\fR.  
.TP
\fIpathName \fBmarker exists \fImarkerId\fR 
Returns \f(CW1\fR if the marker \fImarkerId\fR exists and \f(CW0\fR
otherwise.
.TP
\fIpathName \fBmarker names\fR ?\fIpattern\fR?  
Returns the names of all the markers that currently exist.  If
\fIpattern\fR is supplied, only those markers whose names match it
will be returned.
.TP
\fIpathName \fBmarker type \fImarkerId\fR 
Returns the type of the marker given by \fImarkerId\fR, such as
\f(CWline\fR or \f(CWtext\fR.  If \fImarkerId\fR is not a valid a marker
identifier, \f(CW""\fR is returned.
.SS "BITMAP MARKERS"
A bitmap marker displays a bitmap.  The size of the
bitmap is controlled by the number of coordinates specified.  If two
coordinates, they specify the position of the top-left corner of the
bitmap.  The bitmap retains its normal width and height.  If four
coordinates, the first and second pairs of coordinates represent the
corners of the bitmap.  The bitmap will be stretched or reduced as
necessary to fit into the bounding rectangle.
.PP
Bitmap markers are created with the marker's \fBcreate\fR operation in
the form:
.DS
\fIpathName \fBmarker create bitmap \fR?\fIoption value\fR?...
.DE
There may be many \fIoption\fR-\fIvalue\fR pairs, each 
sets a configuration options for the marker.  These
same \fIoption\fR\-\fIvalue\fR pairs may be used with the marker's
\fBconfigure\fR operation.
.PP
The following options are specific to bitmap markers:
.TP
\fB\-background \fIcolor\fR
Sets the background color of the bitmap.  If \fIcolor\fR is \f(CW""\fR,
the background color will be transparent.  The default background
color is \f(CWwhite\fR.
.TP
\fB\-bitmap \fIbitmap\fR
Specifies the bitmap to be displayed.  If \fIbitmap\fR is \f(CW""\fR,
the marker will not be displayed.  The default is \f(CW""\fR.
.TP
\fB\-foreground \fIcolor\fR 
Sets the foreground color of the bitmap.  The default foreground color
is \f(CWblack\fR.
.TP
\fB\-mask \fImask\fR
Specifies a mask for the bitmap to be displayed. This mask is a bitmap
itself, denoting the pixels that are transparent.  If \fImask\fR is
\f(CW""\fR, all pixels of the bitmap will be drawn.  The default is
\f(CW""\fR.
.TP
\fB\-rotate \fItheta\fR
Sets the rotation of the bitmap.  \fITheta\fR is a real number
representing the angle of rotation in degrees.  The marker is first
rotated and then placed according to its anchor position.  The default
rotation is \f(CW0.0\fR.
.SS "IMAGE MARKERS"
A image marker displays an image.  Image markers are
created with the marker's \fBcreate\fR operation in the form:
.DS
\fIpathName \fBmarker create image \fR?\fIoption value\fR?...
.DE
There may be many \fIoption\fR-\fIvalue\fR
pairs, each sets a configuration option
for the marker.  These same \fIoption\fR\-\fIvalue\fR pairs may be
used with the marker's \fBconfigure\fR operation.
.PP
The following options are specific to image markers:
.TP
\fB\-anchor \fIanchor\fR
\fIAnchor\fR tells how to position the image relative to the
positioning point for the image. For example, if \fIanchor\fR
is \f(CWcenter\fR then the image is centered on the point;  if
\fIanchor\fR is \f(CWn\fR then the image will be drawn such that
the top center point of the rectangular region occupied by the
image will be at the positioning point.
This option defaults to \f(CWcenter\fR.
.TP
\fB\-image \fIimage\fR
Specifies the image to be drawn.
If \fIimage\fR is \f(CW""\fR, the marker will not be
drawn.  The default is \f(CW""\fR.
.SS "LINE MARKERS"
A line marker displays one or more connected line segments.
Line markers are created with marker's \fBcreate\fR operation in the form:
.DS
\fIpathName \fBmarker create line \fR?\fIoption value\fR?...
.DE
There may be many \fIoption\fR-\fIvalue\fR
pairs, each sets a configuration option
for the marker.  These same \fIoption\fR-\fIvalue\fR pairs may be
used with the marker's \fBconfigure\fR operation.
.PP
The following options are specific to line markers:
.TP
\fB\-background \fIcolor\fR
Sets the background color of the line.
The option is affects the line color only when the \fB\-stipple\fR option 
is set.  
If this option isn't specified then it defaults to \f(CWwhite\fR.
.TP
\fB\-dashes \fIdashList\fR
Sets the dash style of the line. \fIDashList\fR is a list of up to 11
numbers that alternately represent the lengths of the dashes and gaps
on the line.  Each number must be between 1 and 255.  If
\fIdashList\fR is \f(CW""\fR, the marker line will be solid.
.TP
\fB\-foreground \fIcolor\fR
Sets the foreground color.  The default foreground color is \f(CWblack\fR.
.TP
\fB\-linewidth \fIpixels\fR
Sets the width of the lines.
The default width is \f(CW0\fR.
.TP
\fB\-stipple \fIbitmap\fR
Specifies a stipple pattern used to draw the line, rather than
a solid line.
\fIBitmap\fR specifies a bitmap to use as the stipple
pattern.  If \fIbitmap\fR is \f(CW""\fR, then the
line is drawn in a solid fashion. The default is \f(CW""\fR.
.SS "POLYGON MARKERS"
A polygon marker displays a closed region described as two or more
connected line segments.  It is assumed the first and
last points are connected.  Polygon markers are created using the
marker \fBcreate\fR operation in the form:
.DS
\fIpathName \fBmarker create polygon \fR?\fIoption value\fR?...
.DE
There may be many \fIoption\fR-\fIvalue\fR
pairs, each sets a configuration option
for the marker.  These same \fIoption\fR\-\fIvalue\fR pairs may be
used with the \fBmarker configure\fR command to change the marker's
configuration.
The following options are supported for polygon markers:
.TP
\fB\-dashes \fIdashList\fR
Sets the dash style of the outline of the polygon. \fIDashList\fR is a
list of up to 11 numbers that alternately represent the lengths of
the dashes and gaps on the outline.  Each number must be between 1 and
255. If \fIdashList\fR is \f(CW""\fR, the outline will be a solid line.
.TP
\fB\-fill \fIcolor\fR
Sets the fill color of the polygon.  If \fIcolor\fR is \f(CW""\fR, then
the interior of the polygon is transparent.
The default is \f(CWwhite\fR.
.TP
\fB\-linewidth \fIpixels\fR
Sets the width of the outline of the polygon. If \fIpixels\fR is zero, 
no outline is drawn. The default is \f(CW0\fR.
.TP
\fB\-outline \fIcolor\fR
Sets the color of the outline of the polygon.  If the polygon is
stippled (see the \fB\-stipple\fR option), then this represents the
foreground color of the stipple.  The default is \f(CWblack\fR.
.TP
\fB\-stipple \fIbitmap\fR
Specifies that the polygon should be drawn with a stippled pattern
rather than a solid color. \fIBitmap\fR specifies a bitmap to use as
the stipple pattern.  If \fIbitmap\fR is \f(CW""\fR, then the polygon is
filled with a solid color (if the \fB\-fill\fR option is set).  The
default is \f(CW""\fR.
.SS "TEXT MARKERS"
A text marker displays a string of characters on one or more lines of
text.  Embedded newlines cause line breaks.  They may be used to
annotate regions of the strip chart.  Text markers are created with the
\fBcreate\fR operation in the form:
.DS
\fIpathName \fBmarker create text \fR?\fIoption value\fR?...
.DE
There may be many \fIoption\fR-\fIvalue\fR pairs, 
each sets a configuration option for the text marker.  
These same \fIoption\fR\-\fIvalue\fR pairs may be used with the 
marker's \fBconfigure\fR operation.  
.PP
The following options are specific to text markers:
.TP
\fB\-anchor \fIanchor\fR
\fIAnchor\fR tells how to position the text relative to the
positioning point for the text. For example, if \fIanchor\fR is
\f(CWcenter\fR then the text is centered on the point; if
\fIanchor\fR is \f(CWn\fR then the text will be drawn such that the
top center point of the rectangular region occupied by the text will
be at the positioning point.  This default is \f(CWcenter\fR.
.TP
\fB\-background \fIcolor\fR
Sets the background color of the text string.  If \fIcolor\fR is
\f(CW""\fR, the background will be transparent.  The default is
\f(CWwhite\fR.
.TP
\fB\-font \fIfontName\fR
Specifies the font of the text.  The default is
\f(CW*-Helvetica-Bold-R-Normal-*-120-*\fR.
.TP
\fB\-foreground \fIcolor\fR
Sets the foreground color of the text.  The default is \f(CWblack\fR.
.TP
\fB\-justify \fIjustify\fR
Specifies how the text should be justified.  This matters only when
the marker contains more than one line of text. \fIJustify\fR must be
\f(CWleft\fR, \f(CWright\fR, or \f(CWcenter\fR.  The default is
\f(CWcenter\fR.
.TP
\fB\-padx \fIpad\fR
Sets the padding to the left and right exteriors of the text.
\fIPad\fR can be a list of one or two screen distances.  If \fIpad\fR
has two elements, the left side of the text is padded by the first
distance and the right side by the second.  If \fIpad\fR has just one
distance, both the left and right sides are padded evenly.  The
default is \f(CW4\fR.
.TP
\fB\-pady \fIpad\fR
Sets the padding above and below the text.  \fIPad\fR can be a list of
one or two screen distances.  If \fIpad\fR has two elements, the area above the
text is padded by the first distance and the area below by the second.
If \fIpad\fR is just one distance, both the top and bottom areas
are padded evenly.  The default is \f(CW4\fR.
.TP
\fB\-rotate \fItheta\fR
Specifies the number of degrees to rotate the text.  \fITheta\fR is a
real number representing the angle of rotation.  The marker is first
rotated along its center and is then drawn according to its anchor
position. The default is \f(CW0.0\fR.
.TP
\fB\-text \fItext\fR
Specifies the text of the marker.  The exact way the text is
displayed may be affected by other options such as \fB\-anchor\fR or
\fB\-rotate\fR.
.SS "WINDOW MARKERS"
A window marker displays a widget at a given position.
Window markers are created with the marker's \fBcreate\fR operation in
the form:
.DS
\fIpathName \fBmarker create window \fR?\fIoption value\fR?...
.DE
There may be many \fIoption\fR-\fIvalue\fR
pairs, each sets a configuration option
for the marker.  These same \fIoption\fR\-\fIvalue\fR pairs may be
used with the marker's \fBconfigure\fR command.
.PP
The following options are specific to window markers:
.TP
\fB\-anchor \fIanchor\fR
\fIAnchor\fR tells how to position the widget relative to the
positioning point for the widget. For example, if \fIanchor\fR is
\f(CWcenter\fR then the widget is centered on the point; if \fIanchor\fR
is \f(CWn\fR then the widget will be displayed such that the top center
point of the rectangular region occupied by the widget will be at the
positioning point.  This option defaults to \f(CWcenter\fR.
.TP
\fB\-height \fIpixels\fR
Specifies the height to assign to the marker's window.  If this option
isn't specified, or if it is specified as \f(CW""\fR, then the window is
given whatever height the widget requests internally.
.TP
\fB\-width \fIpixels\fR
Specifies the width to assign to the marker's window.  If this option
isn't specified, or if it is specified as \f(CW""\fR, then the window is
given whatever width the widget requests internally.
.TP
\fB\-window \fIpathName\fR
Specifies the widget to be managed.  \fIPathName\fR must
be a child of the \fBstripchart\fR widget.
.SH "GRAPH COMPONENT BINDINGS"
Specific stripchart components, such as elements, markers and legend
entries, can have a command trigger when event occurs in them, much
like canvas items in Tk's canvas widget.  Not all event sequences are
valid.  The only binding events that may be specified are those
related to the mouse and keyboard (such as \fBEnter\fR, \fBLeave\fR,
\fBButtonPress\fR, \fBMotion\fR, and \fBKeyPress\fR).
.sp
Only one element or marker can be picked during an event.  This means,
that if the mouse is directly over both an element and a marker, only
the uppermost component is selected.  This isn't true for legend entries.  
Both a legend entry and an element (or marker) binding commands 
will be invoked if both items are picked.
.sp
It is possible for multiple bindings to match a particular event.
This could occur, for example, if one binding is associated with the
element name and another is associated with one of the element's tags
(see the \fB\-bindtags\fR option).  When this occurs, all of the 
matching bindings are invoked.  A binding associated with the element
name is invoked first, followed by one binding for each of the element's 
bindtags.  If there are multiple matching bindings for a single tag, 
then only the most specific binding is invoked.  A continue command 
in a binding script terminates that script, and a break command 
terminates that script and skips any remaining scripts for the event, 
just as for the bind command.
.sp
The \fB\-bindtags\R option for these components controls addition
tag names which can be matched.  Implicitly elements and markers
always have tags matching their names.  Setting the value of
the \fB\-bindtags\fR option doesn't change this.
.SH "C LANGUAGE API"
You can manipulate data elements from the C language.  There
may be situations where it is too expensive to translate the data
values from ASCII strings.  Or you might want to read data in a
special file format.
.PP
Data can manipulated from the C language using BLT vectors.
You specify the x and y data coordinates of an element as vectors and
manipulate the vector from C.  The strip chart will be redrawn automatically
after the vectors are updated.
.PP
From Tcl, create the vectors and configure the element to use them.
.CS
vector X Y
\&.s element configure line1 -xdata X -ydata Y
.CE
To set data points from C, you pass the values as arrays of doubles
using the \fBBlt_ResetVector\fR call.  The vector is reset with the
new data and at the next idle point (when Tk re-enters its event
loop), the strip chart will be redrawn automatically.
.CS
#include <tcl.h>
#include <blt.h>

register int i;
Blt_Vector *xVec, *yVec;
double x[50], y[50];

/* Get the BLT vectors "X" and "Y" (created above from Tcl) */
if ((Blt_GetVector(interp, "X", 50, &xVec) != TCL_OK) ||
    (Blt_GetVector(interp, "Y", 50, &yVec) != TCL_OK)) {
    return TCL_ERROR;
}

for (i = 0; i < 50; i++) {
    x[i] = i * 0.02;
    y[i] = sin(x[i]);
}	

/* Put the data into BLT vectors */
if ((Blt_ResetVector(xVec, x, 50, 50, TCL_VOLATILE) != TCL_OK) ||
    (Blt_ResetVector(yVec, y, 50, 50, TCL_VOLATILE) != TCL_OK)) {
   return TCL_ERROR;
}
.CE
See the \fBvector\fR manual page for more details.
.SH SPEED TIPS
There may be cases where the strip chart needs to be drawn and updated as
quickly as possible.  If drawing speed becomes a big
problem, here are a few tips to speed up displays.
.TP 2
\(bu 
Try to minimize the number of data points.  The more data points
the looked at, the more work the strip chart must do.
.TP 2
\(bu 
If your data is generated as floating point values, the time required
to convert the data values to and from ASCII strings can be
significant, especially when there any many data points.  You can
avoid the redundant string-to-decimal conversions using the C API to
BLT vectors.
.TP 2
\(bu
Data elements without symbols are drawn faster than with symbols.
Set the data element's \fB\-symbol\fR option to \f(CWnone\fR.  If you need to
draw symbols, try using the simple symbols such as \f(CWsplus\fR and
\f(CWscross\fR.
.TP 2
\(bu
Don't stipple or dash the element.  Solid lines are much faster.
.TP 2
\(bu 
If you update data elements frequently, try turning off the
widget's \fB\-bufferelements\fR option.  When the strip chart is first
displayed, it draws data elements into an internal pixmap.  The pixmap
acts as a cache, so that when the strip chart needs to be redrawn again, and
the data elements or coordinate axes haven't changed, the pixmap is
simply copied to the screen.  This is especially useful when you are
using markers to highlight points and regions on the strip chart.  But if
the strip chart is updated frequently, changing either the element data or
coordinate axes, the buffering becomes redundant.
.SH LIMITATIONS
Auto-scale routines do not use requested min/max limits as boundaries
when the axis is logarithmically scaled.
.PP
The PostScript output generated for polygons with more than 1500
points may exceed the limits of some printers (See PostScript Language
Reference Manual, page 568).  The work-around is to break the polygon
into separate pieces.
.SH "FUTURE INCOMPATIBILITY"
The \fB\-mapped\fR options are obsoleted and will be removed.  You can
achieve the same results using the \fB\-hide\fR option instead.
.CS
# Works for now.
\&.s legend configure -mapped no

# Instead use this.
\&.s legend configure -hide yes    
.CE 
.SH KEYWORDS
stripchart, graph, widget

Added doc/rbc/vector.n.
















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
'\"
'\" Copyright 1991-1997 by Lucent Technologies, Inc.
'\"
'\" Permission to use, copy, modify, and distribute this software and its
'\" documentation for any purpose and without fee is hereby granted, provided
'\" that the above copyright notice appear in all copies and that both that the
'\" copyright notice and warranty disclaimer appear in supporting documentation,
'\" and that the names of Lucent Technologies any of their entities not be used
'\" in advertising or publicity pertaining to distribution of the software
'\" without specific, written prior permission.
'\"
'\" Lucent Technologies disclaims all warranties with regard to this software,
'\" including all implied warranties of merchantability and fitness.  In no event
'\" shall Lucent Technologies be liable for any special, indirect or
'\" consequential damages or any damages whatsoever resulting from loss of use,
'\" data or profits, whether in an action of contract, negligence or other
'\" tortuous action, arising out of or in connection with the use or performance
'\" of this software.
'\"
'\" Vector command created by George Howlett.
'\"
.so man.macros
.TH vector n BLT_VERSION BLT "BLT Built-In Commands"
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
vector \-  Vector data type for Tcl
.SH SYNOPSIS
\fBvector create \fIvecName \fR?\fIvecName\fR...? ?\fIswitches\fR?
.sp
\fBvector destroy \fIvecName \fR?\fIvecName\fR...?
.sp
\fBvector expr \fIexpression\fR
.sp
\fBvector names \fR?\fIpattern\fR...?
.BE
.SH DESCRIPTION
The \fBvector\fR command creates a vector of floating point
values.  The vector's components can be manipulated in three ways:
through a Tcl array variable, a Tcl command, or the C API.
.SH INTRODUCTION
A vector is simply an ordered set of numbers.  The components of a
vector are real numbers, indexed by counting numbers.
.PP
Vectors are common data structures for many applications.  For
example, a graph may use two vectors to represent the X-Y
coordinates of the data plotted.  The graph will automatically
be redrawn when the vectors are updated or changed. By using vectors,
you can separate
data analysis from the graph widget.  This makes it easier, for
example, to add data transformations, such as splines.  It's possible
to plot the same data to in multiple graphs, where each graph presents
a different view or scale of the data.
.PP
You could try to use Tcl's associative arrays as vectors.  Tcl arrays
are easy to use.  You can access individual elements randomly by
specifying the index, or the set the entire array by providing a list
of index and value pairs for each element.  The disadvantages of
associative arrays as vectors lie in the fact they are implemented as
hash tables.
.TP 2
\(bu
There's no implied ordering to the associative arrays.  If you used
vectors for plotting, you would want to insure the second component
comes after the first, an so on.  This isn't possible since arrays
are actually hash tables.  For example, you can't get a range of
values between two indices.  Nor can you sort an array.
.TP 2
\(bu
Arrays consume lots of memory when the number of elements becomes
large (tens of thousands).  This is because each element's index and
value are stored as strings in the hash table.
.TP 2
\(bu
The C programming interface is unwieldy.  Normally with vectors, you
would like to view the Tcl array as you do a C array, as an array of
floats or doubles.  But with hash tables, you must convert both the
index and value to and from decimal strings, just to access
an element in the array.  This makes it cumbersome to perform operations on
the array as a whole.
.PP
The \fBvector\fR command tries to overcome these disadvantages while
still retaining the ease of use of Tcl arrays.  The \fBvector\fR
command creates both a new Tcl command and associate array which are
linked to the vector components.  You can randomly access vector
components though the elements of array.  Not have all indices are
generated for the array, so printing the array (using the \fBparray\fR
procedure) does not print out all the component values.  You can use
the Tcl command to access the array as a whole.  You can copy, append,
or sort vector using its command.  If you need greater performance, or
customized behavior, you can write your own C code to manage vectors.
.SH EXAMPLE
You create vectors using the \fBvector\fR command and its \fBcreate\fR
operation.
.CS
# Create a new vector.
vector create y(50)
.CE
This creates a new vector named \f(CWy\fR.  It has fifty components, by
default, initialized to \f(CW0.0\fR.  In addition, both a Tcl command
and array variable, both named \f(CWy\fR, are created.  You can use
either the command or variable to query or modify components of the
vector.
.CS
# Set the first value.
set y(0) 9.25
puts "y has [y length] components"
.CE
The array \f(CWy\fR can be used to read or set individual components of
the vector.  Vector components are indexed from zero.  The array index
must be a number less than the number of components.  For example,
it's an error if you try to set the 51st element of \f(CWy\fR.
.CS
# This is an error. The vector only has 50 components.
set y(50) 0.02
.CE
You can also specify a range of indices using a colon (:) to separate
the first and last indices of the range.
.CS
# Set the first six components of y
set y(0:5) 25.2
.CE
If you don't include an index, then it will default to the first
and/or last component of the vector.
.CS
# Print out all the components of y
puts "y = $y(:)"
.CE
There are special non-numeric indices.  The index \f(CWend\fR, specifies
the last component of the vector.  It's an error to use this index if
the vector is empty (length is zero).  The index \f(CW++end\fR can be
used to extend the vector by one component and initialize it to a specific
value.  You can't read from the array using this index, though.
.CS
# Extend the vector by one component.
set y(++end) 0.02
.CE
The other special indices are \f(CWmin\fR and \f(CWmax\fR.  They return the
current smallest and largest components of the vector.
.CS
# Print the bounds of the vector
puts "min=$y(min) max=$y(max)"
.CE
To delete components from a vector, simply unset the corresponding
array element. In the following example, the first component of
\f(CWy\fR is deleted.  All the remaining components of \f(CWy\fR will be
moved down by one index as the length of the vector is reduced by
one.
.CS
# Delete the first component
unset y(0)
puts "new first element is $y(0)"
.CE
The vector's Tcl command can also be used to query or set the vector.
.CS
# Create and set the components of a new vector
vector create x
x set { 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 }
.CE
Here we've created a vector \f(CWx\fR without a initial length specification.
In this case, the length is zero.  The \fBset\fR operation resets the vector,
extending it and setting values for each new component.
.PP
There are several operations for vectors.  The \fBrange\fR operation
lists the components of a vector between two indices.
.CS
# List the components
puts "x = [x range 0 end]"
.CE
You can search for a particular value using the \fBsearch\fR
operation.  It returns a list of indices of the components with the
same value.  If no component has the same value, it returns \f(CW""\fR.
.CS
# Find the index of the biggest component
set indices [x search $x(max)]
.CE
Other operations copy, append, or sort vectors.  You can append
vectors or new values onto an existing vector with the \fBappend\fR
operation.
.CS
# Append assorted vectors and values to x
x append x2 x3 { 2.3 4.5 } x4
.CE
The \fBsort\fR operation sorts the vector.  If any additional vectors
are specified, they are rearranged in the same order as the vector.
For example, you could use it to sort data points represented by x and
y vectors.
.CS
# Sort the data points
x sort y
.CE
The vector \f(CWx\fR is sorted while the components of \f(CWy\fR are
rearranged so that the original x,y coordinate pairs are retained.
.PP
The \fBexpr\fR operation lets you perform arithmetic on vectors.
The result is stored in the vector.
.CS
# Add the two vectors and a scalar
x expr { x + y }
x expr { x * 2 }
.CE
When a vector is modified, resized, or deleted, it may trigger
call-backs to notify the clients of the vector.  For example, when a
vector used in the \fBgraph\fR widget is updated, the vector
automatically notifies the widget that it has changed.  The graph can
then redrawn itself at the next idle point.  By default, the
notification occurs when Tk is next idle.  This way you can modify the
vector many times without incurring the penalty of the graph redrawing
itself for each change.  You can change this behavior using the
\fBnotify\fR operation.
.CS
# Make vector x notify after every change
x notify always
	...
# Never notify
x notify never
	...
# Force notification now
x notify now
.CE
To delete a vector, use the \fBvector delete\fR command.
Both the vector and its corresponding Tcl command are destroyed.
.CS
# Remove vector x
vector destroy x
.CE
.SH SYNTAX
Vectors are created using the \fBvector create\fR operation.
Th \fBcreate\fR operation can be invoked in one of three forms:
.TP
\fBvector create \fIvecName\fR
This creates a new vector \fIvecName\fR which initially has no components.
.TP
\fBvector create \fIvecName\fR(\fIsize\fR)
This second form creates a new vector which will contain \fIsize\fR
number of components.  The components will be indexed starting from
zero (0). The default value for the components is \f(CW0.0\fR.
.TP
\fBvector create \fIvecName\fR(\fIfirst\fR:\fIlast\fR)
The last form creates a new vector of indexed \fIfirst\fR through
\fIlast\fR.  \fIFirst\fR and \fIlast\fR can be any integer value
so long as \fIfirst\fR is less than \fIlast\fR.
.PP
Vector names must start with a letter and consist of letters, digits,
or underscores.
.CS
# Error: must start with letter
vector create 1abc
.CE
You can automatically generate vector names using the
"\f(CW#auto\fR" vector name.  The \fBcreate\fR operation will generate a
unique vector name.
.CS
set vec [vector create #auto]
puts "$vec has [$vec length] components"
.CE
.SS VECTOR INDICES
Vectors are indexed by integers.  You can access the individual vector
components via its array variable or Tcl command.  The string
representing the index can be an integer, a numeric expression, a
range, or a special keyword.
.PP
The index must lie within the current range of the vector, otherwise
an an error message is returned.  Normally the indices of a vector
are start from 0.  But you can use the \fBoffset\fR operation to
change a vector's indices on-the-fly.
.CS
puts $vecName(0)
vecName offset -5
puts $vecName(-5)
.CE
You can also use numeric expressions as indices.  The result
of the expression must be an integer value.
.CS
set n 21
set vecName($n+3) 50.2
.CE
The following special non-numeric indices are available: \f(CWmin\fR, \f(CWmax\fR, \f(CWend\fR, and
\f(CW++end\fR.
.CS
puts "min = $vecName($min)"
set vecName(end) -1.2
.CE
The indices \f(CWmin\fR and \f(CWmax\fR will return the minimum and maximum
values of the vector.  The index \f(CWend\fR returns the value of the
last component in the vector.  The index \f(CW++end\fR is used to append
new value onto the vector.  It automatically extends the vector by
one component and sets its value.
.CS
# Append an new component to the end
set vecName(++end) 3.2
.CE
A range of indices can be indicated by a colon (:).
.CS
# Set the first six components to 1.0
set vecName(0:5) 1.0
.CE
If no index is supplied the first or last component is assumed.
.CS
# Print the values of all the components
puts $vecName(:)
.CE
.SH VECTOR OPERATIONS
.TP
\fBvector create \fIvecName\fR?(\fIsize\fR)?... \fR?\fIswitches\fR?
The \fBcreate\fR operation creates a new vector \fIvecName\fR.  Both a
Tcl command and array variable \fIvecName\fR are also created.  The
name \fIvecName\fR must be unique, so another Tcl command or array
variable can not already exist in that scope.  You can access the
components of the vector using its variable.  If you change a value in
the array, or unset an array element, the vector is updated to reflect
the changes.  When the variable \fIvecName\fR is unset, the vector and
its Tcl command are also destroyed.
.sp
The vector has optional switches that affect how the vector is created. They
are as follows:
.RS
.TP
\fB\-variable \fIvarName\fR
Specifies the name of a Tcl variable to be mapped to the vector. If
the variable already exists, it is first deleted, then recreated.
If \fIvarName\fR is the empty string, then no variable will be mapped.
You can always map a variable back to the vector using the vector's
\fBvariable\fR operation.
.TP
\fB\-command \fIcmdName\fR
Maps a Tcl command to the vector. The vector can be accessed using
\fIcmdName\fR and one of the vector instance operations.
A Tcl command by that name cannot already exist.
If \fIcmdName\fR is the empty string, no command mapping
will be made.
.TP
\fB\-watchunset \fIboolean\fR
Indicates that the vector should automatically delete itself if
the variable associated with the vector is unset.  By default,
the vector will not be deleted.  This is different from previous
releases.  Set \fIboolean\fR to "true" to get the old behavior.
.RE
.TP
\fBvector destroy \fIvecName\fR \fR?\fIvecName...\fR?
.TP
\fBvector expr \fIexpression\fR
.RS
All binary operators take vectors as operands (remember that numbers
are treated as one-component vectors).  The exact action of binary
operators depends upon the length of the second operand.  If the
second operand has only one component, then each element of the first
vector operand is computed by that value.  For example, the expression
"x * 2" multiples all elements of the vector x by 2.  If the second
operand has more than one component, both operands must be the same
length.  Each pair of corresponding elements are computed.  So "x + y"
adds the the first components of x and y together, the second, and so on.
.sp
The valid operators are listed below, grouped in decreasing order
of precedence:
.TP 20
\fB\-\0\0!\fR
Unary minus and logical NOT.  The unary minus flips the sign of each
component in the vector.  The logical not operator returns a vector of
whose values are 0.0 or 1.0.  For each non-zero component 1.0 is returned,
0.0 otherwise.
.TP 20
\fB^\fR
Exponentiation.
.TP 20
\fB*\0\0/\0\0%\fR
Multiply, divide, remainder.
.TP 20
\fB+\0\0\-\fR
Add and subtract.
.TP 20
\fB<<\0\0>>\fR
Left and right shift.  Circularly shifts the values of the vector
(not implemented yet).
.TP 20
\fB<\0\0>\0\0<=\0\0>=\fR
Boolean less, greater, less than or equal, and greater than or equal.
Each operator returns a vector of ones and zeros.  If the condition is true,
1.0 is the component value, 0.0 otherwise.
.TP 20
\fB==\0\0!=\fR
Boolean equal and not equal.
Each operator returns a vector of ones and zeros.  If the condition is true,
1.0 is the component value, 0.0 otherwise.
.TP 20
\fB|\fR
Bit-wise OR.  (Not implemented).
.TP 20
\fB&&\fR
Logical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
.TP 20
\fB||\fR
Logical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
.TP 20
\fIx\fB?\fIy\fB:\fIz\fR
If-then-else, as in C.  (Not implemented yet).
.LP
See the C manual for more details on the results produced by each
operator.  All of the binary operators group left-to-right within the
same precedence level.
.sp
Several mathematical functions are supported for vectors.  Each of
the following functions invokes the math library function of the same name;
see the manual entries for the library functions for details on what
they do.  The operation is applied to all elements of the vector
returning the results.
.CS
.ta 3c 6c 9c
\fBacos\fR	\fBcos\fR	\fBhypot\fR	\fBsinh\fR
\fBasin\fR	\fBcosh\fR	\fBlog\fR	\fBsqrt\fR
\fBatan\fR	\fBexp\fR	\fBlog10\fR	\fBtan\fR
\fBceil\fR	\fBfloor\fR	\fBsin\fR	\fBtanh\fR
.CE
Additional functions are:
.TP 1i
\fBabs\fR
Returns the absolute value of each component.
.TP 1i
\fBrandom\fR
Returns a vector of non-negative values uniformly distributed
between [0.0, 1.0) using \fIdrand48\fR.
The seed comes from the internal clock of the machine or may be
set manual with the srandom function.
.TP 1i
\fBround\fR
Rounds each component of the vector.
.TP 1i
\fBsrandom\fR
Initializes the random number generator using \fIsrand48\fR.
The high order 32-bits are set using the integral portion of the first
vector component. All other components are ignored.  The low order 16-bits
are set to an arbitrary value.
.PP
The following functions return a single value.
.TP 1i
\fBadev\fR
Returns the average deviation (defined as the sum of the absolute values
of the differences between component and the mean, divided by the length
of the vector).
.TP 1i
\fBkurtosis\fR
Returns the degree of peakedness (fourth moment) of the vector.
.TP 1i
\fBlength\fR
Returns the number of components in the vector.
.TP 1i
\fBmax\fR
Returns the vector's maximum value.
.TP 1i
\fBmean\fR
Returns the mean value of the vector.
.TP 1i
\fBmedian\fR
Returns the median of the vector.
.TP 1i
\fBmin\fR
Returns the vector's minimum value.
.TP 1i
\fBq1\fR
Returns the first quartile of the vector.
.TP 1i
\fBq3\fR
Returns the third quartile of the vector.
.TP 1i
\fBprod\fR
Returns the product of the components.
.TP 1i
\fBsdev\fR
Returns the standard deviation (defined as the square root of the variance)
of the vector.
.TP 1i
\fBskew\fR
Returns the skewness (or third moment) of the vector.  This characterizes
the degree of asymmetry of the vector about the mean.
.TP 1i
\fBsum\fR
Returns the sum of the components.
.TP 1i
\fBvar\fR
Returns the variance of the vector. The sum of the squared differences
between each component and the mean is computed.  The variance is
the sum divided by the length of the vector minus 1.
.PP
The last set returns a vector of the same length as the argument.
.TP 1i
\fBnorm\fR
Scales the values of the vector to lie in the range [0.0..1.0].
.TP 1i
\fBsort\fR
Returns the vector components sorted in ascending order.
.RE
.TP
\fBvector names \fR?\fIpattern\fR?
.SH INSTANCE OPERATIONS
You can also use the vector's Tcl command to query or modify it.  The
general form is
.DS
\fIvecName \fIoperation\fR \fR?\fIarg\fR?...
.DE
Both \fIoperation\fR and its arguments determine the exact behavior of
the command.  The operations available for vectors are listed below.
.TP
\fIvecName \fBappend\fR \fIitem\fR ?\fIitem\fR?...
Appends the component values from \fIitem\fR to \fIvecName\fR.
\fIItem\fR can be either the name of a vector or a list of numeric
values.
.TP
\fIvecName \fBbinread\fR \fIchannel\fR ?\fIlength\fR? ?\fIswitches\fR?
Reads binary values from a Tcl channel. Values are either appended
to the end of the vector or placed at a given index (using the
\fB\-at\fR option), overwriting existing values.  Data is read until EOF
is found on the channel or a specified number of values \fIlength\fR
are read (note that this is not necessarily the same as the number of
bytes). The following switches are supported:
.RS
.TP
\fB\-swap\fR
Swap bytes and words.  The default endian is the host machine.
.TP
\fB\-at \fIindex\fR
New values will start at vector index \fIindex\fR.  This will
overwrite any current values.
.TP
\fB\-format\fR \fIformat\fR
Specifies the format of the data.  \fIFormat\fR can be one of the
following: "i1", "i2", "i4", "i8", "u1, "u2", "u4", "u8", "r4",
"r8", or "r16".  The number indicates the number of bytes
required for each value.  The letter indicates the type: "i" for signed,
"u" for unsigned, "r" or real.  The default format is "r16".
.RE
.TP
\fIvecName \fBclear\fR
Clears the element indices from the array variable associated with
\fIvecName\fR.  This doesn't affect the components of the vector.  By
default, the number of entries in the Tcl array doesn't match the
number of components in the vector.  This is because its too expensive
to maintain decimal strings for both the index and value for each
component.  Instead, the index and value are saved only when you read
or write an element with a new index.  This command removes the index
and value strings from the array.  This is useful when the vector is
large.
.TP
\fIvecName \fBdelete\fR \fIindex\fR ?\fIindex\fR?...
Deletes the \fIindex\fRth component from the vector \fIvecName\fR.
\fIIndex\fR is the index of the element to be deleted.  This is the
same as unsetting the array variable element \fIindex\fR.  The vector
is compacted after all the indices have been deleted.
.TP
\fIvecName \fBdup\fR \fIdestName\fR
Copies \fIvecName\fR to \fIdestName\fR. \fIDestName\fR is the name of a
destination vector.  If a vector \fIdestName\fR already exists, it is
overwritten with the components of \fIvecName\fR.  Otherwise a
new vector is created.
.TP
\fIvecName \fBexpr\fR \fIexpression\fR
Computes the expression and resets the values of the vector accordingly.
Both scalar and vector math operations are allowed.  All values in
expressions are either real numbers or names of vectors.  All numbers
are treated as one component vectors.
.TP
\fIvecName \fBlength\fR ?\fInewSize\fR?
Queries or resets the number of components in \fIvecName\fR.
\fINewSize\fR is a number specifying the new size of the vector.  If
\fInewSize\fR is smaller than the current size of \fIvecName\fR,
\fIvecName\fR is truncated.  If \fInewSize\fR is greater, the vector
is extended and the new components are initialized to \f(CW0.0\fR.  If
no \fInewSize\fR argument is present, the current length of the vector
is returned.
.TP
\fIvecName \fBmerge\fR \fIsrcName\fR ?\fIsrcName\fR?...
Merges the named vectors into a single vector.  The resulting
vector is formed by merging the components of each source vector
one index at a time.
.TP
\fIvecName \fBnotify\fR \fIkeyword\fR
Controls how vector clients are notified of changes to the vector.
The exact behavior is determined by \fIkeyword\fR.
.RS
.TP 0.75i
\f(CWalways\fR
Indicates that clients are to be notified immediately whenever the
vector is updated.
.TP
\f(CWnever\fR
Indicates that no clients are to be notified.
.TP
\f(CWwhenidle\fR
Indicates that clients are to be notified at the next idle point
whenever the vector is updated.
.TP
\f(CWnow\fR
If any client notifications is currently pending, they are notified
immediately.
.TP
\f(CWcancel\fR
Cancels pending notifications of clients using the vector.
.TP
\f(CWpending\fR
Returns \f(CW1\fR if a client notification is pending, and \f(CW0\fR otherwise.
.RE
.TP
\fIvecName \fBoffset\fR ?\fIvalue\fR?
Shifts the indices of the vector by the amount specified by \fIvalue\fR.
\fIValue\fR is an integer number.  If no \fIvalue\fR argument is
given, the current offset is returned.
.TP
\fIvecName \fBpopulate\fR \fIdestName\fR ?\fIdensity\fR?
Creates a vector \fIdestName\fR which is a superset of \fIvecName\fR.
\fIDestName\fR will include all the components of \fIvecName\fR, in
addition the interval between each of the original components will
contain a \fIdensity\fR number of new components, whose values are
evenly distributed between the original components values.  This is
useful for generating abscissas to be interpolated along a spline.
.TP
\fIvecName \fBrange\fR \fIfirstIndex\fR ?\fIlastIndex\fR?...
Returns a list of numeric values representing the vector components
between two indices. Both \fIfirstIndex\fR and \fIlastIndex\fR are
indices representing the range of components to be returned. If
\fIlastIndex\fR is less than \fIfirstIndex\fR, the components are
listed in reverse order.
.TP
\fIvecName \fBsearch\fR \fIvalue\fR ?\fIvalue\fR?
Searches for a value or range of values among the components of
\fIvecName\fR.  If one \fIvalue\fR argument is given, a list of
indices of the components which equal \fIvalue\fR is returned.  If a
second \fIvalue\fR is also provided, then the indices of all
components which lie within the range of the two values are returned.
If no components are found, then \f(CW""\fR is returned.
.TP
\fIvecName \fBset\fR \fIitem\fR
Resets the components of the vector to \fIitem\fR. \fIItem\fR can
be either a list of numeric expressions or another vector.
.TP
\fIvecName \fBseq\fR \fIstart\fR ?\fIfinish\fR? ?\fIstep\fR?
Generates a sequence of values starting with the value \fIstart\fR.
\fIFinish\fR indicates the terminating value of the sequence.
The vector is automatically resized to contain just the sequence.
If three arguments are present, \fIstep\fR designates the interval.
.sp
With only two arguments (no \fIfinish\fR argument), the sequence will
continue until the vector is filled.  With one argument, the interval
defaults to 1.0.
.TP
\fIvecName \fBsort\fR ?\fB-reverse\fR? ?\fIargName\fR?...
Sorts the vector \fIvecName\fR in increasing order.  If the
\fB-reverse\fR flag is present, the vector is sorted in decreasing
order.  If other arguments \fIargName\fR are present, they are the
names of vectors which will be rearranged in the same manner as
\fIvecName\fR.  Each vector must be the same length as \fIvecName\fR.
You could use this to sort the x vector of a graph, while still
retaining the same x,y coordinate pairs in a y vector.
.TP
\fIvecName \fBvariable\fR \fIvarName\fR
Maps a Tcl variable to the vector, creating another means for
accessing the vector.  The variable \fIvarName\fR can't already
exist. This overrides any current variable mapping the vector
may have.
.RE
.SH C LANGUAGE API
You can create, modify, and destroy vectors from C code, using
library routines.
You need to include the header file \f(CWblt.h\fR. It contains the
definition of the structure \fBBlt_Vector\fR, which represents the
vector.  It appears below.
.CS
\fRtypedef struct {
    double *\fIvalueArr\fR;
    int \fInumValues\fR;
    int \fIarraySize\fR;
    double \fImin\fR, \fImax\fR;
} \fBBlt_Vector\fR;
.CE
The field \fIvalueArr\fR points to memory holding the vector
components.  The components are stored in a double precision array,
whose size size is represented by \fIarraySize\fR.  \fINumValues\fR is
the length of vector.  The size of the array is always equal to or
larger than the length of the vector.  \fIMin\fR and \fImax\fR are
minimum and maximum component values.
.SH LIBRARY ROUTINES
The following routines are available from C to manage vectors.
Vectors are identified by the vector name.
.PP
\fBBlt_CreateVector\fR
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_CreateVector\fR (\fIinterp\fR, \fIvecName\fR, \fIlength\fR, \fIvecPtrPtr\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
int \fIlength\fR;
Blt_Vector **\fIvecPtrPtr\fR;
.RE
.CE
.TP
Description:
Creates a new vector \fIvecName\fR\fR with a length of \fIlength\fR.
\fBBlt_CreateVector\fR creates both a new Tcl command and array
variable \fIvecName\fR.  Neither a command nor variable named
\fIvecName\fR can already exist.  A pointer to the vector is
placed into \fIvecPtrPtr\fR.
.TP
Results:
Returns \f(CWTCL_OK\fR if the vector is successfully created.  If
\fIlength\fR is negative, a Tcl variable or command \fIvecName\fR
already exists, or memory cannot be allocated for the vector, then
\f(CWTCL_ERROR\fR is returned and \fIinterp->result\fR will contain an
error message.
.RE
.sp
.PP
\fBBlt_DeleteVectorByName\fR
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_DeleteVectorByName\fR (\fIinterp\fR, \fIvecName\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
.RE
.CE
.TP 1i
Description:
Removes the vector \fIvecName\fR.  \fIVecName\fR is the name of a vector
which must already exist.  Both the Tcl command and array variable
\fIvecName\fR are destroyed.  All clients of the vector will be notified
immediately that the vector has been destroyed.
.TP
Results:
Returns \f(CWTCL_OK\fR if the vector is successfully deleted.  If
\fIvecName\fR is not the name a vector, then \f(CWTCL_ERROR\fR is returned
and \fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_DeleteVector\fR
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_DeleteVector\fR (\fIvecPtr\fR)
.RS 1.25i
Blt_Vector *\fIvecPtr\fR;
.RE
.CE
.TP 1i
Description:
Removes the vector pointed to by \fIvecPtr\fR.  \fIVecPtr\fR is a
pointer to a vector, typically set by \fBBlt_GetVector\fR or
\fBBlt_CreateVector\fR.  Both the Tcl command and array variable of
the vector are destroyed.  All clients of the vector will be notified
immediately that the vector has been destroyed.
.TP
Results:
Returns \f(CWTCL_OK\fR if the vector is successfully deleted.  If
\fIvecName\fR is not the name a vector, then \f(CWTCL_ERROR\fR is returned
and \fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_GetVector\fR
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_GetVector\fR (\fIinterp\fR, \fIvecName\fR, \fIvecPtrPtr\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
Blt_Vector **\fIvecPtrPtr\fR;
.RE
.CE
.TP 1i
Description:
Retrieves the vector \fIvecName\fR.  \fIVecName\fR is the name of a
vector which must already exist.  \fIVecPtrPtr\fR will point be set to
the address of the vector.
.TP
Results:
Returns \f(CWTCL_OK\fR if the vector is successfully retrieved.  If
\fIvecName\fR is not the name of a vector, then \f(CWTCL_ERROR\fR is
returned and \fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_ResetVector\fR
.PP
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_ResetVector\fR (\fIvecPtr\fR, \fIdataArr\fR,
	\fInumValues\fR, \fIarraySize\fR, \fIfreeProc\fR)
.RS 1.25i
Blt_Vector *\fIvecPtr\fR;
double *\fIdataArr\fR;
int *\fInumValues\fR;
int *\fIarraySize\fR;
Tcl_FreeProc *\fIfreeProc\fR;
.RE
.CE
.TP
Description:
Resets the components of the vector pointed to by \fIvecPtr\fR.
Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
notifications to its clients. \fIDataArr\fR is the array of doubles
which represents the vector data. \fINumValues\fR is the number of
elements in the array. \fIArraySize\fR is the actual size of the array
(the array may be bigger than the number of values stored in
it). \fIFreeProc\fP indicates how the storage for the vector component
array (\fIdataArr\fR) was allocated.  It is used to determine how to
reallocate memory when the vector is resized or destroyed.  It must be
\f(CWTCL_DYNAMIC\fR, \f(CWTCL_STATIC\fR, \f(CWTCL_VOLATILE\fR, or a pointer
to a function to free the memory allocated for the vector array. If
\fIfreeProc\fR is \f(CWTCL_VOLATILE\fR, it indicates that \fIdataArr\fR
must be copied and saved.  If \fIfreeProc\fR is \f(CWTCL_DYNAMIC\fR, it
indicates that \fIdataArr\fR was dynamically allocated and that Tcl
should free \fIdataArr\fR if necessary.  \f(CWStatic\fR indicates that
nothing should be done to release storage for \fIdataArr\fR.
.TP
Results:
Returns \f(CWTCL_OK\fR if the vector is successfully resized.  If
\fInewSize\fR is negative, a vector \fIvecName\fR does not exist, or
memory cannot be allocated for the vector, then \f(CWTCL_ERROR\fR is
returned and \fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_ResizeVector\fR
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_ResizeVector\fR (\fIvecPtr\fR, \fInewSize\fR)
.RS 1.25i
Blt_Vector *\fIvecPtr\fR;
int \fInewSize\fR;
.RE
.CE
.TP
Description:
Resets the length of the vector pointed to by \fIvecPtr\fR to
\fInewSize\fR.  If \fInewSize\fR is smaller than the current size of
the vector, it is truncated.  If \fInewSize\fR is greater, the vector
is extended and the new components are initialized to \f(CW0.0\fR.
Calling \fBBlt_ResetVector\fR will trigger the vector to dispatch
notifications.
.TP
Results:
Returns \f(CWTCL_OK\fR if the vector is successfully resized.  If
\fInewSize\fR is negative or memory can not be allocated for the vector,
then \f(CWTCL_ERROR\fR is returned and \fIinterp->result\fR will contain
an error message.
.sp
.PP
\fBBlt_VectorExists\fR
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_VectorExists\fR (\fIinterp\fR, \fIvecName\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
.RE
.CE
.TP
Description:
Indicates if a vector named \fIvecName\fR exists in \fIinterp\fR.
.TP
Results:
Returns \f(CW1\fR if a vector \fIvecName\fR exists and \f(CW0\fR otherwise.
.RE
.sp
.PP
If your application needs to be notified when a vector changes, it can
allocate a unique \fIclient identifier\fR for itself.  Using this
identifier, you can then register a call-back to be made whenever the
vector is updated or destroyed.  By default, the call-backs are made at
the next idle point.  This can be changed to occur at the time the
vector is modified.  An application can allocate more than one
identifier for any vector.  When the client application is done with
the vector, it should free the identifier.
.PP
The call-back routine must of the following type.
.CS
.RS
.sp
typedef void (\fBBlt_VectorChangedProc\fR) (Tcl_Interp *\fIinterp\fR,
.RS .25i
ClientData \fIclientData\fR, Blt_VectorNotify \fInotify\fR);
.RE
.sp
.RE
.CE
.fi
\fIClientData\fR is passed to this routine whenever it is called.  You
can use this to pass information to the call-back.  The \fInotify\fR
argument indicates whether the vector has been updated of destroyed. It
is an enumerated type.
.CS
.RS
.sp
typedef enum {
    \f(CWBLT_VECTOR_NOTIFY_UPDATE\fR=1,
    \f(CWBLT_VECTOR_NOTIFY_DESTROY\fR=2
} \fBBlt_VectorNotify\fR;
.sp
.RE
.CE
.PP
\fBBlt_AllocVectorId\fR
.RS .25i
.TP 1i
Synopsis:
.CS
Blt_VectorId \fBBlt_AllocVectorId\fR (\fIinterp\fR, \fIvecName\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
char *\fIvecName\fR;
.RE
.CE
.TP
Description:
Allocates an client identifier for with the vector \fIvecName\fR.
This identifier can be used to specify a call-back which is triggered
when the vector is updated or destroyed.
.TP
Results:
Returns a client identifier if successful.  If \fIvecName\fR is not
the name of a vector, then \f(CWNULL\fR is returned and
\fIinterp->result\fR will contain an error message.
.RE
.sp
.PP
\fBBlt_GetVectorById\fR
.RS .25i
.TP 1i
Synopsis:
.CS
int \fBBlt_GetVector\fR (\fIinterp\fR, \fIclientId\fR, \fIvecPtrPtr\fR)
.RS 1.25i
Tcl_Interp *\fIinterp\fR;
Blt_VectorId \fIclientId\fR;
Blt_Vector **\fIvecPtrPtr\fR;
.RE
.CE
.TP 1i
Description:
Retrieves the vector used by \fIclientId\fR.  \fIClientId\fR is a valid
vector client identifier allocated by \fBBlt_AllocVectorId\fR.
\fIVecPtrPtr\fR will point be set to the address of the vector.
.TP
Results:
Returns \f(CWTCL_OK\fR if the vector is successfully retrieved.
.RE
.sp
.PP
\fBBlt_SetVectorChangedProc\fR
.RS .25i
.TP 1i
Synopsis:
.CS
void \fBBlt_SetVectorChangedProc\fR (\fIclientId\fR, \fIproc\fR, \fIclientData\fR);
.RS 1.25i
Blt_VectorId \fIclientId\fR;
Blt_VectorChangedProc *\fIproc\fR;
ClientData *\fIclientData\fR;
.RE
.CE
.TP
Description:
Specifies a call-back routine to be called whenever the vector
associated with \fIclientId\fR is updated or deleted.  \fIProc\fR is a
pointer to call-back routine and must be of the type
\fBBlt_VectorChangedProc\fR.  \fIClientData\fR is a one-word value to
be passed to the routine when it is invoked. If \fIproc\fR is
\f(CWNULL\fR, then the client is not notified.
.TP
Results:
The designated call-back procedure will be invoked when the vector is
updated or destroyed.
.RE
.sp
.PP
\fBBlt_FreeVectorId\fR
.RS .25i
.TP 1i
Synopsis:
.CS
void \fBBlt_FreeVectorId\fR (\fIclientId\fR);
.RS 1.25i
Blt_VectorId \fIclientId\fR;
.RE
.CE
.TP
Description:
Frees the client identifier.  Memory allocated for the identifier
is released.  The client will no longer be notified when the
vector is modified.
.TP
Results:
The designated call-back procedure will be no longer be invoked when
the vector is updated or destroyed.
.RE
.sp
.PP
\fBBlt_NameOfVectorId\fR
.RS .25i
.TP 1i
Synopsis:
.CS
char *\fBBlt_NameOfVectorId\fR (\fIclientId\fR);
.RS 1.25i
Blt_VectorId \fIclientId\fR;
.RE
.CE
.TP
Description:
Retrieves the name of the vector associated with the client identifier
\fIclientId\fR.
.TP
Results:
Returns the name of the vector associated with \fIclientId\fR.  If
\fIclientId\fR is not an identifier or the vector has been destroyed,
\f(CWNULL\fR is returned.
.RE
.sp
.PP
\fBBlt_InstallIndexProc\fR
.RS .25i
.TP 1i
Synopsis:
.CS
void \fBBlt_InstallIndexProc\fR (\fIindexName\fR, \fIprocPtr\fR)
.RS 1.25i
char *\fIindexName\fR;
Blt_VectorIndexProc *\fIprocPtr\fR;
.RE
.CE
.TP
Description:
Registers a function to be called to retrieved the index \fIindexName\fR
from the vector's array variable.
.sp
typedef double Blt_VectorIndexProc(Vector *vecPtr);
.sp
The function will be passed a pointer to the vector.  The function must
return a double representing the value at the index.
.TP
Results:
The new index is installed into the vector.
.RE
.RE
.SH C API EXAMPLE
The following example opens a file of binary data and stores it in an
array of doubles. The array size is computed from the size of the
file. If the vector "data" exists, calling \fBBlt_VectorExists\fR,
\fBBlt_GetVector\fR is called to get the pointer to the vector.
Otherwise the routine \fBBlt_CreateVector\fR is called to create a new
vector and returns a pointer to it. Just like the Tcl interface, both
a new Tcl command and array variable are created when a new vector is
created. It doesn't make any difference what the initial size of the
vector is since it will be reset shortly. The vector is updated when
\fBlt_ResetVector\fR is called.  Blt_ResetVector makes the changes
visible to the Tcl interface and other vector clients (such as a graph
widget).
.sp
.CS
#include <tcl.h>
#include <blt.h>
...
Blt_Vector *vecPtr;
double *newArr;
FILE *f;
struct stat statBuf;
int numBytes, numValues;

f = fopen("binary.dat", "r");
fstat(fileno(f), &statBuf);
numBytes = (int)statBuf.st_size;

/* Allocate an array big enough to hold all the data */
newArr = (double *)malloc(numBytes);
numValues = numBytes / sizeof(double);
fread((void *)newArr, numValues, sizeof(double), f);
fclose(f);

if (Blt_VectorExists(interp, "data"))  {
    if (Blt_GetVector(interp, "data", &vecPtr) != TCL_OK) {
	return TCL_ERROR;
    }
} else {
   if (Blt_CreateVector(interp, "data", 0, &vecPtr) != TCL_OK) {
	return TCL_ERROR;
   }
}
/*
 * Reset the vector. Clients will be notified when Tk is idle.
 * TCL_DYNAMIC tells the vector to free the memory allocated
 * if it needs to reallocate or destroy the vector.
 */
if (Blt_ResetVector(vecPtr, newArr, numValues, numValues,
	TCL_DYNAMIC) != TCL_OK) {
    return TCL_ERROR;
}
.CE
.SH "INCOMPATIBILITIES"
In previous versions, if the array variable isn't global
(i.e. local to a Tcl procedure), the vector is automatically
destroyed when the procedure returns.
.CS
proc doit {} {
    # Temporary vector x
    vector x(10)
    set x(9) 2.0
      ...
}
.CE
.PP
This has changed.  Variables are not automatically destroyed when
their variable is unset.  You can restore the old behavior by
setting the "-watchunset" switch.
.CE
.SH KEYWORDS
vector, graph, widget

Added doc/rbc/vector.n.md.






























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
[NAME]: #NAME
[SYNOPSIS]: #SYNOPSIS
[DESCRIPTION]: #DESCRIPTION
[INTRODUCTION]: #INTRODUCTION
[EXAMPLE]: #EXAMPLE
[SYNTAX]: #SYNTAX
[VECTOR INDICES]: #VECTORINDICES
[VECTOR OPERATIONS]: #VECTOROPERATIONS
[INSTANCE OPERATIONS]: #INSTANCEOPERATIONS
[C LANGUAGE API]: #CLANGUAGEAPI
[LIBRARY ROUTINES]: #LIBRARYROUTINES
[C API EXAMPLE]: #CAPIEXAMPLE
[INCOMPATIBILITIES]: #INCOMPATIBILITIES
[KEYWORDS]: #KEYWORDS

# vector(n) -- Vector data type for Tcl

   [NAME][]

	rbc::vector -- 

   [SYNOPSIS][]

   [DESCRIPTION][]

   [INTRODUCTION][]

   [EXAMPLE][] 

   [SYNTAX][]

**rbc::vector create** *vecName*
**rbc::vector create** *vecName(size)*
**rbc::vector create** *vecName(rows,columns)*
**rbc::vector create** *vecName(first:last)*

   [VECTOR INDICES][]

   [VECTOR OPERATIONS][]

**vector configure** *? -flush bool -watchunset bool -oldcreate bool -maxsize int -novariable bool -nocommand bool?*

**vector create** *vecName?(size)?... ?switches?*

            -variable varName 
            -command cmdName 
            -watchunset boolean 
            -flush boolean 

**vector destroy** *vecName ?vecName...?*

**vector expr** *expression*

            - ! 
            ^ 
            * / % 
            + - 
            << >> 
            < > <= >= 
            == != 
            && 
            || 
            x?y:z 

            abs 
            random 
            round 
            srandom 

            adev 
            kurtosis 
            length 
            max 
            mean 
            median 
            min 
            q1 
            q3 
            prod 
            sdev 
            skew 
            sum 
            var 

            invert 
            norm 
            row 
            sort 
            shift(nVec,N) 

**vector names** *?pattern?*

**vector op** *operation vecName ?arg?...*

   [INSTANCE OPERATIONS][]

**vecName +** *item*

**vecName append** *item ?item?...*

**vecName binread** *channel ?length? ?switches?*

            -swap 
            -at index 
            -format format 

**vecName binwrite** *channel ?length? ?-at index?*

**vecName clear**

**vecName delete** *index ?index?...*

**vecName dup** *destName*

**vecName expr** *expression*

**vecName index** *index ?value?...*

**vecName insert** *index item ?item?...*

**vecName length** *?newSize?*

**vecName matrix** *...*

**vecName matrix copy** *dstcolumn srccolumn ?srcVec?*

**vecName matrix delete** *column*

**vecName matrix get** *column*

**vecName matrix insert** *column ?initvalue? .*

**vecName matrix multiply** *srcVec ?dstVec?*

**vecName matrix numcols** *?size?*

**vecName matrix numrows** *?size?*

**vecName matrix set column** *?valuelist?*

**vecName matrix shift** *column amount ?startoffset?*

**vecName matrix sort** *column ?-reverse?*

**vecName matrix transpose** 

**vecName merge** *srcName ?srcName?...*

**vecName notify** *?keyword? ?script?*

            always 
            never 
            whenidle 
            now 
            cancel 
            pending 
            callback ?script? 

**vecName populate** *destName ?density?*

**vecName range** *firstIndex ?lastIndex?...*

**vecName search** *value ?value?*

**vecName set** *item*

**vecName seq** *start ?finish? ?step?*

**vecName sort** *?-reverse? ?argName?...*

**vecName split** *dstName ?dstName?...*

**vecName variable** *varName*

   [C LANGUAGE API][]

   [LIBRARY ROUTINES][]

        Synopsis: 

        Description: 

        Results: 

   [C API EXAMPLE][]

   [INCOMPATIBILITIES][]

   [KEYWORDS][]

## NAME <a name="NAME"></a>

vector - Vector data type for Tcl

## SYNOPSIS <a name="SYNOPSIS"></a>

vector configure option value ...
vector create vecName ?vecName...? ?switches?
vector destroy vecName ?vecName...?
vector expr expression
vector names ?pattern...?
vector op operation vecName ?arg?...

## DESCRIPTION <a name="DESCRIPTION"></a>

The vector command creates a vector of floating point values. The vector's components can be manipulated in three ways: through a Tcl array variable, a Tcl command, or the C API.

## INTRODUCTION <a name="INTRODUCTION"></a>

A vector is simply an ordered set of numbers. The components of a vector are real numbers, indexed by counting numbers.

Vectors are common data structures for many applications. For example, a graph may use two vectors to represent the X-Y coordinates of the data plotted. The graph will automatically be redrawn when the vectors are updated or changed. By using vectors, you can separate data analysis from the graph widget. This makes it easier, for example, to add data transformations, such as splines. It's possible to plot the same data to in multiple graphs, where each graph presents a different view or scale of the data.

You could try to use Tcl's associative arrays as vectors. Tcl arrays are easy to use. You can access individual elements randomly by specifying the index, or the set the entire array by providing a list of index and value pairs for each element. The disadvantages of associative arrays as vectors lie in the fact they are implemented as hash tables.

    •  There's no implied ordering to the associative arrays. If you used vectors for plotting, you would want to insure the second component comes after the first, an so on. This isn't possible since arrays are actually hash tables. For example, you can't get a range of values between two indices. Nor can you sort an array.

    •  Arrays consume lots of memory when the number of elements becomes large (tens of thousands). This is because each element's index and value are stored as strings in the hash table.

    •  The C programming interface is unwieldy. Normally with vectors, you would like to view the Tcl array as you do a C array, as an array of floats or doubles. But with hash tables, you must convert both the index and value to and from decimal strings, just to access an element in the array. This makes it cumbersome to perform operations on the array as a whole.

The vector command tries to overcome these disadvantages while still retaining the ease of use of Tcl arrays. The vector command creates both a new Tcl command and associate array which are linked to the vector components. You can randomly access vector components though the elements of array. Not all indices are generated for the array, so printing the array (using the parray procedure) does not print out all the component values. You can use the Tcl command to access the array as a whole. You can copy, append, or sort vector using its command. If you need greater performance, or customized behavior, you can write your own C code to manage vectors.

## EXAMPLE <a name="EXAMPLE"></a>

You create vectors using the vector command and its create operation.

 # Create a new vector. 
vector create y(50)

This creates a new vector named y. It has fifty components, by default, initialized to 0.0. In addition, both a Tcl command and array variable, both named y, are created. You can use either the command or variable to query or modify components of the vector.

 # Set the first value. 
set y(0) 9.25
puts "y has [y length] components"

The array y can be used to read or set individual components of the vector. Vector components are indexed from zero. The array index must be a number less than the number of components. For example, it's an error if you try to set the 51st element of y.

 # This is an error. The vector only has 50 components.
set y(50) 0.02

You can also specify a range of indices using a colon (:) to separate the first and last indices of the range.

 # Set the first six components of y 
set y(0:5) 25.2

If you don't include an index, then it will default to the first and/or last component of the vector.

 # Print out all the components of y 
puts "y = $y(:)"

There are special non-numeric indices. The index end, specifies the last component of the vector. It's an error to use this index if the vector is empty (length is zero). The index ++end can be used to extend the vector by one component and initialize it to a specific value. You can't read from the array using this index, though.

 # Extend the vector by one component.
set y(++end) 0.02

The other special indices are min and max. They return the current smallest and largest components of the vector.

 # Print the bounds of the vector
puts "min=$y(min) max=$y(max)"

To delete components from a vector, simply unset the corresponding array element. In the following example, the first component of y is deleted. All the remaining components of y will be moved down by one index as the length of the vector is reduced by one.

 # Delete the first component
unset y(0)
puts "new first element is $y(0)"

The vector's Tcl command can also be used to query or set the vector.

 # Create and set the components of a new vector
vector create x
x set { 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 }

Here we've created a vector x without a initial length specification. In this case, the length is zero. The set operation resets the vector, extending it and setting values for each new component.

There are several operations for vectors. The range operation lists the components of a vector between two indices.

 # List the components 
puts "x = [x range 0 end]"

You can search for a particular value using the search operation. It returns a list of indices of the components with the same value. If no component has the same value, it returns "".

 # Find the index of the biggest component
set indices [x search $x(max)]

Other operations copy, append, or sort vectors. You can append vectors or new values onto an existing vector with the append operation.

 # Append assorted vectors and values to x
x append x2 x3 { 2.3 4.5 } x4

The sort operation sorts the vector. If any additional vectors are specified, they are rearranged in the same order as the vector. For example, you could use it to sort data points represented by x and y vectors.

 # Sort the data points
x sort y

The vector x is sorted while the components of y are rearranged so that the original x,y coordinate pairs are retained.

The expr operation lets you perform arithmetic on vectors. The result is stored in the vector.

 # Add the two vectors and a scalar
x expr { x + y }
x expr { x * 2 }

When a vector is modified, resized, or deleted, it may trigger call-backs to notify the clients of the vector. For example, when a vector used in the graph widget is updated, the vector automatically notifies the widget that it has changed. The graph can then redrawn itself at the next idle point. By default, the notification occurs when Tk is next idle. This way you can modify the vector many times without incurring the penalty of the graph redrawing itself for each change. You can change this behavior using the notify operation.

 # Make vector x notify after every change
x notify always
	...
 # Never notify
x notify never
	...
 # Force notification now
x notify now

 # Set Tcl callback for update of Tktable widget .t.
x notify callback {.t conf -padx [.t cget -padx]; .t reread}

To delete a vector, use the vector delete command. Both the vector and its corresponding Tcl command are destroyed.

 # Remove vector x
vector destroy x

The psuedo vector last can be used at the end of an expression to implement running totals. During execution it resolves to the result from the previous vector element evaluation.

vector create A(10)
vector create B(10)
vector create S(10)
vector create T(10)
S expr A+B
T expr S+last; # Running total

## SYNTAX <a name="SYNTAX"></a>

Vectors are created using the vector create operation. Th create operation can be invoked in one of three forms:

vector create vecName
    This creates a new vector vecName which initially has no components.

vector create vecName(size)
    This second form creates a new vector which will contain size number of components. The components will be indexed starting from zero (0). The default value for the components is 0.0.

vector create vecName(rows,columns)
    This form allows creation of a matrix with the specified columns and rows*columns elements. See the matrix section for more details.

vector create vecName(first:last)
    The last form creates a new vector of indexed first through last. First and last can be any integer value so long as first is less than last.

Vector names must start with a letter and consist of letters, digits, or underscores.

 # Error: must start with letter
vector create 1abc

You can automatically generate vector names using the "#auto" vector name. The create operation will generate a unique vector name.

set vec [vector create #auto]
puts "$vec has [$vec length] components"

## VECTOR INDICES <a name="VECTORINDICES"></a>

Vectors are indexed by integers. You can access the individual vector components via its array variable or Tcl command. The string representing the index can be an integer, a numeric expression, a range, or a special keyword.

The index must lie within the current range of the vector, otherwise an an error message is returned. Normally the indices of a vector are start from 0. But you can use the offset operation to change a vector's indices on-the-fly.

puts $vecName(0)
vecName offset -5
puts $vecName(-5)

When matrix numcols is > 1, 2D indexes are supported using ROW,COL form.

vecName matrix numcols 3
puts vecName(0,2)

You can also use numeric expressions as indices. The result of the expression must be an integer value.

set n 21
set vecName($n+3) 50.2

The following special non-numeric indices are available: min, max, end, and ++end.

puts "min = $vecName($min)"
set vecName(end) -1.2

The indices min and max will return the minimum and maximum values of the vector. Also available are: prod, sum, and mean. The index end returns the value of the last component in the vector. he index end,0 returns the value of the last row in column 0 of the vector. The index ++end is used to append new value onto the vector. It automatically extends the vector by numcols and sets its value.

 # Append an new component to the end
set vecName(++end) 3.2

A range of indices can be indicated by a colon (:).

 # Set the first six components to 1.0
set vecName(0:5) 1.0

If no index is supplied the first or last component is assumed.

 # Print the values of all the components
puts $vecName(:)

## VECTOR OPERATIONS <a name="VECTOROPERATIONS"></a>

vector configure ? -flush bool -watchunset bool -oldcreate bool -maxsize int -novariable bool -nocommand bool?
    The configure operation sets the default options used in creating vectors: these options are global to the interpreter. The -maxsize option, when non-zero, limits creation size. The -oldcreate enable the creation shortcut: vector vec1 vec2 .... See the create command for details on the others. By default, these are all disabled or zero.

vector create vecName?(size)?... \fR?\fIswitches\fR?
    The create operation creates a new vector vecName. The size may be an integer, a START:END range or ROW,COL (see matrix). This creates both a Tcl command and array variable called vecName. The name vecName must be unique, so another Tcl command or array variable can not already exist in the current scope. You may access the components of the vector using the variable. If you change a value in the array, or unset an array element, the vector is updated to reflect the changes. When the variable vecName is unset, the vector and its Tcl command are also destroyed.

    The vector has optional switches that affect how the vector is created. They are as follows:

    -variable varName
        Specifies the name of a Tcl variable to be mapped to the vector. If the variable already exists, it is first deleted, then recreated. If varName is the empty string, then no variable will be mapped. You can always map a variable back to the vector using the vector's variable operation.

    -command cmdName
        Maps a Tcl command to the vector. The vector can be accessed using cmdName and one of the vector instance operations. A Tcl command by that name cannot already exist. If cmdName is the empty string, no command mapping will be made.

    -watchunset boolean
        Indicates that the vector should automatically delete itself if the variable associated with the vector is unset. By default, the vector will not be deleted. This is different from previous releases. Set boolean to "true" to get the old behavior.

    -flush boolean
        Indicates that the vector should automatically flush the cached variable elements which unsets all the elements of the Tcl array variable associated with the vector, freeing memory associated with the variable. This includes both the hash table and the hash keys. The down side is that this effectively flushes the caching of vector elements in the array. This means that the subsequent reads of the array will require a decimal to string conversion. By default, flushing is disabled.

vector destroy vecName \fR?\fIvecName...\fR?
    Destroy vectors.

vector expr expression

        All binary operators take vectors as operands (remember that numbers are treated as one-component vectors).The exact action of binary operators depends upon the length of the second operand. If the second operand has only one component, then each element of the first vector operand is computed by that value. For example, the expression "x * 2" multiples all elements of the vector x by 2. If the second operand has more than one component, both operands must be the same length. Each pair of corresponding elements are computed. So "x + y" adds the the first components of x and y together, the second, and so on.

        The valid operators are listed below, grouped in decreasing order of precedence:

        - !
            Unary minus and logical NOT. The unary minus flips the sign of each component in the vector. The logical not operator returns a vector of whose values are 0.0 or 1.0. For each non-zero component 1.0 is returned, 0.0 otherwise.

        ^
            Exponentiation.

        * / %
            Multiply, divide, remainder.

        + -
            Add and subtract.

        << >>
            Left and right shift. Circularly shifts the values of the vector

        < > <= >=
            Boolean less, greater, less than or equal, and greater than or equal. Each operator returns a vector of ones and zeros. If the condition is true, 1.0 is the component value, 0.0 otherwise.

        == !=
            Boolean equal and not equal. Each operator returns a vector of ones and zeros. If the condition is true, 1.0 is the component value, 0.0 otherwise.

        &&
            Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.

        ||
            Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.

        x?y:z
            If-then-else, as in C.

        See the C manual for more details on the results produced by each operator. All of the binary operators group left-to-right within the same precedence level.

        Several mathematical functions are supported for vectors. Each of the following functions invokes the math library function of the same name; see the manual entries for the library functions for details on what they do. The operation is applied to all elements of the vector returning the results. All functions take a vector operand. If no vector operand is used in the call, the current vector is assumed. eg.

        vector create aVec
        aVec seq 0 100
        aVec expr {2*abs(aVec)-1}
        aVec length 100
        aVec expr {2*row()}
        vector expr {2*row()} ; # ERROR!

        acos	cos	hypot	sinh 
        asin	cosh	log	sqrt 
        atan	exp	log10	tan  
        ceil	floor	sin	tanh

        Additional functions are:

        abs
            Returns the absolute value of each component.

        random
            Returns a vector of non-negative values uniformly distributed between [0.0, 1.0) using drand48. The seed comes from the internal clock of the machine or may be set manual with the srandom function.

        round
            Rounds each component of the vector.

        srandom
            Initializes the random number generator using srand48. The high order 32-bits are set using the integral portion of the first vector component. All other components are ignored. The low order 16-bits are set to an arbitrary value.

        The following functions return a single value.

        adev
            Returns the average deviation (defined as the sum of the absolute values of the differences between component and the mean, divided by the length of the vector).

        kurtosis
            Returns the degree of peakedness (fourth moment) of the vector.

        length
            Returns the number of components in the vector.

        max
            Returns the vector's maximum value.

        mean
            Returns the mean value of the vector.

        median
            Returns the median of the vector.

        min
            Returns the vector's minimum value.

        q1
            Returns the first quartile of the vector.

        q3
            Returns the third quartile of the vector.

        prod
            Returns the product of the components.

        sdev
            Returns the standard deviation (defined as the square root of the variance) of the vector.

        skew
            Returns the skewness (or third moment) of the vector. This characterizes the degree of asymmetry of the vector about the mean.

        sum
            Returns the sum of the components.

        var
            Returns the variance of the vector. The sum of the squared differences between each component and the mean is computed. The variance is the sum divided by the length of the vector minus 1.

        This last set of functions returns a vector of the same length as the argument.

        invert
            Returns vector with elements in reversed order.

        norm
            Scales the values of the vector to lie in the range [0.0..1.0].

        row
            Psuedo function to get the current row.

        sort
            Returns the vector components sorted in ascending order.

        shift(nVec,N)
            This is the only function taking a second arg. It provides a version of nvec shifted by N places. When N is a scalar or vector with only one element, shift fills vacant area with 0. Otherwise the second element of nVec is used for the fill value. One use for this is providing running totals.

vector names ?pattern?
    Return names of all defined vectors.

vector op operation vecName ?arg?...
    Invoke instance operation. Supported operations are defined in the next section. Op is the only way to invoke instance operation sub-commands when -command is defined as empty in a vector. It also allows writing vector code that is checkable by a syntax checkers. eg.

    vector create v1
    v1 op append {1 2 3}
    v1 op modify 1 2.1

## INSTANCE OPERATIONS <a name="INSTANCEOPERATIONS"></a>

You can also use the vector's Tcl command to query or modify it. The general form is

    vecName operation \fR?\fIarg\fR?...

Note this is equivalent to the form:

    vector op operation vecName ?arg?...

Both operation and its arguments determine the exact behavior of the command. The operations available for vectors are listed below.

vecName + item
    vecName - item vecName * item vecName / item Perform binary op and return result as a list.

vecName append item ?item?...
    Appends the component values from item to vecName. Item can be either the name of a vector or a list of numeric values.

vecName binread channel ?length? ?switches?
    Reads binary values from a Tcl channel. Values are either appended to the end of the vector or placed at a given index (using the -at option), overwriting existing values. Data is read until EOF is found on the channel or a specified number of values length are read (note that this is not necessarily the same as the number of bytes). The following switches are supported:

    -swap
        Swap bytes and words. The default endian is the host machine.

    -at index
        New values will start at vector index index. This will overwrite any current values.

    -format format
        Specifies the format of the data. Format can be one of the following: "i1", "i2", "i4", "i8", "u1, "u2", "u4", "u8", "r4", "r8", or "r16". The number indicates the number of bytes required for each value. The letter indicates the type: "i" for signed, "u" for unsigned, "r" or real. The default format is "r16".

vecName binwrite channel ?length? ?-at index?
    Like binread, but writes data.

vecName clear
    Clears the element indices from the array variable associated with vecName. This doesn't affect the components of the vector. By default, the number of entries in the Tcl array doesn't match the number of components in the vector. This is because its too expensive to maintain decimal strings for both the index and value for each component. Instead, the index and value are saved only when you read or write an element with a new index. This command removes the index and value strings from the array. This is useful when the vector is large.

vecName delete index ?index?...
    Deletes the indexth component from the vector vecName. Index is the index of the element to be deleted. This is the same as unsetting the array variable element index. The vector is compacted after all the indices have been deleted.

vecName dup destName
    Copies vecName to destName. DestName is the name of a destination vector. If a vector destName already exists, it is overwritten with the components of vecName. Otherwise a new vector is created.

vecName expr expression
    Computes the expression and resets the values of the vector accordingly. Both scalar and vector math operations are allowed. All values in expressions are either real numbers or names of vectors. All numbers are treated as one component vectors.

vecName index index ?value?...
    Get/set individual vector values. This provides element updating when -variable is set to empty.

vecName insert index item ?item?...
    Inserts the component values from item to vecName at index Item can be either the name of a vector or a list of numeric values.

vecName length ?newSize?
    Queries or resets the number of components in vecName. NewSize is a number specifying the new size of the vector. If newSize is smaller than the current size of vecName, vecName is truncated. If newSize is greater, the vector is extended and the new components are initialized to 0.0. If no newSize argument is present, the current length of the vector is returned.

vecName matrix ...
    Matrix provides a 2D array view into 1D data. It provides indexing operations in ROW,COL form making it suitable for use with TkTable. Data storage remains unchanged: vectors are still just a single long array. For example, here are two ways to create a 3 column by 10 row matrix:

    vector create aVec(10,3)
    vector create bVec(30)
    bVec matrix numcols 3
    set aVec(0,0) 99
    set bVec(29,2) -99
    aVec append {5 6 7}; # aVec now has 11 rows.
    aVec append 1 2;     # Now aVec has 13 rows!

    Note that data is appended only in increments of numcols. Elements 0-2 make up the first row, 3-5 the second, etc. Elements will appear only in increments of the column size.

    vecName matrix copy dstcolumn srccolumn ?srcVec?
        Copy a column of element values to column dstcolumn from srccolumn. If vector srcVec is given, and not the same as vecName, the columns numbers must be different. If the srcVec column is longer, vecName will be extended. If shorter, remaining destination values are not overwritten.

    vecName matrix delete column.
        Delete elements in a column. Note that numcols, which must be greater than 1, will be decremented.

    vecName matrix get column
        Get the element in a column: this number must be less than numcols. Note that numcols must be non-zero.

    vecName matrix insert column ?initvalue? .
        Insert a new column of elements at column (default 0). The new column is initialized with initvalue, or 0.0 if not specified. Note that numcols will be incremented.

    vecName matrix multiply srcVec ?dstVec?
        Perform matrix multiplication using srcVec, placing results either in dstVec, or returned as a list. The numrows of srcVec must equal numcols in vecName. One application for multiply is coordinate transformation.

    vecName matrix numcols ?size?
        Get or set the number of columns for a vectors data. Values >1 enable array variables to accept 2d matrix indexes. For example with a numcols of 10, $vec1(1,2) refers to the 13th element in the vector. A vectors size is also constrained to multiples of numcols, as is it's offset. By default, numcols is 1.

    vecName matrix numrows ?size?
        Get or set the length of rows in a columns for a vector. By default, this is just the vector length/numcols. Setting this value simply provides a convenient way to increase or decrease the vector size by multiples of numcols.

    vecName matrix set column ?valuelist?
        Set value elements in a column: this number must be less than numcols. The valuelist is a list values. If this list is shorter than the column, it's last value is used for all remaining columns. The column gets set to the values of item, or 0.0 by default.

    vecName matrix shift column amount ?startoffset?
        Shifts the values of a column by integer inamount. A negative value shifts upward. The startoffset indicates where to start shifting from.

    vecName matrix sort column ?-reverse?
        Sort the vector by the given column.

    vecName matrix transpose
        Transpose all columns with rows in matrix. Note that this is a no-op if numcols is 1. Otherwise, numcols will change to vectorLength/numcols.

vecName merge srcName ?srcName?...
    Merges the named vectors into a single vector. The resulting vector is formed by merging the components of each source vector one index at a time.

vecName notify ?keyword? ?script?
    Queries or controls how vector clients are notified of changes to the vector. Also allows setting a notifier callback. The exact behavior is determined by keyword.

    always
        Indicates that clients are to be notified immediately whenever the vector is updated.

    never
        Indicates that no clients are to be notified.

    whenidle
        Indicates that clients are to be notified at the next idle point whenever the vector is updated.

    now
        If any client notifications is currently pending, they are notified immediately.

    cancel
        Cancels pending notifications of clients using the vector.

    pending
        Returns 1 if a client notification is pending, and 0 otherwise.

    callback ?script?
        Query or set a Tcl callback script that is evaluated when a vector is updated.

vecName populate destName ?density?
    Creates a vector destName which is a superset of vecName. DestName will include all the components of vecName, in addition the interval between each of the original components will contain a density number of new components, whose values are evenly distributed between the original components values. This is useful for generating abscissas to be interpolated along a spline.

vecName range firstIndex ?lastIndex?...
    Returns a list of numeric values representing the vector components between two indices. Both firstIndex and lastIndex are indices representing the range of components to be returned. If lastIndex is less than firstIndex, the components are listed in reverse order.

vecName search value ?value?
    Searches for a value or range of values among the components of vecName. If one value argument is given, a list of indices of the components which equal value is returned. If a second value is also provided, then the indices of all components which lie within the range of the two values are returned. If no components are found, then "" is returned.

vecName set item
    Resets the components of the vector to item. Item can be either a list of numeric expressions or another vector.

vecName seq start ?finish? ?step?
    Generates a sequence of values starting with the value start. Finish indicates the terminating value of the sequence. The vector is automatically resized to contain just the sequence. If three arguments are present, step designates the interval.

    With only two arguments (no finish argument), the sequence will continue until the vector is filled. With one argument, the interval defaults to 1.0.

vecName sort ?-reverse? ?argName?...
    Sorts the vector vecName in increasing order. If the -reverse flag is present, the vector is sorted in decreasing order. If other arguments argName are present, they are the names of vectors which will be rearranged in the same manner as vecName. Each vector must be the same length as vecName. You could use this to sort the x vector of a graph, while still retaining the same x,y coordinate pairs in a y vector.

vecName split dstName ?dstName?...
    Split the vector into a multiple vectors. The resulting N vectors each contain the mod-Nth element from source.

vecName variable varName
    Maps a Tcl variable to the vector, creating another means for accessing the vector. The variable varName can't already exist. This overrides any current variable mapping the vector may have.

## C LANGUAGE API <a name="CLANGUAGEAPI"></a>

You can create, modify, and destroy vectors from C code, using library routines. You need to include the header file blt.h. It contains the definition of the structure Rbc_Vector, which represents the vector. It appears below.

\fRtypedef struct {
    double *\fIvalueArr\fR; 
    int \fInumValues\fR;    
    int \fIarraySize\fR;    
    double \fImin\fR, \fImax\fR;  
} \fBRbc_Vector\fR;

The field valueArr points to memory holding the vector components. The components are stored in a double precision array, whose size size is represented by arraySize. NumValues is the length of vector. The size of the array is always equal to or larger than the length of the vector. Min and max are minimum and maximum component values.

## LIBRARY ROUTINES <a name="LIBRARYROUTINES"></a>

The following routines are available from C to manage vectors. Vectors are identified by the vector name.

Rbc_CreateVector

Synopsis:
    int Rbc_CreateVector (interp, vecName, length, vecPtrPtr)

        Tcl_Interp *interp; char *vecName; int length; Rbc_Vector **vecPtrPtr; 

    Description:
        Creates a new vector vecName\fR with a length of \fIlength\fR. \fBRbc_CreateVector\fR creates both a new Tcl command and array variable \fIvecName\fR. Neither a command nor variable named \fIvecName\fR can already exist. A pointer to the vector is placed into \fIvecPtrPtr\fR.

    Results:
        Returns TCL_OK if the vector is successfully created. If length is negative, a Tcl variable or command vecName already exists, or memory cannot be allocated for the vector, then TCL_ERROR is returned and interp->result will contain an error message.

Rbc_DeleteVectorByName

Synopsis:
    int Rbc_DeleteVectorByName (interp, vecName)

        Tcl_Interp *interp; char *vecName; 

    Description:
        Removes the vector vecName. VecName is the name of a vector which must already exist. Both the Tcl command and array variable vecName are destroyed. All clients of the vector will be notified immediately that the vector has been destroyed.

    Results:
        Returns TCL_OK if the vector is successfully deleted. If vecName is not the name a vector, then TCL_ERROR is returned and interp->result will contain an error message.

Rbc_DeleteVector

Synopsis:
    int Rbc_DeleteVector (vecPtr)

        Rbc_Vector *vecPtr; 

    Description:
        Removes the vector pointed to by vecPtr. VecPtr is a pointer to a vector, typically set by Rbc_GetVector or Rbc_CreateVector. Both the Tcl command and array variable of the vector are destroyed. All clients of the vector will be notified immediately that the vector has been destroyed.

    Results:
        Returns TCL_OK if the vector is successfully deleted. If vecName is not the name a vector, then TCL_ERROR is returned and interp->result will contain an error message.

Rbc_GetVector

Synopsis:
    int Rbc_GetVector (interp, vecName, vecPtrPtr)

        Tcl_Interp *interp; char *vecName; Rbc_Vector **vecPtrPtr; 

    Description:
        Retrieves the vector vecName. VecName is the name of a vector which must already exist. VecPtrPtr will point be set to the address of the vector.

    Results:
        Returns TCL_OK if the vector is successfully retrieved. If vecName is not the name of a vector, then TCL_ERROR is returned and interp->result will contain an error message.

Rbc_ResetVector

Synopsis:
    int Rbc_ResetVector (vecPtr, dataArr, numValues, arraySize, freeProc)

        Rbc_Vector *vecPtr; double *dataArr; int *numValues; int *arraySize; Tcl_FreeProc *freeProc; 

    Description:
        Resets the components of the vector pointed to by vecPtr. Calling Rbc_ResetVector will trigger the vector to dispatch notifications to its clients. DataArr is the array of doubles which represents the vector data. NumValues is the number of elements in the array. ArraySize is the actual size of the array (the array may be bigger than the number of values stored in it). FreeProc indicates how the storage for the vector component array (dataArr) was allocated. It is used to determine how to reallocate memory when the vector is resized or destroyed. It must be TCL_DYNAMIC, TCL_STATIC, TCL_VOLATILE, or a pointer to a function to free the memory allocated for the vector array. If freeProc is TCL_VOLATILE, it indicates that dataArr must be copied and saved. If freeProc is TCL_DYNAMIC, it indicates that dataArr was dynamically allocated and that Tcl should free dataArr if necessary. Static indicates that nothing should be done to release storage for dataArr.

    Results:
        Returns TCL_OK if the vector is successfully resized. If newSize is negative, a vector vecName does not exist, or memory cannot be allocated for the vector, then TCL_ERROR is returned and interp->result will contain an error message.

Rbc_ResizeVector

Synopsis:
    int Rbc_ResizeVector (vecPtr, newSize)

        Rbc_Vector *vecPtr; int newSize; 

    Description:
        Resets the length of the vector pointed to by vecPtr to newSize. If newSize is smaller than the current size of the vector, it is truncated. If newSize is greater, the vector is extended and the new components are initialized to 0.0. Calling Rbc_ResetVector will trigger the vector to dispatch notifications.

    Results:
        Returns TCL_OK if the vector is successfully resized. If newSize is negative or memory can not be allocated for the vector, then TCL_ERROR is returned and interp->result will contain an error message.

    Rbc_VectorExists

    Synopsis:
        int Rbc_VectorExists (interp, vecName)

            Tcl_Interp *interp; char *vecName; 

        Description:
            Indicates if a vector named vecName exists in interp.

        Results:
            Returns 1 if a vector vecName exists and 0 otherwise.

    If your application needs to be notified when a vector changes, it can allocate a unique client identifier for itself. Using this identifier, you can then register a call-back to be made whenever the vector is updated or destroyed. By default, the call-backs are made at the next idle point. This can be changed to occur at the time the vector is modified. An application can allocate more than one identifier for any vector. When the client application is done with the vector, it should free the identifier.

    The call-back routine must of the following type.

        typedef void (Rbc_VectorChangedProc) (Tcl_Interp *interp,

            ClientData clientData, Rbc_VectorNotify notify); 

    ClientData is passed to this routine whenever it is called. You can use this to pass information to the call-back. The notify argument indicates whether the vector has been updated of destroyed. It is an enumerated type.

        typedef enum { BLT_VECTOR_NOTIFY_UPDATE=1, BLT_VECTOR_NOTIFY_DESTROY=2 } Rbc_VectorNotify;

    Rbc_AllocVectorId

    Synopsis:
        Rbc_VectorId Rbc_AllocVectorId (interp, vecName)

            Tcl_Interp *interp; char *vecName; 

        Description:
            Allocates an client identifier for with the vector vecName. This identifier can be used to specify a call-back which is triggered when the vector is updated or destroyed.

        Results:
            Returns a client identifier if successful. If vecName is not the name of a vector, then NULL is returned and interp->result will contain an error message.

    Rbc_GetVectorById

    Synopsis:
        int Rbc_GetVector (interp, clientId, vecPtrPtr)

            Tcl_Interp *interp; Rbc_VectorId clientId; Rbc_Vector **vecPtrPtr; 

        Description:
            Retrieves the vector used by clientId. ClientId is a valid vector client identifier allocated by Rbc_AllocVectorId. VecPtrPtr will point be set to the address of the vector.

        Results:
            Returns TCL_OK if the vector is successfully retrieved.

    Rbc_SetVectorChangedProc

    Synopsis:
        void Rbc_SetVectorChangedProc (clientId, proc, clientData);

            Rbc_VectorId clientId; Rbc_VectorChangedProc *proc; ClientData *clientData; 

        Description:
            Specifies a call-back routine to be called whenever the vector associated with clientId is updated or deleted. Proc is a pointer to call-back routine and must be of the type Rbc_VectorChangedProc. ClientData is a one-word value to be passed to the routine when it is invoked. If proc is NULL, then the client is not notified.

        Results:
            The designated call-back procedure will be invoked when the vector is updated or destroyed.

    Rbc_FreeVectorId

    Synopsis:
        void Rbc_FreeVectorId (clientId);

            Rbc_VectorId clientId; 

        Description:
            Frees the client identifier. Memory allocated for the identifier is released. The client will no longer be notified when the vector is modified.

        Results:
            The designated call-back procedure will be no longer be invoked when the vector is updated or destroyed.

    Rbc_NameOfVectorId

    Synopsis:
        char *Rbc_NameOfVectorId (clientId);

            Rbc_VectorId clientId; 

        Description:
            Retrieves the name of the vector associated with the client identifier clientId.

        Results:
            Returns the name of the vector associated with clientId. If clientId is not an identifier or the vector has been destroyed, NULL is returned.

    Rbc_InstallIndexProc

    Synopsis:
        void Rbc_InstallIndexProc (indexName, procPtr)

            char *indexName; Rbc_VectorIndexProc *procPtr; 

        Description:
            Registers a function to be called to retrieved the index indexName from the vector's array variable.

            typedef double Rbc_VectorIndexProc(Vector *vecPtr);

            The function will be passed a pointer to the vector. The function must return a double representing the value at the index.

        Results:
            The new index is installed into the vector.

## C API EXAMPLE <a name="CAPIEXAMPLE"></a>

The following example opens a file of binary data and stores it in an array of doubles. The array size is computed from the size of the file. If the vector "data" exists, calling Rbc_VectorExists, Rbc_GetVector is called to get the pointer to the vector. Otherwise the routine Rbc_CreateVector is called to create a new vector and returns a pointer to it. Just like the Tcl interface, both a new Tcl command and array variable are created when a new vector is created. It doesn't make any difference what the initial size of the vector is since it will be reset shortly. The vector is updated when lt_ResetVector is called. Rbc_ResetVector makes the changes visible to the Tcl interface and other vector clients (such as a graph widget).

  #include <tcl.h>
  #include <blt.h>
  Rbc_Vector *vecPtr;
  double *newArr;
  FILE *f;
  struct stat statBuf;
  int numBytes, numValues;
  f = fopen("binary.dat", "r");
  fstat(fileno(f), &statBuf);
  numBytes = (int)statBuf.st_size; /* Allocate an array big enough to hold all the data */
  newArr = (double *)malloc(numBytes);
  numValues = numBytes / sizeof(double);
  fread((void *)newArr, numValues, sizeof(double), f);
  fclose(f);
  if (Rbc_VectorExists(interp, "data")) {
    if (Rbc_GetVector(interp, "data", &vecPtr) != TCL_OK) {
      return TCL_ERROR;
    }
  } else {
    if (Rbc_CreateVector(interp, "data", 0, &vecPtr) != TCL_OK) {
      return TCL_ERROR;
    }
  }
  /* * Reset the vector. Clients will be notified when Tk is idle.
   * TCL_DYNAMIC tells the vector to free the memory allocated
   * if it needs to reallocate or destroy the vector.
   */
  if (Rbc_ResetVector(vecPtr, newArr, numValues, numValues, TCL_DYNAMIC) != TCL_OK) {
    return TCL_ERROR;
  }

## INCOMPATIBILITIES <a name="INCOMPATIBILITIES"></a>

In previous versions, if the array variable isn't global (i.e. local to a Tcl procedure), the vector is automatically destroyed when the procedure returns.

proc doit {} {
    # Temporary vector x
    vector x(10)
    set x(9) 2.0
      ...
}

This has changed. Variables are not automatically destroyed when their variable is unset. You can restore the old behavior by setting the "-watchunset" switch.

## KEYWORDS <a name="KEYWORDS"></a>

vector, graph, widget

## COPYRIGHT

&copy; 1995-1997 Roger E. Critchlow Jr.

&copy; 2001 George A. Howlett.

&copy; 2018 René Zaumseil <[email protected]>


Added generic/rbc/rbcAlloc.c.


























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
/*
 * rbcAlloc.C --
 *
 *      TODO: Description
 *
 * 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"

/*
 *----------------------------------------------------------------------
 *
 * RbcCalloc --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void           *
RbcCalloc(
    unsigned int nElems,
    size_t sizeOfElem)
{
    char           *allocPtr;
    size_t          size;

    size = nElems * sizeOfElem;
    allocPtr = ckalloc(size);
    if (allocPtr != NULL) {
        memset(allocPtr, 0, size);
    }
    return allocPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcStrdup --
 *
 *      Create a copy of the string from heap storage.
 *
 * Results:
 *      Returns a pointer to the need string copy.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
char           *
RbcStrdup(
    const char *string)
{
    size_t          size;
    char           *allocPtr;

    size = strlen(string) + 1;
    allocPtr = ckalloc(size * sizeof(char));
    if (allocPtr != NULL) {
        strcpy(allocPtr, string);
    }
    return allocPtr;
}

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

Added generic/rbc/rbcBind.c.


































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/*
 * rbcBind.c --
 *
 *      This module implements object binding procedures for the rbc
 *      toolkit.
 *
 * 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"

/*
 * Binding table procedures.
 */
#define REPICK_IN_PROGRESS (1<<0)
#define LEFT_GRABBED_ITEM  (1<<1)

#define ALL_BUTTONS_MASK \
    (Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask)

#ifndef VirtualEventMask
#define VirtualEventMask    (1L << 30)
#endif

#define ALL_VALID_EVENTS_MASK \
    (ButtonMotionMask | Button1MotionMask | Button2MotionMask | \
     Button3MotionMask | Button4MotionMask | Button5MotionMask | \
     ButtonPressMask | ButtonReleaseMask | EnterWindowMask | \
     LeaveWindowMask | KeyPressMask | KeyReleaseMask | \
     PointerMotionMask | VirtualEventMask)

static int      buttonMasks[] = {
    0,                          /* No buttons pressed */
    Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask,
};

/*
* Prototypes for procedures referenced only in this file:
*/

static Tk_EventProc BindProc;
static void     DoEvent(
    RbcBindTable * bindPtr,
    XEvent * eventPtr,
    ClientData item,
    ClientData context);
static void     PickCurrentItem(
    RbcBindTable * bindPtr,
    XEvent * eventPtr);

/*
 * How to make drag&drop work?
 *
 *  Right now we generate pseudo <Enter> <Leave> events within
 *  button grab on an object.  They're marked NotifyVirtual instead
 *  of NotifyAncestor.  A better solution: generate new-style
 *  virtual <<DragEnter>> <<DragMotion>> <<DragLeave>> events.
 *  These virtual events don't have to exist as "real" event
 *  sequences, like virtual events do now.
 */

/*
 *--------------------------------------------------------------
 *
 * DoEvent --
 *
 *      This procedure is called to invoke binding processing
 *      for a new event that is associated with the current item
 *      for a legend.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Depends on the bindings for the legend.  A binding script
 *      could delete an entry, so callers should protect themselves
 *      with Tcl_Preserve and Tcl_Release.
 *
 *--------------------------------------------------------------
 */
static void
DoEvent(
    RbcBindTable * bindPtr,     /* Binding information for widget in
                                 * which event occurred. */
    XEvent * eventPtr,          /* Real or simulated X event that
                                 * is to be processed. */
    ClientData item,            /* Item picked. */
    ClientData context)
{                               /* Context of item.  */
    RbcList        *bindIds;
    int             nIds;

    if ((bindPtr->tkwin == NULL) || (bindPtr->bindingTable == NULL)) {
        return;
    }
    if ((eventPtr->type == KeyPress) || (eventPtr->type == KeyRelease)) {
        item = bindPtr->focusItem;
        context = bindPtr->focusContext;
    }
    if (item == NULL) {
        return;
    }

    /*
     * Invoke the binding system.
     */
    bindIds = RbcListCreate(TCL_ONE_WORD_KEYS);
    if (bindPtr->tagProc == NULL) {
        RbcListAppend(bindIds, (char *) Tk_GetUid("all"), 0);
        RbcListAppend(bindIds, (char *) item, 0);
    } else {
        (*bindPtr->tagProc) (bindPtr, item, context, bindIds);
    }
    nIds = RbcListGetLength(bindIds);
    if (nIds > 0) {
        ClientData     *idArray;
        ClientData      tags[32];
        register RbcListNode *node;

        idArray = tags;
        if (nIds >= 32) {
            idArray = (ClientData *) ckalloc(sizeof(ClientData) * nIds);
        }
        nIds = 0;
        for (node = RbcListFirstNode(bindIds); node != NULL;
            node = RbcListNextNode(node)) {
            idArray[nIds++] = (ClientData) RbcListGetKey(node);
        }
        Tk_BindEvent(bindPtr->bindingTable, eventPtr, bindPtr->tkwin, nIds,
            idArray);
        if (nIds >= 32) {
            ckfree((char *) idArray);
        }
    }
    RbcListDestroy(bindIds);
}

/*
 *--------------------------------------------------------------
 *
 * PickCurrentItem --
 *
 *      Find the topmost item in a legend that contains a given
 *      location and mark the the current item.  If the current
 *      item has changed, generate a fake exit event on the old
 *      current item and a fake enter event on the new current
 *      item.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      The current item may change.  If it does, then the commands
 *      associated with item entry and exit could do just about
 *      anything.  A binding script could delete the legend, so
 *      callers should protect themselves with Tcl_Preserve and
 *      Tcl_Release.
 *
 *--------------------------------------------------------------
 */
static void
PickCurrentItem(
    RbcBindTable * bindPtr,     /* Binding table information. */
    XEvent * eventPtr)
{                               /* Event describing location of
                                 * mouse cursor.  Must be EnterWindow,
                                 * LeaveWindow, ButtonRelease, or
                                 * MotionNotify. */
    int             buttonDown;
    ClientData      newItem;
    ClientData      newContext;

    /*
     * Check whether or not a button is down.  If so, we'll log entry
     * and exit into and out of the current item, but not entry into
     * any other item.  This implements a form of grabbing equivalent
     * to what the X server does for windows.
     */
    buttonDown = (bindPtr->state & ALL_BUTTONS_MASK);
    if (!buttonDown) {
        bindPtr->flags &= ~LEFT_GRABBED_ITEM;
    }

    /*
     * Save information about this event in the widget.  The event in
     * the widget is used for two purposes:
     *
     * 1. Event bindings: if the current item changes, fake events are
     *    generated to allow item-enter and item-leave bindings to trigger.
     * 2. Reselection: if the current item gets deleted, can use the
     *    saved event to find a new current item.
     * Translate MotionNotify events into EnterNotify events, since that's
     * what gets reported to item handlers.
     */

    if (eventPtr != &bindPtr->pickEvent) {
        if ((eventPtr->type == MotionNotify)
            || (eventPtr->type == ButtonRelease)) {
            bindPtr->pickEvent.xcrossing.type = EnterNotify;
            bindPtr->pickEvent.xcrossing.serial = eventPtr->xmotion.serial;
            bindPtr->pickEvent.xcrossing.send_event =
                eventPtr->xmotion.send_event;
            bindPtr->pickEvent.xcrossing.display = eventPtr->xmotion.display;
            bindPtr->pickEvent.xcrossing.window = eventPtr->xmotion.window;
            bindPtr->pickEvent.xcrossing.root = eventPtr->xmotion.root;
            bindPtr->pickEvent.xcrossing.subwindow = None;
            bindPtr->pickEvent.xcrossing.time = eventPtr->xmotion.time;
            bindPtr->pickEvent.xcrossing.x = eventPtr->xmotion.x;
            bindPtr->pickEvent.xcrossing.y = eventPtr->xmotion.y;
            bindPtr->pickEvent.xcrossing.x_root = eventPtr->xmotion.x_root;
            bindPtr->pickEvent.xcrossing.y_root = eventPtr->xmotion.y_root;
            bindPtr->pickEvent.xcrossing.mode = NotifyNormal;
            bindPtr->pickEvent.xcrossing.detail = NotifyNonlinear;
            bindPtr->pickEvent.xcrossing.same_screen =
                eventPtr->xmotion.same_screen;
            bindPtr->pickEvent.xcrossing.focus = False;
            bindPtr->pickEvent.xcrossing.state = eventPtr->xmotion.state;
        } else {
            bindPtr->pickEvent = *eventPtr;
        }
    }
    bindPtr->activePick = TRUE;

    /*
     * If this is a recursive call (there's already a partially completed
     * call pending on the stack;  it's in the middle of processing a
     * Leave event handler for the old current item) then just return;
     * the pending call will do everything that's needed.
     */
    if (bindPtr->flags & REPICK_IN_PROGRESS) {
        return;
    }

    /*
     * A LeaveNotify event automatically means that there's no current
     * item, so the check for closest item can be skipped.
     */
    newContext = NULL;
    if (bindPtr->pickEvent.type != LeaveNotify) {
        int             x, y;

        x = bindPtr->pickEvent.xcrossing.x;
        y = bindPtr->pickEvent.xcrossing.y;
        newItem = (*bindPtr->pickProc) (bindPtr->clientData, x, y, &newContext);
    } else {
        newItem = NULL;
    }

    if (((newItem == bindPtr->currentItem)
            && (newContext == bindPtr->currentContext))
        && (!(bindPtr->flags & LEFT_GRABBED_ITEM))) {
        /*
         * Nothing to do:  the current item hasn't changed.
         */
        return;
    }
#ifndef FULLY_SIMULATE_GRAB
    if (((newItem != bindPtr->currentItem)
            || (newContext != bindPtr->currentContext)) && (buttonDown)) {
        bindPtr->flags |= LEFT_GRABBED_ITEM;
        return;
    }
#endif
    /*
     * Simulate a LeaveNotify event on the previous current item and
     * an EnterNotify event on the new current item.  Remove the "current"
     * tag from the previous current item and place it on the new current
     * item.
     */
    if ((bindPtr->currentItem != NULL) && ((newItem != bindPtr->currentItem)
            || (newContext != bindPtr->currentContext))
        && !(bindPtr->flags & LEFT_GRABBED_ITEM)) {
        XEvent          event;

        event = bindPtr->pickEvent;
        event.type = LeaveNotify;

        /*
         * If the event's detail happens to be NotifyInferior the
         * binding mechanism will discard the event.  To be consistent,
         * always use NotifyAncestor.
         */
        event.xcrossing.detail = NotifyAncestor;

        bindPtr->flags |= REPICK_IN_PROGRESS;
        DoEvent(bindPtr, &event, bindPtr->currentItem, bindPtr->currentContext);
        bindPtr->flags &= ~REPICK_IN_PROGRESS;

        /*
         * Note:  during DoEvent above, it's possible that
         * bindPtr->newItem got reset to NULL because the
         * item was deleted.
         */
    }
    if (((newItem != bindPtr->currentItem)
            || (newContext != bindPtr->currentContext)) && (buttonDown)) {
        XEvent          event;

        bindPtr->flags |= LEFT_GRABBED_ITEM;
        event = bindPtr->pickEvent;
        if ((newItem != bindPtr->newItem)
            || (newContext != bindPtr->newContext)) {
            ClientData      savedItem;
            ClientData      savedContext;

            /*
             * Generate <Enter> and <Leave> events for objects during
             * button grabs.  This isn't standard. But for example, it
             * allows one to provide balloon help on the individual
             * entries of the Hierbox widget.
             */
            savedItem = bindPtr->currentItem;
            savedContext = bindPtr->currentContext;
            if (bindPtr->newItem != NULL) {
                event.type = LeaveNotify;
                event.xcrossing.detail = NotifyVirtual /* Ancestor */ ;
                bindPtr->currentItem = bindPtr->newItem;
                DoEvent(bindPtr, &event, bindPtr->newItem, bindPtr->newContext);
            }
            bindPtr->newItem = newItem;
            bindPtr->newContext = newContext;
            if (newItem != NULL) {
                event.type = EnterNotify;
                event.xcrossing.detail = NotifyVirtual /* Ancestor */ ;
                bindPtr->currentItem = newItem;
                DoEvent(bindPtr, &event, newItem, newContext);
            }
            bindPtr->currentItem = savedItem;
            bindPtr->currentContext = savedContext;
        }
        return;
    }
    /*
     * Special note:  it's possible that
     *   bindPtr->newItem == bindPtr->currentItem
     * here.  This can happen, for example, if LEFT_GRABBED_ITEM was set.
     */

    bindPtr->flags &= ~LEFT_GRABBED_ITEM;
    bindPtr->currentItem = bindPtr->newItem = newItem;
    bindPtr->currentContext = bindPtr->newContext = newContext;
    if (bindPtr->currentItem != NULL) {
        XEvent          event;

        event = bindPtr->pickEvent;
        event.type = EnterNotify;
        event.xcrossing.detail = NotifyAncestor;
        DoEvent(bindPtr, &event, newItem, newContext);
    }
}

/*
 *--------------------------------------------------------------
 *
 * BindProc --
 *
 *      This procedure is invoked by the Tk dispatcher to handle
 *      events associated with bindings on items.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Depends on the command invoked as part of the binding
 *      (if there was any).
 *
 *--------------------------------------------------------------
 */
static void
BindProc(
    ClientData clientData,      /* Pointer to widget structure. */
    XEvent * eventPtr)
{                               /* Pointer to X event that just
                                 * happened. */
    RbcBindTable   *bindPtr = clientData;
    int             mask;

    Tcl_Preserve(bindPtr->clientData);

    /*
     * This code below keeps track of the current modifier state in
     * bindPtr->state.  This information is used to defer repicks of
     * the current item while buttons are down.
     */
    switch (eventPtr->type) {
    case ButtonPress:
    case ButtonRelease:
        mask = 0;
        if ((eventPtr->xbutton.button >= Button1)
            && (eventPtr->xbutton.button <= Button5)) {
            mask = buttonMasks[eventPtr->xbutton.button];
        }

        /*
         * For button press events, repick the current item using the
         * button state before the event, then process the event.  For
         * button release events, first process the event, then repick
         * the current item using the button state *after* the event
         * (the button has logically gone up before we change the
         * current item).
         */
        if (eventPtr->type == ButtonPress) {
            /*
             * On a button press, first repick the current item using
             * the button state before the event, the process the event.
             */
            bindPtr->state = eventPtr->xbutton.state;
            PickCurrentItem(bindPtr, eventPtr);
            bindPtr->state ^= mask;
            DoEvent(bindPtr, eventPtr, bindPtr->currentItem,
                bindPtr->currentContext);
        } else {
            /*
             * Button release: first process the event, with the button
             * still considered to be down.  Then repick the current
             * item under the assumption that the button is no longer down.
             */
            bindPtr->state = eventPtr->xbutton.state;
            DoEvent(bindPtr, eventPtr, bindPtr->currentItem,
                bindPtr->currentContext);
            eventPtr->xbutton.state ^= mask;
            bindPtr->state = eventPtr->xbutton.state;
            PickCurrentItem(bindPtr, eventPtr);
            eventPtr->xbutton.state ^= mask;
        }
        break;

    case EnterNotify:
    case LeaveNotify:
        bindPtr->state = eventPtr->xcrossing.state;
        PickCurrentItem(bindPtr, eventPtr);
        break;

    case MotionNotify:
        bindPtr->state = eventPtr->xmotion.state;
        PickCurrentItem(bindPtr, eventPtr);
        DoEvent(bindPtr, eventPtr, bindPtr->currentItem,
            bindPtr->currentContext);
        break;

    case KeyPress:
    case KeyRelease:
        bindPtr->state = eventPtr->xkey.state;
        PickCurrentItem(bindPtr, eventPtr);
        DoEvent(bindPtr, eventPtr, bindPtr->currentItem,
            bindPtr->currentContext);
        break;
    }
    Tcl_Release(bindPtr->clientData);
}

/*
 *--------------------------------------------------------------
 *
 * RbcConfigureBindings --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcConfigureBindings(
    Tcl_Interp * interp,
    RbcBindTable * bindPtr,
    ClientData item,
    int argc,
    const char **argv)
{
    const char     *command;
    unsigned long   mask;
    const char     *seq;

    if (argc == 0) {
        Tk_GetAllBindings(interp, bindPtr->bindingTable, item);
        return TCL_OK;
    }
    if (argc == 1) {
        command = Tk_GetBinding(interp, bindPtr->bindingTable, item, argv[0]);
        if (command == NULL) {
            return TCL_ERROR;
        }
        Tcl_SetObjResult(interp, Tcl_NewStringObj(command, -1));
        return TCL_OK;
    }

    seq = argv[0];
    command = argv[1];

    if (command[0] == '\0') {
        return Tk_DeleteBinding(interp, bindPtr->bindingTable, item, seq);
    }

    if (command[0] == '+') {
        mask =
            Tk_CreateBinding(interp, bindPtr->bindingTable, item, seq,
            command + 1, TRUE);
    } else {
        mask =
            Tk_CreateBinding(interp, bindPtr->bindingTable, item, seq, command,
            FALSE);
    }
    if (mask == 0) {
        return TCL_ERROR;
    }
    if (mask & (unsigned) ~ALL_VALID_EVENTS_MASK) {
        Tk_DeleteBinding(interp, bindPtr->bindingTable, item, seq);
        Tcl_ResetResult(interp);
        Tcl_AppendResult(interp, "requested illegal events; ",
            "only key, button, motion, enter, leave, and virtual ",
            "events may be used", (char *) NULL);
        return TCL_ERROR;
    }
    return TCL_OK;
}

#if (TCL_MAJOR_VERSION >= 8)

/*
 *--------------------------------------------------------------
 *
 * RbcConfigureBindingsFromObj --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcConfigureBindingsFromObj(
    Tcl_Interp * interp,
    RbcBindTable * bindPtr,
    ClientData item,
    int objc,
    Tcl_Obj * const *objv)
{
    const char     *command;
    unsigned long   mask;
    char           *seq;
    char           *string;

    if (objc == 0) {
        Tk_GetAllBindings(interp, bindPtr->bindingTable, item);
        return TCL_OK;
    }
    string = Tcl_GetString(objv[0]);
    if (objc == 1) {
        command = Tk_GetBinding(interp, bindPtr->bindingTable, item, string);
        if (command == NULL) {
            Tcl_ResetResult(interp);
            Tcl_AppendResult(interp, "invalid binding event \"", string, "\"",
                (char *) NULL);
            return TCL_ERROR;
        }
        Tcl_SetObjResult(interp, Tcl_NewStringObj(command, -1));
        return TCL_OK;
    }

    seq = string;
    command = Tcl_GetString(objv[1]);

    if (command[0] == '\0') {
        return Tk_DeleteBinding(interp, bindPtr->bindingTable, item, seq);
    }

    if (command[0] == '+') {
        mask =
            Tk_CreateBinding(interp, bindPtr->bindingTable, item, seq,
            command + 1, TRUE);
    } else {
        mask =
            Tk_CreateBinding(interp, bindPtr->bindingTable, item, seq, command,
            FALSE);
    }
    if (mask == 0) {
        return TCL_ERROR;
    }
    if (mask & (unsigned) ~ALL_VALID_EVENTS_MASK) {
        Tk_DeleteBinding(interp, bindPtr->bindingTable, item, seq);
        Tcl_ResetResult(interp);
        Tcl_AppendResult(interp, "requested illegal events; ",
            "only key, button, motion, enter, leave, and virtual ",
            "events may be used", (char *) NULL);
        return TCL_ERROR;
    }
    return TCL_OK;
}
#endif

/*
 *--------------------------------------------------------------
 *
 * RbcCreateBindingTable --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
RbcBindTable   *
RbcCreateBindingTable(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    ClientData clientData,
    RbcBindPickProc * pickProc,
    RbcBindTagProc * tagProc)
{
    unsigned int    mask;
    RbcBindTable   *bindPtr;

    bindPtr = RbcCalloc(1, sizeof(RbcBindTable));
    assert(bindPtr);
    bindPtr->clientData = clientData;
    bindPtr->pickProc = pickProc;
    bindPtr->tagProc = tagProc;
    bindPtr->tkwin = tkwin;
    bindPtr->bindingTable = Tk_CreateBindingTable(interp);
    mask =
        (KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
        EnterWindowMask | LeaveWindowMask | PointerMotionMask);
    Tk_CreateEventHandler(tkwin, mask, BindProc, bindPtr);
    return bindPtr;
}

/*
 *--------------------------------------------------------------
 *
 * RbcDestroyBindingTable --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcDestroyBindingTable(
    RbcBindTable * bindPtr)
{
    unsigned int    mask;

    Tk_DeleteBindingTable(bindPtr->bindingTable);
    mask =
        (KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
        EnterWindowMask | LeaveWindowMask | PointerMotionMask);
    Tk_DeleteEventHandler(bindPtr->tkwin, mask, BindProc, bindPtr);
    ckfree((char *) bindPtr);
}

/*
 *--------------------------------------------------------------
 *
 * RbcPickCurrentItem --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcPickCurrentItem(
    RbcBindTable * bindPtr)
{
    if (bindPtr->activePick) {
        PickCurrentItem(bindPtr, &(bindPtr->pickEvent));
    }
}

/*
 *--------------------------------------------------------------
 *
 * RbcDeleteBindings --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcDeleteBindings(
    RbcBindTable * bindPtr,
    ClientData object)
{
    Tk_DeleteAllBindings(bindPtr->bindingTable, object);

    /*
     * If this is the object currently picked, we need to repick one.
     */
    if (bindPtr->currentItem == object) {
        bindPtr->currentItem = NULL;
        bindPtr->currentContext = NULL;
    }
    if (bindPtr->newItem == object) {
        bindPtr->newItem = NULL;
        bindPtr->newContext = NULL;
    }
    if (bindPtr->focusItem == object) {
        bindPtr->focusItem = NULL;
        bindPtr->focusContext = NULL;
    }
}

/*
 *--------------------------------------------------------------
 *
 * RbcMoveBindingTable --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
void
RbcMoveBindingTable(
    RbcBindTable * bindPtr,
    Tk_Window tkwin)
{
    unsigned int    mask;

    mask =
        (KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
        EnterWindowMask | LeaveWindowMask | PointerMotionMask);
    if (bindPtr->tkwin != NULL) {
        Tk_DeleteEventHandler(bindPtr->tkwin, mask, BindProc, bindPtr);
    }
    Tk_CreateEventHandler(tkwin, mask, BindProc, bindPtr);
    bindPtr->tkwin = tkwin;
}

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

Added generic/rbc/rbcChain.c.


















































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
/*
 * rbcChain.c --
 *
 * The module implements a generic linked list package.
 *
 * 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"

#ifndef ALIGN
#define ALIGN(a) \
    (((size_t)a + (sizeof(double) - 1)) & (~(sizeof(double) - 1)))
#endif /* ALIGN */

/*
 *----------------------------------------------------------------------
 *
 * RbcChainCreate --
 *
 *      Creates a new linked list (chain) structure and initializes
 *      its pointers;
 *
 * Results:
 *      Returns a pointer to the newly created chain structure.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
RbcChain       *
RbcChainCreate(
    )
{
    RbcChain       *chainPtr;

    chainPtr = (RbcChain *) ckalloc(sizeof(RbcChain));
    if (chainPtr != NULL) {
        RbcChainInit(chainPtr);
    }
    return chainPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainInit --
 *
 *      Initializes a linked list.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcChainInit(
    RbcChain * chainPtr)
{                               /* The chain to initialize */
    chainPtr->nLinks = 0;
    chainPtr->headPtr = chainPtr->tailPtr = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainLinkAfter --
 *
 *      Inserts an entry following a given entry.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcChainLinkAfter(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr,
    RbcChainLink * afterPtr)
{
    if (chainPtr->headPtr == NULL) {
        chainPtr->tailPtr = chainPtr->headPtr = linkPtr;
    } else {
        if (afterPtr == NULL) {
            /* Prepend to the front of the chain */
            linkPtr->nextPtr = chainPtr->headPtr;
            linkPtr->prevPtr = NULL;
            chainPtr->headPtr->prevPtr = linkPtr;
            chainPtr->headPtr = linkPtr;
        } else {
            linkPtr->nextPtr = afterPtr->nextPtr;
            linkPtr->prevPtr = afterPtr;
            if (afterPtr == chainPtr->tailPtr) {
                chainPtr->tailPtr = linkPtr;
            } else {
                afterPtr->nextPtr->prevPtr = linkPtr;
            }
            afterPtr->nextPtr = linkPtr;
        }
    }
    chainPtr->nLinks++;
}

/*----------------------------------------------------------------------
 *
 * RbcChainLinkBefore --
 *
 *      Inserts a link preceding a given link.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcChainLinkBefore(
    RbcChain * chainPtr,        /* Chain to contain new entry */
    RbcChainLink * linkPtr,     /* New entry to be inserted */
    RbcChainLink * beforePtr)
{                               /* Entry to link before */
    if (chainPtr->headPtr == NULL) {
        chainPtr->tailPtr = chainPtr->headPtr = linkPtr;
    } else {
        if (beforePtr == NULL) {
            /* Append to the end of the chain. */
            linkPtr->nextPtr = NULL;
            linkPtr->prevPtr = chainPtr->tailPtr;
            chainPtr->tailPtr->nextPtr = linkPtr;
            chainPtr->tailPtr = linkPtr;
        } else {
            linkPtr->prevPtr = beforePtr->prevPtr;
            linkPtr->nextPtr = beforePtr;
            if (beforePtr == chainPtr->headPtr) {
                chainPtr->headPtr = linkPtr;
            } else {
                beforePtr->prevPtr->nextPtr = linkPtr;
            }
            beforePtr->prevPtr = linkPtr;
        }
    }
    chainPtr->nLinks++;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainNewLink --
 *
 *      Creates a new link.
 *
 * Results:
 *      The return value is the pointer to the newly created link.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
RbcChainLink   *
RbcChainNewLink(
    )
{
    RbcChainLink   *linkPtr;

    linkPtr = (RbcChainLink *) ckalloc(sizeof(RbcChainLink));
    assert(linkPtr);
    linkPtr->clientData = NULL;
    linkPtr->nextPtr = linkPtr->prevPtr = NULL;
    return linkPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainReset --
 *
 *      Removes all the links from the chain, freeing the memory for
 *      each link.  Memory pointed to by the link (clientData) is not
 *      freed.  It's the caller's responsibility to deallocate it.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcChainReset(
    RbcChain * chainPtr)
{                               /* Chain to clear */
    if (chainPtr != NULL) {
        RbcChainLink   *oldPtr;
        RbcChainLink   *linkPtr = chainPtr->headPtr;

        while (linkPtr != NULL) {
            oldPtr = linkPtr;
            linkPtr = linkPtr->nextPtr;
            ckfree((char *) oldPtr);
        }
        RbcChainInit(chainPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainDestroy
 *
 *      Frees all the nodes from the chain and deallocates the memory
 *      allocated for the chain structure itself.  It's assumed that
 *      the chain was previous allocated by RbcChainCreate.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
void
RbcChainDestroy(
    RbcChain * chainPtr)
{                               /* The chain to destroy. */
    if (chainPtr != NULL) {
        RbcChainReset(chainPtr);
        ckfree((char *) chainPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainUnlinkLink --
 *
 *      Unlinks a link from the chain. The link is not deallocated,
 *      but only removed from the chain.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcChainUnlinkLink(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr)
{
    /* Indicates if the link is actually removed from the chain. */
    int             unlinked;

    unlinked = FALSE;
    if (chainPtr->headPtr == linkPtr) {
        chainPtr->headPtr = linkPtr->nextPtr;
        unlinked = TRUE;
    }
    if (chainPtr->tailPtr == linkPtr) {
        chainPtr->tailPtr = linkPtr->prevPtr;
        unlinked = TRUE;
    }
    if (linkPtr->nextPtr != NULL) {
        linkPtr->nextPtr->prevPtr = linkPtr->prevPtr;
        unlinked = TRUE;
    }
    if (linkPtr->prevPtr != NULL) {
        linkPtr->prevPtr->nextPtr = linkPtr->nextPtr;
        unlinked = TRUE;
    }
    if (unlinked) {
        chainPtr->nLinks--;
    }
    linkPtr->prevPtr = linkPtr->nextPtr = NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainDeleteLink --
 *
 *      Unlinks and also frees the given link.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcChainDeleteLink(
    RbcChain * chainPtr,
    RbcChainLink * linkPtr)
{
    RbcChainUnlinkLink(chainPtr, linkPtr);
    ckfree((char *) linkPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainAppend --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
RbcChainLink   *
RbcChainAppend(
    RbcChain * chainPtr,
    ClientData clientData)
{
    RbcChainLink   *linkPtr;

    linkPtr = RbcChainNewLink();
    RbcChainLinkBefore(chainPtr, linkPtr, (RbcChainLink *) NULL);
    RbcChainSetValue(linkPtr, clientData);
    return linkPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainPrepend --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
RbcChainLink   *
RbcChainPrepend(
    RbcChain * chainPtr,
    ClientData clientData)
{
    RbcChainLink   *linkPtr;

    linkPtr = RbcChainNewLink();
    RbcChainLinkAfter(chainPtr, linkPtr, (RbcChainLink *) NULL);
    RbcChainSetValue(linkPtr, clientData);
    return linkPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcChainAllocLink --
 *
 *      Creates a new chain link.  Unlink RbcChainNewLink, this
 *      routine also allocates extra memory in the node for data.
 *
 * Results:
 *      The return value is the pointer to the newly created entry.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
RbcChainLink   *
RbcChainAllocLink(
    unsigned int extraSize)
{
    RbcChainLink   *linkPtr;
    unsigned int    linkSize;

    linkSize = ALIGN(sizeof(RbcChainLink));
    linkPtr = RbcCalloc(1, linkSize + extraSize);
    assert(linkPtr);
    if (extraSize > 0) {
        /* Point clientData at the memory beyond the normal structure. */
        linkPtr->clientData = (ClientData) ((char *) linkPtr + linkSize);
    }
    return linkPtr;
}

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

Added generic/rbc/rbcConfig.c.


































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
/*
 * rbcConfig.c --
 *
 *      This module implements custom configuration options for the rbc
 *      toolkit.
 *
 * 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"

#define PIXELS_NONNEGATIVE	0
#define PIXELS_POSITIVE		1
#define PIXELS_ANY		2

#define COUNT_NONNEGATIVE	0
#define COUNT_POSITIVE		1
#define COUNT_ANY		2

/*
 * ----------------------------------------------------------------------
 *
 * The following enumerated values are used as bit flags.
 *	FILL_NONE		Neither coordinate plane is specified
 *	FILL_X			Horizontal plane.
 *	FILL_Y			Vertical plane.
 *	FILL_BOTH		Both vertical and horizontal planes.
 *
 * ----------------------------------------------------------------------
 */
#define FILL_NONE	0
#define FILL_X		1
#define FILL_Y		2
#define FILL_BOTH	3

static int      StringToFill(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *FillToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcFillOption = {
    StringToFill, FillToString, (ClientData) 0
};

static int      StringToPad(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int offset);
static const char *PadToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcPadOption = {
    StringToPad, PadToString, (ClientData) 0
};

static int      StringToDistance(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *DistanceToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcDistanceOption = {
    StringToDistance, DistanceToString, (ClientData) PIXELS_NONNEGATIVE
};

Tk_CustomOption rbcPositiveDistanceOption = {
    StringToDistance, DistanceToString, (ClientData) PIXELS_POSITIVE
};

Tk_CustomOption rbcAnyDistanceOption = {
    StringToDistance, DistanceToString, (ClientData) PIXELS_ANY
};

static int      StringToCount(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *CountToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcCountOption = {
    StringToCount, CountToString, (ClientData) COUNT_NONNEGATIVE
};

Tk_CustomOption rbcPositiveCountOption = {
    StringToCount, CountToString, (ClientData) COUNT_POSITIVE
};

static int      StringToDashes(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *DashesToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcDashesOption = {
    StringToDashes, DashesToString, (ClientData) 0
};

static int      StringToShadow(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *ShadowToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcShadowOption = {
    StringToShadow, ShadowToString, (ClientData) 0
};

static int      StringToUid(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *UidToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcUidOption = {
    StringToUid, UidToString, (ClientData) 0
};

static int      StringToState(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *StateToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcStateOption = {
    StringToState, StateToString, (ClientData) 0
};

static int      StringToList(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *ListToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcListOption = {
    StringToList, ListToString, (ClientData) 0
};

static int      StringToTile(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *value,
    char *widgRec,
    int flags);
static const char *TileToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcTileOption = {
    StringToTile, TileToString, (ClientData) 0
};

static int      GetInt(
    Tcl_Interp * interp,
    const char *string,
    int check,
    int *valuePtr);

/*
 *----------------------------------------------------------------------
 *
 * StringToFill --
 *
 *      Converts the fill style string into its numeric representation.
 *
 *      Valid style strings are:
 *
 *         "none"   Use neither plane.
 *         "x"      X-coordinate plane.
 *         "y"	    Y-coordinate plane.
 *         "both"   Use both coordinate planes.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToFill(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* Fill style string */
    char *widgRec,              /* Cubicle structure record */
    int offset)
{                               /* Offset of style in record */
    int            *fillPtr = (int *) (widgRec + offset);
    unsigned int    length;
    char            c;

    c = string[0];
    length = strlen(string);
    if ((c == 'n') && (strncmp(string, "none", length) == 0)) {
        *fillPtr = FILL_NONE;
    } else if ((c == 'x') && (strncmp(string, "x", length) == 0)) {
        *fillPtr = FILL_X;
    } else if ((c == 'y') && (strncmp(string, "y", length) == 0)) {
        *fillPtr = FILL_Y;
    } else if ((c == 'b') && (strncmp(string, "both", length) == 0)) {
        *fillPtr = FILL_BOTH;
    } else {
        Tcl_AppendResult(interp, "bad argument \"", string,
            "\": should be \"none\", \"x\", \"y\", or \"both\"", (char *) NULL);
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * FillToString --
 *
 *      Returns the fill style string based upon the fill flags.
 *
 * Results:
 *      The fill style string is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
FillToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget structure record */
    int offset,                 /* Offset of fill in widget record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    int             fill = *(int *) (widgRec + offset);

    switch (fill) {
    case FILL_X:
        return "x";
    case FILL_Y:
        return "y";
    case FILL_NONE:
        return "none";
    case FILL_BOTH:
        return "both";
    default:
        return "unknown value";
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGetPixels --
 *
 *      Like Tk_GetPixels, but checks for negative, zero.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
int
RbcGetPixels(
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    int check,                  /* Can be PIXELS_POSITIVE, PIXELS_NONNEGATIVE,
                                 * or PIXELS_ANY, */
    int *valuePtr)
{
    int             length;

    if (Tk_GetPixels(interp, tkwin, string, &length) != TCL_OK) {
        return TCL_ERROR;
    }
    if (length >= SHRT_MAX) {
        Tcl_AppendResult(interp, "bad distance \"", string, "\": ",
            "too big to represent", (char *) NULL);
        return TCL_ERROR;
    }
    switch (check) {
    case PIXELS_NONNEGATIVE:
        if (length < 0) {
            Tcl_AppendResult(interp, "bad distance \"", string, "\": ",
                "can't be negative", (char *) NULL);
            return TCL_ERROR;
        }
        break;
    case PIXELS_POSITIVE:
        if (length <= 0) {
            Tcl_AppendResult(interp, "bad distance \"", string, "\": ",
                "must be positive", (char *) NULL);
            return TCL_ERROR;
        }
        break;
    case PIXELS_ANY:
        break;
    }
    *valuePtr = length;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToDistance --
 *
 *      Like TK_CONFIG_PIXELS, but adds an extra check for negative
 *      values.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToDistance(
    ClientData clientData,      /* Indicated how to check distance */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Window */
    const char *string,         /* Pixel value string */
    char *widgRec,              /* Widget record */
    int offset)
{                               /* Offset of pixel size in record */
    int            *valuePtr = (int *) (widgRec + offset);
    return RbcGetPixels(interp, tkwin, string, (int) clientData, valuePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * DistanceToString --
 *
 *      Returns the string representing the positive pixel size.
 *
 * Results:
 *      The pixel size string is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
DistanceToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget structure record */
    int offset,                 /* Offset in widget record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    int             value = *(int *) (widgRec + offset);
    char           *result;

    result = RbcStrdup(RbcItoa(value));
    assert(result);
    *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * GetInt --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
GetInt(
    Tcl_Interp * interp,
    const char *string,
    int check,                  /* Can be COUNT_POSITIVE, COUNT_NONNEGATIVE,
                                 * or COUNT_ANY, */
    int *valuePtr)
{
    int             count;

    if (Tcl_GetInt(interp, string, &count) != TCL_OK) {
        return TCL_ERROR;
    }
    switch (check) {
    case COUNT_NONNEGATIVE:
        if (count < 0) {
            Tcl_AppendResult(interp, "bad value \"", string, "\": ",
                "can't be negative", (char *) NULL);
            return TCL_ERROR;
        }
        break;
    case COUNT_POSITIVE:
        if (count <= 0) {
            Tcl_AppendResult(interp, "bad value \"", string, "\": ",
                "must be positive", (char *) NULL);
            return TCL_ERROR;
        }
        break;
    case COUNT_ANY:
        break;
    }
    *valuePtr = count;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToCount --
 *
 *      Like TK_CONFIG_PIXELS, but adds an extra check for negative
 *      values.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToCount(
    ClientData clientData,      /* Indicated how to check distance */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* Pixel value string */
    char *widgRec,              /* Widget record */
    int offset)
{                               /* Offset of pixel size in record */
    int            *valuePtr = (int *) (widgRec + offset);
    return GetInt(interp, string, (int) clientData, valuePtr);
}

/*
 *----------------------------------------------------------------------
 *
 * CountToString --
 *
 *      Returns the string representing the positive pixel size.
 *
 * Results:
 *      The pixel size string is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
CountToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget structure record */
    int offset,                 /* Offset in widget record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    int             value = *(int *) (widgRec + offset);
    char           *result;

    result = RbcStrdup(RbcItoa(value));
    assert(result);
    *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToPad --
 *
 *      Convert a string into two pad values.  The string may be in one of
 *      the following forms:
 *
 *          n      - n is a non-negative integer. This sets both
 *                   pad values to n.
 *          {n m}  - both n and m are non-negative integers. side1
 *                   is set to n, side2 is set to m.
 *
 * Results:
 *      If the string is successfully converted, TCL_OK is returned.
 *      Otherwise, TCL_ERROR is returned and an error message is left in
 *      interp->result.
 *
 * Side Effects:
 *      The padding structure passed is updated with the new values.
 *
 *----------------------------------------------------------------------
 */
static int
StringToPad(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Window */
    const char *string,         /* Pixel value string */
    char *widgRec,              /* Widget record */
    int offset)
{                               /* Offset of pad in widget */
    RbcPad         *padPtr = (RbcPad *) (widgRec + offset);
    int             nElem;
    int             pad, result;
    const char    **padArr;

    if (Tcl_SplitList(interp, string, &nElem, &padArr) != TCL_OK) {
        return TCL_ERROR;
    }
    result = TCL_ERROR;
    if ((nElem < 1) || (nElem > 2)) {
        Tcl_AppendResult(interp, "wrong # elements in padding list",
            (char *) NULL);
        goto error;
    }
    if (RbcGetPixels(interp, tkwin, padArr[0], PIXELS_NONNEGATIVE,
            &pad) != TCL_OK) {
        goto error;
    }
    padPtr->side1 = pad;
    if ((nElem > 1)
        && (RbcGetPixels(interp, tkwin, padArr[1], PIXELS_NONNEGATIVE,
                &pad) != TCL_OK)) {
        goto error;
    }
    padPtr->side2 = pad;
    result = TCL_OK;

  error:
    ckfree((char *) padArr);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * PadToString --
 *
 *     Converts the two pad values into a Tcl list.  Each pad has two
 *     pixel values.  For vertical pads, they represent the top and bottom
 *     margins.  For horizontal pads, they're the left and right margins.
 *     All pad values are non-negative integers.
 *
 * Results:
 *     The padding list is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
PadToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Structure record */
    int offset,                 /* Offset of pad in record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    RbcPad         *padPtr = (RbcPad *) (widgRec + offset);
    char           *result;
    char            string[200];

    sprintf(string, "%d %d", padPtr->side1, padPtr->side2);
    result = RbcStrdup(string);
    if (result == NULL) {
        return "out of memory";
    }
    *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToShadow --
 *
 *      Convert a string into two pad values.  The string may be in one of
 *      the following forms:
 *
 *          n      - n is a non-negative integer. This sets both
 *                   pad values to n.
 *          {n m}  - both n and m are non-negative integers. side1
 *                   is set to n, side2 is set to m.
 *
 * Results:
 *      If the string is successfully converted, TCL_OK is returned.
 *      Otherwise, TCL_ERROR is returned and an error message is left in
 *      interp->result.
 *
 * Side Effects:
 *      The padding structure passed is updated with the new values.
 *
 *----------------------------------------------------------------------
 */
static int
StringToShadow(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Window */
    const char *string,         /* Pixel value string */
    char *widgRec,              /* Widget record */
    int offset)
{                               /* Offset of pad in widget */
    RbcShadow      *shadowPtr = (RbcShadow *) (widgRec + offset);
    XColor         *colorPtr;
    int             dropOffset;

    colorPtr = NULL;
    dropOffset = 0;
    if ((string != NULL) && (string[0] != '\0')) {
        int             nElem;
        const char    **elemArr;

        if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
            return TCL_ERROR;
        }
        if ((nElem < 1) || (nElem > 2)) {
            Tcl_AppendResult(interp, "wrong # elements in drop shadow value",
                (char *) NULL);
            ckfree((char *) elemArr);
            return TCL_ERROR;
        }
        colorPtr = Tk_GetColor(interp, tkwin, Tk_GetUid(elemArr[0]));
        if (colorPtr == NULL) {
            ckfree((char *) elemArr);
            return TCL_ERROR;
        }
        dropOffset = 1;
        if (nElem == 2) {
            if (RbcGetPixels(interp, tkwin, elemArr[1], PIXELS_NONNEGATIVE,
                    &dropOffset) != TCL_OK) {
                Tk_FreeColor(colorPtr);
                ckfree((char *) elemArr);
                return TCL_ERROR;
            }
        }
        ckfree((char *) elemArr);
    }
    if (shadowPtr->color != NULL) {
        Tk_FreeColor(shadowPtr->color);
    }
    shadowPtr->color = colorPtr;
    shadowPtr->offset = dropOffset;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ShadowToString --
 *
 *      Converts the two pad values into a Tcl list.  Each pad has two
 *      pixel values.  For vertical pads, they represent the top and bottom
 *      margins.  For horizontal pads, they're the left and right margins.
 *      All pad values are non-negative integers.
 *
 * Results:
 *      The padding list is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
ShadowToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Structure record */
    int offset,                 /* Offset of pad in record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    RbcShadow      *shadowPtr = (RbcShadow *) (widgRec + offset);
    const char     *result;

    result = "";
    if (shadowPtr->color != NULL) {
        char            string[200];

        sprintf(string, "%s %d", Tk_NameOfColor(shadowPtr->color),
            shadowPtr->offset);
        result = RbcStrdup(string);
        *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * GetDashes --
 *
 *      Converts a Tcl list of dash values into a dash list ready for
 *      use with XSetDashes.
 *
 *      A valid list dash values can have zero through 11 elements
 *      (PostScript limit).  Values must be between 1 and 255. Although
 *      a list of 0 (like the empty string) means no dashes.
 *
 * Results:
 *      A standard Tcl result. If the list represented a valid dash
 *      list TCL_OK is returned and *dashesPtr* will contain the
 *      valid dash list. Otherwise, TCL_ERROR is returned and
 *      interp->result will contain an error message.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
GetDashes(
    Tcl_Interp * interp,
    const char *string,
    RbcDashes * dashesPtr)
{
    if ((string == NULL) || (*string == '\0')) {
        dashesPtr->values[0] = 0;
    } else if (strcmp(string, "dash") == 0) {
        dashesPtr->values[0] = 5;
        dashesPtr->values[1] = 2;
        dashesPtr->values[2] = 0;
    } else if (strcmp(string, "dot") == 0) {
        dashesPtr->values[0] = 1;
        dashesPtr->values[1] = 0;
    } else if (strcmp(string, "dashdot") == 0) {
        dashesPtr->values[0] = 2;
        dashesPtr->values[1] = 4;
        dashesPtr->values[2] = 2;
        dashesPtr->values[3] = 0;
    } else if (strcmp(string, "dashdotdot") == 0) {
        dashesPtr->values[0] = 2;
        dashesPtr->values[1] = 4;
        dashesPtr->values[2] = 2;
        dashesPtr->values[3] = 2;
        dashesPtr->values[4] = 0;
    } else {
        int             nValues;
        const char    **strArr;
        long int        value;
        register int    i;

        if (Tcl_SplitList(interp, string, &nValues, &strArr) != TCL_OK) {
            return TCL_ERROR;
        }
        if (nValues > 11) {
            /* This is the postscript limit */
            Tcl_AppendResult(interp, "too many values in dash list \"", string,
                "\"", (char *) NULL);
            ckfree((char *) strArr);
            return TCL_ERROR;
        }
        for (i = 0; i < nValues; i++) {
            if (Tcl_ExprLong(interp, strArr[i], &value) != TCL_OK) {
                ckfree((char *) strArr);
                return TCL_ERROR;
            }
            /*
             * Backward compatibility:
             * Allow list of 0 to turn off dashes
             */
            if ((value == 0) && (nValues == 1)) {
                break;
            }
            if ((value < 1) || (value > 255)) {
                Tcl_AppendResult(interp, "dash value \"", strArr[i],
                    "\" is out of range", (char *) NULL);
                ckfree((char *) strArr);
                return TCL_ERROR;
            }
            dashesPtr->values[i] = (unsigned char) value;
        }
        /* Make sure the array ends with a NUL byte  */
        dashesPtr->values[i] = 0;
        ckfree((char *) strArr);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToDashes --
 *
 *      Convert the list of dash values into a dashes array.
 *
 * Results:
 *      The return value is a standard Tcl result.
 *
 * Side Effects:
 *      The Dashes structure is updated with the new dash list.
 *
 *----------------------------------------------------------------------
 */
static int
StringToDashes(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* New dash value list */
    char *widgRec,              /* Widget record */
    int offset)
{                               /* offset to Dashes structure */
    RbcDashes      *dashesPtr = (RbcDashes *) (widgRec + offset);

    return GetDashes(interp, string, dashesPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * DashesToString --
 *
 *      Convert the dashes array into a list of values.
 *
 * Results:
 *      The string representing the dashes returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
DashesToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget record */
    int offset,                 /* offset of Dashes in record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Memory deallocation scheme to use */
    RbcDashes      *dashesPtr = (RbcDashes *) (widgRec + offset);
    Tcl_DString     dString;
    char           *p;
    char           *result;

    if (dashesPtr->values[0] == 0) {
        return "";
    }
    Tcl_DStringInit(&dString);
    for (p = dashesPtr->values; *p != 0; p++) {
        Tcl_DStringAppendElement(&dString, RbcItoa(*p));
    }
    result = Tcl_DStringValue(&dString);
    if (result == dString.staticSpace) {
        result = RbcStrdup(result);
    }
    *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToUid --
 *
 *      Converts the string to a RbcUid. RbcUid's are hashed, reference
 *      counted strings.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToUid(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* Fill style string */
    char *widgRec,              /* Cubicle structure record */
    int offset)
{                               /* Offset of style in record */
    RbcUid         *uidPtr = (RbcUid *) (widgRec + offset);
    RbcUid          newId;

    newId = NULL;
    if ((string != NULL) && (*string != '\0')) {
        newId = RbcGetUid(string);
    }
    if (*uidPtr != NULL) {
        RbcFreeUid(*uidPtr);
    }
    *uidPtr = newId;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * UidToString --
 *
 *      Returns the fill style string based upon the fill flags.
 *
 * Results:
 *      The fill style string is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
UidToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget structure record */
    int offset,                 /* Offset of fill in widget record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    RbcUid          uid = *(RbcUid *) (widgRec + offset);

    return (uid == NULL) ? "" : uid;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToState --
 *
 *      Converts the string to a state value. Valid states are
 *      disabled, normal.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToState(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* String representation of option value */
    char *widgRec,              /* Widget structure record */
    int offset)
{                               /* Offset of field in record */
    int            *statePtr = (int *) (widgRec + offset);

    if (strcmp(string, "normal") == 0) {
        *statePtr = RBC_STATE_NORMAL;
    } else if (strcmp(string, "disabled") == 0) {
        *statePtr = RBC_STATE_DISABLED;
    } else if (strcmp(string, "active") == 0) {
        *statePtr = RBC_STATE_ACTIVE;
    } else {
        Tcl_AppendResult(interp, "bad state \"", string,
            "\": should be normal, active, or disabled", (char *) NULL);
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * StateToString --
 *
 *      Returns the string representation of the state configuration field
 *
 * Results:
 *      The string is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
StateToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget structure record */
    int offset,                 /* Offset of fill in widget record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    int             state = *(int *) (widgRec + offset);

    switch (state) {
    case RBC_STATE_ACTIVE:
        return "active";
    case RBC_STATE_DISABLED:
        return "disabled";
    case RBC_STATE_NORMAL:
        return "normal";
    default:
        return "???";
    }
}

/*
 *----------------------------------------------------------------------
 *
 * StringToList --
 *
 *      Converts the string to a list.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToList(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* String representation of option value */
    char *widgRec,              /* Widget structure record */
    int offset)
{                               /* Offset of field in record */
    const char   ***listPtr = (const char ***) (widgRec + offset);
    const char    **elemArr;
    int             nElem;

    if (*listPtr != NULL) {
        ckfree((char *) *listPtr);
        *listPtr = NULL;
    }
    if ((string == NULL) || (*string == '\0')) {
        return TCL_OK;
    }
    if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
        return TCL_ERROR;
    }
    if (nElem > 0) {
        *listPtr = elemArr;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * ListToString --
 *
 *      Returns the string representation of the state configuration field
 *
 * Results:
 *      The string is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
ListToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget structure record. */
    int offset,                 /* Offset of fill in widget record. */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    char          **list = *(char ***) (widgRec + offset);
    register char **p;
    char           *result;
    Tcl_DString     dString;

    if (list == NULL) {
        return "";
    }
    Tcl_DStringInit(&dString);
    for (p = list; *p != NULL; p++) {
        Tcl_DStringAppendElement(&dString, *p);
    }
    result = Tcl_DStringValue(&dString);
    if (result == dString.staticSpace) {
        result = RbcStrdup(result);
    }
    Tcl_DStringFree(&dString);
    *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToTile --
 *
 *      Converts the name of an image into a tile.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToTile(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Window on same display as tile */
    const char *string,         /* Name of image */
    char *widgRec,              /* Widget structure record */
    int offset)
{                               /* Offset of tile in record */
    RbcTile        *tilePtr = (RbcTile *) (widgRec + offset);
    RbcTile         tile, oldTile;

    oldTile = *tilePtr;
    tile = NULL;
    if ((string != NULL) && (*string != '\0')) {
        if (RbcGetTile(interp, tkwin, string, &tile) != TCL_OK) {
            return TCL_ERROR;
        }
    }
    /* Don't delete the information for the old tile, until we know
     * that we successfully allocated a new one. */
    if (oldTile != NULL) {
        RbcFreeTile(oldTile);
    }
    *tilePtr = tile;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TileToString --
 *
 *      Returns the name of the tile.
 *
 * Results:
 *      The name of the tile is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
TileToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget structure record */
    int offset,                 /* Offset of tile in record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    RbcTile         tile = *(RbcTile *) (widgRec + offset);

    return RbcNameOfTile(tile);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcConfigModified --
 *
 *      Given the configuration specifications and one or more option
 *      patterns (terminated by a NULL), indicate if any of the matching
 *      configuration options has been reset.
 *
 * Results:
 *      Returns 1 if one of the options has changed, 0 otherwise.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
int
RbcConfigModified(
    Tk_ConfigSpec * specs,
    ...)
{
    va_list         argList;
    register Tk_ConfigSpec *specPtr;
    register char  *option;

    va_start(argList, specs);
    while ((option = va_arg(argList, char *)) != NULL) {
        for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
            if ((Tcl_StringMatch(specPtr->argvName, option))
                && (specPtr->specFlags & TK_CONFIG_OPTION_SPECIFIED)) {
                va_end(argList);
                return 1;
            }
        }
    }
    va_end(argList);
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcConfigureWidgetComponent --
 *
 *      Configures a component of a widget.  This is useful for
 *      widgets that have multiple components which aren't uniquely
 *      identified by a Tk_Window. It allows us, for example, set
 *      resources for axes of the graph widget. The graph really has
 *      only one window, but its convenient to specify components in a
 *      hierarchy of options.
 *
 *          *graph.x.logScale yes
 *          *graph.Axis.logScale yes
 *          *graph.temperature.scaleSymbols yes
 *          *graph.Element.scaleSymbols yes
 *
 *      This is really a hack to work around the limitations of the Tk
 *      resource database.  It creates a temporary window, needed to
 *      call Tk_ConfigureWidget, using the name of the component.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side Effects:
 *      A temporary window is created merely to pass to Tk_ConfigureWidget.
 *
 *----------------------------------------------------------------------
 */
int
RbcConfigureWidgetComponent(
    Tcl_Interp * interp,
    Tk_Window parent,           /* Window to associate with component */
    const char resName[],       /* Name of component */
    const char className[],
    const Tk_ConfigSpec * specsPtr,
    int argc,
    const char *argv[],
    char *widgRec,
    int flags)
{
    Tk_Window       tkwin;
    int             result;
    char           *tempName;
    int             isTemporary = FALSE;

    tempName = RbcStrdup(resName);

    /* Window name can't start with an upper case letter */
    tempName[0] = tolower(resName[0]);

    /*
     * Create component if a child window by the component's name
     * doesn't already exist.
     */
    tkwin = RbcFindChild(parent, tempName);
    if (tkwin == NULL) {
        tkwin = Tk_CreateWindow(interp, parent, tempName, (char *) NULL);
        isTemporary = TRUE;
    }
    if (tkwin == NULL) {
        Tcl_AppendResult(interp, "can't find window in \"", Tk_PathName(parent),
            "\"", (char *) NULL);
        return TCL_ERROR;
    }
    assert(Tk_Depth(tkwin) == Tk_Depth(parent));
    ckfree((char *) tempName);

    Tk_SetClass(tkwin, className);
    result =
        Tk_ConfigureWidget(interp, tkwin, specsPtr, argc, argv, widgRec, flags);
    if (isTemporary) {
        Tk_DestroyWindow(tkwin);
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcStringToEnum --
 *
 *      Converts the string into its enumerated type.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
int
RbcStringToEnum(
    ClientData clientData,      /* Vectors of valid strings. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* String to match. */
    char *widgRec,              /* Widget record. */
    int offset)
{                               /* Offset of field in record */
    int            *enumPtr = (int *) (widgRec + offset);
    char            c;
    register char **p;
    register int    i;
    int             count;

    c = string[0];
    count = 0;
    for (p = (char **) clientData; *p != NULL; p++) {
        if ((c == p[0][0]) && (strcmp(string, *p) == 0)) {
            *enumPtr = count;
            return TCL_OK;
        }
        count++;
    }
    *enumPtr = -1;

    Tcl_AppendResult(interp, "bad value \"", string, "\": should be ",
        (char *) NULL);
    p = (char **) clientData;
    if (count > 0) {
        Tcl_AppendResult(interp, p[0], (char *) NULL);
    }
    for (i = 1; i < (count - 1); i++) {
        Tcl_AppendResult(interp, " ", p[i], ", ", (char *) NULL);
    }
    if (count > 1) {
        Tcl_AppendResult(interp, " or ", p[count - 1], ".", (char *) NULL);
    }
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcEnumToString --
 *
 *      Returns the string associated with the enumerated type.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
const char     *
RbcEnumToString(
    ClientData clientData,      /* List of strings. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget record */
    int offset,                 /* Offset of field in widget record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    int             value = *(int *) (widgRec + offset);
    char          **p;
    int             count;

    count = 0;
    for (p = (char **) clientData; *p != NULL; p++) {
        count++;
    }
    if ((value >= count) || (value < 0)) {
        return "unknown value";
    }
    p = (char **) clientData;
    return p[value];
}

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

Added generic/rbc/rbcGrAxis.c.
























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
143
144
145
146
147
148
149
150
151
152
153
154
155
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
201
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
309
310
311
312
313
314
315
316
317
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
/*
 * rbcGrAxis.c --
 *
 *      This module implements coordinate axes for the rbc graph widget.
 *
 * 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"

#define AXIS_CONFIG_MAJOR (1<<4)        /* User specified major tick intervals. */
#define AXIS_CONFIG_MINOR (1<<5)        /* User specified minor tick intervals. */
#define AXIS_ONSCREEN	  (1<<6)        /* Axis is displayed on the screen via
                                         * the "use" operation */
#define AXIS_DIRTY	  (1<<7)
#define AXIS_ALLOW_NULL   (1<<12)

#define DEF_NUM_TICKS		10      /* Each major tick is 10% */
#define STATIC_TICK_SPACE	10

#define TICK_LABEL_SIZE		200
#define MAXTICKS		10001

/*
 * Round x in terms of units
 */
#define UROUND(x,u)		(Round((x)/(u))*(u))
#define UCEIL(x,u)		(ceil((x)/(u))*(u))
#define UFLOOR(x,u)		(floor((x)/(u))*(u))

#define LENGTH_MAJOR_TICK 	0.030   /* Length of a major tick */
#define LENGTH_MINOR_TICK 	0.015   /* Length of a minor (sub)tick */
#define LENGTH_LABEL_TICK 	0.040   /* Distance from graph to start of the
                                         * label */
#define NUMDIGITS		15      /* Specifies the number of
                                         * digits of accuracy used when
                                         * outputting axis tick labels. */
#define AVG_TICK_NUM_CHARS	16      /* Assumed average tick label size */

#define TICK_RANGE_TIGHT	0
#define TICK_RANGE_LOOSE	1
#define TICK_RANGE_ALWAYS_LOOSE	2

#define AXIS_TITLE_PAD		2       /* Padding for axis title. */
#define AXIS_LINE_PAD		1       /* Padding for axis line. */

#define HORIZMARGIN(m)	(!((m)->site & 0x1))    /* Even sites are horizontal */

typedef enum AxisComponents {
    MAJOR_TICK, MINOR_TICK, TICK_LABEL, AXIS_LINE
} AxisComponent;

/*
 * TickLabel --
 *
 * 	Structure containing the X-Y screen coordinates of the tick
 * 	label (anchored at its center).
 */
typedef struct {
    RbcPoint2D      anchorPos;
    int             width, height;
    char            string[1];
} TickLabel;

typedef struct {
    int             axis;       /* Length of the axis.  */
    int             t1;         /* Length of a major tick (in pixels). */
    int             t2;         /* Length of a minor tick (in pixels). */
    int             label;      /* Distance from axis to tick label.  */
} AxisInfo;

extern Tk_CustomOption rbcDistanceOption;
extern Tk_CustomOption rbcPositiveDistanceOption;
extern Tk_CustomOption rbcShadowOption;
extern Tk_CustomOption rbcListOption;

static Tk_OptionParseProc StringToLimit;
static Tk_OptionPrintProc LimitToString;
static Tk_OptionParseProc StringToTicks;
static Tk_OptionPrintProc TicksToString;
static Tk_OptionParseProc StringToAxis;
static Tk_OptionPrintProc AxisToString;
static Tk_OptionParseProc StringToAnyAxis;
static Tk_OptionParseProc StringToFormat;
static Tk_OptionPrintProc FormatToString;
static Tk_OptionParseProc StringToLoose;
static Tk_OptionPrintProc LooseToString;

static Tk_CustomOption limitOption = {
    StringToLimit, LimitToString, (ClientData) 0
};

static Tk_CustomOption majorTicksOption = {
    StringToTicks, TicksToString, (ClientData) AXIS_CONFIG_MAJOR,
};

static Tk_CustomOption minorTicksOption = {
    StringToTicks, TicksToString, (ClientData) AXIS_CONFIG_MINOR,
};

Tk_CustomOption rbcXAxisOption = {
    StringToAxis, AxisToString, (ClientData) & rbcXAxisUid
};

Tk_CustomOption rbcYAxisOption = {
    StringToAxis, AxisToString, (ClientData) & rbcYAxisUid
};

Tk_CustomOption rbcAnyXAxisOption = {
    StringToAnyAxis, AxisToString, (ClientData) & rbcXAxisUid
};

Tk_CustomOption rbcAnyYAxisOption = {
    StringToAnyAxis, AxisToString, (ClientData) & rbcYAxisUid
};

static Tk_CustomOption formatOption = {
    StringToFormat, FormatToString, (ClientData) 0,
};

static Tk_CustomOption looseOption = {
    StringToLoose, LooseToString, (ClientData) 0,
};

/* Axis flags: */

#define DEF_AXIS_COMMAND            (char *)NULL
#define DEF_AXIS_DESCENDING         "no"
#define DEF_AXIS_FOREGROUND         "black"
#define DEF_AXIS_FG_MONO            "black"
#define DEF_AXIS_HIDE               "no"
#define DEF_AXIS_JUSTIFY            "center"
#define DEF_AXIS_LIMITS_FORMAT      (char *)NULL
#define DEF_AXIS_LINE_WIDTH         "1"
#define DEF_AXIS_LOGSCALE           "no"
#define DEF_AXIS_LOOSE              "no"
#define DEF_AXIS_RANGE              "0.0"
#define DEF_AXIS_ROTATE             "0.0"
#define DEF_AXIS_SCROLL_INCREMENT   "10"
#define DEF_AXIS_SHIFTBY            "0.0"
#define DEF_AXIS_SHOWTICKS          "yes"
#define DEF_AXIS_STEP               "0.0"
#define DEF_AXIS_STEP               "0.0"
#define DEF_AXIS_SUBDIVISIONS       "2"
#define DEF_AXIS_TAGS               "all"
#define DEF_AXIS_TICKS              "0"
#define DEF_AXIS_TICK_FONT          RBC_FONT_SMALL
#define DEF_AXIS_TICK_LENGTH        "8"
#define DEF_AXIS_TITLE_ALTERNATE    "0"
#define DEF_AXIS_TITLE_FG           "black"
#define DEF_AXIS_TITLE_FONT         RBC_FONT
#define DEF_AXIS_X_STEP_BARCHART    "1.0"
#define DEF_AXIS_X_SUBDIVISIONS_BARCHART    "0"
#define DEF_AXIS_BACKGROUND         (char *)NULL
#define DEF_AXIS_BORDERWIDTH        "0"
#define DEF_AXIS_RELIEF             "flat"

static Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_DOUBLE, "-autorange", "autoRange", "AutoRange", DEF_AXIS_RANGE,
            Tk_Offset(RbcAxis, windowSize),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_BORDER, "-background", "background", "Background",
            DEF_AXIS_BACKGROUND, Tk_Offset(RbcAxis, border),
        RBC_ALL_GRAPHS | TK_CONFIG_NULL_OK},
    {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL, (char *) NULL, 0,
        0},
    {TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", DEF_AXIS_TAGS,
            Tk_Offset(RbcAxis, tags), RBC_ALL_GRAPHS | TK_CONFIG_NULL_OK,
        &rbcListOption},
    {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL, (char *) NULL, 0,
        RBC_ALL_GRAPHS},
    {TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth",
            DEF_AXIS_BORDERWIDTH, Tk_Offset(RbcAxis, borderWidth),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT, &rbcDistanceOption},
    {TK_CONFIG_COLOR, "-color", "color", "Color", DEF_AXIS_FOREGROUND,
            Tk_Offset(RbcAxis, tickTextStyle.color),
        TK_CONFIG_COLOR_ONLY | RBC_ALL_GRAPHS},
    {TK_CONFIG_COLOR, "-color", "color", "Color", DEF_AXIS_FG_MONO,
            Tk_Offset(RbcAxis, tickTextStyle.color),
        TK_CONFIG_MONO_ONLY | RBC_ALL_GRAPHS},
    {TK_CONFIG_STRING, "-command", "command", "Command", DEF_AXIS_COMMAND,
        Tk_Offset(RbcAxis, formatCmd), TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS},
    {TK_CONFIG_BOOLEAN, "-descending", "descending", "Descending",
            DEF_AXIS_DESCENDING, Tk_Offset(RbcAxis, descending),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_BOOLEAN, "-hide", "hide", "Hide", DEF_AXIS_HIDE,
            Tk_Offset(RbcAxis, hidden),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_JUSTIFY, "-justify", "justify", "Justify", DEF_AXIS_JUSTIFY,
            Tk_Offset(RbcAxis, titleTextStyle.justify),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_BOOLEAN, "-labeloffset", "labelOffset", "LabelOffset",
        (char *) NULL, Tk_Offset(RbcAxis, labelOffset), RBC_ALL_GRAPHS},
    {TK_CONFIG_COLOR, "-limitscolor", "limitsColor", "Color",
            DEF_AXIS_FOREGROUND, Tk_Offset(RbcAxis, limitsTextStyle.color),
        TK_CONFIG_COLOR_ONLY | RBC_ALL_GRAPHS},
    {TK_CONFIG_COLOR, "-limitscolor", "limitsColor", "Color", DEF_AXIS_FG_MONO,
            Tk_Offset(RbcAxis, limitsTextStyle.color),
        TK_CONFIG_MONO_ONLY | RBC_ALL_GRAPHS},
    {TK_CONFIG_FONT, "-limitsfont", "limitsFont", "Font", DEF_AXIS_TICK_FONT,
        Tk_Offset(RbcAxis, limitsTextStyle.font), RBC_ALL_GRAPHS},
    {TK_CONFIG_CUSTOM, "-limitsformat", "limitsFormat", "LimitsFormat",
            (char *) NULL, Tk_Offset(RbcAxis, limitsFormats),
        TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS, &formatOption},
    {TK_CONFIG_CUSTOM, "-limitsshadow", "limitsShadow", "Shadow", (char *) NULL,
            Tk_Offset(RbcAxis, limitsTextStyle.shadow),
        TK_CONFIG_COLOR_ONLY | RBC_ALL_GRAPHS, &rbcShadowOption},
    {TK_CONFIG_CUSTOM, "-limitsshadow", "limitsShadow", "Shadow", (char *) NULL,
            Tk_Offset(RbcAxis, limitsTextStyle.shadow),
        TK_CONFIG_MONO_ONLY | RBC_ALL_GRAPHS, &rbcShadowOption},
    {TK_CONFIG_CUSTOM, "-linewidth", "lineWidth", "LineWidth",
            DEF_AXIS_LINE_WIDTH, Tk_Offset(RbcAxis, lineWidth),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT, &rbcDistanceOption},
    {TK_CONFIG_BOOLEAN, "-logscale", "logScale", "LogScale", DEF_AXIS_LOGSCALE,
            Tk_Offset(RbcAxis, logScale),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_CUSTOM, "-loose", "loose", "Loose", DEF_AXIS_LOOSE, 0,
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT, &looseOption},
    {TK_CONFIG_CUSTOM, "-majorticks", "majorTicks", "MajorTicks", (char *) NULL,
            Tk_Offset(RbcAxis, t1Ptr), TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS,
        &majorTicksOption},
    {TK_CONFIG_CUSTOM, "-max", "max", "Max", (char *) NULL, Tk_Offset(RbcAxis,
            reqMax), TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS, &limitOption},
    {TK_CONFIG_CUSTOM, "-min", "min", "Min", (char *) NULL, Tk_Offset(RbcAxis,
            reqMin), TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS, &limitOption},
    {TK_CONFIG_CUSTOM, "-minorticks", "minorTicks", "MinorTicks", (char *) NULL,
            Tk_Offset(RbcAxis, t2Ptr), TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS,
        &minorTicksOption},
    {TK_CONFIG_RELIEF, "-relief", "relief", "Relief", DEF_AXIS_RELIEF,
            Tk_Offset(RbcAxis, relief),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_DOUBLE, "-rotate", "rotate", "Rotate", DEF_AXIS_ROTATE,
            Tk_Offset(RbcAxis, tickTextStyle.theta),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_STRING, "-scrollcommand", "scrollCommand", "ScrollCommand",
            (char *) NULL, Tk_Offset(RbcAxis, scrollCmdPrefix),
        RBC_ALL_GRAPHS | TK_CONFIG_NULL_OK},
    {TK_CONFIG_CUSTOM, "-scrollincrement", "scrollIncrement", "ScrollIncrement",
            DEF_AXIS_SCROLL_INCREMENT, Tk_Offset(RbcAxis, scrollUnits),
            RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT,
        &rbcPositiveDistanceOption},
    {TK_CONFIG_CUSTOM, "-scrollmax", "scrollMax", "ScrollMax", (char *) NULL,
            Tk_Offset(RbcAxis, scrollMax), TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS,
        &limitOption},
    {TK_CONFIG_CUSTOM, "-scrollmin", "scrollMin", "ScrollMin", (char *) NULL,
            Tk_Offset(RbcAxis, scrollMin), TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS,
        &limitOption},
    {TK_CONFIG_DOUBLE, "-shiftby", "shiftBy", "ShiftBy", DEF_AXIS_SHIFTBY,
            Tk_Offset(RbcAxis, shiftBy),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_BOOLEAN, "-showticks", "showTicks", "ShowTicks",
            DEF_AXIS_SHOWTICKS, Tk_Offset(RbcAxis, showTicks),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_DOUBLE, "-stepsize", "stepSize", "StepSize", DEF_AXIS_STEP,
            Tk_Offset(RbcAxis, reqStep),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_DOUBLE, "-tickdivider", "tickDivider", "TickDivider",
            DEF_AXIS_STEP, Tk_Offset(RbcAxis, tickZoom),
        RBC_ALL_GRAPHS | TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_INT, "-subdivisions", "subdivisions", "Subdivisions",
            DEF_AXIS_SUBDIVISIONS, Tk_Offset(RbcAxis, reqNumMinorTicks),
        RBC_ALL_GRAPHS},
    {TK_CONFIG_FONT, "-tickfont", "tickFont", "Font", DEF_AXIS_TICK_FONT,
        Tk_Offset(RbcAxis, tickTextStyle.font), RBC_ALL_GRAPHS},
    {TK_CONFIG_PIXELS, "-ticklength", "tickLength", "TickLength",
            DEF_AXIS_TICK_LENGTH, Tk_Offset(RbcAxis, tickLength),
        RBC_ALL_GRAPHS},
    {TK_CONFIG_CUSTOM, "-tickshadow", "tickShadow", "Shadow", (char *) NULL,
            Tk_Offset(RbcAxis, tickTextStyle.shadow),
        TK_CONFIG_COLOR_ONLY | RBC_ALL_GRAPHS, &rbcShadowOption},
    {TK_CONFIG_CUSTOM, "-tickshadow", "tickShadow", "Shadow", (char *) NULL,
            Tk_Offset(RbcAxis, tickTextStyle.shadow),
        TK_CONFIG_MONO_ONLY | RBC_ALL_GRAPHS, &rbcShadowOption},
    {TK_CONFIG_STRING, "-title", "title", "Title", (char *) NULL,
            Tk_Offset(RbcAxis, title),
        TK_CONFIG_DONT_SET_DEFAULT | TK_CONFIG_NULL_OK | RBC_ALL_GRAPHS},
    {TK_CONFIG_BOOLEAN, "-titlealternate", "titleAlternate", "TitleAlternate",
            DEF_AXIS_TITLE_ALTERNATE, Tk_Offset(RbcAxis, titleAlternate),
        TK_CONFIG_DONT_SET_DEFAULT | RBC_ALL_GRAPHS},
    {TK_CONFIG_COLOR, "-titlecolor", "titleColor", "Color", DEF_AXIS_FOREGROUND,
            Tk_Offset(RbcAxis, titleTextStyle.color),
        TK_CONFIG_COLOR_ONLY | RBC_ALL_GRAPHS},
    {TK_CONFIG_COLOR, "-titlecolor", "titleColor", "TitleColor",
            DEF_AXIS_FG_MONO, Tk_Offset(RbcAxis, titleTextStyle.color),
        TK_CONFIG_MONO_ONLY | RBC_ALL_GRAPHS},
    {TK_CONFIG_FONT, "-titlefont", "titleFont", "Font", DEF_AXIS_TITLE_FONT,
        Tk_Offset(RbcAxis, titleTextStyle.font), RBC_ALL_GRAPHS},
    {TK_CONFIG_CUSTOM, "-titleshadow", "titleShadow", "Shadow", (char *) NULL,
            Tk_Offset(RbcAxis, titleTextStyle.shadow),
        TK_CONFIG_COLOR_ONLY | RBC_ALL_GRAPHS, &rbcShadowOption},
    {TK_CONFIG_CUSTOM, "-titleshadow", "titleShadow", "Shadow", (char *) NULL,
            Tk_Offset(RbcAxis, titleTextStyle.shadow),
        TK_CONFIG_MONO_ONLY | RBC_ALL_GRAPHS, &rbcShadowOption},
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};

/* Rotation for each axis title */
static double   titleRotate[4] = {
    0.0, 90.0, 0.0, 270.0
};

/* Forward declarations */
static int      Round(
    register double x);
static void     SetAxisRange(
    RbcAxisRange * rangePtr,
    double min,
    double max);
static int      InRange(
    register double x,
    RbcAxisRange * rangePtr);
static int      AxisIsHorizontal(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr);
static void     FreeLabels(
    RbcChain * chainPtr);
static TickLabel *MakeLabel(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double value);
static void     GetDataLimits(
    RbcAxis * axisPtr,
    double min,
    double max);
static void     FixAxisRange(
    RbcAxis * axisPtr);
static double   NiceNum(
    double x,
    int round);
static RbcTicks *GenerateTicks(
    RbcTickSweep * sweepPtr);
static void     LogScaleAxis(
    RbcAxis * axisPtr,
    double min,
    double max);
static void     LinearScaleAxis(
    RbcAxis * axisPtr,
    double min,
    double max);
static void     SweepTicks(
    RbcAxis * axisPtr);
static void     ResetTextStyles(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr);
static void     DestroyAxis(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr);
static void     AxisOffsets(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int margin,
    int axisOffset,
    AxisInfo * infoPtr);
static void     MakeAxisLine(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int line,
    RbcSegment2D * segPtr);
static void     MakeTick(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double value,
    int tick,
    int line,
    RbcSegment2D * segPtr);
static void     MapAxis(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int offset,
    int margin);
static double   AdjustViewport(
    double offset,
    double windowSize);
static int      GetAxisScrollInfo(
    Tcl_Interp * interp,
    int argc,
    const char **argv,
    double *offsetPtr,
    double windowSize,
    double scrollUnits);
static void     DrawAxis(
    RbcGraph * graphPtr,
    Drawable drawable,
    RbcAxis * axisPtr);
static void     AxisToPostScript(
    RbcPsToken * psToken,
    RbcAxis * axisPtr);
static void     MakeGridLine(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double value,
    RbcSegment2D * segPtr);
static void     GetAxisGeometry(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr);
static int      GetMarginGeometry(
    RbcGraph * graphPtr,
    RbcMargin * marginPtr);
static void     ComputeMargins(
    RbcGraph * graphPtr);
static RbcAxis *CreateAxis(
    RbcGraph * graphPtr,
    const char *name,
    int margin);
static int      ConfigureAxis(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr);
static int      NameToAxis(
    RbcGraph * graphPtr,
    const char *name,
    RbcAxis ** axisPtrPtr);
static int      GetAxis(
    RbcGraph * graphPtr,
    const char *name,
    RbcUid classUid,
    RbcAxis ** axisPtrPtr);
static void     FreeAxis(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr);

static int      BindOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char **argv);
static int      CgetOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char *argv[]);
static int      ConfigureOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char *argv[]);
static int      GetOp(
    RbcGraph * graphPtr,
    int argc,
    const char *argv[]);
static int      LimitsOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char **argv);
static int      InvTransformOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char **argv);
static int      TransformOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char **argv);
static int      UseOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char **argv);
static int      CreateVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      BindVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      CgetVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      ConfigureVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      DeleteVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      InvTransformVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      LimitsVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      NamesVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      TransformVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);
static int      ViewOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv);

/*
 *----------------------------------------------------------------------
 *
 * Round --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
Round(
    register double x)
{
    return (int) (x + ((x < 0.0) ? -0.5 : 0.5));
}

/*
 *----------------------------------------------------------------------
 *
 * SetAxisRange --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
SetAxisRange(
    RbcAxisRange * rangePtr,
    double min,
    double max)
{
    rangePtr->min = min;
    rangePtr->max = max;
    rangePtr->range = max - min;
    if (FABS(rangePtr->range) < DBL_EPSILON) {
        rangePtr->range = 1.0;
    }
    rangePtr->scale = 1.0 / rangePtr->range;
}

/*
 * ----------------------------------------------------------------------
 *
 * InRange --
 *
 *      Determines if a value lies within a given range.
 *
 *      The value is normalized and compared against the interval
 *      [0..1], where 0.0 is the minimum and 1.0 is the maximum.
 *      DBL_EPSILON is the smallest number that can be represented
 *      on the host machine, such that (1.0 + epsilon) != 1.0.
 *
 *      Please note, *max* can't equal *min*.
 *
 * Results:
 *      If the value is within the interval [min..max], 1 is
 *      returned; 0 otherwise.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static int
InRange(
    register double x,
    RbcAxisRange * rangePtr)
{
    if (rangePtr->range < DBL_EPSILON) {
        return (FABS(rangePtr->max - x) >= DBL_EPSILON);
    } else {
        double          norm;

        norm = (x - rangePtr->min) * rangePtr->scale;
        return ((norm >= -DBL_EPSILON) && ((norm - 1.0) < DBL_EPSILON));
    }
}

static int
AxisIsHorizontal(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr)
{
    return ((axisPtr->classUid == rbcYAxisUid) == graphPtr->inverted);
}

/* ----------------------------------------------------------------------
 * Custom option parse and print procedures
 * ----------------------------------------------------------------------
 */

/*
 *----------------------------------------------------------------------
 *
 * StringToAnyAxis --
 *
 *      Converts the name of an axis to a pointer to its axis structure.
 *
 * Results:
 *      The return value is a standard Tcl result.  The axis flags are
 *      written into the widget record.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToAnyAxis(
    ClientData clientData,      /* Class identifier of the type of
                                 * axis we are looking for. */
    Tcl_Interp * interp,        /* Interpreter to send results back to. */
    Tk_Window tkwin,            /* Used to look up pointer to graph. */
    const char *string,         /* String representing new value. */
    char *widgRec,              /* Pointer to structure record. */
    int offset)
{                               /* Offset of field in structure. */
    RbcAxis       **axisPtrPtr = (RbcAxis **) (widgRec + offset);
    RbcUid          classUid = *(RbcUid *) clientData;
    RbcGraph       *graphPtr;
    RbcAxis        *axisPtr;

    graphPtr = RbcGetGraphFromWindowData(tkwin);
    if (*axisPtrPtr != NULL) {
        FreeAxis(graphPtr, *axisPtrPtr);
    }
    if (string[0] == '\0') {
        axisPtr = NULL;
    } else if (GetAxis(graphPtr, string, classUid, &axisPtr) != TCL_OK) {
        return TCL_ERROR;
    }
    *axisPtrPtr = axisPtr;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToAxis --
 *
 *      Converts the name of an axis to a pointer to its axis structure.
 *
 * Results:
 *      The return value is a standard Tcl result.  The axis flags are
 *      written into the widget record.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToAxis(
    ClientData clientData,      /* Class identifier of the type of
                                 * axis we are looking for. */
    Tcl_Interp * interp,        /* Interpreter to send results back to. */
    Tk_Window tkwin,            /* Used to look up pointer to graph. */
    const char *string,         /* String representing new value. */
    char *widgRec,              /* Pointer to structure record. */
    int offset)
{                               /* Offset of field in structure. */
    RbcAxis       **axisPtrPtr = (RbcAxis **) (widgRec + offset);
    RbcUid          classUid = *(RbcUid *) clientData;
    RbcGraph       *graphPtr;

    graphPtr = RbcGetGraphFromWindowData(tkwin);
    if (*axisPtrPtr != NULL) {
        FreeAxis(graphPtr, *axisPtrPtr);
    }
    if (GetAxis(graphPtr, string, classUid, axisPtrPtr) != TCL_OK) {
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * AxisToString --
 *
 *      Convert the window coordinates into a string.
 *
 * Results:
 *      The string representing the coordinate position is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *----------------------------------------------------------------------
 */
static const char *
AxisToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Pointer to structure record . */
    int offset,                 /* Offset of field in structure. */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    RbcAxis        *axisPtr = *(RbcAxis **) (widgRec + offset);

    if (axisPtr == NULL) {
        return "";
    }
    return axisPtr->name;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToFormat --
 *
 *      Convert the name of virtual axis to an pointer.
 *
 * Results:
 *      The return value is a standard Tcl result.  The axis flags are
 *      written into the widget record.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToFormat(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to. */
    Tk_Window tkwin,            /* Used to look up pointer to graph */
    const char *string,         /* String representing new value. */
    char *widgRec,              /* Pointer to structure record. */
    int offset)
{                               /* Offset of field in structure. */
    RbcAxis        *axisPtr = (RbcAxis *) (widgRec);
    const char    **argv;
    int             argc;

    if (axisPtr->limitsFormats != NULL) {
        ckfree((char *) axisPtr->limitsFormats);
    }
    axisPtr->limitsFormats = NULL;
    axisPtr->nFormats = 0;

    if ((string == NULL) || (*string == '\0')) {
        return TCL_OK;
    }
    if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
        return TCL_ERROR;
    }
    if (argc > 2) {
        Tcl_AppendResult(interp, "too many elements in limits format list \"",
            string, "\"", (char *) NULL);
        ckfree((char *) argv);  /*TODO check really? */
        return TCL_ERROR;
    }
    axisPtr->limitsFormats = argv;
    axisPtr->nFormats = argc;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * FormatToString --
 *
 *      Convert the window coordinates into a string.
 *
 * Results:
 *      The string representing the coordinate position is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
FormatToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget record */
    int offset,                 /* offset of limits field */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    RbcAxis        *axisPtr = (RbcAxis *) (widgRec);

    if (axisPtr->nFormats == 0) {
        return "";
    }
    *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    return Tcl_Merge(axisPtr->nFormats, axisPtr->limitsFormats);
}

/*
 * ----------------------------------------------------------------------
 *
 * StringToLimit --
 *
 *      Convert the string representation of an axis limit into its numeric
 *      form.
 *
 * Results:
 *      The return value is a standard Tcl result.  The symbol type is
 *      written into the widget record.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static int
StringToLimit(
    ClientData clientData,      /* Either AXIS_CONFIG_MIN or AXIS_CONFIG_MAX.
                                 * Indicates which axis limit to set. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* String representing new value. */
    char *widgRec,              /* Pointer to structure record. */
    int offset)
{                               /* Offset of field in structure. */
    double         *limitPtr = (double *) (widgRec + offset);

    if ((string == NULL) || (*string == '\0')) {
        *limitPtr = rbcNaN;
    } else if (Tcl_ExprDouble(interp, string, limitPtr) != TCL_OK) {
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * LimitToString --
 *
 *      Convert the floating point axis limits into a string.
 *
 * Results:
 *      The string representation of the limits is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static const char *
LimitToString(
    ClientData clientData,      /* Either LMIN or LMAX */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr)
{
    double          limit = *(double *) (widgRec + offset);
    const char     *result;

    result = "";
    if (!TclIsNaN(limit)) {
        char            string[TCL_DOUBLE_SPACE + 1];
        RbcGraph       *graphPtr;

        graphPtr = RbcGetGraphFromWindowData(tkwin);
        Tcl_PrintDouble(graphPtr->interp, limit, string);
        result = RbcStrdup(string);
        if (result == NULL) {
            return "";
        }
        *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    }
    return result;
}

/*
 * ----------------------------------------------------------------------
 *
 * StringToTicks --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static int
StringToTicks(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* String representing new value. */
    char *widgRec,              /* Pointer to structure record. */
    int offset)
{                               /* Offset of field in structure. */
    unsigned int    mask = (unsigned int) clientData;
    RbcAxis        *axisPtr = (RbcAxis *) widgRec;
    RbcTicks      **ticksPtrPtr = (RbcTicks **) (widgRec + offset);
    int             nTicks;
    RbcTicks       *ticksPtr;

    nTicks = 0;
    ticksPtr = NULL;
    if ((string != NULL) && (*string != '\0')) {
        int             nExprs;
        const char    **exprArr;

        if (Tcl_SplitList(interp, string, &nExprs, &exprArr) != TCL_OK) {
            return TCL_ERROR;
        }
        if (nExprs > 0) {
            register int    i;
            int             result = TCL_ERROR;
            double          value;

            ticksPtr =
                (RbcTicks *) ckalloc(sizeof(RbcTicks) +
                (nExprs * sizeof(double)));
            assert(ticksPtr);
            for (i = 0; i < nExprs; i++) {
                result = Tcl_ExprDouble(interp, exprArr[i], &value);
                if (result != TCL_OK) {
                    break;
                }
                ticksPtr->values[i] = value;
            }
            ckfree((char *) exprArr);
            if (result != TCL_OK) {
                ckfree((char *) ticksPtr);
                return TCL_ERROR;
            }
            nTicks = nExprs;
        }
    }
    axisPtr->flags &= ~mask;
    if (ticksPtr != NULL) {
        axisPtr->flags |= mask;
        ticksPtr->nTicks = nTicks;
    }
    if (*ticksPtrPtr != NULL) {
        ckfree((char *) *ticksPtrPtr);
    }
    *ticksPtrPtr = ticksPtr;
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * TicksToString --
 *
 *      Convert array of tick coordinates to a list.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static const char *
TicksToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr)
{
    RbcTicks       *ticksPtr = *(RbcTicks **) (widgRec + offset);
    char            string[TCL_DOUBLE_SPACE + 1];
    register int    i;
    char           *result;
    Tcl_DString     dString;
    RbcGraph       *graphPtr;

    if (ticksPtr == NULL) {
        return "";
    }
    Tcl_DStringInit(&dString);
    graphPtr = RbcGetGraphFromWindowData(tkwin);
    for (i = 0; i < ticksPtr->nTicks; i++) {
        Tcl_PrintDouble(graphPtr->interp, ticksPtr->values[i], string);
        Tcl_DStringAppendElement(&dString, string);
    }
    *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    result = RbcStrdup(Tcl_DStringValue(&dString));
    Tcl_DStringFree(&dString);
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * StringToLoose --
 *
 *      Convert a string to one of three values.
 *      	0 - false, no, off
 *      	1 - true, yes, on
 *      	2 - always
 *
 * Results:
 *      If the string is successfully converted, TCL_OK is returned.
 *      Otherwise, TCL_ERROR is returned and an error message is left in
 *      interpreter's result field.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
StringToLoose(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* String representing new value. */
    char *widgRec,              /* Pointer to structure record. */
    int offset)
{                               /* Offset of field in structure. */
    RbcAxis        *axisPtr = (RbcAxis *) (widgRec);
    register int    i;
    int             argc;
    const char    **argv;
    int             values[2];

    if (Tcl_SplitList(interp, string, &argc, &argv) != TCL_OK) {
        return TCL_ERROR;
    }
    if ((argc < 1) || (argc > 2)) {
        Tcl_AppendResult(interp, "wrong # elements in loose value \"",
            string, "\"", (char *) NULL);
        return TCL_ERROR;
    }
    for (i = 0; i < argc; i++) {
        if ((argv[i][0] == 'a') && (strcmp(argv[i], "always") == 0)) {
            values[i] = TICK_RANGE_ALWAYS_LOOSE;
        } else {
            int             bool;

            if (Tcl_GetBoolean(interp, argv[i], &bool) != TCL_OK) {
                ckfree((char *) argv);
                return TCL_ERROR;
            }
            values[i] = bool;
        }
    }
    axisPtr->looseMin = axisPtr->looseMax = values[0];
    if (argc > 1) {
        axisPtr->looseMax = values[1];
    }
    ckfree((char *) argv);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * LooseToString --
 *
 *      TODO: Description
 *
 * Results:
 *      The string representation of the auto boolean is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static const char *
LooseToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget record */
    int offset,                 /* offset of flags field in record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Memory deallocation scheme to use */
    RbcAxis        *axisPtr = (RbcAxis *) widgRec;
    Tcl_DString     dString;
    char           *result;

    Tcl_DStringInit(&dString);
    if (axisPtr->looseMin == TICK_RANGE_TIGHT) {
        Tcl_DStringAppendElement(&dString, "0");
    } else if (axisPtr->looseMin == TICK_RANGE_LOOSE) {
        Tcl_DStringAppendElement(&dString, "1");
    } else if (axisPtr->looseMin == TICK_RANGE_ALWAYS_LOOSE) {
        Tcl_DStringAppendElement(&dString, "always");
    }
    if (axisPtr->looseMin != axisPtr->looseMax) {
        if (axisPtr->looseMax == TICK_RANGE_TIGHT) {
            Tcl_DStringAppendElement(&dString, "0");
        } else if (axisPtr->looseMax == TICK_RANGE_LOOSE) {
            Tcl_DStringAppendElement(&dString, "1");
        } else if (axisPtr->looseMax == TICK_RANGE_ALWAYS_LOOSE) {
            Tcl_DStringAppendElement(&dString, "always");
        }
    }
    result = RbcStrdup(Tcl_DStringValue(&dString));
    Tcl_DStringFree(&dString);
    *freeProcPtr = (Tcl_FreeProc *) Tcl_Free;
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeLabels --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
FreeLabels(
    RbcChain * chainPtr)
{
    RbcChainLink   *linkPtr;
    TickLabel      *labelPtr;

    for (linkPtr = RbcChainFirstLink(chainPtr); linkPtr != NULL;
        linkPtr = RbcChainNextLink(linkPtr)) {
        labelPtr = RbcChainGetValue(linkPtr);
        ckfree((char *) labelPtr);
    }
    RbcChainReset(chainPtr);
}

/*
 * ----------------------------------------------------------------------
 *
 * MakeLabel --
 *
 *      Converts a floating point tick value to a string to be used as its
 *      label.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      Returns a new label in the string character buffer.  The formatted
 *      tick label will be displayed on the graph.
 *
 * ----------------------------------------------------------------------
 */
static TickLabel *
MakeLabel(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,          /* Axis structure */
    double value)
{                               /* Value to be convert to a decimal string */
    char            string[TICK_LABEL_SIZE + 1];
    TickLabel      *labelPtr;

    /* Generate a default tick label based upon the tick value.  */
    if (axisPtr->logScale) {
        sprintf(string, "1E%d", ROUND(value));
    } else {
        sprintf(string, "%.*g", NUMDIGITS, value);
    }

    if (axisPtr->formatCmd != NULL) {
        Tcl_Interp     *interp = graphPtr->interp;
        Tk_Window       tkwin = graphPtr->tkwin;

        /*
         * A Tcl proc was designated to format tick labels. Append the path
         * name of the widget and the default tick label as arguments when
         * invoking it. Copy and save the new label from interp->result.
         */
        Tcl_ResetResult(interp);
        if (Tcl_VarEval(interp, axisPtr->formatCmd, " ", Tk_PathName(tkwin),
                " ", string, (char *) NULL) != TCL_OK) {
            Tcl_BackgroundError(interp);
        } else {
            /*
             * The proc could return a string of any length, so arbitrarily
             * limit it to what will fit in the return string.
             */
            strncpy(string, Tcl_GetStringResult(interp), TICK_LABEL_SIZE);
            string[TICK_LABEL_SIZE] = '\0';

            Tcl_ResetResult(interp);    /* Clear the interpreter's result. */
        }
    }
    labelPtr = (TickLabel *) ckalloc(sizeof(TickLabel) + strlen(string));
    assert(labelPtr);
    strcpy(labelPtr->string, string);
    labelPtr->anchorPos.x = labelPtr->anchorPos.y = DBL_MAX;
    return labelPtr;
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcInvHMap --
 *
 *      Maps the given screen coordinate back to a graph coordinate.
 *      Called by the graph locater routine.
 *
 * Results:
 *      Returns the graph coordinate value at the given window
 *      y-coordinate.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
double
RbcInvHMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x)
{
    double          value;

    x = (double) (x - graphPtr->hOffset) * graphPtr->hScale;
    if (axisPtr->descending) {
        x = 1.0 - x;
    }
    value = (x * axisPtr->axisRange.range) + axisPtr->axisRange.min;
    if (axisPtr->logScale) {
        value = EXP10(value);
    }
    return value;
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcInvVMap --
 *
 *      Maps the given window y-coordinate back to a graph coordinate
 *      value. Called by the graph locater routine.
 *
 * Results:
 *      Returns the graph coordinate value at the given window
 *      y-coordinate.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
double
RbcInvVMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double y)
{
    double          value;

    y = (double) (y - graphPtr->vOffset) * graphPtr->vScale;
    if (axisPtr->descending) {
        y = 1.0 - y;
    }
    value = ((1.0 - y) * axisPtr->axisRange.range) + axisPtr->axisRange.min;
    if (axisPtr->logScale) {
        value = EXP10(value);
    }
    return value;
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcHMap --
 *
 *      Map the given graph coordinate value to its axis, returning a window
 *      position.
 *
 * Results:
 *      Returns a double precision number representing the window coordinate
 *      position on the given axis.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
double
RbcHMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double x)
{
    if ((axisPtr->logScale) && (x != 0.0)) {
        x = log10(FABS(x));
    }
    /* Map graph coordinate to normalized coordinates [0..1] */
    x = (x - axisPtr->axisRange.min) * axisPtr->axisRange.scale;
    if (axisPtr->descending) {
        x = 1.0 - x;
    }
    return (x * graphPtr->hRange + graphPtr->hOffset);
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcVMap --
 *
 *      Map the given graph coordinate value to its axis, returning a window
 *      position.
 *
 * Results:
 *      Returns a double precision number representing the window coordinate
 *      position on the given axis.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
double
RbcVMap(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double y)
{
    if ((axisPtr->logScale) && (y != 0.0)) {
        y = log10(FABS(y));
    }
    /* Map graph coordinate to normalized coordinates [0..1] */
    y = (y - axisPtr->axisRange.min) * axisPtr->axisRange.scale;
    if (axisPtr->descending) {
        y = 1.0 - y;
    }
    return (((1.0 - y) * graphPtr->vRange) + graphPtr->vOffset);
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcMap2D --
 *
 *      Maps the given graph x,y coordinate values to a window position.
 *
 * Results:
 *      Returns a XPoint structure containing the window coordinates of
 *      the given graph x,y coordinate.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
RbcPoint2D
RbcMap2D(
    RbcGraph * graphPtr,
    double x,                   /* Graph x coordinate */
    double y,                   /* Graph y coordinate */
    RbcAxis2D * axesPtr)
{                               /* Specifies which axes to use */
    RbcPoint2D      point;

    if (graphPtr->inverted) {
        point.x = RbcHMap(graphPtr, axesPtr->y, y);
        point.y = RbcVMap(graphPtr, axesPtr->x, x);
    } else {
        point.x = RbcHMap(graphPtr, axesPtr->x, x);
        point.y = RbcVMap(graphPtr, axesPtr->y, y);
    }
    return point;
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcInvMap2D --
 *
 *      Maps the given window x,y coordinates to graph values.
 *
 * Results:
 *      Returns a structure containing the graph coordinates of
 *      the given window x,y coordinate.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
RbcPoint2D
RbcInvMap2D(
    RbcGraph * graphPtr,
    double x,                   /* Window x coordinate */
    double y,                   /* Window y coordinate */
    RbcAxis2D * axesPtr)
{                               /* Specifies which axes to use */
    RbcPoint2D      point;

    if (graphPtr->inverted) {
        point.x = RbcInvVMap(graphPtr, axesPtr->x, y);
        point.y = RbcInvHMap(graphPtr, axesPtr->y, x);
    } else {
        point.x = RbcInvHMap(graphPtr, axesPtr->x, x);
        point.y = RbcInvVMap(graphPtr, axesPtr->y, y);
    }
    return point;
}

/*
 *----------------------------------------------------------------------
 *
 * GetDataLimits --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
GetDataLimits(
    RbcAxis * axisPtr,
    double min,
    double max)
{
    if (axisPtr->valueRange.min > min) {
        axisPtr->valueRange.min = min;
    }
    if (axisPtr->valueRange.max < max) {
        axisPtr->valueRange.max = max;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * FixAxisRange --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
FixAxisRange(
    RbcAxis * axisPtr)
{
    double          min, max;
    /*
     * When auto-scaling, the axis limits are the bounds of the element
     * data.  If no data exists, set arbitrary limits (wrt to log/linear
     * scale).
     */
    min = axisPtr->valueRange.min;
    max = axisPtr->valueRange.max;

    if (min == DBL_MAX) {
        if (!TclIsNaN(axisPtr->reqMin)) {
            min = axisPtr->reqMin;
        } else {
            min = (axisPtr->logScale) ? 0.001 : 0.0;
        }
    }
    if (max == -DBL_MAX) {
        if (!TclIsNaN(axisPtr->reqMax)) {
            max = axisPtr->reqMax;
        } else {
            max = 1.0;
        }
    }
    if (min >= max) {
        double          value;

        /*
         * There is no range of data (i.e. min is not less than max),
         * so manufacture one.
         */
        value = min;
        if (value == 0.0) {
            min = -0.1, max = 0.1;
        } else {
            double          x;

            x = FABS(value) * 0.1;
            min = value - x, max = value + x;
        }
    }
    SetAxisRange(&axisPtr->valueRange, min, max);

    /*
     * The axis limits are either the current data range or overridden
     * by the values selected by the user with the -min or -max
     * options.
     */
    axisPtr->min = min;
    axisPtr->max = max;
    if (!TclIsNaN(axisPtr->reqMin)) {
        axisPtr->min = axisPtr->reqMin;
    }
    if (!TclIsNaN(axisPtr->reqMax)) {
        axisPtr->max = axisPtr->reqMax;
    }

    if (axisPtr->max < axisPtr->min) {

        /*
         * If the limits still don't make sense, it's because one
         * limit configuration option (-min or -max) was set and the
         * other default (based upon the data) is too small or large.
         * Remedy this by making up a new min or max from the
         * user-defined limit.
         */

        if (TclIsNaN(axisPtr->reqMin)) {
            axisPtr->min = axisPtr->max - (FABS(axisPtr->max) * 0.1);
        }
        if (TclIsNaN(axisPtr->reqMax)) {
            axisPtr->max = axisPtr->min + (FABS(axisPtr->max) * 0.1);
        }
    }
    /*
     * If a window size is defined, handle auto ranging by shifting
     * the axis limits.
     */
    if ((axisPtr->windowSize > 0.0) &&
        (TclIsNaN(axisPtr->reqMin)) && (TclIsNaN(axisPtr->reqMax))) {
        if (axisPtr->shiftBy < 0.0) {
            axisPtr->shiftBy = 0.0;
        }
        max = axisPtr->min + axisPtr->windowSize;
        if (axisPtr->max >= max) {
            if (axisPtr->shiftBy > 0.0) {
                max = UCEIL(axisPtr->max, axisPtr->shiftBy);
            }
            axisPtr->min = max - axisPtr->windowSize;
        }
        axisPtr->max = max;
    }
    if ((axisPtr->max != axisPtr->prevMax) ||
        (axisPtr->min != axisPtr->prevMin)) {
        /* Indicate if the axis limits have changed */
        axisPtr->flags |= AXIS_DIRTY;
        /* and save the previous minimum and maximum values */
        axisPtr->prevMin = axisPtr->min;
        axisPtr->prevMax = axisPtr->max;
    }
}

/*
 * ----------------------------------------------------------------------
 *
 * NiceNum --
 *
 *      Reference: Paul Heckbert, "Nice Numbers for Graph Labels",
 *             Graphics Gems, pp 61-63.
 *
 *      Finds a "nice" number approximately equal to x.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static double
NiceNum(
    double x,
    int round)
{                               /* If non-zero, round. Otherwise take ceiling
                                 * of value. */
    double          expt;       /* Exponent of x */
    double          frac;       /* Fractional part of x */
    double          nice;       /* Nice, rounded fraction */

    expt = floor(log10(x));
    frac = x / EXP10(expt);     /* between 1 and 10 */
    if (round) {
        if (frac < 1.5) {
            nice = 1.0;
        } else if (frac < 3.0) {
            nice = 2.0;
        } else if (frac < 7.0) {
            nice = 5.0;
        } else {
            nice = 10.0;
        }
    } else {
        if (frac <= 1.0) {
            nice = 1.0;
        } else if (frac <= 2.0) {
            nice = 2.0;
        } else if (frac <= 5.0) {
            nice = 5.0;
        } else {
            nice = 10.0;
        }
    }
    return nice * EXP10(expt);
}

/*
 *----------------------------------------------------------------------
 *
 * GenerateTicks --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static RbcTicks *
GenerateTicks(
    RbcTickSweep * sweepPtr)
{
    RbcTicks       *ticksPtr;
    register int    i;

    ticksPtr =
        (RbcTicks *) ckalloc(sizeof(RbcTicks) +
        (sweepPtr->nSteps * sizeof(double)));
    assert(ticksPtr);

    if (sweepPtr->step == 0.0) {
        static double   logTable[] = {  /* Precomputed log10 values [1..10] */
            0.0,
            0.301029995663981, 0.477121254719662,
            0.602059991327962, 0.698970004336019,
            0.778151250383644, 0.845098040014257,
            0.903089986991944, 0.954242509439325,
            1.0
        };
        /* Hack: A zero step indicates to use log values. */
        for (i = 0; i < sweepPtr->nSteps; i++) {
            ticksPtr->values[i] = logTable[i];
        }
    } else {
        double          value;

        value = sweepPtr->initial;      /* Start from smallest axis tick */
        for (i = 0; i < sweepPtr->nSteps; i++) {
            value = UROUND(value, sweepPtr->step);
            ticksPtr->values[i] = value;
            value += sweepPtr->step;
        }
    }
    ticksPtr->nTicks = sweepPtr->nSteps;
    return ticksPtr;
}

/*
 * ----------------------------------------------------------------------
 *
 * LogScaleAxis --
 *
 *      Determine the range and units of a log scaled axis.
 *
 *      Unless the axis limits are specified, the axis is scaled
 *      automatically, where the smallest and largest major ticks encompass
 *      the range of actual data values.  When an axis limit is specified,
 *      that value represents the smallest(min)/largest(max) value in the
 *      displayed range of values.
 *
 *      Both manual and automatic scaling are affected by the step used.  By
 *      default, the step is the largest power of ten to divide the range in
 *      more than one piece.
 *
 *      Automatic scaling:
 *      Find the smallest number of units which contain the range of values.
 *      The minimum and maximum major tick values will be represent the
 *      range of values for the axis. This greatest number of major ticks
 *      possible is 10.
 *
 *      Manual scaling:
 *          Make the minimum and maximum data values the represent the range of
 *          the values for the axis.  The minimum and maximum major ticks will be
 *          inclusive of this range.  This provides the largest area for plotting
 *          and the expected results when the axis min and max values have be set
 *          by the user (.e.g zooming).  The maximum number of major ticks is 20.
 *
 *          For log scale, there's the possibility that the minimum and
 *          maximum data values are the same magnitude.  To represent the
 *          points properly, at least one full decade should be shown.
 *          However, if you zoom a log scale plot, the results should be
 *          predictable. Therefore, in that case, show only minor ticks.
 *          Lastly, there should be an appropriate way to handle numbers
 *          <=0.
 *
 *              maxY
 *                |    units = magnitude (of least significant digit)
 *                |    high  = largest unit tick < max axis value
 *          high _|    low   = smallest unit tick > min axis value
 *                |
 *                |    range = high - low
 *                |    # ticks = greatest factor of range/units
 *               _|
 *            U   |
 *            n   |
 *            i   |
 *            t  _|
 *                |
 *                |
 *                |
 *           low _|
 *                |
 *                |_minX________________maxX__
 *                |   |       |      |       |
 *         minY  low                        high
 *               minY
 *
 *
 *      numTicks = Number of ticks
 *      min = Minimum value of axis
 *      max = Maximum value of axis
 *      range    = Range of values (max - min)
 *
 *      If the number of decades is greater than ten, it is assumed
 *      that the full set of log-style ticks can't be drawn properly.
 *
 * Results:
 *      None
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ---------------------------------------------------------------------- */
static void
LogScaleAxis(
    RbcAxis * axisPtr,
    double min,
    double max)
{
    double          range;
    double          tickMin, tickMax;
    double          majorStep, minorStep;
    int             nMajor, nMinor;

    min = (min != 0.0) ? log10(FABS(min)) : 0.0;
    max = (max != 0.0) ? log10(FABS(max)) : 1.0;

    tickMin = floor(min);
    tickMax = ceil(max);
    range = tickMax - tickMin;

    if (range > 10) {
        /* There are too many decades to display a major tick at every
         * decade.  Instead, treat the axis as a linear scale.  */
        range = NiceNum(range, 0);
        majorStep = NiceNum(range / DEF_NUM_TICKS, 1);
        tickMin = UFLOOR(tickMin, majorStep);
        tickMax = UCEIL(tickMax, majorStep);
        nMajor = (int) ((tickMax - tickMin) / majorStep) + 1;
        minorStep = EXP10(floor(log10(majorStep)));
        if (minorStep == majorStep) {
            nMinor = 4, minorStep = 0.2;
        } else {
            nMinor = Round(majorStep / minorStep) - 1;
        }
    } else {
        if (tickMin == tickMax) {
            tickMax++;
        }
        majorStep = 1.0;
        nMajor = (int) (tickMax - tickMin + 1); /* FIXME: Check this. */

        minorStep = 0.0;        /* This is a special hack to pass
                                 * information to the GenerateTicks
                                 * routine. An interval of 0.0 tells
                                 *      1) this is a minor sweep and
                                 *      2) the axis is log scale.
                                 */
        nMinor = 10;
    }
    if ((axisPtr->looseMin == TICK_RANGE_TIGHT) ||
        ((axisPtr->looseMin == TICK_RANGE_LOOSE) &&
            (!TclIsNaN(axisPtr->reqMin)))) {
        tickMin = min;
        nMajor++;
    }
    if ((axisPtr->looseMax == TICK_RANGE_TIGHT) ||
        ((axisPtr->looseMax == TICK_RANGE_LOOSE) &&
            (!TclIsNaN(axisPtr->reqMax)))) {
        tickMax = max;
    }
    axisPtr->majorSweep.step = majorStep;
    axisPtr->majorSweep.initial = floor(tickMin);
    axisPtr->majorSweep.nSteps = nMajor;
    axisPtr->minorSweep.initial = axisPtr->minorSweep.step = minorStep;
    axisPtr->minorSweep.nSteps = nMinor;

    SetAxisRange(&axisPtr->axisRange, tickMin, tickMax);
}

/*
 * ----------------------------------------------------------------------
 *
 * LinearScaleAxis --
 *
 *      Determine the units of a linear scaled axis.
 *
 *      The axis limits are either the range of the data values mapped
 *      to the axis (autoscaled), or the values specified by the -min
 *      and -max options (manual).
 *
 *      If autoscaled, the smallest and largest major ticks will
 *      encompass the range of data values.  If the -loose option is
 *      selected, the next outer ticks are choosen.  If tight, the
 *      ticks are at or inside of the data limits are used.
 *
 *      If manually set, the ticks are at or inside the data limits
 *      are used.  This makes sense for zooming.  You want the
 *      selected range to represent the next limit, not something a
 *      bit bigger.
 *
 *      Note: I added an "always" value to the -loose option to force
 *            the manually selected axes to be loose. It's probably
 *            not a good idea.
 *
 *              maxY
 *                |    units = magnitude (of least significant digit)
 *                |    high  = largest unit tick < max axis value
 *          high _|    low   = smallest unit tick > min axis value
 *                |
 *                |    range = high - low
 *                |    # ticks = greatest factor of range/units
 *               _|
 *            U   |
 *            n   |
 *            i   |
 *            t  _|
 *                |
 *                |
 *                |
 *           low _|
 *                |
 *                |_minX________________maxX__
 *                |   |       |      |       |
 *         minY  low                        high
 *               minY
 *
 *      numTicks = Number of ticks
 *      min = Minimum value of axis
 *      max = Maximum value of axis
 *      range    = Range of values (max - min)
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      The axis tick information is set.  The actual tick values will
 *      be generated later.
 *
 * ----------------------------------------------------------------------
 */
static void
LinearScaleAxis(
    RbcAxis * axisPtr,
    double min,
    double max)
{
    double          range, step;
    double          tickMin, tickMax;
    double          axisMin, axisMax;
    int             nTicks;

    range = max - min;

    /* Calculate the major tick stepping. */
    if (axisPtr->reqStep > 0.0) {
        /* An interval was designated by the user.  Keep scaling it
         * until it fits comfortably within the current range of the
         * axis.  */
        step = axisPtr->reqStep;
        while ((2 * step) >= range) {
            step *= 0.5;
        }
    } else {
        range = NiceNum(range, 0);
        step = NiceNum(range / DEF_NUM_TICKS, 1);
    }

    /* Find the outer tick values. Add 0.0 to prevent getting -0.0. */
    axisMin = tickMin = floor(min / step) * step + 0.0;
    axisMax = tickMax = ceil(max / step) * step + 0.0;

    nTicks = Round((tickMax - tickMin) / step) + 1;
    axisPtr->majorSweep.step = step;
    axisPtr->majorSweep.initial = tickMin;
    axisPtr->majorSweep.nSteps = nTicks;

    /*
     * The limits of the axis are either the range of the data
     * ("tight") or at the next outer tick interval ("loose").  The
     * looseness or tightness has to do with how the axis fits the
     * range of data values.  This option is overridden when
     * the user sets an axis limit (by either -min or -max option).
     * The axis limit is always at the selected limit (otherwise we
     * assume that user would have picked a different number).
     */
    if ((axisPtr->looseMin == TICK_RANGE_TIGHT) ||
        ((axisPtr->looseMin == TICK_RANGE_LOOSE) &&
            (!TclIsNaN(axisPtr->reqMin)))) {
        axisMin = min;
    }
    if ((axisPtr->looseMax == TICK_RANGE_TIGHT) ||
        ((axisPtr->looseMax == TICK_RANGE_LOOSE) &&
            (!TclIsNaN(axisPtr->reqMax)))) {
        axisMax = max;
    }
    SetAxisRange(&axisPtr->axisRange, axisMin, axisMax);

    /* Now calculate the minor tick step and number. */

    if ((axisPtr->reqNumMinorTicks > 0) &&
        ((axisPtr->flags & AXIS_CONFIG_MAJOR) == 0)) {
        nTicks = axisPtr->reqNumMinorTicks - 1;
        step = 1.0 / (nTicks + 1);
    } else {
        nTicks = 0;             /* No minor ticks. */
        step = 0.5;             /* Don't set the minor tick interval
                                 * to 0.0. It makes the GenerateTicks
                                 * routine create minor log-scale tick
                                 * marks.  */
    }
    axisPtr->minorSweep.initial = axisPtr->minorSweep.step = step;
    axisPtr->minorSweep.nSteps = nTicks;
}

/*
 *----------------------------------------------------------------------
 *
 * SweepTicks --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
SweepTicks(
    RbcAxis * axisPtr)
{
    if ((axisPtr->flags & AXIS_CONFIG_MAJOR) == 0) {
        if (axisPtr->t1Ptr != NULL) {
            ckfree((char *) axisPtr->t1Ptr);
        }
        axisPtr->t1Ptr = GenerateTicks(&axisPtr->majorSweep);
    }
    if ((axisPtr->flags & AXIS_CONFIG_MINOR) == 0) {
        if (axisPtr->t2Ptr != NULL) {
            ckfree((char *) axisPtr->t2Ptr);
        }
        axisPtr->t2Ptr = GenerateTicks(&axisPtr->minorSweep);
    }
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcResetAxes --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
void
RbcResetAxes(
    RbcGraph * graphPtr)
{
    RbcChainLink   *linkPtr;
    RbcElement     *elemPtr;
    RbcAxis        *axisPtr;
    Tcl_HashEntry  *hPtr;
    Tcl_HashSearch  cursor;
    RbcExtents2D    exts;
    double          min, max;

    /* FIXME: This should be called whenever the display list of
     *        elements change. Maybe yet another flag INIT_STACKS to
     *        indicate that the element display list has changed.
     *        Needs to be done before the axis limits are set.
     */
    RbcInitFreqTable(graphPtr);
    if ((graphPtr->mode == MODE_STACKED) && (graphPtr->nStacks > 0)) {
        RbcComputeStacks(graphPtr);
    }
    /*
     * Step 1:  Reset all axes. Initialize the data limits of the axis to
     *          impossible values.
     */
    for (hPtr = Tcl_FirstHashEntry(&graphPtr->axes.table, &cursor);
        hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
        axisPtr = (RbcAxis *) Tcl_GetHashValue(hPtr);
        axisPtr->min = axisPtr->valueRange.min = DBL_MAX;
        axisPtr->max = axisPtr->valueRange.max = -DBL_MAX;
    }

    /*
     * Step 2:  For each element that's to be displayed, get the smallest
     *          and largest data values mapped to each X and Y-axis.  This
     *          will be the axis limits if the user doesn't override them
     *          with -min and -max options.
     */
    for (linkPtr = RbcChainFirstLink(graphPtr->elements.displayList);
        linkPtr != NULL; linkPtr = RbcChainNextLink(linkPtr)) {
        elemPtr = RbcChainGetValue(linkPtr);
        (*elemPtr->procsPtr->extentsProc) (elemPtr, &exts);
        GetDataLimits(elemPtr->axes.x, exts.left, exts.right);
        GetDataLimits(elemPtr->axes.y, exts.top, exts.bottom);
    }
    /*
     * Step 3:  Now that we know the range of data values for each axis,
     *          set axis limits and compute a sweep to generate tick values.
     */
    for (hPtr = Tcl_FirstHashEntry(&graphPtr->axes.table, &cursor);
        hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
        axisPtr = (RbcAxis *) Tcl_GetHashValue(hPtr);
        FixAxisRange(axisPtr);

        /* Calculate min/max tick (major/minor) layouts */
        min = axisPtr->min;
        max = axisPtr->max;
        if ((!TclIsNaN(axisPtr->scrollMin)) && (min < axisPtr->scrollMin)) {
            min = axisPtr->scrollMin;
        }
        if ((!TclIsNaN(axisPtr->scrollMax)) && (max > axisPtr->scrollMax)) {
            max = axisPtr->scrollMax;
        }
        if (axisPtr->logScale) {
            LogScaleAxis(axisPtr, min, max);
        } else {
            LinearScaleAxis(axisPtr, min, max);
        }

        if ((axisPtr->flags & (AXIS_DIRTY | AXIS_ONSCREEN)) ==
            (AXIS_DIRTY | AXIS_ONSCREEN)) {
            graphPtr->flags |= RBC_REDRAW_BACKING_STORE;
        }
    }

    graphPtr->flags &= ~RBC_RESET_AXES;

    /*
     * When any axis changes, we need to layout the entire graph.
     */
    graphPtr->flags |= (RBC_GET_AXIS_GEOMETRY | RBC_LAYOUT_NEEDED |
        RBC_MAP_ALL | RBC_REDRAW_WORLD);
}

/*
 * ----------------------------------------------------------------------
 *
 * ResetTextStyles --
 *
 *      Configures axis attributes (font, line width, label, etc) and
 *      allocates a new (possibly shared) graphics context.  Line cap
 *      style is projecting.  This is for the problem of when a tick
 *      sits directly at the end point of the axis.
 *
 * Results:
 *      The return value is a standard Tcl result.
 *
 * Side Effects:
 *      Axis resources are allocated (GC, font). Axis layout is
 *      deferred until the height and width of the window are known.
 *
 * ----------------------------------------------------------------------
 */
static void
ResetTextStyles(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr)
{
    GC              newGC;
    XGCValues       gcValues;
    unsigned long   gcMask;

    RbcResetTextStyle(graphPtr->tkwin, &axisPtr->titleTextStyle);
    RbcResetTextStyle(graphPtr->tkwin, &axisPtr->tickTextStyle);
    RbcResetTextStyle(graphPtr->tkwin, &axisPtr->limitsTextStyle);

    gcMask = (GCForeground | GCLineWidth | GCCapStyle);
    gcValues.foreground = axisPtr->tickTextStyle.color->pixel;
    gcValues.line_width = RbcLineWidth(axisPtr->lineWidth);
    gcValues.cap_style = CapProjecting;

    newGC = Tk_GetGC(graphPtr->tkwin, gcMask, &gcValues);
    if (axisPtr->tickGC != NULL) {
        Tk_FreeGC(graphPtr->display, axisPtr->tickGC);
    }
    axisPtr->tickGC = newGC;
}

/*
 * ----------------------------------------------------------------------
 *
 * DestroyAxis --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Resources (font, color, gc, labels, etc.) associated with the
 *      axis are deallocated.
 *
 * ----------------------------------------------------------------------
 */
static void
DestroyAxis(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr)
{
    int             flags;

    flags = RbcGraphType(graphPtr);
    Tk_FreeOptions(configSpecs, (char *) axisPtr, graphPtr->display, flags);
    if (graphPtr->bindTable != NULL) {
        RbcDeleteBindings(graphPtr->bindTable, axisPtr);
    }
    if (axisPtr->linkPtr != NULL) {
        RbcChainDeleteLink(axisPtr->chainPtr, axisPtr->linkPtr);
    }
    if (axisPtr->name != NULL) {
        ckfree((char *) axisPtr->name);
    }
    if (axisPtr->hashPtr != NULL) {
        Tcl_DeleteHashEntry(axisPtr->hashPtr);
    }
    RbcFreeTextStyle(graphPtr->display, &axisPtr->titleTextStyle);
    RbcFreeTextStyle(graphPtr->display, &axisPtr->limitsTextStyle);
    RbcFreeTextStyle(graphPtr->display, &axisPtr->tickTextStyle);

    if (axisPtr->tickGC != NULL) {
        Tk_FreeGC(graphPtr->display, axisPtr->tickGC);
    }
    if (axisPtr->t1Ptr != NULL) {
        ckfree((char *) axisPtr->t1Ptr);
    }
    if (axisPtr->t2Ptr != NULL) {
        ckfree((char *) axisPtr->t2Ptr);
    }
    if (axisPtr->limitsFormats != NULL) {
        ckfree((char *) axisPtr->limitsFormats);
    }
    FreeLabels(axisPtr->tickLabels);
    RbcChainDestroy(axisPtr->tickLabels);
    if (axisPtr->segments != NULL) {
        ckfree((char *) axisPtr->segments);
    }
    if (axisPtr->tags != NULL) {
        ckfree((char *) axisPtr->tags);
    }
    ckfree((char *) axisPtr);
}

/*
 * ----------------------------------------------------------------------
 *
 * AxisOffsets --
 *
 *      Determines the sites of the axis, major and minor ticks,
 *      and title of the axis.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static void
AxisOffsets(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int margin,
    int axisOffset,
    AxisInfo * infoPtr)
{
    int             pad;        /* Offset of axis from interior region. This
                                 * includes a possible border and the axis
                                 * line width. */
    int             p;
    int             majorOffset, minorOffset, labelOffset;
    int             offset;
    int             x, y;

    axisPtr->titleTextStyle.theta = titleRotate[margin];

    majorOffset = minorOffset = 0;
    labelOffset = AXIS_TITLE_PAD;
    if (axisPtr->lineWidth > 0) {
        majorOffset = ABS(axisPtr->tickLength);
        minorOffset = 10 * majorOffset / 15;
        labelOffset = majorOffset + AXIS_TITLE_PAD + axisPtr->lineWidth / 2;
    }
    /* Adjust offset for the interior border width and the line width */
    pad = axisPtr->lineWidth + 1;
    if (graphPtr->plotBorderWidth > 0) {
        pad += graphPtr->plotBorderWidth + 1;
    }
    offset = axisOffset + 1 + pad;
    if ((margin == RBC_MARGIN_LEFT) || (margin == RBC_MARGIN_TOP)) {
        majorOffset = -majorOffset;
        minorOffset = -minorOffset;
        labelOffset = -labelOffset;
    }
    /*
     * Pre-calculate the x-coordinate positions of the axis, tick labels, and
     * the individual major and minor ticks.
     */
    p = 0;                      /* Suppress compiler warning */

    switch (margin) {
    case RBC_MARGIN_TOP:
        p = graphPtr->top - axisOffset - pad;
        if (axisPtr->titleAlternate) {
            x = graphPtr->right + AXIS_TITLE_PAD;
            y = graphPtr->top - axisOffset - (axisPtr->height / 2);
            axisPtr->titleTextStyle.anchor = TK_ANCHOR_W;
        } else {
            x = (graphPtr->right + graphPtr->left) / 2;
            y = graphPtr->top - axisOffset - axisPtr->height - AXIS_TITLE_PAD;
            axisPtr->titleTextStyle.anchor = TK_ANCHOR_N;
        }
        axisPtr->tickTextStyle.anchor = TK_ANCHOR_S;
        offset = axisPtr->borderWidth + axisPtr->lineWidth / 2;
        axisPtr->region.left = graphPtr->hOffset - offset - 2;
        axisPtr->region.right = graphPtr->hOffset + graphPtr->hRange +
            offset - 1;
        axisPtr->region.top = p + labelOffset - 1;
        axisPtr->region.bottom = p;
        axisPtr->titlePos.x = x;
        axisPtr->titlePos.y = y;
        break;

    case RBC_MARGIN_BOTTOM:
        p = graphPtr->bottom + axisOffset + pad;
        if (axisPtr->titleAlternate) {
            x = graphPtr->right + AXIS_TITLE_PAD;
            y = graphPtr->bottom + axisOffset + (axisPtr->height / 2);
            axisPtr->titleTextStyle.anchor = TK_ANCHOR_W;
        } else {
            x = (graphPtr->right + graphPtr->left) / 2;
            y = graphPtr->bottom + axisOffset + axisPtr->height +
                AXIS_TITLE_PAD;
            axisPtr->titleTextStyle.anchor = TK_ANCHOR_S;
        }
        axisPtr->tickTextStyle.anchor = TK_ANCHOR_N;
        offset = axisPtr->borderWidth + axisPtr->lineWidth / 2;
        axisPtr->region.left = graphPtr->hOffset - offset - 2;
        axisPtr->region.right = graphPtr->hOffset + graphPtr->hRange +
            offset - 1;

        axisPtr->region.top = graphPtr->bottom + axisOffset +
            axisPtr->lineWidth - axisPtr->lineWidth / 2;
        axisPtr->region.bottom = graphPtr->bottom + axisOffset +
            axisPtr->lineWidth + labelOffset + 1;
        axisPtr->titlePos.x = x;
        axisPtr->titlePos.y = y;
        break;

    case RBC_MARGIN_LEFT:
        p = graphPtr->left - axisOffset - pad;
        if (axisPtr->titleAlternate) {
            x = graphPtr->left - axisOffset - (axisPtr->width / 2);
            y = graphPtr->top - AXIS_TITLE_PAD;
            axisPtr->titleTextStyle.anchor = TK_ANCHOR_SW;
        } else {
            x = graphPtr->left - axisOffset - axisPtr->width -
                graphPtr->plotBorderWidth;
            y = (graphPtr->bottom + graphPtr->top) / 2;
            axisPtr->titleTextStyle.anchor = TK_ANCHOR_W;
        }
        axisPtr->tickTextStyle.anchor = TK_ANCHOR_E;
        axisPtr->region.left = graphPtr->left - offset + labelOffset - 1;
        axisPtr->region.right = graphPtr->left - offset + 2;

        offset = axisPtr->borderWidth + axisPtr->lineWidth / 2;
        axisPtr->region.top = graphPtr->vOffset - offset - 2;
        axisPtr->region.bottom = graphPtr->vOffset + graphPtr->vRange +
            offset - 1;
        axisPtr->titlePos.x = x;
        axisPtr->titlePos.y = y;
        break;

    case RBC_MARGIN_RIGHT:
        p = graphPtr->right + axisOffset + pad;
        if (axisPtr->titleAlternate) {
            x = graphPtr->right + axisOffset + (axisPtr->width / 2);
            y = graphPtr->top - AXIS_TITLE_PAD;
            axisPtr->titleTextStyle.anchor = TK_ANCHOR_SE;
        } else {
            x = graphPtr->right + axisOffset + axisPtr->width + AXIS_TITLE_PAD;
            y = (graphPtr->bottom + graphPtr->top) / 2;
            axisPtr->titleTextStyle.anchor = TK_ANCHOR_E;
        }
        axisPtr->tickTextStyle.anchor = TK_ANCHOR_W;

        axisPtr->region.left = graphPtr->right + axisOffset +
            axisPtr->lineWidth - axisPtr->lineWidth / 2;
        axisPtr->region.right = graphPtr->right + axisOffset +
            labelOffset + axisPtr->lineWidth + 1;

        offset = axisPtr->borderWidth + axisPtr->lineWidth / 2;
        axisPtr->region.top = graphPtr->vOffset - offset - 2;
        axisPtr->region.bottom = graphPtr->vOffset + graphPtr->vRange +
            offset - 1;
        axisPtr->titlePos.x = x;
        axisPtr->titlePos.y = y;
        break;

    case RBC_MARGIN_NONE:
        break;
    }
    infoPtr->axis = p - (axisPtr->lineWidth / 2);
    infoPtr->t1 = p + majorOffset;
    infoPtr->t2 = p + minorOffset;
    infoPtr->label = p + labelOffset;

    if (axisPtr->tickLength < 0) {
        int             hold;

        hold = infoPtr->t1;
        infoPtr->t1 = infoPtr->axis;
        infoPtr->axis = hold;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MakeAxisLine --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
MakeAxisLine(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,          /* Axis information */
    int line,
    RbcSegment2D * segPtr)
{
    double          min, max;

    min = axisPtr->axisRange.min;
    max = axisPtr->axisRange.max;
    if (axisPtr->logScale) {
        min = EXP10(min);
        max = EXP10(max);
    }
    if (AxisIsHorizontal(graphPtr, axisPtr)) {
        segPtr->p.x = RbcHMap(graphPtr, axisPtr, min);
        segPtr->q.x = RbcHMap(graphPtr, axisPtr, max);
        segPtr->p.y = segPtr->q.y = line;
    } else {
        segPtr->q.x = segPtr->p.x = line;
        segPtr->p.y = RbcVMap(graphPtr, axisPtr, min);
        segPtr->q.y = RbcVMap(graphPtr, axisPtr, max);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MakeTick --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
MakeTick(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double value,
    int tick,                   /* Lengths of tick. */
    int line,                   /* Lengths of axis line. */
    RbcSegment2D * segPtr)
{
    if (axisPtr->logScale) {
        value = EXP10(value);
    }
    if (AxisIsHorizontal(graphPtr, axisPtr)) {
        segPtr->p.x = segPtr->q.x = RbcHMap(graphPtr, axisPtr, value);
        segPtr->p.y = line;
        segPtr->q.y = tick;
    } else {
        segPtr->p.x = line;
        segPtr->p.y = segPtr->q.y = RbcVMap(graphPtr, axisPtr, value);
        segPtr->q.x = tick;
    }
}

/*
 * -----------------------------------------------------------------
 *
 * MapAxis --
 *
 *      Pre-calculates positions of the axis, ticks, and labels (to be
 *      used later when displaying the axis).  Calculates the values
 *      for each major and minor tick and checks to see if they are in
 *      range (the outer ticks may be outside of the range of plotted
 *      values).
 *
 *      Line segments for the minor and major ticks are saved into one
 *      XSegment array so that they can be drawn by a single
 *      XDrawSegments call. The positions of the tick labels are also
 *      computed and saved.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      Line segments and tick labels are saved and used later to draw
 *      the axis.
 *
 * -----------------------------------------------------------------
 */
static void
MapAxis(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int offset,
    int margin)
{
    int             arraySize;
    int             nMajorTicks, nMinorTicks;
    AxisInfo        info;
    RbcSegment2D   *segments;
    RbcSegment2D   *segPtr;

    AxisOffsets(graphPtr, axisPtr, margin, offset, &info);

    /* Save all line coordinates in an array of line segments. */

    if (axisPtr->segments != NULL) {
        ckfree((char *) axisPtr->segments);
    }
    nMajorTicks = nMinorTicks = 0;
    if (axisPtr->t1Ptr != NULL) {
        nMajorTicks = axisPtr->t1Ptr->nTicks;
    }
    if (axisPtr->t2Ptr != NULL) {
        nMinorTicks = axisPtr->t2Ptr->nTicks;
    }
    arraySize = 1 + (nMajorTicks * (nMinorTicks + 1));
    segments = (RbcSegment2D *) ckalloc(arraySize * sizeof(RbcSegment2D));
    assert(segments);

    segPtr = segments;
    if (axisPtr->lineWidth > 0) {
        /* Axis baseline */
        MakeAxisLine(graphPtr, axisPtr, info.axis, segPtr);
        segPtr++;
    }
    if (axisPtr->showTicks) {
        double          t1, t2;
        double          labelPos;
        register int    i, j;
        int             isHoriz;
        TickLabel      *labelPtr;
        RbcChainLink   *linkPtr;
        RbcSegment2D    seg;

        isHoriz = AxisIsHorizontal(graphPtr, axisPtr);
        for (i = 0; i < axisPtr->t1Ptr->nTicks; i++) {
            t1 = axisPtr->t1Ptr->values[i];
            /* Minor ticks */
            for (j = 0; j < axisPtr->t2Ptr->nTicks; j++) {
                t2 = t1 +
                    (axisPtr->majorSweep.step * axisPtr->t2Ptr->values[j]);
                if (InRange(t2, &axisPtr->axisRange)) {
                    MakeTick(graphPtr, axisPtr, t2, info.t2, info.axis, segPtr);
                    segPtr++;
                }
            }
            if (!InRange(t1, &axisPtr->axisRange)) {
                continue;
            }
            /* Major tick */
            MakeTick(graphPtr, axisPtr, t1, info.t1, info.axis, segPtr);
            segPtr++;
        }

        linkPtr = RbcChainFirstLink(axisPtr->tickLabels);
        labelPos = (double) info.label;

        for (i = 0; i < axisPtr->t1Ptr->nTicks; i++) {
            t1 = axisPtr->t1Ptr->values[i];
            if (axisPtr->labelOffset) {
                t1 += axisPtr->majorSweep.step * 0.5;
            }
            if (!InRange(t1, &axisPtr->axisRange)) {
                continue;
            }
            labelPtr = RbcChainGetValue(linkPtr);
            linkPtr = RbcChainNextLink(linkPtr);
            MakeTick(graphPtr, axisPtr, t1, info.t1, info.axis, &seg);
            /* Save tick label X-Y position. */
            if (isHoriz) {
                labelPtr->anchorPos.x = seg.p.x;
                labelPtr->anchorPos.y = labelPos;
            } else {
                labelPtr->anchorPos.x = labelPos;
                labelPtr->anchorPos.y = seg.p.y;
            }
        }
    }
    if (AxisIsHorizontal(graphPtr, axisPtr)) {
        axisPtr->width = graphPtr->right - graphPtr->left;
    } else {
        axisPtr->height = graphPtr->bottom - graphPtr->top;
    }
    axisPtr->segments = segments;
    axisPtr->nSegments = segPtr - segments;
    assert(axisPtr->nSegments <= arraySize);
}

/*
 *----------------------------------------------------------------------
 *
 * AdjustViewport --
 *
 *      Adjusts the offsets of the viewport according to the scroll mode.
 *      This is to accommodate both "listbox" and "canvas" style scrolling.
 *
 *      "canvas"	The viewport scrolls within the range of world
 *              coordinates.  This way the viewport always displays
 *              a full page of the world.  If the world is smaller
 *              than the viewport, then (bizarrely) the world and
 *              viewport are inverted so that the world moves up
 *              and down within the viewport.
 *
 *      "listbox"	The viewport can scroll beyond the range of world
 *              coordinates.  Every entry can be displayed at the
 *              top of the viewport.  This also means that the
 *              scrollbar thumb weirdly shrinks as the last entry
 *              is scrolled upward.
 *
 * Results:
 *      The corrected offset is returned.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static double
AdjustViewport(
    double offset,
    double windowSize)
{
    /*
     * Canvas-style scrolling allows the world to be scrolled
     * within the window.
     */
    if (windowSize > 1.0) {
        if (windowSize < (1.0 - offset)) {
            offset = 1.0 - windowSize;
        }
        if (offset > 0.0) {
            offset = 0.0;
        }
    } else {
        if ((offset + windowSize) > 1.0) {
            offset = 1.0 - windowSize;
        }
        if (offset < 0.0) {
            offset = 0.0;
        }
    }
    return offset;
}

/*
 *----------------------------------------------------------------------
 *
 * GetAxisScrollInfo --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
GetAxisScrollInfo(
    Tcl_Interp * interp,
    int argc,
    const char **argv,
    double *offsetPtr,
    double windowSize,
    double scrollUnits)
{
    char            c;
    unsigned int    length;
    double          offset;
    int             count;
    double          fract;

    offset = *offsetPtr;
    c = argv[0][0];
    length = strlen(argv[0]);
    if ((c == 's') && (strncmp(argv[0], "scroll", length) == 0)) {
        assert(argc == 3);
        /* scroll number unit/page */
        if (Tcl_GetInt(interp, argv[1], &count) != TCL_OK) {
            return TCL_ERROR;
        }
        c = argv[2][0];
        length = strlen(argv[2]);
        if ((c == 'u') && (strncmp(argv[2], "units", length) == 0)) {
            fract = (double) count *scrollUnits;
        } else if ((c == 'p') && (strncmp(argv[2], "pages", length) == 0)) {
            /* A page is 90% of the view-able window. */
            fract = (double) count *windowSize * 0.9;
        } else {
            Tcl_AppendResult(interp, "unknown \"scroll\" units \"", argv[2],
                "\"", (char *) NULL);
            return TCL_ERROR;
        }
        offset += fract;
    } else if ((c == 'm') && (strncmp(argv[0], "moveto", length) == 0)) {
        assert(argc == 2);
        /* moveto fraction */
        if (Tcl_GetDouble(interp, argv[1], &fract) != TCL_OK) {
            return TCL_ERROR;
        }
        offset = fract;
    } else {
        /* Treat like "scroll units" */
        if (Tcl_GetInt(interp, argv[0], &count) != TCL_OK) {
            return TCL_ERROR;
        }
        fract = (double) count *scrollUnits;
        offset += fract;
        /* CHECK THIS: return TCL_OK; */
    }
    *offsetPtr = AdjustViewport(offset, windowSize);
    return TCL_OK;
}

/*
 * -----------------------------------------------------------------
 *
 * DrawAxis --
 *
 *      Draws the axis, ticks, and labels onto the canvas.
 *
 *      Initializes and passes text attribute information through
 *      TextStyle structure.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      Axis gets drawn on window.
 *
 * -----------------------------------------------------------------
 */
static void
DrawAxis(
    RbcGraph * graphPtr,
    Drawable drawable,
    RbcAxis * axisPtr)
{
    if (axisPtr->border != NULL) {
        RbcFill3DRectangle(graphPtr->tkwin, drawable, axisPtr->border,
            axisPtr->region.left + graphPtr->plotBorderWidth,
            axisPtr->region.top + graphPtr->plotBorderWidth,
            axisPtr->region.right - axisPtr->region.left,
            axisPtr->region.bottom - axisPtr->region.top,
            axisPtr->borderWidth, axisPtr->relief);
    }
    if (axisPtr->title != NULL) {
        RbcDrawText(graphPtr->tkwin, drawable, axisPtr->title,
            &axisPtr->titleTextStyle, (int) axisPtr->titlePos.x,
            (int) axisPtr->titlePos.y);
    }
    if (axisPtr->scrollCmdPrefix != NULL) {
        double          viewWidth, viewMin, viewMax;
        double          worldWidth, worldMin, worldMax;
        double          fract;
        int             isHoriz;

        worldMin = axisPtr->valueRange.min;
        worldMax = axisPtr->valueRange.max;
        if (!TclIsNaN(axisPtr->scrollMin)) {
            worldMin = axisPtr->scrollMin;
        }
        if (!TclIsNaN(axisPtr->scrollMax)) {
            worldMax = axisPtr->scrollMax;
        }
        viewMin = axisPtr->min;
        viewMax = axisPtr->max;
        if (viewMin < worldMin) {
            viewMin = worldMin;
        }
        if (viewMax > worldMax) {
            viewMax = worldMax;
        }
        if (axisPtr->logScale) {
            worldMin = log10(worldMin);
            worldMax = log10(worldMax);
            viewMin = log10(viewMin);
            viewMax = log10(viewMax);
        }
        worldWidth = worldMax - worldMin;
        viewWidth = viewMax - viewMin;
        isHoriz = AxisIsHorizontal(graphPtr, axisPtr);

        if (isHoriz != axisPtr->descending) {
            fract = (viewMin - worldMin) / worldWidth;
        } else {
            fract = (worldMax - viewMax) / worldWidth;
        }
        fract = AdjustViewport(fract, viewWidth / worldWidth);

        if (isHoriz != axisPtr->descending) {
            viewMin = (fract * worldWidth);
            axisPtr->min = viewMin + worldMin;
            axisPtr->max = axisPtr->min + viewWidth;
            viewMax = viewMin + viewWidth;
            if (axisPtr->logScale) {
                axisPtr->min = EXP10(axisPtr->min);
                axisPtr->max = EXP10(axisPtr->max);
            }
            RbcUpdateScrollbar(graphPtr->interp, axisPtr->scrollCmdPrefix,
                (viewMin / worldWidth), (viewMax / worldWidth));
        } else {
            viewMax = (fract * worldWidth);
            axisPtr->max = worldMax - viewMax;
            axisPtr->min = axisPtr->max - viewWidth;
            viewMin = viewMax + viewWidth;
            if (axisPtr->logScale) {
                axisPtr->min = EXP10(axisPtr->min);
                axisPtr->max = EXP10(axisPtr->max);
            }
            RbcUpdateScrollbar(graphPtr->interp, axisPtr->scrollCmdPrefix,
                (viewMax / worldWidth), (viewMin / worldWidth));
        }
    }
    if (axisPtr->showTicks) {
        register RbcChainLink *linkPtr;
        TickLabel      *labelPtr;

        for (linkPtr = RbcChainFirstLink(axisPtr->tickLabels); linkPtr != NULL;
            linkPtr = RbcChainNextLink(linkPtr)) {
            /* Draw major tick labels */
            labelPtr = RbcChainGetValue(linkPtr);
            RbcDrawText(graphPtr->tkwin, drawable, labelPtr->string,
                &axisPtr->tickTextStyle, (int) labelPtr->anchorPos.x,
                (int) labelPtr->anchorPos.y);
        }
    }
    if ((axisPtr->nSegments > 0) && (axisPtr->lineWidth > 0)) {
        /* Draw the tick marks and axis line. */
        RbcDraw2DSegments(graphPtr->display, drawable, axisPtr->tickGC,
            axisPtr->segments, axisPtr->nSegments);
    }
}

/*
 * -----------------------------------------------------------------
 *
 * AxisToPostScript --
 *
 *      Generates PostScript output to draw the axis, ticks, and
 *      labels.
 *
 *      Initializes and passes text attribute information through
 *      TextStyle structure.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      PostScript output is left in graphPtr->interp->result;
 *
 * -----------------------------------------------------------------
 */
static void
AxisToPostScript(
    RbcPsToken * psToken,
    RbcAxis * axisPtr)
{
    if (axisPtr->title != NULL) {
        RbcTextToPostScript(psToken, axisPtr->title, &axisPtr->titleTextStyle,
            axisPtr->titlePos.x, axisPtr->titlePos.y);
    }
    if (axisPtr->showTicks) {
        register RbcChainLink *linkPtr;
        TickLabel      *labelPtr;

        for (linkPtr = RbcChainFirstLink(axisPtr->tickLabels);
            linkPtr != NULL; linkPtr = RbcChainNextLink(linkPtr)) {
            labelPtr = RbcChainGetValue(linkPtr);
            RbcTextToPostScript(psToken, labelPtr->string,
                &axisPtr->tickTextStyle, labelPtr->anchorPos.x,
                labelPtr->anchorPos.y);
        }
    }
    if ((axisPtr->nSegments > 0) && (axisPtr->lineWidth > 0)) {
        RbcLineAttributesToPostScript(psToken, axisPtr->tickTextStyle.color,
            axisPtr->lineWidth, (RbcDashes *) NULL, CapButt, JoinMiter);
        Rbc2DSegmentsToPostScript(psToken, axisPtr->segments,
            axisPtr->nSegments);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * MakeGridLine --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
MakeGridLine(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    double value,
    RbcSegment2D * segPtr)
{
    if (axisPtr->logScale) {
        value = EXP10(value);
    }
    /* Grid lines run orthogonally to the axis */
    if (AxisIsHorizontal(graphPtr, axisPtr)) {
        segPtr->p.y = graphPtr->top;
        segPtr->q.y = graphPtr->bottom;
        segPtr->p.x = segPtr->q.x = RbcHMap(graphPtr, axisPtr, value);
    } else {
        segPtr->p.x = graphPtr->left;
        segPtr->q.x = graphPtr->right;
        segPtr->p.y = segPtr->q.y = RbcVMap(graphPtr, axisPtr, value);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGetAxisSegments --
 *
 *      Assembles the grid lines associated with an axis. Generates
 *      tick positions if necessary (this happens when the axis is
 *      not a logical axis too).
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcGetAxisSegments(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    RbcSegment2D ** segPtrPtr,
    int *nSegmentsPtr)
{
    int             needed;
    RbcTicks       *t1Ptr, *t2Ptr;
    register int    i;
    double          value;
    RbcSegment2D   *segments, *segPtr;

    *nSegmentsPtr = 0;
    *segPtrPtr = NULL;
    if (axisPtr == NULL) {
        return;
    }
    t1Ptr = axisPtr->t1Ptr;
    if (t1Ptr == NULL) {
        t1Ptr = GenerateTicks(&axisPtr->majorSweep);
    }
    t2Ptr = axisPtr->t2Ptr;
    if (t2Ptr == NULL) {
        t2Ptr = GenerateTicks(&axisPtr->minorSweep);
    }

    needed = t1Ptr->nTicks;
    if (graphPtr->gridPtr->minorGrid) {
        needed += (t1Ptr->nTicks * t2Ptr->nTicks);
    }
    if (needed == 0) {
        return;
    }
    segments = (RbcSegment2D *) ckalloc(sizeof(RbcSegment2D) * needed);
    if (segments == NULL) {
        return;                 /* Can't allocate memory for grid. */
    }

    segPtr = segments;
    for (i = 0; i < t1Ptr->nTicks; i++) {
        value = t1Ptr->values[i];
        if (graphPtr->gridPtr->minorGrid) {
            register int    j;
            double          subValue;

            for (j = 0; j < t2Ptr->nTicks; j++) {
                subValue = value +
                    (axisPtr->majorSweep.step * t2Ptr->values[j]);
                if (InRange(subValue, &axisPtr->axisRange)) {
                    MakeGridLine(graphPtr, axisPtr, subValue, segPtr);
                    segPtr++;
                }
            }
        }
        if (InRange(value, &axisPtr->axisRange)) {
            MakeGridLine(graphPtr, axisPtr, value, segPtr);
            segPtr++;
        }
    }

    if (t1Ptr != axisPtr->t1Ptr) {
        ckfree((char *) t1Ptr); /* Free generated ticks. */
    }
    if (t2Ptr != axisPtr->t2Ptr) {
        ckfree((char *) t2Ptr); /* Free generated ticks. */
    }
    *nSegmentsPtr = segPtr - segments;
    assert(*nSegmentsPtr <= needed);
    *segPtrPtr = segments;
}

/*
 *----------------------------------------------------------------------
 *
 * GetAxisGeometry --
 *
 *      TODO: Description
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
GetAxisGeometry(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr)
{
    int             height;

    FreeLabels(axisPtr->tickLabels);
    height = 0;
    if (axisPtr->lineWidth > 0) {
        /* Leave room for axis baseline (and pad) */
        height += axisPtr->lineWidth + 2;
    }
    if (axisPtr->showTicks) {
        int             pad;
        register int    i, nLabels;
        int             lw, lh;
        double          x, x2;
        int             maxWidth, maxHeight;
        TickLabel      *labelPtr;

        SweepTicks(axisPtr);

        if (axisPtr->t1Ptr->nTicks < 0) {
            fprintf(stderr, "%s major ticks can't be %d\n",
                axisPtr->name, axisPtr->t1Ptr->nTicks);
            abort();
        }
        if (axisPtr->t1Ptr->nTicks > MAXTICKS) {
            fprintf(stderr, "too big, %s major ticks can't be %d\n",
                axisPtr->name, axisPtr->t1Ptr->nTicks);
            abort();
        }

        maxHeight = maxWidth = 0;
        nLabels = 0;
        for (i = 0; i < axisPtr->t1Ptr->nTicks; i++) {
            x2 = x = axisPtr->t1Ptr->values[i];
            if (axisPtr->labelOffset) {
                x2 += axisPtr->majorSweep.step * 0.5;
            }
            if (!InRange(x2, &axisPtr->axisRange)) {
                continue;
            }
            labelPtr = MakeLabel(graphPtr, axisPtr, x);
            RbcChainAppend(axisPtr->tickLabels, labelPtr);
            nLabels++;
            /*
             * Get the dimensions of each tick label.
             * Remember tick labels can be multi-lined and/or rotated.
             */
            RbcGetTextExtents(&axisPtr->tickTextStyle, labelPtr->string,
                &lw, &lh);
            labelPtr->width = lw;
            labelPtr->height = lh;

            if (axisPtr->tickTextStyle.theta > 0.0) {
                double          rotWidth, rotHeight;

                RbcGetBoundingBox(lw, lh, axisPtr->tickTextStyle.theta,
                    &rotWidth, &rotHeight, (RbcPoint2D *) NULL);
                lw = ROUND(rotWidth);
                lh = ROUND(rotHeight);
            }
            if (maxWidth < lw) {
                maxWidth = lw;
            }
            if (maxHeight < lh) {
                maxHeight = lh;
            }
        }
        assert(nLabels <= axisPtr->t1Ptr->nTicks);

        /* Because the axis cap style is "CapProjecting", we need to
         * account for an extra 1.5 linewidth at the end of each
         * line.  */

        pad = ((axisPtr->lineWidth * 15) / 10);

        if (AxisIsHorizontal(graphPtr, axisPtr)) {
            height += maxHeight + pad;
        } else {
            height += maxWidth + pad;
        }
        if (axisPtr->lineWidth > 0) {
            /* Distance from axis line to tick label. */
            height += AXIS_TITLE_PAD;
            height += ABS(axisPtr->tickLength);
        }
    }

    if (axisPtr->title != NULL) {
        if (axisPtr->titleAlternate) {
            if (height < axisPtr->titleHeight) {
                height = axisPtr->titleHeight;
            }
        } else {
            height += axisPtr->titleHeight + AXIS_TITLE_PAD;
        }
    }

    /* Correct for orientation of the axis. */
    if (AxisIsHorizontal(graphPtr, axisPtr)) {
        axisPtr->height = height;
    } else {
        axisPtr->width = height;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GetMarginGeometry --
 *
 *      Examines all the axes in the given margin and determines the
 *      area required to display them.
 *
 *      Note: For multiple axes, the titles are displayed in another
 *            margin. So we must keep track of the widest title.
 *
 * Results:
 *      Returns the width or height of the margin, depending if it
 *      runs horizontally along the graph or vertically.
 *
 * Side Effects:
 *      The area width and height set in the margin.  Note again that
 *      this may be corrected later (mulitple axes) to adjust for
 *      the longest title in another margin.
 *
 *----------------------------------------------------------------------
 */
static int
GetMarginGeometry(
    RbcGraph * graphPtr,
    RbcMargin * marginPtr)
{
    RbcChainLink   *linkPtr;
    RbcAxis        *axisPtr;
    int             width, height;
    int             isHoriz;
    int             length, count;

    isHoriz = HORIZMARGIN(marginPtr);
    /* Count the number of visible axes. */
    count = 0;
    length = width = height = 0;
    for (linkPtr = RbcChainFirstLink(marginPtr->axes); linkPtr != NULL;
        linkPtr = RbcChainNextLink(linkPtr)) {
        axisPtr = RbcChainGetValue(linkPtr);
        if ((!axisPtr->hidden) && (axisPtr->flags & AXIS_ONSCREEN)) {
            count++;
            if (graphPtr->flags & RBC_GET_AXIS_GEOMETRY) {
                GetAxisGeometry(graphPtr, axisPtr);
            }
            if ((axisPtr->titleAlternate) && (length < axisPtr->titleWidth)) {
                length = axisPtr->titleWidth;
            }
            if (isHoriz) {
                height += axisPtr->height;
            } else {
                width += axisPtr->width;
            }
        }
    }
    /* Enforce a minimum size for margins. */
    if (width < 3) {
        width = 3;
    }
    if (height < 3) {
        height = 3;
    }
    marginPtr->nAxes = count;
    marginPtr->axesTitleLength = length;
    marginPtr->width = width;
    marginPtr->height = height;
    marginPtr->axesOffset = (HORIZMARGIN(marginPtr)) ? height : width;
    return marginPtr->axesOffset;
}

/*
 *----------------------------------------------------------------------
 *
 * ComputeMargins --
 *
 *      Computes the size of the margins and the plotting area.  We
 *      first compute the space needed for the axes in each margin.
 *      Then how much space the legend will occupy.  Finally, if the
 *      user has requested a margin size, we override the computed
 *      value.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *---------------------------------------------------------------------- */
static void
ComputeMargins(
    RbcGraph * graphPtr)
{
    int             left, right, top, bottom;
    int             width, height;
    int             insets;

    /*
     * Step 1:  Compute the amount of space needed to display the
     *          axes (there many be 0 or more) associated with the
     *          margin.
     */
    top = GetMarginGeometry(graphPtr, &graphPtr->margins[RBC_MARGIN_TOP]);
    bottom = GetMarginGeometry(graphPtr, &graphPtr->margins[RBC_MARGIN_BOTTOM]);
    left = GetMarginGeometry(graphPtr, &graphPtr->margins[RBC_MARGIN_LEFT]);
    right = GetMarginGeometry(graphPtr, &graphPtr->margins[RBC_MARGIN_RIGHT]);

    /*
     * Step 2:  Add the graph title height to the top margin.
     */
    if (graphPtr->title != NULL) {
        top += graphPtr->titleTextStyle.height;
    }
    insets = 2 * (graphPtr->inset + graphPtr->plotBorderWidth);

    /*
     * Step 3:  Use the current estimate of the plot area to compute
     *          the legend size.  Add it to the proper margin.
     */
    width = graphPtr->width - (insets + left + right);
    height = graphPtr->height - (insets + top + bottom);
    RbcMapLegend(graphPtr->legend, width, height);
    if (!RbcLegendIsHidden(graphPtr->legend)) {
        switch (RbcLegendSite(graphPtr->legend)) {
        case RBC_LEGEND_RIGHT:
            right += RbcLegendWidth(graphPtr->legend) + 2;
            break;
        case RBC_LEGEND_LEFT:
            left += RbcLegendWidth(graphPtr->legend) + 2;
            break;
        case RBC_LEGEND_TOP:
            top += RbcLegendHeight(graphPtr->legend) + 2;
            break;
        case RBC_LEGEND_BOTTOM:
            bottom += RbcLegendHeight(graphPtr->legend) + 2;
            break;
        case RBC_LEGEND_XY:
        case RBC_LEGEND_PLOT:
        case RBC_LEGEND_WINDOW:
            /* Do nothing. */
            break;
        }
    }

    /*
     * Recompute the plotarea, now accounting for the legend.
     */
    width = graphPtr->width - (insets + left + right);
    height = graphPtr->height - (insets + top + bottom);

    /*
     * Step 5:  If necessary, correct for the requested plot area
     *          aspect ratio.
     */
    if (graphPtr->aspect > 0.0) {
        double          ratio;

        /*
         * Shrink one dimension of the plotarea to fit the requested
         * width/height aspect ratio.
         */
        ratio = (double) width / (double) height;
        if (ratio > graphPtr->aspect) {
            int             scaledWidth;

            /* Shrink the width. */
            scaledWidth = (int) (height * graphPtr->aspect);
            if (scaledWidth < 1) {
                scaledWidth = 1;
            }
            right += (width - scaledWidth);     /* Add the difference to
                                                 * the right margin. */
            /* CHECK THIS: width = scaledWidth; */
        } else {
            int             scaledHeight;

            /* Shrink the height. */
            scaledHeight = (int) (width / graphPtr->aspect);
            if (scaledHeight < 1) {
                scaledHeight = 1;
            }
            top += (height - scaledHeight);     /* Add the difference to
                                                 * the top margin. */
            /* CHECK THIS: height = scaledHeight; */
        }
    }

    /*
     * Step 6:  If there's multiple axes in a margin, the axis
     *          titles will be displayed in the adjoining marging.
     *          Make sure there's room for the longest axis titles.
     */

    if (top < graphPtr->margins[RBC_MARGIN_LEFT].axesTitleLength) {
        top = graphPtr->margins[RBC_MARGIN_LEFT].axesTitleLength;
    }
    if (right < graphPtr->margins[RBC_MARGIN_BOTTOM].axesTitleLength) {
        right = graphPtr->margins[RBC_MARGIN_BOTTOM].axesTitleLength;
    }
    if (top < graphPtr->margins[RBC_MARGIN_RIGHT].axesTitleLength) {
        top = graphPtr->margins[RBC_MARGIN_RIGHT].axesTitleLength;
    }
    if (right < graphPtr->margins[RBC_MARGIN_TOP].axesTitleLength) {
        right = graphPtr->margins[RBC_MARGIN_TOP].axesTitleLength;
    }

    /*
     * Step 7:  Override calculated values with requested margin
     *          sizes.
     */

    graphPtr->margins[RBC_MARGIN_LEFT].width = left;
    graphPtr->margins[RBC_MARGIN_RIGHT].width = right;
    graphPtr->margins[RBC_MARGIN_TOP].height = top;
    graphPtr->margins[RBC_MARGIN_BOTTOM].height = bottom;

    if (graphPtr->margins[RBC_MARGIN_LEFT].reqSize > 0) {
        graphPtr->margins[RBC_MARGIN_LEFT].width = graphPtr->margins[RBC_MARGIN_LEFT].reqSize;
    }
    if (graphPtr->margins[RBC_MARGIN_RIGHT].reqSize > 0) {
        graphPtr->margins[RBC_MARGIN_RIGHT].width = graphPtr->margins[RBC_MARGIN_RIGHT].reqSize;
    }
    if (graphPtr->margins[RBC_MARGIN_TOP].reqSize > 0) {
        graphPtr->margins[RBC_MARGIN_TOP].height = graphPtr->margins[RBC_MARGIN_TOP].reqSize;
    }
    if (graphPtr->margins[RBC_MARGIN_BOTTOM].reqSize > 0) {
        graphPtr->margins[RBC_MARGIN_BOTTOM].height = graphPtr->margins[RBC_MARGIN_BOTTOM].reqSize;
    }
}

/*
 * -----------------------------------------------------------------
 *
 * RbcLayoutMargins --
 *
 *      Calculate the layout of the graph.  Based upon the data,
 *      axis limits, X and Y titles, and title height, determine
 *      the cavity left which is the plotting surface.  The first
 *      step get the data and axis limits for calculating the space
 *      needed for the top, bottom, left, and right margins.
 *
 *      1) The LEFT margin is the area from the left border to the
 *         Y axis (not including ticks). It composes the border
 *         width, the width an optional Y axis label and its padding,
 *         and the tick numeric labels. The Y axis label is rotated
 *         90 degrees so that the width is the font height.
 *
 *      2) The RIGHT margin is the area from the end of the graph
 *         to the right window border. It composes the border width,
 *         some padding, the font height (this may be dubious. It
 *         appears to provide a more even border), the max of the
 *         legend width and 1/2 max X tick number. This last part is
 *         so that the last tick label is not clipped.
 *
 *               Window Width
 *          ___________________________________________________________
 *          |          |                               |               |
 *          |          |   TOP  height of title        |               |
 *          |          |                               |               |
 *          |          |           x2 title            |               |
 *          |          |                               |               |
 *          |          |        height of x2-axis      |               |
 *          |__________|_______________________________|_______________|  W
 *          |          | -plotpady                     |               |  i
 *          |__________|_______________________________|_______________|  n
 *          |          | top                   right   |               |  d
 *          |          |                               |               |  o
 *          |   LEFT   |                               |     RIGHT     |  w
 *          |          |                               |               |
 *          | y        |     Free area = 104%          |      y2       |  H
 *          |          |     Plotting surface = 100%   |               |  e
 *          | t        |     Tick length = 2 + 2%      |      t        |  i
 *          | i        |                               |      i        |  g
 *          | t        |                               |      t  legend|  h
 *          | l        |                               |      l   width|  t
 *          | e        |                               |      e        |
 *          |    height|                               |height         |
 *          |       of |                               | of            |
 *          |    y-axis|                               |y2-axis        |
 *          |          |                               |               |
 *          |          |origin 0,0                     |               |
 *          |__________|_left___________________bottom___|_______________|
 *          |          |-plotpady                      |               |
 *          |__________|_______________________________|_______________|
 *          |          | (xoffset, yoffset)            |               |
 *          |          |                               |               |
 *          |          |       height of x-axis        |               |
 *          |          |                               |               |
 *          |          |   BOTTOM   x title            |               |
 *          |__________|_______________________________|_______________|
 *
 *      3) The TOP margin is the area from the top window border to the top
 *         of the graph. It composes the border width, twice the height of
 *         the title font (if one is given) and some padding between the
 *         title.
 *
 *      4) The BOTTOM margin is area from the bottom window border to the
 *         X axis (not including ticks). It composes the border width, the height
 *         an optional X axis label and its padding, the height of the font
 *         of the tick labels.
 *
 *      The plotting area is between the margins which includes the X and Y axes
 *      including the ticks but not the tick numeric labels. The length of
 *      the ticks and its padding is 5% of the entire plotting area.  Hence the
 *      entire plotting area is scaled as 105% of the width and height of the
 *      area.
 *
 *      The axis labels, ticks labels, title, and legend may or may not be
 *      displayed which must be taken into account.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * -----------------------------------------------------------------
 */
void
RbcLayoutMargins(
    RbcGraph * graphPtr)
{
    int             width, height;
    int             titleY;
    int             left, right, top, bottom;

    ComputeMargins(graphPtr);
    left = graphPtr->margins[RBC_MARGIN_LEFT].width + graphPtr->inset +
        graphPtr->plotBorderWidth;
    right = graphPtr->margins[RBC_MARGIN_RIGHT].width + graphPtr->inset +
        graphPtr->plotBorderWidth;
    top = graphPtr->margins[RBC_MARGIN_TOP].height + graphPtr->inset +
        graphPtr->plotBorderWidth;
    bottom = graphPtr->margins[RBC_MARGIN_BOTTOM].height + graphPtr->inset +
        graphPtr->plotBorderWidth;

    /* Based upon the margins, calculate the space left for the graph. */
    width = graphPtr->width - (left + right);
    height = graphPtr->height - (top + bottom);
    if (width < 1) {
        width = 1;
    }
    if (height < 1) {
        height = 1;
    }
    graphPtr->left = left;
    graphPtr->right = left + width;
    graphPtr->bottom = top + height;
    graphPtr->top = top;

    graphPtr->vOffset = top + graphPtr->padY.side1;     /*top */
    graphPtr->vRange = height - RbcPadding(graphPtr->padY);
    graphPtr->hOffset = left + graphPtr->padX.side1 /*left */ ;
    graphPtr->hRange = width - RbcPadding(graphPtr->padX);

    if (graphPtr->vRange < 1) {
        graphPtr->vRange = 1;
    }
    if (graphPtr->hRange < 1) {
        graphPtr->hRange = 1;
    }
    graphPtr->hScale = 1.0 / (double) graphPtr->hRange;
    graphPtr->vScale = 1.0 / (double) graphPtr->vRange;

    /*
     * Calculate the placement of the graph title so it is centered within the
     * space provided for it in the top margin
     */
    titleY = graphPtr->titleTextStyle.height;
    graphPtr->titleY = (titleY / 2) + graphPtr->inset;
    graphPtr->titleX = (graphPtr->right + graphPtr->left) / 2;

}

/*
 * ----------------------------------------------------------------------
 *
 * ConfigureAxis --
 *
 *      Configures axis attributes (font, line width, label, etc).
 *
 * Results:
 *      The return value is a standard Tcl result.
 *
 * Side Effects:
 *      Axis layout is deferred until the height and width of the
 *      window are known.
 *
 * ----------------------------------------------------------------------
 */
static int
ConfigureAxis(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr)
{
    char            errMsg[200];

    /* Check the requested axis limits. Can't allow -min to be greater
     * than -max, or have undefined log scale limits.  */
    if (((!TclIsNaN(axisPtr->reqMin)) && (!TclIsNaN(axisPtr->reqMax))) &&
        (axisPtr->reqMin >= axisPtr->reqMax)) {
        sprintf(errMsg, "impossible limits (min %g >= max %g) for axis \"%s\"",
            axisPtr->reqMin, axisPtr->reqMax, axisPtr->name);
        Tcl_AppendResult(graphPtr->interp, errMsg, (char *) NULL);
        /* Bad values, turn on axis auto-scaling */
        axisPtr->reqMin = axisPtr->reqMax = rbcNaN;
        return TCL_ERROR;
    }
    if ((axisPtr->logScale) && (!TclIsNaN(axisPtr->reqMin)) &&
        (axisPtr->reqMin <= 0.0)) {
        sprintf(errMsg, "bad logscale limits (min=%g,max=%g) for axis \"%s\"",
            axisPtr->reqMin, axisPtr->reqMax, axisPtr->name);
        Tcl_AppendResult(graphPtr->interp, errMsg, (char *) NULL);
        /* Bad minimum value, turn on auto-scaling */
        axisPtr->reqMin = rbcNaN;
        return TCL_ERROR;
    }
    axisPtr->tickTextStyle.theta = FMOD(axisPtr->tickTextStyle.theta, 360.0);
    if (axisPtr->tickTextStyle.theta < 0.0) {
        axisPtr->tickTextStyle.theta += 360.0;
    }
    ResetTextStyles(graphPtr, axisPtr);

    axisPtr->titleWidth = axisPtr->titleHeight = 0;
    if (axisPtr->title != NULL) {
        int             w, h;

        RbcGetTextExtents(&axisPtr->titleTextStyle, axisPtr->title, &w, &h);
        axisPtr->titleWidth = (short int) w;
        axisPtr->titleHeight = (short int) h;
    }

    /*
     * Don't bother to check what configuration options have changed.
     * Almost every option changes the size of the plotting area
     * (except for -color and -titlecolor), requiring the graph and
     * its contents to be completely redrawn.
     *
     * Recompute the scale and offset of the axis in case -min, -max
     * options have changed.
     */
    graphPtr->flags |= RBC_REDRAW_WORLD;
    if (!RbcConfigModified(configSpecs, "-*color", "-background", "-bg",
            (char *) NULL)) {
        graphPtr->flags |= (RBC_MAP_WORLD | RBC_RESET_AXES);
        axisPtr->flags |= AXIS_DIRTY;
    }
    RbcEventuallyRedrawGraph(graphPtr);

    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * CreateAxis --
 *
 *      Create and initialize a structure containing information to
 *      display a graph axis.
 *
 * Results:
 *      The return value is a standard Tcl result.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static RbcAxis *
CreateAxis(
    RbcGraph * graphPtr,
    const char *name,           /* Identifier for axis. */
    int margin)
{
    RbcAxis        *axisPtr;
    Tcl_HashEntry  *hPtr;
    int             isNew;

    if (name[0] == '-') {
        Tcl_AppendResult(graphPtr->interp, "name of axis \"", name,
            "\" can't start with a '-'", (char *) NULL);
        return NULL;
    }
    hPtr = Tcl_CreateHashEntry(&graphPtr->axes.table, name, &isNew);
    if (!isNew) {
        axisPtr = (RbcAxis *) Tcl_GetHashValue(hPtr);
        if (!axisPtr->deletePending) {
            Tcl_AppendResult(graphPtr->interp, "axis \"", name,
                "\" already exists in \"", Tk_PathName(graphPtr->tkwin), "\"",
                (char *) NULL);
            return NULL;
        }
        axisPtr->deletePending = FALSE;
    } else {
        axisPtr = RbcCalloc(1, sizeof(RbcAxis));
        assert(axisPtr);

        axisPtr->name = RbcStrdup(name);
        axisPtr->hashPtr = hPtr;
        axisPtr->classUid = NULL;
        axisPtr->looseMin = axisPtr->looseMax = TICK_RANGE_TIGHT;
        axisPtr->reqNumMinorTicks = 2;
        axisPtr->scrollUnits = 10;
        axisPtr->showTicks = TRUE;
        axisPtr->reqMin = axisPtr->reqMax = rbcNaN;
        axisPtr->scrollMin = axisPtr->scrollMax = rbcNaN;

        if ((graphPtr->classUid == rbcBarElementUid) &&
            ((margin == RBC_MARGIN_TOP) || (margin == RBC_MARGIN_BOTTOM))) {
            axisPtr->reqStep = 1.0;
            axisPtr->reqNumMinorTicks = 0;
        }
        if ((margin == RBC_MARGIN_RIGHT) || (margin == RBC_MARGIN_TOP)) {
            axisPtr->hidden = TRUE;
        }
        RbcInitTextStyle(&axisPtr->titleTextStyle);
        RbcInitTextStyle(&axisPtr->limitsTextStyle);
        RbcInitTextStyle(&axisPtr->tickTextStyle);
        axisPtr->tickLabels = RbcChainCreate();
        axisPtr->lineWidth = 1;
        axisPtr->tickTextStyle.padX.side1 = 2;
        axisPtr->tickTextStyle.padX.side2 = 2;
        Tcl_SetHashValue(hPtr, axisPtr);
    }
    return axisPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * NameToAxis --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
NameToAxis(
    RbcGraph * graphPtr,        /* Graph widget record. */
    const char *name,           /* Name of the axis to be searched for. */
    RbcAxis ** axisPtrPtr)
{                               /* (out) Pointer to found axis structure. */
    Tcl_HashEntry  *hPtr;

    hPtr = Tcl_FindHashEntry(&graphPtr->axes.table, name);
    if (hPtr != NULL) {
        RbcAxis        *axisPtr;

        axisPtr = (RbcAxis *) Tcl_GetHashValue(hPtr);
        if (!axisPtr->deletePending) {
            *axisPtrPtr = axisPtr;
            return TCL_OK;
        }
    }
    Tcl_AppendResult(graphPtr->interp, "can't find axis \"", name,
        "\" in \"", Tk_PathName(graphPtr->tkwin), "\"", (char *) NULL);
    *axisPtrPtr = NULL;
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * GetAxis --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
GetAxis(
    RbcGraph * graphPtr,
    const char *axisName,
    RbcUid classUid,
    RbcAxis ** axisPtrPtr)
{
    RbcAxis        *axisPtr;

    if (NameToAxis(graphPtr, axisName, &axisPtr) != TCL_OK) {
        return TCL_ERROR;
    }
    if (classUid != NULL) {
        if ((axisPtr->refCount == 0) || (axisPtr->classUid == NULL)) {
            /* Set the axis type on the first use of it. */
            axisPtr->classUid = classUid;
        } else if (axisPtr->classUid != classUid) {
            Tcl_AppendResult(graphPtr->interp, "axis \"", axisName,
                "\" is already in use on an opposite ", axisPtr->classUid,
                "-axis", (char *) NULL);
            return TCL_ERROR;
        }
        axisPtr->refCount++;
    }
    *axisPtrPtr = axisPtr;
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * FreeAxis --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static void
FreeAxis(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr)
{
    axisPtr->refCount--;
    if ((axisPtr->deletePending) && (axisPtr->refCount == 0)) {
        DestroyAxis(graphPtr, axisPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * RbcDestroyAxes --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
void
RbcDestroyAxes(
    RbcGraph * graphPtr)
{
    Tcl_HashEntry  *hPtr;
    Tcl_HashSearch  cursor;
    RbcAxis        *axisPtr;
    int             i;

    for (hPtr = Tcl_FirstHashEntry(&graphPtr->axes.table, &cursor);
        hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
        axisPtr = (RbcAxis *) Tcl_GetHashValue(hPtr);
        axisPtr->hashPtr = NULL;
        DestroyAxis(graphPtr, axisPtr);
    }
    Tcl_DeleteHashTable(&graphPtr->axes.table);
    for (i = 0; i < 4; i++) {
        RbcChainDestroy(graphPtr->axisChain[i]);
    }
    Tcl_DeleteHashTable(&graphPtr->axes.tagTable);
    RbcChainDestroy(graphPtr->axes.displayList);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcDefaultAxes --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
int
RbcDefaultAxes(
    RbcGraph * graphPtr)
{
    register int    i;
    RbcAxis        *axisPtr;
    RbcChain       *chainPtr;
    static const char *axisNames[4] = { "x", "y", "x2", "y2" };
    int             flags;

    flags = RbcGraphType(graphPtr);
    for (i = 0; i < 4; i++) {
        chainPtr = RbcChainCreate();
        graphPtr->axisChain[i] = chainPtr;

        /* Create a default axis for each chain. */
        axisPtr = CreateAxis(graphPtr, axisNames[i], i);
        if (axisPtr == NULL) {
            return TCL_ERROR;
        }
        axisPtr->refCount = 1;  /* Default axes are assumed in use. */
        axisPtr->classUid = (i & 1) ? rbcYAxisUid : rbcXAxisUid;
        axisPtr->flags |= AXIS_ONSCREEN;

        /*
         * RbcConfigureWidgetComponent creates a temporary child window
         * by the name of the axis.  It's used so that the Tk routines
         * that access the X resource database can describe a single
         * component and not the entire graph.
         */
        if (RbcConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
                axisPtr->name, "Axis", configSpecs, 0, (const char **) NULL,
                (char *) axisPtr, flags) != TCL_OK) {
            return TCL_ERROR;
        }
        if (ConfigureAxis(graphPtr, axisPtr) != TCL_OK) {
            return TCL_ERROR;
        }
        axisPtr->linkPtr = RbcChainAppend(chainPtr, axisPtr);
        axisPtr->chainPtr = chainPtr;
    }
    return TCL_OK;
}

/*----------------------------------------------------------------------
 *
 * BindOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
BindOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char **argv)
{
    Tcl_Interp     *interp = graphPtr->interp;

    return RbcConfigureBindings(interp, graphPtr->bindTable,
        RbcMakeAxisTag(graphPtr, axisPtr->name), argc, argv);
}

/*
 * ----------------------------------------------------------------------
 *
 * CgetOp --
 *
 *      Queries axis attributes (font, line width, label, etc).
 *
 * Results:
 *      Return value is a standard Tcl result.  If querying configuration
 *      values, interp->result will contain the results.
 *
 * Side Effects:
 *      TODO: SIde Effects
 *
 * ----------------------------------------------------------------------
 */
static int
CgetOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,                   /* Not used. */
    const char *argv[])
{
    return Tk_ConfigureValue(graphPtr->interp, graphPtr->tkwin, configSpecs,
        (char *) axisPtr, argv[0], RbcGraphType(graphPtr));
}

/*
 * ----------------------------------------------------------------------
 *
 * ConfigureOp --
 *
 *      Queries or resets axis attributes (font, line width, label, etc).
 *
 * Results:
 *      Return value is a standard Tcl result.  If querying configuration
 *      values, interp->result will contain the results.
 *
 * Side Effects:
 *      Axis resources are possibly allocated (GC, font). Axis layout is
 *      deferred until the height and width of the window are known.
 *
 * ----------------------------------------------------------------------
 */
static int
ConfigureOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,
    const char *argv[])
{
    int             flags;

    flags = TK_CONFIG_ARGV_ONLY | RbcGraphType(graphPtr);
    if (argc == 0) {
        return Tk_ConfigureInfo(graphPtr->interp, graphPtr->tkwin, configSpecs,
            (char *) axisPtr, (char *) NULL, flags);
    } else if (argc == 1) {
        return Tk_ConfigureInfo(graphPtr->interp, graphPtr->tkwin, configSpecs,
            (char *) axisPtr, argv[0], flags);
    }
    if (Tk_ConfigureWidget(graphPtr->interp, graphPtr->tkwin, configSpecs,
            argc, argv, (char *) axisPtr, flags) != TCL_OK) {
        return TCL_ERROR;
    }
    if (ConfigureAxis(graphPtr, axisPtr) != TCL_OK) {
        return TCL_ERROR;
    }
    if (axisPtr->flags & AXIS_ONSCREEN) {
        if (!RbcConfigModified(configSpecs, "-*color", "-background", "-bg",
                (char *) NULL)) {
            graphPtr->flags |= RBC_REDRAW_BACKING_STORE;
        }
        graphPtr->flags |= RBC_DRAW_MARGINS;
        RbcEventuallyRedrawGraph(graphPtr);
    }
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * GetOp --
 *
 *      Returns the name of the picked axis (using the axis
 *      bind operation).  Right now, the only name accepted is
 *      "current".
 *
 * Results:
 *      A standard Tcl result.  The interpreter result will contain
 *      the name of the axis.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static int
GetOp(
    RbcGraph * graphPtr,
    int argc,                   /* Not used. */
    const char *argv[])
{
    Tcl_Interp     *interp = graphPtr->interp;
    register RbcAxis *axisPtr;

    axisPtr = (RbcAxis *) RbcGetCurrentItem(graphPtr->bindTable);
    /* Report only on axes. */
    if ((axisPtr != NULL) &&
        ((axisPtr->classUid == rbcXAxisUid) ||
            (axisPtr->classUid == rbcYAxisUid) ||
            (axisPtr->classUid == NULL))) {
        char            c;

        c = argv[3][0];
        if ((c == 'c') && (strcmp(argv[3], "current") == 0)) {
            Tcl_SetObjResult(interp, Tcl_NewStringObj(axisPtr->name, -1));
        } else if ((c == 'd') && (strcmp(argv[3], "detail") == 0)) {
            Tcl_SetObjResult(interp, Tcl_NewStringObj(axisPtr->detail, -1));
        }
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * LimitsOp --
 *
 *      This procedure returns a string representing the axis limits
 *      of the graph.  The format of the string is { left top right bottom}.
 *
 * Results:
 *      Always returns TCL_OK.  The interp->result field is
 *      a list of the graph axis limits.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static int
LimitsOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,                   /* Not used. */
    const char **argv)
{                               /* Not used. */
    Tcl_Interp     *interp = graphPtr->interp;
    double          min, max;

    if (graphPtr->flags & RBC_RESET_AXES) {
        RbcResetAxes(graphPtr);
    }
    if (axisPtr->logScale) {
        min = EXP10(axisPtr->axisRange.min);
        max = EXP10(axisPtr->axisRange.max);
    } else {
        min = axisPtr->axisRange.min;
        max = axisPtr->axisRange.max;
    }
    Tcl_AppendElement(interp, RbcDtoa(interp, min));
    Tcl_AppendElement(interp, RbcDtoa(interp, max));
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * InvTransformOp --
 *
 *      Maps the given window coordinate into an axis-value.
 *
 * Results:
 *      Returns a standard Tcl result.  interp->result contains
 *      the axis value. If an error occurred, TCL_ERROR is returned
 *      and interp->result will contain an error message.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static int
InvTransformOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,                   /* Not used. */
    const char **argv)
{
    int             x;          /* Integer window coordinate */
    double          y;          /* Real graph coordinate */

    if (graphPtr->flags & RBC_RESET_AXES) {
        RbcResetAxes(graphPtr);
    }
    if (Tcl_GetInt(graphPtr->interp, argv[0], &x) != TCL_OK) {
        return TCL_ERROR;
    }
    /*
     * Is the axis vertical or horizontal?
     *
     * Check the site where the axis was positioned.  If the axis is
     * virtual, all we have to go on is how it was mapped to an
     * element (using either -mapx or -mapy options).
     */
    if (AxisIsHorizontal(graphPtr, axisPtr)) {
        y = RbcInvHMap(graphPtr, axisPtr, (double) x);
    } else {
        y = RbcInvVMap(graphPtr, axisPtr, (double) x);
    }
    Tcl_AppendElement(graphPtr->interp, RbcDtoa(graphPtr->interp, y));
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * TransformOp --
 *
 *      Maps the given axis-value to a window coordinate.
 *
 * Results:
 *      Returns a standard Tcl result.  interp->result contains
 *      the window coordinate. If an error occurred, TCL_ERROR
 *      is returned and interp->result will contain an error
 *      message.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static int
TransformOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,
    int argc,                   /* Not used. */
    const char **argv)
{
    double          x;

    if (graphPtr->flags & RBC_RESET_AXES) {
        RbcResetAxes(graphPtr);
    }
    if (Tcl_ExprDouble(graphPtr->interp, argv[0], &x) != TCL_OK) {
        return TCL_ERROR;
    }
    if (AxisIsHorizontal(graphPtr, axisPtr)) {
        x = RbcHMap(graphPtr, axisPtr, x);
    } else {
        x = RbcVMap(graphPtr, axisPtr, x);
    }
    Tcl_SetObjResult(graphPtr->interp, Tcl_NewIntObj((int) x));
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * UseOp --
 *
 *      Changes the virtual axis used by the logical axis.
 *
 * Results:
 *      A standard Tcl result.  If the named axis doesn't exist
 *      an error message is put in interp->result.
 *
 *      .g xaxis use "abc def gah"
 *      .g xaxis use [lappend abc [.g axis use]]
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static int
UseOp(
    RbcGraph * graphPtr,
    RbcAxis * axisPtr,          /* Not used. */
    int argc,
    const char **argv)
{
    RbcChain       *chainPtr;
    int             nNames;
    const char    **names;
    RbcChainLink   *linkPtr;
    int             i;
    RbcUid          classUid;
    int             margin;

    margin = (int) argv[-1];
    chainPtr = graphPtr->margins[margin].axes;
    if (argc == 0) {
        for (linkPtr = RbcChainFirstLink(chainPtr); linkPtr != NULL;
            linkPtr = RbcChainNextLink(linkPtr)) {
            axisPtr = RbcChainGetValue(linkPtr);
            Tcl_AppendElement(graphPtr->interp, axisPtr->name);
        }
        return TCL_OK;
    }
    if ((margin == RBC_MARGIN_BOTTOM) || (margin == RBC_MARGIN_TOP)) {
        classUid = (graphPtr->inverted) ? rbcYAxisUid : rbcXAxisUid;
    } else {
        classUid = (graphPtr->inverted) ? rbcXAxisUid : rbcYAxisUid;
    }
    if (Tcl_SplitList(graphPtr->interp, argv[0], &nNames, &names) != TCL_OK) {
        return TCL_ERROR;
    }
    for (linkPtr = RbcChainFirstLink(chainPtr); linkPtr != NULL;
        linkPtr = RbcChainNextLink(linkPtr)) {
        axisPtr = RbcChainGetValue(linkPtr);
        axisPtr->linkPtr = NULL;
        axisPtr->flags &= ~AXIS_ONSCREEN;
        /* Clear the axis type if it's not currently used. */
        if (axisPtr->refCount == 0) {
            axisPtr->classUid = NULL;
        }
    }
    RbcChainReset(chainPtr);
    for (i = 0; i < nNames; i++) {
        if (NameToAxis(graphPtr, names[i], &axisPtr) != TCL_OK) {
            ckfree((char *) names);
            return TCL_ERROR;
        }
        if (axisPtr->classUid == NULL) {
            axisPtr->classUid = classUid;
        } else if (axisPtr->classUid != classUid) {
            Tcl_AppendResult(graphPtr->interp, "wrong type axis \"",
                axisPtr->name, "\": can't use ", classUid, " type axis.",
                (char *) NULL);
            ckfree((char *) names);
            return TCL_ERROR;
        }
        if (axisPtr->linkPtr != NULL) {
            /* Move the axis from the old margin's "use" list to the new. */
            RbcChainUnlinkLink(axisPtr->chainPtr, axisPtr->linkPtr);
            RbcChainAppendLink(chainPtr, axisPtr->linkPtr);
        } else {
            axisPtr->linkPtr = RbcChainAppend(chainPtr, axisPtr);
        }
        axisPtr->chainPtr = chainPtr;
        axisPtr->flags |= AXIS_ONSCREEN;
    }
    graphPtr->flags |=
        (RBC_GET_AXIS_GEOMETRY | RBC_LAYOUT_NEEDED | RBC_RESET_AXES);
    /* When any axis changes, we need to layout the entire graph.  */
    graphPtr->flags |= (RBC_MAP_WORLD | RBC_REDRAW_WORLD);
    RbcEventuallyRedrawGraph(graphPtr);

    ckfree((char *) names);
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * CreateVirtualOp --
 *
 *      Creates a new axis.
 *
 * Results:
 *      Returns a standard Tcl result.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static int
CreateVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv)
{
    RbcAxis        *axisPtr;
    int             flags;

    axisPtr = CreateAxis(graphPtr, argv[3], RBC_MARGIN_NONE);
    if (axisPtr == NULL) {
        return TCL_ERROR;
    }
    flags = RbcGraphType(graphPtr);
    if (RbcConfigureWidgetComponent(graphPtr->interp, graphPtr->tkwin,
            axisPtr->name, "Axis", configSpecs, argc - 4, argv + 4,
            (char *) axisPtr, flags) != TCL_OK) {
        goto error;
    }
    if (ConfigureAxis(graphPtr, axisPtr) != TCL_OK) {
        goto error;
    }
    Tcl_SetResult(graphPtr->interp, axisPtr->name, TCL_VOLATILE);
    return TCL_OK;
  error:
    DestroyAxis(graphPtr, axisPtr);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * BindVirtualOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
static int
BindVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char **argv)
{
    Tcl_Interp     *interp = graphPtr->interp;

    if (argc == 3) {
        Tcl_HashEntry  *hPtr;
        Tcl_HashSearch  cursor;
        char           *tagName;

        for (hPtr = Tcl_FirstHashEntry(&graphPtr->axes.tagTable, &cursor);
            hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
            tagName = Tcl_GetHashKey(&graphPtr->axes.tagTable, hPtr);
            Tcl_AppendElement(interp, tagName);
        }
        return TCL_OK;
    }
    return RbcConfigureBindings(interp, graphPtr->bindTable,
        RbcMakeAxisTag(graphPtr, argv[3]), argc - 4, argv + 4);
}

/*
 * ----------------------------------------------------------------------
 *
 * CgetVirtualOp --
 *
 *      Queries axis attributes (font, line width, label, etc).
 *
 * Results:
 *      Return value is a standard Tcl result.  If querying configuration
 *      values, interp->result will contain the results.
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
static int
CgetVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char *argv[])
{
    RbcAxis        *axisPtr;

    if (NameToAxis(graphPtr, argv[3], &axisPtr) != TCL_OK) {
        return TCL_ERROR;
    }
    return CgetOp(graphPtr, axisPtr, argc - 4, argv + 4);
}

/*
 * ----------------------------------------------------------------------
 *
 * ConfigureVirtualOp --
 *
 *      Queries or resets axis attributes (font, line width, label, etc).
 *
 * Results:
 *      Return value is a standard Tcl result.  If querying configuration
 *      values, interp->result will contain the results.
 *
 * Side Effects:
 *      Axis resources are possibly allocated (GC, font). Axis layout is
 *      deferred until the height and width of the window are known.
 *
 * ----------------------------------------------------------------------
 */
static int
ConfigureVirtualOp(
    RbcGraph * graphPtr,
    int argc,
    const char *argv[])
{
    RbcAxis        *axisPtr;
    int             nNames, nOpts;
    const char    **options;
    register int    i;

    /* Figure out where the option value pairs begin */
    argc -= 3;
    argv += 3;
    for (i = 0; i < argc; i++) {
        if (arg