Tk Source Code

Changes On Branch tip-510
Login
Bounty program for improvements to Tcl and certain Tcl packages.

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

Changes In Branch tip-510 Excluding Merge-Ins

This is equivalent to a diff from 3fadeb90 to 3e448325

2019-05-08
19:47
New files from René Zaumseil Leaf check-in: 3e448325 user: fvogel tags: tip-510
2019-04-12
20:10
Repair test tk-1.2 check-in: e608f7c6 user: fvogel tags: tip-510
2018-08-21
19:06
Fix [66db98f30d] regarding error messages spit by messageboxes in the test suite, while still not regress as described in [98dce84781] (yes and no answers were swapped) check-in: 854a060c user: fvogel tags: trunk
2018-08-19
14:14
merge trunk check-in: fc67d206 user: fvogel tags: tip-507
14:12
merge trunk check-in: d222f03a user: fvogel tags: tip-510
13:49
merge trunk (leaving out any changes in generic/tkText* however) check-in: 06b9d56a user: fvogel tags: revised_text, tip-466
2018-08-18
21:17
Fix bug [c2c5bdb4aa]: segfault when opening colorpicker check-in: 3fadeb90 user: culler tags: trunk
21:15
Fix bug [c2c5bdb4aa]: segfault when opening colorpicker check-in: 6f994d29 user: culler tags: core-8-6-branch
2018-08-15
16:22
Fix [98dce84781]: yesno messageBoxes on macOS return wrong values check-in: b2160d49 user: fvogel tags: trunk

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

*   [SYNOPSIS](#SYNOPSIS)  
*   [STANDARD OPTIONS](#STANDARD-OPTIONS)  
  [-background or -bg, background, Background](options.htm#M-background)  
  [-borderwidth or -bd, borderWidth, BorderWidth](options.htm#M-borderwidth)  
  [-cursor, cursor, Cursor](options.htm#M-cursor)  
  [-foreground or -fg, foreground, Foreground](options.htm#M-foreground)  
  [-height, height, Height](options.htm#M-height)  
  [-width, width, Width](options.htm#M-width)  
*   [WIDGET-SPECIFIC OPTIONS](#WIDGET-SPECIFIC-OPTIONS)  
  [-aspect, aspect, Aspect](#-aspect) *width/height*  
  [-barmode, barMode, BarMode](#-barmode)  
  [-barwidth, barWidth, BarWidth](#-barwidth)  
  [-baseline, baseline, Baseline](#-baseline)  
  [-bottommargin, bottomMargin, Margin](#-bottommargin) *pixels*  
  [-bottomvariable, bottomVariable, BottomVariable](#-bottomvariable)  
  [-bufferelements, bufferElements, BufferElements](#-bufferelements) *boolean*  
  [-buffergraph, bufferGraph, BufferGraph](#-buffergraph)  
  [-class, class, Class](options.htm#M-class)  
  [-font, font, Font](#-font) *fontName*  
  [-halo, halo, Halo](#-halo) *pixels*  
  [-highlightbackground, highlightBackground, HighlightBackground](#-highlightbackground)  
  [-highlightcolor, highlightColor, HighlightColor](#-highlightcolor)  
  [-highlightthickness, highlightThickness, HighlightThickness](#-highlightthickness)  
  [-invertxy, invertXY, InvertXY](#-invertxy) *boolean*  
  [-justify, justify, Justify](#-justify) *justify*  
  [-leftmargin or -lm, leftMargin, Margin](#-leftmargin) *pixels*  
  [-leftvariable, leftVariable, LeftVariable](#-leftvariable)  
  [-plotbackground, plotBackground, Background](#-plotbackground) *color*  
  [-plotborderwidth, plotBorderWidth, BorderWidth](#-plotborderwidth) *pixels*  
  [-plotpadx, plotPadX, PlotPad](#-plotpadx) *pad*  
  [-plotpady, plotPadY, PlotPad](#-plotpadx) *pad*  
  [-plotrelief, plotRelief, Relief](#-plotrelief) *relief*  
  [-relief, relief, Relief](#-relief) *relief*  
  [-rightmargin or -rm, rightMargin, Margin](#-rightmargin) *pixels*  
  [-rightvariable, rightVariable, RightVariable](#-rightvariable)  
  [-shadow, shadow, Shadow](#-shadow)  
  [-style, style, Style](#-style) *line|bar|strip*  
  [-takefocus, takeFocus, TakeFocus](#-takefocus)  
  [-tile, tile, Tile](#-tile)  
  [-title, title, Title](#-title) *text|image*  
  [-topmargin or -tm, topMargin, Margin](#-topmargin) *pixels*  
  [-topvariable, topVariable, TopVariable](#-topvariable)  
*   [DESCRIPTION](#DESCRIPTION)  
*   [WIDGET COMMAND](#WIDGET-COMMAND)  
  [*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)  
*   [CREDITS](#CREDITS)  
*   [KEYWORDS](#KEYWORDS)  
*   [COPYRIGHT](#COPYRIGHT)  

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

**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="STANDARD-OPTIONS"></a>
## STANDARD OPTIONS

[-background or -bg, background, Background](options.htm#M-background) This includes the margins and legend, but not the plotting area.  
[-borderwidth or -bd, borderWidth, BorderWidth](options.htm#M-borderwidth)  
[-cursor, cursor, Cursor](options.htm#M-cursor)  
[-foreground or -fg, foreground, Foreground](options.htm#M-foreground)  
[-height, height, Height](options.htm#M-height) The default is 4i.  
[-width, width, Width](options.htm#M-width) The default is 5i.  

See the [options][] manual entry for details on the standard options.

<a name="WIDGET-SPECIFIC-OPTIONS"></a>
## WIDGET-SPECIFIC OPTIONS

<a name="-aspect"></a>
Command-Line Name: **-aspect**  
Database Name: **aspect**  
Database Class: **Aspect**

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

<a name="-barmode"></a>
Command-Line Name: **-barmode**  
Database Name: **barMode**  
Database Class: **BarMode**

<a name="-barwidth"></a>
Command-Line Name: **-barwidth**  
Database Name: **barWidth**  
Database Class: **BarWidth**

<a name="-baseline"></a>
Command-Line Name: **-baseline**  
Database Name: **baseline**  
Database Class: **Baseline**

<a name="-bottommargin"></a>
Command-Line Name: **-bottommargin or -bm**  
Database Name: **bottomMargin**  
Database Class: **Margin**

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

<a name="-bottomvariable"></a>
Command-Line Name: **-bottomvariable**  
Database Name: **bottomVariable**  
Database Class: **BottomVariable**

<a name="-bufferelements"></a>
Command-Line Name: **-bufferelements**  
Database Name: **bufferElements**  
Database Class: **BufferElements**

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

<a name="-buffergraph"></a>
Command-Line Name: **-buffergraph**  
Database Name: **bufferGraph**  
Database Class: **BufferGraph**

<a name="-class"></a>
Command-Line Name: **-class**  
Database Name: **class**  
Database Class: **Class**

> > Define class for use in getting values from option database.

<a name="-font"></a>
Command-Line Name: **-font**  
Database Name: **font**  
Database Class: **Font**

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

<a name="-halo"></a>
Command-Line Name: **-halo**  
Database Name: **halo**  
Database Class: **Halo**

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

<a name="-highlightbackground"></a>
Command-Line Name: **-highlightbackground**  
Database Name: **highlightBackground**  
Database Class: **HighlightBackground**

<a name="-highlightcolor"></a>
Command-Line Name: **-highlightcolor**  
Database Name: **highlightColor**  
Database Class: **HighlightColor**

<a name="-highlightthickness"></a>
Command-Line Name: **-highlightthickness**  
Database Name: **highlightThickness**  
Database Class: **HighlightThickness**

<a name="-invertxy"></a>
Command-Line Name: **-invertxy**  
Database Name: **invertXY**  
Database Class: **InvertXY**

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

<a name="-justify"></a>
Command-Line Name: **-justify**  
Database Name: **justify**  
Database Class: **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.

<a name="-leftmargin"></a>
Command-Line Name: **-leftmargin or -lm**  
Database Name: **leftMargin**  
Database Class: **Margin**

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

<a name="-leftvariable"></a>
Command-Line Name: **-leftvariable**  
Database Name: **leftVariable**  
Database Class: **LeftVariable**

<a name="-plotbackground"></a>
Command-Line Name: **-plotbackground**  
Database Name: **plotBackground**  
Database Class: **Background**

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

<a name="-plotborderwidth"></a>
Command-Line Name: **-plotborderwidth**  
Database Name: **plotBorderWidth**  
Database Class: **BorderWidth**

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

<a name="-plotpadx"></a>
Command-Line Name: **-plotpadx**  
Database Name: **plotPadX**  
Database Class: **PlotPad**


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

<a name="-plotpady"></a>
Command-Line Name: **-plotpady**  
Database Name: **plotPadY**  
Database Class: **PlotPad**

> > 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**
<a name="-plotrelief"></a>
Command-Line Name: **-plotrelief**  
Database Name: **plotRelief**  
Database Class: **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*
<a name="-relief"></a>
Command-Line Name: **-relief**  
Database Name: **relief**  
Database Class: **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.

<a name="-rightmargin"></a>
Command-Line Name: **-rightmargin**  
Database Name: **rightMargin**  
Database Class: **Margin**

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

<a name="-rightvariable"></a>
Command-Line Name: **-rightvariable**  
Database Name: **rightVariable**  
Database Class: **RightVariable**

<a name="-shadow"></a>
Command-Line Name: **-shadow**  
Database Name: **shadow**  
Database Class: **Shadow**

<a name="-style"></a>
Command-Line Name: **-style**  
Database Name: **style**  
Database Class: **Style**

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

> **line**

> > Display X-Y plotchart

> **bar**

> > Display barchart.

> **strip**

> > Display stripchart.

> **-takefocus** *focus*
<a name="-takefocus"></a>
Command-Line Name: **-takefocus**  
Database Name: **takeFocus**  
Database Class: **TakeFocus**

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

<a name="-tile"></a>
Command-Line Name: **-tile**  
Database Name: **tile**  
Database Class: **Title**

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

> **text**

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

<a name="-topmargin"></a>
Command-Line Name: **-topmargin**  
Database Name: **topMargin**  
Database Class: **Margin**

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

<a name="-topvariable"></a>
Command-Line Name: **-topvariable**  
Database Name: **topVariable**  
Database Class: **TopVariable**

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

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. They allow you to customize the look and feel of the graph.

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="WIDGET-COMMAND"></a>
## WIDGET COMMAND

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

> Query or modify the configuration options of the widget. If no *option* is specified, returns a list describing all of the available options for pathName (see [Tk_ConfigureInfo][] for information on the format of this list). If *option* is specified with no *value*, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more *option-value* pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. *Option* may have any of the values accepted by the **graph** command. 

<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="CREDITS"></a>
## CREDITS

[BLT][] was originally develeoped by George A. Howlett. It can be found at <https://sourceforge.net/projects/blt/>.

Refactored [BLT][] Components ([Rbc][]), includes data vectors and graph widgets from the original [BLT][]. Both can be found at sourceforge.

User visible changes to the original [Rbc][] code are:

- widget name is **graph**
- new **-style** *line|bar|strip* option instead of three different commands **graph**, **barchart** and **stripchart**
- no unique abbreviations of widget commands

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

graph, widget

<a name="COPYRIGHT"></a>:1

## COPYRIGHT

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

&copy; 2001 George A. Howlett.

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

[BLT]: <https://sourceforge.net/projects/blt/>
[Rbc]: <https://sourceforge.net/projects/rbctoolkit/>

Added doc/path.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
# path(n) -- 2D canvas widget

*   [SYNOPSIS](#SYNOPSIS)
*   [STANDARD OPTIONS](#STANDARD-OPTIONS)  
  [-background or -bg, background, Background](options.htm#M-background)   
  [-borderwidth or -bd, borderWidth, BorderWidth](options.htm#M-borderwidth)  
  [-cursor, cursor, Cursor](options.htm#M-cursor)  
  [-highlightbackground, highlightBackground, HighlightBackground](options.htm#M-highlightbackground)  
  [-highlightcolor, highlightColor, HighlightColor](options.htm#M-highlightcolor)  
  [-highlightthickness, highlightThickness, HighlightThickness](options.htm#M-highlightthickness)  
  [-insertbackground, insertBackground, Foreground](options.htm#M-insertbackground)  
  [-insertborderwidth, insertBorderWidth, BorderWidth](options.htm#M-insertborderwidth)  
  [-insertofftime, insertOffTime, OffTime](options.htm#M-insertofftime)  
  [-insertontime, insertOnTime, OnTime](options.htm#M-insertontime)  
  [-insertwidth, insertWidth, InsertWidth](options.htm#M-insertwidth)  
  [-relief, relief, Relief](options.htm#M-relief)  
  [-selectbackground, selectBackground, Foreground](options.htm#M-selectbackground)  
  [-selectborderwidth, selectBorderWidth, BorderWidth](options.htm#M-selectborderwidth)  
  [-selectforeground, selectForeground, Background](options.htm#M-selectforeground)  
  [-takefocus, takeFocus, TakeFocus](options.htm#M-takefocus)  
  [-xscrollcommand, xScrollCommand, ScrollCommand](options.htm#M-xscrollcommand)  
  [-yscrollcommand, yScrollCommand, ScrollCommand](options.htm#M-yscrollcommand)  
* [WIDGET-SPECIFIC OPTIONS](#WIDGET-SPECIFIC-OPTIONS)  
  [-class, class, Class](#-class)  
  [-closeenough, closeEnough, CloseEnough](#-closeenough)  
  [-confine, confine, Confine](#-confine)  
  [-height, height, Height](#-height)  
  [-offset, offset, Offset](#-offset)  
  [-scrollregion, scrollRegion, ScrollRegion](#-scrollregion)  
  [-state, state, State](#-state)  
  [-tagstyle, tagstyle, Tagstyle](#-tagstyle)  
  [-width, width, Width](#-width)  
  [-xscrollincrement, xScrollIncrement, ScrollIncrement](#-xscrollincrement)  
  [-yscrollincrement, yScrollIncrement, ScrollIncrement](#-yscrollincrement)  
*   [DESCRIPTION](#DESCRIPTION)  
  * [DISPLAY LIST](#DISPLAY-LIST)  
  * [ITEM IDS AND TAGS](#ITEM-IDS-AND-TAGS)  
  * [COORDINATES](#COORDINATES)  
  * [TEXT INDICES](#TEXT-INDICES)  
  * [TRANSFORMATIONS](#TRANSFORMATIONS)    
  [**path::matrix rotate**](#path::matrix-rotate) *angle ?cx? ?cy?*  
  [**path::matrix scale**](#path::matrix-scale) *sx ?sy?*  
  [**path::matrix flip**](#path::matrix-flip) *?cx? ?cy? ?fx? ?fy?*  
  [**path::matrix rotateflip**](#path::matrix-rotateflip) *?angle? ?cx? ?cy? ?fx? ?fy?*  
  [**path::matrix skewx**](#path::matrix-skewx) *?angle?*  
  [**path::matrix skewy**](#path::matrix-skewy) *?angle?*  
  [**path::matrix move**](#path::matrix-move) *dx dy*  
  [**path::matrix mult**](#path::matrix-mult) *ma mb*  
  * [STYLES](#STYLES)  
  [**path::style cget**](#path::style-cget) *token option*  
  [**path::style configure**](#path::style-configure) *token ?option? ?value option value...?*  
  [**path::style create**](#path::style-create) *?fillOptions strokeOptions?*  
  [**path::style delete**](#path::style-delete) *token*  
  [**path::style inuse**](#path::style-inuse) *token*  
  [**path::style names**](#path::style-names)  
  * [GRADIENTS](#GRADIENTS)  
  [**path::gradient cget**](#path::gradient-cget) *token option*  
  [**path::gradient configure**](#path::gradient-configure) *token ?option? ?value option value...?*  
  [**path::gradient create**](#path::gradient-create) *type ?-key value ...?*  
  [**path::gradient delete**](#path::gradient-delete) *token*  
  [**path::gradient inuse**](#path::gradient-inuse) *token*  
  [**path::gradient names**](#path::gradient-names)  
  [**path::gradient type**](#path::gradient-type) *token*  
  * [SURFACE](#SURFACE)  
  [**path::surface names**](#path::surface-names)  
  [**path::surface new**](#path::surface-new) *width height*  
*   [WIDGET COMMAND](#WIDGET-COMMAND)  
  [*pathName* **addtag**](#pathName-addtag) *tag searchSpec ?arg arg ...?*  
  [*pathName* **ancestors**](#pathName-ancestors) *tagOrId*  
  [*pathName* **bind**](#pathName-bind) *tagOrId ?sequence? ?command?*  
  [*pathName* **canvasy**](#pathName-canvasy) *screeny ?gridspacing?*  
  [*pathName* **cget**](#pathName-cget) *option*  
  [*pathName* **children**](#pathName-children) *tagOrId*  
  [*pathName* **configure**](#pathName-configure) *?option? ?value? ?option value ...?*  
  [*pathName* **coords**](#pathName-coords) *tagOrId ?x0 y0 ...?*  
  [*pathName* **create**](#pathName-create) *type x y ?x y ...? ?option value ...?*  
  [*pathName* **dchars**](#pathName-dchars) *tagOrId first ?last?*  
  [*pathName* **delete**](#pathName-delete) *?*tagOrId* *tagOrId* ...?*  
  [*pathName* **depth**](#pathName-depth) *tagOrId*  
  [*pathName* **distance**](#pathName-distance) *tagOrId x y*  
  [*pathName* **dtag**](#pathName-dtag) *tagOrId ?tagToDelete?*  
  [*pathName* **find**](#pathName-find) *searchCommand ?arg arg ...?*  
  [*pathName* **firstchild**](#pathName-firstchild) *tagOrId*  
  [*pathName* **focus**](#pathName-focus) *?*tagOrId*?*  
  [*pathName* **gettags**](#pathName-gettags) *tagOrId*  
  [*pathName* **gradient**](#pathName-gradient) *command ?options?*  
  [*pathName* **icursor**](#pathName-icursor) *tagOrId index*   
  [*pathName* **imove**](#pathName-imove) *tagOrId index x y*  
  [*pathName* **index**](#pathName-index) *tagOrId index*  
  [*pathName* **insert**](#pathName-insert) *tagOrId beforeThis string*  
  [*pathName* **itemcget**](#pathName-itemcget) *tagOrId option*  
  [*pathName* **itemconfigure**](#pathName-itemconfigure) *tagOrId ?option? ?value? ?option value ...?*  
  [*pathName* **itempdf**](#pathName-itempdf) *tagOrId ?extgsProc objProc gradProc?*  
  [*pathName* **lastchild**](#pathName-lastchild) *tagOrId*  
  [*pathName* **lower**](#pathName-lower) *tagOrId ?belowThis?*  
  [*pathName* **move**](#pathName-move) *tagOrId xAmount yAmount*  
  [*pathName* **moveto**](#pathName-moveto) *tagOrId xPos yPos*  
  [*pathName* **nextsibling**](#pathName-nextsibling) *tagOrId*  
  [*pathName* **parent**](#pathName-parent) *tagOrId*  
  [*pathName* **prevsibling**](#pathName-prevsibling) *tagOrId*  
  [*pathName* **raise**](#pathName-raise) *tagOrId ?aboveThis?*  
  [*pathName* **rchars**](#pathName-rchars) *tagOrId first last string*  
  [*pathName* **scale**](#pathName-scale) *tagOrId xOrigin yOrigin xScale yScale*  
  [*pathName* **scan**](#pathName-scan) *option args*  
  [*pathName* **select**](#pathName-select) *option ?*tagOrId* arg?*  
  [*pathName* **style**](#pathName-style) *cmd ?options?*  
  [*pathName* **type**](#pathName-type) *tagOrId*  
  [*pathName* **types**](#pathName-types)  
  [*pathName* **xview**](#pathName-xview) *?args?*  
  [*pathName* **yview**](#pathName-yview) *?args?*  
*   [ITEM TYPES](#ITEM-TYPES)  
  * [COMMON ITEM OPTIONS](#COMMON-ITEM-OPTIONS)  
  [**-fill** *color\|gradientToken*](#ITEM-fill)  
  [**-fillopacity** *value*](#ITEM-fillopacity)  
  [**-fillrule** *nonzero\|evenodd*](#ITEM-fillrule)  
  [**-stroke** *color*](#ITEM-stroke)  
  [**-strokedasharray** *dashArray*](#ITEM-strokedasharray)  
  [**-strokelinecap** *butt\|round\|square*](#ITEM-strokelinecap)  
  [**-strokelinejoin** *miter\|round\|bevel*](#ITEM-strokelinejoin)  
  [**-strokemiterlimit** *float*](#ITEM-strokemiterlimit)  
  [**-strokeopacity** *value*](#ITEM-strokeopacity)  
  [**-strokewidth** *float*](#ITEM-strokewidth)  
  [**-matrix** *{a b c d tx ty}*](#ITEM-matrix)  
  [**-parent** *tagOrId*](#ITEM-parent)  
  [**-state** *active\|disabled\|normal\|hidden*](#ITEM-state)  
  [**-style** *styleToken*](#ITEM-style)  
  [**-tags** *tagList*](#ITEM-tags)  
  [**-startarrow** *boolean*](#ITEM-startarrow)  
  [**-startarrowlength** *float*](#ITEM-startarrowlength)  
  [**-startarrowwidth** *float*](#ITEM-startarrowwidth)  
  [**-startarrowfill** *float*](#ITEM-startarrowfill)  
  [**-endarrow** *boolean*](#ITEM-endarrow)  
  [**-endarrowlength** *float*](#ITEM-endarrowlength)  
  [**-endarrowwidth** *float*](#ITEM-endarrowwidth)  
  [**-endarrowfill** *float*](#ITEM-endarrowfill)  
  * [GROUP ITEM](#GROUP-ITEM)  
  [*pathName* **create group**](#pathName-create-group) *?fillOptions strokeOptions genericOptions?*  
  * [PATH ITEMS](#PATH-ITEM)  
  [*pathName* **create path**](#pathName-create-path) *pathSpec ?fillOptions strokeOptions arrowOptions genericOptions?*  
  * [LINE ITEM](#LINE-ITEM)  
  [*pathName* **create line**](#pathName-create-line) *x1 y1 x2 y2 ?strokeOptions arrowOptions genericOptions?*  
  * [POLYLINE ITEM](#POLYLINE-ITEM)  
  [*pathName* **create polyline**](#pathName-create-polyline) *x1 y1 x2 y2 .... ?strokeOptions arrowOptions genericOptions?*  
  * [POLYGON ITEM](#POLYGON-ITEM)  
  [*pathName* **create polygon**](#pathName-create-polygon) *x1 y1 x2 y2 .... ?fillOptions strokeOptions genericOptions?*  
  * [RECT ITEM](#RECT-ITEM)  
  [*pathName* **create rect**](#pathName-create-rect) *x1 y1 x2 y2 ?-rx value? ?-ry value? ?fillOptions strokeOptions genericOptions?*  
  * [CIRCLE ITEM](#CIRCLE-ITEM)  
  [*pathName* **create circle**](#pathName-create-circle) *cx cy ?-r fillOptions strokeOptions genericOptions?*  
  * [ELLIPSE ITEM](#ELLIPSE-ITEM)  
  [*pathName* **create ellipse**](#pathName-create-ellipse) *cx cy ?-rx value? ?-ry value? ?fillOptions strokeOptions genericOptions?*  
  * [IMAGE ITEM](#IMAGE-ITEM)  
  [*pathName* **create image**](#pathName-create-image) *x y ?-image -width -height genericOptions?*  
  * [TEXT ITEM](#TEXT-ITEM)  
  [*pathName* **create text**](#pathName-create-text) *x y ?-text string? ?-textanchor start\|middle\|end\|n\|w\|s\|e\|nw\|ne\|sw\|se\|c? ?-fontfamily fontname -fontsize float? ?-fontslant normal\|italic\|oblique? ?-fontweight normal\|bold? ?fillOptions strokeOptions genericOptions? ?-filloverstroke BOOLEAN?*  
  * [WINDOW ITEM](#WINDOW-ITEM)  
  [*pathName* **create window**](#pathName-create-window) *x y ?option value ...?*  
*   [CREDITS](#CREDITS)  
*   [KEYWORDS](#KEYWORDS)  
*   [COPYRIGHT](#COPYRIGHT)  

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

**path** *pathName ?options?*

The **path** command creates a new Tcl command whose name is *pathName*. This command may be used to invoke various operations on the widget.

<a name="STANDARD-OPTIONS"></a>
## STANDARD OPTIONS

[-background or -bg, background, Background](options.htm#M-background)  
[-borderwidth or -bd, borderWidth, BorderWidth](options.htm#M-borderwidth)  
[-cursor, cursor, Cursor](options.htm#M-cursor)  
[-highlightbackground, highlightBackground, HighlightBackground](options.htm#M-highlightbackground)  
[-highlightcolor, highlightColor, HighlightColor](options.htm#M-highlightcolor)  
[-highlightthickness, highlightThickness, HighlightThickness](options.htm#M-highlightthickness)  
[-insertbackground, insertBackground, Foreground](options.htm#M-insertbackground)  
[-insertborderwidth, insertBorderWidth, BorderWidth](options.htm#M-insertborderwidth)  
[-insertofftime, insertOffTime, OffTime](options.htm#M-insertofftime)  
[-insertontime, insertOnTime, OnTime](options.htm#M-insertontime)  
[-insertwidth, insertWidth, InsertWidth](options.htm#M-insertwidth)  
[-relief, relief, Relief](options.htm#M-relief)  
[-selectbackground, selectBackground, Foreground](options.htm#M-selectbackground)  
[-selectborderwidth, selectBorderWidth, BorderWidth](options.htm#M-selectborderwidth)  
[-selectforeground, selectForeground, Background](options.htm#M-selectforeground)  
[-takefocus, takeFocus, TakeFocus](options.htm#M-takefocus)  
[-xscrollcommand, xScrollCommand, ScrollCommand](options.htm#M-xscrollcommand)  
[-yscrollcommand, yScrollCommand, ScrollCommand](options.htm#M-yscrollcommand)  

See the [options][] manual entry for details on the standard options.

<a name="WIDGET-SPECIFIC-OPTIONS"></a>
## WIDGET-SPECIFIC OPTIONS

<a name="-class"></a>
Command-Line Name: **-class**  
Database Name: **class**  
Database Class: **Class**

> > Define class for use in getting values from option database.

<a name="-closeenough"></a>
Command-Line Name: **-closeenough**  
Database Name: **closeEnough**  
Database Class: **CloseEnough**

> Specifies a floating-point value indicating how close the mouse cursor must be to an item before it is considered to be "inside" the item. Defaults to 1.0. 

<a name="-confine"></a>
Command-Line Name: **-confine**  
Database Name: **confine**  
Database Class: **Confine**

> Specifies a boolean value that indicates whether or not it should be allowable to set the canvas's view outside the region defined by the **scrollRegion** argument. Defaults to true, which means that the view will be constrained within the scroll region. 

<a name="-height"></a>
Command-Line Name: **-height**  
Database Name: **height**  
Database Class: **Height**

> Specifies a desired window height that the canvas widget should request from its geometry manager. The value may be specified in any of the forms described in the [COORDINATES][] section below. 

<a name="-offset"></a>
Command-Line Name: **-offset**  
Database Name: **offset**  
Database Class: **Offset**

> Stipple offset for outline. 

<a name="-scrollregion"></a>
Command-Line Name: **-scrollregion**  
Database Name: **scrollRegion**  
Database Class: **ScrollRegion**

> Specifies a list with four coordinates describing the left, top, right, and bottom coordinates of a rectangular region. This region is used for scrolling purposes and is considered to be the boundary of the information in the canvas. Each of the coordinates may be specified in any of the forms given in the [COORDINATES][] section below. 

<a name="-state"></a>
Command-Line Name: **-state**  
Database Name: **state**  
Database Class: **State**

> Modifies the default state of the canvas where state may be set to one of: **normal**, **disabled**, or **hidden**. Individual canvas objects all have their own state option which may override the default state. Many options can take separate specifications such that the appearance of the item can be different in different situations. The options that start with **active** control the appearance when the mouse pointer is over it, while the option starting with **disabled** controls the appearance when the state is disabled. Canvas items which are **disabled** will not react to canvas bindings. 

<a name="-tagstyle"></a>
Command-Line Name: **-tagstyle**  
Database Name: **tagstyle**  
Database Class: **Tagstyle**

> Define working with tags. Possible values are *expr\|exact\|glob*. Default is *expr*. TODO

<a name="-width"></a>
Command-Line Name: **-width**  
Database Name: **width**  
Database Class: **Width**

> Specifies a desired window width that the canvas widget should request from its geometry manager. The value may be specified in any of the forms described in the [COORDINATES][] section below. 

<a name="-xscrollincrement"></a>
Command-Line Name: **-xscrollincrement**  
Database Name: **xScrollIncrement**  
Database Class: **ScrollIncrement**

> Specifies an increment for horizontal scrolling, in any of the usual forms permitted for screen distances. If the value of this option is greater than zero, the horizontal view in the window will be constrained so that the canvas x coordinate at the left edge of the window is always an even multiple of **xScrollIncrement**; furthermore, the units for scrolling (e.g., the change in view when the left and right arrows of a scrollbar are selected) will also be **xScrollIncrement**. If the value of this option is less than or equal to zero, then horizontal scrolling is unconstrained. 

<a name="-yscrollincrement"></a>
Command-Line Name: **-yscrollincrement**  
Database Name: **yScrollIncrement**  
Database Class: **ScrollIncrement**

> Specifies an increment for vertical scrolling, in any of the usual forms permitted for screen distances. If the value of this option is greater than zero, the vertical view in the window will be constrained so that the canvas y coordinate at the top edge of the window is always an even multiple of **yScrollIncrement**; furthermore, the units for scrolling (e.g., the change in view when the top and bottom arrows of a scrollbar are selected) will also be **yScrollIncrement**. If the value of this option is less than or equal to zero, then vertical scrolling is unconstrained. 

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

The **path** command creates a new window (given by the pathName argument) and makes it into a canvas widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the canvas such as its colors and 3-D relief. The **path** command returns its pathName argument. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist.

Canvas widgets implement structured graphics. A canvas displays any number of items, which may be things like rectangles, circles, lines, and text. Items may be manipulated (e.g. moved or re-colored) and commands may be associated with items in much the same way that the [bind][] command allows commands to be bound to widgets. For example, a particular command may be associated with the <Button-1> event so that the command is invoked whenever button 1 is pressed with the mouse cursor over an item. This means that items in a canvas can have behaviors defined by the Tcl scripts bound to them. 

This widget implements a canvas widget which is modelled after its [SVG][] counterpart. Items are put in a tree structure with a persistent root item with id 0. All other items are descendants of this root item. The path items, described below, are by default a child of the root item, but can be configured to be a child of any group item using the -parent option.

<a name="DISPLAY-LIST"></a>
### DISPLAY LIST

The items in a canvas are ordered for purposes of display, with the first item in the display list being displayed first, followed by the next item in the list, and so on. Items later in the display list obscure those that are earlier in the display list and are sometimes referred to as being "on top" of earlier items. When a new item is created it is placed at the end of the display list, on top of everything else. Widget commands may be used to re-arrange the order of the display list.

Window items are an exception to the above rules. The underlying window systems require them always to be drawn on top of other items. In addition, the stacking order of window items is not affected by any of the canvas widget commands; you must use the Tk [raise][] command and [lower][] command instead. 

Items can be structured using groups.

A group item is merely a placeholder for other items, similar to how a frame widget is a container for other widgets. It is a building block for the tree structure. Unlike other items, and unlike frame widgets, it doesn't display anything. It has no coordinates which is an additional difference. The root item is a special group item with id 0 and tags equal to "root". The root group can be configured like other items, but its -tags and -parent options are read only. Group items define the canvas tree structure:

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

Antialiasing, if available, is controlled by the variable **path::antialias**. To switch on set it to 1.

<a name="ITEM-IDS-AND-TAGS"></a>
### ITEM IDS AND TAGS

Items in a canvas widget may be named in either of two ways: by id or by tag. Each item has a unique identifying number, which is assigned to that item when it is created. The id of an item never changes and id numbers are never re-used within the lifetime of a canvas widget. 
Each item may also have any number of tags associated with it. A tag is just a string of characters, and it may take any form except that of an integer. For example, "x123" is OK but "123" is not. The same tag may be associated with many different items. This is commonly done to group items in various interesting ways; for example, all selected items might be given the tag "selected". 

The tag **all** is implicitly associated with every item in the canvas; it may be used to invoke operations on all the items in the canvas. Note that this presently also includes the root item which can result in some unexpected behavior. In many case you can operate on the root item (0) instead. As an example, if you want to move, scale etc. all items in canvas, then do:

> <code>
    pathName move 0 x y  
</code>

The tag **current** is managed automatically by Tk; it applies to the current item, which is the topmost item whose drawn area covers the position of the mouse cursor (different item types interpret this in varying ways; see the individual item type documentation for details). If the mouse is not in the canvas widget or is not over an item, then no item has the **current** tag. 

When specifying items in canvas widget commands, if the specifier is an integer then it is assumed to refer to the single item with that id. If the specifier is not an integer, then it is assumed to refer to all of the items in the canvas that have a tag matching the specifier. The symbol *tagOrId* is used below to indicate that an argument specifies either an id that selects a single item or a tag that selects zero or more items. 

*tagOrId* may contain a logical expressions of tags by using operators: "**&&**", "**\|\|**", "**^**", "**!**", and parenthesized subexpressions. For example: 

> <code>
    .c find withtag {(a&&!b)||(!a&&b)}  
</code>

or equivalently:
 
> <code>
    .c find withtag {a^b}  
</code>

will find only those items with either "a" or "b" tags, but not both. 

Some widget commands only operate on a single item at a time; if *tagOrId* is specified in a way that names multiple items, then the normal behavior is for the command to use the first (lowest) of these items in the display list that is suitable for the command. Exceptions are noted in the widget command descriptions below. 

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

All coordinates related to canvases are stored as floating-point numbers. Coordinates and distances are specified in screen units, which are floating-point numbers optionally followed by one of several letters. If no letter is supplied then the distance is in pixels. If the letter is **m** then the distance is in millimeters on the screen; if it is **c** then the distance is in centimeters; **i** means inches, and **p** means printers points (1/72 inch). Larger y-coordinates refer to points lower on the screen; larger x-coordinates refer to points farther to the right. Coordinates can be specified either as an even number of parameters, or as a single list parameter containing an even number of x and y coordinate values. 

The command **path::pixelalign** says how the platform graphics library draw when we specify integer coordinates. Some libraries position a one pixel wide line exactly at the pixel boundaries, and smears it out, if antialiasing, over the adjecent pixels. This can look blurred since a one pixel wide black line suddenly becomes a two pixel wide grey line.  It seems that cairo and quartz (MacOSX) do this, while gdi+ on Windows doesn't. This command just provides the info for you so you may take actions. Either you can manually position lines with odd integer widths at the center of pixels (adding 0.5), or set the **path::depixelize** equal to 1, see below.

With the boolean variable **path::depixelize** equal to 1 we try to adjust coordinates for objects with integer line widths.

There can be subtle differences compared to the original canvas. One such situation is where an option value has switched from an integer to float (double).

<a name="TEXT-INDICES"></a>
### TEXT INDICES

Text items support the notion of an index for identifying particular positions within the item. In a similar fashion, line and polygon items support index for identifying, inserting and deleting subsets of their coordinates. Indices are used for commands such as inserting or deleting a range of characters or coordinates, and setting the insertion cursor position. An index may be specified in any of a number of ways, and different types of items may support different forms for specifying indices. Text items support the following forms for an index; if you define new types of text-like items, it would be advisable to support as many of these forms as practical. Note that it is possible to refer to the character just after the last one in the text item; this is necessary for such tasks as inserting new text at the end of the item. Lines and Polygons do not support the insertion cursor and the selection. Their indices are supposed to be even always, because coordinates always appear in pairs. 

*number*

> A decimal number giving the position of the desired character within the text item. 0 refers to the first character, 1 to the next character, and so on. If indexes are odd for lines and polygons, they will be automatically decremented by one. A number less than 0 is treated as if it were zero, and a number greater than the length of the text item is treated as if it were equal to the length of the text item. For polygons, numbers less than 0 or greater then the length of the coordinate list will be adjusted by adding or subtracting the length until the result is between zero and the length, inclusive. 

**end**

> Refers to the character or coordinate just after the last one in the item (same as the number of characters or coordinates in the item). 

**insert**

> Refers to the character just before which the insertion cursor is drawn in this item. Not valid for lines and polygons. 

**sel.first**

> Refers to the first selected character in the item. If the selection is not in this item then this form is illegal. 

**sel.last**

> Refers to the last selected character in the item. If the selection is not in this item then this form is illegal. 

*@x,y*

> Refers to the character or coordinate at the point given by x and y, where x and y are specified in the coordinate system of the canvas. If x and y lie outside the coordinates covered by the text item, then they refer to the first or last character in the line that is closest to the given point. 

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

Normally the origin of the canvas coordinate system is at the upper-left corner of the window containing the canvas. It is possible to adjust the origin of the canvas coordinate system relative to the origin of the window using the **xview** and **yview** widget commands; this is typically used for scrolling. Canvases do not support scaling or rotation of the canvas coordinate system relative to the window coordinate system. 
Individual items may be moved or scaled using widget commands described below, but they may not be rotated. 

Note that the default origin of the canvas's visible area is coincident with the origin for the whole window as that makes bindings using the mouse position easier to work with; you only need to use the **canvasx** and **canvasy** widget commands if you adjust the origin of the visible area. However, this also means that any focus ring (as controlled by the **-highlightthickness** option) and window border (as controlled by the **-borderwidth** option) must be taken into account before you get to the visible area of the canvas. 

Each path item has a **-matrix** option which defines the local coordinate system for that item. It is defined as a double list {a b c d tx ty} where a simple scaling is {sx 0 0 sy 0 0}, a translation {1 0 0 1 tx ty}, and a rotation around origin with an angle 'a' is {cos(a) sin(a) -sin(a) cos(a) 0 0}. The simplest way to interpret this is to design an extra coordinate system according to the matrix, and then draw the item in that system.

Inheritance works differently for the **-matrix** option than for the other options which are just overwritten. Instead any set -matrix option starting from the root, via any number of group items, to the actual item being displayed, are nested. That is, any defined matrices from the root down define a sequence of coordinate transformations.

The following functions provide some basic matrix operations such as rotation, translation etc.. All function return a matrix which can be used as value for the *-matrix* option.


<a name="path::matrix-rotate"></a>
**path::matrix rotate** *angle ?cx? ?cy?*

> Return matrix with rotation of *angle* around *cx, cy*.

<a name="path::matrix-scale"></a>
**path::matrix scale** *sx ?sy?*

> Return scaling matrix. If *sy* is not provided use *sx* for x and y direction.

<a name="path::matrix-flip"></a>
**path::matrix flip** *?cx? ?cy? ?fx? ?fy?*

> Return matrix with translation of *cx, cy* and flip with *fx* and *fy*.

<a name="path::matrix-rotateflip"></a>
**path::matrix rotateflip** *?angle? ?cx? ?cy? ?fx? ?fy?*

> Return matrix with rotation of *angle* around *cx, cy* and flip with *fx* and *fy*.

<a name="path::matrix-skewx"></a>
**path::matrix skewx** *?angle?*

> Return matrix with skew in x-direction of *angle*

<a name="path::matrix-skewy"></a>
**path::matrix skewy** *?angle?*

> Return matrix with skew in y-direction of *angle*

<a name="path::matrix-move"></a>
**path::matrix move** *dx dy*

> Return matrix with translation of *dx* in x-direction and *dy* in y-direction.

<a name="path::matrix-mult"></a>
**path::matrix mult** *ma mb*

> Return product of matrix multiplication of *ma* and *mb*.

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

Styles are created and configured using:

> <code>
    path::style command ?options?  
</code>

<a name="path::style-cget"></a>
**path::style cget** *token option*

> Returns the value of an option.

<a name="path::style-configure"></a>
**path::style configure** *token ?option? ?value option value...?*

> Configures the object in the usual tcl way.

<a name="path::style-create"></a>
**path::style create** *?fillOptions strokeOptions?*

> Creates a style object and returns its token.

<a name="path::style-delete"></a>
**path::style delete** *token*

> Deletes the object.

<a name="path::style-inuse"></a>
**path::style inuse** *token*

> If any item is configured with the style token 1 is returned, else 0.

<a name="path::style-names"></a>
**path::style names**

> Returns all existing tokens.

The same options as for the item are supported with the exception of **-style**, **-state**, and **-tags**.

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

Gradients are created and configured using:

> <code>
    path::gradient command ?options?  
</code>

<a name="path::gradient-cget"></a>
**path::gradient cget** *token option*

> Returns the value of an option.

<a name="path::gradient-configure"></a>
**path::gradient configure** *token ?option? ?value option value...?*

> Configures the object in the usual tcl way.

<a name="path::gradient-create"></a>
**path::gradient create** *type ?-key value ...?*

> Creates a linear gradient object with type any of linear or radial and returns its token.

<a name="path::gradient-delete"></a>
**path::gradient delete** *token*

> Deletes the object.

<a name="path::gradient-inuse"></a>
**path::gradient inuse** *token*

> If any item is configured with the gradient token 1 is returned, else 0.

<a name="path::gradient-names"></a>
**path::gradient names**

> Returns all existing tokens.

<a name="path::gradient-type"></a>
**path::gradient type** *token*

> Returns the type (linear\|radial) of the gradient. The options for linear gradients are:

> **-method** pad\|repeat\|reflect

> > Partial implementation; defaults to pad

> **-stops** *{stopSpec ?stopSpec...?}*

> > Where *stopSpec* is a list {offset color ?opacity?}. All offsets must be ordered and run from 0 to 1.

> **-lineartransition** *{x1 y1 x2 y2}*

> > Specifies the transtion vector relative the items bounding box. Depending on **-units** it gets interpreted differently. If **-units** is 'bbox' coordinates run from 0 to 1 and are relative the items bounding box. If **-units** is 'userspace' then they are defined in absolute coordinates but in the space of the items coordinate system. It defaults to {0 0 1 0}, left to right.

> **-matrix** *{a b c d tx ty}*

> > Sets a specific transformation for the gradient pattern only. NB: not sure about the order transforms, see **-units**.

> **-units** bbox\|userspace

> > Sets the units of the transition coordinates. See above. Defaults to 'bbox'.

The options for radial gradients are the same as for linear gradients except that the **-lineartransition** is replaced by a **-radialtransition**:

> **-radialtransition** *{cx cy ?r? ?fx fy?}*

> > Specifies the transition circles relative the items bounding box and run from 0 to 1. They default to {0.5 0.5 0.5 0.5 0.5}. *cx,cy* is the center of the end circle and *fx,fy* the center of the start point.

> **path::gradientstopstyle** *name args*

> Currently is only 'rainbow' as name supported. The function illustrate the  definition of gradients.

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

In memory drawing surface.

<a name="path::surface-names"></a>
**path::surface names**

> Lists the existing surface tokens.

<a name="path::surface-new"></a>
**path::surface new** *width height*

> Creates an in memory drawing surface. Its format is platform dependent. It returns a *surfaceToken* which is a new command.

The surface token commands are:

> *surfaceToken* **copy** *imageName*

> > Copies the surface to an existing image (photo) and returns the name of
the image so you can do:

> > <code>
    set image [$token copy [image create photo]]  
</code>

> > See [Tk_PhotoPutBlock][] for how it affects the existing image.

> > The boolean variable **path::premultiplyalpha** controls how the copy action handles surfaces with the alpha component premultiplied. If 1 the copy process correctly handles any format with premultiplied alpha. This gets the highest quality for antialiasing and correct results for partial transparency. It is also slower. If 0 the alpha values are not remultiplied and the result is wrong for transparent regions, and gives poor antialiasing effects. But it is faster. The default is 1.

> *surfaceTtoken* **create** *type coords ?options?*

> > Draws the item of type to the surface. All item types except the group and the corresponding options as described above are supported, except the canvas specific **-tags** and **-state**.

> *surfaceToken* **destroy**

> > Destroys surface.

> *surfaceToken* **erase** *x y width height*

> > Erases the indicated area to transparent.

> *surfaceToken* **height**

> > Returns height.

> *surfaceToken* **width**

> > Returns width.

> Note that the surface behaves different from the canvas widget. When you have put an item there there is no way to configure it or to remove it. If you have done a mistake then you have to erase the complete surface and start all over. Better to experiment on the canvas and then reproduce your drawing to a surface when you are satisfied with it.

> NB: gdi+ seems unable to produce antialiasing effects here but there seems to be no gdi+ specific way of drawing in memory bitmaps but had to call CreateDIBSection() which is a Win32 GDI API.

<a name="WIDGET COMMAND"></a>
## WIDGET COMMAND

<a name="pathName-addtag"></a>
*pathName* **addtag** *tag searchSpec ?arg arg ...?*

> For each item that meets the constraints specified by *searchSpec* and the *args*, add *tag* to the list of tags associated with the item if it is not already present on that list. It is possible that no items will satisfy the constraints given by searchSpec and args, in which case the command has no effect. This command returns an empty string as result. *SearchSpec* and *arg'*s may take any of the following forms: 

> **above** *tagOrId*
	
> > Selects the item just after (above) the one given by *tagOrId* in the display list. If *tagOrId* denotes more than one item, then the last (topmost) of these items in the display list is used. The command is constrained to siblings.

> **all**

> > Selects all the items in the canvas. 

> **below** *tagOrId*

> > Selects the item just before (below) the one given by *tagOrId* in the display list. If *tagOrId* denotes more than one item, then the first (lowest) of these items in the display list is used. The command is constrained to siblings.

> **closest** *x y ?halo? ?start?*

> > Selects the item closest to the point given by *x* and *y*. If more than one item is at the same closest distance (e.g. two items overlap the point), then the topmost of these items (the last one in the display list) is used. If *halo* is specified, then it must be a non-negative value. Any item closer than *halo* to the point is considered to overlap it. The *start* argument may be used to step circularly through all the closest items. If *start* is specified, it names an item using a tag or id (if by tag, it selects the first item in the display list with the given tag). Instead of selecting the topmost closest item, this form will select the topmost closest item that is below start in the display list; if no such item exists, then the selection behaves as if the start argument had not been specified. 

> **enclosed** *x1 y1 x2 y2*

> > Selects all the items completely enclosed within the rectangular region given by *x1, y1, x2, and y2*. *X1* must be no greater then *x2* and *y1* must be no greater than *y2*. 

> **overlapping** *x1 y1 x2 y2*

> > Selects all the items that overlap or are enclosed within the rectangular region given by *x1, y1, x2,* and *y2*. *X1* must be no greater then *x2* and *y1* must be no greater than *y2*. 

> **withtag** *tagOrId*

> > Selects all the items given by *tagOrId*. 

<a name="pathName-ancestors"></a>
*pathName* **ancestors** *tagOrId*

> Returns a list of item id's of the first item matching *tagOrId* starting with the root item with id 0.

*pathName* **bbox** *tagOrId ?tagOrId tagOrId ...?*

> Returns a list with four elements giving an approximate bounding box for all the items named by the *tagOrId* arguments. The list has the form *x1 y1 x2 y2* such that the drawn areas of all the named elements are within the region bounded by *x1* on the left, *x2* on the right, *y1* on the top, and *y2* on the bottom. The return value may overestimate the actual bounding box by a few pixels. If no items match any of the *tagOrId* arguments or if the matching items have empty bounding boxes (i.e. they have nothing to display) then an empty string is returned. 

<a name="pathName-bind"></a>
*pathName* **bind** *tagOrId ?sequence? ?command?*

> This command associates *command* with all the items given by *tagOrId* such that whenever the event sequence given by *sequence* occurs for one of the items the command will be invoked. This widget command is similar to the [bind][] command except that it operates on items in a canvas rather than entire widgets. See the [bind][] manual entry for complete details on the syntax of 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 *tagOrId* (if the first character of *command* is “+” then *command* augments an existing binding rather than replacing it). In this case the return value is an empty string. If *command* is omitted then the command returns the *command* associated with *tagOrId* and *sequence* (an error occurs if there is no such binding). If both *command* and *sequence* are omitted then the command returns a list of all the sequences for which bindings have been defined for *tagOrId*. 

> The only events for which bindings may be specified are those related to the mouse and keyboard (such as **Enter**, **Leave**, **ButtonPress**, **Motion**, and **KeyPress**) or virtual events. The handling of events in canvases uses the current item defined in [ITEM IDS AND TAGS][] above. **Enter** and **Leave** events trigger for an item when it becomes the current item or ceases to be the current item; note that these events are different than **Enter** and **Leave** events for windows. Mouse-related events are directed to the current item, if any. Keyboard-related events are directed to the focus item, if any (see the **focus** widget command below for more on this). If a virtual event is used in a binding, that binding can trigger only if the virtual event is defined by an underlying mouse-related or keyboard-related event. 

> It is possible for multiple bindings to match a particular event. This could occur, for example, if one binding is associated with the item's id and another is associated with one of the item's tags. When this occurs, all of the matching bindings are invoked. A binding associated with the **all** tag is invoked first, followed by one binding for each of the item's tags (in order), followed by a binding associated with the item's id. 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. 

> If bindings have been created for a canvas window using the [bind][] command, then they are invoked in addition to bindings created for the canvas's items using the **bind** widget command. The bindings for items will be invoked before any of the bindings for the window as a whole. 

<a name="pathName-canvasx"></a>
*pathName* **canvasx** *screenx ?gridspacing?*

> Given a window x-coordinate in the canvas *screenx*, this command returns the canvas x-coordinate that is displayed at that location. If *gridspacing* is specified, then the canvas coordinate is rounded to the nearest multiple of *gridspacing* units. 

<a name="pathName-canvasy"></a>
*pathName* **canvasy** *screeny ?gridspacing?*

> Given a window y-coordinate in the canvas *screeny*, this command returns the canvas y-coordinate that is displayed at that location. If *gridspacing* is specified, then the canvas coordinate is rounded to the nearest multiple of *gridspacing* units. 

<a name="pathName-cget"></a>
*pathName* **cget** *option*

> Returns the current value of the configuration option given by *option*. *Option* may have any of the values accepted by the **path** command. 

<a name="pathName-children"></a>
*pathName* **children** *tagOrId*

> Lists all children of the first item matching *tagOrId*.

<a name="pathName-configure"></a>
*pathName* **configure** *?option? ?value? ?option value ...?*

> Query or modify the configuration options of the widget. If no *option* is specified, returns a list describing all of the available options for pathName (see [Tk_ConfigureInfo][] for information on the format of this list). If *option* is specified with no *value*, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more *option-value* pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. *Option* may have any of the values accepted by the **path** command. 

<a name="pathName-coords"></a>
*pathName* **coords** *tagOrId ?x0 y0 ...?*

*pathName* **coords** *tagOrId ?coordList?*

> Query or modify the coordinates that define an item. If no coordinates are specified, this command returns a list whose elements are the coordinates of the item named by *tagOrId*. If coordinates are specified, then they replace the current coordinates for the named item. If *tagOrId* refers to multiple items, then the first one in the display list is used. 

<a name="pathName-create"></a>
*pathName* **create** *type x y ?x y ...? ?option value ...?*

*pathName* **create** *type coordList ?option value ...?*

> Create a new item in pathName of type *type*. The exact format of the arguments after type depends on *type*, but usually they consist of the coordinates for one or more points, followed by specifications for zero or more item options. See the subsections on individual item types below for more on the syntax of this command. This command returns the id for the new item. 

> For further informations about useable items see section [ITEM TYPES](#ITEM-TYPES).

<a name="pathName-dchars"></a>
*pathName* **dchars** *tagOrId first ?last?*

> For each item given by *tagOrId*, delete the characters, or coordinates, in the range given by *first* and *last*, inclusive. If some of the items given by *tagOrId* do not support indexing operations then they ignore this operation. Text items interpret *first* and *last* as indices to a character, line and polygon items interpret them as indices to a coordinate (an x,y pair). Indices are described in [INDICES][] above. If *last* is omitted, it defaults to *first*. This command returns an empty string. 

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

> Delete each of the items given by each *tagOrId*, and return an empty string. 

<a name="pathName-depth"></a>
*pathName* **depth** *tagOrId*

> Returns the depth in the tree hierarchy of the first item matching *tagOrId*. The root item has depth 0 and children of the root has depth 1 and so on.

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

> Returns the closest distance between the point (*x, y*) and the first item matching *tagOrId*.

<a name="pathName-dtag"></a>
*pathName* **dtag** *tagOrId ?tagToDelete?*

> For each of the items given by *tagOrId*, delete the tag given by *tagToDelete* from the list of those associated with the item. If an item does not have the tag *tagToDelete* then the item is unaffected by the command. If *tagToDelete* is omitted then it defaults to *tagOrId*. This command returns an empty string. 

<a name="pathName-find"></a>
*pathName* **find** *searchCommand ?arg arg ...?*

> This command returns a list consisting of all the items that meet the constraints specified by *searchCommand* and *arg'*s. *SearchCommand* and *args* have any of the forms accepted by the **addtag** command. The items are returned in stacking order, with the lowest item first. 

<a name="pathName-firstchild"></a>
*pathName* **firstchild** *tagOrId*

> Returns the first child item of the first item matching *tagOrId*. Applies only for groups.

<a name="pathName-focus"></a>
*pathName* **focus** *?*tagOrId*?*

> Set the keyboard focus for the canvas widget to the item given by *tagOrId*. If *tagOrId* refers to several items, then the focus is set to the first such item in the display list that supports the insertion cursor. If *tagOrId* does not refer to any items, or if none of them support the insertion cursor, then the focus is not changed. If *tagOrId* is an empty string, then the focus item is reset so that no item has the focus. If *tagOrId* is not specified then the command returns the id for the item that currently has the focus, or an empty string if no item has the focus. 

> Once the focus has been set to an item, the item will display the insertion cursor and all keyboard events will be directed to that item. The focus item within a canvas and the focus window on the screen (set with the focus command) are totally independent: a given item does not actually have the input focus unless (a) its canvas is the focus window and (b) the item is the focus item within the canvas. In most cases it is advisable to follow the focus widget command with the focus command to set the focus window to the canvas (if it was not there already). 

<a name="pathName-gettags"></a>
*pathName* **gettags** *tagOrId*

> Return a list whose elements are the tags associated with the item given by *tagOrId*. If *tagOrId* refers to more than one item, then the tags are returned from the first such item in the display list. If *tagOrId* does not refer to any items, or if the item contains no tags, then an empty string is returned. 

<a name="pathName-gradient"></a>
*pathName* **gradient** *command ?options?*

> See [GRADIENTS][] for the commands. The gradients created with this command are local to the canvas instance. Only gradients defined this way can be used.

<a name="pathName-icursor"></a>
*pathName* **icursor** *tagOrId index*

> Set the position of the insertion cursor for the item(s) given by *tagOrId* to just before the character whose position is given by *index*. If some or all of the items given by *tagOrId* do not support an insertion cursor then this command has no effect on them. See INDICES above for a description of the legal forms for *index*. Note: the insertion cursor is only displayed in an item if that item currently has the keyboard focus (see the focus widget command, above), but the cursor position may be set even when the item does not have the focus. This command returns an empty string. 

<a name="pathName-imove"></a>
*pathName* **imove** *tagOrId index x y*

> This command causes the *index*'th coordinate of each of the items indicated by *tagOrId* to be relocated to the location (*x,y*). Each item interprets *index *independently according to the rules described in [INDICES][] above. Out of the standard set of items, only line and polygon items may have their coordinates relocated this way. 

> If you apply move on a group item it will apply this to all its descendants, also to child group items in a recursive way.

<a name="pathName-index"></a>
*pathName* **index** *tagOrId index*

> This command returns a decimal string giving the numerical index within *tagOrId* corresponding to *index*. Index gives a textual description of the desired position as described in INDICES above. Text items interpret *index* as an index to a character, line and polygon items interpret it as an index to a coordinate (an x,y pair). The return value is guaranteed to lie between 0 and the number of characters, or coordinates, within the item, inclusive. If *tagOrId* refers to multiple items, then the *index* is processed in the first of these items that supports indexing operations (in display list order). 

<a name="pathName-insert"></a>
*pathName* **insert** *tagOrId beforeThis string*

> For each of the items given by *tagOrId*, if the item supports text or coordinate, insertion then string is inserted into the item's text just before the character, or coordinate, whose index is *beforeThis*. Text items interpret *beforeThis* as an index to a character, line and polygon items interpret it as an index to a coordinate (an x,y pair). For lines and polygons the string must be a valid coordinate sequence. See INDICES above for information about the forms allowed for *beforeThis*. This command returns an empty string. 

<a name="pathName-itemcget"></a>
*pathName* **itemcget** *tagOrId option*

> Returns the current value of the configuration option for the item given by *tagOrId* whose name is *option*. This command is similar to the **cget** widget command except that it applies to a particular item rather than the widget as a whole. *Option* may have any of the values accepted by the **create** widget command when the item was created. If *tagOrId* is a tag that refers to more than one item, the first (lowest) such item is used. 

<a name="pathName-itemconfigure"></a>
*pathName* **itemconfigure** *tagOrId ?option? ?value? ?option value ...?*

> This command is similar to the **configure** widget command except that it modifies item-specific options for the items given by *tagOrId* instead of modifying options for the overall canvas widget. If no *option* is specified, returns a list describing all of the available options for the first item given by *tagOrId* (see [Tk_ConfigureInfo][] for information on the format of this list). If *option* is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no *option* is specified). If one or more *option-value* pairs are specified, then the command modifies the given widget option(s) to have the given value(s) in each of the items given by *tagOrId*; in this case the command returns an empty string. The *options* and *values* are the same as those permissible in the **create** widget command when the item(s) were created; see the sections describing individual item types below for details on the legal options. 

<a name="pathName-itempdf"></a>
*pathName* **itempdf** *tagOrId ?extgsProc objProc gradProc?*

> The command return pdf code describing the given *tagOrId*. The function is optimised to work with [pdf4tcl][]. To create pdf from a **path** just call the **canvas** method from the pdf object p.e.:

    $pdf canvas $pathName -bbox [$pathName bbox] -x 0 -y 0

> See function `CanvasDoTkpathItem` in [pdf4tcl][] for details.

> If *extgsProc* is given and item has special graphic state *extgsProc* is called.

> If *objProc* is given and item has special object info *objProc* is called.

> If *gradProc* is given and the item uses a gradient the *gradProc* is called.

<a name="pathName-lastchild"></a>
*pathName* **lastchild** *tagOrId*

> Returns the last child item of the first item matching *tagOrId*. Applies only for groups.

<a name="pathName-lower"></a>
*pathName* **lower** *tagOrId ?belowThis?*

> Move all of the items given by *tagOrId* to a new position in the display list just before the item given by *belowThis*. If *tagOrId* refers to more than one item then all are moved but the relative order of the moved items will not be changed. *BelowThis* is a tag or id; if it refers to more than one item then the first (lowest) of these items in the display list is used as the destination location for the moved items. Note: this command has no effect on window items. Window items always obscure other item types, and the stacking order of window items is determined by the [raise][] command and [lower][] command, not the **raise** widget command and **lower** widget command for canvases. This command returns an empty string.

> Movement is constrained to siblings. If reference *tagOrId* not given it defaults to first/last item of the root items children. Items which are not siblings to the reference *tagOrId* are silently ignored.

<a name="pathName-move"></a>
*pathName* **move** *tagOrId xAmount yAmount*

> Move each of the items given by *tagOrId* in the canvas coordinate space by adding *xAmount* to the x-coordinate of each point associated with the item and *yAmount* to the y-coordinate of each point associated with the item. This command returns an empty string. 

<a name="pathName-moveto"></a>
*pathName* **moveto** *tagOrId xPos yPos*

Move the items given by *tagOrId* in the canvas coordinate space so that the first coordinate pair of the bottommost item with tag *tagOrId* is located at position (*xPos,yPos*). *xPos* and *yPos* may be the empty string, in which case the corresponding coordinate will be unchanged. All items matching *tagOrId* remain in the same positions relative to each other. This command returns an empty string. 

<a name="pathName-nextsibling"></a>
*pathName* **nextsibling** *tagOrId*

> Returns the next sibling item of the first item matching *tagOrId*. If *tagOrId* is the last child we return empty.

<a name="pathName-parent"></a>
*pathName* **parent** *tagOrId*

> Returns the parent item of the first item matching *tagOrId*. This command works for all items, also for the standard ones. It is therefore better to use this than `cget id -parent` which is only supported for the new path items.

<a name="pathName-prevsibling"></a>
*pathName* **prevsibling** *tagOrId*

> Returns the previous sibling item of the first item matching *tagOrId*. If *tagOrId* is the first child we return empty.

<a name="pathName-raise"></a>
*pathName* **raise** *tagOrId ?aboveThis?*

> Move all of the items given by *tagOrId* to a new position in the display list just after the item given by aboveThis. If *tagOrId* refers to more than one item then all are moved but the relative order of the moved items will not be changed. AboveThis is a tag or id; if it refers to more than one item then the last (topmost) of these items in the display list is used as the destination location for the moved items. This command returns an empty string. 

> Movement is constrained to siblings. If reference *tagOrId* not given it defaults to first/last item of the root items children. Items which are not siblings to the reference *tagOrId* are silently ignored.

> Note: this command has no effect on window items. Window items always obscure other item types, and the stacking order of window items is determined by the raise command and lower command, not the raise widget command and lower widget command for canvases. 

<a name="pathName-rchars"></a>
*pathName* **rchars** *tagOrId first last string*

> This command causes the text or coordinates between *first* and *last* for each of the items indicated by *tagOrId* to be replaced by string. Each item interprets *first* and *last* independently according to the rules described in [INDICES][] above. Out of the standard set of items, text items support this operation by altering their text as directed, and line and polygon items support this operation by altering their coordinate list (in which case string should be a list of coordinates to use as a replacement). The other items ignore this operation. 

<a name="pathName-scale"></a>
*pathName* **scale** *tagOrId xOrigin yOrigin xScale yScale*

> Rescale the coordinates of all of the items given by *tagOrId* in canvas coordinate space. *XOrigin* and *yOrigin* identify the origin for the scaling operation and *xScale* and *yScale* identify the scale factors for x- and y-coordinates, respectively (a scale factor of 1.0 implies no change to that coordinate). For each of the points defining each item, the x-coordinate is adjusted to change the distance from *xOrigin* by a factor of *xScale*. Similarly, each y-coordinate is adjusted to change the distance from *yOrigin* by a factor of *yScale*. This command returns an empty string. 

> Note that some items have only a single pair of coordinates (e.g. windows) and so scaling of them by this command can only move them around.

> If you apply scale on a group item it will apply this to all its descendants, also to child group items in a recursive way. 

<a name="pathName-scan"></a>
*pathName* **scan** *option args*

> This command is used to implement scanning on canvases. It has two forms, depending on option: 

> *pathName* **scan mark** *x y*

> > Records *x* and *y* and the canvas's current view; used in conjunction with later scan dragto commands. Typically this command is associated with a mouse button press in the widget and *x* and *y* are the coordinates of the mouse. It returns an empty string. 

> *pathName* **scan dragto** *x y ?gain?*

> > This command computes the difference between its *x* and *y* arguments (which are typically mouse coordinates) and the x and y arguments to the last scan mark command for the widget. It then adjusts the view by *gain* times the difference in coordinates, where *gain* defaults to 10. This command is typically associated with mouse motion events in the widget, to produce the effect of dragging the canvas at high speed through its window. The return value is an empty string. 

<a name="pathName-select"></a>
*pathName* **select** *option ?*tagOrId* arg?*

> Manipulates the selection in one of several ways, depending on *option*. The command may take any of the forms described below. In all of the descriptions below, *tagOrId* must refer to an item that supports indexing and selection; if it refers to multiple items then the first of these that supports indexing and the selection is used. Index gives a textual description of a position within *tagOrId*, as described in [INDICES][] above. 

> *pathName* **select adjust** *tagOrId index*

> > Locate the end of the selection in *tagOrId* nearest to the character given by *index*, and adjust that end of the selection to be at *index* (i.e. including but not going beyond index). The other end of the selection is made the anchor point for future select to commands. If the selection is not currently in *tagOrId* then this command behaves the same as the select to widget command. Returns an empty string. 

> *pathName* **select clear**

> > Clear the selection if it is in this widget. If the selection is not in this widget then the command has no effect. Returns an empty string. 

> *pathName* **select from** *tagOrId index*

> > Set the selection anchor point for the widget to be just before the character given by *index* in the item given by *tagOrId*. This command does not change the selection; it just sets the fixed end of the selection for future select to commands. Returns an empty string. 

>  *pathName* **select item**

> > Returns the id of the selected item, if the selection is in an item in this canvas. If the selection is not in this canvas then an empty string is returned. 

> *pathName* **select to** *tagOrId index*

> > Set the selection to consist of those characters of *tagOrId* between the selection anchor point and *index*. The new selection will include the character given by *index*; it will include the character given by the anchor point only if *index* is greater than or equal to the anchor point. The anchor point is determined by the most recent select adjust or select from command for this widget. If the selection anchor point for the widget is not currently in *tagOrId*, then it is set to the same character given by *index*. Returns an empty string. 

<a name="pathName-style"></a>
*pathName* **style** *cmd ?options?*

> See [STYLES](#STYLES) for the commands. The styles created with this command are local to the canvas instance. Only styles defined this way can be used.

> The styleToken is a style created with 'pathName style create'. It's options take precedence over any other options set directly. This is how SVG works (bad?). Currently all a style's options ever set are recorded in a cumulative way using a mask. Even if an option is set to its default it takes precedence over an items option.

<a name="pathName-type"></a>
*pathName* **type** *tagOrId*

> Returns the type of the item given by *tagOrId*, such as rectangle or text. If *tagOrId* refers to more than one item, then the type of the first item in the display list is returned. If *tagOrId* does not refer to any items at all then an empty string is returned. 

<a name="pathName-types"></a>
*pathName* **types**

> List all item types defined in canvas.

<a name=*pathName-xview"></a>
*pathName* **xview** *?args?*

> This command is used to query and change the horizontal position of the information displayed in the canvas's window. It can take any of the following forms: 

> *pathName* **xview**

> > Returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the horizontal span that is visible in the window. For example, if the first element is .2 and the second element is .6, 20% of the canvas's area (as defined by the **-scrollregion** option) is off-screen to the left, the middle 40% is visible in the window, and 40% of the canvas is off-screen to the right. These are the same values passed to scrollbars via the **-xscrollcommand** option. 

> *pathName* **xview moveto** *fraction*

> > Adjusts the view in the window so that *fraction* of the total width of the canvas is off-screen to the left. *Fraction* must be a fraction between 0 and 1. 

> *pathName* **xview scroll** *number what*

> > This command shifts the view in the window left or right according to *number* and *what*. *Number* must be an integer. *What* must be either **units** or **pages** or an abbreviation of one of these. If *what* is units, the view adjusts left or right in **units** of the **xScrollIncrement** option, if it is greater than zero, or in units of one-tenth the window's width otherwise. If what is **pages** then the view adjusts in units of nine-tenths the window's width. If *number* is negative then information farther to the left becomes visible; if it is positive then information farther to the right becomes visible. 

<a name="pathName-yview"></a>
*pathName* **yview** *?args?*

> This command is used to query and change the vertical position of the information displayed in the canvas's window. It can take any of the following forms: 

> *pathName* **yview**

> > Returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the vertical span that is visible in the window. For example, if the first element is .6 and the second element is 1.0, the lowest 40% of the canvas's area (as defined by the **-scrollregion** option) is visible in the window. These are the same values passed to scrollbars via the **-yscrollcommand** option. 

> *pathName* **yview moveto** *fraction*

> > Adjusts the view in the window so that *fraction* of the canvas's area is off-screen to the top. *Fraction* is a fraction between 0 and 1. 

> *pathName* **yview scroll** *number what*

> > This command adjusts the view in the window up or down according to *number* and *what*. *Number* must be an integer. *What* must be either **units** or **pages**. If *what* is **units**, the view adjusts up or down in units of the **yScrollIncrement** option, if it is greater than zero, or in units of one-tenth the window's height otherwise. If what is pages then the view adjusts in units of nine-tenths the window's height. If *number* is negative then higher information becomes visible; if it is positive then lower information becomes visible. 

<a name="ITEM-TYPES"></a>
## ITEM TYPES

The sections below describe the various types of items supported by canvas widgets. Each item type is characterized by two things: first, the form of the **create** command used to create instances of the type; and second, a set of configuration options for items of that type, which may be used in the **create** and **itemconfigure** widget commands. Most items do not support indexing or selection or the commands related to them, such as **index** and **insert**. Where items do support these facilities, it is noted explicitly in the descriptions below. At present, text, line and polygon items provide this support. For lines and polygons the indexing facility is used to manipulate the coordinates of the item. 

<a name="COMMON-ITEM-OPTIONS"></a>
### COMMON ITEM OPTIONS

The options can be separated into a few groups depending on the nature of an item for which they apply. Not all are implemented.

Arrow options accepted by line, polyline and path objects. Arrows are not
implemented on surfaces (see path::surface).

Options set in a group are inherited by its children but they never override
options explicitly set in children. This also applies to group items configured
with a -style.

    .c create group ?fillOptions strokeOptions genericOptions?

<a name="ITEM-fill"></a>
**-fill** *color\|gradientToken*

> This is either a usual tk color or the name of a gradient.

<a name="ITEM-fillopacity"></a>
**-fillopacity** *value*

> The given *value* is a float value between 0.0 and 1.0

<a name="ITEM-fillrule"></a>
**-fillrule** *nonzero\|evenodd*

<a name="ITEM-stroke"></a>
**-stroke** *color*

<a name="ITEM-strokedasharray"></a>
**-strokedasharray** *dashArray*

> The *dashArray* is a list of integers. Each element represents the number of pixels of a line segment. Only the odd segments are drawn using the "outline" color. The other segments are drawn transparent. 

<a name="ITEM-strokelinecap"></a>
**-strokelinecap** *butt\|round\|square*

<a name="ITEM-strokelinejoin"></a>
**-strokelinejoin** *miter\|round\|bevel*

<a name="ITEM-strokemiterlimit"></a>
**-strokemiterlimit** *float*

<a name="ITEM-strokeopacity"></a>
**-strokeopacity** *value*

> The given *value* is a float value between 0.0 and 1.0

<a name="ITEM-strokewidth"></a>
**-strokewidth** *float*

<a name="ITEM-matrix"></a>
**-matrix** *{a b c d tx ty}*

<a name="ITEM-parent"></a>
**-parent** *tagOrId*

<a name="ITEM-state"></a>
**-state** *active\|disabled\|normal\|hidden*

<a name="ITEM-style"></a>
**-style** *styleToken*

<a name="ITEM-tags"></a>
**-tags** *tagList*

<a name="ITEM-startarrow"></a>
**-startarrow** *boolean*

> Arrowhead on/off; the default value is off.

<a name="ITEM-startarrowlength"></a>
**-startarrowlength** *float*

> Length of the arrowhead.
  * 0.0 is special and draws '|-----'
  * negative values draw '>----'

<a name="ITEM-startarrowwidth"></a>
**-startarrowwidth** *float*

> Arrow width; must be positive.

<a name="ITEM-startarrowfill"></a>
**-startarrowfill** *float*

> Relative to startarrowlength; for example:
  * 0.0: do not fill arrowhead, arrowhead will be two lines
  * 1.0: '<|-------'
  * 2.0: '<>-------'

<a name="ITEM-endarrow"></a>
**-endarrow** *boolean*

> See **-startarrow**.

<a name="ITEM-endarrowlength"></a>
**-endarrowlength** *float*

> See **-startarrowlength**.

<a name="ITEM-endarrowwidth"></a>
**-endarrowwidth** *float*

> See **-startarrowwidth**.

<a name="ITEM-endarrowfill"></a>
**-endarrowfill** *float*

> See **-startarrowfill**.

<a name="GROUP-ITEM"></a>
### GROUP ITEM

<a name="pathName-create-group"></a>
*pathName* **create group** *?fillOptions strokeOptions genericOptions?*

A group item is merely a placeholder for other items, similar to how a
frame widget is a container for other widgets. It is a building block for
the tree structure. Unlike other items, and unlike frame widgets, it
doesn't display anything. It has no coordinates which is an additional
difference. The root item is a special group item with id 0 and tags
equal to "root". The root group can be configured like other items, but
its -tags and -parent options are read only.
Options set in a group are inherited by its children but they never override
options explicitly set in children. This also applies to group items configured
with a -style.

<a name="PATH-ITEM"></a>
### PATH ITEM

<a name="pathName-create-path"></a>
*pathName* **create path** *pathSpec ?fillOptions strokeOptions arrowOptions genericOptions?*

The path specification must be a single list and not concateneted with the rest of the command:

    pathName create path {M 10 10 h 10 v 10 h -10 z} -fill blue
    pathName create path M 10 10 h 10 v 10 h -10 z -fill blue    ;# Error

Furthermore, coordinates are pixel coordinates and nothing else.
SVG: It implements the complete syntax of the path elements d attribute with
one major difference: all separators must be whitespace, no commas, no
implicit assumptions; all instructions and numbers must form a tcl list.

All path specifications are normalized initially to the fundamental atoms
M, L, A, Q, and C, all upper case. When you use the canvas 'coords' command
it is the normalized path spec that is returned. Bad?

Visualize this as a pen which always has a current coordinate after
the first M. Coordinates are floats:

* M x y

> Put the pen on the paper at specified coordinate. Must be the first atom but can appear any time later. The pen doesn't draw anything when moved to this point.

* L x y

> Draw a straight line to the given coordinate. 

* H x

> Draw a horizontal line to the given x coordinate.

* V y

> Draw a vertical line to the given y coordinate.

* A rx ry phi largeArc sweep x y

> Draw an elliptical arc from the current point to (x, y). The points are on an ellipse with x-radius rx and y-radius ry. The ellipse is rotated by phi degrees. If the arc is less than 180 degrees, largeArc is zero, else it is one. If the arc is to be drawn in cw direction, sweep is one, and zero for the ccw direction.

> NB: the start and end points may not coincide else the result  is undefined. If you want to make a circle just do two 180 degree arcs.

* Q x1 y1 x y

> Draw a qadratic Bezier curve from the current point to (x, y) using control point (x1, y1).

* T x y

> Draw a qadratic Bezier curve from the current point to (x, y) The control point will be the reflection of the previous Q atoms control point. This makes smooth paths.

* C x1 y1 x2 y2 x y

> Draw a cubic Bezier curve from the current point to (x, y) using control points (x1, y1) and (x2, y2).

* S x2 y2 x y

> Draw a cubic Bezier curve from the current point to (x, y), using (x2, y2) as the control point for this new endpoint. The first control point will be the reflection of the previous C atoms ending control point. This makes smooth paths.

* Z
   
> Close path by drawing from the current point to the preceeding M point.

You may use lower case characters for all atoms which then means that all
coordinates, where relevant, are interpreted as coordinates relative the
current point.

Helper function for making path definitions:

> **path::path ellipse** *x y rx ry*

> > The function return a path definition of an ellipse with a middle point at *x* and *y* and a radius in x-disrection of *rx* and a radius in y-direction of *ry*.

> **path::path circle** *x y r*

> > The function return a path definition of an circle with a middle point at *x* and *y* and a radius of *r*.

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

<a name="pathName-create-line"></a>
*pathName* **create line** *x1 y1 x2 y2 ?strokeOptions arrowOptions genericOptions?*

Makes a single-segment straight line.

<a name="POLYLINE-ITEM"></a>
### POLYLINE ITEM

<a name="pathName-create-polyline"></a>
*pathName* **create polyline** *x1 y1 x2 y2 .... ?strokeOptions arrowOptions genericOptions?*

Makes a multi-segment line with open ends.

<a name="POLYGON-ITEM"></a>
### POLYGON ITEM

<a name="pathName-create-polygon"></a>
*pathName* **create polygon** *x1 y1 x2 y2 .... ?fillOptions strokeOptions genericOptions?*

Makes a closed polygon.

<a name="RECT-ITEM"></a>
### RECT ITEM

<a name="pathName-create-rect"></a>
*pathName* **create rect** *x1 y1 x2 y2 ?-rx value? ?-ry value? ?fillOptions strokeOptions genericOptions?*

This is a rectangle item with optionally rounded corners.
Item specific options:

**-rx** *value*

> Corner x-radius, or if -ry not given it sets the uniform radius.

**-ry** *value*

> Corner y-radius

<a name="CIRCLE-ITEM"></a>
### CIRCLE ITEM

<a name="pathName-create-circle"></a>
*pathName* **create circle** *cx cy ?-r fillOptions strokeOptions genericOptions?*

A plain circle item. Item specific options:

**-r** *value*

> Its radius; defaults to zero

<a name="ELLIPSE-ITEM"></a>
### ELLIPSE ITEM

<a name="pathName-create-ellipse"></a>
*pathName* **create ellipse** *cx cy ?-rx value? ?-ry value? ?fillOptions strokeOptions genericOptions?*

An ellipse item. Item specific options:

**-rx** *value*

> Its x-radius

**-ry** *value*

> Its y-radius


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

<a name="pathName-create-image"></a>
*pathName* **create image** *x y ?-image -width -height genericOptions?*

This displays an image in the canvas anchored nw. If -width or -height is
nonzero then the image is scaled to this size prior to any affine transform.

image extra options:

**-anchor** *n\|w\|s\|e\|nw\|ne\|sw\|se\|c*

> Default value is nw

**-tintcolor** *color*

> Tint color; the default value is "" which means no tinting

**-tintamount** *value*

*Value* is amount for tinting between 0. and 1.

**-interpolation** *mode*

> Image interpolation *mode* is one of **none, fast** or **best**

**-srcregion** *{x1 y1 x2 y2}*

> Shows only the specified region of image; if x2 or y2 are larger than the image bounds, then the image will be repeated (tiling)

These options are not implemented on surfaces (see path::surface).

<a name="TEXT-ITEM"></a>
### TEXT ITEM

<a name="pathName-create-text"></a>
*pathName* **create text** *x y ?-text string? ?-textanchor start\|middle\|end\|n\|w\|s\|e\|nw\|ne\|sw\|se\|c? ?-fontfamily fontname -fontsize float? ?-fontslant normal\|italic\|oblique? ?-fontweight normal\|bold? ?fillOptions strokeOptions genericOptions? ?-filloverstroke BOOLEAN?*

Displays text as expected. Note that the x coordinate marks the baseline
of the text. Gradient fills are unsupported so far. Especially the font
handling and settings will likely be developed further.
Editing not implemented. The default font family and size is platform dependent.

text extra options:

**-textanchor** *n\|w\|s\|e\|nw\|ne\|sw\|se\|c\|start\|middle\|end*

> Textanchor extended with points of compass.

**-fontslant** *normal\|italic\|oblique*

> Default value is normal

**-fontweight** *normal\|bold*

> Default value is normal

**-filloverstroke** *boolean*

> Fill drawn over the stroke; default value is false

These options are not implemented on surface items (path::surface), except for

**-textanchor** *start\|middle\|end*

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

Items of type window cause a particular window to be displayed at a given position on the canvas. Window items are created with widget commands of the following form: 

<a name="pathName-create-window"></a>
*pathName* **create window** *x y ?option value ...?*

*pathName* **create window** *coordList ?option value ...?*

The arguments x and y or coordList (which must have two elements) specify the coordinates of a point used to position the window on the display, as controlled by the -anchor option. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. Theoretically, a window item becomes the current item when the mouse pointer is over any part of its bounding box, but in practice this typically does not happen because the mouse pointer ceases to be over the canvas at that point. 

The following standard options are supported by window items: 

> **-anchor**

> **-state**

> **-tags**

The following extra options are supported for window items: 

**-height** *pixels*

> Specifies the height to assign to the item's window. Pixels may have any of the forms described in the [COORDINATES][] section above. If this option is not specified, or if it is specified as zero, then the window is given whatever height it requests internally. 

**-width** *pixels*

> Specifies the width to assign to the item's window. Pixels may have any of the forms described in the [COORDINATES][] section above. If this option is not specified, or if it is specified as zero, then the window is given whatever width it requests internally. 

**-window** *pathName*

> Specifies the window to associate with this item. The window specified by pathName must either be a child of the canvas widget or a child of some ancestor of the canvas widget. PathName may not refer to a top-level window. 

Note: due to restrictions in the ways that windows are managed, it is not possible to draw other graphical items (such as lines and images) on top of window items. A window item always obscures any graphics that overlap it, regardless of their order in the display list. Also note that window items, unlike other canvas items, are not clipped for display by their containing canvas's border, and are instead clipped by the parent widget of the window specified by the -window option; when the parent widget is the canvas, this means that the window item can overlap the canvas's border. 

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

In the current implementation, new canvases are not given any default behavior: you will have to execute explicit Tcl commands to give the canvas its behavior. 

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

Tk's canvas widget is a blatant ripoff of ideas from Joel Bartlett's ezd program. Ezd provides structured graphics in a Scheme environment and preceded canvases by a year or two. Its simple mechanisms for placing and animating graphical objects inspired the functions of canvases.

[Tkpath][] was originally developed by Matts Bengtsson.

User visisble changes to the original [Tkpath][] code are:

- changed widget name in **path** and use of namespace **::path**
- -matrix is now a flat list
- tk canvas items removed, only exception is **window** item
- changed item names to match [SVG][] names:
  - **pimage** => **image**
  - **pline** => **line**
  - **ppolygon** => **polygon**
  - **prect** => **rect**
  - **ptext** => **text**
- no unique abbreviations of widget commands

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

canvas, svg, widget

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

&copy; 2005-2008 Mats Bengtsson

&copy; 2015- Christian Werner <[email protected]>

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

BSD style license.

<a name="SEE-ALSO"></a>
## SEE ALSO

[bind][], [font][], [image][], [scrollbar][], [pdf4tcl][], [SVG][], [Cairo][]

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

canvas, pdf, svg, widget

[bind]: bind.htm
[break]: break.htm
[continue]: continue.htm
[font]: font.htm
[image]: image.htm
[options]: options.htm
[raise]: raise.htm
[scrollbar]: scrollbar.htm
[lower]: lower.htm
[Tk_ConfigureInfo]: ConfigWidg.htm
[Tkpath]: <https://sourceforge.net/projects/tclbitprint/>
[pdf4tcl]: <https://sourceforge.net/projects/pdf4tcl/>
[SVG]: <http://www.w3.org/TR/SVG11/>
[Cairo]: <http://cairographics.org>


Added doc/tkoWidget.3.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
# tkoWidget(3) -- oo class like widgets

*   [NAME](#NAME)
*   [SYNOPSIS](#SYNOPSIS)
*   [ARGUMENTS](#ARGUMENTS)  
*   [DESCRIPTION](#DESCRIPTION)  
*   [SEE ALSO](#SEE-ALSO)  
*   [KEYWORDS](#KEYWORDS)  
*   [COPYRIGHT](#COPYRIGHT)  

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

TkoWidgetClassDefine,
TkoWidgetOptionVar,
TkoWidgetOptionGet,
TkoWidgetOptionSet,
TkoWidgetWindow -- tko widget class commands

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

**#include "tkoWidget.h"**

int  
**TkoWidgetClassDefine**(*interp,clazz,classname,methods,options*)  
Tk\_Window \*  
**TkoWidgetWindow**(*object*)  
Tcl\_Obj \*  
**TkoWidgetOptionVar**(*object*)  
Tcl\_Obj \*  
**TkoWidgetOptionGet**(*interp,object,option*)  
int  
**TkoWidgetOptionSet**(*interp,context,option,type,meta,offset*)  

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

| Tcl\_Interp **\*interp** | Used interpreter.  
| Tcl\_Class **clazz** | Oo class of widget.  
| Tcl\_Obj **\*classname** |Oo class name of widget.  
| const Tcl\_MethodType **\*methods** | This array defines class methods to create. For creation methods see [Tcl_NewMethod] manpage. If the method name of the first array entry is not NULL it will be used as **constructor**, if the second method name is not NULL it used as **destructor**. Then follow public methods until an entry with an method name equal NULL comes. Then follow private methods until an entry with an method name equal NULL comes.  
| const tkoWidgetOptionDefine **\*options** | This array contain option definitions.  
| Tcl\_Object **object** | This is the current object reference.  
| Tcl\_Obj **\*option** | The name of the used option.  
| Tcl\_ObjectContext **context** | The context of the current object. Used to get associated object data.  
| tkoWidgetOptionType **type** | A type used in the common option setting routine.  
| Tcl\_ObjectMetadataType **\*meta** | The type of metadata attaches to the current object.  
| size\_t **offset** | Offset of variable to set in the attaches meta data record.  

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

The **TkoWidgetClassDefine** function can be used to define options and methods of an **tko::widget** subclass. The function is used in the widget class definition of a new tko widget class.

The **TkoWidgetWindow** function return the address of the internally created Tk\_Window. Subclasses should check the address on NULL after creation. If the Tk\_Window\* at these address is NULL the widget is destroyed and it should not be used.

The **TkoWidgetOptionVar** function return the globally accessible name of the array variable holding the option values. Additionall there is an field "**.**" containing the tk widget path name of the widget.

The **TkoWidgetOptionGet** function returns the current value of the given option.

The **TkoWidgetOptionSet** function can be used to check given *option* values and set C record structure fields at the given *offset*. The record will be retrieved using the given *meta* metadata. The *type* must be one of the **tkoWidgetOptionType** described below.

### Struct: `tkoWidgetOptionDefine`

    typedef struct tkoWidgetOptionDefine {
      const char *option;    /* Name of option. Starts with "-" minus sign */
      const char *dbname;    /* Option DB name or synonym option if dbclass is NULL */
      const char *dbclass;   /* Option DB class name or NULL for synonym options. */
      const char *defvalue;  /* Default value. */
      int flags;             /* bit array of TKO_OPTION_* values to configure option behaviour */
      Tcl_Obj *optionPtr;    /* tko internally used, always init with NULL! */
      const char *proc;      /* If not NULL it is the body of the newly created -option method */
      Tcl_MethodCallProc *method;     /* If not NULL it is the function name of the -option method */
      tkoWidgetOptionType type;       /* if greater 0 then option type used in common option set method */
      Tcl_ObjectMetadataType *meta;   /* meta data address used in common option set method */
      int offset;            /* offset in meta data struct */
    } tkoWidgetOptionDefine;
    #define TKO_OPTION_READONLY 0x1 /* option is only setable at creation time */
    #define TKO_OPTION_HIDE     0x2 /* option is hidden in configure method */ 

### Enum: `tkoWidgetOptionType`

Suported enum type in the TkowidgetOptinSet() function. In comments is the type of the address provided in the **TkoWidgetOptionSet** funtion.

    typedef enum tkoWidgetOptionType {
        TKO_SET_CLASS = 1,     /* (Tcl_Obj **)address */
        TKO_SET_VISUAL, /* (Tcl_Obj **)address */
        TKO_SET_COLORMAP,       /* (Tcl_Obj **)address */
        TKO_SET_USENULL,        /* (Tcl_Obj **)address */
        TKO_SET_CONTAINER,      /* (int *)address */
        TKO_SET_TCLOBJ, /* (Tcl_Obj **)address */
        TKO_SET_XCOLOR, /* (Xcolor **)address */
        TKO_SET_3DBORDER,       /* (Tk_3DBorder *)address */
        TKO_SET_PIXEL,  /* (int *)address */
        TKO_SET_PIXELNONEGATIV, /* (int *)address */
        TKO_SET_PIXELPOSITIV,   /* (int *)address */
        TKO_SET_DOUBLE, /* (double *)address */
        TKO_SET_BOOLEAN,        /* (int *)address */
        TKO_SET_CURSOR, /* (Tk_Cursor *)address */
        TKO_SET_INT,    /* (int *)address */
        TKO_SET_RELIEF, /* (int *)address */
        TKO_SET_ANCHOR, /* (int *)address */
        TKO_SET_WINDOW, /* (Tk_Window *)address */
        TKO_SET_FONT,   /* (Tk_Font *)address */
        TKO_SET_STRING, /* (char **)address */
        TKO_SET_STRINGNULL,     /* (char **)address */
        TKO_SET_SCROLLREGION,   /* (int *[4])address */
        TKO_SET_JUSTIFY /* (Tk_Justify *)address */
    } tkoWidgetOptionType;

<a name="SEE-ALSO"></a>
## SEE ALSO

[frame][], [labelframe][], [toplevel][], [oo::class][]

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

oo widget method option

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

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

BSD style license.

[options]: options.htm
[frame]: frame.htm
[labelframe]: labelframe.htm
[toplevel]: toplevel.htm
[oo::class]: class.htm
[graph]: graph.htm
[path]: path.htm
[Tkpath]: <https://sourceforge.net/projects/tclbitprint/>
[Rbc]: <https://sourceforge.net/projects/rbctoolkit/>


Added doc/tkoWidget.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
# tko::widget(n) -- oo class like widgets

*   [SYNOPSIS](#SYNOPSIS)
*   [TKO STANDARD OPTIONS](#TKO-STANDARD-OPTIONS)  
  [-class, class, Class](#-class)  
  [-screen, screen, Screen](#-screen)  
*   [DESCRIPTION](#DESCRIPTION)  
*   [WIDGET METHODS](#WIDGET-METHODS)  
*   [WIDGET OPTIONS](#WIDGET-OPTIONS)  
*   [EXAMPLES](#EXAMPLES)  
*   [SEE ALSO](#SEE-ALSO)  
*   [KEYWORDS](#KEYWORDS)  
*   [COPYRIGHT](#COPYRIGHT)  

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

    oo::class create myWidget {
      {*}$::tko::unknown    ;# define unknown method to support common tk widget style
      superclass "tkoClass" ;# one of the provided tko widget class's
      variable tko          ;# array with options *$tko(-option)* and widget path *$tko(.)*
      method -myoption {...};# deal with option when set
      ...
      constructor {optionlist arglist} {
        next [concat {
          {-myoption myOption MyOption value}
          ...
        } $optionlist] $arglist
        ...
      }
      destructor {next}
    }

The command creates a new Tcl class whose name is *widgetClass*. This command may be used to create new widgets. Each new widget class has as a *tkoClass* as superclass. The common functionality is in the **tko::widget** class. Currently the following *tkoClass* superclasses are provided:

**::tko::toplevel** *pathName ?option value? ..*

**::tko::frame** *pathName ?option value? ..*

**::tko::labelframe** *pathName ?option value? ..*

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

**::path** *pathName ?option value? ..*

<a name="TKO-STANDARD-OPTIONS"></a>
## TKO STANDARD OPTIONS

<a name="-class"></a>
Command-Line Name: **-class**  
Database Name: **class**  
Database Class: **Class**

> > Define class for use in getting values from option database. Can only be set on widget creation time.

<a name="-screen"></a>
Command-Line Name: **-screen**  
Database Name: **screen**  
Database Class: **Screen**

> > Affect creation of underlying widget structure. If given the created widget will be a toplevel widget.

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

The **tko::widget** class contain the common widget functionality. To get these functionality you have to create a subclass of the **tko::widget** class. This can only be done in C. To use the functionality on tcl script level the following classes are provided.

<a name="tko-toplevel"></a>
## tko::toplevel

These class contain the functionality of the [toplevel][] widget command.

<a name="tko-frame"></a>
## tko::frame

These class contain the functionality of the [frame][] widget command.

<a name="tko-labelframe"></a>
## tko::labelframe

These class contain the functionality of the [labelframe][] widget command.

<a name="tko-graph"></a>
## graph

These class contain the functionality of the [Rbc][] graph widget command. It is described in detail in the [graph][] manpage.

<a name="tko-path"></a>
## path

These class contain the functionality of the [Tkpath][] widget command. It is described in detail in the [path][] manpage.

<a name="WIDGET-METHODS"></a>
### WIDGET METHODS

Widget methods can be dynamically added and removed at class or object level.

**NOTE** Do not change *tkoClass*'s behaviour. Instead create your own class and modify it to your need! Or change created widget objects behaviour.

The **tko::widget** class provides the following methods.

<a name="method-constructor"></a>
**constructor {optionlist arglist}**

> The *optionlist* contain a sorted list off option descriptions as described in **configure optonadd**. It will be processed in the **tko::widget** constructor in the given order. It should always start with the "-class" option definition. The necessary *-option* method's should already be exist.

> The *arglist* is the normal *-option value ..* list of all tk widgets.

> Each widget class constructor should call **next** *$optionlist $arglist*!


<a name="method-destructor"></a>
**destructor {}**

> Here you can free your own ressources. Don't forget to call **next**! After **next** the **tko::widget** data are gone (widget path, tko array variable).

<a name="method-cget"></a>
**cget** *option*

> Return the current vlaue of the given *option*.

<a name="method-configure"></a>
**configure** *args*

> **configure**

> > If *args* is empty the method will return a sorted list of all configuration options.

> **configure** *-option*

> > If we have one element in *args* starting with a minus sign ("-") then the method return the configuration list including the current value of the given *-option*.

> **configure** *-option value ..*

> > If we have an even number list in *args* and the first element starts with a minus sign ("-") then the method does configure all the given option-value pairs. If an error occurs the the corresponding element is not set and the method gives an error. Alrready successfull set options remain.

> **configure init**

> > This is an internal function used in constructing new widgets. It is used in the *unknown* method to initialize all options.

> **configure optionadd** *-synonym -option*

> > Add a *-synonym* for a given *-option*. The *-option* needs not to be defined at this time.

> **configure optionadd** *-synonym dbnam dbclass ?default? ?flags?*

> > Add a new option. If ?flags? is equal "1" then the option is readonly and can only be set in this call. Before adding a new option a *-option* method must created. The method will be called without any arguments. The method can access the new value using the *tko(-option)* array variable. If the method throws a n error the array variable will be reset to the old value.

> **configure optiondel** *-option*

> > Delete the given option and unset the entry in the tko array variable. The created *-option* method's are not deleted. This is the task of the caller.

> **configure optionhide** *?-option? ..*

> > If no *-option* is given return a list of all not configure'able options. Otherwise hide all of the given options.

> **configure optionshow** *?-option? ..*

> > If no *-option* is given return a list of all configure'able options. Otherwise make all of the given options configure'able.

> **configure optionvar**

> > The method return the global varname of the tko array variable holding all option values.

<a name="method-cget"></a>
**\_tko\_configure**

> This is an virtuel method of the **tko::widget** class. This method will be called at the end of each **configure** *-option value ..* call. It can be implemented in each class to amke necessary changes. If it is implemented it should also call **next** to notify underlying classes.

<a name="WIDGET-OPTIONS"></a>
### WIDGET OPTIONS

Widget option values are saved in an option array. The option name is the field name in the array. Additionally is an field "**.**" containing the tk widget path name of the widget. The name of the option array variable can be retrieved using the following code:
    set myVar [.w configure optionvar]
    parray $myVar

Widget options can be dynamically added and removed at class or object level.
It is possible to hide and unhide options.

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

    # Add options at class creation:
    oo::class create ::myWidget {
      {*}$::tko::unknown
      superclass ::tko::frame
      variable tko
      method -myoption {} {puts $tko(-myoption)}
      method -myreadonly {} {puts $tko(-myreadonly)}
      constructor {optionlist arglist} {
        next [concat {
          {-myoption myOption MyOption value}
          {-myreadonly myReadonly MyReadonly value 1}
        } $optionlist] $arglist
      }
    }
    proc output {} {
      puts "config: [.w configure]"
      puts "normal: [.w configure optionhide]"
      puts "hidden: [.w configure optionshow]"
    }
    # Add options at object level:
    ::myWidget .w
    oo::objdefine .w method -o1 {} {my variable tko; puts $tko(-o1)}
    oo::objdefine .w method -o2 {} {my variable tko; puts $tko(-o2)}
    .w configure optionadd -o1 o1 O1 v1 1 ;#->
    .w configure optionadd -o2 o2 O2 v2
    output
    # Remove one and hide rest
    .w configure optiondel -o2
    .w configure optionhide {*}[.w configure optionshow]
    output
    # Reverse state
    .w configure optionshow {*}[.w configure optionhide]
    output


<a name="SEE-ALSO"></a>
## SEE ALSO

[frame][], [labelframe][], [toplevel][], [oo::class][]

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

oo widget method option

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

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

BSD style license.

[options]: options.htm
[frame]: frame.htm
[labelframe]: labelframe.htm
[toplevel]: toplevel.htm
[oo::class]: class.htm
[graph]: graph.htm
[path]: path.htm
[Tkpath]: <https://sourceforge.net/projects/tclbitprint/>
[Rbc]: <https://sourceforge.net/projects/rbctoolkit/>


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
1043
1044
1045
1046
1047
1048
1049
# graph::vector(n) -- Vector data type for graph widgets

*   [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)
* [CREDITS](#CREDITS)  
* [KEYWORDS](#KEYWORDS)
* [COPYRIGHT](#COPYRIGHT)

<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="CREDITS"></a>
## CREDITS

[BLT][] was originally develeoped by George A. Howlett. It can be found at <https://sourceforge.net/projects/blt/>.

Refactored [BLT][] Components ([Rbc][]), includes data vectors and graph widgets from the original [BLT][]. Both can be found at sourceforge.

User visible changes to the original [Rbc][] code are:

- command name is now **graph::vector**

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

[BLT]: <https://sourceforge.net/projects/blt/>
[Rbc]: <https://sourceforge.net/projects/rbctoolkit/>

Changes to generic/tkCmds.c.

38
39
40
41
42
43
44




45
46
47
48
49
50
51
..
64
65
66
67
68
69
70



71
72
73
74
75
76
77
...
969
970
971
972
973
974
975
























976
977
978
979
980
981
982
			    int objc, Tcl_Obj *const *objv);
static int		CaretCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
static int		InactiveCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
static int		ScalingCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);




static int		UseinputmethodsCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const *objv);
static int		WindowingsystemCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const *objv);

................................................................................
    {"busy",		Tk_BusyObjCmd, NULL },
    {"caret",		CaretCmd, NULL },
    {"inactive",	InactiveCmd, NULL },
    {"scaling",		ScalingCmd, NULL },
    {"useinputmethods",	UseinputmethodsCmd, NULL },
    {"windowingsystem",	WindowingsystemCmd, NULL },
    {"fontchooser",	NULL, tkFontchooserEnsemble},



    {NULL, NULL, NULL}
};
 
/*
 *----------------------------------------------------------------------
 *
 * Tk_BellObjCmd --
................................................................................
	Tcl_ResetResult(interp);
    } else {
	Tcl_WrongNumArgs(interp, 1, objv, "?-displayof window? ?reset?");
	return TCL_ERROR;
    }
    return TCL_OK;
}
























 
/*
 *----------------------------------------------------------------------
 *
 * Tk_TkwaitObjCmd --
 *
 *	This function is invoked to process the "tkwait" Tcl command. See the






>
>
>
>







 







>
>
>







 







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







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
...
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
			    int objc, Tcl_Obj *const *objv);
static int		CaretCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
static int		InactiveCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
static int		ScalingCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
#ifndef MAC_OSX_TK
static int		SnapCmd(ClientData dummy, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const *objv);
#endif
static int		UseinputmethodsCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const *objv);
static int		WindowingsystemCmd(ClientData dummy,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const *objv);

................................................................................
    {"busy",		Tk_BusyObjCmd, NULL },
    {"caret",		CaretCmd, NULL },
    {"inactive",	InactiveCmd, NULL },
    {"scaling",		ScalingCmd, NULL },
    {"useinputmethods",	UseinputmethodsCmd, NULL },
    {"windowingsystem",	WindowingsystemCmd, NULL },
    {"fontchooser",	NULL, tkFontchooserEnsemble},
#ifndef MAC_OSX_TK
    {"snap",		SnapCmd, NULL},
#endif
    {NULL, NULL, NULL}
};
 
/*
 *----------------------------------------------------------------------
 *
 * Tk_BellObjCmd --
................................................................................
	Tcl_ResetResult(interp);
    } else {
	Tcl_WrongNumArgs(interp, 1, objv, "?-displayof window? ?reset?");
	return TCL_ERROR;
    }
    return TCL_OK;
}

#ifndef MAC_OSX_TK
int
SnapCmd(
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = clientData;
    int skip = TkGetDisplayOf(interp, objc - 1, objv + 1, &tkwin);

    if (skip < 0) {
	return TCL_ERROR;
    }
    if (objc != 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "window photo");
	return TCL_ERROR;
    }

    return Rbc_SnapWindow(interp, tkwin, Tcl_GetString(objv[1]),
        Tcl_GetString(objv[2]), 0, 0);
}
#endif
 
/*
 *----------------------------------------------------------------------
 *
 * Tk_TkwaitObjCmd --
 *
 *	This function is invoked to process the "tkwait" Tcl command. See the

Changes to generic/tkInt.h.

1001
1002
1003
1004
1005
1006
1007










1008
1009
1010
1011
1012
1013
1014
/*
 * Themed widget set init function:
 */

MODULE_SCOPE int	Ttk_Init(Tcl_Interp *interp);











/*
 * Internal functions shared among Tk modules but not exported to the outside
 * world:
 */

MODULE_SCOPE int	Tk_BellObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,






>
>
>
>
>
>
>
>
>
>







1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
/*
 * Themed widget set init function:
 */

MODULE_SCOPE int	Ttk_Init(Tcl_Interp *interp);

/*
 * Used tko widget set functions:
 */
#ifndef MAC_OSX_TK
MODULE_SCOPE int	Tko_Init(Tcl_Interp *interp);
MODULE_SCOPE int	Rbc_SnapWindow(Tcl_Interp *interp,Tk_Window tkmain,
			    const char*pathname, const char *photoimage,
			    int destWidth, int destHeight);
#endif

/*
 * Internal functions shared among Tk modules but not exported to the outside
 * world:
 */

MODULE_SCOPE int	Tk_BellObjCmd(ClientData clientData,
			    Tcl_Interp *interp, int objc,

Changes to generic/tkWindow.c.

3308
3309
3310
3311
3312
3313
3314









3315
3316
3317
3318
3319
3320
3321
     */

    code = Ttk_Init(interp);
    if (code != TCL_OK) {
	goto done;
    }










    /*
     * Invoke platform-specific initialization. Unlock mutex before entering
     * TkpInit, as that may run through the Tk_Init routine again for the
     * console window interpreter.
     */

    code = TkpInit(interp);






>
>
>
>
>
>
>
>
>







3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
     */

    code = Ttk_Init(interp);
    if (code != TCL_OK) {
	goto done;
    }

    /*
     * Initialize the tko widget set
     */
#ifndef MAC_OSX_TK
    code = Tko_Init(interp);
    if (code != TCL_OK) {
	goto done;
    }
#endif
    /*
     * Invoke platform-specific initialization. Unlock mutex before entering
     * TkpInit, as that may run through the Tk_Init routine again for the
     * console window interpreter.
     */

    code = TkpInit(interp);

Added generic/tko/tkoFrame.c.




































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
/*
 * tkoFrame.c --
 *
 *	This module implements "frame", "labelframe" and "toplevel" widgets
 *	for the Tk toolkit. Frames are windows with a background color and
 *	possibly a 3-D effect, but not much else in the way of attributes.
 *
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2019 Rene Zaumseil
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkoWidget.h"

 /*
  * The following enum is used to define the type of the frame.
  */
enum FrameType {
    TYPE_FRAME, TYPE_TOPLEVEL, TYPE_LABELFRAME
};

/*
 * tkoFrame --
 *
 * A data structure of the following type is kept for each
 * frame that currently exists for this process:
 */
typedef struct tkoFrame {
    Tk_Window *win;
    Tcl_Object object;
    Tcl_Interp *interp;
    Display *display;
    enum FrameType type;       /* Type of widget, such as TYPE_FRAME. */
    char *menuName;            /* Textual description of menu to use for
                                * menubar. Malloc-ed, may be NULL. */
    Colormap colormap;         /* If not None, identifies a colormap
                                * allocated for this window, which must be
                                * freed when the window is deleted. */
    Tk_3DBorder border;        /* Structure used to draw 3-D border and
                                * background. NULL means no background or
                                * border. */
    int borderWidth;           /* Width of 3-D border (if any). */
    int relief;                /* 3-d effect: TK_RELIEF_RAISED etc. */
    int highlightWidth;        /* Width in pixels of highlight to draw around
                                * widget when it has the focus. 0 means don't
                                * draw a highlight. */
    XColor *highlightBgColorPtr;
    /* Color for drawing traversal highlight area
     * when highlight is off. */
    XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
    int width;                 /* Width to request for window. <= 0 means
                                * don't request any size. */
    int height;                /* Height to request for window. <= 0 means
                                * don't request any size. */
    Tk_Cursor cursor;          /* Current cursor for window, or None. */
    int isContainer;           /* 1 means this window is a container, 0 means
                                * that it isn't. */
    Tcl_Obj *useThis;          /* If the window is embedded, this points to
                                * the name of the window in which it is
                                * embedded (malloc'ed). For non-embedded
                                * windows this is NULL. */
    int flags;                 /* Various flags; see below for
                                * definitions. */
    int padX;                  /* Integer value corresponding to padXPtr. */
    int padY;                  /* Integer value corresponding to padYPtr. */
    unsigned int mask;
} tkoFrame;

/*
 * tkoLabelframe --
 *
 * A data structure of the following type is kept for each labelframe widget
 * managed by this file:
 */
typedef struct tkoLabelframe {
    tkoFrame frame;            /* A pointer to the generic frame structure.
                                * This must be the first element of the
                                * tkoLabelframe. */
    /*
     * tkoLabelframe specific configuration settings.
     */
    Tcl_Obj *textPtr;          /* Value of -text option: specifies text to
                                * display in button. */
    Tk_Font tkfont;            /* Value of -font option: specifies font to
                                * use for display text. */
    XColor *textColorPtr;      /* Value of -fg option: specifies foreground
                                * color in normal mode. */
    int labelAnchor;           /* Value of -labelanchor option: specifies
                                * where to place the label. */
    Tk_Window labelWin;        /* Value of -labelwidget option: Window to use
                                * as label for the frame. */
    /*
     * tkoLabelframe specific fields for use with configuration settings above.
     */
    GC  textGC;                /* GC for drawing text in normal mode. */
    Tk_TextLayout textLayout;  /* Stored text layout information. */
    XRectangle labelBox;       /* The label's actual size and position. */
    int labelReqWidth;         /* The label's requested width. */
    int labelReqHeight;        /* The label's requested height. */
    int labelTextX, labelTextY; /* Position of the text to be drawn. */
} tkoLabelframe;

/*
 * The following macros define how many extra pixels to leave around a label's
 * text.
 */
#define LABELSPACING 1
#define LABELMARGIN 4

 /*
  * Flag bits for frames:
  *
  * REDRAW_PENDING:             Non-zero means a DoWhenIdle handler has
  *                             already been queued to redraw this window.
  * GOT_FOCUS:                  Non-zero means this widget currently has the
  *                             input focus.
  */
#define REDRAW_PENDING		1
#define GOT_FOCUS		4

  /*
   * The following enum is used to define a type for the -labelanchor option of
   * the Labelframe widget. These values are used as indices into the string
   * table below.
   */
enum labelanchor {
    LABELANCHOR_E, LABELANCHOR_EN, LABELANCHOR_ES,
    LABELANCHOR_N, LABELANCHOR_NE, LABELANCHOR_NW,
    LABELANCHOR_S, LABELANCHOR_SE, LABELANCHOR_SW,
    LABELANCHOR_W, LABELANCHOR_WN, LABELANCHOR_WS
};

/*
* Methods
*/
static int FrameConstructorFrame(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int FrameConstructorLabelframe(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int FrameConstructorToplevel(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int FrameDestructor(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int FrameMethod_tko_configure(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int FrameMethod_tko_option(
	ClientData clientData,
	Tcl_Interp * interp,
	Tcl_ObjectContext context,
	int objc,
	Tcl_Obj * const objv[]);
static int FrameMethod_labelanchor(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int FrameMethod_labelwidget(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);

/*
 * Functions
 */
static int FrameConstructor(
    int type,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static void FrameMetaDestroy(
    tkoFrame * frame);
static void
FrameMetaDelete(
    ClientData clientData)
{
    Tcl_EventuallyFree(clientData, (Tcl_FreeProc *) FrameMetaDestroy);
}

static void FrameComputeGeometry(
    tkoFrame * frame);
static void FrameDisplay(
    ClientData clientData);
static void FrameEventProc(
    ClientData clientData,
    XEvent * eventPtr);
static void FrameLostSlaveProc(
    ClientData clientData,
    Tk_Window tkWin);
static void FrameRequestProc(
    ClientData clientData,
    Tk_Window tkWin);
static void FrameStructureProc(
    ClientData clientData,
    XEvent * eventPtr);
static void FrameWorldChanged(
    ClientData instanceData);
static void FrameLabelwinRemove(
    tkoLabelframe * labelframe);
static void FrameMap(
    ClientData clientData);

/*
 * Data
 */

/*
 * frameMeta --
 *
 * The structure is used to identify our own data inoo objects.
 */
static Tcl_ObjectMetadataType frameMeta = {
    TCL_OO_METADATA_VERSION_CURRENT,
    "FrameMeta",
    FrameMetaDelete,
    NULL
};

/*
 * frameClass --
 *
 * The structure below defines frame class behavior by means of functions that
 * can be invoked from generic window code.
 */
static const Tk_ClassProcs frameClass = {
    sizeof(Tk_ClassProcs),      /* size */
    FrameWorldChanged,  /* worldChangedProc */
    NULL,      /* createProc */
    NULL       /* modalProc */
};

/*
 * frameGeomType --
 *
 * The structure below defines the official type record for the labelframe's
 * geometry manager:
 */
static const Tk_GeomMgr frameGeomType = {
    "labelframe",       /* name */
    FrameRequestProc,   /* requestProc */
    FrameLostSlaveProc  /* lostSlaveProc */
};

/*
 * Definition of options created in object constructor.
 * Order of used options in definition is important:
 * -class -visual -colormap -container -use
 */

/* Common options for all defined widgets. */
#define FRAME_COMMONDEFINE \
	{ "-background" , "background", "Background", DEF_FRAME_BG_COLOR, 0, NULL, \
        NULL, NULL,	TKO_SET_3DBORDER, &frameMeta, offsetof(tkoFrame, border)}, \
	{ "-bg" , "-background", NULL, NULL, 0, NULL, NULL, NULL,0,NULL,0}, \
	{ "-bd" , "-borderwidth", NULL, NULL, 0, NULL, NULL, NULL,0,NULL,0}, \
	{ "-cursor" , "cursor", "Cursor", DEF_FRAME_CURSOR, 0, NULL, \
		NULL, NULL, TKO_SET_CURSOR, &frameMeta, offsetof(tkoFrame, cursor)}, \
	{ "-height" , "height", "Height", DEF_FRAME_HEIGHT, 0, NULL, \
		NULL, NULL, TKO_SET_PIXEL, &frameMeta, offsetof(tkoFrame, height)}, \
	{ "-highlightbackground", "highlightbackground", "highlightBackground", DEF_FRAME_HIGHLIGHT_BG, 0, NULL, \
		NULL, NULL, TKO_SET_XCOLOR, &frameMeta, offsetof(tkoFrame, highlightBgColorPtr)}, \
	{ "-highlightcolor", "highlightColor", "HighlightColor", DEF_FRAME_HIGHLIGHT, 0,NULL, \
		NULL, NULL, TKO_SET_XCOLOR, &frameMeta, offsetof(tkoFrame, highlightColorPtr)}, \
	{ "-highlightthickness" , "highlightThickness", "HighlightThickness", DEF_FRAME_HIGHLIGHT_WIDTH,  0,NULL, \
		NULL, NULL, TKO_SET_PIXEL, &frameMeta, offsetof(tkoFrame, highlightWidth)}, \
	{ "-padx" , "padX", "Pad", DEF_FRAME_PADX, 0,NULL, \
		NULL, NULL, TKO_SET_PIXEL, &frameMeta, offsetof(tkoFrame, padX)}, \
	{ "-pady" , "padY", "Pad", DEF_FRAME_PADY, 0,NULL, \
		NULL, NULL, TKO_SET_PIXEL, &frameMeta, offsetof(tkoFrame, padY)}, \
	{ "-takefocus" , "takeFocus", "TakeFocus", DEF_FRAME_TAKE_FOCUS,  0,NULL, \
		NULL, NULL, TKO_SET_STRING, NULL, 0}, \
	{ "-width" , "width", "Width", DEF_FRAME_WIDTH,  0,NULL, \
		NULL, NULL, TKO_SET_PIXEL, &frameMeta, offsetof(tkoFrame, width)}, \
	{ NULL,NULL,NULL,NULL,0,NULL, NULL,NULL,0,NULL,0}

/* tko::frame options */
static tkoWidgetOptionDefine frameOptions[] = {
    {"-class", "class", "Class", "TkoFrame", TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_CLASS, NULL, 0},
    {"-visual", "visual", "Visual", DEF_FRAME_VISUAL, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_VISUAL, NULL, 0},
    {"-colormap", "colormap", "Colormap", DEF_FRAME_COLORMAP, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_COLORMAP, NULL, 0},
    {"-container", "container", "Container", DEF_FRAME_CONTAINER, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_CONTAINER, &frameMeta, offsetof(tkoFrame, isContainer)},
    {"-borderwidth", "borderWidth", "BorderWidth", DEF_FRAME_BORDER_WIDTH, 0,NULL,
	NULL, NULL, TKO_SET_PIXEL, &frameMeta, offsetof(tkoFrame, borderWidth)},
    {"-relief", "relief", "Relief", DEF_FRAME_RELIEF, 0,NULL,
	NULL, NULL, TKO_SET_RELIEF, &frameMeta, offsetof(tkoFrame, relief)},
    FRAME_COMMONDEFINE
};

/* tko::toplevel options */
static tkoWidgetOptionDefine toplevelOptions[] = {
    {"-screen", "screen", "Screen", "", TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_STRING, NULL, 0},
    {"-class", "class", "Class", "TkoToplevel", TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_CLASS, NULL, 0},
    {"-container", "container", "Container", DEF_FRAME_CONTAINER, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_CONTAINER, &frameMeta, offsetof(tkoFrame, isContainer)},
    {"-use", "use", "Use", DEF_TOPLEVEL_USE, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_USENULL, &frameMeta, offsetof(tkoFrame, useThis)},
    {"-visual", "visual", "Visual", DEF_FRAME_VISUAL, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_VISUAL, NULL, 0},
    {"-colormap", "colormap", "Colormap", DEF_FRAME_COLORMAP, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_COLORMAP, NULL, 0},
    {"-borderwidth", "borderWidth", "BorderWidth", DEF_FRAME_BORDER_WIDTH, 0,NULL,
	NULL, NULL, TKO_SET_PIXEL, &frameMeta, offsetof(tkoFrame, borderWidth)},
    {"-menu", "menu", "Menu", DEF_TOPLEVEL_MENU, 0,NULL,
	NULL, NULL, TKO_SET_STRINGNULL, &frameMeta, offsetof(tkoFrame, menuName)},
    {"-relief", "relief", "Relief", DEF_FRAME_RELIEF, 0,NULL,
	NULL, NULL, TKO_SET_RELIEF, &frameMeta, offsetof(tkoFrame, relief)},
    FRAME_COMMONDEFINE
};

/* tko::labelframe options */
static tkoWidgetOptionDefine labelframeOptions[] = {
    {"-class", "class", "Class", "TkoLabelframe", TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_CLASS, NULL, 0},
    {"-visual", "visual", "Visual", DEF_FRAME_VISUAL, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_VISUAL, NULL, 0},
    {"-colormap", "colormap", "Colormap", DEF_FRAME_COLORMAP, TKO_OPTION_READONLY,NULL,
	NULL, NULL, TKO_SET_COLORMAP, NULL, 0},
    {"-borderwidth", "borderWidth", "BorderWidth", DEF_LABELFRAME_BORDER_WIDTH, 0,NULL,
	NULL, NULL, TKO_SET_PIXEL, &frameMeta, offsetof(tkoFrame, borderWidth)},
    {"-fg", "-foreground", NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0},
    {"-font", "font", "Font", DEF_LABELFRAME_FONT, 0,NULL,
	NULL, NULL, TKO_SET_FONT, &frameMeta, offsetof(tkoLabelframe, tkfont)},
	{"-foreground", "foreground", "Foreground", DEF_LABELFRAME_FG, 0, NULL,
	NULL, NULL, TKO_SET_XCOLOR, &frameMeta, offsetof(tkoLabelframe, textColorPtr)},
    {"-labelanchor", "labelAnchor", "LabelAnchor", DEF_LABELFRAME_LABELANCHOR, 0, NULL,
	NULL, FrameMethod_labelanchor, 0, NULL, 0},
    {"-labelwidget", "labelWidget", "LabelWidget", "",0, NULL,
	NULL, FrameMethod_labelwidget, 0, NULL, 0},
    {"-relief", "relief", "Relief", DEF_LABELFRAME_RELIEF, 0, NULL,
	NULL, NULL, TKO_SET_RELIEF, &frameMeta, offsetof(tkoFrame, relief)},
    {"-text", "text", "Text", DEF_LABELFRAME_TEXT, 0, NULL,
	NULL, NULL, TKO_SET_TCLOBJ, &frameMeta, offsetof(tkoLabelframe, textPtr)},
    FRAME_COMMONDEFINE
};

/*
 * Definition of object methods created in Tko_FrameInit() function.
 */

/* tko::frame methods. */
static Tcl_MethodType frameMethods[] = {
    {TCL_OO_METHOD_VERSION_CURRENT, NULL, FrameConstructorFrame, NULL, NULL},
    {TCL_OO_METHOD_VERSION_CURRENT, NULL, FrameDestructor, NULL, NULL},
    {-1, NULL, NULL, NULL, NULL},
    {TCL_OO_METHOD_VERSION_CURRENT, "_tko_configure", FrameMethod_tko_configure,
            NULL, NULL},
    {-1, NULL, NULL, NULL, NULL}
};

/* tko::labelframe methods. */
static Tcl_MethodType labelframeMethods[] = {
    {TCL_OO_METHOD_VERSION_CURRENT, NULL, FrameConstructorLabelframe, NULL,
            NULL},
    {TCL_OO_METHOD_VERSION_CURRENT, NULL, FrameDestructor, NULL, NULL},
    {-1, NULL, NULL, NULL, NULL},
    {TCL_OO_METHOD_VERSION_CURRENT, "_tko_configure", FrameMethod_tko_configure,
            NULL, NULL},
    {-1, NULL, NULL, NULL, NULL}
};

/* tko::toplevel methods. */
static Tcl_MethodType toplevelMethods[] = {
    {TCL_OO_METHOD_VERSION_CURRENT, NULL, FrameConstructorToplevel, NULL, NULL},
    {TCL_OO_METHOD_VERSION_CURRENT, NULL, FrameDestructor, NULL, NULL},
    {-1, NULL, NULL, NULL, NULL},
    {TCL_OO_METHOD_VERSION_CURRENT, "_tko_configure", FrameMethod_tko_configure,
            NULL, NULL},
    {-1, NULL, NULL, NULL, NULL}
};

/*
 * Tko_FrameInit --
 *
 * Create tko frame widget class objects.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
int
Tko_FrameInit(
    Tcl_Interp * interp)
{              /* Tcl interpreter. */
Tcl_Class clazz;
Tcl_Object object;

    /* Create class like tk command and remove oo functions from widget commands */
static const char *initScript =
    "::oo::class create ::tko::frame {superclass ::tko::widget; variable tko; {*}$::tko::unknown}\n"
    "::oo::class create ::tko::labelframe {superclass ::tko::widget; variable tko; {*}$::tko::unknown}\n"
    "::oo::class create ::tko::toplevel {superclass ::tko::widget; variable tko; {*}$::tko::unknown}\n";

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

    /*
     * ::tko::toplevel
     */
    /* Get class object */
    if((object = Tcl_GetObjectFromObj(interp, TkoObj.tko_toplevel)) == NULL
        || (clazz = Tcl_GetObjectAsClass(object)) == NULL) {
        return TCL_ERROR;
    }
    /* Add methods and options */
    if(TkoWidgetClassDefine(interp, clazz, Tcl_GetObjectName(interp, object),
            toplevelMethods, toplevelOptions) != TCL_OK) {
        return TCL_ERROR;
    }
    /*
     * ::tko::frame
     */
    /* Get class object */
    if((object = Tcl_GetObjectFromObj(interp, TkoObj.tko_frame)) == NULL
        || (clazz = Tcl_GetObjectAsClass(object)) == NULL) {
        return TCL_ERROR;
    }
    /* Add methods and options */
    if(TkoWidgetClassDefine(interp, clazz, Tcl_GetObjectName(interp, object),
            frameMethods, frameOptions) != TCL_OK) {
        return TCL_ERROR;
    }

    /*
     * ::tko::labelframe
     */
    /* Get class object */
    if((object = Tcl_GetObjectFromObj(interp, TkoObj.tko_labelframe)) == NULL
        || (clazz = Tcl_GetObjectAsClass(object)) == NULL) {
        return TCL_ERROR;
    }
    /* Add methods and options */
    if(TkoWidgetClassDefine(interp, clazz, Tcl_GetObjectName(interp, object),
            labelframeMethods, labelframeOptions) != TCL_OK) {
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 * FrameConstructorFrame --
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
FrameConstructorFrame(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    return FrameConstructor(TYPE_FRAME, interp, context, objc, objv);
}

/*
 * FrameConstructorLabelframe --
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
FrameConstructorLabelframe(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    return FrameConstructor(TYPE_LABELFRAME, interp, context, objc, objv);
}

/*
 * FrameConstructorToplevel --
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
FrameConstructorToplevel(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    return FrameConstructor(TYPE_TOPLEVEL, interp, context, objc, objv);
}

/*
 * FrameDestructor --
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
FrameDestructor(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    int skip;
    Tcl_Object object;
    tkoFrame *frame;
    Tk_Window tkWin = NULL;
    tkoLabelframe *labelframe;
    if((object = Tcl_ObjectContextObject(context)) == NULL) {
        return TCL_ERROR;
    }
    skip = Tcl_ObjectContextSkippedArgs(context);
    if((frame = (tkoFrame *) Tcl_ObjectGetMetadata(object, &frameMeta)) != NULL) {
        Tcl_Preserve(frame);
        labelframe = (tkoLabelframe *) frame;

        if(frame->win) {
            tkWin = *(frame->win);
            frame->win = NULL;
        }
        if(tkWin) {
            Tk_DeleteEventHandler(tkWin, frame->mask, FrameEventProc, frame);
        }
        if(frame->cursor != None) {
            if(frame->display != None) {
                Tk_FreeCursor(frame->display, frame->cursor);
            }
            frame->cursor = None;
        }
        frame->flags = 0;
        Tcl_CancelIdleCall(FrameDisplay, frame);
        Tcl_CancelIdleCall(FrameMap, frame);

        if(frame->menuName != NULL && tkWin) {
            TkSetWindowMenuBar(frame->interp, tkWin, frame->menuName, NULL);
            frame->menuName = NULL;
        }
        if(frame->type == TYPE_LABELFRAME && labelframe->labelWin) {
            Tk_ManageGeometry(labelframe->labelWin, NULL, NULL);
            if(tkWin && (tkWin != Tk_Parent(labelframe->labelWin))) {
                Tk_UnmaintainGeometry(labelframe->labelWin, tkWin);
            }
            Tk_UnmapWindow(labelframe->labelWin);
            labelframe->labelWin = NULL;
        }
        Tcl_Release(frame);
        Tcl_ObjectSetMetadata(object, &frameMeta, NULL);
    }
    /* ignore errors */
    Tcl_ObjectContextInvokeNext(interp, context, objc, objv, skip);

    return TCL_OK;
}

/*
 * FrameMethod_tko_configure --
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
FrameMethod_tko_configure(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    char *oldMenuName;
    Tcl_Object object;
    tkoFrame *frame;
    tkoLabelframe *labelframe;
    Tk_Window oldWindow;
    Tk_Window tkwin;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (frame =
            (tkoFrame *) Tcl_ObjectGetMetadata(object, &frameMeta)) == NULL
        || frame->win == NULL || (tkwin = *(frame->win)) == NULL) {
        return TCL_ERROR;
    }
    labelframe = (tkoLabelframe *) frame;

    /*
     * Need the old menubar name for the menu code to delete it.
     */

    if(frame->menuName == NULL) {
        oldMenuName = NULL;
    } else {
        oldMenuName = ckalloc(strlen(frame->menuName) + 1);
        strcpy(oldMenuName, frame->menuName);
    }

    if(frame->type == TYPE_LABELFRAME) {
        oldWindow = labelframe->labelWin;
    }
    /*TODO ???      if (oldMenuName != NULL) {
     * ckfree(oldMenuName);
     * }
     */

    /*
     * A few of the options require additional processing.
     */

    if((((oldMenuName == NULL) && (frame->menuName != NULL))
            || ((oldMenuName != NULL) && (frame->menuName == NULL))
            || ((oldMenuName != NULL) && (frame->menuName != NULL)
                && strcmp(oldMenuName, frame->menuName) != 0))
        && frame->type == TYPE_TOPLEVEL) {
        TkSetWindowMenuBar(frame->interp, tkwin, oldMenuName, frame->menuName);
    }

    if(oldMenuName != NULL) {
        ckfree(oldMenuName);
    }

    if(frame->border != NULL) {
        Tk_SetBackgroundFromBorder(tkwin, frame->border);
    } else {
        Tk_SetWindowBackgroundPixmap(tkwin, None);
    }

    if(frame->highlightWidth < 0) {
        frame->highlightWidth = 0;
    }
    if(frame->padX < 0) {
        frame->padX = 0;
    }
    if(frame->padY < 0) {
        frame->padY = 0;
    }

    FrameWorldChanged(frame);
    if(Tcl_ObjectContextInvokeNext(interp, context, objc, objv,
            Tcl_ObjectContextSkippedArgs(context)) != TCL_OK) {
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 * FrameMethod_labelanchor --
 *
 * Process -labelanchor option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
FrameMethod_labelanchor(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    int index, code;
    Tcl_Object object;
    tkoLabelframe *labelframe;
    Tcl_Obj *value;
	static const char *const labelAnchorStrings[] = {
		"e", "en", "es", "n", "ne", "nw", "s", "se", "sw", "w", "wn", "ws",
		NULL
	};

	if((object = Tcl_ObjectContextObject(context)) == NULL
        || (labelframe =
            (tkoLabelframe *) Tcl_ObjectGetMetadata(object, &frameMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }
    code =
        Tcl_GetIndexFromObj(interp, value, labelAnchorStrings, "labelanchor", 0,
        &index);
    if(code != TCL_OK) {
        return TCL_ERROR;
    }
    labelframe->labelAnchor = (Tk_Anchor) index;
    return TCL_OK;
}

/*
 * FrameMethod_labelwidget --
 *
 * Process -labelwidget option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
FrameMethod_labelwidget(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tk_Window oldWindow = NULL;
    Tk_Window newWindow = NULL;
    Tk_Window tkwin = NULL;
    Tk_Window ancestor, parent, sibling = NULL;
    Tcl_Object object;
    tkoLabelframe *labelframe;
    Tcl_Obj *value;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (labelframe =
            (tkoLabelframe *) Tcl_ObjectGetMetadata(object, &frameMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }

    if(labelframe->frame.win == NULL
        || (tkwin = *(labelframe->frame.win)) == NULL) {
        return TCL_ERROR;
    }

    if(value == NULL || Tcl_GetCharLength(value) == 0) {
        newWindow = NULL;
    } else if(TkGetWindowFromObj(interp, tkwin, value, &newWindow) != TCL_OK) {
        return TCL_ERROR;
    }
    /*
     * If a -labelwidget is specified, check that it is valid and set up
     * geometry management for it.
     */
    oldWindow = labelframe->labelWin;
    if(oldWindow != newWindow) {
        if(newWindow != NULL) {
            /*
             * Make sure that the frame is either the parent of the window
             * used as label or a descendant of that parent. Also, don't
             * allow a top-level window to be managed inside the frame.
             */
            parent = Tk_Parent(newWindow);
            for(ancestor = tkwin;; ancestor = Tk_Parent(ancestor)) {
                if(ancestor == parent) {
                    break;
                }
                sibling = ancestor;
                if(Tk_IsTopLevel(ancestor)) {
                    goto badLabelWindow;
                }
            }
            if(Tk_IsTopLevel(newWindow)) {
                goto badLabelWindow;
            }
            if(newWindow == tkwin) {
                goto badLabelWindow;
            }
        }
        if(oldWindow != NULL) {
            Tk_DeleteEventHandler(oldWindow, StructureNotifyMask,
                FrameStructureProc, labelframe);
            Tk_ManageGeometry(oldWindow, NULL, NULL);
            Tk_UnmaintainGeometry(oldWindow, tkwin);
            Tk_UnmapWindow(oldWindow);
        }
        if(newWindow != NULL) {
            Tk_CreateEventHandler(newWindow,
                StructureNotifyMask, FrameStructureProc, labelframe);
            Tk_ManageGeometry(newWindow, &frameGeomType, labelframe);
            /*
             * If the frame is not parent to the label, make sure the
             * label is above its sibling in the stacking order.
             */
            if(sibling != NULL) {
                Tk_RestackWindow(newWindow, Above, sibling);
            }
        }
        labelframe->labelWin = newWindow;
    }
    //      FrameWorldChanged(labelframe);
    return TCL_OK;

  badLabelWindow:
    Tcl_SetObjResult(interp,
        Tcl_ObjPrintf("can't use %s as label in this frame",
            Tk_PathName(labelframe->labelWin)));
    Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL);
    labelframe->labelWin = NULL;
    return TCL_ERROR;
}

/*
 * FrameConstructor --
 *
 * Common part of all widget contructors.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
FrameConstructor(
    int type,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tcl_Object object;
    tkoFrame *frame;
    int skip;
    Tcl_Obj *myObjv[2];

    /* Get current object. Should not fail? */
    if((object = Tcl_ObjectContextObject(context)) == NULL) {
        return TCL_ERROR;
    }
    skip = Tcl_ObjectContextSkippedArgs(context);
    /* Check objv[] arguments: ... optionlist arglist */
    if(objc - skip != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "optionlist arglist");
        return TCL_ERROR;
    }
    if(type == TYPE_FRAME) {
        frame = ckalloc(sizeof(tkoFrame));
        memset(frame, 0, sizeof(tkoFrame));
        myObjv[0] =
            Tcl_ObjGetVar2(interp, TkoObj.tko_options, TkoObj.tko_frame,
            TCL_GLOBAL_ONLY);
        myObjv[1] = objv[objc - 1];
    } else if(type == TYPE_LABELFRAME) {
    tkoLabelframe *labelframe;

        frame = ckalloc(sizeof(tkoLabelframe));
        memset(frame, 0, sizeof(tkoLabelframe));
        myObjv[0] =
            Tcl_ObjGetVar2(interp, TkoObj.tko_options, TkoObj.tko_labelframe,
            TCL_GLOBAL_ONLY);
        myObjv[1] = objv[objc - 1];
        labelframe = (tkoLabelframe *) frame;
        labelframe->textPtr = NULL;
        labelframe->tkfont = NULL;
        labelframe->textColorPtr = NULL;
        labelframe->labelAnchor = LABELANCHOR_NW;
        labelframe->labelWin = NULL;
        labelframe->textGC = None;
        labelframe->textLayout = NULL;
        /*labelframe->labelBox */
        labelframe->labelReqWidth = 0;
        labelframe->labelReqHeight = 0;
        labelframe->labelTextX = 0;
        labelframe->labelTextY = 0;
    } else if(type == TYPE_TOPLEVEL) {
        myObjv[1] = Tcl_NewStringObj("-screen {}", -1);
        Tcl_IncrRefCount(myObjv[1]);
        if(Tcl_ListObjAppendList(interp, myObjv[1], objv[objc - 1]) != TCL_OK) {
            Tcl_DecrRefCount(myObjv[1]);
            return TCL_ERROR;
        }
        frame = ckalloc(sizeof(tkoFrame));
        memset(frame, 0, sizeof(tkoFrame));
        myObjv[0] =
            Tcl_ObjGetVar2(interp, TkoObj.tko_options, TkoObj.tko_toplevel,
            TCL_GLOBAL_ONLY);
    } else {
        Tcl_WrongNumArgs(interp, 1, objv, "internal type error");
        return TCL_ERROR;
    }
    if(myObjv[0] == NULL) {
        return TCL_ERROR;
    }
    frame->win = NULL;
    frame->object = object;
    frame->interp = interp;
    frame->display = None;
    frame->type = type;
    frame->menuName = NULL;
    frame->colormap = None;
    frame->border = NULL;
    frame->borderWidth = 0;
    frame->relief = TK_RELIEF_FLAT;
    frame->highlightWidth = 0;
    frame->highlightBgColorPtr = NULL;
    frame->highlightColorPtr = NULL;
    frame->width = 0;
    frame->height = 0;
    frame->cursor = None;
    frame->isContainer = 0;
    frame->useThis = NULL;
    frame->flags = 0;
    frame->padX = 0;
    frame->padY = 0;
    frame->mask = ExposureMask | StructureNotifyMask | FocusChangeMask;
    if(type == TYPE_TOPLEVEL) {
        frame->mask |= ActivateMask;
    }

    Tcl_ObjectSetMetadata(object, &frameMeta, (ClientData) frame);

    myObjv[0] = Tcl_DuplicateObj(myObjv[0]);
    Tcl_IncrRefCount(myObjv[0]);
    Tcl_ListObjAppendList(interp, myObjv[0], objv[objc - 2]);
    if(Tcl_ObjectContextInvokeNext(interp, context, 2, myObjv, 0) != TCL_OK) {
        Tcl_DecrRefCount(myObjv[0]);
        if(type == TYPE_TOPLEVEL) {
            Tcl_DecrRefCount(myObjv[1]);
        }
        return TCL_ERROR;
    }
    Tcl_DecrRefCount(myObjv[0]);
    if(type == TYPE_TOPLEVEL) {
        Tcl_DecrRefCount(myObjv[1]);
    }
    frame->win = TkoWidgetWindow(object);
    if(frame->win == NULL || *(frame->win) == NULL) {
        return TCL_ERROR;
    }
    if((frame->display = Tk_Display(*(frame->win))) == None) {
        return TCL_ERROR;
    }
    if(frame->isContainer && frame->useThis != NULL) {
        Tcl_SetObjResult(interp,
            Tcl_NewStringObj
            ("windows cannot have both the -use and the -container"
                " option set", -1));
        Tcl_SetErrorCode(interp, "TK", "FRAME", "CONTAINMENT", NULL);
        return TCL_ERROR;
    }
    /*
     * For top-level windows, provide an initial geometry request of 200x200,
     * just so the window looks nicer on the screen if it doesn't request a
     * size for itself.
     */
    if(type == TYPE_TOPLEVEL) {
        Tk_GeometryRequest(*(frame->win), 200, 200);
    }

    /*
     * Store backreference to frame widget in window structure.
     */

    Tk_SetClassProcs(*(frame->win), &frameClass, frame);

    /*
     * Mark Tk frames as suitable candidates for [wm manage].
     */

    ((TkWindow *) * (frame->win))->flags |= TK_WM_MANAGEABLE;

    Tk_CreateEventHandler(*(frame->win), frame->mask, FrameEventProc, frame);

    if(type == TYPE_TOPLEVEL) {
        Tcl_DoWhenIdle(FrameMap, frame);
    }

    return TCL_OK;
}

/*
 * FrameMetaDestroy --
 *
 *	This function is invoked by Tcl_EventuallyFree or Tcl_Release to clean
 *	up the internal structure of a frame at a safe time (when no-one is
 *	using it anymore).
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Everything associated with the frame is freed up.
 */
static void
FrameMetaDestroy(
    tkoFrame * frame)
{              /* Info about frame widget. */
tkoLabelframe *labelframe = (tkoLabelframe *) frame;

    if(frame->menuName != NULL) {
        ckfree(frame->menuName);
    }
    if(frame->useThis) {
        Tcl_DecrRefCount(frame->useThis);
    }
    if(frame->type == TYPE_LABELFRAME) {
        if(labelframe->textLayout) {
            Tk_FreeTextLayout(labelframe->textLayout);
        }
        if(labelframe->textGC != None && frame->display != None) {
            Tk_FreeGC(frame->display, labelframe->textGC);
        }
    }
    if(frame->border) {
        Tk_Free3DBorder(frame->border);
    }
    if(frame->colormap != None && frame->display != None) {
        Tk_FreeColormap(frame->display, frame->colormap);
    }
    if(frame->highlightBgColorPtr != NULL) {
        Tk_FreeColor(frame->highlightBgColorPtr);
    }
    if(frame->highlightColorPtr != NULL) {
        Tk_FreeColor(frame->highlightColorPtr);
    }
    ckfree(frame);
}

/*
 * FrameWorldChanged --
 *
 *	This function is called when the world has changed in some way and the
 *	widget needs to recompute all its graphics contexts and determine its
 *	new geometry.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Frame will be relayed out and redisplayed.
 */
static void
FrameWorldChanged(
    ClientData instanceData)
{              /* Information about widget. */
tkoFrame *frame = instanceData;
tkoLabelframe *labelframe = instanceData;
XGCValues gcValues;
GC  gc;
int anyTextLabel, anyWindowLabel;
int bWidthLeft, bWidthRight, bWidthTop, bWidthBottom;
const char *labelText;
    if(frame->win == NULL || *(frame->win) == NULL)
        return;

    anyTextLabel = (frame->type == TYPE_LABELFRAME) &&
        (labelframe->textPtr != NULL) && (labelframe->labelWin == NULL);
    anyWindowLabel = (frame->type == TYPE_LABELFRAME) &&
        (labelframe->labelWin != NULL);

    if(frame->type == TYPE_LABELFRAME) {
        /*
         * The textGC is needed even in the labelWin case, so it's always
         * created for a labelframe.
         */

        gcValues.font = Tk_FontId(labelframe->tkfont);
        gcValues.foreground = labelframe->textColorPtr->pixel;
        gcValues.graphics_exposures = False;
        gc = Tk_GetGC(*(frame->win),
            GCForeground | GCFont | GCGraphicsExposures, &gcValues);
        if(labelframe->textGC != None) {
            Tk_FreeGC(frame->display, labelframe->textGC);
        }
        labelframe->textGC = gc;

        /*
         * Calculate label size.
         */

        labelframe->labelReqWidth = labelframe->labelReqHeight = 0;

        if(anyTextLabel) {
            labelText = Tcl_GetString(labelframe->textPtr);
            if(labelframe->textLayout) {
                Tk_FreeTextLayout(labelframe->textLayout);
            }
            labelframe->textLayout =
                Tk_ComputeTextLayout(labelframe->tkfont,
                labelText, -1, 0, TK_JUSTIFY_CENTER, 0,
                &labelframe->labelReqWidth, &labelframe->labelReqHeight);
            labelframe->labelReqWidth += 2 * LABELSPACING;
            labelframe->labelReqHeight += 2 * LABELSPACING;
        } else if(anyWindowLabel) {
            labelframe->labelReqWidth = Tk_ReqWidth(labelframe->labelWin);
            labelframe->labelReqHeight = Tk_ReqHeight(labelframe->labelWin);
        }

        /*
         * Make sure label size is at least as big as the border. This
         * simplifies later calculations and gives a better appearance with
         * thick borders.
         */

        if((labelframe->labelAnchor >= LABELANCHOR_N) &&
            (labelframe->labelAnchor <= LABELANCHOR_SW)) {
            if(labelframe->labelReqHeight < frame->borderWidth) {
                labelframe->labelReqHeight = frame->borderWidth;
            }
        } else {
            if(labelframe->labelReqWidth < frame->borderWidth) {
                labelframe->labelReqWidth = frame->borderWidth;
            }
        }
    }

    /*
     * Calculate individual border widths.
     */

    bWidthBottom = bWidthTop = bWidthRight = bWidthLeft =
        frame->borderWidth + frame->highlightWidth;

    bWidthLeft += frame->padX;
    bWidthRight += frame->padX;
    bWidthTop += frame->padY;
    bWidthBottom += frame->padY;

    if(anyTextLabel || anyWindowLabel) {
        switch (labelframe->labelAnchor) {
        case LABELANCHOR_E:
        case LABELANCHOR_EN:
        case LABELANCHOR_ES:
            bWidthRight += labelframe->labelReqWidth - frame->borderWidth;
            break;
        case LABELANCHOR_N:
        case LABELANCHOR_NE:
        case LABELANCHOR_NW:
            bWidthTop += labelframe->labelReqHeight - frame->borderWidth;
            break;
        case LABELANCHOR_S:
        case LABELANCHOR_SE:
        case LABELANCHOR_SW:
            bWidthBottom += labelframe->labelReqHeight - frame->borderWidth;
            break;
        default:
            bWidthLeft += labelframe->labelReqWidth - frame->borderWidth;
            break;
        }
    }

    Tk_SetInternalBorderEx(*(frame->win), bWidthLeft, bWidthRight, bWidthTop,
        bWidthBottom);

    FrameComputeGeometry(frame);

    /*
     * A labelframe should request size for its label.
     */

    if(frame->type == TYPE_LABELFRAME) {
int minwidth = labelframe->labelReqWidth;
int minheight = labelframe->labelReqHeight;
int padding = frame->highlightWidth;

        if(frame->borderWidth > 0) {
            padding += frame->borderWidth + LABELMARGIN;
        }
        padding *= 2;
        if((labelframe->labelAnchor >= LABELANCHOR_N) &&
            (labelframe->labelAnchor <= LABELANCHOR_SW)) {
            minwidth += padding;
            minheight += frame->borderWidth + frame->highlightWidth;
        } else {
            minheight += padding;
            minwidth += frame->borderWidth + frame->highlightWidth;
        }
        Tk_SetMinimumRequestSize(*(frame->win), minwidth, minheight);
    }

    if((frame->width > 0) || (frame->height > 0)) {
        Tk_GeometryRequest(*(frame->win), frame->width, frame->height);
    }

    if(Tk_IsMapped(*(frame->win))) {
        if(!(frame->flags & REDRAW_PENDING)) {
            Tcl_DoWhenIdle(FrameDisplay, frame);
        }
        frame->flags |= REDRAW_PENDING;
    }
}

/*
 * FrameComputeGeometry --
 *
 *	This function is called to compute various geometrical information for
 *	a frame, such as where various things get displayed. It's called when
 *	the window is reconfigured.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Display-related numbers get changed in *frame.
 */

static void
FrameComputeGeometry(
    register tkoFrame * frame)
{              /* Information about widget. */
    int otherWidth, otherHeight, otherWidthT, otherHeightT, padding;
    int maxWidth, maxHeight;
    tkoLabelframe *labelframe = (tkoLabelframe *) frame;
    if(frame->win == NULL || *(frame->win) == NULL)
        return;

    /*
     * We have nothing to do here unless there is a label.
     */

    if(frame->type != TYPE_LABELFRAME) {
        return;
    }
    if(labelframe->textPtr == NULL && labelframe->labelWin == NULL) {
        return;
    }

    /*
     * Calculate the available size for the label
     */

    labelframe->labelBox.width = labelframe->labelReqWidth;
    labelframe->labelBox.height = labelframe->labelReqHeight;

    padding = frame->highlightWidth;
    if(frame->borderWidth > 0) {
        padding += frame->borderWidth + LABELMARGIN;
    }
    padding *= 2;

    maxHeight = Tk_Height(*(frame->win));
    maxWidth = Tk_Width(*(frame->win));

    if((labelframe->labelAnchor >= LABELANCHOR_N) &&
        (labelframe->labelAnchor <= LABELANCHOR_SW)) {
        maxWidth -= padding;
        if(maxWidth < 1) {
            maxWidth = 1;
        }
    } else {
        maxHeight -= padding;
        if(maxHeight < 1) {
            maxHeight = 1;
        }
    }
    if(labelframe->labelBox.width > maxWidth) {
        labelframe->labelBox.width = maxWidth;
    }
    if(labelframe->labelBox.height > maxHeight) {
        labelframe->labelBox.height = maxHeight;
    }

    /*
     * Calculate label and text position. The text's position is based on the
     * requested size (= the text's real size) to get proper alignment if the
     * text does not fit.
     */

    otherWidth = Tk_Width(*(frame->win)) - labelframe->labelBox.width;
    otherHeight = Tk_Height(*(frame->win)) - labelframe->labelBox.height;
    otherWidthT = Tk_Width(*(frame->win)) - labelframe->labelReqWidth;
    otherHeightT = Tk_Height(*(frame->win)) - labelframe->labelReqHeight;
    padding = frame->highlightWidth;

    switch (labelframe->labelAnchor) {
    case LABELANCHOR_E:
    case LABELANCHOR_EN:
    case LABELANCHOR_ES:
        labelframe->labelTextX = otherWidthT - padding;
        labelframe->labelBox.x = otherWidth - padding;
        break;
    case LABELANCHOR_N:
    case LABELANCHOR_NE:
    case LABELANCHOR_NW:
        labelframe->labelTextY = padding;
        labelframe->labelBox.y = padding;
        break;
    case LABELANCHOR_S:
    case LABELANCHOR_SE:
    case LABELANCHOR_SW:
        labelframe->labelTextY = otherHeightT - padding;
        labelframe->labelBox.y = otherHeight - padding;
        break;
    default:
        labelframe->labelTextX = padding;
        labelframe->labelBox.x = padding;
        break;
    }

    if(frame->borderWidth > 0) {
        padding += frame->borderWidth + LABELMARGIN;
    }

    switch (labelframe->labelAnchor) {
    case LABELANCHOR_NW:
    case LABELANCHOR_SW:
        labelframe->labelTextX = padding;
        labelframe->labelBox.x = padding;
        break;
    case LABELANCHOR_N:
    case LABELANCHOR_S:
        labelframe->labelTextX = otherWidthT / 2;
        labelframe->labelBox.x = otherWidth / 2;
        break;
    case LABELANCHOR_NE:
    case LABELANCHOR_SE:
        labelframe->labelTextX = otherWidthT - padding;
        labelframe->labelBox.x = otherWidth - padding;
        break;
    case LABELANCHOR_EN:
    case LABELANCHOR_WN:
        labelframe->labelTextY = padding;
        labelframe->labelBox.y = padding;
        break;
    case LABELANCHOR_E:
    case LABELANCHOR_W:
        labelframe->labelTextY = otherHeightT / 2;
        labelframe->labelBox.y = otherHeight / 2;
        break;
    default:
        labelframe->labelTextY = otherHeightT - padding;
        labelframe->labelBox.y = otherHeight - padding;
        break;
    }
}

/*
 * FrameDisplay --
 *
 *	This function is invoked to display a frame widget.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Commands are output to X to display the frame in its current mode.
 */
static void
FrameDisplay(
    ClientData clientData /* Information about widget. */)
{             
    tkoFrame *frame = clientData;
    int bdX1, bdY1, bdX2, bdY2, hlWidth;
    Pixmap pixmap;
    TkRegion clipRegion = NULL;

    if(frame->win == NULL || *(frame->win) == NULL)
        return;

    frame->flags &= ~REDRAW_PENDING;
    if(!Tk_IsMapped(*(frame->win))) {
        return;
    }

    /*
     * Highlight shall always be drawn if it exists, so do that first.
     */

    hlWidth = frame->highlightWidth;

    if(hlWidth != 0) {
GC  fgGC, bgGC;

        bgGC = Tk_GCForColor(frame->highlightBgColorPtr,
            Tk_WindowId(*(frame->win)));
        if(frame->flags & GOT_FOCUS) {
            fgGC = Tk_GCForColor(frame->highlightColorPtr,
                Tk_WindowId(*(frame->win)));
            TkpDrawHighlightBorder(*(frame->win), fgGC, bgGC, hlWidth,
                Tk_WindowId(*(frame->win)));
        } else {
            TkpDrawHighlightBorder(*(frame->win), bgGC, bgGC, hlWidth,
                Tk_WindowId(*(frame->win)));
        }
    }

    /*
     * If -background is set to "", no interior is drawn.
     */

    if(frame->border == NULL) {
        return;
    }

    if(frame->type != TYPE_LABELFRAME) {
        /*
         * Pass to platform specific draw function. In general, it just draws
         * a simple rectangle, but it may "theme" the background.
         */

      noLabel:
        TkpDrawFrame(*(frame->win), frame->border, hlWidth,
            frame->borderWidth, frame->relief);
    } else {
        tkoLabelframe *labelframe = (tkoLabelframe *) frame;

        if((labelframe->textPtr == NULL) && (labelframe->labelWin == NULL)) {
            goto noLabel;
        }
#ifndef TK_NO_DOUBLE_BUFFERING
        /*
         * In order to avoid screen flashes, this function redraws the frame
         * into off-screen memory, then copies it back on-screen in a single
         * operation. This means there's no point in time where the on-screen
         * image has been cleared.
         */

        pixmap = Tk_GetPixmap(frame->display, Tk_WindowId(*(frame->win)),
            Tk_Width(*(frame->win)), Tk_Height(*(frame->win)),
            Tk_Depth(*(frame->win)));
#else
        pixmap = Tk_WindowId(tkWin);
#endif /* TK_NO_DOUBLE_BUFFERING */

        /*
         * Clear the pixmap.
         */

        Tk_Fill3DRectangle(*(frame->win), pixmap, frame->border, 0, 0,
            Tk_Width(*(frame->win)), Tk_Height(*(frame->win)), 0,
            TK_RELIEF_FLAT);

        /*
         * Calculate how the label affects the border's position.
         */

        bdX1 = bdY1 = hlWidth;
        bdX2 = Tk_Width(*(frame->win)) - hlWidth;
        bdY2 = Tk_Height(*(frame->win)) - hlWidth;

        switch (labelframe->labelAnchor) {
        case LABELANCHOR_E:
        case LABELANCHOR_EN:
        case LABELANCHOR_ES:
            bdX2 -= (labelframe->labelBox.width - frame->borderWidth) / 2;
            break;
        case LABELANCHOR_N:
        case LABELANCHOR_NE:
        case LABELANCHOR_NW:
            /*
             * Since the glyphs of the text tend to be in the lower part we
             * favor a lower border position by rounding up.
             */

            bdY1 += (labelframe->labelBox.height - frame->borderWidth + 1) / 2;
            break;
        case LABELANCHOR_S:
        case LABELANCHOR_SE:
        case LABELANCHOR_SW:
            bdY2 -= (labelframe->labelBox.height - frame->borderWidth) / 2;
            break;
        default:
            bdX1 += (labelframe->labelBox.width - frame->borderWidth) / 2;
            break;
        }

        /*
         * Draw border
         */

        Tk_Draw3DRectangle(*(frame->win), pixmap, frame->border, bdX1, bdY1,
            bdX2 - bdX1, bdY2 - bdY1, frame->borderWidth, frame->relief);

        if(labelframe->labelWin == NULL) {
            /*
             * Clear behind the label
             */

            Tk_Fill3DRectangle(*(frame->win), pixmap,
                frame->border, labelframe->labelBox.x,
                labelframe->labelBox.y, labelframe->labelBox.width,
                labelframe->labelBox.height, 0, TK_RELIEF_FLAT);

            /*
             * Draw label. If there is not room for the entire label, use
             * clipping to get a nice appearance.
             */

            if((labelframe->labelBox.width < labelframe->labelReqWidth)
                || (labelframe->labelBox.height < labelframe->labelReqHeight)) {
                clipRegion = TkCreateRegion();
                TkUnionRectWithRegion(&labelframe->labelBox, clipRegion,
                    clipRegion);
                TkSetRegion(frame->display, labelframe->textGC, clipRegion);
            }

            Tk_DrawTextLayout(frame->display, pixmap,
                labelframe->textGC, labelframe->textLayout,
                labelframe->labelTextX + LABELSPACING,
                labelframe->labelTextY + LABELSPACING, 0, -1);

            if(clipRegion != NULL) {
                XSetClipMask(frame->display, labelframe->textGC, None);
                TkDestroyRegion(clipRegion);
            }
        } else {
            /*
             * Reposition and map the window (but in different ways depending
             * on whether the frame is the window's parent).
             */

            if(*(frame->win) == Tk_Parent(labelframe->labelWin)) {
                if((labelframe->labelBox.x != Tk_X(labelframe->labelWin))
                    || (labelframe->labelBox.y != Tk_Y(labelframe->labelWin))
                    || (labelframe->labelBox.width !=
                        Tk_Width(labelframe->labelWin))
                    || (labelframe->labelBox.height !=
                        Tk_Height(labelframe->labelWin))) {
                    Tk_MoveResizeWindow(labelframe->labelWin,
                        labelframe->labelBox.x,
                        labelframe->labelBox.y,
                        labelframe->labelBox.width,
                        labelframe->labelBox.height);
                }
                Tk_MapWindow(labelframe->labelWin);
            } else {
                Tk_MaintainGeometry(labelframe->labelWin, *(frame->win),
                    labelframe->labelBox.x, labelframe->labelBox.y,
                    labelframe->labelBox.width, labelframe->labelBox.height);
            }
        }

#ifndef TK_NO_DOUBLE_BUFFERING
        /*
         * Everything's been redisplayed; now copy the pixmap onto the screen
         * and free up the pixmap.
         */

        XCopyArea(frame->display, pixmap, Tk_WindowId(*(frame->win)),
            labelframe->textGC, hlWidth, hlWidth,
            (unsigned)(Tk_Width(*(frame->win)) - 2 * hlWidth),
            (unsigned)(Tk_Height(*(frame->win)) - 2 * hlWidth),
            hlWidth, hlWidth);
        Tk_FreePixmap(frame->display, pixmap);
#endif /* TK_NO_DOUBLE_BUFFERING */
    }

}

/*
 * FrameEventProc --
 *
 *	This function is invoked by the Tk dispatcher on structure changes to
 *	a frame. For frames with 3D borders, this function is also invoked for
 *	exposures.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	When the window gets deleted, internal structures get cleaned up.
 *	When it gets exposed, it is redisplayed.
 */
static void
FrameEventProc(
    ClientData clientData,     /* Information about window. */
    register XEvent * eventPtr)
{              /* Information about event. */
    tkoFrame *frame = clientData;
    if(eventPtr->type == DestroyNotify || frame->win == NULL
        || *(frame->win) == NULL)
        return;

    if((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
        goto redraw;
    } else if(eventPtr->type == ConfigureNotify) {
        FrameComputeGeometry(frame);
        goto redraw;
    } else if(eventPtr->type == FocusIn) {
        if(eventPtr->xfocus.detail != NotifyInferior) {
            frame->flags |= GOT_FOCUS;
            if(frame->highlightWidth > 0) {
                goto redraw;
            }
        }
    } else if(eventPtr->type == FocusOut) {
        if(eventPtr->xfocus.detail != NotifyInferior) {
            frame->flags &= ~GOT_FOCUS;
            if(frame->highlightWidth > 0) {
                goto redraw;
            }
        }
    } else if(eventPtr->type == ActivateNotify) {
        TkpSetMainMenubar(frame->interp, *(frame->win), frame->menuName);
    }
    return;

  redraw:
    if(!(frame->flags & REDRAW_PENDING)) {
        Tcl_DoWhenIdle(FrameDisplay, frame);
        frame->flags |= REDRAW_PENDING;
    }
}

/*
 * FrameMap --
 *
 *	This function is invoked as a when-idle handler to map a newly-created
 *	top-level frame.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The frame given by the clientData argument is mapped.
 */
static void
FrameMap(
    ClientData clientData)
{              /* Pointer to frame structure. */
tkoFrame *frame = clientData;
    if(frame->win == NULL || *(frame->win) == NULL)
        return;

    /*
     * Wait for all other background events to be processed before mapping
     * window. This ensures that the window's correct geometry will have been
     * determined before it is first mapped, so that the window manager
     * doesn't get a false idea of its desired geometry.
     */

    Tcl_Preserve(frame);
    while(1) {
        if(Tcl_DoOneEvent(TCL_IDLE_EVENTS) == 0) {
            break;
        }

        /*
         * After each event, make sure that the window still exists and quit
         * if the window has been destroyed.
         */
        if(frame->win == NULL || *(frame->win) == NULL) {
            Tcl_Release(frame);
            return;
        }
    }
    Tk_MapWindow(*(frame->win));
    Tcl_Release(frame);
}

/*
 * FrameStructureProc --
 *
 *	This function is invoked whenever StructureNotify events occur for a
 *	window that's managed as label for the frame. This procudure's only
 *	purpose is to clean up when windows are deleted.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The window is disassociated from the frame when it is deleted.
 */
static void
FrameStructureProc(
    ClientData clientData,     /* Pointer to record describing frame. */
    XEvent * eventPtr)
{              /* Describes what just happened. */
tkoLabelframe *labelframe = clientData;

    /*
     * This should only happen in a labelframe but it doesn't hurt to be
     * careful.
     */
    if((eventPtr->type == DestroyNotify)
        && (labelframe->frame.type == TYPE_LABELFRAME)) {
        FrameLabelwinRemove(labelframe);
    }
}

/*
 * FrameLabelwinRemove --
 *
 * Results:
 *  None.
 *
 * Side effects:
 */
static void
FrameLabelwinRemove(
    tkoLabelframe * labelframe)
{
tkoFrame *frame = (tkoFrame *) labelframe;
Tcl_Obj *arrayName = TkoWidgetOptionVar(frame->object);
    labelframe->labelWin = NULL;
    if(arrayName == NULL)
        return;
    Tcl_ObjSetVar2(frame->interp, arrayName, TkoObj._labelwidget, TkoObj.empty,
        TCL_GLOBAL_ONLY);
    FrameWorldChanged(labelframe);
}

/*
 * FrameRequestProc --
 *
 *	This function is invoked whenever a window that's associated with a
 *	frame changes its requested dimensions.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The size and location on the screen of the window may change depending
 *	on the options specified for the frame.
 */
static void
FrameRequestProc(
    ClientData clientData,     /* Pointer to record for frame. */
    Tk_Window tkWin)
{              /* Window that changed its desired size. */
tkoFrame *frame = clientData;

    FrameWorldChanged(frame);
}

/*
 * FrameLostSlaveProc --
 *
 *	This function is invoked by Tk whenever some other geometry claims
 *	control over a slave that used to be managed by us.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Forgets all frame-related information about the slave.
 */
static void
FrameLostSlaveProc(
    ClientData clientData,     /* Frame structure for slave window that was
                                * stolen away. */
    Tk_Window tkWin            /* Tk's handle for the slave window. */)
{
    tkoLabelframe *labelframe = clientData;

    /*
     * This should only happen in a labelframe but it doesn't hurt to be
     * careful.
     */

    if(labelframe->frame.type == TYPE_LABELFRAME) {
        Tk_DeleteEventHandler(labelframe->labelWin, StructureNotifyMask,
            FrameStructureProc, labelframe);
        if(tkWin != Tk_Parent(labelframe->labelWin)) {
            Tk_UnmaintainGeometry(labelframe->labelWin, tkWin);
        }
        Tk_UnmapWindow(labelframe->labelWin);
        FrameLabelwinRemove(labelframe);
    }
}

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

Added generic/tko/tkoGraph.c.


















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
/*
 * rbcGraph.c --
 *
 *      This module implements a graph widget for the rbc toolkit.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

/*
 * To do:
 *
 * 5) Surface, contour, and flow graphs
 *
 * 7) Arrows for line markers
 *
 */

#include "tkoGraph.h"

Tk_Uid rbcXAxisUid;
Tk_Uid rbcYAxisUid;
Tk_Uid rbcBarElementUid;
Tk_Uid rbcLineElementUid;
Tk_Uid rbcStripElementUid;
Tk_Uid rbcContourElementUid;
Tk_Uid rbcLineMarkerUid;
Tk_Uid rbcBitmapMarkerUid;
Tk_Uid rbcImageMarkerUid;
Tk_Uid rbcTextMarkerUid;
Tk_Uid rbcPolygonMarkerUid;
Tk_Uid rbcWindowMarkerUid;

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;

static Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};

#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
#define DEF_GRAPH_BORDERWIDTH       RBC_BORDERWIDTH
#define DEF_GRAPH_BUFFER_ELEMENTS   "1"
#define DEF_GRAPH_BUFFER_GRAPH	    "1"
#define DEF_GRAPH_CURSOR            "crosshair"
#define DEF_GRAPH_FONT              RBC_FONT_LARGE
#define DEF_GRAPH_HALO              "2m"
#define DEF_GRAPH_HALO_BAR          "0.1i"
#define DEF_GRAPH_HEIGHT            "4i"
#define DEF_GRAPH_HIGHLIGHT_BACKGROUND  RBC_NORMAL_BACKGROUND
#define DEF_GRAPH_HIGHLIGHT_BG_MONO RBC_NORMAL_BG_MONO
#define DEF_GRAPH_HIGHLIGHT_COLOR   "black"
#define DEF_GRAPH_HIGHLIGHT_WIDTH   "2"
#define DEF_GRAPH_INVERT_XY         "0"
#define DEF_GRAPH_JUSTIFY           "center"
#define DEF_GRAPH_MARGIN            "0"
#define DEF_GRAPH_MARGIN_VAR        (char *)NULL
#define DEF_GRAPH_PLOT_BACKGROUND   "white"
#define DEF_GRAPH_PLOT_BG_MONO      "white"
#define DEF_GRAPH_PLOT_BW_COLOR     RBC_BORDERWIDTH
#define DEF_GRAPH_PLOT_BW_MONO      "0"
#define DEF_GRAPH_PLOT_PADX         "8"
#define DEF_GRAPH_PLOT_PADY         "8"
#define DEF_GRAPH_PLOT_RELIEF       "sunken"
#define DEF_GRAPH_RELIEF            "flat"
#define DEF_GRAPH_SHADOW_COLOR      (char *)NULL
#define DEF_GRAPH_SHADOW_MONO       (char *)NULL
#define DEF_GRAPH_SHOW_VALUES       "no"
#define DEF_GRAPH_TAKE_FOCUS        ""
#define DEF_GRAPH_TITLE             (char *)NULL
#define DEF_GRAPH_TITLE_COLOR       RBC_NORMAL_FOREGROUND
#define DEF_GRAPH_TITLE_MONO        RBC_NORMAL_FG_MONO
#define DEF_GRAPH_WIDTH             "5i"
#define DEF_GRAPH_DATA              (char *)NULL
#define DEF_GRAPH_DATA_COMMAND      (char *)NULL

static RbcSwitchParseProc StringToFormat;
static RbcSwitchCustom formatSwitch = {
    StringToFormat, (RbcSwitchFreeProc *) NULL, (ClientData) 0,
};

/*
 * SnapData --
 */
typedef struct SnapData {
    char *name;
    int width, height;
    int format;
} SnapData;

enum SnapFormats { FORMAT_PHOTO, FORMAT_EMF, FORMAT_WMF };

/*
 * snapSwitches --
 */
static RbcSwitchSpec snapSwitches[] = {
    {RBC_SWITCH_INT_POSITIVE, "-width", Tk_Offset(SnapData, width), 0},
    {RBC_SWITCH_INT_POSITIVE, "-height", Tk_Offset(SnapData, height), 0},
    {RBC_SWITCH_CUSTOM, "-format", Tk_Offset(SnapData, format), 0,
        &formatSwitch},
    {RBC_SWITCH_END, NULL, 0, 0}
};

static Tcl_IdleProc DisplayGraph;
static Tk_EventProc GraphEventProc;

static RbcBindPickProc PickEntry;
static RbcTileChangedProc TileChangedProc;
/*
* Methods
*/
static int GraphConstructor(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphDestructor(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod_tko_configure(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod_style(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod_barmode(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod_barwidth(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod_plotpadx(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod_plotpady(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod_shadow(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);
static int GraphMethod_tile(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[]);

/*
 * Functions
 */
static void AdjustAxisPointers(
    RbcGraph * graph);
static void DrawMargins(
    RbcGraph * graph,
    Drawable drawable);
static void DrawPlotRegion(
    RbcGraph * graph,
    Drawable drawable);
static void UpdateMarginTraces(
    RbcGraph * graph);
static int XAxisOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int X2AxisOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int YAxisOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int Y2AxisOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int BarOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int LineOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int ElementOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int ExtentsOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int InsideOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int InvtransformOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int TransformOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
static int SnapOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv);
#ifdef __WIN32
static int InitMetaFileHeader(
    Tk_Window tkwin,
    int width,
    int height,
    APMHEADER * mfhPtr);
static int CreateAPMetaFile(
    Tcl_Interp * interp,
    HANDLE hMetaFile,
    HDC hDC,
    APMHEADER * mfhPtr,
    char *fileName);
#endif
static void GraphMetaDestroy(
    RbcGraph * graph);
static void
GraphMetaDelete(
    ClientData clientData)
{
    Tcl_EventuallyFree(clientData, (Tcl_FreeProc *) GraphMetaDestroy);
}

/*
 * graphMeta --
 */
static Tcl_ObjectMetadataType graphMeta = {
    TCL_OO_METADATA_VERSION_CURRENT,
    "GraphMeta",
    GraphMetaDelete,
    NULL
};

/*
 * RbcGraphFromObject --
 *
 * Return:
 *  RbcGraph structure from object meta data.
 */
RbcGraph *
RbcGraphFromObject(
    Tcl_Object object)
{
    return (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta);
}

/*
 * graphOptionDefine --
 *
 * Options and option methods created in class constructor.
 */
static tkoWidgetOptionDefine graphOptionDefine[] = {
    {"-class", "class", "Class", "TkoGraph", TKO_OPTION_READONLY, NULL,
	NULL, NULL, TKO_SET_CLASS, NULL, 0},
    {"-style", "style", "Style", "line", TKO_OPTION_READONLY, NULL,
	NULL, GraphMethod_style, 0, NULL, 0},
    {"-aspect", "aspect", "Aspect", DEF_GRAPH_ASPECT_RATIO, 0, NULL,
	NULL, NULL, TKO_SET_DOUBLE, &graphMeta, offsetof(RbcGraph, aspect)},
    {"-background", "background", "Background", DEF_GRAPH_BACKGROUND, 0, NULL,
	NULL, NULL, TKO_SET_3DBORDER, &graphMeta, offsetof(RbcGraph, border)},
    {"-barmode", "barMode", "BarMode", DEF_GRAPH_BAR_MODE, 0, NULL,
	NULL, GraphMethod_barmode, 0, NULL, 0},
    {"-barwidth", "barWidth", "BarWidth", DEF_GRAPH_BAR_WIDTH, 0, NULL,
	NULL, GraphMethod_barwidth, 0, NULL, 0},
    {"-baseline", "baseline", "Baseline", DEF_GRAPH_BAR_BASELINE, 0, NULL,
	NULL, NULL, TKO_SET_DOUBLE, &graphMeta, offsetof(RbcGraph, baseline)},
    {"-bd", "-borderwidth", NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0},
    {"-bg", "-background", NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0},
    {"-bm", "-bottommargin", NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0},
    {"-borderwidth", "borderWidth", "BorderWidth", DEF_GRAPH_BORDERWIDTH, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph, borderWidth)},
    {"-bottommargin", "bottomMargin", "Margin", DEF_GRAPH_MARGIN, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph,margins[RBC_MARGIN_BOTTOM].reqSize)},
    {"-bottomvariable", "bottomVariable", "BottomVariable", DEF_GRAPH_MARGIN_VAR, 0, NULL,
	NULL, NULL, TKO_SET_STRINGNULL, &graphMeta, offsetof(RbcGraph,margins[RBC_MARGIN_BOTTOM].varName)},
    {"-bufferelements", "bufferElements", "BufferElements", DEF_GRAPH_BUFFER_ELEMENTS, 0, NULL,
	NULL, NULL, TKO_SET_BOOLEAN, &graphMeta, offsetof(RbcGraph, backingStore)},
    {"-buffergraph", "bufferGraph", "BufferGraph", DEF_GRAPH_BUFFER_GRAPH, 0, NULL,
	NULL, NULL, TKO_SET_BOOLEAN, &graphMeta, offsetof(RbcGraph, doubleBuffer)},
    {"-cursor", "cursor", "Cursor", DEF_GRAPH_CURSOR, 0, NULL,
	NULL, NULL, TKO_SET_CURSOR, &graphMeta, offsetof(RbcGraph, cursor)},
    {"-fg", "-foreground", NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0},
    {"-font", "font", "Font", DEF_GRAPH_FONT, 0, NULL,
	NULL, NULL, TKO_SET_FONT, &graphMeta, offsetof(RbcGraph, titleTextStyle.font)},
    {"-foreground", "foreground", "Foreground", DEF_GRAPH_TITLE_COLOR, 0, NULL,
	NULL, NULL, TKO_SET_XCOLOR, &graphMeta, offsetof(RbcGraph, titleTextStyle.color)},
    {"-halo", "halo", "Halo", DEF_GRAPH_HALO, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph, halo)},
    {"-height", "height", "Height", DEF_GRAPH_HEIGHT, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph, reqHeight)},
    {"-highlightbackground", "highlightBackground", "HighlightBackground", DEF_GRAPH_HIGHLIGHT_BACKGROUND, 0, NULL,
	NULL, NULL, TKO_SET_XCOLOR, &graphMeta, offsetof(RbcGraph, highlightBgColor)},
    {"-highlightcolor", "highlightColor", "HighlightColor", DEF_GRAPH_HIGHLIGHT_COLOR, 0, NULL,
	NULL, NULL, TKO_SET_XCOLOR, &graphMeta, offsetof(RbcGraph, highlightColor)},
    {"-highlightthickness", "highlightThickness", "HighlightThickness", DEF_GRAPH_HIGHLIGHT_WIDTH, 0, NULL,
	NULL, NULL, TKO_SET_PIXEL, &graphMeta, offsetof(RbcGraph, highlightWidth)},
    {"-invertxy", "invertXY", "InvertXY", DEF_GRAPH_INVERT_XY, 0, NULL,
	NULL, NULL, TKO_SET_BOOLEAN, &graphMeta, offsetof(RbcGraph, inverted)},
    {"-justify", "justify", "Justify", DEF_GRAPH_JUSTIFY, 0, NULL,
	NULL, NULL, TKO_SET_JUSTIFY, &graphMeta, offsetof(RbcGraph,titleTextStyle.justify)},
    {"-leftmargin", "leftMargin", "Margin", DEF_GRAPH_MARGIN, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph,margins[RBC_MARGIN_LEFT].reqSize)},
    {"-leftvariable", "leftVariable", "LeftVariable", DEF_GRAPH_MARGIN_VAR, 0, NULL,
	NULL, NULL, TKO_SET_STRINGNULL, &graphMeta, offsetof(RbcGraph,margins[RBC_MARGIN_LEFT].varName)},
    {"-lm", "-leftmargin", NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0},
    {"-plotbackground", "plotBackground", "Background", DEF_GRAPH_PLOT_BG_MONO, 0, NULL,
	NULL, NULL, TKO_SET_XCOLOR, &graphMeta, offsetof(RbcGraph, plotBg)},
    {"-plotborderwidth", "plotBorderWidth", "BorderWidth", DEF_GRAPH_PLOT_BW_COLOR, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph,plotBorderWidth)},
    {"-plotpadx", "plotPadX", "PlotPad", DEF_GRAPH_PLOT_PADX, 0, NULL,
	NULL, GraphMethod_plotpadx, 0, NULL, 0},
    {"-plotpady", "plotPadY", "PlotPad", DEF_GRAPH_PLOT_PADY, 0, NULL,
	NULL, GraphMethod_plotpady, 0, NULL, 0},
    {"-plotrelief", "plotRelief", "Relief", DEF_GRAPH_PLOT_RELIEF, 0, NULL,
	NULL, NULL, TKO_SET_RELIEF, &graphMeta, offsetof(RbcGraph, plotRelief)},
    {"-relief", "relief", "Relief", DEF_GRAPH_RELIEF, 0, NULL,
	NULL, NULL, TKO_SET_RELIEF, &graphMeta, offsetof(RbcGraph, relief)},
    {"-rightmargin", "rightMargin", "Margin", DEF_GRAPH_MARGIN, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph,margins[RBC_MARGIN_RIGHT].reqSize)},
    {"-rightvariable", "rightVariable", "RightVariable", DEF_GRAPH_MARGIN_VAR, 0, NULL,
	NULL, NULL, TKO_SET_STRINGNULL, &graphMeta, offsetof(RbcGraph,margins[RBC_MARGIN_RIGHT].varName)},
    {"-rm", "-rightmargin", NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0},
    {"-shadow", "shadow", "Shadow", DEF_GRAPH_SHADOW_COLOR, 0, NULL,
	NULL, GraphMethod_shadow, 0, NULL, 0},
    {"-takefocus", "takeFocus", "TakeFocus", DEF_GRAPH_TAKE_FOCUS, 0, NULL,
	NULL, NULL, TKO_SET_STRINGNULL, &graphMeta, offsetof(RbcGraph, takeFocus)},
    {"-tile", "tile", "Tile", NULL, 0, NULL,
	NULL, GraphMethod_tile, 0, NULL, 0},
    {"-title", "title", "Title", DEF_GRAPH_TITLE, 0, NULL,
	NULL, NULL, TKO_SET_STRINGNULL, &graphMeta, offsetof(RbcGraph, title)},
    {"-tm", "-topmargin", NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0},
    {"-topmargin", "-topmargin", "Margin", DEF_GRAPH_MARGIN, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph,margins[RBC_MARGIN_TOP].reqSize)},
    {"-topvariable", "topVariable", "TopVariable", DEF_GRAPH_MARGIN_VAR, 0, NULL,
	NULL, NULL, TKO_SET_STRINGNULL, &graphMeta, offsetof(RbcGraph,margins[RBC_MARGIN_TOP].varName)},
    {"-width", "width", "Width", DEF_GRAPH_WIDTH, 0, NULL,
	NULL, NULL, TKO_SET_PIXELNONEGATIV, &graphMeta, offsetof(RbcGraph, reqWidth)},
    {NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, 0}
};

/*
 * graphMethods --
 *
 * Methods created in class constructor.
 */
static Tcl_MethodType graphMethods[] = {
    {TCL_OO_METHOD_VERSION_CURRENT, NULL, GraphConstructor, NULL, NULL},
    {TCL_OO_METHOD_VERSION_CURRENT, NULL, GraphDestructor, 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, "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},
    {TCL_OO_METHOD_VERSION_CURRENT, "_tko_configure", GraphMethod_tko_configure,
            NULL, NULL},
    {-1, NULL, NULL, NULL, NULL}
};

/*
 * Tko_GraphInit --
 *
 *  Initializer for the graph widget package.
 *
 * Results:
 *  A standard Tcl result.
 *
 * Side Effects:
 *  Tcl commands created
 */
int
Tko_GraphInit(
    Tcl_Interp * interp)
{
Tcl_Class clazz;
Tcl_Object object;
static const char *initScript =
    "::oo::class create ::graph {superclass ::tko::widget; variable tko; {*}$::tko::unknown}";

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

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

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

    /* Create widget class. */
    if(Tcl_Eval(interp, initScript) != TCL_OK) {
        return TCL_ERROR;
    }
    /*
     * Get class object
     */
    if((object = Tcl_GetObjectFromObj(interp, TkoObj.graph)) == NULL
        || (clazz = Tcl_GetObjectAsClass(object)) == NULL) {
        return TCL_ERROR;
    }
    /*
     * Add methods and options
     */
    if(TkoWidgetClassDefine(interp, clazz, Tcl_GetObjectName(interp, object),
            graphMethods, graphOptionDefine) != TCL_OK) {
        return TCL_ERROR;
    }

    return TCL_OK;
}

/*
 * GraphConstructor --
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphConstructor(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tcl_Object object;
    RbcGraph *graph;
    int skip;
    Tcl_Obj *myObjv[5];

    /* Get current object. Should not fail? */
    if((object = Tcl_ObjectContextObject(context)) == NULL) {
        return TCL_ERROR;
    }
    skip = Tcl_ObjectContextSkippedArgs(context);
    /* Check calling args */
    if(skip != 3 || objc != 5 || strcmp("create", Tcl_GetString(objv[1])) != 0) {
        Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
        return TCL_ERROR;
    }
    if(objc < 3 || strcmp("create", Tcl_GetString(objv[1])) != 0) {
        Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
        return TCL_ERROR;
    }
    /* Get own options */
    myObjv[3] =
        Tcl_ObjGetVar2(interp, TkoObj.tko_options, TkoObj.graph,
        TCL_GLOBAL_ONLY);
    if(myObjv[3] == NULL) {
        return TCL_ERROR;
    }

    /*
     * Create and initialize the graph data structure.
     */
    graph = RbcCalloc(1, sizeof(RbcGraph));
    assert(graph);
    graph->interp = interp;
    graph->win = NULL;
    graph->classUid = rbcLineElementUid;
    graph->chartStyle = "line";
    graph->object = object;
    graph->display = None;
    graph->flags = (RBC_RESET_WORLD);
    graph->cursor = None;
    graph->inset = 0;
    graph->borderWidth = 0;
    graph->relief = TK_RELIEF_FLAT;
    graph->highlightWidth = 2;
    graph->cursor = None;
    graph->border = NULL;
    graph->highlightBgColor = NULL;
    graph->highlightColor = NULL;
    graph->title = NULL;
    graph->titleX = graph->titleY = 0;
    RbcInitTextStyle(&graph->titleTextStyle);
    graph->takeFocus = NULL;
    graph->reqWidth = graph->reqHeight = 0;
    graph->width = graph->height = 0;
    Tcl_InitHashTable(&graph->penTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graph->axes.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graph->axes.tagTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graph->elements.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graph->elements.tagTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graph->markers.table, TCL_STRING_KEYS);
    Tcl_InitHashTable(&graph->markers.tagTable, TCL_STRING_KEYS);
    graph->elements.displayList = RbcChainCreate();
    graph->markers.displayList = RbcChainCreate();
    graph->axes.displayList = RbcChainCreate();
    graph->classUid = NULL;
    graph->chartStyle = NULL;
    graph->bindTable = NULL;
    graph->nextMarkerId = 1;
    graph->axisChain[0] = NULL; /* set in RbcDefaultAxes() */
    graph->axisChain[1] = NULL; /* set in RbcDefaultAxes() */
    graph->axisChain[2] = NULL; /* set in RbcDefaultAxes() */
    graph->axisChain[3] = NULL; /* set in RbcDefaultAxes() */
    graph->margins[RBC_MARGIN_BOTTOM].site = RBC_MARGIN_BOTTOM;
    graph->margins[RBC_MARGIN_LEFT].site = RBC_MARGIN_LEFT;
    graph->margins[RBC_MARGIN_TOP].site = RBC_MARGIN_TOP;
    graph->margins[RBC_MARGIN_RIGHT].site = RBC_MARGIN_RIGHT;
    graph->postscript = NULL;
    graph->legend = NULL;
    graph->crosshairs = NULL;
    graph->gridPtr = NULL;
    graph->halo = 0;
    graph->inverted = 0;
    graph->tile = NULL;
    graph->drawGC = NULL;
    graph->fillGC = NULL;
    graph->plotBorderWidth = 0;
    graph->plotRelief = TK_RELIEF_SUNKEN;
    graph->plotBg = NULL;
    graph->plotFillGC = NULL;
    graph->aspect = 0.0;
    graph->left = graph->right = 0;
    graph->top = graph->bottom = 0;
    graph->padX.side1 = graph->padX.side2 = 8;
    graph->vRange = graph->vOffset = 0;
    graph->padY.side1 = graph->padY.side2 = 8;
    graph->hRange = graph->hOffset = 0;
    graph->vScale = graph->hScale = 0.;
    graph->doubleBuffer = TRUE;
    graph->backingStore = TRUE;
    graph->backPixmap = None;
    graph->backWidth = graph->backHeight = 0;
    graph->baseline = 0.;
    graph->barWidth = 0.;
    graph->mode = MODE_INFRONT;
    graph->freqArr = NULL;
/*      Tcl_HashTable   freqTable; */
    graph->nStacks = 0;

    Tcl_ObjectSetMetadata(object, &graphMeta, (ClientData) graph);

    graph->win = TkoWidgetWindow(object);
    if(graph)
        /* call next constructor */
        myObjv[0] = objv[0];
    myObjv[1] = objv[1];
    myObjv[2] = objv[2];
    myObjv[3] = Tcl_DuplicateObj(myObjv[3]);
    Tcl_IncrRefCount(myObjv[3]);
    Tcl_ListObjAppendList(interp, myObjv[3], objv[objc - 2]);
    myObjv[4] = objv[4];
    if(Tcl_ObjectContextInvokeNext(interp, context, objc, myObjv,
            skip) != TCL_OK) {
        Tcl_DecrRefCount(myObjv[3]);
        return TCL_ERROR;
    }
    Tcl_DecrRefCount(myObjv[3]);
    graph->win = TkoWidgetWindow(object);
    if(graph->win == NULL || *(graph->win) == NULL) {
        return TCL_ERROR;
    }
    if((graph->display = Tk_Display(*(graph->win))) == None) {
        return TCL_ERROR;
    }

    RbcSetWindowInstanceData(*(graph->win), graph);

    /*
     * Init pens
     */
    if(RbcCreatePen(graph, "activeLine", rbcLineElementUid, 0,
            (const char **)NULL) == NULL) {
        return TCL_ERROR;
    }
    if(RbcCreatePen(graph, "activeBar", rbcBarElementUid, 0,
            (const char **)NULL) == NULL) {
        return TCL_ERROR;
    }
    /*
     * Create axis
     */
    if(RbcDefaultAxes(graph) != TCL_OK) {
        return TCL_ERROR;
    }
    AdjustAxisPointers(graph);

    if(RbcCreatePostScript(graph) != TCL_OK) {
        return TCL_ERROR;
    }
    if(RbcCreateCrosshairs(graph) != TCL_OK) {
        return TCL_ERROR;
    }
    if(RbcCreateLegend(graph) != TCL_OK) {
        return TCL_ERROR;
    }
    if(RbcCreateGrid(graph) != TCL_OK) {
        return TCL_ERROR;
    }
    Tk_CreateEventHandler(*(graph->win),
        ExposureMask | StructureNotifyMask | FocusChangeMask, GraphEventProc,
        graph);

    graph->bindTable =
        RbcCreateBindingTable(interp, *(graph->win), graph, PickEntry);

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

/*
 * GraphDestructor --
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphDestructor(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tcl_Object object;
    int skip;
    RbcGraph *graph;
    Tk_Window tkWin = NULL;

    /* Get current object. Should not fail? */
    if((object = Tcl_ObjectContextObject(context)) == NULL)
        return TCL_ERROR;
    skip = Tcl_ObjectContextSkippedArgs(context);

    if((graph = (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) != NULL) {
        Tcl_Preserve(graph);

        if(graph->win) {
            tkWin = *(graph->win);
            graph->win = NULL;
        }
        if(tkWin) {
            Tk_DeleteEventHandler(tkWin,
                ExposureMask | StructureNotifyMask | FocusChangeMask,
                GraphEventProc, graph);
        }

        Tcl_Release(graph);
        Tcl_ObjectSetMetadata(object, &graphMeta, NULL);
    }
    /* ignore errors */
    Tcl_ObjectContextInvokeNext(interp, context, objc, objv, skip);

    return TCL_OK;
}

/*
* GraphMetaDestroy --
*
*      This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
*      to clean up the internal structure of a graph at a safe time
*      (when no-one is using it anymore).
*
* Results:
*      None.
*
* Side effects:
*      Everything associated with the widget is freed up.
*/
static void
GraphMetaDestroy(
    RbcGraph * graph)
{
    if(graph->flags & RBC_REDRAW_PENDING) {
        Tcl_CancelIdleCall(DisplayGraph, graph);
    }
    if(graph->border != NULL) {
        Tk_Free3DBorder(graph->border);
    }
    if(graph->highlightBgColor != NULL) {
        Tk_FreeColor(graph->highlightBgColor);
    }
    if(graph->highlightColor != NULL) {
        Tk_FreeColor(graph->highlightColor);
    }
    if(graph->plotBg != NULL) {
        Tk_FreeColor(graph->plotBg);
    }
    /*
     * Destroy the individual components of the graph: elements, markers,
     * X and Y axes, legend, display lists etc.
     */
    RbcDestroyMarkers(graph);
    RbcDestroyElements(graph);
    RbcDestroyAxes(graph);      /* take care of *axisChain */
    RbcDestroyPens(graph);

    if(graph->legend != NULL) {
        RbcDestroyLegend(graph);
    }
    if(graph->postscript != NULL) {
        RbcDestroyPostScript(graph);
    }
    if(graph->crosshairs != NULL) {
        RbcDestroyCrosshairs(graph);
    }
    if(graph->gridPtr != NULL) {
        RbcDestroyGrid(graph);
    }
    if(graph->bindTable != NULL) {
        RbcDestroyBindingTable(graph->bindTable);
    }

    /* Release allocated X resources and memory. */
    if(graph->display != None) {
        if(graph->cursor != None) {
            Tk_FreeCursor(graph->display, graph->cursor);
        }
        if(graph->drawGC != NULL) {
            Tk_FreeGC(graph->display, graph->drawGC);
        }
        if(graph->fillGC != NULL) {
            Tk_FreeGC(graph->display, graph->fillGC);
        }
        if(graph->plotFillGC != NULL) {
            Tk_FreeGC(graph->display, graph->plotFillGC);
        }
        RbcFreeTextStyle(graph->display, &graph->titleTextStyle);
        if(graph->backPixmap != None) {
            Tk_FreePixmap(graph->display, graph->backPixmap);
        }
    }
    if(graph->freqArr != NULL) {
        ckfree((char *)graph->freqArr);
    }
    if(graph->title != NULL) {
        ckfree(graph->title);
    }
    if(graph->takeFocus != NULL) {
        ckfree(graph->takeFocus);
    }
    if(graph->nStacks > 0) {
        Tcl_DeleteHashTable(&graph->freqTable);
    }
    if(graph->tile != NULL) {
        RbcFreeTile(graph->tile);
    }
    ckfree((char *)graph);
}

/*
* GraphMethod_tko_configure --
*
*      Allocates resources for the graph.
*
* Results:
*      None.
*
* Side effects:
*      Configuration information, such as text string, colors, font,
*      etc. get set for graph;  old resources get freed, if there
*      were any.  The graph is redisplayed.
*/
static int
GraphMethod_tko_configure(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tcl_Object object;
    RbcGraph *graph;
    XColor *colorPtr;
    GC  newGC;
    XGCValues gcValues;
    unsigned long gcMask;

    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (graph =
            (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) == NULL) {
        return TCL_ERROR;
    }
    if(graph->win == NULL || *(graph->win) == NULL)
        return TCL_ERROR;

    /* Don't allow negative bar widths. Reset to an arbitrary value (0.1) */
    if(graph->barWidth <= 0.0) {
        graph->barWidth = 0.1;
    }
    graph->inset = graph->borderWidth + graph->highlightWidth + 1;
    if((graph->reqHeight != Tk_ReqHeight(*(graph->win)))
        || (graph->reqWidth != Tk_ReqWidth(*(graph->win)))) {
        Tk_GeometryRequest(*(graph->win), graph->reqWidth, graph->reqHeight);
    }
    Tk_SetInternalBorder(*(graph->win), graph->borderWidth);
    colorPtr = Tk_3DBorderColor(graph->border);

    if(graph->title != NULL) {
    int w, h;

        RbcGetTextExtents(&graph->titleTextStyle, graph->title, &w, &h);
        graph->titleTextStyle.height = h + 10;
    } else {
        graph->titleTextStyle.width = graph->titleTextStyle.height = 0;
    }

    /*
     * Create GCs for interior and exterior regions, and a background
     * GC for clearing the margins with XFillRectangle
     */

    /* Margin GC */

    gcValues.foreground = graph->titleTextStyle.color->pixel;
    gcValues.background = colorPtr->pixel;
    gcMask = (GCForeground | GCBackground);
    newGC = Tk_GetGC(*(graph->win), gcMask, &gcValues);
    if(graph->drawGC != NULL) {
        Tk_FreeGC(graph->display, graph->drawGC);
    }
    graph->drawGC = newGC;

    /* Plot fill GC (Background = Foreground) */

    gcValues.foreground = graph->plotBg->pixel;
    newGC = Tk_GetGC(*(graph->win), gcMask, &gcValues);
    if(graph->plotFillGC != NULL) {
        Tk_FreeGC(graph->display, graph->plotFillGC);
    }
    graph->plotFillGC = newGC;

    /* Margin fill GC (Background = Foreground) */

    gcValues.foreground = colorPtr->pixel;
    gcValues.background = graph->titleTextStyle.color->pixel;
    newGC = Tk_GetGC(*(graph->win), gcMask, &gcValues);
    if(graph->fillGC != NULL) {
        Tk_FreeGC(graph->display, graph->fillGC);
    }
    graph->fillGC = newGC;
    if(graph->tile != NULL) {
        RbcSetTileChangedProc(graph->tile, TileChangedProc, graph);
    }

    RbcResetTextStyle(*(graph->win), &graph->titleTextStyle);

    if(RbcConfigModified(configSpecs, "-invertxy", (char *)NULL)) {

        /*
         * If the -inverted option changed, we need to readjust the pointers
         * to the axes and recompute the their scales.
         */

        AdjustAxisPointers(graph);
        graph->flags |= RBC_RESET_AXES;
    }
    if((!graph->backingStore) && (graph->backPixmap != None)) {

        /*
         * Free the pixmap if we're not buffering the display of elements
         * anymore.
         */

        Tk_FreePixmap(graph->display, graph->backPixmap);
        graph->backPixmap = None;
    }
    /*
     * Reconfigure the crosshairs, just in case the background color of
     * the plotarea has been changed.
     */
    RbcConfigureCrosshairs(graph);

    /*
     *  Update the layout of the graph (and redraw the elements) if
     *  any of the following graph options which affect the size of
     *  the plotting area has changed.
     *
     *      -aspect
     *      -borderwidth, -plotborderwidth
     *      -font, -title
     *      -width, -height
     *      -invertxy
     *      -bottommargin, -leftmargin, -rightmargin, -topmargin,
     *      -barmode, -barwidth
     */
    if(RbcConfigModified(configSpecs, "-invertxy", "-title", "-font",
            "-*margin", "-*width", "-height", "-barmode", "-*pad*", "-aspect",
            (char *)NULL)) {
        graph->flags |= RBC_RESET_WORLD;
    }
    if(RbcConfigModified(configSpecs, "-plotbackground", (char *)NULL)) {
        graph->flags |= RBC_REDRAW_BACKING_STORE;
    }
    graph->flags |= RBC_REDRAW_WORLD;
    RbcEventuallyRedrawGraph(graph);
    return TCL_OK;
}

/*
 * GraphMethod --
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphMethod(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    int cmdIndex, result;
    RbcOp proc;
    int i;
    const char **myArgv;
    static const char *const graphCmdNames[] = {
        "axis", "bar",
        "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_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
    };

    RbcGraph *graph =
        (RbcGraph *) Tcl_ObjectGetMetadata(Tcl_ObjectContextObject(context),
        &graphMeta);

    /*
     * 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_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(graph);
    result = (*proc) (graph, interp, objc, myArgv);
    Tcl_Release(graph);
    ckfree(myArgv);
    return result;
}

/*
 * GraphMethod_style --
 *
 *  Process -style option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphMethod_style(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    const char *chPtr;
    Tcl_Object object;
    RbcGraph *graph;
    Tcl_Obj *value;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (graph =
            (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }

    chPtr = Tcl_GetString(value);
    if(strcmp(chPtr, "line") == 0) {
        graph->classUid = rbcLineElementUid;
        graph->chartStyle = "line";
    } else if(strcmp(chPtr, "bar") == 0) {
        graph->classUid = rbcBarElementUid;
        graph->chartStyle = "bar";
    } else if(strcmp(chPtr, "chart") == 0) {
        graph->classUid = rbcStripElementUid;
        graph->chartStyle = "strip";
    } else {
        Tcl_SetObjResult(interp,
            Tcl_ObjPrintf("wrong -style option, should be line,bar or chart"));
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 * GraphMethod_barmode --
 *
 *  Process -barmode option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphMethod_barmode(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    const char *string;
    int length;
    Tcl_Object object;
    RbcGraph *graph;
    Tcl_Obj *value;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (graph =
            (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }

    string = Tcl_GetStringFromObj(value, &length);
    if((string[0] == 'n') && (strncmp(string, "normal", length) == 0)) {
        graph->mode = MODE_INFRONT;
    } else if((string[0] == 'i') && (strncmp(string, "infront", length) == 0)) {
        graph->mode = MODE_INFRONT;
    } else if((string[0] == 's') && (strncmp(string, "stacked", length) == 0)) {
        graph->mode = MODE_STACKED;
    } else if((string[0] == 'a') && (strncmp(string, "aligned", length) == 0)) {
        graph->mode = MODE_ALIGNED;
    } else if((string[0] == 'o') && (strncmp(string, "overlap", length) == 0)) {
        graph->mode = MODE_OVERLAP;
    } else {
        Tcl_AppendResult(interp, "bad mode argument \"", string,
            "\": should be \"infront\", \"stacked\", \"overlap\", or \"aligned\"",
            (char *)NULL);
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 * GraphMethod_barwidth --
 *
 *  Process -barwidth option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphMethod_barwidth(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    double dblVal;
    Tcl_Obj *array;
    Tcl_Object object;
    RbcGraph *graph;
    Tcl_Obj *value;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (graph =
            (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }

    if(Tcl_GetDoubleFromObj(interp, value, &dblVal) != TCL_OK) {
        return TCL_ERROR;
    }
    if((array = TkoWidgetOptionVar(object)) == NULL) {
        return TCL_ERROR;
    }
    if(dblVal < 0.1) {
        dblVal = 0.1;
    }
    Tcl_ObjSetVar2(interp, array, objv[objc - 1], Tcl_NewDoubleObj(dblVal),
        TCL_GLOBAL_ONLY);
    graph->barWidth = dblVal;
    return TCL_OK;
}

/*
 * GraphMethod_plotpadx --
 *
 *  Process -plotpadx option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphMethod_plotpadx(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tcl_Obj *array;
    Tcl_Object object;
    RbcGraph *graph;
    Tcl_Obj *value;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (graph =
            (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }

    if((array = TkoWidgetOptionVar(object)) == NULL) {
        return TCL_ERROR;
    }
    if(RbcGraphOptionSetPad(interp, object, value, &graph->padX) != TCL_OK) {
        return TCL_ERROR;
    }
    Tcl_ObjSetVar2(interp, array, objv[objc - 1],
        Tcl_ObjPrintf("%d %d", graph->padX.side1, graph->padX.side2),
        TCL_GLOBAL_ONLY);
    return TCL_OK;
}

/*
 * GraphMethod_plotpady --
 *
 *  Process -plotpady option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphMethod_plotpady(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tcl_Obj *array;
    Tcl_Object object;
    RbcGraph *graph;
    Tcl_Obj *value;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (graph =
            (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }

    if((array = TkoWidgetOptionVar(object)) == NULL) {
        return TCL_ERROR;
    }
    if(RbcGraphOptionSetPad(interp, object, value, &graph->padY) != TCL_OK) {
        return TCL_ERROR;
    }
    Tcl_ObjSetVar2(interp, array, objv[objc - 1],
        Tcl_ObjPrintf("%d %d", graph->padY.side1, graph->padY.side2),
        TCL_GLOBAL_ONLY);
    return TCL_OK;
}

/*
 * GraphMethod_shadow --
 *
 * Process -shadow option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphMethod_shadow(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tcl_Obj *array;
    Tcl_Object object;
    RbcGraph *graph;
    Tcl_Obj *value;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (graph =
            (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }

    if((array = TkoWidgetOptionVar(object)) == NULL) {
        return TCL_ERROR;
    }
    if(RbcGraphOptionSetShadow(interp, object, value,
            &graph->titleTextStyle.shadow) != TCL_OK) {
        return TCL_ERROR;
    }
    if(graph->titleTextStyle.shadow.color != NULL) {
        Tcl_ObjSetVar2(interp, array, objv[objc - 1],
            Tcl_ObjPrintf("%s %d",
                Tk_NameOfColor(graph->titleTextStyle.shadow.color),
                graph->titleTextStyle.shadow.offset), TCL_GLOBAL_ONLY);
    } else {
        Tcl_ObjSetVar2(interp, array, objv[objc - 1], TkoObj.empty,
            TCL_GLOBAL_ONLY);
    }
    return TCL_OK;
}

/*
 * GraphMethod_tile --
 *
 *  Process -tile option.
 *
 * Results:
 *  TODO
 *
 * Side effects:
 *  TODO
 */
static int
GraphMethod_tile(
    ClientData clientData,
    Tcl_Interp * interp,
    Tcl_ObjectContext context,
    int objc,
    Tcl_Obj * const objv[])
{
    Tcl_Object object;
    RbcGraph *graph;
    Tcl_Obj *value;
    if((object = Tcl_ObjectContextObject(context)) == NULL
        || (graph =
            (RbcGraph *) Tcl_ObjectGetMetadata(object, &graphMeta)) == NULL
        || (value =
            TkoWidgetOptionGet(interp, object, objv[objc - 1])) == NULL) {
        return TCL_ERROR;
    }

    return (RbcGraphOptionSetTile(interp, object, value, &graph->tile));
}

/*
 * RbcEventuallyRedrawGraph --
 *
 *      Tells the Tk dispatcher to call the graph display routine at
 *      the next idle point.  This request is made only if the window
 *      is displayed and no other redraw request is pending.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      The window is eventually redisplayed.
 */
void
RbcEventuallyRedrawGraph(
    RbcGraph * graph)
{              /* Graph widget record */
    if(graph->win == NULL || *(graph->win) == NULL)
        return;
    if(!(graph->flags & RBC_REDRAW_PENDING)) {
        Tcl_DoWhenIdle(DisplayGraph, graph);
        graph->flags |= RBC_REDRAW_PENDING;
    }
}

/*
 * GraphEventProc --
 *
 *      This procedure is invoked by the Tk dispatcher for various
 *      events on graphs.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      When the window gets deleted, internal structures get
 *      cleaned up.  When it gets exposed, the graph is eventually
 *      redisplayed.
 */
static void
GraphEventProc(
    ClientData clientData,     /* Graph widget record */
    register XEvent * eventPtr)
{              /* Event which triggered call to routine */
    RbcGraph *graph = clientData;
    if(eventPtr->type == DestroyNotify || graph->win == NULL
        || *(graph->win) == NULL)
        return;

    if(eventPtr->type == Expose) {
        if(eventPtr->xexpose.count == 0) {
            graph->flags |= RBC_REDRAW_WORLD;
            RbcEventuallyRedrawGraph(graph);
        }
    } else if((eventPtr->type == FocusIn) || (eventPtr->type == FocusOut)) {
        if(eventPtr->xfocus.detail != NotifyInferior) {
            if(eventPtr->type == FocusIn) {
                graph->flags |= RBC_GRAPH_FOCUS;
            } else {
                graph->flags &= ~RBC_GRAPH_FOCUS;
            }
            graph->flags |= RBC_REDRAW_WORLD;
            RbcEventuallyRedrawGraph(graph);
        }
    } else if(eventPtr->type == ConfigureNotify) {
        graph->flags |= (RBC_MAP_WORLD | RBC_REDRAW_WORLD);
        RbcEventuallyRedrawGraph(graph);
    }
}

/*
 * TileChangedProc --
 *
 *      Rebuilds the designated GC with the new tile pixmap.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static void
TileChangedProc(
    ClientData clientData,
    RbcTile tile)
{              /* Not used. */
RbcGraph *graph = clientData;
    if(graph->win == NULL || *(graph->win) == NULL)
        return;

    graph->flags |= RBC_REDRAW_WORLD;
    RbcEventuallyRedrawGraph(graph);
}

/*
 * AdjustAxisPointers --
 *
 *      Sets the axis pointers according to whether the axis is
 *      inverted on not.  The axis sites are also reset.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static void
AdjustAxisPointers(
    RbcGraph * graph)
{              /* Graph widget record */
    if(graph->inverted) {
        graph->margins[RBC_MARGIN_LEFT].axes = graph->axisChain[0];
        graph->margins[RBC_MARGIN_BOTTOM].axes = graph->axisChain[1];
        graph->margins[RBC_MARGIN_RIGHT].axes = graph->axisChain[2];
        graph->margins[RBC_MARGIN_TOP].axes = graph->axisChain[3];
    } else {
        graph->margins[RBC_MARGIN_LEFT].axes = graph->axisChain[1];
        graph->margins[RBC_MARGIN_BOTTOM].axes = graph->axisChain[0];
        graph->margins[RBC_MARGIN_RIGHT].axes = graph->axisChain[3];
        graph->margins[RBC_MARGIN_TOP].axes = graph->axisChain[2];
    }
}

/*
 * PickEntry --
 *
 *      Find the closest point from the set of displayed elements,
 *      searching the display list from back to front.  That way, if
 *      the points from two different elements overlay each other exactly,
 *      the one that's on top (visible) is picked.
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static ClientData
PickEntry(
    ClientData clientData,
    int x,
    int y,
    ClientData * contextPtr)
{              /* Not used. */
    RbcGraph *graph = clientData;
    RbcChainLink *linkPtr;
    RbcElement *elemPtr;
    RbcMarker *markerPtr;
    RbcExtents2D exts;

    if(graph->flags & RBC_MAP_ALL) {
        /* Can't pick anything until the next
         * redraw occurs. */
        return NULL;
    }
    RbcGraphExtents(graph, &exts);

    if((x > exts.right) || (x < exts.left) || (y > exts.bottom)
        || (y < exts.top)) {
        /*
         * Sample coordinate is in one of the graph margins.  Can only
         * pick an axis.
         */
        return RbcNearestAxis(graph, x, y);
    }

    /*
     * From top-to-bottom check:
     *  1. markers drawn on top (-under false).
     *  2. elements using its display list back to front.
     *  3. markers drawn under element (-under true).
     */
    markerPtr = (RbcMarker *) RbcNearestMarker(graph, x, y, FALSE);
    if(markerPtr != NULL) {
        /* Found a marker (-under false). */
        return markerPtr;
    }
    {
    RbcClosestSearch search;

        search.along = RBC_SEARCH_BOTH;
        search.halo = graph->halo + 1;
        search.index = -1;
        search.x = x;
        search.y = y;
        search.dist = (double)(search.halo + 1);
        search.mode = RBC_SEARCH_AUTO;

        for(linkPtr = RbcChainLastLink(graph->elements.displayList);
            linkPtr != NULL; linkPtr = RbcChainPrevLink(linkPtr)) {
            elemPtr = RbcChainGetValue(linkPtr);
            if((elemPtr->flags & RBC_MAP_ITEM)
                || (RbcVectorNotifyPending(elemPtr->x.clientId))
                || (RbcVectorNotifyPending(elemPtr->y.clientId))) {
                continue;
            }
            if((!elemPtr->hidden) && (elemPtr->state == RBC_STATE_NORMAL)) {
                (*elemPtr->procsPtr->closestProc) (graph, elemPtr, &search);
            }
        }
        if(search.dist <= (double)search.halo) {
            /* Found an element within the
             * minimum halo distance. */
            return search.elemPtr;
        }
    }
    markerPtr = (RbcMarker *) RbcNearestMarker(graph, x, y, TRUE);
    if(markerPtr != NULL) {
        /* Found a marker (-under true) */
        return markerPtr;
    }
    /* Nothing found. */
    return NULL;
}

/* Widget sub-commands */

/*
 * XAxisOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
XAxisOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv)
{
    int margin;

    margin = (graph->inverted) ? RBC_MARGIN_LEFT : RBC_MARGIN_BOTTOM;
    return RbcAxisOp(graph, margin, argc, argv);
}

/*
 * X2AxisOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
X2AxisOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv)
{
    int margin;

    margin = (graph->inverted) ? RBC_MARGIN_RIGHT : RBC_MARGIN_TOP;
    return RbcAxisOp(graph, margin, argc, argv);
}

/*
 * YAxisOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
YAxisOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv)
{
    int margin;

    margin = (graph->inverted) ? RBC_MARGIN_BOTTOM : RBC_MARGIN_LEFT;
    return RbcAxisOp(graph, margin, argc, argv);
}

/*
 * Y2AxisOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
Y2AxisOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv)
{
    int margin;

    margin = (graph->inverted) ? RBC_MARGIN_TOP : RBC_MARGIN_RIGHT;
    return RbcAxisOp(graph, margin, argc, argv);
}

/*
 * BarOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
BarOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv)
{
    return RbcElementOp(graph, interp, argc, argv, rbcBarElementUid);
}

/*
 * LineOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
LineOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv)
{
    return RbcElementOp(graph, interp, argc, argv, rbcLineElementUid);
}

/*
 * ElementOp --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
ElementOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,
    const char **argv)
{
    return RbcElementOp(graph, interp, argc, argv, graph->classUid);
}

/*
 * ExtentsOp --
 *
 *      Reports the size of one of several items within the graph.
 *      The following are valid items:
 *
 *        "bottommargin"    Height of the bottom margin
 *        "leftmargin"      Width of the left margin
 *        "legend"          x y w h of the legend
 *        "plotarea"        x y w h of the plotarea
 *        "plotheight"      Height of the plot area
 *        "rightmargin"     Width of the right margin
 *        "topmargin"       Height of the top margin
 *        "plotwidth"       Width of the plot area
 *
 * Results:
 *      Always returns TCL_OK.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
ExtentsOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,                  /* Not used. */
    const char **argv)
{
    char c;
    unsigned int length;
    char string[200];

    c = argv[2][0];
    length = strlen(argv[2]);
    if((c == 'p') && (length > 4)
        && (strncmp("plotheight", argv[2], length) == 0)) {
        Tcl_SetObjResult(interp, Tcl_NewIntObj(graph->bottom - graph->top + 1));
    } else if((c == 'p') && (length > 4)
        && (strncmp("plotwidth", argv[2], length) == 0)) {
        Tcl_SetObjResult(interp, Tcl_NewIntObj(graph->right - graph->left + 1));
    } else if((c == 'p') && (length > 4)
        && (strncmp("plotarea", argv[2], length) == 0)) {
        sprintf(string, "%d %d %d %d", graph->left, graph->top,
            graph->right - graph->left + 1, graph->bottom - graph->top + 1);
        Tcl_SetObjResult(interp, Tcl_NewStringObj(string, -1));
    } else if((c == 'l') && (length > 2)
        && (strncmp("legend", argv[2], length) == 0)) {
        sprintf(string, "%d %d %d %d", RbcLegendX(graph->legend),
            RbcLegendY(graph->legend), RbcLegendWidth(graph->legend),
            RbcLegendHeight(graph->legend));
        Tcl_SetObjResult(interp, Tcl_NewStringObj(string, -1));
    } else if((c == 'l') && (length > 2)
        && (strncmp("leftmargin", argv[2], length) == 0)) {
        Tcl_SetObjResult(interp,
            Tcl_NewIntObj(graph->margins[RBC_MARGIN_LEFT].width));
    } else if((c == 'r') && (length > 1)
        && (strncmp("rightmargin", argv[2], length) == 0)) {
        Tcl_SetObjResult(interp,
            Tcl_NewIntObj(graph->margins[RBC_MARGIN_RIGHT].width));
    } else if((c == 't') && (length > 1)
        && (strncmp("topmargin", argv[2], length) == 0)) {
        Tcl_SetObjResult(interp,
            Tcl_NewIntObj(graph->margins[RBC_MARGIN_TOP].height));
    } else if((c == 'b') && (length > 1)
        && (strncmp("bottommargin", argv[2], length) == 0)) {
        Tcl_SetObjResult(interp,
            Tcl_NewIntObj(graph->margins[RBC_MARGIN_BOTTOM].height));
    } else {
        Tcl_AppendResult(interp, "bad extent item \"", argv[2],
            "\": should be plotheight, plotwidth, leftmargin, rightmargin, \
topmargin, bottommargin, plotarea, or legend", (char *)NULL);
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 * InsideOp --
 *
 *      Returns true of false whether the given point is inside
 *      the plotting area (defined by left,bottom right, top).
 *
 * Results:
 *      Always returns TCL_OK.  interp->result will contain
 *      the boolean string representation.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
InsideOp(
    RbcGraph * graph,
    Tcl_Interp * interp,
    int argc,                  /* Not used. */
    const char **argv)
{
    int x, y;
    RbcExtents2D exts;
    int result;
    if(graph->win == NULL || *(graph->win) == NULL)
        return TCL_ERROR;

    if(Tk_GetPixels(interp, *(graph->win), argv[2], &x) != TCL_OK) {
        return TCL_ERROR;
    }
    if(Tk_GetPixels(interp, *(graph->win), argv[3], &y) != TCL_OK) {
        return TCL_ERROR;
    }
    RbcGraphExtents(graph, &exts);
    result = RbcPointInRegion(&exts, x, y);
    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(result));
    return TCL_OK;
}

/*
 * InvtransformOp --
 *
 *      This procedure returns a list of the graph coordinate
 *      values corresponding with the given window X and Y
 *      coordinate positions.
 *
 * Results:
 *      Returns a standard Tcl result.  If an error occurred while
 *      parsing the window positions, TCL_ERROR is returned, and
 *      interp->result will contain the error message.  Otherwise
 *      interp->result will contain a Tcl list of the x and y
 *      coordinates.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
InvtransformOp(
    RbcGraph * graph,          /* Graph widget record */
    Tcl_Interp * interp,
    int argc,                  /* Not used. */
    const char **argv)
{
    double x, y;
    RbcPoint2D point;
    RbcAxis2D axes;
    char stringDouble[TCL_DOUBLE_SPACE];

    if(Tcl_ExprDouble(interp, argv[2], &x) != TCL_OK ||
        Tcl_ExprDouble(interp, argv[3], &y) != TCL_OK) {
        return TCL_ERROR;
    }
    if(graph->flags & RBC_RESET_AXES) {
        RbcResetAxes(graph);
    }
    /* Perform the reverse transformation, converting from window
     * coordinates to graph data coordinates.  Note that the point is
     * always mapped to the bottom and left axes (which may not be
     * what the user wants).  */

    /*  Pick the first pair of axes */
    axes.x = RbcGetFirstAxis(graph->axisChain[0]);
    axes.y = RbcGetFirstAxis(graph->axisChain[1]);
    point = RbcInvMap2D(graph, x, y, &axes);

    Tcl_PrintDouble(NULL, point.x, stringDouble);
    Tcl_AppendElement(interp, stringDouble);
    Tcl_PrintDouble(NULL, point.y, stringDouble);
    Tcl_AppendElement(interp, stringDouble);
    return TCL_OK;
}

/*
 * TransformOp --
 *
 *      This procedure returns a list of the window coordinates
 *      corresponding with the given graph x and y coordinates.
 *
 * Results:
 *      Returns a standard Tcl result.  interp->result contains
 *      the list of the graph coordinates. If an error occurred
 *      while parsing the window positions, TCL_ERROR is returned,
 *      then interp->result will contain an error message.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
TransformOp(
    RbcGraph * graph,          /* Graph widget record */
    Tcl_Interp * interp,
    int argc,                  /* Not used. */
    const char **argv)
{
    double x, y;
    RbcPoint2D point;
    RbcAxis2D axes;

    if((Tcl_ExprDouble(interp, argv[2], &x) != TCL_OK) ||
        (Tcl_ExprDouble(interp, argv[3], &y) != TCL_OK)) {
        return TCL_ERROR;
    }
    if(graph->flags & RBC_RESET_AXES) {
        RbcResetAxes(graph);
    }
    /*
     * Perform the transformation from window to graph coordinates.
     * Note that the points are always mapped onto the bottom and left
     * axes (which may not be the what the user wants).
     */
    axes.x = RbcGetFirstAxis(graph->axisChain[0]);
    axes.y = RbcGetFirstAxis(graph->axisChain[1]);

    point = RbcMap2D(graph, x, y, &axes);
    Tcl_AppendPrintfToObj(Tcl_GetObjResult(interp),
        "%d %d", ROUND(point.x), ROUND(point.y));
    return TCL_OK;
}

/*
 * StringToFormat --
 *
 *      Convert a string represent a node number into its integer
 *      value.
 *
 * Results:
 *      The return value is a standard Tcl result.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
StringToFormat(
    ClientData clientData,     /* Contains a pointer to the tabset containing
                                * this image. */
    Tcl_Interp * interp,       /* Interpreter to send results back to */
    char *switchName,          /* Not used. */
    char *string,              /* String representation */
    char *record,              /* Structure record */
    int offset)
{              /* Offset to field in structure */
    int *formatPtr = (int *)(record + offset);
    char c;

    c = string[0];
    if((c == 'p') && (strcmp(string, "photo") == 0)) {
        *formatPtr = FORMAT_PHOTO;
#ifdef _WIN32
    } else if((c == 'e') && (strcmp(string, "emf") == 0)) {
        *formatPtr = FORMAT_EMF;
    } else if((c == 'w') && (strcmp(string, "wmf") == 0)) {
        *formatPtr = FORMAT_WMF;
#endif /* _WIN32 */
    } else {
#ifdef _WIN32
        Tcl_AppendResult(interp, "bad format \"", string,
            "\": should be photo, emf, or wmf.", (char *)NULL);
#else
        Tcl_AppendResult(interp, "bad format \"", string,
            "\": should be photo.", (char *)NULL);
#endif /* _WIN32 */
        return TCL_ERROR;
    }
    return TCL_OK;
}

#ifdef _WIN32

/*
 * InitMetaFileHeader --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
InitMetaFileHeader(
    Tk_Window tkwin,
    int width,
    int height,
    APMHEADER * mfhPtr)
{
    unsigned int *p;
    unsigned int sum;
    Screen *screen;
#define MM_INCH		25.4
    double dpiX, dpiY;

    mfhPtr->key = 0x9ac6cdd7L;
    mfhPtr->hmf = 0;
    mfhPtr->inch = 1440;

    screen = Tk_Screen(tkwin);
    dpiX = (WidthOfScreen(screen) * MM_INCH) / WidthMMOfScreen(screen);
    dpiY = (HeightOfScreen(screen) * MM_INCH) / HeightMMOfScreen(screen);

    mfhPtr->bbox.Left = mfhPtr->bbox.Top = 0;
    mfhPtr->bbox.Bottom = (SHORT) ((width * 1440) / dpiX);
    mfhPtr->bbox.Right = (SHORT) ((height * 1440) / dpiY);
    mfhPtr->reserved = 0;
    sum = 0;
    for(p = (unsigned int *)mfhPtr;
        p < (unsigned int *)&(mfhPtr->checksum); p++) {
        sum ^= *p;
    }
    mfhPtr->checksum = sum;
    return TCL_OK;
}

/*
 * CreateAPMetaFile --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
CreateAPMetaFile(
    Tcl_Interp * interp,
    HANDLE hMetaFile,
    HDC hDC,
    APMHEADER * mfhPtr,
    char *fileName)
{
    HANDLE hFile;
    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,
            "\":", RbcLastError(), (char *)NULL);
        return TCL_ERROR;
    }
    if((!WriteFile(hFile, (LPVOID) mfhPtr, sizeof(APMHEADER), &count,
                NULL)) || (count != sizeof(APMHEADER))) {
        Tcl_AppendResult(interp, "can't create metafile header to \"",
            fileName, "\":", RbcLastError(), (char *)NULL);
        goto error;
    }
    nBytes = GetWinMetaFileBits(hMetaFile, 0, NULL, MM_ANISOTROPIC, hDC);
    hMem = GlobalAlloc(GHND, nBytes);
    if(hMem == NULL) {
        Tcl_AppendResult(interp, "can't create allocate global memory:",
            RbcLastError(), (char *)NULL);
        goto error;
    }
    buffer = (LPVOID) GlobalLock(hMem);
    if(!GetWinMetaFileBits(hMetaFile, nBytes, buffer, MM_ANISOTROPIC, hDC)) {
        Tcl_AppendResult(interp, "can't get metafile bits:",
            RbcLastError(), (char *)NULL);
        goto error;
    }
    if((!WriteFile(hFile, buffer, nBytes, &count, NULL)) || (count != nBytes)) {
        Tcl_AppendResult(interp, "can't write metafile bits:",
            RbcLastError(), (char *)NULL);
        goto error;
    }
    result = TCL_OK;
  error:
    CloseHandle(hFile);
    if(hMem != NULL) {
        GlobalUnlock(hMem);
        GlobalFree(hMem);
    }
    return result;
}

#endif /*_WIN32*/

/*
 * SnapOp --
 *
 *      Snaps a picture of the graph and stores it in the specified image
 *
 * Results:
 *      Returns a standard Tcl result.  interp->result contains
 *      the list of the graph coordinates. If an error occurred
 *      while parsing the window positions, TCL_ERROR is returned,
 *      then interp->result will contain an error message.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static int
SnapOp(
    RbcGraph * graph,          /* Graph widget record */
    Tcl_Interp * interp,
    int argc,                  /* Not used. */
    const char **argv)
{
    int result;
    Pixmap drawable;
    int noBackingStore = 0;
    register int i;
    SnapData data;
    if(graph->win == NULL || *(graph->win) == NULL)
        return TCL_ERROR;

    /* .g snap ?switches? name */
    data.height = Tk_Height(*(graph->win));
    data.width = Tk_Width(*(graph->win));
    data.format = FORMAT_PHOTO;
    /* Process switches  */
    i = RbcProcessSwitches(interp, snapSwitches, argc - 2, argv + 2,
        (char *)&data, RBC_SWITCH_OBJV_PARTIAL);
    if(i < 0) {
        return TCL_ERROR;
    }
    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. */
    graph->width = data.width;
    graph->height = data.height;
    RbcLayoutGraph(graph);

    drawable = Tk_WindowId(*(graph->win));
    if(data.format == FORMAT_PHOTO) {
        drawable = Tk_GetPixmap(graph->display, drawable, graph->width,
            graph->height, Tk_Depth(*(graph->win)));
#ifdef _WIN32
        assert(drawable != None);
#endif
        graph->flags |= RBC_RESET_WORLD;
        RbcDrawGraph(graph, drawable, noBackingStore);
        result = RbcSnapPhoto(interp, *(graph->win), drawable, 0, 0,
            data.width, data.height, data.width, data.height, data.name, 1.0);
        Tk_FreePixmap(graph->display, drawable);
#ifdef _WIN32
    } else if((data.format == FORMAT_WMF) || (data.format == FORMAT_EMF)) {
    TkWinDC drawableDC;
    TkWinDCState state;
    HDC hRefDC, hDC;
    HENHMETAFILE hMetaFile;
    Tcl_DString dString;
    char *title;

        hRefDC = TkWinGetDrawableDC(graph->display, drawable, &state);

        Tcl_DStringInit(&dString);
        Tcl_DStringAppend(&dString, "::graph ", -1);
        Tcl_DStringAppend(&dString, "\0", -1);
        Tcl_DStringAppend(&dString, Tk_PathName(*(graph->win)), -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;
        }

        drawableDC.hdc = hDC;
        drawableDC.type = TWD_WINDC;

        RbcLayoutGraph(graph);
        graph->flags |= RBC_RESET_WORLD;
        RbcDrawGraph(graph, (Drawable) & drawableDC, FALSE);

        hMetaFile = CloseEnhMetaFile(hDC);
        if(strcmp(data.name, "CLIPBOARD") == 0) {
    HWND hWnd;

            hWnd = Tk_GetHWND(drawable);
            OpenClipboard(hWnd);
            EmptyClipboard();
            SetClipboardData(CF_ENHMETAFILE, hMetaFile);
            CloseClipboard();
            result = TCL_OK;
        } else {
            result = TCL_ERROR;
            if(data.format == FORMAT_WMF) {
    APMHEADER mfh;

                assert(sizeof(mfh) == 22);
                InitMetaFileHeader(*(graph->win), 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);
        }
        TkWinReleaseDrawableDC(drawable, hRefDC, &state);

#endif /*_WIN32*/
    } else {
        Tcl_AppendResult(interp, "bad snapshot format", (char *)NULL);
        return TCL_ERROR;
    }
    graph->flags = RBC_MAP_WORLD;
    RbcEventuallyRedrawGraph(graph);
    return result;
}

static RbcOpSpec graphOps[] = {
    {"axis", 1, (RbcOp) RbcVirtualAxisOp, 2, 0, "oper ?args?",},
    {"bar", 2, (RbcOp) BarOp, 2, 0, "oper ?args?",},
    {"crosshairs", 2, (RbcOp) RbcCrosshairsOp, 2, 0, "oper ?args?",},
    {"element", 2, (RbcOp) ElementOp, 2, 0, "oper ?args?",},
    {"extents", 2, (RbcOp) ExtentsOp, 3, 3, "item",},
    {"grid", 1, (RbcOp) RbcGridOp, 2, 0, "oper ?args?",},
    {"inside", 3, (RbcOp) InsideOp, 4, 4, "winX winY",},
    {"invtransform", 3, (RbcOp) InvtransformOp, 4, 4, "winX winY",},
    {"legend", 2, (RbcOp) RbcLegendOp, 2, 0, "oper ?args?",},
    {"line", 2, (RbcOp) LineOp, 2, 0, "oper ?args?",},
    {"marker", 2, (RbcOp) RbcMarkerOp, 2, 0, "oper ?args?",},
    {"pen", 2, (RbcOp) RbcPenOp, 2, 0, "oper ?args?",},
    {"postscript", 2, (RbcOp) RbcPostScriptOp, 2, 0, "oper ?args?",},
    {"snap", 1, (RbcOp) SnapOp, 3, 0, "?switches? name",},
    {"transform", 1, (RbcOp) TransformOp, 4, 4, "x y",},
    {"x2axis", 2, (RbcOp) X2AxisOp, 2, 0, "oper ?args?",},
    {"xaxis", 2, (RbcOp) XAxisOp, 2, 0, "oper ?args?",},
    {"y2axis", 2, (RbcOp) Y2AxisOp, 2, 0, "oper ?args?",},
    {"yaxis", 2, (RbcOp) YAxisOp, 2, 0, "oper ?args?",},
};

static int nGraphOps = sizeof(graphOps) / sizeof(RbcOpSpec);

/*
 * RbcGraphInstCmdProc --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
int
RbcGraphInstCmdProc(
    ClientData clientData,
    Tcl_Interp * interp,
    int argc,
    const char *argv[])
{
    RbcOp proc;
    int result;
    RbcGraph *graph = clientData;

    proc = RbcGetOp(interp, nGraphOps, graphOps, RBC_OP_ARG1, argc, argv, 0);
    if(proc == NULL) {
        return TCL_ERROR;
    }
    Tcl_Preserve(graph);
    result = (*proc) (graph, interp, argc, argv);
    Tcl_Release(graph);
    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
 *      rectangle structure.
 *
 *      ---------------------------------
 *          |                               |
 *          |           rectArr[0]          |
 *          |                               |
 *      ---------------------------------
 *          |     |top           right|     |
 *          |     |                   |     |
 *          |     |                   |     |
 *          | [1] |                   | [2] |
 *          |     |                   |     |
 *          |     |                   |     |
 *          |     |                   |     |
 *          |     |                   |     |
 *          |     |                   |     |
 *          |     |left         bottom|     |
 *      ---------------------------------
 *          |                               |
 *          |          rectArr[3]           |
 *          |                               |
 *      ---------------------------------
 *
 *          X coordinate axis
 *          Y coordinate axis
 *          legend
 *          interior border
 *          exterior border
 *          titles (X and Y axis, graph)
 *
 * Returns:
 *      None.
 *
 * Side Effects:
 *      Exterior of graph is displayed in its window.
 */
static void
DrawMargins(
    RbcGraph * graph,
    Drawable drawable /* Pixmap or window to draw into */)
{             
    XRectangle rects[4];

    if(graph->win == NULL || *(graph->win) == NULL)
        return;
    /*
     * Draw the four outer rectangles which encompass the plotting
     * surface. This clears the surrounding area and clips the plot.
     */
    rects[0].x = rects[0].y = rects[3].x = rects[1].x = 0;
    rects[0].width = rects[3].width = (short int)graph->width;
    rects[0].height = (short int)graph->top;
    rects[3].y = graph->bottom;
    rects[3].height = graph->height - graph->bottom;
    rects[2].y = rects[1].y = graph->top;
    rects[1].width = graph->left;
    rects[2].height = rects[1].height = graph->bottom - graph->top;
    rects[2].x = graph->right;
    rects[2].width = graph->width - graph->right;

    if(graph->tile != NULL) {
        RbcSetTileOrigin(*(graph->win), graph->tile, 0, 0);
        RbcTileRectangles(*(graph->win), drawable, graph->tile, rects, 4);
    } else {
        XFillRectangles(graph->display, drawable, graph->fillGC, rects, 4);
    }

    /* Draw 3D border around the plotting area */

    if(graph->plotBorderWidth > 0) {
        int x, y, width, height;

        x = graph->left - graph->plotBorderWidth;
        y = graph->top - graph->plotBorderWidth;
        width = (graph->right - graph->left) + (2 * graph->plotBorderWidth);
        height = (graph->bottom - graph->top) + (2 * graph->plotBorderWidth);
        Tk_Draw3DRectangle(*(graph->win), drawable, graph->border, x, y,
            width, height, graph->plotBorderWidth, graph->plotRelief);
    }
    if(RbcLegendSite(graph->legend) & RBC_LEGEND_IN_MARGIN) {
        /* Legend is drawn on one of the graph margins */
        RbcDrawLegend(graph->legend, drawable);
    }
    if(graph->title != NULL) {
        RbcDrawText(*(graph->win), drawable, graph->title,
            &graph->titleTextStyle, graph->titleX, graph->titleY);
    }
    RbcDrawAxes(graph, drawable);

}

/*
 * DrawPlotRegion --
 *
 *      Draws the contents of the plotting area.  This consists of
 *      the elements, markers (draw under elements), axis limits,
 *      grid lines, and possibly the legend.  Typically, the output
 *      will be cached into a backing store pixmap, so that redraws
 *      can occur quickly.
 *
 * Results:
 *      None.
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static void
DrawPlotRegion(
    RbcGraph * graph,
    Drawable drawable)
{              /* Pixmap or window to draw into */
    /* Clear the background of the plotting area. */
    XFillRectangle(graph->display, drawable, graph->plotFillGC,
        graph->left, graph->top, graph->right - graph->left + 1,
        graph->bottom - graph->top + 1);

    /* Draw the elements, markers, legend, and axis limits. */

    if(!graph->gridPtr->hidden) {
        RbcDrawGrid(graph, drawable);
    }
    RbcDrawMarkers(graph, drawable, RBC_MARKER_UNDER);
    if((RbcLegendSite(graph->legend) & RBC_LEGEND_IN_PLOT) &&
        (!RbcLegendIsRaised(graph->legend))) {
        RbcDrawLegend(graph->legend, drawable);
    }
    RbcDrawAxisLimits(graph, drawable);
    RbcDrawElements(graph, drawable);
}

/*
 * RbcLayoutGraph --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
void
RbcLayoutGraph(
    RbcGraph * graph)
{
    if(graph->flags & RBC_RESET_AXES) {
        RbcResetAxes(graph);
    }
    if(graph->flags & RBC_LAYOUT_NEEDED) {
        RbcLayoutMargins(graph);
        graph->flags &= ~RBC_LAYOUT_NEEDED;
    }
    /* Compute coordinate transformations for graph components */
    if((graph->vRange > 1) && (graph->hRange > 1)) {
        if(graph->flags & RBC_MAP_WORLD) {
            RbcMapAxes(graph);
        }
        RbcMapElements(graph);
        RbcMapMarkers(graph);
        RbcMapGrid(graph);
        graph->flags &= ~(RBC_MAP_ALL);
    }
}

/*
 * RbcDrawGraph --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
void
RbcDrawGraph(
    RbcGraph * graph,
    Drawable drawable,         /* Pixmap or window to draw into */
    int backingStore)
{              /* If non-zero, use backing store for
                * plotting area. */
    if(graph->win == NULL || *(graph->win) == NULL)
        return;
    if(backingStore) {
        /*
         * Create another pixmap to save elements if one doesn't
         * already exist or the size of the window has changed.
         */
        if((graph->backPixmap == None) ||
            (graph->backWidth != graph->width) ||
            (graph->backHeight != graph->height)) {

            if(graph->backPixmap != None) {
                Tk_FreePixmap(graph->display, graph->backPixmap);
            }
            graph->backPixmap = Tk_GetPixmap(graph->display,
                Tk_WindowId(*(graph->win)), graph->width,
                graph->height, Tk_Depth(*(graph->win)));
            graph->backWidth = graph->width;
            graph->backHeight = graph->height;
            graph->flags |= RBC_REDRAW_BACKING_STORE;
        }
        if(graph->flags & RBC_REDRAW_BACKING_STORE) {
            /* The backing store is new or out-of-date. */
            DrawPlotRegion(graph, graph->backPixmap);
            graph->flags &= ~RBC_REDRAW_BACKING_STORE;
        }

        /* Copy the pixmap to the one used for drawing the entire graph. */

        XCopyArea(graph->display, graph->backPixmap, drawable,
            graph->drawGC, graph->left, graph->top,
            (graph->right - graph->left + 1),
            (graph->bottom - graph->top + 1), graph->left, graph->top);
    } else {
        DrawPlotRegion(graph, drawable);
    }

    /* Draw markers above elements */
    RbcDrawMarkers(graph, drawable, RBC_MARKER_ABOVE);
    RbcDrawActiveElements(graph, drawable);

    if(graph->flags & RBC_DRAW_MARGINS) {
        DrawMargins(graph, drawable);
    }
    if((RbcLegendSite(graph->legend) & RBC_LEGEND_IN_PLOT) &&
        (RbcLegendIsRaised(graph->legend))) {
        RbcDrawLegend(graph->legend, drawable);
    }
    /* Draw 3D border just inside of the focus highlight ring. */
    if((graph->borderWidth > 0) && (graph->relief != TK_RELIEF_FLAT)) {
        Tk_Draw3DRectangle(*(graph->win), drawable, graph->border,
            graph->highlightWidth, graph->highlightWidth,
            graph->width - 2 * graph->highlightWidth,
            graph->height - 2 * graph->highlightWidth,
            graph->borderWidth, graph->relief);
    }
    /* Draw focus highlight ring. */
    if((graph->highlightWidth > 0) && (graph->flags & RBC_GRAPH_FOCUS)) {
    GC  gc;

        gc = Tk_GCForColor(graph->highlightColor, drawable);
        Tk_DrawFocusHighlight(*(graph->win), gc, graph->highlightWidth,
            drawable);
    }
}

/*
 * UpdateMarginTraces --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
static void
UpdateMarginTraces(
    RbcGraph * graph)
{
    RbcMargin *marginPtr;
    int size;
    register int i;

    for(i = 0; i < 4; i++) {
        marginPtr = graph->margins + i;
        if(marginPtr->varName != NULL) {        /* Trigger variable traces */
            if((marginPtr->site == RBC_MARGIN_LEFT) ||
                (marginPtr->site == RBC_MARGIN_RIGHT)) {
                size = marginPtr->width;
            } else {
                size = marginPtr->height;
            }
            Tcl_SetVar2Ex(graph->interp, marginPtr->varName, NULL,
                Tcl_NewIntObj(size), TCL_GLOBAL_ONLY);
        }
    }
}

/*
 * DisplayGraph --
 *
 *      This procedure is invoked to display a graph widget.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Commands are output to X to display the graph in its
 *      current mode.
 */
static void
DisplayGraph(
    ClientData clientData)
{
    RbcGraph *graph = clientData;
    Pixmap drawable;
    graph->flags &= ~RBC_REDRAW_PENDING;
    if(graph->win == NULL || *(graph->win) == NULL)
        return;

    if(RbcGraphUpdateNeeded(graph)) {
        /*
         * One of the elements of the graph has a vector notification
         * pending.  This means that the vector will eventually notify
         * the graph that its data has changed.  Since the graph uses
         * the actual vector (not a copy) we need to keep in-sync.
         * Therefore don't draw right now but wait until we've been
         * notified before redrawing.
         */
        return;
    }
    graph->width = Tk_Width(*(graph->win));
    graph->height = Tk_Height(*(graph->win));
    RbcLayoutGraph(graph);
    RbcUpdateCrosshairs(graph);
    if(!Tk_IsMapped(*(graph->win))) {
        /* The graph's window isn't displayed, so don't bother
         * drawing anything.  By getting this far, we've at least
         * computed the coordinates of the graph's new layout.  */
        return;
    }

    /* Disable crosshairs before redisplaying to the screen */
    RbcDisableCrosshairs(graph);
    /*
     * Create a pixmap the size of the window for double buffering.
     */
    if(graph->doubleBuffer) {
        drawable = Tk_GetPixmap(graph->display, Tk_WindowId(*(graph->win)),
            graph->width, graph->height, Tk_Depth(*(graph->win)));
    } else {
        drawable = Tk_WindowId(*(graph->win));
    }
#ifdef _WIN32
    assert(drawable != None);
#endif
    RbcDrawGraph(graph, drawable, graph->backingStore && graph->doubleBuffer);
    if(graph->flags & RBC_DRAW_MARGINS) {
        XCopyArea(graph->display, drawable, Tk_WindowId(*(graph->win)),
            graph->drawGC, 0, 0, graph->width, graph->height, 0, 0);
    } else {
        XCopyArea(graph->display, drawable, Tk_WindowId(*(graph->win)),
            graph->drawGC, graph->left, graph->top,
            (graph->right - graph->left + 1),
            (graph->bottom - graph->top + 1), graph->left, graph->top);
    }
    if(graph->doubleBuffer) {
        Tk_FreePixmap(graph->display, drawable);
    }
    RbcEnableCrosshairs(graph);
    graph->flags &= ~RBC_RESET_WORLD;
    UpdateMarginTraces(graph);
}

/*
 * RbcGetGraphFromWindowData --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
RbcGraph *
RbcGetGraphFromWindowData(
    Tk_Window tkwin)
{
RbcGraph *graph;

    while(tkwin != NULL) {
        graph = (RbcGraph *) RbcGetWindowInstanceData(tkwin);
        if(graph != NULL) {
            return graph;
        }
        tkwin = Tk_Parent(tkwin);
    }
    return NULL;
}

/*
 * RbcGraphType --
 *
 *      TODO: Description
 *
 * Results:
 *      TODO: Results
 *
 * Side Effects:
 *      TODO: Side Effects
 */
int
RbcGraphType(
    RbcGraph * graph)
{
    if(graph->classUid == rbcLineElementUid) {
        return RBC_GRAPH;
    } else if(graph->classUid == rbcBarElementUid) {
        return RBC_BARCHART;
    } else if(graph->classUid == rbcStripElementUid) {
        return RBC_STRIPCHART;
    }
    return 0;
}

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

Added generic/tko/tkoGraph.h.






































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
/*
 * tkoGraph.h --
 *
 *      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.
 */

#ifndef _TKOGRAPH_H
#define _TKOGRAPH_H

#include "tkoWidget.h"

/*
 * For C++ compilers, use extern "C"
 */
#ifdef __cplusplus
extern "C" {
#endif

/*
 * Used standard values
 */
#define RBC_NORMAL_BG_MONO	    "white"
#define RBC_NORMAL_FG_MONO	    "black"
#define RBC_ACTIVE_BG_MONO	    "black"
#define RBC_ACTIVE_FG_MONO	    "white"
#define RBC_SELECT_BG_MONO	    "black"
#define RBC_SELECT_FG_MONO      "black"
#define RBC_SELECT_BORDERWIDTH  "2"
#define RBC_BORDERWIDTH 	    "2"
#define RBC_FONT                "TkDefaultFont 10"
#define RBC_FONT_HUGE           "TkDefaultFontArial 16"
#define RBC_FONT_LARGE          "TkDefaultFontArial 12"
#define RBC_FONT_SMALL          "TkDefaultFontArial 8"
#define RBC_NORMAL_BACKGROUND   "gray85"
#define RBC_NORMAL_FOREGROUND   "black"
#define RBC_ACTIVE_BACKGROUND   "gray64"
#define RBC_ACTIVE_FOREGROUND   "black"
#define RBC_SELECT_BACKGROUND   "lightblue1"
#define RBC_SELECT_FOREGROUND   "black"
#define RBC_INDICATOR_COLOR	    "maroon"

#define RBC_OP_LINEAR_SEARCH	1
#define RBC_OP_BINARY_SEARCH	0

#define RBC_STATIC_STRING_SPACE 150

#define RBC_NS_SEARCH_NONE		(0)
#define RBC_NS_SEARCH_CURRENT	(1<<0)
#define RBC_NS_SEARCH_GLOBAL	(1<<1)
#define RBC_NS_SEARCH_BOTH		(RBC_NS_SEARCH_GLOBAL | RBC_NS_SEARCH_CURRENT)

/* Recognize "min", "max", and "++end" as valid indices */
#define RBC_INDEX_SPECIAL	(1<<0)

/* Also recognize a range of indices separated by a colon */
#define RBC_INDEX_COLON	(1<<1)

/* Verify that the specified index or range of indices are within limits */
#define RBC_INDEX_CHECK	(1<<2)
#define RBC_INDEX_ALL_FLAGS    (RBC_INDEX_SPECIAL | RBC_INDEX_COLON | RBC_INDEX_CHECK)
#define RBC_SPECIAL_INDEX		-2

/* The data of the vector has changed.  Update the min and max limits when they are needed */
#define RBC_UPDATE_RANGE		(1<<9)

#define RBC_COLOR_NONE		    (XColor *)0
#define RBC_COLOR_DEFAULT		(XColor *)1
#define RBC_COLOR_ALLOW_DEFAULTS	1

#define RBC_STATE_NORMAL	0
#define RBC_STATE_ACTIVE	(1<<0)
#define RBC_STATE_DISABLED	(1<<1)
#define RBC_STATE_EMPHASIS	(1<<2)

#define RBC_ROTATE_0	0
#define RBC_ROTATE_90	1
#define RBC_ROTATE_180	2
#define RBC_ROTATE_270	3

#define RBC_SEARCH_X	0
#define RBC_SEARCH_Y	1
#define RBC_SEARCH_BOTH	2

#define RBC_SHOW_NONE	0
#define RBC_SHOW_X		1
#define RBC_SHOW_Y		2
#define RBC_SHOW_BOTH	3

#define RBC_SEARCH_POINTS	0       /* Search for closest data point. */
#define RBC_SEARCH_TRACES	1       /* Search for closest point on trace.
                                         * Interpolate the connecting line segments
                                         * if necessary. */
#define RBC_SEARCH_AUTO	2      /* Automatically determine whether to search
                                * for data points or traces.  Look for
                                * traces if the linewidth is > 0 and if
                                * there is more than one data point. */

#define	RBC_ELEM_ACTIVE	(1<<8) /* Non-zero indicates that the element
                                * should be drawn in its active
                                * foreground and background
                                * colors. */
#define	RBC_ACTIVE_PENDING	(1<<7)

#define	RBC_LABEL_ACTIVE 	(1<<9)  /* Non-zero indicates that the
                                         * element's entry in the legend
                                         * should be drawn in its active
                                         * foreground and background
                                         * colors. */
#define RBC_SCALE_SYMBOL	(1<<10)

#define RBC_SWITCH_ARGV_ONLY		(1<<0)
#define RBC_SWITCH_OBJV_ONLY		(1<<0)
#define RBC_SWITCH_ARGV_PARTIAL		(1<<1)
#define RBC_SWITCH_OBJV_PARTIAL		(1<<1)

/*
 * Possible flag values for RbcSwitchSpec structures.  Any bits at
 * or above RBC_SWITCH_USER_BIT may be used by clients for selecting
 * certain entries.
 */
#define RBC_SWITCH_NULL_OK		(1<<0)
#define RBC_SWITCH_DONT_SET_DEFAULT	(1<<3)
#define RBC_SWITCH_SPECIFIED		(1<<4)
#define RBC_SWITCH_USER_BIT		(1<<8)

/*
 * Bit flags definitions:
 *
 * 	All kinds of state information kept here.  All these
 *	things happen when the window is available to draw into
 *	(DisplayGraph). Need the window width and height before
 *	we can calculate graph layout (i.e. the screen coordinates
 *	of the axes, elements, titles, etc). But we want to do this
 *	only when we have to, not every time the graph is redrawn.
 *
 *	Same goes for maintaining a pixmap to double buffer graph
 *	elements.  Need to mark when the pixmap needs to updated.
 *
 *
 *	MAP_ITEM		Indicates that the element/marker/axis
 *				configuration has changed such that
 *				its layout of the item (i.e. its
 *				position in the graph window) needs
 *				to be recalculated.
 *
 *	MAP_ALL			Indicates that the layout of the axes and
 *				all elements and markers and the graph need
 *				to be recalculated. Otherwise, the layout
 *				of only those markers and elements that
 *				have changed will be reset.
 *
 *	GET_AXIS_GEOMETRY	Indicates that the size of the axes needs
 *				to be recalculated.
 *
 *	RESET_AXES		Flag to call to RbcResetAxes routine.
 *				This routine recalculates the scale offset
 *				(used for mapping coordinates) of each axis.
 *				If an axis limit has changed, then it sets
 *				flags to re-layout and redraw the entire
 *				graph.  This needs to happend before the axis
 *				can compute transformations between graph and
 *				screen coordinates.
 *
 *	LAYOUT_NEEDED
 *
 *	REDRAW_BACKING_STORE	If set, redraw all elements into the pixmap
 *				used for buffering elements.
 *
 *	REDRAW_PENDING		Non-zero means a DoWhenIdle handler has
 *				already been queued to redraw this window.
 *
 *	DRAW_LEGEND		Non-zero means redraw the legend. If this is
 *				the only DRAW_* flag, the legend display
 *				routine is called instead of the graph
 *				display routine.
 *
 *	DRAW_MARGINS		Indicates that the margins bordering
 *				the plotting area need to be redrawn.
 *				The possible reasons are:
 *
 *				1) an axis configuration changed
 *				2) an axis limit changed
 *				3) titles have changed
 *				4) window was resized.
 *
 *	GRAPH_FOCUS
 */
#define	RBC_MAP_ITEM		(1<<0)  /* 0x0001 */
#define	RBC_MAP_ALL			(1<<1)  /* 0x0002 */
#define	RBC_GET_AXIS_GEOMETRY	(1<<2)  /* 0x0004 */
#define RBC_RESET_AXES		(1<<3)  /* 0x0008 */
#define RBC_LAYOUT_NEEDED		(1<<4)  /* 0x0010 */

#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 */
#define RBC_LEGEND_LEFT	(1<<1) /* Left margin */
#define RBC_LEGEND_BOTTOM	(1<<2)  /* Bottom margin */
#define RBC_LEGEND_TOP	(1<<3) /* Top margin, below the graph title. */
#define RBC_LEGEND_PLOT	(1<<4) /* Plot area */
#define RBC_LEGEND_XY	(1<<5) /* Screen coordinates in the plotting
                                * area. */
#define RBC_LEGEND_WINDOW	(1<<6)  /* External window. */
#define RBC_LEGEND_IN_MARGIN \
	(RBC_LEGEND_RIGHT | RBC_LEGEND_LEFT | RBC_LEGEND_BOTTOM | RBC_LEGEND_TOP)
#define RBC_LEGEND_IN_PLOT  (RBC_LEGEND_PLOT | RBC_LEGEND_XY)

#define RBC_MARKER_UNDER	1       /* Draw markers designated to lie underneath
                                         * elements, grids, legend, etc. */
#define RBC_MARKER_ABOVE	0       /* Draw markers designated to rest above
                                         * elements, grids, legend, etc. */

/*
 * Mask values used to selectively enable GRAPH or BARCHART entries in
 * the various configuration specs.
 */
#define RBC_GRAPH		(TK_CONFIG_USER_BIT << 1)
#define RBC_STRIPCHART	(TK_CONFIG_USER_BIT << 2)
#define RBC_BARCHART	(TK_CONFIG_USER_BIT << 3)
#define RBC_LINE_GRAPHS	(RBC_GRAPH | RBC_STRIPCHART)
#define RBC_ALL_GRAPHS	(RBC_GRAPH | RBC_BARCHART | RBC_STRIPCHART)

#define RBC_PEN_DELETE_PENDING	(1<<0)
#define RBC_ACTIVE_PEN		(TK_CONFIG_USER_BIT << 6)
#define RBC_NORMAL_PEN		(TK_CONFIG_USER_BIT << 7)
#define RBC_ALL_PENS		(RBC_NORMAL_PEN | RBC_ACTIVE_PEN)

#define RBC_MARGIN_NONE     -1
#define RBC_MARGIN_BOTTOM   0
#define RBC_MARGIN_LEFT     1
#define RBC_MARGIN_TOP      2
#define RBC_MARGIN_RIGHT    3

/* forward references, defined later */
    typedef struct RbcGraph RbcGraph;
    typedef struct RbcElement RbcElement;
    typedef struct RbcLegend RbcLegend;
    typedef struct RbcBindTable RbcBindTable;
    typedef struct RbcChainLink RbcChainLink;
    typedef struct RbcTileClient *RbcTile;      /* Opaque type for tiles */
    typedef struct RbcPsToken RbcPsToken;
    typedef struct RbcPen RbcPen;
    typedef struct RbcMarker RbcMarker;
    typedef struct RbcCrosshairs RbcCrosshairs;
    typedef struct RbcParseValue RbcParseValue;

/*
 * RbcPad --
 *
 * 	Specifies vertical and horizontal padding.
 *
 *	Padding can be specified on a per side basis.  The fields
 *	side1 and side2 refer to the opposite sides, either
 *	horizontally or vertically.
 *
 *		side1	side2
 *              -----   -----
 *      x | left    right
 *	    y | top     bottom
 */
    typedef struct {
        short int side1;
        short int side2;
    } RbcPad;

/*
 * RbcTextFragment --
 */
    typedef struct {
        char *text;            /* Text to be displayed */
        short int x, y;        /* X-Y offset of the baseline from the
                                * upper-left corner of the bbox. */
        short int sx, sy;      /* See rbcWinUtil.c */
        short int count;       /* Number of bytes in text. The actual
                                * character count may differ because of
                                * multi-byte UTF encodings. */
        short int width;       /* Width of segment in pixels. This
                                * information is used to draw
                                * PostScript strings the same width
                                * as X. */
    } RbcTextFragment;

/*
 * RbcTextLayout --
 */
    typedef struct {
        int nFrags;            /* # fragments of text */
        short int width, height;        /* Dimensions of text bounding box */
        RbcTextFragment fragArr[1];     /* Information about each fragment of text */
    } RbcTextLayout;

/*
 * RbcShadow --
 */
    typedef struct {
        XColor *color;
        int offset;
    } RbcShadow;

/*
 * RbcTextStyle --
 *
 * 	Represents a convenient structure to hold text attributes
 *	which determine how a text string is to be displayed on the
 *	window, or drawn with PostScript commands.  The alternative
 *	is to pass lots of parameters to the drawing and printing
 *	routines. This seems like a more efficient and less cumbersome
 *	way of passing parameters.
 */
    typedef struct {
        unsigned int state;    /* If non-zero, indicates to draw text
                                * in the active color */
        short int width, height;        /* Extents of text */
        XColor *color;         /* Normal color */
        XColor *activeColor;   /* Active color */
        Tk_Font font;          /* Font to use to draw text */
        Tk_3DBorder border;    /* Background color of text.  This is also
                                * used for drawing disabled text. */
        RbcShadow shadow;      /* Drop shadow color and offset */
        Tk_Justify justify;    /* Justification of the text string. This
                                * only matters if the text is composed
                                * of multiple lines. */
        GC  gc;                /* GC used to draw the text */
        double theta;          /* Rotation of text in degrees. */
        Tk_Anchor anchor;      /* Indicates how the text is anchored around
                                * its x and y coordinates. */
        RbcPad padX, padY;     /* # pixels padding of around text region */
        short int leader;      /* # pixels spacing between lines of text */
    } RbcTextStyle;

/*
 *
 */
    typedef ClientData(
        RbcBindPickProc) (
        ClientData clientData,
        int x,
        int y,
        ClientData * contextPtr);

/*
 * RbcBindTable --
 *
 * Binding structure information:
 */
    typedef struct RbcBindTable {
        unsigned int flags;
        Tk_BindingTable bindingTable;   /* Table of all bindings currently defined.
                                         * NULL means that no bindings exist, so the
                                         * table hasn't been created.  Each "object"
                                         * used for this table is either a Tk_Uid for
                                         * a tag or the address of an item named by
                                         * id. */
        ClientData currentItem; /* The item currently containing the mouse
                                 * pointer, or NULL if none. */
        ClientData currentContext;      /* One word indicating what kind of object
                                         * was picked. */
        ClientData newItem;    /* The item that is about to become the
                                * current one, or NULL.  This field is
                                * used to detect deletions of the new
                                * current item pointer that occur during
                                * Leave processing of the previous current
                                * tab.  */
        ClientData newContext; /* One-word indicating what kind of object
                                * was just picked. */
        ClientData focusItem;
        ClientData focusContext;
        XEvent pickEvent;      /* The event upon which the current choice
                                * of the current tab is based.  Must be saved
                                * so that if the current item is deleted,
                                * we can pick another. */
        int activePick;        /* The pick event has been initialized so
                                * that we can repick it */
        int state;             /* Last known modifier state.  Used to
                                * defer picking a new current object
                                * while buttons are down. */
        ClientData clientData;
        Tk_Window tkwin;
        RbcBindPickProc *pickProc;      /* Routine to report the item the mouse is
                                         * currently over. */
    } RbcBindTable;

/*
 * RbcChainLink --
 *
 * A RbcChainLink is the container structure for the RbcChain.
 */
    typedef struct RbcChainLink {
        RbcChainLink *prevPtr; /* Link to the previous link */
        RbcChainLink *nextPtr; /* Link to the next link */
        ClientData clientData; /* Pointer to the data object */
    } RbcChainLink;

    typedef int (
        RbcChainCompareProc) (
        RbcChainLink ** l1PtrPtr,
        RbcChainLink ** l2PtrPtr);

/*
 * RbcChain --
 *
 * A RbcChain is a doubly chained list structure.
 */
    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 */
        Tcl_HashTable indexProcTable;
        Tcl_Interp *interp;
        unsigned int nextId;
    } RbcVectorInterpData;

/*
 * RbcVectorObject --
 *
 *	A vector is an array of double precision values.  It can be
 *	accessed through a Tcl command, a Tcl array variable, or C
 *	API. The storage for the array points initially to a
 *	statically allocated buffer, but to malloc-ed memory if more
 *	is necessary.
 *
 *	Vectors can be shared by several clients (for example, two
 *	different graph widgets).  The data is shared. When a client
 *	wants to use a vector, it allocates a vector identifier, which
 *	identifies the client.  Clients use this ID to specify a
 *	callback routine to be invoked whenever the vector is modified
 *	or destroyed.  Whenever the vector is updated or destroyed,
 *	each client is notified of the change by their callback
 *	routine.
 */
    typedef struct {
        /*
         * If you change these fields, make sure you change the definition
         * 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
                                 * track the vectors in use. */
        Tcl_FreeProc *freeProc; /* Address of procedure to call to
                                 * release storage for the value
                                 * array, Optionally can be one of the
                                 * following: TCL_STATIC, TCL_DYNAMIC,
                                 * or TCL_VOLATILE. */
        char *arrayName;       /* The namespace-qualified name of the
                                * Tcl array variable
                                * mapped to the vector
                                * (malloc'ed). If NULL, indicates
                                * that the vector isn't mapped to any variable */
        int offset;            /* Offset from zero of the vector's
                                * starting index */
        Tcl_Command cmdToken;  /* Token for vector's Tcl command. */
        RbcChain *chainPtr;    /* List of clients using this vector */
        int notifyFlags;       /* Notification flags. See definitions
                                * below */
        int varFlags;          /* Indicate if the variable is global,
                                * namespace, or local */
        int freeOnUnset;       /* For backward compatibility only: If
                                * non-zero, free the vector when its
                                * variable is unset. */
        int flush;
        int first, last;       /* Selected region of vector. This is used
                                * mostly for the math routines */
    } RbcVectorObject;

    typedef struct RbcVectorIdStruct *RbcVectorId;

/*
 * 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
 *	argument, or the result of a nested command).  At any given
 *	time, the space available for output is fixed, but a procedure
 *	may be called to expand the space available if the current
 *	space runs out.
 */
    typedef struct RbcParseValue {
        char *buffer;          /* Address of first character in
                                * output buffer. */
        char *next;            /* Place to store next character in
                                * output buffer. */
        char *end;             /* Address of the last usable character
                                * in the buffer. */
        void (
            *expandProc) (
            RbcParseValue * pvPtr,
            int needed);
        /* Procedure to call when space runs out;
         * it will make more space. */
        ClientData clientData; /* Arbitrary information for use of
                                * expandProc. */
    } RbcParseValue;

/*
 * RbcParseVector --
 */
    typedef struct {
        RbcVectorObject *vPtr;
        char staticSpace[RBC_STATIC_STRING_SPACE];
        RbcParseValue pv;      /* Used to hold a string value, if any. */
    } RbcParseVector;

/*
 * RbcOp --
 *
 * 	Generic function prototype of CmdOptions.
 */
    typedef int (
        *RbcOp) (
        );

/*
 * RbcOpSpec --
 *
 * 	Structure to specify a set of operations for a Tcl command.
 *      This is passed to the RbcGetOp procedure to look
 *      for a function pointer associated with the operation name.
 */
    typedef struct {
        const char *name;      /* Name of operation */
        int minChars;          /* Minimum # characters to disambiguate */
        RbcOp proc;
        int minArgs;           /* Minimum # args required */
        int maxArgs;           /* Maximum # args required */
        const char *usage;     /* Usage message */
    } RbcOpSpec;

/*
 * RbcOpIndex --
 */
    typedef enum {
        RBC_OP_ARG0,           /* Op is the first argument. */
        RBC_OP_ARG1,           /* Op is the second argument. */
        RBC_OP_ARG2,           /* Op is the third argument. */
        RBC_OP_ARG3,           /* Op is the fourth argument. */
        RBC_OP_ARG4            /* Op is the fifth argument. */
    } RbcOpIndex;

    typedef int (
        QSortCompareProc) (
        const void *,
        const void *);

/*
 * RbcDashes --
 *
 * 	List of dash values (maximum 11 based upon PostScript limit).
 */
    typedef struct {
        char values[12];
        int offset;
    } RbcDashes;
#define RbcLineIsDashed(d) ((d).values[0] != 0)

/*
 * RbcPoint2D --
 *
 *	2-D coordinate.
 */
    typedef struct {
        double x;
        double y;
    } RbcPoint2D;

/*
 * RbcPoint3D --
 *
 *	3-D coordinate.
 */
    typedef struct {
        double x;
        double y;
        double z;
    } RbcPoint3D;

/*
 * RbcSegment2D --
 *
 *	2-D line segment.
 */
    typedef struct {
        RbcPoint2D p;          /* First end point of the segment. */
        RbcPoint2D q;          /* Last end point of the segment. */
    } RbcSegment2D;

/*
 * RbcDim2D --
 *
 *	2-D dimension.
 */
    typedef struct {
        short int width;
        short int height;
    } RbcDim2D;

/*
 * RbcRegion2D --
 *
 *      2-D region.  Used to copy parts of images.
 */
    typedef struct {
        int left;
        int right;
        int top;
        int bottom;
    } RbcRegion2D;

/*
 * RbcExtents2D --
 */
    typedef struct {
        double left;
        double right;
        double top;
        double bottom;
    } RbcExtents2D;

/*
 * RbcExtents3D --
 */
    typedef struct {
        double left;
        double right;
        double top;
        double bottom;
        double front;
        double back;
    } RbcExtents3D;

/* int RbcPointInRegion(RbcRegion2D e, int x, int y) */
#define RbcPointInRegion(e,x,y) \
	(((x) <= (e)->right) && ((x) >= (e)->left) && \
	 ((y) <= (e)->bottom) && ((y) >= (e)->top))

/*
 * RbcColorPair --
 *
 *	Holds a pair of foreground, background colors.
 */
    typedef struct {
        XColor *fgColor, *bgColor;
    } RbcColorPair;

    typedef void (
        RbcTileChangedProc) (
        ClientData clientData,
        RbcTile tile);

/*
 * RbcPix32 --
 *
 *      A union representing either a pixel as a RGB triplet or a
 *	single word value.
 */
    typedef union {
        unsigned int value;    /* Lookup table address */
        struct RGBA {
            unsigned char red; /* Red intensity 0..255 */
            unsigned char green;        /* Green intensity 0.255 */
            unsigned char blue; /* Blue intensity 0..255 */
            unsigned char alpha;        /* Alpha-channel for compositing. 0..255 */
        } rgba;
        unsigned char channel[4];
    } RbcPix32;

/*
 * RbcColorImage --
 *
 *      The structure below represents a color image.  Each pixel
 *	occupies a 32-bit word of memory: one byte for each of the
 *	red, green, and blue color intensities, and another for
 *	alpha-channel image compositing (e.g. transparency).
 */
    typedef struct RbcColorImage {
        int width;             /* Dimensions of the image */
        int height;            /* Dimensions of the image */
        RbcPix32 *bits;        /* Array of pixels representing the image. */
    } RbcColorImage;

/*
 * ResampleFilterProc --
 *
 *      A function implementing a 1-D filter.
 */
    typedef double (
        ResampleFilterProc) (
        double value);

/*
 * RbcFilter2D --
 *
 *      Defines a convolution mask for a 2-D filter.  Used to smooth or
 *	enhance images.
 */
    typedef struct {
        double support;        /* Radius of filter */
        double sum, scale;     /* Sum of kernel */
        double *kernel;        /* Array of values (malloc-ed) representing
                                * the discrete 2-D filter. */
    } RbcFilter2D;

/*
 * RbcPsColorMode --
 */
    typedef enum {
        PS_MODE_MONOCHROME,    /* Only black and white. */
        PS_MODE_GREYSCALE,     /* Color converted to greyscale. */
        PS_MODE_COLOR          /* Full color */
    } RbcPsColorMode;

/*
 * RbcPsToken --
 */
    typedef struct RbcPsToken {
        Tcl_Interp *interp;    /* Interpreter to report errors to. */
        Tk_Window tkwin;       /* Tk_Window used to get font and color
                                * information */
        Tcl_DString dString;   /* Dynamic string used to contain the
                                * PostScript generated. */
        char *fontVarName;     /* Name of a Tcl array variable to convert
                                * X font names to PostScript fonts. */
        char *colorVarName;    /* Name of a Tcl array variable to convert
                                * X color names to PostScript. */
        RbcPsColorMode colorMode;       /* Mode: color or greyscale */
        /*
         * Utility space for building strings.  Currently used to create
         * PostScript output for the "postscript" command.
         */
        char scratchArr[BUFSIZ * 2];
    } RbcPsToken;

/*
 * RbxAxisRange --
 *
 *	Designates a range of values by a minimum and maximum limit.
 */
    typedef struct {
        double min;
        double max;
        double range;
        double scale;
    } RbcAxisRange;

/*
 * RbcTicks --
 *
 * 	Structure containing information where the ticks (major or
 *	minor) will be displayed on the graph.
 */
    typedef struct {
        int nTicks;            /* # of ticks on axis */
        double values[1];      /* Array of tick values (malloc-ed). */
    } RbcTicks;

/*
 * RbcTickSweep --
 *
 * 	Structure containing information where the ticks (major or
 *	minor) will be displayed on the graph.
 */
    typedef struct {
        double initial;        /* Initial value */
        double step;           /* Size of interval */
        int nSteps;            /* Number of intervals. */
    } RbcTickSweep;

/*
 * RbcAxis --
 *
 * 	Structure contains options controlling how the axis will be
 * 	displayed.
 */
    typedef struct {
        char *name;            /* Identifier to refer the element.
                                * Used in the "insert", "delete", or
                                * "show", commands. */
        Tk_Uid classUid;       /* Type of axis. */
        RbcGraph *graphPtr;    /* Graph widget of element */
        unsigned int flags;    /* Set bit field definitions below */
        /*
         * AXIS_DRAWN               Axis is designated as a logical axis
         * AXIS_DIRTY
         *
         * AXIS_CONFIG_MAJOR        User specified major ticks.
         * AXIS_CONFIG_MINOR        User specified minor ticks.
         */
        char **tags;
        const char *detail;
        int deletePending;     /* Indicates that the axis was
                                * scheduled for deletion. The actual
                                * deletion may be deferred until the
                                * axis is no longer in use.  */
        int refCount;          /* Number of elements referencing this
                                * axis. */
        Tcl_HashEntry *hashPtr; /* Points to axis entry in hash
                                 * table. Used to quickly remove axis
                                 * entries. */
        int logScale;          /* If non-zero, scale the axis values
                                * logarithmically. */
        int hidden;            /* If non-zero, don't display the
                                * axis title, ticks, or line. */
        int showTicks;         /* If non-zero, display tick marks and
                                * labels. */
        int descending;        /* If non-zero, display the range of
                                * values on the axis in descending
                                * order, from high to low. */
        int looseMin, looseMax; /* If non-zero, axis range extends to
                                 * the outer major ticks, otherwise at
                                 * the limits of the data values. This
                                 * is overriddened by setting the -min
                                 * and -max options.  */
        char *title;           /* Title of the axis. */
        RbcTextStyle titleTextStyle;    /* Text attributes (color, font,
                                         * rotation, etc.)  of the axis
                                         * title. */
        int titleAlternate;    /* Indicates whether to position the
                                * title above/left of the axis. */
        RbcPoint2D titlePos;   /* Position of the title */
        unsigned short int titleWidth, titleHeight;
        int lineWidth;         /* Width of lines representing axis
                                * (including ticks).  If zero, then
                                * no axis lines or ticks are
                                * drawn. */
        const char **limitsFormats;     /* One or two strings of sprintf-like
                                         * formats describing how to display
                                         * virtual axis limits. If NULL,
                                         * display no limits. */
        int nFormats;
        RbcTextStyle limitsTextStyle;   /* Text attributes (color, font,
                                         * rotation, etc.)  of the limits. */
        double windowSize;     /* Size of a sliding window of values
                                * used to scale the axis automatically
                                * as new data values are added. The axis
                                * will always display the latest values
                                * in this range. */
        double shiftBy;        /* Shift maximum by this interval. */
        int tickLength;        /* Length of major ticks in pixels */
        RbcTextStyle tickTextStyle;     /* Text attributes (color, font, rotation,
                                         * etc.) for labels at each major tick. */
        char *formatCmd;       /* Specifies a Tcl command, to be invoked
                                * by the axis whenever it has to generate
                                * tick labels. */
        char *scrollCmdPrefix;
        int scrollUnits;
        double min, max;       /* The actual axis range. */
        double reqMin, reqMax; /* Requested axis bounds. Consult the
                                * axisPtr->flags field for
                                * AXIS_CONFIG_MIN and AXIS_CONFIG_MAX
                                * to see if the requested bound have
                                * been set.  They override the
                                * computed range of the axis
                                * (determined by auto-scaling). */
        double scrollMin, scrollMax;    /* Defines the scrolling reqion of the axis.
                                         * Normally the region is determined from
                                         * the data limits. If specified, these
                                         * values override the data-range. */
        RbcAxisRange valueRange;        /* Range of data values of elements mapped
                                         * to this axis. This is used to auto-scale
                                         * the axis in "tight" mode. */
        RbcAxisRange axisRange; /* Smallest and largest major tick values
                                 * for the axis.  The tick values lie outside
                                 * the range of data values.  This is used to
                                 * auto-scale the axis in "loose" mode. */
        double prevMin, prevMax;
        double reqStep;        /* If > 0.0, overrides the computed major
                                * tick interval.  Otherwise a stepsize
                                * is automatically calculated, based
                                * upon the range of elements mapped to the
                                * axis. The default value is 0.0. */
        double tickZoom;       /* If > 0.0, overrides the computed major
                                * tick interval.  Otherwise a stepsize
                                * is automatically calculated, based
                                * upon the range of elements mapped to the
                                * axis. The default value is 0.0. */
        GC  tickGC;            /* Graphics context for axis and tick labels */
        RbcTicks *t1Ptr;       /* Array of major tick positions. May be
                                * set by the user or generated from the
                                * major sweep below. */
        RbcTicks *t2Ptr;       /* Array of minor tick positions. May be
                                * set by the user or generated from the
                                * minor sweep below. */
        RbcTickSweep minorSweep, majorSweep;
        int reqNumMinorTicks;  /* If non-zero, represents the
                                * requested the number of minor ticks
                                * to be uniformally displayed along
                                * each major tick. */
        int labelOffset;       /* If non-zero, indicates that the tick
                                * label should be offset to sit in the
                                * middle of the next interval. */
        /* The following fields are specific to logical axes */
        RbcChainLink *linkPtr; /* Axis link in margin list. */
        RbcChain *chainPtr;
        short int width, height;        /* Extents of axis */
        RbcSegment2D *segments; /* Array of line segments representing
                                 * the major and minor ticks, but also
                                 * the axis line itself. The segment
                                 * coordinates are relative to the
                                 * axis. */
        int nSegments;         /* Number of segments in the above array. */
        RbcChain *tickLabels;  /* Contains major tick label strings
                                * and their offsets along the axis. */
        RbcRegion2D region;
        Tk_3DBorder border;
        int borderWidth;
        int relief;
    } RbcAxis;

/*
 * RbcAxis2D --
 *
 *	The pair of axes mapping a point onto the graph.
 */
    typedef struct {
        RbcAxis *x;
        RbcAxis *y;
    } RbcAxis2D;

/*
* RbcElemWeight --
*
*	Designates a range of values by a minimum and maximum limit.
*/
    typedef struct {
        double min;
        double max;
        double range;
    } RbcElemWeight;

/*
 * RbcPenStyle --
 *
 * An element has one or more vectors plus several attributes, such as
 * line style, thickness, color, and symbol type.  It has an
 * identifier which distinguishes it among the list of all elements.
 */
    typedef struct {
        RbcElemWeight weight;  /* Weight range where this pen is valid. */
        RbcPen *penPtr;        /* Pen to use. */
        RbcSegment2D *xErrorBars;       /* Point to start of this pen's X-error bar
                                         * segments in the element's array. */
        RbcSegment2D *yErrorBars;       /* Point to start of this pen's Y-error bar
                                         * segments in the element's array. */
        int xErrorBarCnt;      /* # of error bars for this pen. */
        int yErrorBarCnt;      /* # of error bars for this pen. */
        int errorBarCapWidth;  /* Length of the cap ends on each
                                * error bar. */
        int symbolSize;        /* Size of the pen's symbol scaled to
                                * the current graph size. */
    } RbcPenStyle;

    typedef struct {
        int halo;              /* Maximal distance a candidate point
                                * can be from the sample window
                                * coordinate */
        int mode;              /* Indicates whether to find the closest
                                * data point or the closest point on the
                                * trace by interpolating the line segments.
                                * Can also be SEARCH_AUTO, indicating to
                                * choose how to search.*/
        int x, y;              /* Screen coordinates of test point */
        int along;             /* Indicates to let search run along a
                                * particular axis: x, y, or both. */
        /* Output */
        RbcElement *elemPtr;   /* Name of the closest element */
        RbcPoint2D point;      /* Graph coordinates of closest point */
        int index;             /* Index of closest data point */
        double dist;           /* Distance in screen coordinates */
    } RbcClosestSearch;

    typedef void (
        RbcElementDrawProc) (
        RbcGraph * graphPtr,
        Drawable drawable,
        RbcElement * elemPtr);
    typedef void (
        RbcElementToPostScriptProc) (
        RbcGraph * graphPtr,
        RbcPsToken * psToken,
        RbcElement * elemPtr);
    typedef void (
        RbcElementDestroyProc) (
        RbcGraph * graphPtr,
        RbcElement * elemPtr);
    typedef int (
        RbcElementConfigProc) (
        RbcGraph * graphPtr,
        RbcElement * elemPtr);
    typedef void (
        RbcElementMapProc) (
        RbcGraph * graphPtr,
        RbcElement * elemPtr);
    typedef void (
        RbcElementExtentsProc) (
        RbcElement * elemPtr,
        RbcExtents2D * extsPtr);
    typedef void (
        RbcElementClosestProc) (
        RbcGraph * graphPtr,
        RbcElement * elemPtr,
        RbcClosestSearch * searchPtr);
    typedef void (
        RbcElementDrawSymbolProc) (
        RbcGraph * graphPtr,
        Drawable drawable,
        RbcElement * elemPtr,
        int x,
        int y,
        int symbolSize);
    typedef void (
        RbcElementSymbolToPostScriptProc) (
        RbcGraph * graphPtr,
        RbcPsToken * psToken,
        RbcElement * elemPtr,
        double x,
        double y,
        int symSize);

/*
 * RbcElementProcs --
 */
    typedef struct {
        RbcElementClosestProc *closestProc;
        RbcElementConfigProc *configProc;
        RbcElementDestroyProc *destroyProc;
        RbcElementDrawProc *drawActiveProc;
        RbcElementDrawProc *drawNormalProc;
        RbcElementDrawSymbolProc *drawSymbolProc;
        RbcElementExtentsProc *extentsProc;
        RbcElementToPostScriptProc *printActiveProc;
        RbcElementToPostScriptProc *printNormalProc;
        RbcElementSymbolToPostScriptProc *printSymbolProc;
        RbcElementMapProc *mapProc;
    } RbcElementProcs;

/*
 * 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. */
    } RbcElemVector;

/*
 * RbcElement --
 */
    typedef struct RbcElement {
        char *name;            /* Identifier to refer the element.
                                * Used in the "insert", "delete", or
                                * "show", commands. */
        Tk_Uid classUid;       /* Type of element */
        RbcGraph *graphPtr;    /* Graph widget of element */
        unsigned int flags;    /* Indicates if the entire element is
                                * active, or if coordinates need to
                                * be calculated */
        char **tags;
        int hidden;            /* If non-zero, don't display the element. */
        Tcl_HashEntry *hashPtr;
        char *label;           /* Label displayed in legend */
        int labelRelief;       /* Relief of label in legend. */
        RbcAxis2D axes;        /* X-axis and Y-axis mapping the element */
        RbcElemVector x, y, w; /* Contains array of floating point
                                * graph coordinate values. Also holds
                                * min/max and the number of
                                * coordinates */
        RbcElemVector xError;  /* Relative/symmetric X error values. */
        RbcElemVector yError;  /* Relative/symmetric Y error values. */
        RbcElemVector xHigh, xLow;      /* Absolute/asymmetric X-coordinate high/low
                                         * error values. */
        RbcElemVector yHigh, yLow;      /* Absolute/asymmetric Y-coordinate high/low
                                         * error values. */
        int *activeIndices;    /* Array of indices (malloc-ed) which
                                * indicate which data points are
                                * active (drawn with "active"
                                * colors). */
        int nActiveIndices;    /* Number of active data points.
                                * Special case: if nActiveIndices < 0
                                * and the active bit is set in
                                * "flags", then all data points are
                                * drawn active. */
        RbcElementProcs *procsPtr;
        Tk_ConfigSpec *specsPtr;        /* Configuration specifications. */
        RbcSegment2D *xErrorBars;       /* Point to start of this pen's X-error bar
                                         * segments in the element's array. */
        RbcSegment2D *yErrorBars;       /* Point to start of this pen's Y-error bar
                                         * segments in the element's array. */
        int xErrorBarCnt;      /* # of error bars for this pen. */
        int yErrorBarCnt;      /* # of error bars for this pen. */
        int *xErrorToData;     /* Maps error bar segments back to the data
                                * point. */
        int *yErrorToData;     /* Maps error bar segments back to the data
                                * point. */
        int errorBarCapWidth;  /* Length of cap on error bars */
        RbcPen *activePenPtr;  /* Standard Pens */
        RbcPen *normalPenPtr;
        RbcChain *palette;     /* Palette of pens. */
        /* Symbol scaling */
        int scaleSymbols;      /* If non-zero, the symbols will scale
                                * in size as the graph is zoomed
                                * in/out.  */
        double xRange, yRange; /* Initial X-axis and Y-axis ranges:
                                * used to scale the size of element's
                                * symbol. */
        int state;
    } RbcElement;

/*
 * RbcFreqInfo --
 */
    typedef struct {
        int freq;              /* Number of occurrences of x-coordinate */
        RbcAxis2D axes;        /* Indicates which x and y axis are mapped to
                                * the x-value */
        double sum;            /* Sum of the ordinates of each duplicate
                                * abscissa */
        int count;
        double lastY;

    } RbcFreqInfo;

/*
 * RbcBarMode --
 *
 *	Bar elements are displayed according to their x-y coordinates.
 *	If two bars have the same abscissa (x-coordinate), the bar
 *	segments will be drawn according to one of the following
 *	modes:
 */
    typedef enum {
        MODE_INFRONT,          /* Each successive segment is drawn in
                                * front of the previous. */
        MODE_STACKED,          /* Each successive segment is drawn
                                * stacked above the previous. */
        MODE_ALIGNED,          /* Each successive segment is drawn
                                * aligned to the previous from
                                * right-to-left. */
        MODE_OVERLAP           /* Like "aligned", each successive segment
                                * is drawn from right-to-left. In addition
                                * the segments will overlap each other
                                * by a small amount */
    } RbcBarMode;

    typedef RbcPen *(
        PenCreateProc) (
        void);
    typedef int (
        PenConfigureProc) (
        RbcGraph * graphPtr,
        RbcPen * penPtr);
    typedef void (
        PenDestroyProc) (
        RbcGraph * graphPtr,
        RbcPen * penPtr);

/*
 * RbcPen --
 */
    typedef struct RbcPen {
        char *name;            /* Pen style identifier.  If NULL pen
                                * was statically allocated. */
        Tk_Uid classUid;       /* Type of pen */
        char *typeId;          /* String token identifying the type of pen */
        unsigned int flags;    /* Indicates if the pen element is active or
                                * normal */
        int refCount;          /* Reference count for elements using
                                * this pen. */
        Tcl_HashEntry *hashPtr;

        Tk_ConfigSpec *configSpecs;     /* Configuration specifications */

        PenConfigureProc *configProc;
        PenDestroyProc *destroyProc;

    } RbcPen;

/*
 * RbcPostScript --
 *
 * 	Structure contains information specific to the outputting of
 *	PostScript commands to print the graph.
 *
 */
    typedef struct {
        /* User configurable fields */

        int decorations;       /* If non-zero, print graph with
                                * color background and 3D borders */

        int reqWidth, reqHeight;        /* If greater than zero, represents the
                                         * requested dimensions of the printed graph */
        int reqPaperWidth;
        int reqPaperHeight;    /* Requested dimensions for the PostScript
                                * page. Can constrain the size of the graph
                                * if the graph (plus padding) is larger than
                                * the size of the page. */
        RbcPad padX, padY;     /* Requested padding on the exterior of the
                                * graph. This forms the bounding box for
                                * the page. */
        RbcPsColorMode colorMode;       /* Selects the color mode for PostScript page
                                         * (0=monochrome, 1=greyscale, 2=color) */
        char *colorVarName;    /* If non-NULL, is the name of a Tcl array
                                * variable containing X to PostScript color
                                * translations */
        char *fontVarName;     /* If non-NULL, is the name of a Tcl array
                                * variable containing X to PostScript font
                                * translations */
        int landscape;         /* If non-zero, orient the page 90 degrees */
        int center;            /* If non-zero, center the graph on the page */
        int maxpect;           /* If non-zero, indicates to scale the graph
                                * so that it fills the page (maintaining the
                                * aspect ratio of the graph) */
        int addPreview;        /* If non-zero, generate a preview image and
                                * add it to the PostScript output */
        int footer;            /* If non-zero, a footer with the title, date
                                * and user will be added to the PostScript
                                * output outside of the bounding box. */
        int previewFormat;     /* Format of EPS preview:
                                * PS_PREVIEW_WMF, PS_PREVIEW_EPSI, or
                                * PS_PREVIEW_TIFF. */

        /* Computed fields */

        int left, bottom;      /* Bounding box of PostScript plot. */
        int right, top;

        double pageScale;      /* Scale of page. Set if "-maxpect" option
                                * is set, otherwise 1.0. */
    } RbcPostScript;

/*
 * RbcGrid --
 *
 *	Contains attributes of describing how to draw grids (at major
 *	ticks) in the graph.  Grids may be mapped to either/both x and
 *	y axis.
 */
    typedef struct {
        GC  gc;                /* Graphics context for the grid. */
        RbcAxis2D axes;
        int hidden;            /* If non-zero, grid isn't displayed. */
        int minorGrid;         /* If non-zero, draw grid line for minor
                                * axis ticks too */
        RbcDashes dashes;      /* Dashstyle of the grid. This represents
                                * an array of alternatingly drawn pixel
                                * values. */
        int lineWidth;         /* Width of the grid lines */
        XColor *colorPtr;      /* Color of the grid lines */

        struct GridSegments {
            RbcSegment2D *segments;     /* Array of line segments representing the
                                         * x or y grid lines */
            int nSegments;     /* # of axis segments. */
        } x,
            y;

    } RbcGrid;

/*
 * RbcMargin --
 */
    typedef struct {
        short int width, height;        /* Extents of the margin */

        short int axesOffset;
        short int axesTitleLength;      /* Width of the widest title to be shown.
                                         * Multiple titles are displayed in
                                         * another margin. This is the minimum
                                         * space requirement. */
        unsigned int nAxes;    /* Number of axes to be displayed */
        RbcChain *axes;        /* Extra axes associated with this margin */

        char *varName;         /* If non-NULL, name of variable to be
                                * updated when the margin size changes */

        int reqSize;           /* Requested size of margin */
        int site;              /* Indicates where margin is located:
                                * left/right/top/bottom. */
    } RbcMargin;

/*
 * RbcGraph --
 *
 *	Top level structure containing everything pertaining to
 *	the graph.
 */
    typedef struct RbcGraph {
        Tk_Window *win;
        Tcl_Object object;
        Tcl_Interp *interp;    /* Interpreter associated with graph */
        Display *display;      /* Display containing widget; needed,
                                * among other things, to release
                                * resources after tkwin has already gone
                                * away. */
        unsigned int flags;    /* Flags;  see below for definitions. */
        Tk_Cursor cursor;
        int inset;             /* Sum of focus highlight and 3-D
                                * border.  Indicates how far to
                                * offset the graph from outside
                                * edge of the window. */
        int borderWidth;       /* Width of the exterior border */
        int relief;            /* Relief of the exterior border */
        Tk_3DBorder border;    /* 3-D border used to delineate the plot
                                * surface and outer edge of window */
        int highlightWidth;    /* Width in pixels of highlight to draw
                                * around widget when it has the focus.
                                * <= 0 means don't draw a highlight. */
        XColor *highlightBgColor;       /* Color for drawing traversal highlight
                                         * area when highlight is off. */
        XColor *highlightColor; /* Color for drawing traversal highlight. */
        char *title;
        short int titleX, titleY;
        RbcTextStyle titleTextStyle;    /* Graph title */
        char *takeFocus;
        int reqWidth, reqHeight;        /* Requested size of graph window */
        int width, height;     /* Size of graph window or PostScript
                                * page */
        Tcl_HashTable penTable; /* Table of pens */
        struct Component {
            Tcl_HashTable table;        /* Hash table of ids. */
            RbcChain *displayList;      /* Display list. */
            Tcl_HashTable tagTable;     /* Table of bind tags. */
        } elements,
            markers,
            axes;
        Tk_Uid 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.
                                 */
        RbcMargin margins[4];
        RbcPostScript *postscript;      /* PostScript options: see rbcGrPS.c */
        RbcLegend *legend;     /* Legend information: see rbcGrLegd.c */
        RbcCrosshairs *crosshairs;      /* Crosshairs information: see rbcGrHairs.c */
        RbcGrid *gridPtr;      /* Grid attribute information */
        int halo;              /* Maximum distance allowed between points
                                * when searching for a point */
        int inverted;          /* If non-zero, indicates the x and y axis
                                * positions should be inverted. */
        RbcTile tile;
        GC  drawGC;            /* Used for drawing on the margins. This
                                * includes the axis lines */
        GC  fillGC;            /* Used to fill the background of the
                                * margins. The fill is governed by
                                * the background color or the tiled
                                * pixmap. */
        int plotBorderWidth;   /* Width of interior 3-D border. */
        int plotRelief;        /* 3-d effect: TK_RELIEF_RAISED etc. */
        XColor *plotBg;        /* Color of plotting surface */
        GC  plotFillGC;        /* Used to fill the plotting area with a
                                * solid background color. The fill color
                                * is stored in "plotBg". */
        /* If non-zero, force plot to conform to aspect ratio W/H */
        double aspect;
        short int left, right; /* Coordinates of plot bbox */
        short int top, bottom;
        RbcPad padX;           /* Vertical padding for plotarea */
        int vRange, vOffset;   /* Vertical axis range and offset from the
                                * left side of the graph window. Used to
                                * transform coordinates to vertical
                                * axes. */
        RbcPad padY;           /* Horizontal padding for plotarea */
        int hRange, hOffset;   /* Horizontal axis range and offset from
                                * the top of the graph window. Used to
                                * transform horizontal axes */
        double vScale, hScale;
        int doubleBuffer;      /* If non-zero, draw the graph into a pixmap
                                * first to reduce flashing. */
        int backingStore;      /* If non-zero, cache elements by drawing
                                * them into a pixmap */
        Pixmap backPixmap;     /* Pixmap used to cache elements
                                * displayed.  If *backingStore* is
                                * non-zero, each element is drawn
                                * into this pixmap before it is
                                * copied onto the screen.  The pixmap
                                * then acts as a cache (only the
                                * pixmap is redisplayed if the none
                                * of elements have changed). This is
                                * done so that markers can be redrawn
                                * quickly over elements without
                                * redrawing each element. */
        int backWidth, backHeight;      /* Size of element backing store pixmap. */
        /*
         * barchart specific information
         */
        double baseline;       /* Baseline from bar chart.  */
        double barWidth;       /* Default width of each bar in graph units.
                                * The default width is 1.0 units. */
        RbcBarMode mode;       /* Mode describing how to display bars
                                * with the same x-coordinates. Mode can
                                * be "stack", "align", or "normal" */
        RbcFreqInfo *freqArr;  /* Contains information about duplicate
                                * x-values in bar elements (malloc-ed).
                                * This information can also be accessed
                                * by the frequency hash table */
        Tcl_HashTable freqTable;        /* */
        int nStacks;           /* Number of entries in frequency array.
                                * If zero, indicates nothing special needs
                                * to be done for "stack" or "align" modes */
    } RbcGraph;

    typedef ClientData(
        MakeTagProc) (
        RbcGraph * graphPtr,
        const char *tagName);

    typedef int (
        RbcSwitchParseProc) (
        ClientData clientData,
        Tcl_Interp * interp,
        char *switchName,
        char *value,
        char *record,
        int offset);

    typedef void (
        RbcSwitchFreeProc) (
        char *ptr);

/*
 * RbcSwitchCustom --
 */
    typedef struct {
        RbcSwitchParseProc *parseProc;  /* Procedure to parse a switch value
                                         * and store it in its converted
                                         * form in the data record. */
        RbcSwitchFreeProc *freeProc;    /* Procedure to free a switch. */
        ClientData clientData; /* Arbitrary one-word value
                                * used by switch parser,
                                * passed to parseProc. */
    } RbcSwitchCustom;

/*
 * Type values for RbcSwitchSpec structures.  See the user
 * documentation for details.
 */
    typedef enum {
        RBC_SWITCH_BOOLEAN, RBC_SWITCH_INT, RBC_SWITCH_INT_POSITIVE,
        RBC_SWITCH_INT_NONNEGATIVE, RBC_SWITCH_DOUBLE, RBC_SWITCH_STRING,
        RBC_SWITCH_LIST, RBC_SWITCH_FLAG, RBC_SWITCH_VALUE, RBC_SWITCH_CUSTOM,
        RBC_SWITCH_END
    } RbcSwitchTypes;

    typedef struct {
        RbcSwitchTypes type;   /* Type of option, such as RBC_SWITCH_DOUBLE;
                                * see definitions above.  Last option in
                                * table must have type RBC_SWITCH_END. */
        const char *switchName; /* Switch used to specify option in argv.
                                 * NULL means this spec is part of a group. */
        int offset;            /* Where in widget record to store value;
                                * use RbcOffset macro to generate values
                                * for this. */
        int flags;             /* Any combination of the values defined
                                * below. */
        RbcSwitchCustom *customPtr;     /* If type is RBC_SWITCH_CUSTOM then this is
                                         * a pointer to info about how to parse and
                                         * print the option.  Otherwise it is
                                         * irrelevant. */
        int value;
    } RbcSwitchSpec;

/*
 * RbcResampleFilter --
 *
 *      Contains information about a 1-D filter (its support and
 *	the procedure implementing the filter).
 */
    typedef struct {
        const char *name;      /* Name of the filter */
        ResampleFilterProc *proc;       /* 1-D filter procedure. */
        double support;        /* Width of 1-D filter */
    } RbcResampleFilter;

/*
 * Data declarations:
 */
    extern double rbcNaN;
    extern RbcResampleFilter *rbcBoxFilterPtr;  /* The ubiquitous box filter */
    extern Tk_Uid rbcBarElementUid;
    extern Tk_Uid rbcLineElementUid;
    extern Tk_Uid rbcStripElementUid;
    extern Tk_Uid rbcLineMarkerUid;
    extern Tk_Uid rbcBitmapMarkerUid;
    extern Tk_Uid rbcImageMarkerUid;
    extern Tk_Uid rbcTextMarkerUid;
    extern Tk_Uid rbcPolygonMarkerUid;
    extern Tk_Uid rbcWindowMarkerUid;
    extern Tk_Uid rbcXAxisUid;
    extern Tk_Uid rbcYAxisUid;

/*
 * Inline function declarations:
 */

/* int RbcNumberOfPoints(RbcAxis2D e); */
#define RbcNumberOfPoints(e)	MIN((e)->x.nValues, (e)->y.nValues)

/* int RbcLineWidth(int w); */
#define RbcLineWidth(w)	(((w) > 1) ? (w) : 0)

/* int RbcPadding(RbcPad w); */
#define RbcPadding(x)	((x).side1 + (x).side2)

/* ClientData RbcGetCurrentItem(RbcBindTable *bindPtr); */
#define RbcGetCurrentItem(bindPtr)  ((bindPtr)->currentItem)
/* */
/* ClientData RbcGetBindingData(RbcBindTable *bindPtr); */
#define RbcGetBindingData(bindPtr)  ((bindPtr)->clientData)
/* int RbcChainGetLength(RbcChain *c); */
#define RbcChainGetLength(c)	(((c) == NULL) ? 0 : (c)->nLinks)
/* RbcChainLink *RbcChainFirstLink(RbcChain *c); */
#define RbcChainFirstLink(c)	(((c) == NULL) ? NULL : (c)->headPtr)
/* */
/* RbcChainLink *RbcChainLastLink(RbcChain *c); */
#define RbcChainLastLink(c)	(((c) == NULL) ? NULL : (c)->tailPtr)
/* RbcChainLink *RbcChainPrevLink(RbcChainLink *l); */
#define RbcChainPrevLink(l)	((l)->prevPtr)
/* RbcChainLink *RbcChainNextLink(RbcChainLink *l); */
#define RbcChainNextLink(l) 	((l)->nextPtr)
/* ClientData RbcChainGetValue(RbcChainLink *l); */
#define RbcChainGetValue(l)  	((l)->clientData)
/* void RbcChainSetValue(RbcChainLink *l, ClientData value); */
#define RbcChainSetValue(l, value) ((l)->clientData = (ClientData)(value))

/*
 * Function declarations:
 */

/* rbcBind.c */
    MODULE_SCOPE int RbcConfigureBindings(
        Tcl_Interp * interp,
        RbcBindTable * table,
        ClientData item,
        int argc,
        const char **argv);
    MODULE_SCOPE int RbcConfigureBindingsFromObj(
        Tcl_Interp * interp,
        RbcBindTable * table,
        ClientData item,
        int objc,
        Tcl_Obj * const *objv);
    MODULE_SCOPE RbcBindTable *RbcCreateBindingTable(
        Tcl_Interp * interp,
        Tk_Window tkwin,
        ClientData clientData,
        RbcBindPickProc * pickProc);
    MODULE_SCOPE void RbcDestroyBindingTable(
        RbcBindTable * table);
    MODULE_SCOPE void RbcPickCurrentItem(
        RbcBindTable * table);
    MODULE_SCOPE void RbcDeleteBindings(
        RbcBindTable * table,
        ClientData object);
    MODULE_SCOPE void RbcMoveBindingTable(
        RbcBindTable * table,
        Tk_Window tkwin);

/* rbcChain,c */
    MODULE_SCOPE RbcChain *RbcChainCreate(
        );
    MODULE_SCOPE void RbcChainInit(
        RbcChain * chainPtr);
    MODULE_SCOPE void RbcChainLinkAfter(
        RbcChain * chainPtr,
        RbcChainLink * linkPtr,
        RbcChainLink * afterLinkPtr);
    MODULE_SCOPE void RbcChainLinkBefore(
        RbcChain * chainPtr,
        RbcChainLink * linkPtr,
        RbcChainLink * beforeLinkPtr);
    MODULE_SCOPE RbcChainLink *RbcChainNewLink(
        void);
    MODULE_SCOPE void RbcChainReset(
        RbcChain * chainPtr);
    MODULE_SCOPE void RbcChainDestroy(
        RbcChain * chainPtr);
    MODULE_SCOPE void RbcChainUnlinkLink(
        RbcChain * chainPtr,
        RbcChainLink * linkPtr);
    MODULE_SCOPE void RbcChainDeleteLink(
        RbcChain * chainPtr,
        RbcChainLink * linkPtr);
    MODULE_SCOPE RbcChainLink *RbcChainAppend(
        RbcChain * chainPtr,
        ClientData clientData);
    MODULE_SCOPE RbcChainLink *RbcChainPrepend(
        RbcChain * chainPtr,
        ClientData clientData);
    MODULE_SCOPE RbcChainLink *RbcChainAllocLink(
        unsigned int size);

/* rbcConfig.c */
    MODULE_SCOPE int RbcGraphOptionSetPad(
        Tcl_Interp * interp,
        Tcl_Object object,
        Tcl_Obj * value,
        RbcPad * address);
    MODULE_SCOPE int RbcGraphOptionSetShadow(
        Tcl_Interp * interp,
        Tcl_Object object,
        Tcl_Obj * value,
        RbcShadow * shadow);
    MODULE_SCOPE int RbcGraphOptionSetTile(
        Tcl_Interp * interp,
        Tcl_Object object,
        Tcl_Obj * value,
        RbcTile * tile);
    MODULE_SCOPE int RbcGetPixels(
        Tcl_Interp * interp,
        Tk_Window tkwin,
        const char *string,
        int check,
        int *valuePtr);
    MODULE_SCOPE int RbcConfigModified(
        Tk_ConfigSpec * specs,
        ...);
    MODULE_SCOPE int RbcConfigureWidgetComponent(
        Tcl_Interp * interp,
        Tk_Window tkwin,
        const char *name,
        const char *class,
        const Tk_ConfigSpec * specs,
        int argc,
        const char **argv,
        char *widgRec,
        int flags);

/* rbcGraph.c */
    MODULE_SCOPE RbcGraph *RbcGraphFromObject(
        Tcl_Object object);
    MODULE_SCOPE void RbcEventuallyRedrawGraph(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcGraphInstCmdProc(
        ClientData clientData,
        Tcl_Interp * interp,
        int argc,
        const char *argv[]);
    MODULE_SCOPE void RbcLayoutGraph(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcDrawGraph(
        RbcGraph * graphPtr,
        Drawable drawable,
        int backingStore);
    MODULE_SCOPE RbcGraph *RbcGetGraphFromWindowData(
        Tk_Window tkwin);
    MODULE_SCOPE int RbcGraphType(
        RbcGraph * graphPtr);

/* rbcGrAxis.c */
    MODULE_SCOPE double RbcInvHMap(
        RbcGraph * graphPtr,
        RbcAxis * axisPtr,
        double x);
    MODULE_SCOPE double RbcInvVMap(
        RbcGraph * graphPtr,
        RbcAxis * axisPtr,
        double x);
    MODULE_SCOPE double RbcHMap(
        RbcGraph * graphPtr,
        RbcAxis * axisPtr,
        double x);
    MODULE_SCOPE double RbcVMap(
        RbcGraph * graphPtr,
        RbcAxis * axisPtr,
        double y);
    MODULE_SCOPE RbcPoint2D RbcMap2D(
        RbcGraph * graphPtr,
        double x,
        double y,
        RbcAxis2D * pairPtr);
    MODULE_SCOPE RbcPoint2D RbcInvMap2D(
        RbcGraph * graphPtr,
        double x,
        double y,
        RbcAxis2D * pairPtr);
    MODULE_SCOPE void RbcResetAxes(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcGetAxisSegments(
        RbcGraph * graphPtr,
        RbcAxis * axisPtr,
        RbcSegment2D ** segPtrPtr,
        int *nSegmentsPtr);
    MODULE_SCOPE void RbcLayoutMargins(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcDestroyAxes(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcDefaultAxes(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcVirtualAxisOp(
        RbcGraph * graphPtr,
        Tcl_Interp * interp,
        int argc,
        const char **argv);
    MODULE_SCOPE int RbcAxisOp(
        RbcGraph * graphPtr,
        int margin,
        int argc,
        const char **argv);
    MODULE_SCOPE void RbcMapAxes(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcDrawAxes(
        RbcGraph * graphPtr,
        Drawable drawable);
    MODULE_SCOPE void RbcAxesToPostScript(
        RbcGraph * graphPtr,
        RbcPsToken * psToken);
    MODULE_SCOPE void RbcDrawAxisLimits(
        RbcGraph * graphPtr,
        Drawable drawable);
    MODULE_SCOPE void RbcAxisLimitsToPostScript(
        RbcGraph * graphPtr,
        RbcPsToken * psToken);
    MODULE_SCOPE RbcAxis *RbcGetFirstAxis(
        RbcChain * chainPtr);
    MODULE_SCOPE RbcAxis *RbcNearestAxis(
        RbcGraph * graphPtr,
        int x,
        int y);
    MODULE_SCOPE ClientData RbcMakeAxisTag(
        RbcGraph * graphPtr,
        const char *tagName);

/* rbcGrBar.c */
    MODULE_SCOPE RbcPen *RbcBarPen(
        const char *penName);
    MODULE_SCOPE RbcElement *RbcBarElement(
        RbcGraph * graphPtr,
        const char *name,
        Tk_Uid type);
    MODULE_SCOPE void RbcInitFreqTable(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcComputeStacks(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcResetStacks(
        RbcGraph * graphPtr);

/* rbcGrElem.c */
    MODULE_SCOPE double RbcFindElemVectorMinimum(
        RbcElemVector * vecPtr,
        double minLimit);
    MODULE_SCOPE void RbcFreePalette(
        RbcGraph * graphPtr,
        RbcChain * palette);
    MODULE_SCOPE int RbcStringToStyles(
        ClientData clientData,
        Tcl_Interp * interp,
        Tk_Window tkwin,
        const char *string,
        char *widgRec,
        int offset);
    MODULE_SCOPE const char *RbcStylesToString(
        ClientData clientData,
        Tk_Window tkwin,
        char *widgRec,
        int offset,
        Tcl_FreeProc ** freeProcPtr);
    MODULE_SCOPE RbcPenStyle **RbcStyleMap(
        RbcElement * elemPtr);
    MODULE_SCOPE void RbcMapErrorBars(
        RbcGraph * graphPtr,
        RbcElement * elemPtr,
        RbcPenStyle ** dataToStyle);
    MODULE_SCOPE void RbcDestroyElements(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcMapElements(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcDrawElements(
        RbcGraph * graphPtr,
        Drawable drawable);
    MODULE_SCOPE void RbcDrawActiveElements(
        RbcGraph * graphPtr,
        Drawable drawable);
    MODULE_SCOPE void RbcElementsToPostScript(
        RbcGraph * graphPtr,
        RbcPsToken * psToken);
    MODULE_SCOPE void RbcActiveElementsToPostScript(
        RbcGraph * graphPtr,
        RbcPsToken * psToken);
    MODULE_SCOPE int RbcGraphUpdateNeeded(
        RbcGraph * graphPtr);
    MODULE_SCOPE ClientData RbcMakeElementTag(
        RbcGraph * graphPtr,
        const char *tagName);
    MODULE_SCOPE int RbcElementOp(
        RbcGraph * graphPtr,
        Tcl_Interp * interp,
        int argc,
        const char **argv,
        Tk_Uid classUid);

/* rbcGrGrid.c */
    MODULE_SCOPE void RbcMapGrid(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcDrawGrid(
        RbcGraph * graphPtr,
        Drawable drawable);
    MODULE_SCOPE void RbcGridToPostScript(
        RbcGraph * graphPtr,
        RbcPsToken * psToken);
    MODULE_SCOPE void RbcDestroyGrid(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcCreateGrid(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcGridOp(
        RbcGraph * graphPtr,
        Tcl_Interp * interp,
        int argc,
        const char **argv);

/* rbcGrHairs.c */
    MODULE_SCOPE void RbcConfigureCrosshairs(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcEnableCrosshairs(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcDisableCrosshairs(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcUpdateCrosshairs(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcDestroyCrosshairs(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcCreateCrosshairs(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcCrosshairsOp(
        RbcGraph * graphPtr,
        Tcl_Interp * interp,
        int argc,
        const char **argv);

/* rbcGrLegd.c */
    MODULE_SCOPE void RbcMapLegend(
        RbcLegend * legendPtr,
        int width,
        int height);
    MODULE_SCOPE void RbcDrawLegend(
        RbcLegend * legendPtr,
        Drawable drawable);
    MODULE_SCOPE void RbcLegendToPostScript(
        RbcLegend * legendPtr,
        RbcPsToken * psToken);
    MODULE_SCOPE void RbcDestroyLegend(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcCreateLegend(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcLegendOp(
        RbcGraph * graphPtr,
        Tcl_Interp * interp,
        int argc,
        const char **argv);
    MODULE_SCOPE int RbcLegendSite(
        RbcLegend * legendPtr);
    MODULE_SCOPE int RbcLegendWidth(
        RbcLegend * legendPtr);
    MODULE_SCOPE int RbcLegendHeight(
        RbcLegend * legendPtr);
    MODULE_SCOPE int RbcLegendIsHidden(
        RbcLegend * legendPtr);
    MODULE_SCOPE int RbcLegendIsRaised(
        RbcLegend * legendPtr);
    MODULE_SCOPE int RbcLegendX(
        RbcLegend * legendPtr);
    MODULE_SCOPE int RbcLegendY(
        RbcLegend * legendPtr);
    MODULE_SCOPE void RbcLegendRemoveElement(
        RbcLegend * legendPtr,
        RbcElement * elemPtr);

/* rbcGrLine.c */
    MODULE_SCOPE RbcPen *RbcLinePen(
        const char *penName);
    MODULE_SCOPE RbcElement *RbcLineElement(
        RbcGraph * graphPtr,
        const char *name,
        Tk_Uid classUid);

/* rbcGrMarker.c */
    MODULE_SCOPE ClientData RbcMakeMarkerTag(
        RbcGraph * graphPtr,
        const char *tagName);
    MODULE_SCOPE int RbcMarkerOp(
        RbcGraph * graphPtr,
        Tcl_Interp * interp,
        int argc,
        const char **argv);
    MODULE_SCOPE void RbcMarkersToPostScript(
        RbcGraph * graphPtr,
        RbcPsToken * psToken,
        int under);
    MODULE_SCOPE void RbcDrawMarkers(
        RbcGraph * graphPtr,
        Drawable drawable,
        int under);
    MODULE_SCOPE void RbcMapMarkers(
        RbcGraph * graphPtr);
    MODULE_SCOPE void RbcDestroyMarkers(
        RbcGraph * graphPtr);
    MODULE_SCOPE RbcMarker *RbcNearestMarker(
        RbcGraph * graphPtr,
        int x,
        int y,
        int under);

/* rbcGrMisc.c */
    MODULE_SCOPE int RbcGetXY(
        Tcl_Interp * interp,
        Tk_Window tkwin,
        const char *string,
        int *x,
        int *y);
    MODULE_SCOPE void RbcFreeColorPair(
        RbcColorPair * pairPtr);
    MODULE_SCOPE int RbcPointInSegments(
        RbcPoint2D * samplePtr,
        RbcSegment2D * segments,
        int nSegments,
        double halo);
    MODULE_SCOPE int RbcPointInPolygon(
        RbcPoint2D * samplePtr,
        RbcPoint2D * screenPts,
        int nScreenPts);
    MODULE_SCOPE int RbcRegionInPolygon(
        RbcExtents2D * extsPtr,
        RbcPoint2D * points,
        int nPoints,
        int enclosed);
    MODULE_SCOPE void RbcGraphExtents(
        RbcGraph * graphPtr,
        RbcExtents2D * extsPtr);
    MODULE_SCOPE int RbcLineRectClip(
        RbcExtents2D * extsPtr,
        RbcPoint2D * p,
        RbcPoint2D * q);
    MODULE_SCOPE int RbcPolyRectClip(
        RbcExtents2D * extsPtr,
        RbcPoint2D * inputPts,
        int nInputPts,
        RbcPoint2D * outputPts);
    MODULE_SCOPE RbcPoint2D RbcGetProjection(
        int x,
        int y,
        RbcPoint2D * p,
        RbcPoint2D * q);
    MODULE_SCOPE int RbcAdjustViewport(
        int offset,
        int worldSize,
        int windowSize,
        int scrollUnits,
        int scrollMode);
    MODULE_SCOPE int RbcGetScrollInfo(
        Tcl_Interp * interp,
        int argc,
        char **argv,
        int *offsetPtr,
        int worldSize,
        int windowSize,
        int scrollUnits,
        int scrollMode);
    MODULE_SCOPE int RbcGetScrollInfoFromObj(
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const *objv,
        int *offsetPtr,
        int worldSize,
        int windowSize,
        int scrollUnits,
        int scrollMode);
    MODULE_SCOPE void RbcUpdateScrollbar(
        Tcl_Interp * interp,
        char *scrollCmd,
        double firstFract,
        double lastFract);
    MODULE_SCOPE GC RbcGetPrivateGCFromDrawable(
        Display * display,
        Drawable drawable,
        unsigned long gcMask,
        XGCValues * valuePtr);
    MODULE_SCOPE GC RbcGetPrivateGC(
        Tk_Window tkwin,
        unsigned long gcMask,
        XGCValues * valuePtr);
    MODULE_SCOPE void RbcFreePrivateGC(
        Display * display,
        GC gc);
    MODULE_SCOPE void RbcSetDashes(
        Display * display,
        GC gc,
        RbcDashes * dashesPtr);
    MODULE_SCOPE int RbcSimplifyLine(
        RbcPoint2D * origPts,
        int low,
        int high,
        double tolerance,
        int indices[]);
    MODULE_SCOPE void RbcDraw2DSegments(
        Display * display,
        Drawable drawable,
        GC gc,
        RbcSegment2D * segments,
        int nSegments);
    MODULE_SCOPE int RbcMaxRequestSize(
        Display * display,
        unsigned int elemSize);

/* rbcPen.c */
    MODULE_SCOPE void RbcFreePen(
        RbcGraph * graphPtr,
        RbcPen * penPtr);
    MODULE_SCOPE RbcPen *RbcCreatePen(
        RbcGraph * graphPtr,
        const char *penName,
        Tk_Uid classUid,
        int nOpts,
        const char **options);
    MODULE_SCOPE int RbcGetPen(
        RbcGraph * graphPtr,
        const char *name,
        Tk_Uid classUid,
        RbcPen ** penPtrPtr);
    MODULE_SCOPE void RbcDestroyPens(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcPenOp(
        RbcGraph * graphPtr,
        Tcl_Interp * interp,
        int argc,
        const char **argv);

/* rbcGrPs.c */
    MODULE_SCOPE void RbcDestroyPostScript(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcCreatePostScript(
        RbcGraph * graphPtr);
    MODULE_SCOPE int RbcPostScriptOp(
        RbcGraph * graphPtr,
        Tcl_Interp * interp,
        int argc,
        const char *argv[]);

/* rbcImage.c */
    MODULE_SCOPE RbcColorImage *RbcCreateColorImage(
        int width,
        int height);
    MODULE_SCOPE void RbcFreeColorImage(
        RbcColorImage * image);
    MODULE_SCOPE void RbcGammaCorrectColorImage(
        RbcColorImage * src,
        double newGamma);
    MODULE_SCOPE void RbcColorImageToGreyscale(
        RbcColorImage * image);
    MODULE_SCOPE void RbcColorImageToPhoto(
        Tcl_Interp * interp,
        RbcColorImage * image,
        Tk_PhotoHandle photo);
    MODULE_SCOPE RbcColorImage *RbcPhotoRegionToColorImage(
        Tk_PhotoHandle photo,
        int x,
        int y,
        int width,
        int height);
    MODULE_SCOPE RbcColorImage *RbcPhotoToColorImage(
        Tk_PhotoHandle photo);
    MODULE_SCOPE int RbcGetResampleFilter(
        Tcl_Interp * interp,
        char *filterName,
        RbcResampleFilter ** filterPtrPtr);
    MODULE_SCOPE RbcColorImage *RbcResampleColorImage(
        RbcColorImage * image,
        int destWidth,
        int destHeight,
        RbcResampleFilter * horzFilterPtr,
        RbcResampleFilter * vertFilterPtr);
    MODULE_SCOPE void RbcResamplePhoto(
        Tcl_Interp * interp,
        Tk_PhotoHandle srcPhoto,
        int x,
        int y,
        int width,
        int height,
        Tk_PhotoHandle destPhoto,
        RbcResampleFilter * horzFilterPtr,
        RbcResampleFilter * vertFilterPtr);
    MODULE_SCOPE void RbcResizePhoto(
        Tcl_Interp * interp,
        Tk_PhotoHandle srcPhoto,
        int x,
        int y,
        int width,
        int height,
        Tk_PhotoHandle destPhoto);
    MODULE_SCOPE RbcColorImage *RbcResizeColorImage(
        RbcColorImage * src,
        int x,
        int y,
        int width,
        int height,
        int destWidth,
        int destHeight);
    MODULE_SCOPE RbcColorImage *RbcResizeColorSubimage(
        RbcColorImage * src,
        int x,
        int y,
        int width,
        int height,
        int destWidth,
        int destHeight);
    MODULE_SCOPE RbcColorImage *RbcConvolveColorImage(
        RbcColorImage * srcImage,
        RbcFilter2D * filter);
    MODULE_SCOPE int RbcSnapPhoto(
        Tcl_Interp * interp,
        Tk_Window tkwin,
        Drawable drawable,
        int x,
        int y,
        int width,
        int height,
        int destWidth,
        int destHeight,
        const char *photoName,
        double inputGamma);
    MODULE_SCOPE RbcColorImage *RbcRotateColorImage(
        RbcColorImage * image,
        double theta);
    MODULE_SCOPE int RbcQuantizeColorImage(
        RbcColorImage * src,
        RbcColorImage * dest,
        int nColors);
    MODULE_SCOPE RbcRegion2D *RbcSetRegion(
        int x,
        int y,
        int width,
        int height,
        RbcRegion2D * regionPtr);
    MODULE_SCOPE Tk_Image RbcCreateTemporaryImage(
        Tcl_Interp * interp,
        Tk_Window tkwin,
        ClientData clientData);
    MODULE_SCOPE int RbcDestroyTemporaryImage(
        Tcl_Interp * interp,
        Tk_Image tkImage);
    MODULE_SCOPE const char *RbcNameOfImage(
        Tk_Image tkImage);
    MODULE_SCOPE int RbcImageIsDeleted(
        Tk_Image tkImage);

/* rbcParse.c */
    MODULE_SCOPE void RbcExpandParseValue(
        RbcParseValue * parsePtr,
        int needed);
    MODULE_SCOPE int RbcParseNestedCmd(
        Tcl_Interp * interp,
        char *string,
        int flags,
        char **termPtr,
        RbcParseValue * parsePtr);
    MODULE_SCOPE int RbcParseBraces(
        Tcl_Interp * interp,
        char *string,
        char **termPtr,
        RbcParseValue * parsePtr);
    MODULE_SCOPE int RbcParseQuotes(
        Tcl_Interp * interp,
        char *string,
        int termChar,
        int flags,
        char **termPtr,
        RbcParseValue * parsePtr);

/* rbcPs.c */
    MODULE_SCOPE RbcPsToken *RbcGetPsToken(
        Tcl_Interp * interp,
        Tk_Window tkwin);
    MODULE_SCOPE void RbcReleasePsToken(
        RbcPsToken * psToken);
    MODULE_SCOPE char *RbcPostScriptFromToken(
        RbcPsToken * psToken);
    MODULE_SCOPE char *RbcScratchBufferFromToken(
        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(
        RbcPsToken * psToken,
        Display * display,
        Pixmap bitmap,
        int width,
        int height);
    MODULE_SCOPE int RbcColorImageToPsData(
        RbcColorImage * image,
        int nComponents,
        Tcl_DString * resultPtr,
        const char *prefix);
    MODULE_SCOPE void RbcClearBackgroundToPostScript(
        RbcPsToken * psToken);
    MODULE_SCOPE void RbcLineWidthToPostScript(
        RbcPsToken * psToken,
        int lineWidth);
    MODULE_SCOPE void RbcLineDashesToPostScript(
        RbcPsToken * psToken,
        RbcDashes * dashesPtr);
    MODULE_SCOPE void RbcLineAttributesToPostScript(
        RbcPsToken * psToken,
        XColor * colorPtr,
        int lineWidth,
        RbcDashes * dashesPtr,
        int capStyle,
        int joinStyle);
    MODULE_SCOPE void RbcRectangleToPostScript(
        RbcPsToken * psToken,
        double x,
        double y,
        int width,
        int height);
    MODULE_SCOPE void RbcRegionToPostScript(
        RbcPsToken * psToken,
        double x,
        double y,
        int width,
        int height);
    MODULE_SCOPE void RbcPathToPostScript(
        RbcPsToken * psToken,
        RbcPoint2D * screenPts,
        int nScreenPts);
    MODULE_SCOPE void RbcPolygonToPostScript(
        RbcPsToken * psToken,
        RbcPoint2D * screenPts,
        int nScreenPts);
    MODULE_SCOPE void RbcSegmentsToPostScript(
        RbcPsToken * psToken,
        XSegment * segArr,
        int nSegs);
    MODULE_SCOPE void RbcRectanglesToPostScript(
        RbcPsToken * psToken,
        XRectangle * rectArr,
        int nRects);
    MODULE_SCOPE void RbcDraw3DRectangleToPostScript(
        RbcPsToken * psToken,
        Tk_3DBorder border,
        double x,
        double y,
        int width,
        int height,
        int borderWidth,
        int relief);
    MODULE_SCOPE void RbcFill3DRectangleToPostScript(
        RbcPsToken * psToken,
        Tk_3DBorder border,
        double x,
        double y,
        int width,
        int height,
        int borderWidth,
        int relief);
    MODULE_SCOPE void RbcStippleToPostScript(
        RbcPsToken * psToken,
        Display * display,
        Pixmap bitmap);
    MODULE_SCOPE void RbcColorImageToPostScript(
        RbcPsToken * psToken,
        RbcColorImage * image,
        double x,
        double y);
    MODULE_SCOPE void RbcWindowToPostScript(
        RbcPsToken * psToken,
        Tk_Window tkwin,
        double x,
        double y);
    MODULE_SCOPE void RbcPhotoToPostScript(
        RbcPsToken * psToken,
        Tk_PhotoHandle photoToken,
        double x,
        double y);
    MODULE_SCOPE void RbcFontToPostScript(
        RbcPsToken * psToken,
        Tk_Font font);
    MODULE_SCOPE void RbcTextToPostScript(
        RbcPsToken * psToken,
        char *string,
        RbcTextStyle * attrPtr,
        double x,
        double y);
    MODULE_SCOPE void RbcLineToPostScript(
        RbcPsToken * psToken,
        XPoint * pointArr,
        int nPoints);
    MODULE_SCOPE void RbcBitmapToPostScript(
        RbcPsToken * psToken,
        Display * display,
        Pixmap bitmap,
        double scaleX,
        double scaleY);
    MODULE_SCOPE void Rbc2DSegmentsToPostScript(
        RbcPsToken * psToken,
        RbcSegment2D * segments,
        int nSegments);

/* rbcSpline.c */
    MODULE_SCOPE int RbcQuadraticSpline(
        RbcPoint2D * origPts,
        int nOrigPts,
        RbcPoint2D * intpPts,
        int nIntpPts);
    MODULE_SCOPE int RbcNaturalSpline(
        RbcPoint2D * origPts,
        int nOrigPts,
        RbcPoint2D * intpPts,
        int nIntpPts);
    MODULE_SCOPE int RbcSplineInit(
        Tcl_Interp * interp);
    MODULE_SCOPE int RbcNaturalParametricSpline(
        RbcPoint2D * origPts,
        int nOrigPts,
        RbcExtents2D * extsPtr,
        int isClosed,
        RbcPoint2D * intpPts,
        int nIntpPts);
    MODULE_SCOPE int RbcCatromParametricSpline(
        RbcPoint2D * origPts,
        int nOrigPts,
        RbcPoint2D * intpPts,
        int nIntpPts);

/* rbcSwitch.c */
    MODULE_SCOPE int RbcProcessSwitches(
        Tcl_Interp * interp,
        RbcSwitchSpec * specs,
        int argc,
        const char **argv,
        char *record,
        int flags);
    MODULE_SCOPE int RbcProcessObjSwitches(
        Tcl_Interp * interp,
        RbcSwitchSpec * specPtr,
        int objc,
        Tcl_Obj * const *objv,
        char *record,
        int flags);
    MODULE_SCOPE void RbcFreeSwitches(
        RbcSwitchSpec * specs,
        char *record,
        int flags);
    MODULE_SCOPE int RbcSwitchChanged(
        RbcSwitchSpec * specs,
        ...);

/* rbcText.c */
    MODULE_SCOPE RbcTextLayout *RbcGetTextLayout(
        char *string,
        RbcTextStyle * stylePtr);
    MODULE_SCOPE void RbcGetTextExtents(
        RbcTextStyle * stylePtr,
        char *text,
        int *widthPtr,
        int *heightPtr);
    MODULE_SCOPE void RbcGetBoundingBox(
        int width,
        int height,
        double theta,
        double *widthPtr,
        double *heightPtr,
        RbcPoint2D * points);
    MODULE_SCOPE void RbcTranslateAnchor(
        int x,
        int y,
        int width,
        int height,
        Tk_Anchor anchor,
        int *transXPtr,
        int *transYPtr);
    MODULE_SCOPE RbcPoint2D RbcTranslatePoint(
        RbcPoint2D * pointPtr,
        int width,
        int height,
        Tk_Anchor anchor);
    MODULE_SCOPE void RbcInitTextStyle(
        RbcTextStyle * stylePtr);
    MODULE_SCOPE void RbcSetDrawTextStyle(
        RbcTextStyle * stylePtr,
        Tk_Font font,
        GC gc,
        XColor * normalColor,
        XColor * activeColor,
        XColor * shadowColor,
        double theta,
        Tk_Anchor anchor,
        Tk_Justify justify,
        int leader,
        int shadowOffset);
    MODULE_SCOPE void RbcSetPrintTextStyle(
        RbcTextStyle * stylePtr,
        Tk_Font font,
        XColor * fgColor,
        XColor * bgColor,
        XColor * shadowColor,
        double theta,
        Tk_Anchor anchor,
        Tk_Justify justify,
        int leader,
        int shadowOffset);
    MODULE_SCOPE void RbcDrawTextLayout(
        Tk_Window tkwin,
        Drawable drawable,
        RbcTextLayout * textPtr,
        RbcTextStyle * stylePtr,
        int x,
        int y);
    MODULE_SCOPE void RbcDrawText2(
        Tk_Window tkwin,
        Drawable drawable,
        char *string,
        RbcTextStyle * stylePtr,
        int x,
        int y,
        RbcDim2D * dimPtr);
    MODULE_SCOPE void RbcDrawText(
        Tk_Window tkwin,
        Drawable drawable,
        char *string,
        RbcTextStyle * stylePtr,
        int x,
        int y);
    MODULE_SCOPE GC RbcGetBitmapGC(
        Tk_Window tkwin);
    MODULE_SCOPE void RbcResetTextStyle(
        Tk_Window tkwin,
        RbcTextStyle * stylePtr);
    MODULE_SCOPE void RbcFreeTextStyle(
        Display * display,
        RbcTextStyle * stylePtr);

/* rbcTile.c */
    MODULE_SCOPE int RbcGetTile(
        Tcl_Interp * interp,
        Tk_Window tkwin,
        const char *imageName,
        RbcTile * tilePtr);
    MODULE_SCOPE void RbcFreeTile(
        RbcTile tile);
    MODULE_SCOPE const char *RbcNameOfTile(
        RbcTile tile);
    Pixmap RbcPixmapOfTile(
        RbcTile tile);
    MODULE_SCOPE void RbcSizeOfTile(
        RbcTile tile,
        int *widthPtr,
        int *heightPtr);
    MODULE_SCOPE void RbcSetTileChangedProc(
        RbcTile tile,
        RbcTileChangedProc * changeProc,
        ClientData clientData);
    MODULE_SCOPE void RbcSetTileOrigin(
        Tk_Window tkwin,
        RbcTile tile,
        int x,
        int y);
    MODULE_SCOPE void RbcSetTSOrigin(
        Tk_Window tkwin,
        RbcTile tile,
        int x,
        int y);
    MODULE_SCOPE void RbcTilePolygon(
        Tk_Window tkwin,
        Drawable drawable,
        RbcTile tile,
        XPoint * pointArr,
        int nPoints);
    MODULE_SCOPE void RbcTileRectangle(
        Tk_Window tkwin,
        Drawable drawable,
        RbcTile tile,
        int x,
        int y,
        unsigned int width,
        unsigned int height);
    MODULE_SCOPE void RbcTileRectangles(
        Tk_Window tkwin,
        Drawable drawable,
        RbcTile tile,
        XRectangle * rectArr,
        int nRects);

/* rbcUtil.c */
    MODULE_SCOPE void *RbcCalloc(
        unsigned int nElem,
        size_t size);
    MODULE_SCOPE char *RbcStrdup(
        const char *ptr);
    MODULE_SCOPE RbcOp RbcGetOp(
        Tcl_Interp * interp,
        int nSpecs,
        RbcOpSpec * specArr,
        int operPos,
        int argc,
        const char **argv,
        int flags);
    MODULE_SCOPE RbcOp RbcGetOpFromObj(
        Tcl_Interp * interp,
        int nSpecs,
        RbcOpSpec * specArr,
        int operPos,
        int objc,
        Tcl_Obj * const *objv,
        int flags);

/* 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[]);
    MODULE_SCOPE int RbcArithOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcBinreadOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcClearOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcDeleteOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcDupOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcExprOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcIndexOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcLengthOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcMergeOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcNormalizeOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcOffsetOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcPopulateOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcRandomOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcRangeOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcSearchOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcSeqOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcSetOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcSortOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcSplitOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int RbcVariableOp(
        RbcVectorObject * vPtr,
        Tcl_Interp * interp,
        int objc,
        Tcl_Obj * const objv[]);
    MODULE_SCOPE int *RbcVectorSortIndex(
        RbcVectorObject ** vPtrPtr,
        int nVectors);

/* rbcVector.c */
    MODULE_SCOPE double Rbcdrand48(
        void);
    MODULE_SCOPE RbcVectorInterpData *RbcVectorGetInterpData(
        Tcl_Interp * interp);
    MODULE_SCOPE RbcVectorObject *RbcVectorNew(
        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(
        Tcl_Interp * interp,
        RbcVectorObject * vPtr,
        const char *name);
    MODULE_SCOPE int RbcVectorReset(
        RbcVectorObject * vPtr,
        double *valueArr,
        int length,
        int size,
        Tcl_FreeProc * freeProc);
    MODULE_SCOPE int RbcVectorNotifyPending(
        RbcVectorId clientId);
    MODULE_SCOPE int RbcVectorChangeLength(
        RbcVectorObject * vPtr,
        int length);
    MODULE_SCOPE int RbcVectorLookupName(
        RbcVectorInterpData * dataPtr,
        const char *vecName,
        RbcVectorObject ** vPtrPtr);
    MODULE_SCOPE void RbcVectorUpdateRange(
        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(
        RbcVectorObject * vPtr);
    MODULE_SCOPE Tcl_Obj *RbcGetValues(
        RbcVectorObject * vPtr,
        int first,
        int last);
    MODULE_SCOPE void RbcReplicateValue(
        RbcVectorObject * vPtr,
        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(
        Tk_Window parent,
        char *name);
    MODULE_SCOPE void RbcSetWindowInstanceData(
        Tk_Window tkwin,
        ClientData instanceData);
    MODULE_SCOPE ClientData RbcGetWindowInstanceData(
        Tk_Window tkwin);
    MODULE_SCOPE void RbcDeleteWindowInstanceData(
        Tk_Window tkwin);

/* rbcWinImage.c rbcUnixImage.c */
    MODULE_SCOPE RbcColorImage *RbcDrawableToColorImage(
        Tk_Window tkwin,
        Drawable drawable,
        int x,
        int y,
        int width,
        int height,
        double inputGamma);
    MODULE_SCOPE Pixmap RbcPhotoImageMask(
        Tk_Window tkwin,
        Tk_PhotoImageBlock src);
    MODULE_SCOPE Pixmap RbcRotateBitmap(
        Tk_Window tkwin,
        Pixmap bitmap,
        int width,
        int height,
        double theta,
        int *widthPtr,
        int *heightPtr);
    MODULE_SCOPE Pixmap RbcScaleBitmap(
        Tk_Window tkwin,
        Pixmap srcBitmap,
        int srcWidth,
        int srcHeight,
        int scaledWidth,
        int scaledHeight);
    MODULE_SCOPE Pixmap RbcScaleRotateBitmapRegion(
        Tk_Window tkwin,
        Pixmap srcBitmap,
        unsigned int srcWidth,
        unsigned int srcHeight,
        int regionX,
        int regionY,
        unsigned int regionWidth,
        unsigned int regionHeight,
        unsigned int virtWidth,
        unsigned int virtHeight,
        double theta);

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

#ifndef _WIN32
#define PurifyPrintf  printf
#endif                         /* _WIN32 */

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

/*
 * end block for C++
 */

#ifdef __cplusplus
}
#endif
#endif                         /* _TKOGRAPH_H */
/* vim: set ts=4 sw=4 sts=4 ff=unix et : */

Added generic/tko/tkoGraphAxis.c.




































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
/*
 * rbcGrAxis.c --
 *
 *      This module implements coordinate axes for the rbc graph widget.
 *
 * Copyright (c) 2001 BLT was created by George Howlett.
 * Copyright (c) 2009 RBC was created by Samuel Green, Nicholas Hudson, Stanton Sievers, Jarrod Stormo
 * Copyright (c) 2018 Rene Zaumseil

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

#include "tkoGraph.h"

#define AXIS_CONFIG_MAJOR (1<<4)        /* User specified major tick intervals. */
#define AXIS_CONFIG_MINOR (1<<5)        /* User specified minor tick intervals. */
#define AXIS_ONSCREEN	  (1<<6)        /* Axis is displayed on the screen via
                                         * the "use" operation */
#define AXIS_DIRTY	  (1<<7)
#define AXIS_ALLOW_NULL   (1<<12)

#define DEF_NUM_TICKS		10      /* Each major tick is 10% */
#define STATIC_TICK_SPACE	10

#define TICK_LABEL_SIZE		200
#define MAXTICKS		10001

/*
 * Round x in terms of units
 */
#define UROUND(x,u)		(Round((x)/(u))*(u))
#define UCEIL(x,u)		(ceil((x)/(u))*(u))
#define UFLOOR(x,u)		(floor((x)/(u))*(u))

#define LENGTH_MAJOR_TICK 	0.030   /* Length of a major tick */
#define LENGTH_MINOR_TICK 	0.015   /* Length of a minor (sub)tick */
#define LENGTH_LABEL_TICK 	0.040   /* Distance from graph to start of the
                                         * label */
#define NUMDIGITS		15      /* Specifies the number of
                                         * digits of accuracy used when
                                         * outputting axis tick labels. */
#define AVG_TICK_NUM_CHARS	16      /* Assumed average tick label size */

#define TICK_RANGE_TIGHT	0
#define TICK_RANGE_LOOSE	1
#define TICK_RANGE_ALWAYS_LOOSE	2

#define AXIS_TITLE_PAD		2       /* Padding for axis title. */
#define AXIS_LINE_PAD		1       /* Padding for axis line. */

#define HORIZMARGIN(m)	(!((m)->site & 0x1))    /* Even sites are horizontal */

typedef enum AxisComponents {
    MAJOR_TICK, MINOR_TICK, TICK_LABEL, AXIS_LINE
} AxisComponent;

/*
 * TickLabel --
 *
 * 	Structure containing the X-Y screen coordinates of the tick
<