Tk Source Code

Check-in [c5371055]
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:New files from René Zaumseil
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tip-510
Files: files | file ages | folders
SHA3-256: c53710558d43d7264ce0118293a6c9324bdd9093de0120bf7b26b9971710483f
User & Date: fvogel 2018-11-28 20:49:14
Context
2018-11-29
08:19
More files from René Zaumseil check-in: efa37635 user: fvogel tags: tip-510
2018-11-28
20:49
New files from René Zaumseil check-in: c5371055 user: fvogel tags: tip-510
2018-11-02
08:43
Cleaning up the script bindings further. [table] is gone; [grid] replaces it. check-in: 76212b98 user: dkf tags: tip-510
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added doc/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
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
# graph(n) -- 2D graph for plotting X-Y coordinate data

*   [NAME]((#NAME)
*   [SYNOPSIS](#SYNOPSIS)
*   [DESCRIPTION](#DESCRIPTION)
*   [INTRODUCTION](#INTRODUCTION)
*   [SYNTAX](#SYNTAX)
*   [GRAPH OPERATIONS](#GRAPH-OPERATIONS)
  * [pathName axis](#pathName-axis) *operation ?arg?...*
  * [pathName binding](#pathName-binding) *?crosshairs? ?findelement? ?legend? ?zoom?*
  * [pathName bar](#pathName-bar) *elemName ?option value?...*
  * [pathName cget](#pathName-cget) *option*
  * [pathName configure](#pathName-configure) *?option value?...*
  * [pathName crosshairs](#pathName-crosshairs) *operation ?arg?*
  * [pathName element](#pathName-element) *operation ?arg?...*
  * [pathName extents](#pathName-extents) *item*
  * [pathName grid](#pathName-grid) *operation ?arg?...*
  * [pathName invtransform](#pathName-invtransform) *winX winY*
  * [pathName inside](#pathName-inside) *x y*
  * [pathName legend](#pathName-legend) *operation ?arg?...*
  * [pathName line](#pathName-line) *operation arg...*
  * [pathName marker](#pathName-marker) *operation ?arg?...*
  * [pathName postscript](#pathName-postscript) *operation ?arg?...*
  * [pathName snap](#pathName-snap) *?switches? outputName*
  * [pathName transform](#pathName-transform) *x y*
  * [pathName xaxis](#pathName-xaxis) *operation ?arg?...*
  * [pathName x2axis](#pathName-x2axis) *operation ?arg?...*
  * [pathName yaxis](#pathName-yaxis) *operation ?arg?...*
  * [pathName y2axis](#pathName-y2axis) *operation ?arg?...*
* [AXIS COMPONENT](#AXIS-COMPONENT)
  * [pathName axis bind](#pathName-axis-bind) *tagName ?sequence? ?command?*
  * [pathName axis cget](#pathName-axis-cget) *axisName option*
  * [pathName axis configure](#pathName-axis-configure) *axisName ?axisName?... ?option value?...*
  * [pathName axis create](#pathName-axis-create) *axisName ?option value?...*
  * [pathName axis delete](#pathName-axis-delete) *?axisName?...*
  * [pathName axis invtransform](#pathName-axis-invtransform) *axisName value*
  * [pathName axis limits](#pathName-axis-limits) *axisName*
  * [pathName axis names](#pathName-axis-names) *?pattern?...*
  * [pathName axis transform](#pathName-axis-transform) *axisName value*
  * [pathName axis view](#pathName-axis-view) *axisName*
* [CROSSHAIRS COMPONENT](#)
  * [pathName crosshairs cget](#pathName-crosshairs-cget) *option*
  * [pathName crosshairs configure](#pathName-crosshairs-configure) *?option value?...*
  * [pathName crosshairs off](#pathName-crosshairs-off)
  * [pathName crosshairs on](#pathName-crosshairs-on)
  * [pathName crosshairs toggle](#pathName-crosshairs-toggle)
* [ELEMENT COMPONENT](#ELEMENT-COMPONENT)
  * [pathName element activate](#pathName-element-activate) *elemName ?index?...*
  * [pathName element bind](#pathName-element-bind) *tagName ?sequence? ?command?*
  * [pathName element cget](#pathName-element-cget) *elemName option*
  * [pathName element closest](#pathName-element-closest) *x y varName ?option value?... ?elemName?...*
  * [pathName element configure](#pathName-element-configure) *elemName ?elemName... ?option value?...*
  * [pathName element create](#pathName-element-create) *elemName ?option value?...*
  * [pathName element deactivate](#pathName-element-deactivate) *elemName ?elemName?...*
  * [pathName element delete](#pathName-element-delete) *?elemName?...*
  * [pathName element exists](#pathName-element-exists) *elemName*
  * [pathName element names](#pathName-element-names) *?pattern?...*
  * [pathName element show](#pathName-element-show) *?nameList?*
  * [pathName element type](#pathName-element-type) *elemName*
* [GRID COMPONENT](#GRID-COMPONENT)
  * [pathName grid cget](#pathName-grid-cget) *option*
  * [pathName grid configure](#pathName-grid-configure) *?option value?...*
  * [pathName grid off](#pathName-grid-off)
  * [pathName grid on](#pathName-grid-on)
  * [pathName grid toggle](#pathName-grid-toggle)
* [LEGEND COMPONENT](#LEGEND-COMPONENT)
  * [pathName legend activate](#pathName-legend-activate) *pattern...*
  * [pathName legend bind](#pathName-legend-bind) *tagName ?sequence? ?command?*
  * [pathName legend cget](#pathName-legend-cget) *option*
  * [pathName legend configure](#pathName-legend-configure) *?option value?...*
  * [pathName legend deactivate](#pathName-legend-deactivate) *pattern...*
  * [pathName legend get](#pathName-legend-get) *pos*
* [PEN COMPONENT](#PEN-COMPONENT)
  * [pathName pen cget](#pathName-pen-cget) *penName option*
  * [pathName pen configure](#pathName-pen-configure) *penName ?penName... ?option value?...*
  * [pathName pen create](#pathName-pen-create) *penName ?option value?...*
  * [pathName pen delete](#pathName-pen-delete) *?penName?...*
  * [pathName pen names](#pathName-pen-names) *?pattern?...*
* [POSTSCRIPT COMPONENT](#POSTSCRIPT-COMPONENT)
  * [pathName postscript cget](#pathName-postscript-cget) *option*
  * [pathName postscript configure](#pathName-postscript-configure) *?option value?...*
  * [pathName postscript output](#pathName-postscript-output) *?fileName? ?option value?...*
* [MARKER COMPONENT](#MARKER-COMPONENT)
  * [pathName marker after](#pathName-marker-after) *markerId ?afterId?*
  * [pathName marker before](#pathName-marker-before) *markerId ?beforeId?*
  * [pathName marker bind](#pathName-marker-bind) *tagName ?sequence? ?command?*
  * [pathName marker cget](#pathName-marker-cget) *option*
  * [pathName marker configure](#pathName-marker-configure) *markerId ?option value?...*
  * [pathName marker create](#pathName-marker-create) *type ?option value?...*
  * [pathName marker delete](#pathName-marker-delete) *?name?...*
  * [pathName marker exists](#pathName-marker-exists) *markerId*
  * [pathName marker names](#pathName-marker-names) *?pattern?*
  * [pathName marker type](#pathName-marker-type) *markerId*
  * [BITMAP MARKERS](#BITMAP-MARKERS)
  * [pathName marker create bitmap](#pathName-marker-create-bitmap) *?option value?...*
  * [IMAGE MARKERS](#IMAGE-MARKERS)
  * [pathName marker create image](#pathName-marker-create-image) *?option value?...*
  * [LINE MARKERS](#LINE-MARKERS)
  * [pathName marker create line](#pathName-marker-create-line) *?option value?...*
  * [POLYGON MARKERS](#POLYGON-MARKERS)
  * [pathName marker create polygon](#pathName-marker-create-polygon) *?option value?...*
  * [TEXT MARKERS](#TEXT-MARKERS)
  * [pathName marker create text](#pathName-marker-create-text) *?option value?...*
  * [WINDOW MARKERS](#WINDOW-MARKERS)
  * [pathName marker create window](#pathName-marker-create-window) *?option value?...*
*   [GRAPH COMPONENT BINDINGS](#GRAPH-COMPONENT-BINDINGS)
*   [C LANGUAGE API](#[C-LANGUAGE-API)
*   [SPEED TIPS](#SPEED-TIPS)
*   [LIMITATIONS](#LIMITATIONS)
*   [EXAMPLE](#EXAMPLE)
*   [KEYWORDS](#KEYWORDS)

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

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

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

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

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

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.

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

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.

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

**graph** *pathName ?-style line|bar|strip? ?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.

The *-style* option can only be set on creation time of the new window. The option control the appearance of the widget. Default value is "line".

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?...*

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.

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.

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

<a name="pathName-axis"></a>
**pathName axis** *operation ?arg?...*

> See the [AXIS COMPONENT](#AXIS-COMPONENT) section.

<a name="pathName-bar"></a>
**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. TODO

name="pathName-binding"></a>
**pathName binding** *?crosshairs? ?findelement? ?legend? ?zoom?*

The procedure allows the setting of some default bindings. It will add bindings if a name is given and remove bindings if a name is not given.

> If given then the following bindings will be applied:

> *crosshairs*

> > <Any-Motion> will draw crosshairs in the graph window. Leaving the widget will remove the crosshairs.

> *findelement*

> > <Control-ButtonPress-2> This will display informations of the nearest element point.  
> > <Control-Buttonrelease-2> This will remove the displayed informations.  

> *legend* 

> > <Enter> an element will activate the elment entry in the legend window.  
> > <Leave> an element will deactivate the element entry in the legend window.  
> > <ButtonPress-1> will select the element entry in the legend window.  

> *zoom*

> > <ButtonPress-1> Create first and second point of a zooming window. When the second point is created the graph will be zoomed to the new window and the old window will be remembered.  
> > <ButtonPress-3> Undo the last zoom operation.  

<a name="pathName-cget"></a>
**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.

<a name="pathName-configure"></a>
**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.

<a name="pathName-crosshairs"></a>
**pathName crosshairs** *operation ?arg?*

> See the [CROSSHAIRS COMPONENT](#CROSSHAIRS-COMPONENT) section.

<a name="pathName-element"></a>
**pathName element** *operation ?arg?...*

> See the [ELEMENT COMPONENT](#ELEMENT-COMPONENT) section.

<a name="pathName-extents"></a>
**pathName extents** *item*

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

<a name="pathName-grid"></a>
**pathName grid** *operation ?arg?...*

> See the [GRID COMPONENT](#GRID-COMPONENT) section.

<a name="pathName-invtransform"></a>
**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.

<a name="pathName-inside"></a>
**pathName inside** *x y*

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

<a name="pathName-legend"></a>
**pathName legend** *operation ?arg?...*

> See the [LEGEND COMPONENT](#LEGEND-COMPONENT) section.

<a name="pathName-line"></a>
**pathName line** *operation arg...*

> The operation is the same as element.

<a name="pathName-marker"></a>
**pathName marker** *operation ?arg?...*

> See the [MARKER COMPONENT](#MARKER-COMPONENT) section.

<a name="pathName-postscript"></a>
**pathName postscript** *operation ?arg?...*

> See the [POSTSCIPT COMPONENT](#POSTSCRIPT-COMPONENT)section.

<a name="pathName-snap"></a>
**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.

<a name="pathName-transform"></a>
**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.

<a name="pathName-xaxis"></a>
**pathName xaxis** *operation ?arg?...*

<a name="pathName-x2axis"></a>
**pathName x2axis** *operation ?arg?...*

<a name="pathName-yaxis"></a>
**pathName yaxis** *operation ?arg?...*

<a name="pathName-y2axis"></a>
**pathName y2axis** *operation ?arg?...*

> See the [AXIS COMPONENT](#AXIS-COMPONENT) section.

<a name="AXIS-COMPONENT"></a>
## AXIS COMPONENT

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.

> <code>
	# Create a new axis called "tempAxis"  
	.g axis create tempAxis  
</code>

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.

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

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.

> <code>
	# Display the axis tempAxis in the left margin.  
	.g yaxis use tempAxis  
</code>

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.

<a name="pathName-axis-bind"></a>
**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.

<a name="pathName-axis-cget"></a>
**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.

<a name="pathName-axis-configure"></a>
**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).

> <code>
        option add *Graph.Axis.Color  blue
        option add *Graph.x.LogScale  true
        option add *Graph.x2.LogScale false
</code>

<a name="pathName-axis-create"></a>
**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.

<a name="pathName-axis-delete"></a>
**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.

<a name="pathName-axis-invtransform"></a>
**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.

<a name="pathName-axis-limits"></a>
**pathName axis limits** *axisName*

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

<a name="pathName-axis-names"></a>
**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.

<a name="pathName-axis-transform"></a>
**pathName axis transform** *axisName value*

> Transforms the coordinate value to a screen coordinate by mapping the it to axisName. Returns the transformed screen coordinate.

<a name="pathName-axis-view"></a>
**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.

> <code>
	.g create axis temp  
	.g create axis time  
	...  
	.g xaxis use temp  
	.g yaxis use time  
</code>

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.

<a name="CROSSHAIRS-COMPONENT"></a>
## 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 graph.

The following operations are available for cross hairs:

<a name="pathName-crosshairs-cget"></a>
**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.

<a name="pathName-crosshairs-configure"></a>
**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.

> > <code>
        option add *Graph.Crosshairs.LineWidth 2  
        option add *Graph.Crosshairs.Color     red  
</code>

<a name="pathName-crosshairs-off"></a>
**pathName crosshairs off**

> Turns off the cross hairs.

<a name="pathName-crosshairs-on"></a>
**pathName crosshairs on**

> Turns on the display of the cross hairs.

<a name="pathName-crosshairs-toggle"></a>
**pathName crosshairs toggle**

> Toggles the current state of the cross hairs, alternately mapping and unmapping the cross hairs.

<a name="ELEMENT-COMPONENT"></a>
## ELEMENT COMPONENT

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.

<a name="pathName-element-activate"></a>
**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.

<a name="pathName-element-bind"></a>
**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.

<a name="pathName-element-cget"></a>
**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.

<a name="pathName-element-closest"></a>
**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.

<a name="pathName-element-configure"></a>
**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 graph 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 graph vector or a list of numeric expressions.

> **-ydata** *yVec*

> > Specifies the Y-coordinates of the data. YVec is the name of a graph 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.

> > <code>
        option add *Graph.Element.symbol line  
        option add *Graph.e1.symbol line  
</code>

<a name="pathName-element-create"></a>
**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.

<a name="pathName-element-deactivate"></a>
**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.

<a name="pathName-element-delete"></a>
**pathName element delete** *?elemName?...*

> Deletes all the named elements. The graph is automatically redrawn.

<a name="pathName-element-exists"></a>
**pathName element exists** *elemName*

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

<a name="pathName-element-names"></a>
**pathName element names** *?pattern?...*

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

<a name="pathName-element-show"></a>
**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.

<a name="pathName-element-type"></a>
**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".

<a name="GRID-COMPONENT"></a>
## 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.

<a name="pathName-grid-cget"></a>
**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.

<a name="pathName-grid-configure"></a>
**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.

> **-raised** *boolean*

> > Grid is to be raised or drawn over elements.

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

> > <code>
        option add *Graph.grid.LineWidth 2  
        option add *Graph.Grid.Color     black  
</code>

<a name="pathName-grid-off"></a>
**pathName grid off**

> Turns off the display the grid lines.

<a name="pathName-grid-on"></a>
**pathName grid on**

> Turns on the display the grid lines.

<a name="pathName-grid-toggle"></a>
**pathName grid toggle**

> Toggles the display of the grid.

<a name="LEGEND-COMPONENT"></a>
## 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.

The following operations are valid for the legend.

<a name="pathName-legend-activate"></a>
**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.

<a name="pathName-legend-bind"></a>
**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.

<a name="pathName-legend-cget"></a>
**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.

<a name="pathName-legend-configure"></a>
**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.

> > <code>
        option add *Graph.legend.Foreground blue  
        option add *Graph.Legend.Relief     raised  
</code>

<a name="pathName-legend-deactivate"></a>
**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.

<a name="pathName-legend-get"></a>
**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.

<a name="PEN-COMPONENT"></a>
## PEN COMPONENT

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.

> <code>
	.g pen configure "activeLine" -color green  
</code>

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

> <code>
	.g pen create myPen  
</code>

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

> <code>
	.g element create "line1" -xdata $x -ydata $tempData -pen myPen  
</code>

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).

> <code>
	.g element configure "line1" -styles { myPen 2.0 3.0 }  
</code>

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.

<a name="pathName-pen-cget"></a>
**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.

<a name="pathName-pen-configure"></a>
**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.

> > <code>
        option add *Graph.Pen.Color  blue  
        option add *Graph.activeLine.color  green  
</code>

<a name="pathName-pen-create"></a>
**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.

<a name="pathName-pen-delete"></a>
**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.

<a name="pathName-pen-names"></a>
**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.

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

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.

<a name="pathName-postscript-cget"></a>
**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.

<a name="pathName-postscript-configure"></a>
**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.

> > <code>
        option add *Graph.postscript.Decorations false  
        option add *Graph.Postscript.Landscape   true  
</code>

<a name="pathName-postscript-output"></a>
**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.

<a name="MARKER-COMPONENT"></a>
## MARKER COMPONENT

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.

<a name="pathName-marker-after"></a>
**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.

<a name="pathName-marker-before"></a>
**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.

<a name="pathName-marker-bind"></a>
**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.

<a name="pathName-marker-cget"></a>
**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.

<a name="pathName-marker-configure"></a>
**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.

> > <code>
        option add *Graph.TextMarker.Foreground white  
        option add *Graph.BitmapMarker.Foreground white  
        option add *Graph.m1.Background     blue  
</code>

<a name="pathName-marker-create"></a>
**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.

<a name="pathName-marker-delete"></a>
**pathName marker delete** *?name?...*

> Removes one of more markers. The graph will automatically be redrawn without the marker.

<a name="pathName-marker-exists"></a>
**pathName marker exists** *markerId*

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

<a name="pathName-marker-names"></a>
**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.

<a name="pathName-marker-type"></a>
**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.

<a name="BITMAP-MARKERS"></a>
### 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.

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

<a name="pathName-marker-create-bitmap"></a>
**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.

<a name="IMAGE-MARKERS"></a>
### IMAGE MARKERS

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

<a name="pathName-marker-create-image"></a>
**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 "".

<a name="LINE-MARKERS"></a>
### LINE MARKERS

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

<a name="pathName-marker-create-line"></a>
**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 "".

<a name=">POLYGON-MARKERS"></a>
### 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 create operation in the form:

<a name="pathName-marker-create-polygon"></a>
**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 "".

<a name=TEXT-MARKERS"></a>
### 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 graph. Text markers are created with the create operation in the form:

<a name="pathName-marker-create-text"></a>
**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.

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

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

<a name="pathName-marker-create-window"></a>
**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.

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

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.

Some common bindings can be set with the [pathName binding](#pathName-binding) command.

## <a name="C-LANGUAGE-API"></a>
## 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 graph 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.

> <code>
	vector X Y  
	.g element configure line1 -xdata X -ydata Y  
</code>

To set data points from C, you pass the values as arrays of doubles using the Rbc_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.

> <code>
	#include "tcl.h"  
	#include "rbcInt.h"  

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

	/* Get the graph vectors "X" and "Y" (created above from Tcl) */  
	if ((Rbc_GetVector(interp, "X", &xVec) != TCL_OK) ||  
	    (Rbc_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 graph vectors */  
	if ((Rbc_ResetVector(xVec, x, 50, 50, TCL_VOLATILE) != TCL_OK) ||  
	    (Rbc_ResetVector(yVec, y, 50, 50, TCL_VOLATILE) != TCL_OK)) {  
	    return TCL_ERROR;  
	}  
</code>

See the vector manual page for more details.

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

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 graph 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.

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

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.

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

The graph command creates a new graph.

> <code>
	# Create a new graph.  Plotting area is black.  
	graph .g -plotbackground black
</code>

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.

> <code>
	# Change the title.  
	.g configure -title "My Plot"
</code>

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.

> <code>
	# 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 }
</code>

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

> <code>
	# 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  
</code>

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

> <code>
	# Change the y coordinate of the first point.  
	set yVector(0) 25.18
</code>

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.

> <code>
	# 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]  
</code>

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.

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

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.

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

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.

> <code>
	# Configure line1  
	.g element configure line1 -symbol square -color red -dashes { 2 4 2 } -linewidth 2 -pixels 2c  
</code>

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.

> <code>
	# Map "line1" on the alternate Y-axis "y2".  
	.g element configure line1 -mapy y2  
</code>
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.

> <code>
	# Y-axis is log scale.  
	.g axis configure y -logscale yes  
</code>

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.

> <code>
	.g axis configure x -min 1.0 -max 1.5  
	.g axis configure y -min 12.0 -max 55.15  
</code>

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.

> <code>
	# 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]  
	}  
</code>

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.

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

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

> <code>
	# Configure the legend font, color, and relief  
	.g legend configure -position left -relief raised -font fixed -fg blue  
</code>

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

> <code>
	# Don't display the legend.  
	.g legend configure -hide yes  
</code>

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.

> <code>
	# 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  
</code>
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.

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

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

> <code>
	# 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  
	}  
</code>

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.

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

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).

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

graph, widget

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

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

&copy; 2001 George A. Howlett.

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

Deleted 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]>


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Deleted 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
..
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<






























































































































































































































































































































































































































































































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












































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































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














































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Deleted 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 doc/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
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
# vector(n) -- Vector data type for Tcl

*   [NAME]((#NAME)
*   [SYNOPSIS](#SYNOPSIS)
*   [DESCRIPTION](#DESCRIPTION)
*   [SYNTAX](#SYNTAX)
  * [graph::vector configure](#graph::vector-configure) *?option value?...*
  * [graph::vector create](#graph::vector-create) *vectorName?(...)? ?option value?...*
  * [graph::vector destroy](#graph::vector-destroy) *vectorName ?vectorName?...*
  * [graph::vector expression](#graph::vector-expression) *expression*
  * [graph::vector names](#graph::vector-names) *?pattern...?*
  * [graph::vector op](#graph::vector-op) *operation vectorName ?arg?...*
*   [VECTOR INDICES](#VECTOR-INDICES)
*   [VECTOR OPERATIONS](#VECTOR-OPERATIONS)
  * [vectorName +](#vectorName-plus") *item*
  * [vectorName -](#vectorName-minus") *item*
  * [vectorName `*`](#vectorName-mult") *item*
  * [vectorName /](#vectorName-div") *item*
  * [vectorName append](#vectorName-append) *item ?item?...*
  * [vectorName binread](#vectorName-binread) *channel ?length? ?switches?*
  * [vectorName binwrite](#vectorName-binwrite) *channel ?length? ?-at index?*
  * [vectorName clear](#vectorName-clear)
  * [vectorName delete](#vectorName-delete) *index ?index?...*
  * [vectorName dup](#vectorName-dup) *destName*
  * [vectorName expr](#vectorName-expr) *expression*
  * [vectorName index](#vectorName-index) *index ?value?...*
  * [vectorName insert](#vectorName-insert) *index item ?item?...*
  * [vectorName length](#vectorName-length) *?newSize?*
  * [vectorName matrix](#vectorName-matrix) *...*
    * [vectorName matrix copy](#vectorName-matrix-copy) *dstcolumn srccolumn ?srcVec?*
    * [vectorName matrix delete](#vectorName-matrix-delete) *column*
    * [vectorName matrix get](#vectorName-matrix-get) *column*
    * [vectorName matrix insert](#vectorName-matrix-insert) *column ?initvalue?*
    * [vectorName matrix multiply](#vectorName-matrix-multiply) *srcVec ?dstVec?*
    * [vectorName matrix numcols](#vectorName-matrix-numcols) *?size?*
    * [vectorName matrix numrows](#vectorName-matrix-numrows) *?size?*
    * [vectorName matrix set](#vectorName-matrix-set) *column ?valuelist?*
    * [vectorName matrix shift](#vectorName-matrix-shift) *column amount ?startoffset?*
    * [vectorName matrix sort](#vectorName-matrix-sort) *column ?-reverse?*
    * [vectorName matrix transpose](#vectorName-matrix-transpose)
  * [vectorName merge](#vectorName-merge) *srcName ?srcName?...*
  * [vectorName notify](#vectorName-notify) *?keyword? ?script?*
  * [vectorName populate](#vectorName-populate) *destName ?density?*
  * [vectorName range](#vectorName-range) *firstIndex ?lastIndex?...*
  * [vectorName search](#vectorName-search) *value ?value?*
  * [vectorName set](#vectorName-set) *item*
  * [vectorName seq](#vectorName-seq) *start ?finish? ?step?*
  * [vectorName sort](#vectorName-sort) *?-reverse? ?argName?...*
  * [vectorName split](#vectorName-split) *dstName ?dstName?...*
  * [vectorName variable](#vectorName-variable) *varName*
* [C LANGUAGE API](#C-LANGUAGE-API)
* [LIBRARY ROUTINES](#LIBRARY-ROUTINES)
* [C API EXAMPLE](#C-API-EXAMPLE)
* [INCOMPATIBILITIEA](#INCOMPATIBILITIES)
* [EXAMPLE](#EXAMPLE)
* [KEYWORDS](#KEYWORDS)
* [COPYRIGHT](#COPYRIGHT)

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

graph::vector - Vector data type for graph widgets

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

**[graph::vector configure](#graph::vector-configure)** *?option value? ...*

**[graph::vector create](#graph::vector-create)** *vectorName?(...)? ?option value?...*

**[graph::vector destroy](#graph::vector-destroy)** *vectorName ?vectorName...?*

**[graph::vector expr](#graph::vector-expr)** *expression*

**[graph::vector names](#graph::vector-names)** *?pattern...?*

**[graph::vector op](#graph::vector-op)** *operation vectorName ?arg?...*

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

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.

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.

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

<a name="graph::vector-configure"></a>
**graph::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.

<a name="graph::vector-create"></a>
**graph::vector create** *vectorName?(...)? ?option value?*

> The create operation creates a new vector vectorName. This creates both a Tcl command and array variable called vectorName. The name vectorName 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 vectorName is unset, the vector and its Tcl command are also destroyed.

> *vectorName*

> > This creates a new vector vectorName which initially has no components.

> *vectorName(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.

> *vectorName(rows,columns)*

> > This form allows creation of a matrix with the specified columns and `rows*columns` elements. See the matrix section for more details.

> *vectorName(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.

> 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 names must start with a letter and consist of letters, digits, or underscores.

> > <code>
	# Error: must start with letter  
	graph::vector create 1abc  
</code>

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

> > <code>
	set vec [graph::vector create #auto]  
	puts "$vec has [$vec length] components"  
</code>

> If successful, vector returns the name of the vector. 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 vector. The general form is:

> **vectorName** *operation ?arg?...*

> Both, operation and its arguments determine the exact behavior of the command. The operations available for the graph are described in section [VECTOR OPERATIONS](#VECTOR-OPERATIONS).

<a name="graph::vector-destroy"></a>
**graph::vector destroy** *vectorName ?vectorName...?*

> Destroy given vectors.

<a name="graph::vector-expr"></a>
**graph::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.

> <code>
        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!
</code>

> Standard mathematical functions:

> > **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.

<a name="graph::vector-names"></a>
**graph::vector names** *?pattern?*

> Return names of all defined vectors.

<a name="graph::vector-op"></a>
**graph::vector op** *operation vectorName ?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.

> <code>
    graph::vector create v1  
    v1 op append {1 2 3}  
    v1 op modify 1 2.1  
</code>

<a name="VECTOR-INDICES"></a>
## 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.

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.

> <code>
puts $vectorName(0)  
vectorName offset -5  
puts $vectorName(-5)  
</code>

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

> <code>
vectorName matrix numcols 3  
puts vectorName(0,2)  
</code>

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

> <code>
set n 21  
set vectorName($n+3) 50.2  
</code>

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

> <code>
puts "min = $vectorName($min)"  
set vectorName(end) -1.2  
</code>

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.

> <code>
 # Append an new component to the end  
set vectorName(++end) 3.2  
</code>

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

> <code>
 # Set the first six components to 1.0  
set vectorName(0:5) 1.0  
</code>

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

> <code>
 # Print the values of all the components  
puts $vectorName(:)  
</code>

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

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

> **vectorName** *operation arg...*

Note this is equivalent to the form:

> **graph::vector op** *operation vectorName ?arg?...*

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

<a name="vectorName-plus"></a>
**vectorName +** *item*

<a name="vectorName-minus"></a>
**vectorName -** *item*

<a name="vectorName-mult"></a>
**vectorName** `*` *item*

<a name="vectorName-div"></a>
**vectorName /** *item*

> Perform binary op and return result as a list.

<a name="vectorName-append"></a>
**vectorName append** *item ?item?...*

> Appends the component values from item to vectorName. Item can be either the name of a vector or a list of numeric values.

<a name="vectorName-binread"></a>
**vectorName 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".

<a name="vectorName-binwrite"></a>
**vectorName binwrite** *channel ?length? ?-at index?*

> Like binread, but writes data.

<a name="vectorName-clear"></a>
**vectorName clear**

> Clears the element indices from the array variable associated with vectorName. 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.

<a name="vectorName-delete"></a>
**vectorName delete** *index ?index?...*

> Deletes the indexth component from the vector vectorName. 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.

<a name="vectorName-dup"></a>
**vectorName dup** *destName*

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

<a name="vectorName-expr"></a>
**vectorName 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.

<a name="vectorName-index"></a>
**vectorName index** *index ?value?...*

> Get/set individual vector values. This provides element updating when -variable is set to empty.

<a name="vectorName-insert"></a>
**vectorName insert** *index item ?item?...*

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

<a name="vectorName-length"></a>
**vectorName length** *?newSize?*

> Queries or resets the number of components in vectorName. NewSize is a number specifying the new size of the vector. If newSize is smaller than the current size of vectorName, vectorName 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.

<a name="vectorName-matrix"></a>
**vectorName 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:

> <code>
    graph::vector create aVec(10,3)  
    graph::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!  
</code>

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

<a name="vectorName-matrix-copy"></a>
**vectorName 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 vectorName, the columns numbers must be different. If the srcVec column is longer, vectorName will be extended. If shorter, remaining destination values are not overwritten.

<a name="vectorName-matrix-delete"></a>
**vectorName matrix delete** *column*

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

<a name="vectorName-matrix-get"></a>
**vectorName matrix get** *column*

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

<a name="vectorName-matrix-insert"></a>
**vectorName 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.

<a name="vectorName-matrix-multiply"></a>
**vectorName 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 vectorName. One application for multiply is coordinate transformation.

<a name="vectorName-matrix-numcols"></a>
**vectorName 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.

<a name="vectorName-matrix-numrows"></a>
**vectorName 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.

<a name="vectorName-matrix-set"></a>
**vectorName 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.

<a name="vectorName-matrix-shift"></a>
**vectorName 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.

<a name="vectorName-matrix-sort"></a>
**vectorName matrix sort** *column ?-reverse?*

> Sort the vector by the given column.

<a name="vectorName-matrix-transpose"></a>
**vectorName 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.

<a name="vectorName-merge"></a>
**vectorName 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.

<a name="vectorName-notify"></a>
**vectorName 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.

<a name="vectorName-populate"></a>
**vectorName populate** *destName ?density?*

> Creates a vector destName which is a superset of vectorName. DestName will include all the components of vectorName, 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.

<a name="vectorName-range"></a>
**vectorName 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.

<a name="vectorName-search"></a>
**vectorName search** *value ?value?*

> Searches for a value or range of values among the components of vectorName. 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.

<a name="vectorName-set"></a>
**vectorName set** *item*

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

<a name="vectorName-seq"></a>
**vectorName 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.

<a name="vectorName-sort"></a>
**vectorName sort** *?-reverse? ?argName?...*

> Sorts the vector vectorName 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 vectorName. Each vector must be the same length as vectorName. 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.

<a name="vectorName-split"></a>
**vectorName split** *dstName ?dstName?...*

> Split the vector into a multiple vectors. The resulting N vectors each contain the mod-Nth element from source.

<a name="vectorName-variable"></a>
**vectorName 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.

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

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.

> <code>
typedef struct {  
double valueArr;  
int numValues;  
int arraySize;    
double min, max;  
} **Rbc_Vector**;  
</code>

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.

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

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

**Rbc_CreateVector**

> Synopsis:

> > `int Rbc_CreateVector(Tcl_Interp *interp; char *vectorName; int length; Rbc_Vector **vecPtrPtr);`

> Description:

> > Creates a new vector vectorName with a length of length. Rbc_CreateVector creates both a new Tcl command and array variable vectorName. Neither a command nor variable named vectorName can already exist. A pointer to the vector is placed into vecPtrPtr.

> Results:

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

**Rbc_VectorFree**

> Synopsis:

> > `int Rbc_VectorFree(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 vectorName is not the name a vector, then TCL_ERROR is returned.

**Rbc_GetVector**

> Synopsis:

> > `int Rbc_GetVector(Tcl_Interp *interp; char *vectorName; Rbc_Vector **vecPtrPtr);`

> Description:

> > Retrieves the vector vectorName. 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 vectorName 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(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 vectorName 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(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(Tcl_Interp *interp; char *vectorName);` 

> Description:

> > Indicates if a vector named vectorName exists in interp.

> Results:

> > Returns 1 if a vector vectorName 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 { RBC_VECTOR_NOTIFY_UPDATE=1, RBC_VECTOR_NOTIFY_DESTROY=2 } Rbc_VectorNotify;`

**Rbc_AllocVectorId**

> Synopsis:

> > `Rbc_VectorId Rbc_AllocVectorId(Tcl_Interp *interp; char *vectorName);` 

> Description:

> > Allocates an client identifier for with the vector vectorName. 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 vectorName is not the name of a vector, then NULL is returned and interp->result will contain an error message.

**Rbc_GetVectorById**

> Synopsis:

> > `int Rbc_GetVectorById(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(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(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(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.

<a name="C-API-EXAMPLE"></a>
## 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 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).

> <code>
  #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;  
  }  
</code>

<a name="INCOMPATIBILITIES"></a>
## 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.

> <code>
proc doit {} {  
    # Temporary vector x  
    vector x(10)  
    set x(9) 2.0  
      ...  
}  
</code>

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

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

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

> <code>
 # Create a new vector.  
graph::vector create y(50)  
</code>

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.

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

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.

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

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

> <code>
 # Set the first six components of y  
set y(0:5) 25.2  
</code>

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

> <code>
 # Print out all the components of y  
puts "y = $y(:)"  
</code>

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.

> <code>
 # Extend the vector by one component.  
set y(++end) 0.02  
</code>

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

> <code>
 # Print the bounds of the vector  
puts "min=$y(min) max=$y(max)"  
</code>

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.

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

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

> <code>
 # Create and set the components of a new vector  
graph::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 }  
</code>

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.

> <code>
 # List the components  
puts "x = [x range 0 end]"  
</code>

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 "".

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

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

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

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.

> <code>
 # Sort the data points  
x sort y  
</code>

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.

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

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.

> <code>
 # 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}  
</code>

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

> <code>
 # Remove vector x  
graph::vector destroy x  
</code>

The pseudo 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.

> <code>
graph::vector create A(10)  
graph::vector create B(10)  
graph::vector create S(10)  
graph::vector create T(10)  
graph::S expr A+B  
graph::T expr S+last; # Running total  
</code>

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

vector, graph, widget

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

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

&copy; 2001 George A. Howlett.

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


Changes to generic/rbc/rbcConfig.c.

51
52
53
54
55
56
57


















58
59
60
61
62
63
64
...
323
324
325
326
327
328
329
























































330
331
332
333
334
335
336
    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,
................................................................................
        return "none";
    case FILL_BOTH:
        return "both";
    default:
        return "unknown value";
    }
}

























































/*
 *----------------------------------------------------------------------
 *
 * RbcGetPixels --
 *
 *      Like Tk_GetPixels, but checks for negative, zero.






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
...
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
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcFillOption = {
    StringToFill, FillToString, (ClientData) 0
};

static int      StringToStyle(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
    int flags);
static const char *StyleToString(
    ClientData clientData,
    Tk_Window tkwin,
    char *widgRec,
    int offset,
    Tcl_FreeProc ** freeProcPtr);

Tk_CustomOption rbcStyleOption = {
    StringToStyle, StyleToString, (ClientData) 0
};

static int      StringToPad(
    ClientData clientData,
    Tcl_Interp * interp,
    Tk_Window tkwin,
    const char *string,
    char *widgRec,
................................................................................
        return "none";
    case FILL_BOTH:
        return "both";
    default:
        return "unknown value";
    }
}


/*
 *----------------------------------------------------------------------
 *
 * StringToStyle --
 *
 *      Not possible. throw an error.
 *
 * Results:
 *      Return error message.
 *
 * Side Effects:
 *      None
 *
 *----------------------------------------------------------------------
 */
static int
StringToStyle(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,        /* Interpreter to send results back to */
    Tk_Window tkwin,            /* Not used. */
    const char *string,         /* New string */
    char *widgRec,              /* Structure record */
    int offset)
{                               /* Offset of style in record */
    Tcl_AppendResult(interp, "-style can only be set in constructor", (char *) NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * StyleToString --
 *
 *      Returns the fill style string based upon the fill flags.
 *
 * Results:
 *      The string is returned.
 *
 * Side Effects:
 *      None
 *
 *----------------------------------------------------------------------
 */
static const char *
StyleToString(
    ClientData clientData,      /* Not used. */
    Tk_Window tkwin,            /* Not used. */
    char *widgRec,              /* Widget structure record */
    int offset,                 /* String in widget record */
    Tcl_FreeProc ** freeProcPtr)
{                               /* Not used. */
    return (widgRec + offset);
}


/*
 *----------------------------------------------------------------------
 *
 * RbcGetPixels --
 *
 *      Like Tk_GetPixels, but checks for negative, zero.

Changes to generic/rbc/rbcGrBar.c.

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#define	DEF_PEN_VALUE_FORMAT        "%g"
#define	DEF_PEN_VALUE_ROTATE        (char *)NULL
#define	DEF_PEN_VALUE_SHADOW        (char *)NULL
#define DEF_PEN_SHOW_VALUES         "no"

#define FreeElemVector(v) \
    if ((v).clientId != NULL) { \
	RbcFreeVectorId((v).clientId); \
    } else if ((v).valueArr != NULL) { \
	ckfree((char *)(v).valueArr); \
    }

static Tk_ConfigSpec barPenConfigSpecs[] = {
    {TK_CONFIG_BORDER, "-background", "background", "Background",
            DEF_PEN_ACTIVE_BACKGROUND, Tk_Offset(BarPen, border),






|







250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#define	DEF_PEN_VALUE_FORMAT        "%g"
#define	DEF_PEN_VALUE_ROTATE        (char *)NULL
#define	DEF_PEN_VALUE_SHADOW        (char *)NULL
#define DEF_PEN_SHOW_VALUES         "no"

#define FreeElemVector(v) \
    if ((v).clientId != NULL) { \
	Rbc_FreeVectorId((v).clientId); \
    } else if ((v).valueArr != NULL) { \
	ckfree((char *)(v).valueArr); \
    }

static Tk_ConfigSpec barPenConfigSpecs[] = {
    {TK_CONFIG_BORDER, "-background", "background", "Background",
            DEF_PEN_ACTIVE_BACKGROUND, Tk_Offset(BarPen, border),

Changes to generic/rbc/rbcGrElem.c.

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
...
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
 *----------------------------------------------------------------------
 */
static void
FreeDataVector(
    RbcElemVector * vPtr)
{
    if (vPtr->clientId != NULL) {
        RbcFreeVectorId(vPtr->clientId);        /* Free the old vector */
        vPtr->clientId = NULL;
    } else if (vPtr->valueArr != NULL) {
        ckfree((char *) vPtr->valueArr);
    }
    vPtr->valueArr = NULL;
    vPtr->nValues = 0;
}
................................................................................
        vPtr->clientId = NULL;
        vPtr->valueArr = NULL;
        vPtr->nValues = 0;
        break;

    case RBC_VECTOR_NOTIFY_UPDATE:
    default:
        RbcGetVectorById(interp, vPtr->clientId, &vPtr->vecPtr);
        SyncElemVector(vPtr);
        break;
    }
    graphPtr->flags |= RBC_RESET_AXES;
    elemPtr->flags |= RBC_MAP_ITEM;
    if (!elemPtr->hidden) {
        graphPtr->flags |= RBC_REDRAW_BACKING_STORE;
................................................................................
    char *widgRec,              /* Element record */
    int offset)
{                               /* Offset of vector in Element record */
    RbcElement     *elemPtr = (RbcElement *) (widgRec);
    RbcElemVector  *vPtr = (RbcElemVector *) (widgRec + offset);

    FreeDataVector(vPtr);
    if (RbcVectorExists2(interp, string)) {
        RbcVectorId     clientId;

        clientId = RbcAllocVectorId(interp, string);
        if (RbcGetVectorById(interp, clientId, &vPtr->vecPtr) != TCL_OK) {
            return TCL_ERROR;
        }
        RbcSetVectorChangedProc(clientId, VectorChangedProc, vPtr);
        vPtr->elemPtr = elemPtr;
        vPtr->clientId = clientId;
        SyncElemVector(vPtr);
        elemPtr->flags |= RBC_MAP_ITEM;
    } else {
        double         *newArr;
        int             nValues;
................................................................................
    RbcElement     *elemPtr = (RbcElement *) (widgRec);
    Tcl_DString     dString;
    char           *result;
    char            string[TCL_DOUBLE_SPACE + 1];
    double         *p, *endPtr;

    if (vPtr->clientId != NULL) {
        return RbcNameOfVectorId(vPtr->clientId);
    }
    if (vPtr->nValues == 0) {
        return "";
    }
    Tcl_DStringInit(&dString);
    endPtr = vPtr->valueArr + vPtr->nValues;
    for (p = vPtr->valueArr; p < endPtr; p++) {






|







 







|







 







|



|


|







 







|







334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
...
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
 *----------------------------------------------------------------------
 */
static void
FreeDataVector(
    RbcElemVector * vPtr)
{
    if (vPtr->clientId != NULL) {
        Rbc_FreeVectorId(vPtr->clientId);        /* Free the old vector */
        vPtr->clientId = NULL;
    } else if (vPtr->valueArr != NULL) {
        ckfree((char *) vPtr->valueArr);
    }
    vPtr->valueArr = NULL;
    vPtr->nValues = 0;
}
................................................................................
        vPtr->clientId = NULL;
        vPtr->valueArr = NULL;
        vPtr->nValues = 0;
        break;

    case RBC_VECTOR_NOTIFY_UPDATE:
    default:
        Rbc_GetVectorById(interp, vPtr->clientId, &vPtr->vecPtr);
        SyncElemVector(vPtr);
        break;
    }
    graphPtr->flags |= RBC_RESET_AXES;
    elemPtr->flags |= RBC_MAP_ITEM;
    if (!elemPtr->hidden) {
        graphPtr->flags |= RBC_REDRAW_BACKING_STORE;
................................................................................
    char *widgRec,              /* Element record */
    int offset)
{                               /* Offset of vector in Element record */
    RbcElement     *elemPtr = (RbcElement *) (widgRec);
    RbcElemVector  *vPtr = (RbcElemVector *) (widgRec + offset);

    FreeDataVector(vPtr);
    if (Rbc_VectorExists(interp, string)) {
        RbcVectorId     clientId;

        clientId = RbcAllocVectorId(interp, string);
        if (Rbc_GetVectorById(interp, clientId, &vPtr->vecPtr) != TCL_OK) {
            return TCL_ERROR;
        }
        Rbc_SetVectorChangedProc(clientId, VectorChangedProc, vPtr);
        vPtr->elemPtr = elemPtr;
        vPtr->clientId = clientId;
        SyncElemVector(vPtr);
        elemPtr->flags |= RBC_MAP_ITEM;
    } else {
        double         *newArr;
        int             nValues;
................................................................................
    RbcElement     *elemPtr = (RbcElement *) (widgRec);
    Tcl_DString     dString;
    char           *result;
    char            string[TCL_DOUBLE_SPACE + 1];
    double         *p, *endPtr;

    if (vPtr->clientId != NULL) {
        return Rbc_NameOfVectorId(vPtr->clientId);
    }
    if (vPtr->nValues == 0) {
        return "";
    }
    Tcl_DStringInit(&dString);
    endPtr = vPtr->valueArr + vPtr->nValues;
    for (p = vPtr->valueArr; p < endPtr; p++) {

Changes to generic/rbc/rbcGrLine.c.

5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
                               linePtr->symbolToData + count);
        }
        count += stylePtr->nSymbolPts;
    }
}
#define FreeVector(v) \
    if ((v).clientId != NULL) { \
	RbcFreeVectorId((v).clientId); \
    } else if ((v).valueArr != NULL) { \
	ckfree((char *)(v).valueArr); \
    }
/*
 *----------------------------------------------------------------------
 *
 * DestroyLine --






|







5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
                               linePtr->symbolToData + count);
        }
        count += stylePtr->nSymbolPts;
    }
}
#define FreeVector(v) \
    if ((v).clientId != NULL) { \
	Rbc_FreeVectorId((v).clientId); \
    } else if ((v).valueArr != NULL) { \
	ckfree((char *)(v).valueArr); \
    }
/*
 *----------------------------------------------------------------------
 *
 * DestroyLine --

Changes to generic/rbc/rbcGrPs.c.

704
705
706
707
708
709
710

711
712
713
714
715
716
717
...
767
768
769
770
771
772
773
774


775
776

777
778
779
780
781
782
783
....
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
    char            date[200];  /* Hold the date string from ctime() */
    const char     *version;
    double          dpiX, dpiY;
    double          xPixelsToPica, yPixelsToPica;       /* Scales to convert pixels to pica */
    Screen         *screenPtr;
    char           *nl;
    int             paperHeightPixels;


    paperHeightPixels = ComputeBoundingBox(graphPtr, psPtr);
    if (fileName == NULL) {
        fileName = Tk_PathName(graphPtr->tkwin);
    }
    RbcAppendToPostScript(psToken, "%!PS-Adobe-3.0 EPSF-3.0\n", (char *) NULL);

................................................................................
    }
    RbcAppendToPostScript(psToken,
        "%%DocumentNeededResources: font Helvetica Courier\n", (char *) NULL);
    RbcAppendToPostScript(psToken, "%%EndComments\n\n", (char *) NULL);
    if ((psPtr->addPreview) && (psPtr->previewFormat == PS_PREVIEW_EPSI)) {
        PreviewImage(graphPtr, psToken);
    }
    if (RbcFileToPostScript(psToken, "rbcGraph.pro") != TCL_OK) {


        return TCL_ERROR;
    }

    if (psPtr->footer) {
        const char     *who;

        who = getenv("LOGNAME");
        if (who == NULL) {
            who = "???";
        }
................................................................................
    result = TCL_ERROR;
    hRefDC = TkWinGetDrawableDC(graphPtr->display,
        Tk_WindowId(graphPtr->tkwin), &state);

    /* Build a description string. */
    Tcl_DStringInit(&dString);
    Tcl_DStringAppend(&dString, "Rbc Graph ", -1);
    Tcl_DStringAppend(&dString, RBC_VERSION, -1);
    Tcl_DStringAppend(&dString, "\0", -1);
    Tcl_DStringAppend(&dString, Tk_PathName(graphPtr->tkwin), -1);
    Tcl_DStringAppend(&dString, "\0", -1);

    hDC = CreateEnhMetaFileA(hRefDC, NULL, NULL, Tcl_DStringValue(&dString));
    Tcl_DStringFree(&dString);







>







 







|
>
>
|

>







 







<







704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
...
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
....
1097
1098
1099
1100
1101
1102
1103

1104
1105
1106
1107
1108
1109
1110
    char            date[200];  /* Hold the date string from ctime() */
    const char     *version;
    double          dpiX, dpiY;
    double          xPixelsToPica, yPixelsToPica;       /* Scales to convert pixels to pica */
    Screen         *screenPtr;
    char           *nl;
    int             paperHeightPixels;
    Tcl_Obj *preambleObj;

    paperHeightPixels = ComputeBoundingBox(graphPtr, psPtr);
    if (fileName == NULL) {
        fileName = Tk_PathName(graphPtr->tkwin);
    }
    RbcAppendToPostScript(psToken, "%!PS-Adobe-3.0 EPSF-3.0\n", (char *) NULL);

................................................................................
    }
    RbcAppendToPostScript(psToken,
        "%%DocumentNeededResources: font Helvetica Courier\n", (char *) NULL);
    RbcAppendToPostScript(psToken, "%%EndComments\n\n", (char *) NULL);
    if ((psPtr->addPreview) && (psPtr->previewFormat == PS_PREVIEW_EPSI)) {
        PreviewImage(graphPtr, psToken);
    }
    preambleObj = Tcl_GetVar2Ex(graphPtr->interp, "::graph::ps_preamble", NULL,
	    TCL_LEAVE_ERR_MSG);
    if (preambleObj == NULL) {
	    return TCL_ERROR;
    }
    RbcAppendToPostScript(psToken, Tcl_GetString(preambleObj), (char *) NULL);
    if (psPtr->footer) {
        const char     *who;

        who = getenv("LOGNAME");
        if (who == NULL) {
            who = "???";
        }
................................................................................
    result = TCL_ERROR;
    hRefDC = TkWinGetDrawableDC(graphPtr->display,
        Tk_WindowId(graphPtr->tkwin), &state);

    /* Build a description string. */
    Tcl_DStringInit(&dString);
    Tcl_DStringAppend(&dString, "Rbc Graph ", -1);

    Tcl_DStringAppend(&dString, "\0", -1);
    Tcl_DStringAppend(&dString, Tk_PathName(graphPtr->tkwin), -1);
    Tcl_DStringAppend(&dString, "\0", -1);

    hDC = CreateEnhMetaFileA(hRefDC, NULL, NULL, Tcl_DStringValue(&dString));
    Tcl_DStringFree(&dString);

Changes to generic/rbc/rbcGraph.c.

42
43
44
45
46
47
48

49
50
51
52
53
54
55
...
121
122
123
124
125
126
127


128
129
130
131
132
133
134
...
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
...
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
...
353
354
355
356
357
358
359















































360
361
362
363
364
365
366
...
389
390
391
392
393
394
395



396
397
398
399
400
401
402
...
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
...
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
....
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
....
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
....
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
....
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
....
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
....
2320
2321
2322
2323
2324
2325
2326



2327
2328
2329
2330
2331
2332
2333
....
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
....
2482
2483
2484
2485
2486
2487
2488
2489



























































































































































































































































































































































































































2490
extern Tk_CustomOption rbcLinePenOption;
extern Tk_CustomOption rbcBarPenOption;
extern Tk_CustomOption rbcDistanceOption;
extern Tk_CustomOption rbcBarModeOption;
extern Tk_CustomOption rbcPadOption;
extern Tk_CustomOption rbcTileOption;
extern Tk_CustomOption rbcShadowOption;


#define DEF_GRAPH_ASPECT_RATIO      "0.0"
#define DEF_GRAPH_BAR_BASELINE      "0.0"
#define DEF_GRAPH_BAR_MODE          "normal"
#define DEF_GRAPH_BAR_WIDTH         "0.8"
#define DEF_GRAPH_BACKGROUND        RBC_NORMAL_BACKGROUND
#define DEF_GRAPH_BG_MONO           RBC_NORMAL_BG_MONO
................................................................................
        TK_CONFIG_NULL_OK},
    {TK_CONFIG_BOOLEAN, "-bufferelements", "bufferElements", "BufferElements",
            DEF_GRAPH_BUFFER_ELEMENTS, Tk_Offset(RbcGraph, backingStore),
        TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_BOOLEAN, "-buffergraph", "bufferGraph", "BufferGraph",
            DEF_GRAPH_BUFFER_GRAPH, Tk_Offset(RbcGraph, doubleBuffer),
        TK_CONFIG_DONT_SET_DEFAULT},


    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", DEF_GRAPH_CURSOR,
        Tk_Offset(RbcGraph, cursor), TK_CONFIG_NULL_OK},
    {TK_CONFIG_STRING, "-data", "data", "Data", (char *) NULL,
        Tk_Offset(RbcGraph, data), TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_STRING, "-datacommand", "dataCommand", "DataCommand",
            (char *) NULL, Tk_Offset(RbcGraph, dataCmd),
        TK_CONFIG_DONT_SET_DEFAULT},
................................................................................
};

static Tcl_IdleProc DisplayGraph;
static Tcl_FreeProc DestroyGraph;
static Tk_EventProc GraphEventProc;

static RbcBindPickProc PickEntry;
static Tcl_CmdProc StripchartCmd;
static Tcl_CmdProc BarchartCmd;
static Tcl_CmdProc GraphCmd;
static Tcl_CmdDeleteProc GraphInstCmdDeleteProc;
static RbcTileChangedProc TileChangedProc;

static void     AdjustAxisPointers(
    RbcGraph * graphPtr);
static int      InitPens(
    RbcGraph * graphPtr);
static RbcGraph *CreateGraph(
    Tcl_Interp * interp,
    int argc,
    const const char **argv,
    RbcUid classUid);
static void     ConfigureGraph(
    RbcGraph * graphPtr);
static int      NewGraph(
    Tcl_Interp * interp,
    int argc,
    const char **argv,
    RbcUid classUid);
static void     DrawMargins(
    RbcGraph * graphPtr,
    Drawable drawable);
static void     DrawPlotRegion(
    RbcGraph * graphPtr,
    Drawable drawable);
static void     UpdateMarginTraces(
................................................................................
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int      ConfigureOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const const char **argv);
static int      CgetOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int      ExtentsOp(
    RbcGraph * graphPtr,
................................................................................
    int argc,
    const char **argv);
static int      SnapOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
















































#ifdef __WIN32
static int      InitMetaFileHeader(
    Tk_Window tkwin,
    int width,
    int height,
    APMHEADER * mfhPtr);
................................................................................
 *
 *--------------------------------------------------------------
 */
void
RbcEventuallyRedrawGraph(
    RbcGraph * graphPtr)
{                               /* Graph widget record */



    if ((graphPtr->tkwin != NULL) && !(graphPtr->flags & RBC_REDRAW_PENDING)) {
        Tcl_DoWhenIdle(DisplayGraph, graphPtr);
        graphPtr->flags |= RBC_REDRAW_PENDING;
    }
}

/*
................................................................................
            } else {
                graphPtr->flags &= ~RBC_GRAPH_FOCUS;
            }
            graphPtr->flags |= RBC_REDRAW_WORLD;
            RbcEventuallyRedrawGraph(graphPtr);
        }
    } else if (eventPtr->type == DestroyNotify) {


        if (graphPtr->tkwin != NULL) {
            RbcDeleteWindowInstanceData(graphPtr->tkwin);
            graphPtr->tkwin = NULL;
            Tcl_DeleteCommandFromToken(graphPtr->interp, graphPtr->cmdToken);
        }
        if (graphPtr->flags & RBC_REDRAW_PENDING) {
            Tcl_CancelIdleCall(DisplayGraph, graphPtr);
        }
        Tcl_EventuallyFree(graphPtr, DestroyGraph);

    } else if (eventPtr->type == ConfigureNotify) {
        graphPtr->flags |= (RBC_MAP_WORLD | RBC_REDRAW_WORLD);
        RbcEventuallyRedrawGraph(graphPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * GraphInstCmdDeleteProc --
 *
 *      This procedure is invoked when a widget command is deleted.  If
 *      the widget isn't already in the process of being destroyed,
 *      this command destroys it.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      The widget is destroyed.
 *
 *---------------------------------------------------------------------- */
static void
GraphInstCmdDeleteProc(
    ClientData clientData)
{                               /* Pointer to widget record. */
    RbcGraph       *graphPtr = clientData;

    if (graphPtr->tkwin != NULL) {      /* NULL indicates window has
                                         * already been destroyed. */
        Tk_Window       tkwin;

        tkwin = graphPtr->tkwin;
        graphPtr->tkwin = NULL;
        RbcDeleteWindowInstanceData(tkwin);
        Tk_DestroyWindow(tkwin);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TileChangedProc --
 *
 *      Rebuilds the designated GC with the new tile pixmap.
 *
................................................................................
    }
    if (graphPtr->tile != NULL) {
        RbcFreeTile(graphPtr->tile);
    }
    ckfree((char *) graphPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * CreateGraph --
 *
 *      This procedure creates and initializes a new widget.
 *
 * Results:
 *      The return value is a pointer to a structure describing
 *      the new widget.  If an error occurred, then the return
 *      value is NULL and an error message is left in interp->result.
 *
 * Side effects:
 *      Memory is allocated, a Tk_Window is created, etc.
 *
 *----------------------------------------------------------------------
 */
static RbcGraph *
CreateGraph(
    Tcl_Interp * interp,
    int argc,
    const char **argv,
    RbcUid classUid)
{
    RbcGraph       *graphPtr;
    Tk_Window       tkwin;

    tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1],
        (char *) NULL);
    if (tkwin == NULL) {
        return NULL;
    }
    graphPtr = RbcCalloc(1, sizeof(RbcGraph));
    assert(graphPtr);
    /* Initialize the graph data structure. */

    graphPtr->tkwin = tkwin;
    graphPtr->display = Tk_Display(tkwin);
    graphPtr->interp = interp;
    graphPtr->classUid = classUid;
    graphPtr->backingStore = TRUE;
    graphPtr->doubleBuffer = TRUE;
    graphPtr->highlightWidth = 2;
    graphPtr->plotRelief = TK_RELIEF_SUNKEN;
    graphPtr->relief = TK_RELIEF_FLAT;
    graphPtr->flags = (RBC_RESET_WORLD);
    graphPtr->nextMarkerId = 1;
    graphPtr->padX.side1 = graphPtr->padX.side2 = 8;
    graphPtr->padY.side1 = graphPtr->padY.side2 = 8;
    graphPtr->margins[RBC_MARGIN_BOTTOM].site = RBC_MARGIN_BOTTOM;
    graphPtr->margins[RBC_MARGIN_LEFT].site = RBC_MARGIN_LEFT;
    graphPtr->margins[RBC_MARGIN_TOP].site = RBC_MARGIN_TOP;
    graphPtr->margins[RBC_MARGIN_RIGHT].site = RBC_MARGIN_RIGHT;
    RbcInitTextStyle(&graphPtr->titleTextStyle);

    Tcl_InitHashTable(&graphPtr->axes.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->axes.tagTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->elements.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->elements.tagTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->markers.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->markers.tagTable, TCL_STRING_KEYS);
    graphPtr->elements.displayList = RbcChainCreate();
    graphPtr->markers.displayList = RbcChainCreate();
    graphPtr->axes.displayList = RbcChainCreate();

    if (classUid == rbcLineElementUid) {
        Tk_SetClass(tkwin, "Graph");
    } else if (classUid == rbcBarElementUid) {
        Tk_SetClass(tkwin, "Barchart");
    } else if (classUid == rbcStripElementUid) {
        Tk_SetClass(tkwin, "Stripchart");
    }
    RbcSetWindowInstanceData(tkwin, graphPtr);

    if (InitPens(graphPtr) != TCL_OK) {
        goto error;
    }
    if (Tk_ConfigureWidget(interp, tkwin, configSpecs, argc - 2, argv + 2,
            (char *) graphPtr, 0) != TCL_OK) {
        goto error;
    }
    if (RbcDefaultAxes(graphPtr) != TCL_OK) {
        goto error;
    }
    AdjustAxisPointers(graphPtr);

    if (RbcCreatePostScript(graphPtr) != TCL_OK) {
        goto error;
    }
    if (RbcCreateCrosshairs(graphPtr) != TCL_OK) {
        goto error;
    }
    if (RbcCreateLegend(graphPtr) != TCL_OK) {
        goto error;
    }
    if (RbcCreateGrid(graphPtr) != TCL_OK) {
        goto error;
    }
    Tk_CreateEventHandler(graphPtr->tkwin,
        ExposureMask | StructureNotifyMask | FocusChangeMask, GraphEventProc,
        graphPtr);

    graphPtr->cmdToken =
        Tcl_CreateCommand(interp, argv[1], RbcGraphInstCmdProc, graphPtr,
        GraphInstCmdDeleteProc);
    ConfigureGraph(graphPtr);
    graphPtr->bindTable =
        RbcCreateBindingTable(interp, tkwin, graphPtr, PickEntry);
    return graphPtr;

  error:
    DestroyGraph((char *) graphPtr);
    return NULL;
}

/* Widget sub-commands */

/*
 *----------------------------------------------------------------------
 *
 * XAxisOp --
 *
................................................................................
    HANDLE          hMem;
    LPVOID          buffer;
    int             result;
    DWORD           count, nBytes;

    result = TCL_ERROR;
    hMem = NULL;
    hFile = CreateFile(fileName,        /* File path */
        GENERIC_WRITE,          /* Access mode */
        0,                      /* No sharing. */
        NULL,                   /* Security attributes */
        CREATE_ALWAYS,          /* Overwrite any existing file */
        FILE_ATTRIBUTE_NORMAL, NULL);   /* No template file */
    if (hFile == INVALID_HANDLE_VALUE) {
        Tcl_AppendResult(interp, "can't create metafile \"", fileName,
................................................................................
    }
    i += 2;
    if (i >= argc) {
        Tcl_AppendResult(interp, "missing name argument: should be \"",
            argv[0], "snap ?switches? name\"", (char *) NULL);
        return TCL_ERROR;
    }
    data.name = argv[i];
    if (data.width < 2) {
        data.width = 400;
    }
    if (data.height < 2) {
        data.height = 400;
    }
    /* Always re-compute the layout of the graph before snapping the photo. */
................................................................................
        Tcl_DStringInit(&dString);
        Tcl_DStringAppend(&dString, "RBC Graph ", -1);
        Tcl_DStringAppend(&dString, RBC_VERSION, -1);
        Tcl_DStringAppend(&dString, "\0", -1);
        Tcl_DStringAppend(&dString, Tk_PathName(graphPtr->tkwin), -1);
        Tcl_DStringAppend(&dString, "\0", -1);
        title = Tcl_DStringValue(&dString);
        hDC = CreateEnhMetaFile(hRefDC, NULL, NULL, title);
        Tcl_DStringFree(&dString);

        if (hDC == NULL) {
            Tcl_AppendResult(interp, "can't create metafile: ",
                RbcLastError(), (char *) NULL);
            return TCL_ERROR;
        }
................................................................................
                InitMetaFileHeader(graphPtr->tkwin, data.width, data.height,
                    &mfh);
                result = CreateAPMetaFile(interp, hMetaFile, hRefDC, &mfh,
                    data.name);
            } else {
                HENHMETAFILE    hMetaFile2;

                hMetaFile2 = CopyEnhMetaFile(hMetaFile, data.name);
                if (hMetaFile2 != NULL) {
                    result = TCL_OK;
                    DeleteEnhMetaFile(hMetaFile2);
                }
            }
            DeleteEnhMetaFile(hMetaFile);
        }
................................................................................
    }
    Tcl_Preserve(graphPtr);
    result = (*proc) (graphPtr, interp, argc, argv);
    Tcl_Release(graphPtr);
    return result;
}

/*
 * --------------------------------------------------------------------------
 *
 * NewGraph --
 *
 *      Creates a new window and Tcl command representing an
 *      instance of a graph widget.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side effects:
 *      See the user documentation.
 *
 * --------------------------------------------------------------------------
 */
static int
NewGraph(
    Tcl_Interp * interp,
    int argc,
    const char **argv,
    RbcUid classUid)
{
    RbcGraph       *graphPtr;
    if (argc < 2) {
        Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
            " pathName ?option value?...\"", (char *) NULL);
        return TCL_ERROR;
    }
    graphPtr = CreateGraph(interp, argc, argv, classUid);
    if (graphPtr == NULL) {
        return TCL_ERROR;
    }
    Tcl_SetObjResult(interp, Tcl_NewStringObj(Tk_PathName(graphPtr->tkwin),
            -1));
    return TCL_OK;
}

/*
 * --------------------------------------------------------------------------
 *
 * GraphCmd --
 *
 *      Creates a new window and Tcl command representing an
 *      instance of a graph widget.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side effects:
 *      See the user documentation.
 *
 * --------------------------------------------------------------------------
 */
static int
GraphCmd(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,
    int argc,
    const char *argv[])
{
    return NewGraph(interp, argc, argv, rbcLineElementUid);
}

/*
 *--------------------------------------------------------------
 *
 * BarchartCmd --
 *
 *      Creates a new window and Tcl command representing an
 *      instance of a barchart widget.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side effects:
 *      See the user documentation.
 *
 *--------------------------------------------------------------
 */
static int
BarchartCmd(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,
    int argc,
    const char *argv[])
{
    return NewGraph(interp, argc, argv, rbcBarElementUid);
}

/*
 *--------------------------------------------------------------
 *
 * StripchartCmd --
 *
 *      Creates a new window and Tcl command representing an
 *      instance of a barchart widget.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side effects:
 *      See the user documentation.
 *
 *--------------------------------------------------------------
 */
static int
StripchartCmd(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,
    int argc,
    const char *argv[])
{
    return NewGraph(interp, argc, argv, rbcStripElementUid);
}

/*
 * -----------------------------------------------------------------------
 *
 * DrawMargins --
 *
 *      Draws the exterior region of the graph (axes, ticks, titles, etc)
 *      onto a pixmap. The interior region is defined by the given
................................................................................
static void
DisplayGraph(
    ClientData clientData)
{
    RbcGraph       *graphPtr = clientData;
    Pixmap          drawable;




    graphPtr->flags &= ~RBC_REDRAW_PENDING;
    if (graphPtr->tkwin == NULL) {
        return;                 /* Window destroyed (should not get here) */
    }
    if (RbcGraphUpdateNeeded(graphPtr)) {
        /*
         * One of the elements of the graph has a vector notification
................................................................................
    graphPtr->flags &= ~RBC_RESET_WORLD;
    UpdateMarginTraces(graphPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGraphInit --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 *
 *----------------------------------------------------------------------
 */
int
RbcGraphInit(
    Tcl_Interp * interp)
{
    rbcBarElementUid = (RbcUid) Tk_GetUid("BarElement");
    rbcLineElementUid = (RbcUid) Tk_GetUid("LineElement");
    rbcStripElementUid = (RbcUid) Tk_GetUid("StripElement");
    rbcContourElementUid = (RbcUid) Tk_GetUid("ContourElement");

    rbcLineMarkerUid = (RbcUid) Tk_GetUid("LineMarker");
    rbcBitmapMarkerUid = (RbcUid) Tk_GetUid("BitmapMarker");
    rbcImageMarkerUid = (RbcUid) Tk_GetUid("ImageMarker");
    rbcTextMarkerUid = (RbcUid) Tk_GetUid("TextMarker");
    rbcPolygonMarkerUid = (RbcUid) Tk_GetUid("PolygonMarker");
    rbcWindowMarkerUid = (RbcUid) Tk_GetUid("WindowMarker");

    rbcXAxisUid = (RbcUid) Tk_GetUid("X");
    rbcYAxisUid = (RbcUid) Tk_GetUid("Y");

    Tcl_CreateCommand(interp, "rbc::graph", GraphCmd, (ClientData) NULL,
        (Tcl_CmdDeleteProc *) NULL);
    Tcl_CreateCommand(interp, "rbc::barchart", BarchartCmd, (ClientData) NULL,
        (Tcl_CmdDeleteProc *) NULL);
    Tcl_CreateCommand(interp, "rbc::stripchart", StripchartCmd,
        (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * RbcGetGraphFromWindowData --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
................................................................................
    } else if (graphPtr->classUid == rbcBarElementUid) {
        return RBC_BARCHART;
    } else if (graphPtr->classUid == rbcStripElementUid) {
        return RBC_STRIPCHART;
    }
    return 0;
}




























































































































































































































































































































































































































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






>







 







>
>







 







<
<
<
<






<
<
<
<
<


<
<
<
<
<







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>







 







>
>
|
|
|
|
|
|
|
|
|
>






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







 







|







 







|







 







|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
255
256
257
258
259
260
261




262
263
264
265
266
267





268
269





270
271
272
273
274
275
276
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
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
...
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
...
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
...
896
897
898
899
900
901
902



















































































































903
904
905
906
907
908
909
....
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
....
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
....
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
....
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
....
1769
1770
1771
1772
1773
1774
1775




















































































































1776
1777
1778
1779
1780
1781
1782
....
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
....
2164
2165
2166
2167
2168
2169
2170











































2171
2172
2173
2174
2175
2176
2177
....
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
extern Tk_CustomOption rbcLinePenOption;
extern Tk_CustomOption rbcBarPenOption;
extern Tk_CustomOption rbcDistanceOption;
extern Tk_CustomOption rbcBarModeOption;
extern Tk_CustomOption rbcPadOption;
extern Tk_CustomOption rbcTileOption;
extern Tk_CustomOption rbcShadowOption;
extern Tk_CustomOption rbcStyleOption;

#define DEF_GRAPH_ASPECT_RATIO      "0.0"
#define DEF_GRAPH_BAR_BASELINE      "0.0"
#define DEF_GRAPH_BAR_MODE          "normal"
#define DEF_GRAPH_BAR_WIDTH         "0.8"
#define DEF_GRAPH_BACKGROUND        RBC_NORMAL_BACKGROUND
#define DEF_GRAPH_BG_MONO           RBC_NORMAL_BG_MONO
................................................................................
        TK_CONFIG_NULL_OK},
    {TK_CONFIG_BOOLEAN, "-bufferelements", "bufferElements", "BufferElements",
            DEF_GRAPH_BUFFER_ELEMENTS, Tk_Offset(RbcGraph, backingStore),
        TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_BOOLEAN, "-buffergraph", "bufferGraph", "BufferGraph",
            DEF_GRAPH_BUFFER_GRAPH, Tk_Offset(RbcGraph, doubleBuffer),
        TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_CUSTOM, "-style", "style", "Style", NULL,
        Tk_Offset(RbcGraph, chartStyle), 0, &rbcStyleOption},
    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", DEF_GRAPH_CURSOR,
        Tk_Offset(RbcGraph, cursor), TK_CONFIG_NULL_OK},
    {TK_CONFIG_STRING, "-data", "data", "Data", (char *) NULL,
        Tk_Offset(RbcGraph, data), TK_CONFIG_DONT_SET_DEFAULT},
    {TK_CONFIG_STRING, "-datacommand", "dataCommand", "DataCommand",
            (char *) NULL, Tk_Offset(RbcGraph, dataCmd),
        TK_CONFIG_DONT_SET_DEFAULT},
................................................................................
};

static Tcl_IdleProc DisplayGraph;
static Tcl_FreeProc DestroyGraph;
static Tk_EventProc GraphEventProc;

static RbcBindPickProc PickEntry;




static RbcTileChangedProc TileChangedProc;

static void     AdjustAxisPointers(
    RbcGraph * graphPtr);
static int      InitPens(
    RbcGraph * graphPtr);





static void     ConfigureGraph(
    RbcGraph * graphPtr);





static void     DrawMargins(
    RbcGraph * graphPtr,
    Drawable drawable);
static void     DrawPlotRegion(
    RbcGraph * graphPtr,
    Drawable drawable);
static void     UpdateMarginTraces(
................................................................................
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int      ConfigureOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int      CgetOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int      ExtentsOp(
    RbcGraph * graphPtr,
................................................................................
    int argc,
    const char **argv);
static int      SnapOp(
    RbcGraph * graphPtr,
    Tcl_Interp * interp,
    int argc,
    const char **argv);

static int GraphMethod(
    ClientData clientData,
    Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
static void GraphMetaDelete(ClientData clientData);
static int GraphConstructor(
    ClientData clientData,
    Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);

static Tcl_ObjectMetadataType pathMeta = {
    TCL_OO_METADATA_VERSION_CURRENT,
    "GraphMeta",
    GraphMetaDelete,
    NULL
};

static Tcl_MethodType graphMethods[] = {
    {TCL_OO_METHOD_VERSION_CURRENT,NULL , GraphConstructor    , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"axis" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"bar" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"cget" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"configure" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"crosshairs" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"element" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"extents" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"grid" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"inside" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"invtransform" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"legend" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"line" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"marker" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"pen" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"postscript" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"snap" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"transform" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"x2axis" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"xaxis" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"y2axis" , GraphMethod , NULL , NULL },
    {TCL_OO_METHOD_VERSION_CURRENT,"yaxis" , GraphMethod , NULL , NULL },
    { -1    , NULL          , NULL     , NULL , NULL }
};

#ifdef __WIN32
static int      InitMetaFileHeader(
    Tk_Window tkwin,
    int width,
    int height,
    APMHEADER * mfhPtr);
................................................................................
 *
 *--------------------------------------------------------------
 */
void
RbcEventuallyRedrawGraph(
    RbcGraph * graphPtr)
{                               /* Graph widget record */
    if ((graphPtr->flags & RBC_GRAPH_DELETED) || !Tk_IsMapped(graphPtr->tkwin)) {
    return;
    }
    if ((graphPtr->tkwin != NULL) && !(graphPtr->flags & RBC_REDRAW_PENDING)) {
        Tcl_DoWhenIdle(DisplayGraph, graphPtr);
        graphPtr->flags |= RBC_REDRAW_PENDING;
    }
}

/*
................................................................................
            } else {
                graphPtr->flags &= ~RBC_GRAPH_FOCUS;
            }
            graphPtr->flags |= RBC_REDRAW_WORLD;
            RbcEventuallyRedrawGraph(graphPtr);
        }
    } else if (eventPtr->type == DestroyNotify) {
        if (!(graphPtr->flags & RBC_GRAPH_DELETED)) {
            graphPtr->flags |= RBC_GRAPH_DELETED;
            if (graphPtr->tkwin != NULL) {
                RbcDeleteWindowInstanceData(graphPtr->tkwin);
                graphPtr->tkwin = NULL;
                Tcl_DeleteCommandFromToken(graphPtr->interp, graphPtr->cmdToken);
            }
            if (graphPtr->flags & RBC_REDRAW_PENDING) {
                Tcl_CancelIdleCall(DisplayGraph, graphPtr);
            }
            Tcl_EventuallyFree(graphPtr, DestroyGraph);
        }
    } else if (eventPtr->type == ConfigureNotify) {
        graphPtr->flags |= (RBC_MAP_WORLD | RBC_REDRAW_WORLD);
        RbcEventuallyRedrawGraph(graphPtr);
    }
}


































/*
 *----------------------------------------------------------------------
 *
 * TileChangedProc --
 *
 *      Rebuilds the designated GC with the new tile pixmap.
 *
................................................................................
    }
    if (graphPtr->tile != NULL) {
        RbcFreeTile(graphPtr->tile);
    }
    ckfree((char *) graphPtr);
}




















































































































/* Widget sub-commands */

/*
 *----------------------------------------------------------------------
 *
 * XAxisOp --
 *
................................................................................
    HANDLE          hMem;
    LPVOID          buffer;
    int             result;
    DWORD           count, nBytes;

    result = TCL_ERROR;
    hMem = NULL;
    hFile = CreateFile((LPCWSTR)fileName,        /* File path */
        GENERIC_WRITE,          /* Access mode */
        0,                      /* No sharing. */
        NULL,                   /* Security attributes */
        CREATE_ALWAYS,          /* Overwrite any existing file */
        FILE_ATTRIBUTE_NORMAL, NULL);   /* No template file */
    if (hFile == INVALID_HANDLE_VALUE) {
        Tcl_AppendResult(interp, "can't create metafile \"", fileName,
................................................................................
    }
    i += 2;
    if (i >= argc) {
        Tcl_AppendResult(interp, "missing name argument: should be \"",
            argv[0], "snap ?switches? name\"", (char *) NULL);
        return TCL_ERROR;
    }
    data.name = (char *)argv[i];
    if (data.width < 2) {
        data.width = 400;
    }
    if (data.height < 2) {
        data.height = 400;
    }
    /* Always re-compute the layout of the graph before snapping the photo. */
................................................................................
        Tcl_DStringInit(&dString);
        Tcl_DStringAppend(&dString, "RBC Graph ", -1);
        Tcl_DStringAppend(&dString, RBC_VERSION, -1);
        Tcl_DStringAppend(&dString, "\0", -1);
        Tcl_DStringAppend(&dString, Tk_PathName(graphPtr->tkwin), -1);
        Tcl_DStringAppend(&dString, "\0", -1);
        title = Tcl_DStringValue(&dString);
        hDC = CreateEnhMetaFile(hRefDC, NULL, NULL, (LPCWSTR)title);
        Tcl_DStringFree(&dString);

        if (hDC == NULL) {
            Tcl_AppendResult(interp, "can't create metafile: ",
                RbcLastError(), (char *) NULL);
            return TCL_ERROR;
        }
................................................................................
                InitMetaFileHeader(graphPtr->tkwin, data.width, data.height,
                    &mfh);
                result = CreateAPMetaFile(interp, hMetaFile, hRefDC, &mfh,
                    data.name);
            } else {
                HENHMETAFILE    hMetaFile2;

                hMetaFile2 = CopyEnhMetaFile(hMetaFile, (LPCWSTR)data.name);
                if (hMetaFile2 != NULL) {
                    result = TCL_OK;
                    DeleteEnhMetaFile(hMetaFile2);
                }
            }
            DeleteEnhMetaFile(hMetaFile);
        }
................................................................................
    }
    Tcl_Preserve(graphPtr);
    result = (*proc) (graphPtr, interp, argc, argv);
    Tcl_Release(graphPtr);
    return result;
}





















































































































/*
 * -----------------------------------------------------------------------
 *
 * DrawMargins --
 *
 *      Draws the exterior region of the graph (axes, ticks, titles, etc)
 *      onto a pixmap. The interior region is defined by the given
................................................................................
static void
DisplayGraph(
    ClientData clientData)
{
    RbcGraph       *graphPtr = clientData;
    Pixmap          drawable;

    if (graphPtr->flags & RBC_GRAPH_DELETED) {
    return;
    }
    graphPtr->flags &= ~RBC_REDRAW_PENDING;
    if (graphPtr->tkwin == NULL) {
        return;                 /* Window destroyed (should not get here) */
    }
    if (RbcGraphUpdateNeeded(graphPtr)) {
        /*
         * One of the elements of the graph has a vector notification
................................................................................
    graphPtr->flags &= ~RBC_RESET_WORLD;
    UpdateMarginTraces(graphPtr);
}

/*
 *----------------------------------------------------------------------
 *











































 * RbcGetGraphFromWindowData --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
................................................................................
    } else if (graphPtr->classUid == rbcBarElementUid) {
        return RBC_BARCHART;
    } else if (graphPtr->classUid == rbcStripElementUid) {
        return RBC_STRIPCHART;
    }
    return 0;
}

//============================================================================

/*
 *----------------------------------------------------------------------
 *
 * Rbc_GraphInit --
 *
 *        Initializer for the graph widget package.
 *
 * Results:
 *        A standard Tcl result.
 *
 * Side Effects:
 *       Tcl commands created
 *
 *----------------------------------------------------------------------
 */
int
Rbc_GraphInit(
    Tcl_Interp * interp)
{
    Tcl_Class clazz;
    Tcl_Object object;
    Tcl_Obj *objPtr;
    int i;
	static const char *initScript =
		"::oo::class create ::graph {"
		" self method unknown {args} {uplevel #0 ::graph create {*}$args; return [lindex $args 0]}\n"
        " self unexport new destroy\n"
        " unexport new create destroy\n"
        "}";

    rbcBarElementUid = (RbcUid) Tk_GetUid("BarElement");
    rbcLineElementUid = (RbcUid) Tk_GetUid("LineElement");
    rbcStripElementUid = (RbcUid) Tk_GetUid("StripElement");
    rbcContourElementUid = (RbcUid) Tk_GetUid("ContourElement");

    rbcLineMarkerUid = (RbcUid) Tk_GetUid("LineMarker");
    rbcBitmapMarkerUid = (RbcUid) Tk_GetUid("BitmapMarker");
    rbcImageMarkerUid = (RbcUid) Tk_GetUid("ImageMarker");
    rbcTextMarkerUid = (RbcUid) Tk_GetUid("TextMarker");
    rbcPolygonMarkerUid = (RbcUid) Tk_GetUid("PolygonMarker");
    rbcWindowMarkerUid = (RbcUid) Tk_GetUid("WindowMarker");

    rbcXAxisUid = (RbcUid) Tk_GetUid("X");
    rbcYAxisUid = (RbcUid) Tk_GetUid("Y");

	/* Needed oo extension */
	if (Tcl_OOInitStubs(interp) == NULL) {
		return TCL_ERROR;
	}

    /* Create widget class. */
    if (Tcl_Eval(interp, initScript) != TCL_OK) {
        return TCL_ERROR;
    }

    /* Get class object */
    objPtr = Tcl_NewStringObj("::graph", -1);
    Tcl_IncrRefCount(objPtr);
    if ((object = Tcl_GetObjectFromObj(interp, objPtr)) == NULL) {
        Tcl_DecrRefCount(objPtr);
        return TCL_ERROR;
    }
    Tcl_DecrRefCount(objPtr);
    if ((clazz = Tcl_GetObjectAsClass(object)) == NULL) {
        return TCL_ERROR;
    }
    /* Add methods */
    Tcl_ClassSetConstructor(interp, clazz, Tcl_NewMethod(interp, clazz, NULL, 1, &graphMethods[0], NULL));
    for (i = 1; graphMethods[i].name != NULL; i++) {
        Tcl_NewMethod(interp, clazz, Tcl_NewStringObj(graphMethods[i].name, -1), 1, &graphMethods[i], NULL);
    }

    return TCL_OK;
}

/* Constructor */
static int GraphConstructor(
    ClientData clientData,
    Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[])
{
    Tcl_Object object;
    RbcGraph       *graphPtr;
    Tk_Window tkWin;
    RbcUid classUid = rbcLineElementUid;
    int i;
    const char *chPtr;
    int myArgc;
    const char **myArgv;

	/* Get current object. Should not fail? */
    if ((object = Tcl_ObjectContextObject(objectContext)) == NULL) {
        return TCL_ERROR;
    }
    /* Check calling args */
    if (objc < 3 || strcmp("create", Tcl_GetString(objv[1])) != 0) {
        Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
        return TCL_ERROR;
    }

    tkWin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), Tcl_GetString(objv[2]), NULL);
    if (tkWin == NULL) {
        return TCL_ERROR;
    }

    /*
     * Convert objv to argv and check on -class option
     */
    myArgv = ckalloc((objc-1)*sizeof(char *));
    myArgv[0] = Tcl_GetString(objv[0]);
    myArgv[1] = Tcl_GetString(objv[2]);
    myArgc = 2;
    for (i=3; i<objc; i += 2) {
        chPtr = Tcl_GetString(objv[i]);
        if (strcmp(chPtr,"-style") == 0) {
            chPtr = Tcl_GetString(objv[i+1]);
            if (strcmp(chPtr,"line") == 0) {
                classUid = rbcLineElementUid;
            } else if (strcmp(chPtr,"bar") == 0) {
                classUid = rbcBarElementUid;
            } else if (strcmp(chPtr,"strip") == 0) {
                classUid = rbcStripElementUid;
            } else {
                ckfree(myArgv);
                Tk_DestroyWindow(tkWin);
                Tcl_WrongNumArgs(interp, 1, objv, "pathName -style line|bar|strip ?options?");
                return TCL_ERROR;
            }
        } else {
            myArgv[myArgc++] = chPtr;
            myArgv[myArgc++] = Tcl_GetString(objv[i+1]);
        }
    }
    /*
     * Create and initialize the graph data structure.
     */
    graphPtr = RbcCalloc(1, sizeof(RbcGraph));
    assert(graphPtr);
    if (classUid == rbcLineElementUid) {
        Tk_SetClass(tkWin, "Graph");
        graphPtr->chartStyle = "line";
    } else if (classUid == rbcBarElementUid) {
        Tk_SetClass(tkWin, "Barchart");
        graphPtr->chartStyle = "bar";
    } else if (classUid == rbcStripElementUid) {
        Tk_SetClass(tkWin, "Stripchart");
        graphPtr->chartStyle = "strip";
    }
    graphPtr->classUid = classUid;

    graphPtr->tkwin = tkWin;
    graphPtr->display = Tk_Display(tkWin);
    graphPtr->interp = interp;
    graphPtr->backingStore = TRUE;
    graphPtr->doubleBuffer = TRUE;
    graphPtr->highlightWidth = 2;
    graphPtr->plotRelief = TK_RELIEF_SUNKEN;
    graphPtr->relief = TK_RELIEF_FLAT;
    graphPtr->flags = (RBC_RESET_WORLD);
    graphPtr->nextMarkerId = 1;
    graphPtr->padX.side1 = graphPtr->padX.side2 = 8;
    graphPtr->padY.side1 = graphPtr->padY.side2 = 8;
    graphPtr->margins[RBC_MARGIN_BOTTOM].site = RBC_MARGIN_BOTTOM;
    graphPtr->margins[RBC_MARGIN_LEFT].site = RBC_MARGIN_LEFT;
    graphPtr->margins[RBC_MARGIN_TOP].site = RBC_MARGIN_TOP;
    graphPtr->margins[RBC_MARGIN_RIGHT].site = RBC_MARGIN_RIGHT;
    RbcInitTextStyle(&graphPtr->titleTextStyle);

    Tcl_InitHashTable(&graphPtr->axes.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->axes.tagTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->elements.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->elements.tagTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->markers.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graphPtr->markers.tagTable, TCL_STRING_KEYS);
    graphPtr->elements.displayList = RbcChainCreate();
    graphPtr->markers.displayList = RbcChainCreate();
    graphPtr->axes.displayList = RbcChainCreate();

    RbcSetWindowInstanceData(tkWin, graphPtr);

    if (InitPens(graphPtr) != TCL_OK) {
        goto error;
    }
    if (Tk_ConfigureWidget(interp, tkWin, configSpecs, myArgc - 2, myArgv + 2,
            (char *) graphPtr, 0) != TCL_OK) {
        goto error;
    }
    if (RbcDefaultAxes(graphPtr) != TCL_OK) {
        goto error;
    }
    AdjustAxisPointers(graphPtr);

    if (RbcCreatePostScript(graphPtr) != TCL_OK) {
        goto error;
    }
    if (RbcCreateCrosshairs(graphPtr) != TCL_OK) {
        goto error;
    }
    if (RbcCreateLegend(graphPtr) != TCL_OK) {
        goto error;
    }
    if (RbcCreateGrid(graphPtr) != TCL_OK) {
        goto error;
    }
    Tk_CreateEventHandler(tkWin,
        ExposureMask | StructureNotifyMask | FocusChangeMask, GraphEventProc,
        graphPtr);

    graphPtr->cmdToken = Tcl_GetObjectCommand(object);
    Tcl_ObjectSetMetadata(object, &pathMeta, (ClientData)graphPtr);
    ConfigureGraph(graphPtr);
    graphPtr->bindTable =
        RbcCreateBindingTable(interp, tkWin, graphPtr, PickEntry);

	/* No need to set return value. It will be ignored by "oo::class create" */
    return TCL_OK;

  error:
    ckfree(myArgv);
    Tk_DestroyWindow(tkWin);
    DestroyGraph((char *) graphPtr);
    return TCL_ERROR;

}

static const char *const graphCmdNames[] = {
    "axis", "bar", "cget", "configure",
    "crosshairs", "element", "extents", "grid",
    "inside", "invtransform", "legend", "line",
    "marker", "pen", "postscript",
    "snap", "transform",
    "x2axis", "xaxis", "y2axis", "yaxis",
    NULL
};

enum graphCmd {
    COMMAND_AXIS, COMMAND_BAR, COMMAND_CGET, COMMAND_CONFIGURE,
    COMMAND_CROSSHAIRS, COMMAND_ELEMENT, COMMAND_EXTENTS, COMMAND_GRID,
    COMMAND_INSIDE, COMMAND_INVTRANSFORM, COMMAND_LEGEND, COMMAND_LINE,
    COMMAND_MARKER, COMMAND_PEN, COMMAND_POSTSCRIPT,
    COMMAND_SNAP, COMMAND_TRANSFORM,
    COMMAND_X2AXIS, COMMAND_XAXIS, COMMAND_Y2AXIS, COMMAND_YAXIS
};

/*
 *
 */
static int GraphMethod(
    ClientData clientData,
    Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[])
{
    int cmdIndex, result;
    RbcOp           proc;
    int i;
    const char **myArgv;

    RbcGraph *graphPtr = (RbcGraph *)Tcl_ObjectGetMetadata(Tcl_ObjectContextObject(objectContext), &pathMeta);

    /*
     * Parse the widget command by looking up the second token in the list of
     * valid command names.
     */

    result = Tcl_GetIndexFromObj(interp, objv[1], graphCmdNames, "option", 0,
	    &cmdIndex);
    if (result != TCL_OK) {
	    return result;
    }

    switch ((enum graphCmd) cmdIndex) {
        case COMMAND_AXIS: {
            proc = (RbcOp)RbcVirtualAxisOp;
            break;
        }
        case COMMAND_BAR: {
            proc = BarOp;
            break;
        }
        case COMMAND_CGET: {
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "option");
                return TCL_ERROR;
            }
            proc = CgetOp;
            break;
        }
        case COMMAND_CONFIGURE: {
            proc = ConfigureOp;
            break;
        }
        case COMMAND_CROSSHAIRS: {
            proc = RbcCrosshairsOp;
            break;
        }
        case COMMAND_ELEMENT: {
            proc = ElementOp;
            break;
        }
        case COMMAND_EXTENTS: {
            if (objc != 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "item");
                return TCL_ERROR;
            }
            proc = ExtentsOp;
            break;
        }
        case COMMAND_GRID: {
            proc = RbcGridOp;
            break;
        }
        case COMMAND_INSIDE: {
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "winX winY");
                return TCL_ERROR;
            }
            proc = InsideOp;
            break;
        }
        case COMMAND_INVTRANSFORM: {
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "winX winY");
                return TCL_ERROR;
            }
            proc = InvtransformOp;
            break;
        }
        case COMMAND_LEGEND: {
            proc = RbcLegendOp;
            break;
        }
        case COMMAND_LINE: {
            proc = LineOp;
            break;
        }
        case COMMAND_MARKER: {
            proc = RbcMarkerOp;
            break;
        }
        case COMMAND_PEN: {
            proc = RbcPenOp;
            break;
        }
        case COMMAND_POSTSCRIPT: {
            proc = RbcPostScriptOp;
            break;
        }
        case COMMAND_SNAP: {
            if (objc < 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "?switchse? name");
                return TCL_ERROR;
            }
            proc = SnapOp;
            break;
        }
        case COMMAND_TRANSFORM: {
            if (objc != 4) {
                Tcl_WrongNumArgs(interp, 2, objv, "x y");
                return TCL_ERROR;
            }
            proc = TransformOp;
            break;
        }
        case COMMAND_X2AXIS: {
            proc = X2AxisOp;
            break;
        }
        case COMMAND_XAXIS: {
            proc = XAxisOp;
            break;
        }
        case COMMAND_Y2AXIS: {
            proc = Y2AxisOp;
            break;
        }
        case COMMAND_YAXIS: {
            proc = YAxisOp;
            break;
        }
        default: {return TCL_ERROR;}
    }
    myArgv = ckalloc(objc*sizeof(char *));
    for (i=0; i<objc; i ++) {
        myArgv[i] = Tcl_GetString(objv[i]);
    }
    Tcl_Preserve(graphPtr);
    result = (*proc) (graphPtr, interp, objc, myArgv);
    Tcl_Release(graphPtr);
    ckfree(myArgv);
    return result;
}

/*
 *
 */
static void
GraphMetaDelete(ClientData clientData) {
    register RbcGraph *graphPtr = clientData;

    /* Destroy window will calling DestroyGraph() also. */
    if (graphPtr && (!(graphPtr->flags & RBC_GRAPH_DELETED))) {
        Tk_DestroyWindow(graphPtr->tkwin);
    }
}

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

Changes to generic/rbc/rbcInt.h.

13
14
15
16
17
18
19

20
21
22
23
24
25
26
..
32
33
34
35
36
37
38


39
40
41
42
43
44
45
...
264
265
266
267
268
269
270


271
272
273
274
275
276
277
...
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
...
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
...
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
....
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
....
1466
1467
1468
1469
1470
1471
1472

1473
1474
1475
1476
1477
1478
1479
....
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
....
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
....
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
....
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
....
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
....
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
 */

#ifndef _RBCINT
#define _RBCINT

#include <tcl.h>
#include <tclInt.h>             /* only #define's and inline functions */


#include <tk.h>
#include <tkInt.h>

#ifndef _WIN32
#include <X11/Xproto.h>
#endif
................................................................................
#else
#include "tkUnixInt.h"
#endif

#include "tk3d.h"
#include "tkFont.h"



#include <assert.h>

/*
 * Mathematical functions
 */
#undef ABS
#define ABS(x)		(((x)<0)?(-(x)):(x))
................................................................................
#define RBC_REDRAW_PENDING		(1<<8)  /* 0x0100 */
#define RBC_DRAW_LEGEND		(1<<9)  /* 0x0200 */
#define RBC_DRAW_MARGINS		(1<<10) /* 0x0400 */
#define	RBC_REDRAW_BACKING_STORE	(1<<11) /* 0x0800 */

#define RBC_GRAPH_FOCUS		(1<<12) /* 0x1000 */
#define RBC_DATA_CHANGED		(1<<13) /* 0x2000 */



#define	RBC_MAP_WORLD		(RBC_MAP_ALL|RBC_RESET_AXES|RBC_GET_AXIS_GEOMETRY)
#define RBC_REDRAW_WORLD	(RBC_DRAW_MARGINS | RBC_DRAW_LEGEND)
#define RBC_RESET_WORLD		(RBC_REDRAW_WORLD | RBC_MAP_WORLD)

/* Legend */
#define RBC_LEGEND_RIGHT	(1<<0)  /* Right margin */
................................................................................
typedef struct {
    RbcChainLink   *headPtr;    /* Pointer to first element in chain */
    RbcChainLink   *tailPtr;    /* Pointer to last element in chain */
    int             nLinks;     /* Number of elements in chain */
} RbcChain;

/*
 * RbcVector --
 */
typedef struct {
    double         *valueArr;   /* Array of values (possibly malloc-ed) */
    int             numValues;  /* Number of values in the array */
    int             arraySize;  /* Size of the allocated space */
    double          min, max;   /* Minimum and maximum values in the vector */
    int             dirty;      /* Indicates if the vector has been updated */
    int             reserved;   /* Reserved for future use */
} RbcVector;

/*
 * RbcVectorInterpData --
 */
typedef struct {
    Tcl_HashTable   vectorTable;        /* Table of vectors */
    Tcl_HashTable   mathProcTable;      /* Table of vector math functions */
................................................................................
     * of RbcVector in rbcVector.h too.
     */
    double         *valueArr;   /* Array of values (malloc-ed) */
    int             length;     /* Current number of values in the array. */
    int             size;       /* Maximum number of values that can be stored
                                 * in the value array. */
    double          min, max;   /* Minimum and maximum values in the vector */
    int             dirty;      /* Indicates if the vector has been updated */
    int             reserved;
    /* The following fields are local to this module  */
    char           *name;       /* The namespace-qualified name of the vector command.
                                 * It points to the hash key allocated for the
                                 * entry in the vector hash table. */
    RbcVectorInterpData *dataPtr;
    Tcl_Interp     *interp;     /* Interpreter associated with the vector */
    Tcl_HashEntry  *hashPtr;    /* If non-NULL, pointer in a hash table to
................................................................................
/*
 * RbcVectorNotify --
 */
typedef enum {
    RBC_VECTOR_NOTIFY_UPDATE = 1,       /* The vector's values has been updated */
    RBC_VECTOR_NOTIFY_DESTROY   /* The vector has been destroyed and the client
                                 * should no longer use its data (calling
                                 * RbcFreeVectorId) */
} RbcVectorNotify;

typedef void    (RbcVectorChangedProc) (
    Tcl_Interp * interp,
    ClientData clientData,
    RbcVectorNotify notify);
typedef double  (RbcVectorIndexProc) (
    RbcVector * vecPtr);

/*
 * RbcParseValue --
 *
 *	The following data structure is used by various parsing
 *	procedures to hold information about where to store the
 *	results of parsing (e.g. the substituted contents of a quoted
................................................................................
 * RbcElemVector --
 *
 * The data structure below contains information pertaining to a line
 * vector.  It consists of an array of floating point data values and
 * for convenience, the number and minimum/maximum values.
 */
typedef struct {
    RbcVector      *vecPtr;
    double         *valueArr;
    int             nValues;
    int             arraySize;
    double          min, max;
    RbcVectorId     clientId;   /* If non-NULL, a client token identifying the
                                 * external vector. */
    RbcElement     *elemPtr;    /* Element associated with vector. */
................................................................................
        Tcl_HashTable   table;  /* Hash table of ids. */
        RbcChain       *displayList;    /* Display list. */
        Tcl_HashTable   tagTable;       /* Table of bind tags. */
    } elements     ,
                    markers,
                    axes;
    RbcUid          classUid;   /* Default element type */

    RbcBindTable   *bindTable;
    int             nextMarkerId;       /* Tracks next marker identifier available */
    RbcChain       *axisChain[4];       /* Chain of axes for each of the
                                         * margins.  They're separate from the
                                         * margin structures to make it easier
                                         * to invert the X-Y axes by simply
                                         * switching chain pointers.
................................................................................
    RbcPsToken * psToken);
MODULE_SCOPE void RbcAppendToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE void RbcFormatToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE int RbcFileToPostScript(
    RbcPsToken * psToken,
    const char *fileName);
MODULE_SCOPE void RbcBackgroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcForegroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcBitmapDataToPostScript(
................................................................................

/* rbcVecMath.c */
MODULE_SCOPE void RbcVectorInstallMathFunctions(
    Tcl_HashTable * tablePtr);
MODULE_SCOPE void RbcVectorInstallSpecialIndices(
    Tcl_HashTable * tablePtr);
MODULE_SCOPE double RbcVecMin(
    RbcVector * vecPtr);
MODULE_SCOPE double RbcVecMax(
    RbcVector * vecPtr);
MODULE_SCOPE int RbcExprVector(
    Tcl_Interp * interp,
    char *string,
    RbcVector * vecPtr);

/* rbcVecObjCmd.c */
MODULE_SCOPE int RbcAppendOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
................................................................................
    RbcVectorInterpData * dataPtr);
MODULE_SCOPE RbcVectorObject *RbcVectorCreate(
    RbcVectorInterpData * dataPtr,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int *newPtr);
MODULE_SCOPE void RbcVectorFree(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorDuplicate(
    RbcVectorObject * destPtr,
    RbcVectorObject * srcPtr);
MODULE_SCOPE void RbcVectorFlushCache(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorMapVariable(
................................................................................
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorGetIndex(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int *indexPtr,
    int flags,
    RbcVectorIndexProc ** procPtrPtr);
MODULE_SCOPE int RbcVectorGetIndexRange(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int flags,
    RbcVectorIndexProc ** procPtrPtr);
RbcVectorObject *RbcVectorParseElement(
    Tcl_Interp * interp,
    RbcVectorInterpData * dataPtr,
    const char *start,
    char **endPtr,
    int flags);
MODULE_SCOPE void RbcVectorUpdateClients(
................................................................................
    int first,
    int last,
    double value);
MODULE_SCOPE int RbcGetDouble(
    Tcl_Interp * interp,
    Tcl_Obj * objPtr,
    double *valuePtr);
MODULE_SCOPE void RbcFreeVectorId(
    RbcVectorId clientId);
MODULE_SCOPE int RbcGetVectorById(
    Tcl_Interp * interp,
    RbcVectorId clientId,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcVectorExists2(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE RbcVectorId RbcAllocVectorId(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE void RbcSetVectorChangedProc(
    RbcVectorId clientId,
    RbcVectorChangedProc * proc,
    ClientData clientData);
MODULE_SCOPE char *RbcNameOfVectorId(
    RbcVectorId clientId);
MODULE_SCOPE int RbcGetVector(
    Tcl_Interp * interp,
    const char *vecName,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcCreateVector2(
    Tcl_Interp * interp,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int initialSize,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcCreateVector(
    Tcl_Interp * interp,
    const char *vecName,
    int size,
    RbcVector ** vecPtrPtr);
MODULE_SCOPE int RbcResizeVector(
    RbcVector * vecPtr,
    int nValues);
MODULE_SCOPE char *RbcNameOfVector(
    RbcVector * vecPtr);
MODULE_SCOPE int RbcResetVector(
    RbcVector * vecPtr,
    double *dataArr,
    int nValues,
    int arraySize,
    Tcl_FreeProc * freeProc);

/* rbcWindow.c */
MODULE_SCOPE Tk_Window RbcFindChild(
................................................................................
    int regionY,
    unsigned int regionWidth,
    unsigned int regionHeight,
    unsigned int virtWidth,
    unsigned int virtHeight,
    double theta);

/* rbcScrollbar.c */
#include <tclOO.h>
MODULE_SCOPE int RbcScrollbarInit(
    Tcl_Interp *interp);
MODULE_SCOPE int RbcScrollbarConstructor(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarDestructor(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarActivate(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarCget(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarConfigure(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarDelta(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarFraction(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarGet(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarIdentify(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);
MODULE_SCOPE int RbcScrollbarSet(
    ClientData clientData,
	Tcl_Interp *interp,
    Tcl_ObjectContext objectContext,
    int objc,
    Tcl_Obj *const objv[]);

/* Windows */
#ifdef _WIN32
#include "rbcWin.h"
#endif

#ifndef _WIN32
#define PurifyPrintf  printf






>







 







>
>







 







>
>







 







|






<
<
|







 







<
<







 







|






|
|







 







|







 







>







 







<
<
<







 







|

|



|







 







|







 







|





|







 







|

|


|
|





|



|

|


|






|
|



|
|
|


|
|
|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
...
494
495
496
497
498
499
500
501
502
503
504
505
506
507


508
509
510
511
512
513
514
515
...
542
543
544
545
546
547
548


549
550
551
552
553
554
555
...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
....
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
....
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
....
2314
2315
2316
2317
2318
2319
2320



2321
2322
2323
2324
2325
2326
2327
....
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
....
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
....
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
....
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
....
2948
2949
2950
2951
2952
2953
2954

































































2955
2956
2957
2958
2959
2960
2961
 */

#ifndef _RBCINT
#define _RBCINT

#include <tcl.h>
#include <tclInt.h>             /* only #define's and inline functions */
#include "tclOO.h"

#include <tk.h>
#include <tkInt.h>

#ifndef _WIN32
#include <X11/Xproto.h>
#endif
................................................................................
#else
#include "tkUnixInt.h"
#endif

#include "tk3d.h"
#include "tkFont.h"

#define _USE_MATH_DEFINES
#include <math.h> /* VC math constants M_PI, M_SQRT1_2 */
#include <assert.h>

/*
 * Mathematical functions
 */
#undef ABS
#define ABS(x)		(((x)<0)?(-(x)):(x))
................................................................................
#define RBC_REDRAW_PENDING		(1<<8)  /* 0x0100 */
#define RBC_DRAW_LEGEND		(1<<9)  /* 0x0200 */
#define RBC_DRAW_MARGINS		(1<<10) /* 0x0400 */
#define	RBC_REDRAW_BACKING_STORE	(1<<11) /* 0x0800 */

#define RBC_GRAPH_FOCUS		(1<<12) /* 0x1000 */
#define RBC_DATA_CHANGED		(1<<13) /* 0x2000 */

#define RBC_GRAPH_DELETED   (1<<15) /* 0x8000 */

#define	RBC_MAP_WORLD		(RBC_MAP_ALL|RBC_RESET_AXES|RBC_GET_AXIS_GEOMETRY)
#define RBC_REDRAW_WORLD	(RBC_DRAW_MARGINS | RBC_DRAW_LEGEND)
#define RBC_RESET_WORLD		(RBC_REDRAW_WORLD | RBC_MAP_WORLD)

/* Legend */
#define RBC_LEGEND_RIGHT	(1<<0)  /* Right margin */
................................................................................
typedef struct {
    RbcChainLink   *headPtr;    /* Pointer to first element in chain */
    RbcChainLink   *tailPtr;    /* Pointer to last element in chain */
    int             nLinks;     /* Number of elements in chain */
} RbcChain;

/*
 * Rbc_Vector --
 */
typedef struct {
    double         *valueArr;   /* Array of values (possibly malloc-ed) */
    int             numValues;  /* Number of values in the array */
    int             arraySize;  /* Size of the allocated space */
    double          min, max;   /* Minimum and maximum values in the vector */


} Rbc_Vector;

/*
 * RbcVectorInterpData --
 */
typedef struct {
    Tcl_HashTable   vectorTable;        /* Table of vectors */
    Tcl_HashTable   mathProcTable;      /* Table of vector math functions */
................................................................................
     * of RbcVector in rbcVector.h too.
     */
    double         *valueArr;   /* Array of values (malloc-ed) */
    int             length;     /* Current number of values in the array. */
    int             size;       /* Maximum number of values that can be stored
                                 * in the value array. */
    double          min, max;   /* Minimum and maximum values in the vector */


    /* The following fields are local to this module  */
    char           *name;       /* The namespace-qualified name of the vector command.
                                 * It points to the hash key allocated for the
                                 * entry in the vector hash table. */
    RbcVectorInterpData *dataPtr;
    Tcl_Interp     *interp;     /* Interpreter associated with the vector */
    Tcl_HashEntry  *hashPtr;    /* If non-NULL, pointer in a hash table to
................................................................................
/*
 * RbcVectorNotify --
 */
typedef enum {
    RBC_VECTOR_NOTIFY_UPDATE = 1,       /* The vector's values has been updated */
    RBC_VECTOR_NOTIFY_DESTROY   /* The vector has been destroyed and the client
                                 * should no longer use its data (calling
                                 * Rbc_FreeVectorId) */
} RbcVectorNotify;

typedef void    (RbcVectorChangedProc) (
    Tcl_Interp * interp,
    ClientData clientData,
    RbcVectorNotify notify);
typedef double  (Rbc_VectorIndexProc) (
    Rbc_Vector * vecPtr);

/*
 * RbcParseValue --
 *
 *	The following data structure is used by various parsing
 *	procedures to hold information about where to store the
 *	results of parsing (e.g. the substituted contents of a quoted
................................................................................
 * RbcElemVector --
 *
 * The data structure below contains information pertaining to a line
 * vector.  It consists of an array of floating point data values and
 * for convenience, the number and minimum/maximum values.
 */
typedef struct {
    Rbc_Vector      *vecPtr;
    double         *valueArr;
    int             nValues;
    int             arraySize;
    double          min, max;
    RbcVectorId     clientId;   /* If non-NULL, a client token identifying the
                                 * external vector. */
    RbcElement     *elemPtr;    /* Element associated with vector. */
................................................................................
        Tcl_HashTable   table;  /* Hash table of ids. */
        RbcChain       *displayList;    /* Display list. */
        Tcl_HashTable   tagTable;       /* Table of bind tags. */
    } elements     ,
                    markers,
                    axes;
    RbcUid          classUid;   /* Default element type */
    const char     *chartStyle; /* one of line, bar or strip */
    RbcBindTable   *bindTable;
    int             nextMarkerId;       /* Tracks next marker identifier available */
    RbcChain       *axisChain[4];       /* Chain of axes for each of the
                                         * margins.  They're separate from the
                                         * margin structures to make it easier
                                         * to invert the X-Y axes by simply
                                         * switching chain pointers.
................................................................................
    RbcPsToken * psToken);
MODULE_SCOPE void RbcAppendToPostScript(
    RbcPsToken * psToken,
    ...);
MODULE_SCOPE void RbcFormatToPostScript(
    RbcPsToken * psToken,
    ...);



MODULE_SCOPE void RbcBackgroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcForegroundToPostScript(
    RbcPsToken * psToken,
    XColor * colorPtr);
MODULE_SCOPE void RbcBitmapDataToPostScript(
................................................................................

/* rbcVecMath.c */
MODULE_SCOPE void RbcVectorInstallMathFunctions(
    Tcl_HashTable * tablePtr);
MODULE_SCOPE void RbcVectorInstallSpecialIndices(
    Tcl_HashTable * tablePtr);
MODULE_SCOPE double RbcVecMin(
    Rbc_Vector * vecPtr);
MODULE_SCOPE double RbcVecMax(
    Rbc_Vector * vecPtr);
MODULE_SCOPE int RbcExprVector(
    Tcl_Interp * interp,
    char *string,
    Rbc_Vector * vecPtr);

/* rbcVecObjCmd.c */
MODULE_SCOPE int RbcAppendOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[]);
................................................................................
    RbcVectorInterpData * dataPtr);
MODULE_SCOPE RbcVectorObject *RbcVectorCreate(
    RbcVectorInterpData * dataPtr,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int *newPtr);
MODULE_SCOPE void Rbc_VectorFree(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorDuplicate(
    RbcVectorObject * destPtr,
    RbcVectorObject * srcPtr);
MODULE_SCOPE void RbcVectorFlushCache(
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorMapVariable(
................................................................................
    RbcVectorObject * vPtr);
MODULE_SCOPE int RbcVectorGetIndex(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int *indexPtr,
    int flags,
    Rbc_VectorIndexProc ** procPtrPtr);
MODULE_SCOPE int RbcVectorGetIndexRange(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int flags,
    Rbc_VectorIndexProc ** procPtrPtr);
RbcVectorObject *RbcVectorParseElement(
    Tcl_Interp * interp,
    RbcVectorInterpData * dataPtr,
    const char *start,
    char **endPtr,
    int flags);
MODULE_SCOPE void RbcVectorUpdateClients(
................................................................................
    int first,
    int last,
    double value);
MODULE_SCOPE int RbcGetDouble(
    Tcl_Interp * interp,
    Tcl_Obj * objPtr,
    double *valuePtr);
MODULE_SCOPE void Rbc_FreeVectorId(
    RbcVectorId clientId);
MODULE_SCOPE int Rbc_GetVectorById(
    Tcl_Interp * interp,
    RbcVectorId clientId,
    Rbc_Vector ** vecPtrPtr);
MODULE_SCOPE int Rbc_VectorExists(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE RbcVectorId RbcAllocVectorId(
    Tcl_Interp * interp,
    const char *vecName);
MODULE_SCOPE void Rbc_SetVectorChangedProc(
    RbcVectorId clientId,
    RbcVectorChangedProc * proc,
    ClientData clientData);
MODULE_SCOPE char *Rbc_NameOfVectorId(
    RbcVectorId clientId);
MODULE_SCOPE int Rbc_GetVector(
    Tcl_Interp * interp,
    const char *vecName,
    Rbc_Vector ** vecPtrPtr);
MODULE_SCOPE int RbcCreateVector2(
    Tcl_Interp * interp,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int initialSize,
    Rbc_Vector ** vecPtrPtr);
MODULE_SCOPE int Rbc_CreateVector(
    Tcl_Interp * interp,
    const char *vecName,
    int size,
    Rbc_Vector ** vecPtrPtr);
MODULE_SCOPE int Rbc_ResizeVector(
    Rbc_Vector * vecPtr,
    int nValues);
MODULE_SCOPE char *RbcNameOfVector(
    Rbc_Vector * vecPtr);
MODULE_SCOPE int Rbc_ResetVector(
    Rbc_Vector * vecPtr,
    double *dataArr,
    int nValues,
    int arraySize,
    Tcl_FreeProc * freeProc);

/* rbcWindow.c */
MODULE_SCOPE Tk_Window RbcFindChild(
................................................................................
    int regionY,
    unsigned int regionWidth,
    unsigned int regionHeight,
    unsigned int virtWidth,
    unsigned int virtHeight,
    double theta);


































































/* Windows */
#ifdef _WIN32
#include "rbcWin.h"
#endif

#ifndef _WIN32
#define PurifyPrintf  printf

Deleted generic/rbc/rbcMain.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
/*
 * rbcMain.c --
 *
 *      This file constructs the basic functionality of the rbc commands.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

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

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

MODULE_SCOPE int
Rbc_Init(
    Tcl_Interp *interp)
{                               /* Base interpreter to return results to. */
    Tcl_Namespace *nsPtr = Tcl_CreateNamespace(interp, "::rbc", NULL, NULL);

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

    /*
     * Export our public API.
     */

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

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

    RbcVectorInit(interp);
    RbcGraphInit(interp);

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

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


















































































































































Changes to generic/rbc/rbcPs.c.

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
    va_start(argList, psToken);
    fmt = va_arg(argList, char *);
    vsprintf(tokenPtr->scratchArr, fmt, argList);
    va_end(argList);
    Tcl_DStringAppend(&(tokenPtr->dString), tokenPtr->scratchArr, -1);
}

/*
 *--------------------------------------------------------------
 *
 * RbcFileToPostScript --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcFileToPostScript(
    RbcPsToken * tokenPtr,
    const char *fileName)
{
    Tcl_Channel     channel;
    Tcl_DString     dString;
    Tcl_Interp     *interp;
    char           *buf;
    char           *libDir;
    int             nBytes;

    interp = tokenPtr->interp;
    buf = tokenPtr->scratchArr;

    /*
     * Read in a standard prolog file from file and append it to the
     * PostScript output stored in the Tcl_DString in tokenPtr.
     */

    libDir = (char *) Tcl_GetVar(interp, "rbc::library", TCL_GLOBAL_ONLY);
    if (libDir == NULL) {
        Tcl_AppendResult(interp, "couldn't find rbc script library:",
            "global variable \"rbc::library\" doesn't exist", (char *) NULL);
        return TCL_ERROR;
    }
    Tcl_DStringInit(&dString);
    Tcl_DStringAppend(&dString, libDir, -1);
    Tcl_DStringAppend(&dString, "/", -1);
    Tcl_DStringAppend(&dString, fileName, -1);
    fileName = Tcl_DStringValue(&dString);
    RbcAppendToPostScript(tokenPtr, "\n% including file \"", fileName,
        "\"\n\n", (char *) NULL);
    channel = Tcl_OpenFileChannel(interp, fileName, "r", 0);
    if (channel == NULL) {
        Tcl_AppendResult(interp, "couldn't open prologue file \"", fileName,
            "\": ", Tcl_PosixError(interp), (char *) NULL);
        return TCL_ERROR;
    }
    for (;;) {
        nBytes = Tcl_Read(channel, buf, (BUFSIZ*2)-1);
        if (nBytes < 0) {
            Tcl_AppendResult(interp, "error reading prologue file \"",
                fileName, "\": ", Tcl_PosixError(interp), (char *) NULL);
            Tcl_Close(interp, channel);
            Tcl_DStringFree(&dString);
            return TCL_ERROR;
        }
        if (nBytes == 0) {
            break;
        }
        buf[nBytes] = '\0';
        RbcAppendToPostScript(tokenPtr, buf, (char *) NULL);
    }
    Tcl_DStringFree(&dString);
    Tcl_Close(interp, channel);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * XColorToPostScript --
 *
 *      Convert the a XColor (from its RGB values) to a PostScript
 *      command.  If a Tk color map variable exists, it will be






<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







200
201
202
203
204
205
206










































































207
208
209
210
211
212
213
    va_start(argList, psToken);
    fmt = va_arg(argList, char *);
    vsprintf(tokenPtr->scratchArr, fmt, argList);
    va_end(argList);
    Tcl_DStringAppend(&(tokenPtr->dString), tokenPtr->scratchArr, -1);
}











































































/*
 *----------------------------------------------------------------------
 *
 * XColorToPostScript --
 *
 *      Convert the a XColor (from its RGB values) to a PostScript
 *      command.  If a Tk color map variable exists, it will be

Changes to generic/rbc/rbcSpline.c.

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
....
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
....
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
SplineCmd(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,
    int argc,
    const char *argv[])
{
    RbcOp           proc;
    RbcVector      *x, *y, *splX, *splY;
    double         *xArr, *yArr;
    register int    i;
    RbcPoint2D     *origPts, *intpPts;
    int             nOrigPts, nIntpPts;

    proc = RbcGetOp(interp, nSplineOps, splineOps, RBC_OP_ARG1, argc, argv, 0);
    if (proc == NULL) {
        return TCL_ERROR;
    }
    if ((RbcGetVector(interp, argv[2], &x) != TCL_OK) ||
        (RbcGetVector(interp, argv[3], &y) != TCL_OK) ||
        (RbcGetVector(interp, argv[4], &splX) != TCL_OK)) {
        return TCL_ERROR;
    }
    nOrigPts = x->numValues;
    if (nOrigPts < 3) {
        Tcl_AppendResult(interp, "length of vector \"", argv[2], "\" is < 3",
            (char *) NULL);
        return TCL_ERROR;
................................................................................
    }
    if (nOrigPts != y->numValues) {
        Tcl_AppendResult(interp, "vectors \"", argv[2], "\" and \"", argv[3],
            " have different lengths", (char *) NULL);
        return TCL_ERROR;
    }
    nIntpPts = splX->numValues;
    if (RbcGetVector(interp, argv[5], &splY) != TCL_OK) {
        /*
         * If the named vector to hold the ordinates of the spline
         * doesn't exist, create one the same size as the vector
         * containing the abscissas.
         */
        if (RbcCreateVector(interp, argv[5], nIntpPts, &splY) != TCL_OK) {
            return TCL_ERROR;
        }
    } else if (nIntpPts != splY->numValues) {
        /*
         * The x and y vectors differ in size. Make the number of ordinates
         * the same as the number of abscissas.
         */
        if (RbcResizeVector(splY, nIntpPts) != TCL_OK) {
            return TCL_ERROR;
        }
    }
    origPts = (RbcPoint2D *) ckalloc(sizeof(RbcPoint2D) * nOrigPts);
    if (origPts == NULL) {
        Tcl_AppendPrintfToObj(Tcl_GetObjResult(interp),
            "can't allocate \"%d\" points", nOrigPts);
................................................................................
    }
    ckfree((char *) origPts);
    ckfree((char *) intpPts);

    /* Finally update the vector. The size of the vector hasn't
     * changed, just the data. Reset the vector using TCL_STATIC to
     * indicate this. */
    if (RbcResetVector(splY, splY->valueArr, splY->numValues,
            splY->arraySize, TCL_STATIC) != TCL_OK) {
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*






|









|
|
|







 







|





|







|







 







|







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
....
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
....
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
SplineCmd(
    ClientData clientData,      /* Not used. */
    Tcl_Interp * interp,
    int argc,
    const char *argv[])
{
    RbcOp           proc;
    Rbc_Vector      *x, *y, *splX, *splY;
    double         *xArr, *yArr;
    register int    i;
    RbcPoint2D     *origPts, *intpPts;
    int             nOrigPts, nIntpPts;

    proc = RbcGetOp(interp, nSplineOps, splineOps, RBC_OP_ARG1, argc, argv, 0);
    if (proc == NULL) {
        return TCL_ERROR;
    }
    if ((Rbc_GetVector(interp, argv[2], &x) != TCL_OK) ||
        (Rbc_GetVector(interp, argv[3], &y) != TCL_OK) ||
        (Rbc_GetVector(interp, argv[4], &splX) != TCL_OK)) {
        return TCL_ERROR;
    }
    nOrigPts = x->numValues;
    if (nOrigPts < 3) {
        Tcl_AppendResult(interp, "length of vector \"", argv[2], "\" is < 3",
            (char *) NULL);
        return TCL_ERROR;
................................................................................
    }
    if (nOrigPts != y->numValues) {
        Tcl_AppendResult(interp, "vectors \"", argv[2], "\" and \"", argv[3],
            " have different lengths", (char *) NULL);
        return TCL_ERROR;
    }
    nIntpPts = splX->numValues;
    if (Rbc_GetVector(interp, argv[5], &splY) != TCL_OK) {
        /*
         * If the named vector to hold the ordinates of the spline
         * doesn't exist, create one the same size as the vector
         * containing the abscissas.
         */
        if (Rbc_CreateVector(interp, argv[5], nIntpPts, &splY) != TCL_OK) {
            return TCL_ERROR;
        }
    } else if (nIntpPts != splY->numValues) {
        /*
         * The x and y vectors differ in size. Make the number of ordinates
         * the same as the number of abscissas.
         */
        if (Rbc_ResizeVector(splY, nIntpPts) != TCL_OK) {
            return TCL_ERROR;
        }
    }
    origPts = (RbcPoint2D *) ckalloc(sizeof(RbcPoint2D) * nOrigPts);
    if (origPts == NULL) {
        Tcl_AppendPrintfToObj(Tcl_GetObjResult(interp),
            "can't allocate \"%d\" points", nOrigPts);
................................................................................
    }
    ckfree((char *) origPts);
    ckfree((char *) intpPts);

    /* Finally update the vector. The size of the vector hasn't
     * changed, just the data. Reset the vector using TCL_STATIC to
     * indicate this. */
    if (Rbc_ResetVector(splY, splY->valueArr, splY->numValues,
            splY->arraySize, TCL_STATIC) != TCL_OK) {
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*

Changes to generic/rbc/rbcVecMath.c.

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
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
...
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
...
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
...
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
...
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
...
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
...
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
...
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
...
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
...
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
...
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
...
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
....
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
....
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
};

typedef double  (ComponentProc)  (double value);
typedef int     (VectorProc)     (RbcVectorObject * vPtr);
typedef double  (ScalarProc)     (RbcVectorObject * vPtr);


static void   InstallIndexProc   (Tcl_HashTable *tablePtr, const char *string, RbcVectorIndexProc *procPtr);
static int    First              (RbcVectorObject *vPtr);
static int    Next               (RbcVectorObject *vPtr, int current);
static double Mean               (RbcVector *vecPtr);
static double Sum                (RbcVector *vecPtr);
static double Product            (RbcVector *vecPtr);
static double Fabs               (double value);
static double AvgDeviation       (RbcVector *vecPtr);
static double Kurtosis           (RbcVector *vecPtr);
static double Length             (RbcVector *vecPtr);
static double Median             (RbcVector *vecPtr);
static int    Norm               (RbcVector *vecPtr);
static double Nonzeros           (RbcVector *vecPtr);
static double Q1                 (RbcVector *vecPtr);
static double Q3                 (RbcVector *vecPtr);
static double Round              (double value);
static double StdDeviation       (RbcVector *vecPtr);
static double Skew               (RbcVector *vecPtr);
static int    Sort               (RbcVectorObject *vPtr);
static double Sum                (RbcVector *vecPtr);
static double Variance           (RbcVector *vecPtr);
static int    EvaluateExpression (Tcl_Interp *interp, char *string, RbcParseVector *valuePtr);
static int    NextValue          (Tcl_Interp *interp, ParseInfo *parsePtr, int prec, RbcParseVector *valuePtr);
static void   MathError          (Tcl_Interp *interp, double value);
static int    NextToken          (Tcl_Interp *interp, ParseInfo *parsePtr, RbcParseVector *valuePtr);
static double Fmod               (double x, double y);
static int    ParseString        (Tcl_Interp *interp, const char *string, RbcParseVector *valuePtr);
static int    ParseMathFunction  (Tcl_Interp *interp, char *start, ParseInfo *parsePtr, RbcParseVector *valuePtr);
................................................................................
 *
 *----------------------------------------------------------------------
 */
static void
InstallIndexProc(
    Tcl_HashTable *tablePtr,
    const char *string,
    RbcVectorIndexProc *procPtr) /* Pointer to function to be called
                                   * when the vector finds the named index.
                                   * If NULL, this indicates to remove
                                   * the index from the table.
                                   */
{
    Tcl_HashEntry *hPtr;
    int dummy;
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
double
RbcVecMin(
    RbcVector *vecPtr) /* The vector to calculate the min for */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    double min;
    register int i;
    min = rbcNaN;
    for (i = 0; i < vPtr->length; i++) {
        if (!TclIsInfinite(vPtr->valueArr[i])) {
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
double
RbcVecMax(
    RbcVector *vecPtr) /* The vector to calculate the max for */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    double max;
    register int i;
    max = rbcNaN;
    for (i = 0; i < vPtr->length; i++) {
        if (!TclIsInfinite(vPtr->valueArr[i])) {
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
static double
Mean(
    RbcVector *vecPtr) /* The vector to calculate the mean of */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    register int i;
    int count;
    double sum;
    sum = 0.0;
    count = 0;
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
static double
Sum(
    RbcVector *vecPtr) /* The vector to calculate the sum for */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    register int i;
    double sum;
    sum = 0.0;
    for (i = First(vPtr); i >= 0; i = Next(vPtr, i)) {
        sum += vPtr->valueArr[i];
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
static double
Product(
    RbcVector *vecPtr) /* The Vector to calculate product for */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    register int i;
    register double prod;
    prod = 1.0;
    for (i = First(vPtr); i >= 0; i = Next(vPtr, i)) {
        prod *= vPtr->valueArr[i];
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Length(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    int count;
    register int i;
    count = 0;
    for (i = First(vPtr); i >= 0; i = Next(vPtr, i)) {
        count++;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Median(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    int *iArr;
    double q2;
    int mid;
    if (vPtr->length == 0) {
        return -DBL_MAX;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Variance(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register double dx, var, mean;
    register int i;
    int count;
    mean = Mean(vecPtr);
    var = 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Skew(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register double diff, var, skew, mean, diffsq;
    register int i;
    int count;
    mean = Mean(vecPtr);
    var = skew = 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
StdDeviation(
    RbcVector *vecPtr)
{
    double var;
    var = Variance(vecPtr);
    if (var > 0.0) {
        return sqrt(var);
    }
    return 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
AvgDeviation(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register double diff, avg, mean;
    register int i;
    int count;
    mean = Mean(vecPtr);
    avg = 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Kurtosis(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register double diff, diffsq, kurt, var, mean;
    register int i;
    int count;
    mean = Mean(vecPtr);
    var = kurt = 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Q1(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    double q1;
    int *iArr;
    if (vPtr->length == 0) {
        return -DBL_MAX;
    }
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Q3(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    double q3;
    int *iArr;
    if (vPtr->length == 0) {
        return -DBL_MAX;
    }
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static int
Norm(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    double norm, range, min, max;
    register int i;
    min = RbcVecMin(vecPtr);
    max = RbcVecMax(vecPtr);
    range = max - min;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Nonzeros(
    RbcVector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register int i;
    int count;
    count = 0;
    for (i = First(vPtr); i >= 0; i = Next(vPtr, i)) {
        if (vPtr->valueArr[i] == 0.0) {
................................................................................
 *
 *--------------------------------------------------------------
 */
int
RbcExprVector(
    Tcl_Interp *interp,
    char *string,
    RbcVector *vecPtr)
{
    RbcVectorInterpData *dataPtr; /* Interpreter-specific data. */
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    RbcParseVector value;
    char stringDouble[TCL_DOUBLE_SPACE];

    dataPtr = (vecPtr != NULL) ? vPtr->dataPtr : RbcVectorGetInterpData(interp);
    value.vPtr = RbcVectorNew(dataPtr);
    if (EvaluateExpression(interp, string, &value) != TCL_OK) {
        RbcVectorFree(value.vPtr);
        return TCL_ERROR;
    }
    if (vPtr != NULL) {
        RbcVectorDuplicate(vPtr, value.vPtr);
    } else {
        register int i;
        /* No result vector.  Put values in Tcl_GetString(Tcl_GetObjResult(interp)).  */
        for (i = 0; i < value.vPtr->length; i++) {
            Tcl_PrintDouble(NULL, value.vPtr->valueArr[i], stringDouble);
            Tcl_AppendElement(interp, stringDouble);
        }
    }
    RbcVectorFree(value.vPtr);
    return TCL_OK;
}
/*
 *--------------------------------------------------------------
 *
 * EvaluateExpression --
 *
................................................................................
            }
        }
    }
done:
    if (value2.pv.buffer != value2.staticSpace) {
        ckfree((char *)value2.pv.buffer);
    }
    RbcVectorFree(v2Ptr);
    return result;
error:
    if (value2.pv.buffer != value2.staticSpace) {
        ckfree((char *)value2.pv.buffer);
    }
    RbcVectorFree(v2Ptr);
    return TCL_ERROR;
}
/*
 *----------------------------------------------------------------------
 *
 * MathError --
 *






|


|
|
|

|
|
|
|
|
|
|
|

|
|

|
|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|









|












|







 







|





|







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
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
...
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
...
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
...
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
...
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
...
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
...
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
...
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
...
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
...
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
...
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
...
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
...
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
....
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
....
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
};

typedef double  (ComponentProc)  (double value);
typedef int     (VectorProc)     (RbcVectorObject * vPtr);
typedef double  (ScalarProc)     (RbcVectorObject * vPtr);


static void   InstallIndexProc   (Tcl_HashTable *tablePtr, const char *string, Rbc_VectorIndexProc *procPtr);
static int    First              (RbcVectorObject *vPtr);
static int    Next               (RbcVectorObject *vPtr, int current);
static double Mean               (Rbc_Vector *vecPtr);
static double Sum                (Rbc_Vector *vecPtr);
static double Product            (Rbc_Vector *vecPtr);
static double Fabs               (double value);
static double AvgDeviation       (Rbc_Vector *vecPtr);
static double Kurtosis           (Rbc_Vector *vecPtr);
static double Length             (Rbc_Vector *vecPtr);
static double Median             (Rbc_Vector *vecPtr);
static int    Norm               (Rbc_Vector *vecPtr);
static double Nonzeros           (Rbc_Vector *vecPtr);
static double Q1                 (Rbc_Vector *vecPtr);
static double Q3                 (Rbc_Vector *vecPtr);
static double Round              (double value);
static double StdDeviation       (Rbc_Vector *vecPtr);
static double Skew               (Rbc_Vector *vecPtr);
static int    Sort               (RbcVectorObject *vPtr);
static double Sum                (Rbc_Vector *vecPtr);
static double Variance           (Rbc_Vector *vecPtr);
static int    EvaluateExpression (Tcl_Interp *interp, char *string, RbcParseVector *valuePtr);
static int    NextValue          (Tcl_Interp *interp, ParseInfo *parsePtr, int prec, RbcParseVector *valuePtr);
static void   MathError          (Tcl_Interp *interp, double value);
static int    NextToken          (Tcl_Interp *interp, ParseInfo *parsePtr, RbcParseVector *valuePtr);
static double Fmod               (double x, double y);
static int    ParseString        (Tcl_Interp *interp, const char *string, RbcParseVector *valuePtr);
static int    ParseMathFunction  (Tcl_Interp *interp, char *start, ParseInfo *parsePtr, RbcParseVector *valuePtr);
................................................................................
 *
 *----------------------------------------------------------------------
 */
static void
InstallIndexProc(
    Tcl_HashTable *tablePtr,
    const char *string,
    Rbc_VectorIndexProc *procPtr) /* Pointer to function to be called
                                   * when the vector finds the named index.
                                   * If NULL, this indicates to remove
                                   * the index from the table.
                                   */
{
    Tcl_HashEntry *hPtr;
    int dummy;
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
double
RbcVecMin(
    Rbc_Vector *vecPtr) /* The vector to calculate the min for */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    double min;
    register int i;
    min = rbcNaN;
    for (i = 0; i < vPtr->length; i++) {
        if (!TclIsInfinite(vPtr->valueArr[i])) {
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
double
RbcVecMax(
    Rbc_Vector *vecPtr) /* The vector to calculate the max for */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    double max;
    register int i;
    max = rbcNaN;
    for (i = 0; i < vPtr->length; i++) {
        if (!TclIsInfinite(vPtr->valueArr[i])) {
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
static double
Mean(
    Rbc_Vector *vecPtr) /* The vector to calculate the mean of */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    register int i;
    int count;
    double sum;
    sum = 0.0;
    count = 0;
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
static double
Sum(
    Rbc_Vector *vecPtr) /* The vector to calculate the sum for */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    register int i;
    double sum;
    sum = 0.0;
    for (i = First(vPtr); i >= 0; i = Next(vPtr, i)) {
        sum += vPtr->valueArr[i];
................................................................................
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */
static double
Product(
    Rbc_Vector *vecPtr) /* The Vector to calculate product for */
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    register int i;
    register double prod;
    prod = 1.0;
    for (i = First(vPtr); i >= 0; i = Next(vPtr, i)) {
        prod *= vPtr->valueArr[i];
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Length(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    int count;
    register int i;
    count = 0;
    for (i = First(vPtr); i >= 0; i = Next(vPtr, i)) {
        count++;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Median(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    int *iArr;
    double q2;
    int mid;
    if (vPtr->length == 0) {
        return -DBL_MAX;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Variance(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register double dx, var, mean;
    register int i;
    int count;
    mean = Mean(vecPtr);
    var = 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Skew(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register double diff, var, skew, mean, diffsq;
    register int i;
    int count;
    mean = Mean(vecPtr);
    var = skew = 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
StdDeviation(
    Rbc_Vector *vecPtr)
{
    double var;
    var = Variance(vecPtr);
    if (var > 0.0) {
        return sqrt(var);
    }
    return 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
AvgDeviation(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register double diff, avg, mean;
    register int i;
    int count;
    mean = Mean(vecPtr);
    avg = 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Kurtosis(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register double diff, diffsq, kurt, var, mean;
    register int i;
    int count;
    mean = Mean(vecPtr);
    var = kurt = 0.0;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Q1(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    double q1;
    int *iArr;
    if (vPtr->length == 0) {
        return -DBL_MAX;
    }
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Q3(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    double q3;
    int *iArr;
    if (vPtr->length == 0) {
        return -DBL_MAX;
    }
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static int
Norm(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    double norm, range, min, max;
    register int i;
    min = RbcVecMin(vecPtr);
    max = RbcVecMax(vecPtr);
    range = max - min;
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
static double
Nonzeros(
    Rbc_Vector *vecPtr)
{
    RbcVectorObject *vPtr = (RbcVectorObject *)vecPtr;
    register int i;
    int count;
    count = 0;
    for (i = First(vPtr); i >= 0; i = Next(vPtr, i)) {
        if (vPtr->valueArr[i] == 0.0) {
................................................................................
 *
 *--------------------------------------------------------------
 */
int
RbcExprVector(
    Tcl_Interp *interp,
    char *string,
    Rbc_Vector *vecPtr)
{
    RbcVectorInterpData *dataPtr; /* Interpreter-specific data. */
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    RbcParseVector value;
    char stringDouble[TCL_DOUBLE_SPACE];

    dataPtr = (vecPtr != NULL) ? vPtr->dataPtr : RbcVectorGetInterpData(interp);
    value.vPtr = RbcVectorNew(dataPtr);
    if (EvaluateExpression(interp, string, &value) != TCL_OK) {
        Rbc_VectorFree(value.vPtr);
        return TCL_ERROR;
    }
    if (vPtr != NULL) {
        RbcVectorDuplicate(vPtr, value.vPtr);
    } else {
        register int i;
        /* No result vector.  Put values in Tcl_GetString(Tcl_GetObjResult(interp)).  */
        for (i = 0; i < value.vPtr->length; i++) {
            Tcl_PrintDouble(NULL, value.vPtr->valueArr[i], stringDouble);
            Tcl_AppendElement(interp, stringDouble);
        }
    }
    Rbc_VectorFree(value.vPtr);
    return TCL_OK;
}
/*
 *--------------------------------------------------------------
 *
 * EvaluateExpression --
 *
................................................................................
            }
        }
    }
done:
    if (value2.pv.buffer != value2.staticSpace) {
        ckfree((char *)value2.pv.buffer);
    }
    Rbc_VectorFree(v2Ptr);
    return result;
error:
    if (value2.pv.buffer != value2.staticSpace) {
        ckfree((char *)value2.pv.buffer);
    }
    Rbc_VectorFree(v2Ptr);
    return TCL_ERROR;
}
/*
 *----------------------------------------------------------------------
 *
 * MathError --
 *

Changes to generic/rbc/rbcVecObjCmd.c.

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
...
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
...
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
...
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
...
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
....
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
....
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
            if (i >= objc) {
                Tcl_AppendResult(interp, "missing arg after \"", string, "\"",
                    (char *) NULL);
                return TCL_ERROR;
            }
            string = Tcl_GetString(objv[i]);
            if (RbcVectorGetIndex(interp, vPtr, string, &first, 0,
                    (RbcVectorIndexProc **) NULL) != TCL_OK) {
                return TCL_ERROR;
            }
            if (first > vPtr->length) {
                Tcl_AppendResult(interp, "index \"", string,
                    "\" is out of range", (char *) NULL);
                return TCL_ERROR;
            }
................................................................................
    unsigned char  *unsetArr;
    register int    i, j;
    register int    count;
    char           *string;

    /* FIXME: Don't delete vector with no indices.  */
    if (objc == 2) {
        RbcVectorFree(vPtr);
        return TCL_OK;
    }
    /*
     * Allocate an "unset" bitmap the size of the vector.
     */
    unsetArr = (unsigned char *) RbcCalloc(sizeof(unsigned char),
        (vPtr->length + 7) / 8);
................................................................................
#define GetBit(i) \
    (unsetArr[(i) >> 3] & (1 << ((i) & 0x07)))

    for (i = 2; i < objc; i++) {
        string = Tcl_GetStringFromObj(objv[i], NULL);
        if (RbcVectorGetIndexRange(interp, vPtr, string,
                (RBC_INDEX_COLON | RBC_INDEX_CHECK),
                (RbcVectorIndexProc **) NULL) != TCL_OK) {
            ckfree((char *) unsetArr);
            return TCL_ERROR;
        }
        for (j = vPtr->first; j <= vPtr->last; j++) {
            SetBit(j);          /* Mark the range of elements for deletion. */
        }
    }
................................................................................
RbcExprOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[])
{
    if (RbcExprVector(interp, Tcl_GetStringFromObj(objv[2], NULL),
            (RbcVector *) vPtr) != TCL_OK) {
        return TCL_ERROR;
    }
    if (vPtr->flush) {
        RbcVectorFlushCache(vPtr);
    }
    RbcVectorUpdateClients(vPtr);
    return TCL_OK;
................................................................................
    Tcl_Obj * const objv[])
{
    int             first, last;
    char           *string;

    string = Tcl_GetStringFromObj(objv[2], NULL);
    if (RbcVectorGetIndexRange(interp, vPtr, string, RBC_INDEX_ALL_FLAGS,
            (RbcVectorIndexProc **) NULL) != TCL_OK) {
        return TCL_ERROR;
    }
    first = vPtr->first, last = vPtr->last;
    if (objc == 3) {
        Tcl_Obj        *listObjPtr;

        if (first == vPtr->length) {
................................................................................
{
    Tcl_Obj        *listObjPtr;
    int             first, last;
    register int    i;

    if ((RbcVectorGetIndex(interp, vPtr, Tcl_GetStringFromObj(objv[2], NULL),
                &first, RBC_INDEX_CHECK,
                (RbcVectorIndexProc **) NULL) != TCL_OK)
        || (RbcVectorGetIndex(interp, vPtr, Tcl_GetStringFromObj(objv[3], NULL),
                &last, RBC_INDEX_CHECK,
                (RbcVectorIndexProc **) NULL) != TCL_OK)) {
        return TCL_ERROR;
    }
    listObjPtr = Tcl_NewListObj(0, NULL);
    if (first > last) {
        /* Return the list reversed */
        for (i = last; i <= first; i++) {
            Tcl_ListObjAppendElement(interp, listObjPtr,
................................................................................
             * overlaps.
             */
            tmpPtr = RbcVectorNew(vPtr->dataPtr);
            result = RbcVectorDuplicate(tmpPtr, v2Ptr);
            if (result == TCL_OK) {
                result = RbcVectorDuplicate(vPtr, tmpPtr);
            }
            RbcVectorFree(tmpPtr);
        } else {
            result = RbcVectorDuplicate(vPtr, v2Ptr);
        }
    } else if (Tcl_ListObjGetElements(interp, objv[2], &nElem,
            &elemObjArr) == TCL_OK) {
        result = CopyList(vPtr, nElem, elemObjArr);
    } else {






|







 







|







 







|







 







|







 







|







 







|


|







 







|







351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
...
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
...
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
...
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
...
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
....
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
....
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
            if (i >= objc) {
                Tcl_AppendResult(interp, "missing arg after \"", string, "\"",
                    (char *) NULL);
                return TCL_ERROR;
            }
            string = Tcl_GetString(objv[i]);
            if (RbcVectorGetIndex(interp, vPtr, string, &first, 0,
                    (Rbc_VectorIndexProc **) NULL) != TCL_OK) {
                return TCL_ERROR;
            }
            if (first > vPtr->length) {
                Tcl_AppendResult(interp, "index \"", string,
                    "\" is out of range", (char *) NULL);
                return TCL_ERROR;
            }
................................................................................
    unsigned char  *unsetArr;
    register int    i, j;
    register int    count;
    char           *string;

    /* FIXME: Don't delete vector with no indices.  */
    if (objc == 2) {
        Rbc_VectorFree(vPtr);
        return TCL_OK;
    }
    /*
     * Allocate an "unset" bitmap the size of the vector.
     */
    unsetArr = (unsigned char *) RbcCalloc(sizeof(unsigned char),
        (vPtr->length + 7) / 8);
................................................................................
#define GetBit(i) \
    (unsetArr[(i) >> 3] & (1 << ((i) & 0x07)))

    for (i = 2; i < objc; i++) {
        string = Tcl_GetStringFromObj(objv[i], NULL);
        if (RbcVectorGetIndexRange(interp, vPtr, string,
                (RBC_INDEX_COLON | RBC_INDEX_CHECK),
                (Rbc_VectorIndexProc **) NULL) != TCL_OK) {
            ckfree((char *) unsetArr);
            return TCL_ERROR;
        }
        for (j = vPtr->first; j <= vPtr->last; j++) {
            SetBit(j);          /* Mark the range of elements for deletion. */
        }
    }
................................................................................
RbcExprOp(
    RbcVectorObject * vPtr,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[])
{
    if (RbcExprVector(interp, Tcl_GetStringFromObj(objv[2], NULL),
            (Rbc_Vector *) vPtr) != TCL_OK) {
        return TCL_ERROR;
    }
    if (vPtr->flush) {
        RbcVectorFlushCache(vPtr);
    }
    RbcVectorUpdateClients(vPtr);
    return TCL_OK;
................................................................................
    Tcl_Obj * const objv[])
{
    int             first, last;
    char           *string;

    string = Tcl_GetStringFromObj(objv[2], NULL);
    if (RbcVectorGetIndexRange(interp, vPtr, string, RBC_INDEX_ALL_FLAGS,
            (Rbc_VectorIndexProc **) NULL) != TCL_OK) {
        return TCL_ERROR;
    }
    first = vPtr->first, last = vPtr->last;
    if (objc == 3) {
        Tcl_Obj        *listObjPtr;

        if (first == vPtr->length) {
................................................................................
{
    Tcl_Obj        *listObjPtr;
    int             first, last;
    register int    i;

    if ((RbcVectorGetIndex(interp, vPtr, Tcl_GetStringFromObj(objv[2], NULL),
                &first, RBC_INDEX_CHECK,
                (Rbc_VectorIndexProc **) NULL) != TCL_OK)
        || (RbcVectorGetIndex(interp, vPtr, Tcl_GetStringFromObj(objv[3], NULL),
                &last, RBC_INDEX_CHECK,
                (Rbc_VectorIndexProc **) NULL) != TCL_OK)) {
        return TCL_ERROR;
    }
    listObjPtr = Tcl_NewListObj(0, NULL);
    if (first > last) {
        /* Return the list reversed */
        for (i = last; i <= first; i++) {
            Tcl_ListObjAppendElement(interp, listObjPtr,
................................................................................
             * overlaps.
             */
            tmpPtr = RbcVectorNew(vPtr->dataPtr);
            result = RbcVectorDuplicate(tmpPtr, v2Ptr);
            if (result == TCL_OK) {
                result = RbcVectorDuplicate(vPtr, tmpPtr);
            }
            Rbc_VectorFree(tmpPtr);
        } else {
            result = RbcVectorDuplicate(vPtr, v2Ptr);
        }
    } else if (Tcl_ListObjGetElements(interp, objv[2], &nElem,
            &elemObjArr) == TCL_OK) {
        result = CopyList(vPtr, nElem, elemObjArr);
    } else {

Changes to generic/rbc/rbcVector.c.

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
...
229
230
231
232
233
234
235










236
237



238
239
240
241
242
243
244
...
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
...
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
...
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
....
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
....
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
....
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
....
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
....
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
....
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
....
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
....
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
....
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
....
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
....
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
....
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
....
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
....
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
....
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
....
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
....
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
....
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
....
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
....
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
....
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
....
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
....
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
....
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
....
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
    RbcVectorObject * vPtr);

double          rbcNaN;

/*
 * -----------------------------------------------------------------------
 *
 * RbcVectorInit --
 *
 *      This procedure is invoked to initialize the "vector" command.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Creates the new command and adds a new entry into a global Tcl
 *      associative array.
 *
 * ------------------------------------------------------------------------
 */
double
Rbcdrand48(
    )
{
    return ((double) rand() / (double) RAND_MAX);
}

/*
 * -----------------------------------------------------------------------
 *
 * RbcVectorInit --
 *
 *      This procedure is invoked to initialize the "vector" command.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Creates the new command and adds a new entry into a global Tcl
 *      associative array.
 *
 * ------------------------------------------------------------------------
 */
int
RbcVectorInit(
    Tcl_Interp * interp)
{

    RbcVectorInterpData *dataPtr;       /* Interpreter-specific data. */
#ifdef __BORLANDC__
    union Real {
        struct DoubleWord {
            int             lo, hi;
        } doubleWord;
        double          number;
................................................................................
    rbcNaN = sqrt(-1.0);        /* Generate IEEE 754 Quiet Not-A-Number. */
#endif /* _MSC_VER */

#if !defined(__BORLANDC__) && !defined(_MSC_VER)
    rbcNaN = 0.0 / 0.0;         /* Generate IEEE 754 Not-A-Number. */
#endif /* !__BORLANDC__  && !_MSC_VER */











    dataPtr = RbcVectorGetInterpData(interp);
    Tcl_CreateObjCommand(interp, "rbc::vector", VectorObjCmd, dataPtr, NULL);




    return TCL_OK;
}

/*
 * ------------------------------------------------------------------------
 *
................................................................................
    RbcVectorObject *vPtr;
    register int    i;
    for (i = 2; i < objc; i++) {
        if (RbcVectorLookupName(dataPtr, Tcl_GetStringFromObj(objv[i], NULL),
                &vPtr) != TCL_OK) {
            return TCL_ERROR;
        }
        RbcVectorFree(vPtr);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
................................................................................
static int
VectorExprObjCmd(
    ClientData clientData,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[])
{
    return RbcExprVector(interp, Tcl_GetString(objv[2]), (RbcVector *) NULL);
}

/*
 *----------------------------------------------------------------------
 *
 * VectorNamesObjCmd --
 *
................................................................................
    Tcl_HashSearch  cursor;
    RbcVectorObject *vPtr;

    for (hPtr = Tcl_FirstHashEntry(&(dataPtr->vectorTable), &cursor);
        hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
        vPtr = (RbcVectorObject *) Tcl_GetHashValue(hPtr);
        vPtr->hashPtr = NULL;
        RbcVectorFree(vPtr);
    }
    Tcl_DeleteHashTable(&(dataPtr->vectorTable));

    /* If any user-defined math functions were installed, remove them.  */
    Tcl_DeleteHashTable(&(dataPtr->mathProcTable));

    Tcl_DeleteHashTable(&(dataPtr->indexProcTable));
................................................................................

    *newPtr = isNew;
    Tcl_DStringFree(&qualVecNamePtr);
    return vPtr;

  error:
    if (vPtr != NULL) {
        RbcVectorFree(vPtr);
    }
    Tcl_DStringFree(&qualVecNamePtr);
    return NULL;
}

/*
 * ----------------------------------------------------------------------
................................................................................
static void
VectorInstDeleteProc(
    ClientData clientData)
{                               /* Vector object to delete */
    RbcVectorObject *vPtr = clientData;

    vPtr->cmdToken = 0;
    RbcVectorFree(vPtr);
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcVectorFree --
 *
 *     Removes the memory and frees resources associated with the
 *     vector.
 *
 *        o Removes the trace and the Tcl array variable and unsets
 *          the variable.
 *        o Notifies clients of the vector that the vector is being
................................................................................
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
void
RbcVectorFree(
    RbcVectorObject * vPtr)
{                               /* The vector to free */
    RbcChainLink   *linkPtr;
    VectorClient   *clientPtr;

    if (vPtr->cmdToken != 0) {
        DeleteCommand(vPtr);
................................................................................
        clientPtr = RbcChainGetValue(linkPtr);
        if (clientPtr->proc != NULL) {
            (*clientPtr->proc) (vPtr->interp, clientPtr->clientData, notify);
        }
    }
    /*
     * Some clients may not handle the "destroy" callback properly
     * (they should call RbcFreeVectorId to release the client
     * identifier), so mark any remaining clients to indicate that
     * vector's server has gone away.
     */
    if (notify == RBC_VECTOR_NOTIFY_DESTROY) {
        for (linkPtr = RbcChainFirstLink(vPtr->chainPtr); linkPtr != NULL;
            linkPtr = RbcChainNextLink(linkPtr)) {
            clientPtr = RbcChainGetValue(linkPtr);
................................................................................
int
RbcVectorGetIndex(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int *indexPtr,              /* index to convert */
    int flags,
    RbcVectorIndexProc ** procPtrPtr)
{
    char            c;
    int             value;

    c = string[0];

    /* Treat the index "end" like a numeric index.  */
................................................................................
    }
    if (procPtrPtr != NULL) {
        Tcl_HashEntry  *hPtr;

        hPtr = Tcl_FindHashEntry(&(vPtr->dataPtr->indexProcTable), string);
        if (hPtr != NULL) {
            *indexPtr = RBC_SPECIAL_INDEX;
            *procPtrPtr = (RbcVectorIndexProc *) Tcl_GetHashValue(hPtr);
            return TCL_OK;
        }
    }
    if (Tcl_GetInt(interp, (char *) string, &value) != TCL_OK) {
        long int        lvalue;
        /*
         * Unlike Tcl_GetInt, Tcl_ExprLong needs a valid interpreter,
................................................................................
 */
int
RbcVectorGetIndexRange(
    Tcl_Interp * interp,        /* The interpreter to return results to */
    RbcVectorObject * vPtr,     /* The vector object to get the range from */
    const char *string,         /* The index in the vector to convert */
    int flags,                  /* The flags for special cases */
    RbcVectorIndexProc ** procPtrPtr)
{                               /* The index procedure */
    int             ielem;
    char           *colon;

    colon = NULL;
    if (flags & RBC_INDEX_COLON) {
        colon = strchr(string, ':');
................................................................................
            vPtr->first = 0;    /* Default to the first index */
        } else {
            int             result;

            *colon = '\0';
            result =
                RbcVectorGetIndex(interp, vPtr, string, &ielem, flags,
                (RbcVectorIndexProc **) NULL);
            *colon = ':';
            if (result != TCL_OK) {
                return TCL_ERROR;
            }
            vPtr->first = ielem;
        }
        if (*(colon + 1) == '\0') {
            /* Default to the last index */
            vPtr->last = (vPtr->length > 0) ? vPtr->length - 1 : 0;
        } else {
            if (RbcVectorGetIndex(interp, vPtr, colon + 1, &ielem, flags,
                    (RbcVectorIndexProc **) NULL) != TCL_OK) {
                return TCL_ERROR;
            }
            vPtr->last = ielem;
        }
        if (vPtr->first > vPtr->last) {
            if (interp != NULL) {
                Tcl_AppendResult(interp, "bad range \"", string,
................................................................................
                    "\"", (char *) NULL);
            }
            return NULL;
        }
        *p = '\0';
        result =
            RbcVectorGetIndexRange(interp, vPtr, start,
            (RBC_INDEX_COLON | RBC_INDEX_CHECK), (RbcVectorIndexProc **) NULL);
        *p = ')';
        if (result != TCL_OK) {
            return NULL;
        }
        p++;
    }
    if (endPtr != NULL) {
................................................................................
 *
 * ----------------------------------------------------------------------
 */
void
RbcVectorUpdateClients(
    RbcVectorObject * vPtr)
{                               /* The vector to update clients for */
    vPtr->dirty++;
    vPtr->max = vPtr->min = rbcNaN;
    if (vPtr->notifyFlags & NOTIFY_NEVER) {
        return;
    }
    vPtr->notifyFlags |= NOTIFY_UPDATED;
    if (vPtr->notifyFlags & NOTIFY_ALWAYS) {
        VectorNotifyClients(vPtr);
................................................................................
VectorVarTrace(
    ClientData clientData,      /* Vector object. */
    Tcl_Interp * interp,        /* Interpreter of the vector */
    const char *part1,          /* name of array variable accessed */
    const char *part2,          /* name of array element accessed */
    int flags)
{
    RbcVectorIndexProc *indexProc;
    RbcVectorObject *vPtr = clientData;
    int             first, last;
    int             varFlags;

    static char     message[MAX_ERR_MSG + 1];

    if (part2 == NULL) {
        if (flags & TCL_TRACE_UNSETS) {
            /* vector is deleted via an unset on the whole array variable */
            ckfree((char *) vPtr->arrayName);
            vPtr->arrayName = NULL;
            if (vPtr->freeOnUnset) {
                RbcVectorFree(vPtr);
            }
        }
        return NULL;
    }
    if (RbcVectorGetIndexRange(interp, vPtr, part2, RBC_INDEX_ALL_FLAGS,
            &indexProc) != TCL_OK) {
        goto error;
................................................................................
            return "write-only index";
        }
        if (first == last) {
            if (first >= 0) {
                value = vPtr->valueArr[first];
            } else {
                vPtr->first = 0, vPtr->last = vPtr->length - 1;
                value = (*indexProc) ((RbcVector *) vPtr);
            }
            objPtr = Tcl_NewDoubleObj(value);
            if (Tcl_SetVar2Ex(interp, part1, part2, objPtr, varFlags) == NULL) {
                Tcl_DecrRefCount(objPtr);
                goto error;
            }
        } else {
................................................................................
    }
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * RbcFreeVectorId --
 *
 *      Releases the token for an existing vector.  This
 *      indicates that the client is no longer interested
 *      the vector.  Any previously specified callback
 *      routine will no longer be invoked when (and if) the
 *      vector changes.
 *
................................................................................
 * Side Effects:
 *      Any previously specified callback routine will no
 *      longer be invoked when (and if) the vector changes.
 *
 *--------------------------------------------------------------
 */
void
RbcFreeVectorId(
    RbcVectorId clientId)
{                               /* Client token identifying the vector */
    VectorClient   *clientPtr = (VectorClient *) clientId;

    if (clientPtr->magic != VECTOR_MAGIC) {
        return;                 /* Not a valid token */
    }
................................................................................
    }
    ckfree((char *) clientPtr);
}

/*
 * -----------------------------------------------------------------------
 *
 * RbcGetVectorById --
 *
 *      Returns a pointer to the vector associated with the client
 *      token.
 *
 * Results:
 *      A standard Tcl result.  If the client token is not associated
 *      with a vector any longer, TCL_ERROR is returned. Otherwise,
................................................................................
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * -----------------------------------------------------------------------
 */
int
RbcGetVectorById(
    Tcl_Interp * interp,
    RbcVectorId clientId,       /* Client token identifying the vector */
    RbcVector ** vecPtrPtr)
{
    VectorClient   *clientPtr = (VectorClient *) clientId;

    if (clientPtr->magic != VECTOR_MAGIC) {
        Tcl_AppendResult(interp, "bad vector token", (char *) NULL);
        return TCL_ERROR;
    }
    if (clientPtr->serverPtr == NULL) {
        Tcl_AppendResult(interp, "vector no longer exists", (char *) NULL);
        return TCL_ERROR;
    }
    RbcVectorUpdateRange(clientPtr->serverPtr);
    *vecPtrPtr = (RbcVector *) clientPtr->serverPtr;
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * RbcVectorExists2 --
 *
 *      Returns whether the vector associated with the client token
 *      still exists.
 *
 * Results:
 *      Returns 1 is the vector still exists, 0 otherwise.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
int
RbcVectorExists2(
    Tcl_Interp * interp,
    const char *vecName)
{
    RbcVectorInterpData *dataPtr;       /* Interpreter-specific data. */

    dataPtr = RbcVectorGetInterpData(interp);
    if (GetVectorObject(dataPtr, vecName, RBC_NS_SEARCH_BOTH) != NULL) {
................................................................................
    clientId = (RbcVectorId) clientPtr;
    return clientId;
}

/*
 * -----------------------------------------------------------------------
 *
 * RbcSetVectorChangedProc --
 *
 *      Sets the routine to be called back when the vector is changed
 *      or deleted.  *clientData* will be provided as an argument. If
 *      *proc* is NULL, no callback will be made.
 *
 * Results:
 *      None.
................................................................................
 * Side Effects:
 *      The designated routine will be called when the vector is changed
 *      or deleted.
 *
 * -----------------------------------------------------------------------
 */
void
RbcSetVectorChangedProc(
    RbcVectorId clientId,       /* Client token identifying the vector */
    RbcVectorChangedProc * proc,        /* Address of routine to call when the contents
                                         * of the vector change. If NULL, no routine
                                         * will be called */
    ClientData clientData)
{                               /* One word of information to pass along when
                                 * the above routine is called */
................................................................................
    clientPtr->clientData = clientData;
    clientPtr->proc = proc;
}

/*
 *--------------------------------------------------------------
 *
 * RbcNameOfVectorId --
 *
 *      Returns the name of the vector (and array variable).
 *
 * Results:
 *      The name of the array variable is returned.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
char           *
RbcNameOfVectorId(
    RbcVectorId clientId)
{                               /* Client token identifying the vector */
    VectorClient   *clientPtr = (VectorClient *) clientId;

    if ((clientPtr->magic != VECTOR_MAGIC) || (clientPtr->serverPtr == NULL)) {
        return NULL;
    }
    return clientPtr->serverPtr->name;
}

/*
 * -----------------------------------------------------------------------
 *
 * RbcGetVector --
 *
 *      Returns a pointer to the vector associated with the given name.
 *
 * Results:
 *      A standard Tcl result.  If there is no vector "name", TCL_ERROR
 *      is returned.  Otherwise TCL_OK is returned and vecPtrPtr will
 *      point to the vector.
................................................................................
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * -----------------------------------------------------------------------
 */
int
RbcGetVector(
    Tcl_Interp * interp,
    const char *name,
    RbcVector ** vecPtrPtr)
{
    RbcVectorInterpData *dataPtr;       /* Interpreter-specific data. */
    RbcVectorObject *vPtr;
    char           *nameCopy;
    int             result;

    dataPtr = RbcVectorGetInterpData(interp);
................................................................................
    nameCopy = RbcStrdup(name);
    result = RbcVectorLookupName(dataPtr, nameCopy, &vPtr);
    ckfree((char *) nameCopy);
    if (result != TCL_OK) {
        return TCL_ERROR;
    }
    RbcVectorUpdateRange(vPtr);
    *vecPtrPtr = (RbcVector *) vPtr;
    return TCL_OK;
}

/*
 * -----------------------------------------------------------------------
 *
 * RbcCreateVector --
................................................................................
int
RbcCreateVector2(
    Tcl_Interp * interp,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int initialSize,
    RbcVector ** vecPtrPtr)
{
    RbcVectorInterpData *dataPtr;       /* Interpreter-specific data. */
    RbcVectorObject *vPtr;
    int             isNew;
    char           *nameCopy;

    if (initialSize < 0) {
................................................................................
    }
    if (initialSize > 0) {
        if (RbcVectorChangeLength(vPtr, initialSize) != TCL_OK) {
            return TCL_ERROR;
        }
    }
    if (vecPtrPtr != NULL) {
        *vecPtrPtr = (RbcVector *) vPtr;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * RbcCreateVector --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
RbcCreateVector(
    Tcl_Interp * interp,
    const char *name,
    int size,
    RbcVector ** vecPtrPtr)
{
    return RbcCreateVector2(interp, name, name, name, size, vecPtrPtr);
}

/*
 * -----------------------------------------------------------------------
 *
 * RbcResizeVector --
 *
 *      Changes the size of the vector.  All clients with designated
 *      callback routines will be notified of the size change.
 *
 * Results:
 *      A standard Tcl result.  If no vector exists by that name,
 *      TCL_ERROR is returned.  Otherwise TCL_OK is returned and
................................................................................
 * Side Effects:
 *      Memory may be reallocated for the new vector size.  All clients
 *      which set call back procedures will be notified.
 *
 * -----------------------------------------------------------------------
 */
int
RbcResizeVector(
    RbcVector * vecPtr,
    int length)
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;

    if (RbcVectorChangeLength(vPtr, length) != TCL_OK) {
        Tcl_AppendResult(vPtr->interp, "can't resize vector \"", vPtr->name,
            "\"", (char *) NULL);
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
char           *
RbcNameOfVector(
    RbcVector * vecPtr)
{                               /* Vector to query. */
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    return vPtr->name;
}

/*
 * -----------------------------------------------------------------------
 *
 * RbcResetVector --
 *
 *      Resets the vector data.  This is called by a client to
 *      indicate that the vector data has changed.  The vector does
 *      not need to point to different memory.  Any clients of the
 *      vector will be notified of the change.
 *
 * Results:
................................................................................
 * Side Effects:
 *      Any client designated callbacks will be posted.  Memory may
 *      be changed for the vector array.
 *
 * -----------------------------------------------------------------------
 */
int
RbcResetVector(
    RbcVector * vecPtr,
    double *valueArr,           /* Array containing the elements of the
                                 * vector. If NULL, indicates to reset the
                                 * vector.*/
    int length,                 /* The number of elements that the vector
                                 * currently holds. */
    int size,                   /* The maximum number of elements that the
                                 * array can hold. */






|

|


|


<
|













|













|


>







 







>
>
>
>
>
>
>
>
>
>

|
>
>
>







 







|







 







|







 







|







 







|







 







|





|







 







|







 







|







 







|







 







|







 







|







 







|











|







 







|







 







<







 







|












|







 







|







 







|







 







|







 







|







 







|


|












|






|













|







 







|







 







|







 







|












|













|







 







|


|







 







|







 







|







 







|







|












|



|







|







 







|
|







 







|








|







 







|
|







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
...
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
...
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
...
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
...
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
....
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
....
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
....
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
....
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
....
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
....
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
....
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
....
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
....
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
....
2133
2134
2135
2136
2137
2138
2139

2140
2141
2142
2143
2144
2145
2146
....
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
....
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
....
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
....
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
....
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
....
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
....
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
....
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
....
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
....
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
....
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
....
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
....
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
....
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
....
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
    RbcVectorObject * vPtr);

double          rbcNaN;

/*
 * -----------------------------------------------------------------------
 *
 * Rbcdrand48 --
 *
 *      TODO
 *
 * Results:
 *      TODO
 *
 * Side effects:

 *      TODO
 *
 * ------------------------------------------------------------------------
 */
double
Rbcdrand48(
    )
{
    return ((double) rand() / (double) RAND_MAX);
}

/*
 * -----------------------------------------------------------------------
 *
 * Rbc_VectorInit --
 *
 *      This procedure is invoked to initialize the "vector" command.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Creates the new command and adds a new entry into a global Tcl
 *      associative array.
 *
 * ------------------------------------------------------------------------
 */
int
Rbc_VectorInit(
    Tcl_Interp * interp)
{
    Tcl_Namespace *nsPtr;
    RbcVectorInterpData *dataPtr;       /* Interpreter-specific data. */
#ifdef __BORLANDC__
    union Real {
        struct DoubleWord {
            int             lo, hi;
        } doubleWord;
        double          number;
................................................................................
    rbcNaN = sqrt(-1.0);        /* Generate IEEE 754 Quiet Not-A-Number. */
#endif /* _MSC_VER */

#if !defined(__BORLANDC__) && !defined(_MSC_VER)
    rbcNaN = 0.0 / 0.0;         /* Generate IEEE 754 Not-A-Number. */
#endif /* !__BORLANDC__  && !_MSC_VER */

    /*
     * Create holding namespace.
     */
    nsPtr = Tcl_CreateNamespace(interp, "::graph", NULL, NULL);
    if (nsPtr == NULL) {
        return TCL_ERROR;
    }
    /*
     * Create and export our public API.
     */
    dataPtr = RbcVectorGetInterpData(interp);
    Tcl_CreateObjCommand(interp, "::graph::vector", VectorObjCmd, dataPtr, NULL);
    if (Tcl_Export(interp, nsPtr, "vector", 0) != TCL_OK) {
        return TCL_ERROR;
    }

    return TCL_OK;
}

/*
 * ------------------------------------------------------------------------
 *
................................................................................
    RbcVectorObject *vPtr;
    register int    i;
    for (i = 2; i < objc; i++) {
        if (RbcVectorLookupName(dataPtr, Tcl_GetStringFromObj(objv[i], NULL),
                &vPtr) != TCL_OK) {
            return TCL_ERROR;
        }
        Rbc_VectorFree(vPtr);
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
................................................................................
static int
VectorExprObjCmd(
    ClientData clientData,
    Tcl_Interp * interp,
    int objc,
    Tcl_Obj * const objv[])
{
    return RbcExprVector(interp, Tcl_GetString(objv[2]), (Rbc_Vector *) NULL);
}

/*
 *----------------------------------------------------------------------
 *
 * VectorNamesObjCmd --
 *
................................................................................
    Tcl_HashSearch  cursor;
    RbcVectorObject *vPtr;

    for (hPtr = Tcl_FirstHashEntry(&(dataPtr->vectorTable), &cursor);
        hPtr != NULL; hPtr = Tcl_NextHashEntry(&cursor)) {
        vPtr = (RbcVectorObject *) Tcl_GetHashValue(hPtr);
        vPtr->hashPtr = NULL;
        Rbc_VectorFree(vPtr);
    }
    Tcl_DeleteHashTable(&(dataPtr->vectorTable));

    /* If any user-defined math functions were installed, remove them.  */
    Tcl_DeleteHashTable(&(dataPtr->mathProcTable));

    Tcl_DeleteHashTable(&(dataPtr->indexProcTable));
................................................................................

    *newPtr = isNew;
    Tcl_DStringFree(&qualVecNamePtr);
    return vPtr;

  error:
    if (vPtr != NULL) {
        Rbc_VectorFree(vPtr);
    }
    Tcl_DStringFree(&qualVecNamePtr);
    return NULL;
}

/*
 * ----------------------------------------------------------------------
................................................................................
static void
VectorInstDeleteProc(
    ClientData clientData)
{                               /* Vector object to delete */
    RbcVectorObject *vPtr = clientData;

    vPtr->cmdToken = 0;
    Rbc_VectorFree(vPtr);
}

/*
 * ----------------------------------------------------------------------
 *
 * Rbc_VectorFree --
 *
 *     Removes the memory and frees resources associated with the
 *     vector.
 *
 *        o Removes the trace and the Tcl array variable and unsets
 *          the variable.
 *        o Notifies clients of the vector that the vector is being
................................................................................
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
void
Rbc_VectorFree(
    RbcVectorObject * vPtr)
{                               /* The vector to free */
    RbcChainLink   *linkPtr;
    VectorClient   *clientPtr;

    if (vPtr->cmdToken != 0) {
        DeleteCommand(vPtr);
................................................................................
        clientPtr = RbcChainGetValue(linkPtr);
        if (clientPtr->proc != NULL) {
            (*clientPtr->proc) (vPtr->interp, clientPtr->clientData, notify);
        }
    }
    /*
     * Some clients may not handle the "destroy" callback properly
     * (they should call Rbc_FreeVectorId to release the client
     * identifier), so mark any remaining clients to indicate that
     * vector's server has gone away.
     */
    if (notify == RBC_VECTOR_NOTIFY_DESTROY) {
        for (linkPtr = RbcChainFirstLink(vPtr->chainPtr); linkPtr != NULL;
            linkPtr = RbcChainNextLink(linkPtr)) {
            clientPtr = RbcChainGetValue(linkPtr);
................................................................................
int
RbcVectorGetIndex(
    Tcl_Interp * interp,
    RbcVectorObject * vPtr,
    const char *string,
    int *indexPtr,              /* index to convert */
    int flags,
    Rbc_VectorIndexProc ** procPtrPtr)
{
    char            c;
    int             value;

    c = string[0];

    /* Treat the index "end" like a numeric index.  */
................................................................................
    }
    if (procPtrPtr != NULL) {
        Tcl_HashEntry  *hPtr;

        hPtr = Tcl_FindHashEntry(&(vPtr->dataPtr->indexProcTable), string);
        if (hPtr != NULL) {
            *indexPtr = RBC_SPECIAL_INDEX;
            *procPtrPtr = (Rbc_VectorIndexProc *) Tcl_GetHashValue(hPtr);
            return TCL_OK;
        }
    }
    if (Tcl_GetInt(interp, (char *) string, &value) != TCL_OK) {
        long int        lvalue;
        /*
         * Unlike Tcl_GetInt, Tcl_ExprLong needs a valid interpreter,
................................................................................
 */
int
RbcVectorGetIndexRange(
    Tcl_Interp * interp,        /* The interpreter to return results to */
    RbcVectorObject * vPtr,     /* The vector object to get the range from */
    const char *string,         /* The index in the vector to convert */
    int flags,                  /* The flags for special cases */
    Rbc_VectorIndexProc ** procPtrPtr)
{                               /* The index procedure */
    int             ielem;
    char           *colon;

    colon = NULL;
    if (flags & RBC_INDEX_COLON) {
        colon = strchr(string, ':');
................................................................................
            vPtr->first = 0;    /* Default to the first index */
        } else {
            int             result;

            *colon = '\0';
            result =
                RbcVectorGetIndex(interp, vPtr, string, &ielem, flags,
                (Rbc_VectorIndexProc **) NULL);
            *colon = ':';
            if (result != TCL_OK) {
                return TCL_ERROR;
            }
            vPtr->first = ielem;
        }
        if (*(colon + 1) == '\0') {
            /* Default to the last index */
            vPtr->last = (vPtr->length > 0) ? vPtr->length - 1 : 0;
        } else {
            if (RbcVectorGetIndex(interp, vPtr, colon + 1, &ielem, flags,
                    (Rbc_VectorIndexProc **) NULL) != TCL_OK) {
                return TCL_ERROR;
            }
            vPtr->last = ielem;
        }
        if (vPtr->first > vPtr->last) {
            if (interp != NULL) {
                Tcl_AppendResult(interp, "bad range \"", string,
................................................................................
                    "\"", (char *) NULL);
            }
            return NULL;
        }
        *p = '\0';
        result =
            RbcVectorGetIndexRange(interp, vPtr, start,
            (RBC_INDEX_COLON | RBC_INDEX_CHECK), (Rbc_VectorIndexProc **) NULL);
        *p = ')';
        if (result != TCL_OK) {
            return NULL;
        }
        p++;
    }
    if (endPtr != NULL) {
................................................................................
 *
 * ----------------------------------------------------------------------
 */
void
RbcVectorUpdateClients(
    RbcVectorObject * vPtr)
{                               /* The vector to update clients for */

    vPtr->max = vPtr->min = rbcNaN;
    if (vPtr->notifyFlags & NOTIFY_NEVER) {
        return;
    }
    vPtr->notifyFlags |= NOTIFY_UPDATED;
    if (vPtr->notifyFlags & NOTIFY_ALWAYS) {
        VectorNotifyClients(vPtr);
................................................................................
VectorVarTrace(
    ClientData clientData,      /* Vector object. */
    Tcl_Interp * interp,        /* Interpreter of the vector */
    const char *part1,          /* name of array variable accessed */
    const char *part2,          /* name of array element accessed */
    int flags)
{
    Rbc_VectorIndexProc *indexProc;
    RbcVectorObject *vPtr = clientData;
    int             first, last;
    int             varFlags;

    static char     message[MAX_ERR_MSG + 1];

    if (part2 == NULL) {
        if (flags & TCL_TRACE_UNSETS) {
            /* vector is deleted via an unset on the whole array variable */
            ckfree((char *) vPtr->arrayName);
            vPtr->arrayName = NULL;
            if (vPtr->freeOnUnset) {
                Rbc_VectorFree(vPtr);
            }
        }
        return NULL;
    }
    if (RbcVectorGetIndexRange(interp, vPtr, part2, RBC_INDEX_ALL_FLAGS,
            &indexProc) != TCL_OK) {
        goto error;
................................................................................
            return "write-only index";
        }
        if (first == last) {
            if (first >= 0) {
                value = vPtr->valueArr[first];
            } else {
                vPtr->first = 0, vPtr->last = vPtr->length - 1;
                value = (*indexProc) ((Rbc_Vector *) vPtr);
            }
            objPtr = Tcl_NewDoubleObj(value);
            if (Tcl_SetVar2Ex(interp, part1, part2, objPtr, varFlags) == NULL) {
                Tcl_DecrRefCount(objPtr);
                goto error;
            }
        } else {
................................................................................
    }
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * Rbc_FreeVectorId --
 *
 *      Releases the token for an existing vector.  This
 *      indicates that the client is no longer interested
 *      the vector.  Any previously specified callback
 *      routine will no longer be invoked when (and if) the
 *      vector changes.
 *
................................................................................
 * Side Effects:
 *      Any previously specified callback routine will no
 *      longer be invoked when (and if) the vector changes.
 *
 *--------------------------------------------------------------
 */
void
Rbc_FreeVectorId(
    RbcVectorId clientId)
{                               /* Client token identifying the vector */
    VectorClient   *clientPtr = (VectorClient *) clientId;

    if (clientPtr->magic != VECTOR_MAGIC) {
        return;                 /* Not a valid token */
    }
................................................................................
    }
    ckfree((char *) clientPtr);
}

/*
 * -----------------------------------------------------------------------
 *
 * Rbc_GetVectorById --
 *
 *      Returns a pointer to the vector associated with the client
 *      token.
 *
 * Results:
 *      A standard Tcl result.  If the client token is not associated
 *      with a vector any longer, TCL_ERROR is returned. Otherwise,
................................................................................
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * -----------------------------------------------------------------------
 */
int
Rbc_GetVectorById(
    Tcl_Interp * interp,
    RbcVectorId clientId,       /* Client token identifying the vector */
    Rbc_Vector ** vecPtrPtr)
{
    VectorClient   *clientPtr = (VectorClient *) clientId;

    if (clientPtr->magic != VECTOR_MAGIC) {
        Tcl_AppendResult(interp, "bad vector token", (char *) NULL);
        return TCL_ERROR;
    }
    if (clientPtr->serverPtr == NULL) {
        Tcl_AppendResult(interp, "vector no longer exists", (char *) NULL);
        return TCL_ERROR;
    }
    RbcVectorUpdateRange(clientPtr->serverPtr);
    *vecPtrPtr = (Rbc_Vector *) clientPtr->serverPtr;
    return TCL_OK;
}

/*
 * ----------------------------------------------------------------------
 *
 * Rbc_VectorExists --
 *
 *      Returns whether the vector associated with the client token
 *      still exists.
 *
 * Results:
 *      Returns 1 is the vector still exists, 0 otherwise.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * ----------------------------------------------------------------------
 */
int
Rbc_VectorExists(
    Tcl_Interp * interp,
    const char *vecName)
{
    RbcVectorInterpData *dataPtr;       /* Interpreter-specific data. */

    dataPtr = RbcVectorGetInterpData(interp);
    if (GetVectorObject(dataPtr, vecName, RBC_NS_SEARCH_BOTH) != NULL) {
................................................................................
    clientId = (RbcVectorId) clientPtr;
    return clientId;
}

/*
 * -----------------------------------------------------------------------
 *
 * Rbc_SetVectorChangedProc --
 *
 *      Sets the routine to be called back when the vector is changed
 *      or deleted.  *clientData* will be provided as an argument. If
 *      *proc* is NULL, no callback will be made.
 *
 * Results:
 *      None.
................................................................................
 * Side Effects:
 *      The designated routine will be called when the vector is changed
 *      or deleted.
 *
 * -----------------------------------------------------------------------
 */
void
Rbc_SetVectorChangedProc(
    RbcVectorId clientId,       /* Client token identifying the vector */
    RbcVectorChangedProc * proc,        /* Address of routine to call when the contents
                                         * of the vector change. If NULL, no routine
                                         * will be called */
    ClientData clientData)
{                               /* One word of information to pass along when
                                 * the above routine is called */
................................................................................
    clientPtr->clientData = clientData;
    clientPtr->proc = proc;
}

/*
 *--------------------------------------------------------------
 *
 * Rbc_NameOfVectorId --
 *
 *      Returns the name of the vector (and array variable).
 *
 * Results:
 *      The name of the array variable is returned.
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
char           *
Rbc_NameOfVectorId(
    RbcVectorId clientId)
{                               /* Client token identifying the vector */
    VectorClient   *clientPtr = (VectorClient *) clientId;

    if ((clientPtr->magic != VECTOR_MAGIC) || (clientPtr->serverPtr == NULL)) {
        return NULL;
    }
    return clientPtr->serverPtr->name;
}

/*
 * -----------------------------------------------------------------------
 *
 * Rbc_GetVector --
 *
 *      Returns a pointer to the vector associated with the given name.
 *
 * Results:
 *      A standard Tcl result.  If there is no vector "name", TCL_ERROR
 *      is returned.  Otherwise TCL_OK is returned and vecPtrPtr will
 *      point to the vector.
................................................................................
 *
 * Side effects:
 *      TODO: Side Effects
 *
 * -----------------------------------------------------------------------
 */
int
Rbc_GetVector(
    Tcl_Interp * interp,
    const char *name,
    Rbc_Vector ** vecPtrPtr)
{
    RbcVectorInterpData *dataPtr;       /* Interpreter-specific data. */
    RbcVectorObject *vPtr;
    char           *nameCopy;
    int             result;

    dataPtr = RbcVectorGetInterpData(interp);
................................................................................
    nameCopy = RbcStrdup(name);
    result = RbcVectorLookupName(dataPtr, nameCopy, &vPtr);
    ckfree((char *) nameCopy);
    if (result != TCL_OK) {
        return TCL_ERROR;
    }
    RbcVectorUpdateRange(vPtr);
    *vecPtrPtr = (Rbc_Vector *) vPtr;
    return TCL_OK;
}

/*
 * -----------------------------------------------------------------------
 *
 * RbcCreateVector --
................................................................................
int
RbcCreateVector2(
    Tcl_Interp * interp,
    const char *vecName,
    const char *cmdName,
    const char *varName,
    int initialSize,
    Rbc_Vector ** vecPtrPtr)
{
    RbcVectorInterpData *dataPtr;       /* Interpreter-specific data. */
    RbcVectorObject *vPtr;
    int             isNew;
    char           *nameCopy;

    if (initialSize < 0) {
................................................................................
    }
    if (initialSize > 0) {
        if (RbcVectorChangeLength(vPtr, initialSize) != TCL_OK) {
            return TCL_ERROR;
        }
    }
    if (vecPtrPtr != NULL) {
        *vecPtrPtr = (Rbc_Vector *) vPtr;
    }
    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * Rbc_CreateVector --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
int
Rbc_CreateVector(
    Tcl_Interp * interp,
    const char *name,
    int size,
    Rbc_Vector ** vecPtrPtr)
{
    return RbcCreateVector2(interp, name, name, name, size, vecPtrPtr);
}

/*
 * -----------------------------------------------------------------------
 *
 * Rbc_ResizeVector --
 *
 *      Changes the size of the vector.  All clients with designated
 *      callback routines will be notified of the size change.
 *
 * Results:
 *      A standard Tcl result.  If no vector exists by that name,
 *      TCL_ERROR is returned.  Otherwise TCL_OK is returned and
................................................................................
 * Side Effects:
 *      Memory may be reallocated for the new vector size.  All clients
 *      which set call back procedures will be notified.
 *
 * -----------------------------------------------------------------------
 */
int
Rbc_ResizeVector(
    Rbc_Vector * vecPtr,
    int length)
{
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;

    if (RbcVectorChangeLength(vPtr, length) != TCL_OK) {
        Tcl_AppendResult(vPtr->interp, "can't resize vector \"", vPtr->name,
            "\"", (char *) NULL);
................................................................................
 * Side effects:
 *      TODO: Side Effects
 *
 *--------------------------------------------------------------
 */
char           *
RbcNameOfVector(
    Rbc_Vector * vecPtr)
{                               /* Vector to query. */
    RbcVectorObject *vPtr = (RbcVectorObject *) vecPtr;
    return vPtr->name;
}

/*
 * -----------------------------------------------------------------------
 *
 * Rbc_ResetVector --
 *
 *      Resets the vector data.  This is called by a client to
 *      indicate that the vector data has changed.  The vector does
 *      not need to point to different memory.  Any clients of the
 *      vector will be notified of the change.
 *
 * Results:
................................................................................
 * Side Effects:
 *      Any client designated callbacks will be posted.  Memory may
 *      be changed for the vector array.
 *
 * -----------------------------------------------------------------------
 */
int
Rbc_ResetVector(
    Rbc_Vector * vecPtr,
    double *valueArr,           /* Array containing the elements of the
                                 * vector. If NULL, indicates to reset the
                                 * vector.*/
    int length,                 /* The number of elements that the vector
                                 * currently holds. */
    int size,                   /* The maximum number of elements that the
                                 * array can hold. */

Changes to generic/tkWindow.c.

3312
3313
3314
3315
3316
3317
3318




3319
3320
3321
3322
3323
3324
3325
3326
	goto done;
    }

    /*
     * Initialize the rbc widget set
     */
#ifndef MAC_OSX_TK




    code = Rbc_Init(interp);
    if (code != TCL_OK) {
	goto done;
    }
#endif

    /*
     * Invoke platform-specific initialization. Unlock mutex before entering






>
>
>
>
|







3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
	goto done;
    }

    /*
     * Initialize the rbc widget set
     */
#ifndef MAC_OSX_TK
    code = Rbc_VectorInit(interp);
    if (code != TCL_OK) {
	goto done;
    }
    code = Rbc_GraphInit(interp);
    if (code != TCL_OK) {
	goto done;
    }
#endif

    /*
     * Invoke platform-specific initialization. Unlock mutex before entering

Added library/graph.tcl.












































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
# graph.tcl --
#
# This file defines the default bindings for Tk graph widgets and provides
# procedures that help in implementing those bindings.
#

## Used namespace.
namespace eval ::graph {
    variable _zoom
    array set _zoom {}
}

## ::graph binding --
#
#   Enable and disable default bindings for specified elements.
#
# Arguments:
# args -    list of entries for which to enable default bindings.
#           For not given entries bindings will be disabled.
#           Possible names are:
#               legend, crosshairs, zoom, findelement
#
::oo::define ::graph method bindings {args} {
    array set myArgs {legend 0 crosshairs 0 zoom 0 findelement 0}
    foreach myName $args {
        if {![info exists myArgs($myName)]} {
            return -code error "wrong or double name '$myName' in given list"
        }
        set myArgs($myName) 1
    }
    set my  [namespace which my]
    if {$myArgs(legend)} {
        my legend bind all <Enter> [list $my _legend activate]
	    my legend bind all <Leave> [list $my _legend deactivate]
	    my legend bind all <ButtonPress-1> [list $my _legend select]
    } else {
        my legend bind all <Enter> {}
	    my legend bind all <Leave> {}
	    my legend bind all <ButtonPress-1> {}
    }
    if {$myArgs(crosshairs)} {
        my crosshairs on
        my _bindtag bind cross <Any-Motion> {%W crosshairs configure -position @%x,%y}
        my _bindtag bind cross <Leave> {%W crosshairs off}
        my _bindtag bind cross <Enter> {%W crosshairs on}
	    my _bindtag add cross
    } else {
        my crosshairs off
	    my _bindtag remove cross
    }
    if {$myArgs(zoom)} {
        my _zoom init
        my _bindtag bind zoom <ButtonPress-1> [list $my _zoom setpoint %x %y]
        my _bindtag bind zoom <ButtonPress-3> [list $my _zoom reset]
        my _bindtag add zoom
    } else {
        my _zoom remove
	    my _bindtag remove zoom
    }
    if {$myArgs(findelement)} {
        my _bindtag bind find <Control-ButtonPress-2> [list $my _findelement %x %y]
        my _bindtag bind find <Control-ButtonRelease-2> [list $my _findelement {} {}]
        my _bindtag add find
    } else {
        my _findelement {} {}
        my _bindtag remove find
    }
}

#
# Private functions.
#

# ::graph _legend --
#
#   Helper function for legend bindings.
#
# Arguments:
# mode -    Indicate what to do
#   - activate "w"
#   - deactivate "w"
#   - select "w"
::oo::define ::graph method _legend {mode} {
    set elem [my legend get current]
    switch -- $mode {
        activate {
            my legend activate $elem
        }
        deactivate {
            my legend deactivate $elem
        }
        select {
            set relief [my element cget $elem -labelrelief]
            if { $relief eq "flat" } {
        	    my element configure $elem -labelrelief raised
        	    my element activate $elem
            } else {
        	    my element configure $elem -labelrelief flat
        	    my element deactivate $elem
            }
        }
    }
}

# ::graph _bindtag --
#
#   Helper function to add/remove of bindtags.
#
# Arguments:
# mode -    Indicate what to do
#   - add "widget" "tag"
#   - remove "widget" "tag"
# tag -     Tag to add or remove
::oo::define ::grap