File: scatterplotClass.c

package info (click to toggle)
ggobi 2.1.9~20091212-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 19,340 kB
  • ctags: 5,083
  • sloc: ansic: 57,242; xml: 30,604; cpp: 833; makefile: 355; java: 225; perl: 201; sh: 122; python: 23
file content (1707 lines) | stat: -rw-r--r-- 50,281 bytes parent folder | download | duplicates (3)
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
/* scatterplotClass.c */
/*
 * ggobi
 * Copyright (C) AT&T, Duncan Temple Lang, Dianne Cook 1999-2005
 *
 * ggobi is free software; you may use, redistribute, and/or modify it
 * under the terms of the Common Public License, which is distributed
 * with the source code and displayed on the ggobi web site, 
 * www.ggobi.org.  For more information, contact the authors:
 *
 *   Deborah F. Swayne   dfs@research.att.com
 *   Di Cook             dicook@iastate.edu
 *   Duncan Temple Lang  duncan@wald.ucdavis.edu
 *   Andreas Buja        andreas.buja@wharton.upenn.edu
*/

#include "ggobi.h"
#include "scatterplotClass.h"
#include "externs.h"

#include <string.h>

#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

#ifdef ENABLE_CAIRO
#include <math.h>
#endif

/*
  display_datad_added_cb() in display.c
    scatterplot_wants to display_edge_menu_update()
    Hint that scatmat_edge... also needed.

  display_options_cb

  varpanel_highd needs a new method to be defined.

  viewmode_set needs a special handler. 

  motion_notify_cb in movepts_ui.c works only for scatterplot and
  scatterplot matrices
  Perhaps just don't register the event handler for other types.
  Same with button_press_cb

  world_to_raw needs methods.

  display_data_added_cb should only be called for scatterplot guys.
  
   splot_draw_to_pixmap0_unbinned needs an additional pre-plot hook for drawing edges.

  tour1d tourcorr and tour2d realloc up's don't get done for anything but scatterplot. 
  
  varcircle_draw needs a hook.

  selectScatterplotX only applies to scatterplots.

*/

static void
setShowAxesLabelOption (displayd * display, gboolean active)
{
  if (display->cpanel.pmode == TOUR2D)
    display_plot (display, FULL, display->ggobi);
  else if (display->cpanel.pmode == TOUR2D3)
    display_plot (display, FULL, display->ggobi);
}

static void
setShowAxesValuesOption (displayd * display, gboolean active)
{
  if (display->cpanel.pmode == TOUR2D)
    display_plot (display, FULL, display->ggobi);
  else if (display->cpanel.pmode == TOUR2D3)
    display_plot (display, FULL, display->ggobi);
}

static void
setShowAxesOption (displayd * display, gboolean active)
{
  switch (display->cpanel.pmode) {
  case XYPLOT:
    if (display->hrule != NULL) {
      scatterplot_show_vrule (display, active);
      scatterplot_show_hrule (display, active);
    }
    break;
  case P1PLOT:
    if (display->hrule != NULL) {
      if (display->p1d_orientation == VERTICAL)
        scatterplot_show_vrule (display, active);
      else
        scatterplot_show_hrule (display, active);
    }
  case TOUR1D:
  case TOUR2D3:
  case TOUR2D:
  case COTOUR:
    display_plot (display, FULL, display->ggobi);
    break;
  default:
    break;
  }
}

static void
selectXVar (GtkWidget * w, displayd * display, gint jvar, ggobid * gg)
{
  GGobiData *d = display->d;
  splotd *sp = (splotd *) display->splots->data;
  cpaneld *cpanel = &display->cpanel;

  varsel (w, cpanel, sp, jvar, VARSEL_X, -1, false, false, false, d, gg);
}

static void
varpanelRefresh (displayd * display, splotd * sp, GGobiData * d)
{
  cpaneld *cpanel = &display->cpanel;
  gint j;

  switch (cpanel->pmode) {
  case P1PLOT:
    for (j = 0; j < d->ncols; j++) {
      varpanel_toggle_set_active (VARSEL_X, j, j == sp->p1dvar, d);

      varpanel_toggle_set_active (VARSEL_Y, j, false, d);
      varpanel_widget_set_visible (VARSEL_Y, j, false, d);
      varpanel_toggle_set_active (VARSEL_Z, j, false, d);
      varpanel_widget_set_visible (VARSEL_Z, j, false, d);
    }
    break;
  case XYPLOT:
    for (j = 0; j < d->ncols; j++) {
      varpanel_toggle_set_active (VARSEL_X, j, (j == sp->xyvars.x), d);
      varpanel_widget_set_visible (VARSEL_Y, j, true, d);
      varpanel_toggle_set_active (VARSEL_Y, j, (j == sp->xyvars.y), d);

      varpanel_toggle_set_active (VARSEL_Z, j, false, d);
      varpanel_widget_set_visible (VARSEL_Z, j, false, d);
    }
    break;

  case TOUR1D:
    for (j = 0; j < d->ncols; j++) {
      varpanel_toggle_set_active (VARSEL_X, j, false, d);
      varpanel_toggle_set_active (VARSEL_Y, j, false, d);
      varpanel_widget_set_visible (VARSEL_Y, j, false, d);
      varpanel_toggle_set_active (VARSEL_Z, j, false, d);
      varpanel_widget_set_visible (VARSEL_Z, j, false, d);
    }
    for (j = 0; j < display->t1d.nsubset; j++) {
      varpanel_toggle_set_active (VARSEL_X,
                                  display->t1d.subset_vars.els[j], true, d);
    }
    break;

  case TOUR2D3:
    for (j = 0; j < d->ncols; j++) {
      varpanel_toggle_set_active (VARSEL_X, j, false, d);
      varpanel_toggle_set_active (VARSEL_Y, j, false, d);
      varpanel_widget_set_visible (VARSEL_Y, j, true, d);
      varpanel_toggle_set_active (VARSEL_Z, j, false, d);
      varpanel_widget_set_visible (VARSEL_Z, j, true, d);
    }

    varpanel_toggle_set_active (VARSEL_X,
                                display->t2d3.subset_vars.els[0], true, d);
    varpanel_toggle_set_active (VARSEL_Y,
                                display->t2d3.subset_vars.els[1], true, d);
    varpanel_toggle_set_active (VARSEL_Z,
                                display->t2d3.subset_vars.els[2], true, d);
    break;

  case TOUR2D:
    for (j = 0; j < d->ncols; j++) {
      varpanel_toggle_set_active (VARSEL_X, j, false, d);
      varpanel_toggle_set_active (VARSEL_Y, j, false, d);
      varpanel_widget_set_visible (VARSEL_Y, j, false, d);
      varpanel_toggle_set_active (VARSEL_Z, j, false, d);
      varpanel_widget_set_visible (VARSEL_Z, j, false, d);
    }
    for (j = 0; j < display->t2d.nsubset; j++) {
      varpanel_toggle_set_active (VARSEL_X,
                                  display->t2d.subset_vars.els[j], true, d);
    }
    break;
  case COTOUR:
    for (j = 0; j < d->ncols; j++) {
      varpanel_toggle_set_active (VARSEL_X, j, false, d);
      varpanel_toggle_set_active (VARSEL_Y, j, false, d);
      varpanel_widget_set_visible (VARSEL_Y, j, true, d);
      varpanel_toggle_set_active (VARSEL_Z, j, false, d);
      varpanel_widget_set_visible (VARSEL_Z, j, false, d);
    }
    for (j = 0; j < display->tcorr1.nsubset; j++) {
      varpanel_toggle_set_active (VARSEL_X,
                                  display->tcorr1.subset_vars.els[j], true,
                                  d);
    }
    for (j = 0; j < display->tcorr2.nsubset; j++) {
      varpanel_toggle_set_active (VARSEL_Y,
                                  display->tcorr2.subset_vars.els[j], true,
                                  d);
    }
    break;
    /*-- to pacify compiler --*/
  default:
    break;
  }
}

static gboolean
variableSelect (GtkWidget * w, displayd * display, splotd * sp, gint jvar,
                gint toggle, gint mouse, cpaneld * cpanel, ggobid * gg)
{
  gboolean redraw = false;
  gint jvar_prev = -1;

  switch (cpanel->pmode) {
  case P1PLOT:
    redraw = p1d_varsel (sp, jvar, &jvar_prev, toggle, mouse);
    if (imode_get (gg) == BRUSH && cpanel->br.mode == BR_TRANSIENT)
      reinit_transient_brushing (display, gg);
    break;
  case XYPLOT:
    redraw = xyplot_varsel (sp, jvar, &jvar_prev, toggle, mouse);
    if (redraw)
      if (imode_get (gg) == BRUSH && cpanel->br.mode == BR_TRANSIENT)
        reinit_transient_brushing (display, gg);
    break;
  case TOUR1D:
    redraw = tour1d_varsel (w, jvar, toggle, mouse, display->d, gg);
    break;
  case TOUR2D3:
    redraw = tour2d3_varsel (w, jvar, toggle, mouse, display->d, gg);
    break;
  case TOUR2D:
    redraw = tour2d_varsel (w, jvar, toggle, mouse, display->d, gg);
    break;
  case COTOUR:
    redraw = tourcorr_varsel (w, jvar, toggle, mouse, display->d, gg);
    break;
    /*-- to pacify compiler if we change these to an enum --*/
  default:
    break;
  }
  return (redraw);
}

static gboolean
varcircleDraw (displayd * display, gint jvar, GdkPixmap * da_pix, ggobid * gg)
{
  gdouble r = VAR_CIRCLE_DIAM / 2.0;
  gint x, y, k;
  cpaneld *cpanel = &display->cpanel;
  gboolean chosen = false;

#ifdef ENABLE_CAIRO
  cairo_t *c = gdk_cairo_create (da_pix);
  cairo_set_source_rgb (c, 1.0, 0, 1.0);
  cairo_set_line_width (c, 1);
#endif

  switch (cpanel->pmode) {
  case TOUR1D:
    x = (gint) (display->t1d.F.vals[0][jvar] * (gfloat) r);
    y = 0;
#ifndef ENABLE_CAIRO
    gdk_draw_line (da_pix, gg->selvarfg_GC, r, r, r + x, r - y);
#endif
    if (jvar == display->t1d_manip_var) {
#ifdef ENABLE_CAIRO
      cairo_arc (c, r, r, r - 5, (5.0 / 6) * M_PI, (7.0 / 6) * M_PI);
      cairo_stroke (c);
      cairo_arc (c, r, r, r - 5, (11.0 / 6) * M_PI, (13.0 / 6) * M_PI);
#else
      gdk_draw_arc (da_pix, gg->manipvarfg_GC, false,
                    5, 5, VAR_CIRCLE_DIAM - 10, VAR_CIRCLE_DIAM - 10,
                    150 * 64, 60 * 64);
      gdk_draw_arc (da_pix, gg->manipvarfg_GC, false, 5, 5,
                    VAR_CIRCLE_DIAM - 10, VAR_CIRCLE_DIAM - 10, 330 * 64,
                    60 * 64);
#endif
    }

    for (k = 0; k < display->t1d.nactive; k++) {
      if (display->t1d.active_vars.els[k] == jvar) {
        chosen = true;
        break;
      }
    }
    break;

  case TOUR2D3:
    x = (gint) (display->t2d3.F.vals[0][jvar] * (gfloat) r);
    y = (gint) (display->t2d3.F.vals[1][jvar] * (gfloat) r);
#ifndef ENABLE_CAIRO
    gdk_draw_line (da_pix, gg->selvarfg_GC, r, r, r + x, r - y);
#endif
    if (jvar == display->t2d3_manip_var) {
#ifdef ENABLE_CAIRO
      cairo_arc (c, r, r, r - 5, 0, 2 * M_PI);
#else
      gdk_draw_arc (da_pix, gg->manipvarfg_GC, false,
                    5, 5, VAR_CIRCLE_DIAM - 10, VAR_CIRCLE_DIAM - 10, 0 * 64,
                    360 * 64);
#endif
    }

    for (k = 0; k < display->t2d3.nactive; k++) {
      if (display->t2d3.active_vars.els[k] == jvar) {
        chosen = true;
        break;
      }
    }
    break;

  case TOUR2D:
    x = (gint) (display->t2d.F.vals[0][jvar] * (gfloat) r);
    y = (gint) (display->t2d.F.vals[1][jvar] * (gfloat) r);
#ifndef ENABLE_CAIRO
    gdk_draw_line (da_pix, gg->selvarfg_GC, r, r, r + x, r - y);
#endif
    if (jvar == display->t2d_manip_var) {
#ifdef ENABLE_CAIRO
      cairo_arc (c, r, r, r - 5, 0, 2 * M_PI);
#else
      gdk_draw_arc (da_pix, gg->manipvarfg_GC, false,
                    5, 5, VAR_CIRCLE_DIAM - 10, VAR_CIRCLE_DIAM - 10, 0 * 64,
                    360 * 64);
#endif
    }

    for (k = 0; k < display->t2d.nactive; k++) {
      if (display->t2d.active_vars.els[k] == jvar) {
        chosen = true;
        break;
      }
    }
    break;
  case COTOUR:
    /*          for (i=0; i<display->tcorr1.nactive; i++)
       if (jvar == display->tcorr1.active_vars.els[i]) {
       xvar = true;
       break;
       } */
    /*          if (xvar) { */
    x = (gint) (display->tcorr1.F.vals[0][jvar] * (gfloat) r);
    y = (gint) (display->tcorr2.F.vals[0][jvar] * (gfloat) r);
#ifndef ENABLE_CAIRO
    gdk_draw_line (da_pix, gg->selvarfg_GC, r, r, r + x, r - y);
#endif
    if (jvar == display->tc1_manip_var) {
#ifdef ENABLE_CAIRO
      cairo_arc (c, r, r, r - 5, (5.0 / 6) * M_PI, (7.0 / 6) * M_PI);
      cairo_stroke (c);
      cairo_arc (c, r, r, r - 5, (11.0 / 6) * M_PI, (13.0 / 6) * M_PI);
#else
      gdk_draw_arc (da_pix, gg->manipvarfg_GC, false,
                    5, 5, VAR_CIRCLE_DIAM - 10, VAR_CIRCLE_DIAM - 10,
                    150 * 64, 60 * 64);
      gdk_draw_arc (da_pix, gg->manipvarfg_GC, false, 5, 5,
                    VAR_CIRCLE_DIAM - 10, VAR_CIRCLE_DIAM - 10, 330 * 64,
                    60 * 64);
#endif
    }
    if (jvar == display->tc2_manip_var) {
#ifdef ENABLE_CAIRO
      cairo_arc (c, r, r, r - 5, (1.0 / 3) * M_PI, (2.0 / 3) * M_PI);
      cairo_stroke (c);
      cairo_arc (c, r, r, r - 5, (4.0 / 3) * M_PI, (5.0 / 3) * M_PI);
#else
      gdk_draw_arc (da_pix, gg->manipvarfg_GC, false,
                    5, 5, VAR_CIRCLE_DIAM - 10, VAR_CIRCLE_DIAM - 10, 60 * 64,
                    60 * 64);
      gdk_draw_arc (da_pix, gg->manipvarfg_GC, false, 5, 5,
                    VAR_CIRCLE_DIAM - 10, VAR_CIRCLE_DIAM - 10, 240 * 64,
                    60 * 64);
#endif
    }

    for (k = 0; k < display->tcorr1.nactive; k++) {
      if (display->tcorr1.active_vars.els[k] == jvar) {
        chosen = true;
        break;
      }
    }
    for (k = 0; k < display->tcorr2.nactive; k++) {
      if (display->tcorr2.active_vars.els[k] == jvar) {
        chosen = true;
        break;
      }
    }
    break;






    /*      } 
       else {

       x = 0;
       y = (gint) (display->tcorr2.F.vals[0][jvar]*(gfloat)r);
       gdk_draw_line (da_pix,
       gg->selvarfg_GC, r, r, r+x, r-y);

       } */

  default:
    break;
  }

#ifdef ENABLE_CAIRO
  cairo_stroke (c);
  cairo_set_source_rgb (c, 0, 0, 0);
  cairo_set_line_width (c, 2);
  cairo_move_to (c, r, r);
  cairo_line_to (c, r + x, r - y);
  cairo_stroke (c);
  cairo_destroy (c);
#endif

  return (chosen);
}

static void
tourCorrRealloc (displayd * dsp, gint nc, GGobiData * d)
{
  /*
   * because display_tourcorr_init_null has been performed even if
   * alloc_tourcorr has not, Fa.ncols has been initialized, and
   * dsp->tcorr1.Fa.ncols = 0.
   */
  gint old_ncols, i;
  old_ncols = dsp->tcorr1.Fa.ncols;

  if (nc >= MIN_NVARS_FOR_COTOUR) {
    if (old_ncols < MIN_NVARS_FOR_COTOUR)
      display_tourcorr_init (dsp, d->gg);

    if (dsp->d == d) {
      arrayd_add_cols (&dsp->tcorr1.Fa, nc);
      arrayd_add_cols (&dsp->tcorr1.Fz, nc);
      arrayd_add_cols (&dsp->tcorr1.F, nc);
      arrayd_add_cols (&dsp->tcorr1.Ga, nc);
      arrayd_add_cols (&dsp->tcorr1.Gz, nc);
      arrayd_add_cols (&dsp->tcorr1.G, nc);
      arrayd_add_cols (&dsp->tcorr1.Va, nc);
      arrayd_add_cols (&dsp->tcorr1.Vz, nc);
      arrayd_add_cols (&dsp->tcorr1.tv, nc);

      vectori_realloc (&dsp->tcorr1.subset_vars, nc);
      vectorb_realloc (&dsp->tcorr1.subset_vars_p, nc);
      vectori_realloc (&dsp->tcorr1.active_vars, nc);
      vectorb_realloc (&dsp->tcorr1.active_vars_p, nc);

      vectorf_realloc (&dsp->tcorr1.lambda, nc);
      vectorf_realloc (&dsp->tcorr1.tau, nc);
      vectorf_realloc (&dsp->tcorr1.tinc, nc);

      arrayd_add_cols (&dsp->tc1_manbasis, (gint) nc);
      arrayd_add_cols (&dsp->tc2_manbasis, (gint) nc);

      arrayd_add_cols (&dsp->tcorr2.Fa, nc);
      arrayd_add_cols (&dsp->tcorr2.Fz, nc);
      arrayd_add_cols (&dsp->tcorr2.F, nc);
      arrayd_add_cols (&dsp->tcorr2.Ga, nc);
      arrayd_add_cols (&dsp->tcorr2.Gz, nc);
      arrayd_add_cols (&dsp->tcorr2.G, nc);
      arrayd_add_cols (&dsp->tcorr2.Va, nc);
      arrayd_add_cols (&dsp->tcorr2.Vz, nc);
      arrayd_add_cols (&dsp->tcorr2.tv, nc);

      vectori_realloc (&dsp->tcorr2.subset_vars, nc);
      vectorb_realloc (&dsp->tcorr2.subset_vars_p, nc);
      vectori_realloc (&dsp->tcorr2.active_vars, nc);
      vectorb_realloc (&dsp->tcorr2.active_vars_p, nc);

      vectorf_realloc (&dsp->tcorr2.lambda, nc);
      vectorf_realloc (&dsp->tcorr2.tau, nc);
      vectorf_realloc (&dsp->tcorr2.tinc, nc);

      /* need to zero extra cols */
      for (i = old_ncols; i < nc; i++) {
        dsp->tcorr1.Fa.vals[0][i] = 0.0;
        dsp->tcorr1.Fz.vals[0][i] = 0.0;
        dsp->tcorr1.F.vals[0][i] = 0.0;
        dsp->tcorr1.Ga.vals[0][i] = 0.0;
        dsp->tcorr1.Gz.vals[0][i] = 0.0;
        dsp->tcorr1.G.vals[0][i] = 0.0;
        dsp->tcorr1.Va.vals[0][i] = 0.0;
        dsp->tcorr1.Vz.vals[0][i] = 0.0;
        dsp->tcorr1.tv.vals[0][i] = 0.0;

        dsp->tcorr1.subset_vars.els[i] = 0;
        dsp->tcorr1.subset_vars_p.els[i] = false;
        dsp->tcorr1.active_vars.els[i] = 0;
        dsp->tcorr1.active_vars_p.els[i] = false;

        dsp->tcorr1.lambda.els[i] = 0.0;
        dsp->tcorr1.tau.els[i] = 0.0;
        dsp->tcorr1.tinc.els[i] = 0.0;

        dsp->tcorr2.Fa.vals[0][i] = 0.0;
        dsp->tcorr2.Fz.vals[0][i] = 0.0;
        dsp->tcorr2.F.vals[0][i] = 0.0;
        dsp->tcorr2.Ga.vals[0][i] = 0.0;
        dsp->tcorr2.Gz.vals[0][i] = 0.0;
        dsp->tcorr2.G.vals[0][i] = 0.0;
        dsp->tcorr2.Va.vals[0][i] = 0.0;
        dsp->tcorr2.Vz.vals[0][i] = 0.0;
        dsp->tcorr2.tv.vals[0][i] = 0.0;

        dsp->tcorr2.subset_vars.els[i] = 0;
        dsp->tcorr2.subset_vars_p.els[i] = false;
        dsp->tcorr2.active_vars.els[i] = 0;
        dsp->tcorr2.active_vars_p.els[i] = false;

        dsp->tcorr2.lambda.els[i] = 0.0;
        dsp->tcorr2.tau.els[i] = 0.0;
        dsp->tcorr2.tinc.els[i] = 0.0;
      }
    }
  }
}

static void
tour2d3Realloc (displayd * dsp, gint nc, GGobiData * d)
{
  gint old_ncols, i;
  /*
   * because display_tour2d_init_null has been performed even if
   * alloc_tour2d has not, Fa.ncols has been initialized.
   */
  old_ncols = dsp->t2d3.Fa.ncols;

  if (nc >= MIN_NVARS_FOR_TOUR2D3) {
    if (old_ncols < MIN_NVARS_FOR_TOUR2D3)
      display_tour2d3_init (dsp, d->gg);

    if (dsp->d == d) {
      arrayd_add_cols (&dsp->t2d3.Fa, nc);
      arrayd_add_cols (&dsp->t2d3.Fz, nc);
      arrayd_add_cols (&dsp->t2d3.F, nc);
      arrayd_add_cols (&dsp->t2d3.Ga, nc);
      arrayd_add_cols (&dsp->t2d3.Gz, nc);
      arrayd_add_cols (&dsp->t2d3.G, nc);
      arrayd_add_cols (&dsp->t2d3.Va, nc);
      arrayd_add_cols (&dsp->t2d3.Vz, nc);
      arrayd_add_cols (&dsp->t2d3.tv, nc);

      vectori_realloc (&dsp->t2d3.subset_vars, nc);
      vectorb_realloc (&dsp->t2d3.subset_vars_p, nc);
      vectori_realloc (&dsp->t2d3.active_vars, nc);
      vectorb_realloc (&dsp->t2d3.active_vars_p, nc);

      vectorf_realloc (&dsp->t2d3.lambda, nc);
      vectorf_realloc (&dsp->t2d3.tau, nc);
      vectorf_realloc (&dsp->t2d3.tinc, nc);

      arrayd_add_cols (&dsp->t2d3_manbasis, (gint) nc);

      /* need to zero extra cols */
      for (i = old_ncols; i < nc; i++) {
        dsp->t2d3.Fa.vals[0][i] = dsp->t2d3.Fa.vals[1][i] = 0.0;
        dsp->t2d3.Fz.vals[0][i] = dsp->t2d3.Fz.vals[1][i] = 0.0;
        dsp->t2d3.F.vals[0][i] = dsp->t2d3.F.vals[1][i] = 0.0;
        dsp->t2d3.Ga.vals[0][i] = dsp->t2d3.Ga.vals[1][i] = 0.0;
        dsp->t2d3.Gz.vals[0][i] = dsp->t2d3.Gz.vals[1][i] = 0.0;
        dsp->t2d3.G.vals[0][i] = dsp->t2d3.G.vals[1][i] = 0.0;
        dsp->t2d3.Va.vals[0][i] = dsp->t2d3.Va.vals[1][i] = 0.0;
        dsp->t2d3.Vz.vals[0][i] = dsp->t2d3.Vz.vals[1][i] = 0.0;
        dsp->t2d3.tv.vals[0][i] = dsp->t2d3.tv.vals[1][i] = 0.0;
        dsp->t2d3.subset_vars.els[i] = 0;
        dsp->t2d3.subset_vars_p.els[i] = false;
        dsp->t2d3.active_vars.els[i] = 0;
        dsp->t2d3.active_vars_p.els[i] = false;
        dsp->t2d3.lambda.els[i] = 0.0;
        dsp->t2d3.tau.els[i] = 0.0;
        dsp->t2d3.tinc.els[i] = 0.0;
      }
    }
  }
}

static void
tour2dRealloc (displayd * dsp, gint nc, GGobiData * d)
{
  gint old_ncols, i;
  /*
   * because display_tour2d_init_null has been performed even if
   * alloc_tour2d has not, Fa.ncols has been initialized.
   */
  old_ncols = dsp->t2d.Fa.ncols;

  if (nc >= MIN_NVARS_FOR_TOUR2D) {
    if (old_ncols < MIN_NVARS_FOR_TOUR2D)
      display_tour2d_init (dsp, d->gg);

    if (dsp->d == d) {
      arrayd_add_cols (&dsp->t2d.Fa, nc);
      arrayd_add_cols (&dsp->t2d.Fz, nc);
      arrayd_add_cols (&dsp->t2d.F, nc);
      arrayd_add_cols (&dsp->t2d.Ga, nc);
      arrayd_add_cols (&dsp->t2d.Gz, nc);
      arrayd_add_cols (&dsp->t2d.G, nc);
      arrayd_add_cols (&dsp->t2d.Va, nc);
      arrayd_add_cols (&dsp->t2d.Vz, nc);
      arrayd_add_cols (&dsp->t2d.tv, nc);

      vectori_realloc (&dsp->t2d.subset_vars, nc);
      vectorb_realloc (&dsp->t2d.subset_vars_p, nc);
      vectori_realloc (&dsp->t2d.active_vars, nc);
      vectorb_realloc (&dsp->t2d.active_vars_p, nc);

      vectorf_realloc (&dsp->t2d.lambda, nc);
      vectorf_realloc (&dsp->t2d.tau, nc);
      vectorf_realloc (&dsp->t2d.tinc, nc);

      arrayd_add_cols (&dsp->t2d_manbasis, (gint) nc);

      /* need to zero extra cols */
      for (i = old_ncols; i < nc; i++) {
        dsp->t2d.Fa.vals[0][i] = dsp->t2d.Fa.vals[1][i] = 0.0;
        dsp->t2d.Fz.vals[0][i] = dsp->t2d.Fz.vals[1][i] = 0.0;
        dsp->t2d.F.vals[0][i] = dsp->t2d.F.vals[1][i] = 0.0;
        dsp->t2d.Ga.vals[0][i] = dsp->t2d.Ga.vals[1][i] = 0.0;
        dsp->t2d.Gz.vals[0][i] = dsp->t2d.Gz.vals[1][i] = 0.0;
        dsp->t2d.G.vals[0][i] = dsp->t2d.G.vals[1][i] = 0.0;
        dsp->t2d.Va.vals[0][i] = dsp->t2d.Va.vals[1][i] = 0.0;
        dsp->t2d.Vz.vals[0][i] = dsp->t2d.Vz.vals[1][i] = 0.0;
        dsp->t2d.tv.vals[0][i] = dsp->t2d.tv.vals[1][i] = 0.0;
        dsp->t2d.subset_vars.els[i] = 0;
        dsp->t2d.subset_vars_p.els[i] = false;
        dsp->t2d.active_vars.els[i] = 0;
        dsp->t2d.active_vars_p.els[i] = false;
        dsp->t2d.lambda.els[i] = 0.0;
        dsp->t2d.tau.els[i] = 0.0;
        dsp->t2d.tinc.els[i] = 0.0;
      }
    }
  }
}

static void
tour1dRealloc (displayd * dsp, gint nc, GGobiData * d)
{
  gint old_ncols, i;
  /*
   * because display_tour1d_init_null has been performed even if
   * alloc_tour1d has not, Fa.ncols has been initialized.
   */
  old_ncols = dsp->t1d.Fa.ncols;

  if (old_ncols < MIN_NVARS_FOR_TOUR1D && nc >= MIN_NVARS_FOR_TOUR1D) {
    display_tour1d_init (dsp, d->gg);
  }

  if (dsp->d == d) {
    arrayd_add_cols (&dsp->t1d.Fa, nc);
    arrayd_add_cols (&dsp->t1d.Fz, nc);
    arrayd_add_cols (&dsp->t1d.F, nc);
    arrayd_add_cols (&dsp->t1d.Ga, nc);
    arrayd_add_cols (&dsp->t1d.Gz, nc);
    arrayd_add_cols (&dsp->t1d.G, nc);
    arrayd_add_cols (&dsp->t1d.Va, nc);
    arrayd_add_cols (&dsp->t1d.Vz, nc);
    arrayd_add_cols (&dsp->t1d.tv, nc);

    vectori_realloc (&dsp->t1d.subset_vars, nc);
    vectorb_realloc (&dsp->t1d.subset_vars_p, nc);
    vectori_realloc (&dsp->t1d.active_vars, nc);
    vectorb_realloc (&dsp->t1d.active_vars_p, nc);

    vectorf_realloc (&dsp->t1d.lambda, nc);
    vectorf_realloc (&dsp->t1d.tau, nc);
    vectorf_realloc (&dsp->t1d.tinc, nc);

    arrayd_add_cols (&dsp->t1d_manbasis, (gint) nc);

    /* need to zero extra cols */
    for (i = old_ncols; i < nc; i++) {
      dsp->t1d.Fa.vals[0][i] = 0.0;
      dsp->t1d.Fz.vals[0][i] = 0.0;
      dsp->t1d.F.vals[0][i] = 0.0;
      dsp->t1d.Ga.vals[0][i] = 0.0;
      dsp->t1d.Gz.vals[0][i] = 0.0;
      dsp->t1d.G.vals[0][i] = 0.0;
      dsp->t1d.Va.vals[0][i] = 0.0;
      dsp->t1d.Vz.vals[0][i] = 0.0;
      dsp->t1d.tv.vals[0][i] = 0.0;
      dsp->t1d.subset_vars.els[i] = 0;
      dsp->t1d.subset_vars_p.els[i] = false;
      dsp->t1d.active_vars.els[i] = 0;
      dsp->t1d.active_vars_p.els[i] = false;
      dsp->t1d.lambda.els[i] = 0.0;
      dsp->t1d.tau.els[i] = 0.0;
      dsp->t1d.tinc.els[i] = 0.0;
    }
  }
}

/* XXX duncan and dfs: you need to sort this out
void
worldToRaw(displayd *display, splotd *sp, gint pt, GGobiData *d, ggobid *gg)
{
  cpaneld *cpanel = &display->cpanel;
  ProjectionMode proj = cpanel->pmode;
  gint j;

  switch (proj) {
    case P1PLOT:
      if (display->p1d_orientation == VERTICAL)
        world_to_raw_by_var (pt, sp->p1dvar, display, d, gg);
      else
        world_to_raw_by_var (pt, sp->p1dvar, display, d, gg);
    break;
    case XYPLOT:
      world_to_raw_by_var (pt, sp->xyvars.x, display, d, gg);
      world_to_raw_by_var (pt, sp->xyvars.y, display, d, gg);
    break;
    case TOUR1D:
      for (j=0; j<display->t1d.nactive; j++)
        world_to_raw_by_var (pt, display->t1d.active_vars.els[j],
          display, d, gg);
    break;
    case TOUR2D3:
      for (j=0; j<display->t2d3.nactive; j++)
        world_to_raw_by_var (pt, display->t2d3.active_vars.els[j],
          display, d, gg);
    break;
    case TOUR2D:
      for (j=0; j<display->t2d.nactive; j++)
        world_to_raw_by_var (pt, display->t2d.active_vars.els[j],
          display, d, gg);
    break;
    case COTOUR:
      for (j=0; j<display->tcorr1.nactive; j++)
        world_to_raw_by_var (pt, display->tcorr1.active_vars.els[j],
          display, d, gg);
      for (j=0; j<display->tcorr2.nactive; j++)
        world_to_raw_by_var (pt, display->tcorr2.active_vars.els[j],
          display, d, gg);
    break;
    default:
    break;
  }
}
*/


void
scatterplotMovePointsButtonCb (displayd * display, splotd * sp, GtkWidget * w,
                               GdkEventButton * event, ggobid * gg)
{
  GGobiData *d = gg->current_display->d;

  g_assert (d->clusterid.nels == d->nrows);

  if (d->nearest_point != -1) {
    movepts_history_add (d->nearest_point, sp, d, gg);

    /*-- add the history information for the cluster here --*/
    if (gg->movepts.cluster_p) {
      clusters_set (d, gg);
      if (d->nclusters > 1) {
        gint i, k, id = d->nearest_point;
        gfloat cur_clust = d->clusterid.els[id];
        for (i = 0; i < d->nrows_in_plot; i++) {
          k = d->rows_in_plot.els[i];
          if (k == id);
          else if (d->clusterid.els[k] == cur_clust)
            if (!d->hidden_now.els[k])
              movepts_history_add (k, sp, d, gg);
        }
      }
    }

    splot_redraw (sp, QUICK, gg);
  }
}

void
scatterplotMovePointsMotionCb (displayd * display, splotd * sp, GtkWidget * w,
                               GdkEventMotion * event, ggobid * gg)
{
  GGobiData *d = display->d;
  gboolean button1_p, button2_p;
  gboolean inwindow, wasinwindow;

  /*-- define wasinwindow before the new mousepos is calculated --*/
  wasinwindow = mouseinwindow (sp);
  /*-- get the mouse position and find out which buttons are pressed --*/
  mousepos_get_motion (w, event, &button1_p, &button2_p, sp);
  inwindow = mouseinwindow (sp);

  if (gg->buttondown == 0) {

    gint k = find_nearest_point (&sp->mousepos, sp, d, gg);
    d->nearest_point = k;
    if (k != d->nearest_point_prev) {
      displays_plot (NULL, QUICK, gg);
      d->nearest_point_prev = k;
    }

  }
  else {

    /*-- If the pointer is inside the plotting region ... --*/
    if (inwindow) {
      /*-- ... and if the pointer has moved ...--*/
      if ((sp->mousepos.x != sp->mousepos_o.x) ||
          (sp->mousepos.y != sp->mousepos_o.y)) {
        /*
         * move the point: compute the data pipeline in reverse,
         * (then run it forward again?) and draw the plot.
         */
        if (d->nearest_point != -1) {
          move_pt (d->nearest_point, sp->mousepos.x, sp->mousepos.y,
                   sp, d, gg);
        }
        sp->mousepos_o.x = sp->mousepos.x;
        sp->mousepos_o.y = sp->mousepos.y;
      }
    }
    else {    /*-- if !inwindow --*/
      if (wasinwindow) {
        d->nearest_point = -1;
        splot_redraw (sp, QUICK, gg);
      }
    }
  }
}

static void
pmodeSet (ProjectionMode pmode, displayd * display, ggobid * gg)
{
  if (display && pmode != NULL_PMODE) {
    display->cpanel.pmode = pmode;

    if (pmode != gg->pmode_prev) {
      scatterplot_show_rulers (display, pmode);
    }
  }
}

static gboolean
scatterplotKeyEventHandled (GtkWidget * w, displayd * display, splotd * sp,
                            GdkEventKey * event, ggobid * gg)
{
  gboolean ok = true;
  cpaneld *cpanel = &display->cpanel;
  ProjectionMode pmode = NULL_PMODE;
  InteractionMode imode = DEFAULT_IMODE;

  /* The key press could either lead to a pmode or an imode change;
     this works with or without the control key being pressed */

  if (event->state == 0 || event->state == GDK_CONTROL_MASK) {

    switch (event->keyval) {
    case GDK_0:
    case GDK_1:
    case GDK_2:
    case GDK_3:
    case GDK_4:
    case GDK_5:
    case GDK_6:
    case GDK_7:
    case GDK_8:
    case GDK_9:
      if (gg->NumberedKeyEventHandler != NULL &&
          gg->NumberedKeyEventHandler->handlerRoutine) {
        (gg->NumberedKeyEventHandler->handlerRoutine) (event->keyval, w,
                                                       event, cpanel, sp, gg,
                                                       gg->
                                                       NumberedKeyEventHandler->
                                                       userData);
      }
      break;
    case GDK_d:
    case GDK_D:
      pmode = P1PLOT;
      break;
    case GDK_x:
    case GDK_X:
      pmode = XYPLOT;
      break;
    case GDK_t:
    case GDK_T:
      pmode = TOUR1D;
      break;
    case GDK_r:
    case GDK_R:
      pmode = TOUR2D3;
      break;
    case GDK_g:
    case GDK_G:
      pmode = TOUR2D;
      break;
    case GDK_c:
    case GDK_C:
      pmode = COTOUR;
      break;

    case GDK_s:
    case GDK_S:
      imode = SCALE;
      break;
    case GDK_b:
    case GDK_B:
      imode = BRUSH;
      break;
    case GDK_i:
    case GDK_I:
      imode = IDENT;
      break;
    case GDK_e:
    case GDK_E:
      imode = EDGEED;
      break;
    case GDK_m:
    case GDK_M:
      imode = MOVEPTS;
      break;
    default:
      ok = false;
    }

    if (ok) {
      if (pmode > -1 && !projection_ok (pmode, display))
        ok = false;
      else
        GGOBI (full_viewmode_set) (pmode, imode, gg);
    }
  }
  else {
    ok = false;
  }

  return ok;
}

static gboolean
varpanelHighd (displayd * display)
{
  ProjectionMode proj = display->cpanel.pmode;
  return (proj == TOUR1D || proj == TOUR2D3 || proj == TOUR2D
          || proj == COTOUR);
}

void
scatterplotDisplayInit (scatterplotDisplayd * display)
{
  GGOBI_DISPLAY (display)->p1d_orientation = HORIZONTAL;
}



gboolean
binningPermitted (displayd * dpy)
{
  cpaneld *cpanel = &dpy->cpanel;
  ggobid *gg = dpy->ggobi;
  GGobiData *e = dpy->e;

  if (pmode_get (dpy, gg) == P1PLOT &&
      cpanel->p1d.type == ASH && cpanel->p1d.ASH_add_lines_p)
    return (false);
  /*
     if (cpanel->br_point_targets == br_select)
     return(false);
   */
  /*-- if we're drawing edges --*/
  if (e != NULL && e->edge.n > 0) {
    if (dpy->options.edges_undirected_show_p ||
        dpy->options.edges_directed_show_p || dpy->options.whiskers_show_p) {
      return (false);
    }
  }

  return (true);
}

gboolean
cpanelSet (displayd * dpy, cpaneld * cpanel, ggobid * gg)
{
  cpanel_p1d_set (dpy, cpanel, gg);
  cpanel_xyplot_set (dpy, cpanel, gg);
  cpanel_tour1d_set (dpy, cpanel, gg);
  if (dpy->d->ncols >= MIN_NVARS_FOR_TOUR2D3)
    cpanel_tour2d3_set (dpy, cpanel, gg);
  if (dpy->d->ncols >= MIN_NVARS_FOR_TOUR2D)
    cpanel_tour2d_set (dpy, cpanel, gg);
  if (dpy->d->ncols >= MIN_NVARS_FOR_COTOUR)
    cpanel_tourcorr_set (dpy, cpanel, gg);

  cpanel_brush_set (dpy, cpanel, gg);
  cpanel_scale_set (dpy, cpanel, gg);
  cpanel_edgeedit_set (dpy, cpanel, gg);
  cpanel_identify_set (dpy, cpanel, gg);

  return (true);
}

void
displaySet (displayd * dpy, ggobid * gg)
{
}

/* Hmm.  These are probably useful in the other display classes. dfs */
static gboolean
handlesProjection (displayd * dpy, ProjectionMode v)
{
  return (true);
}

static gboolean
handlesInteraction (displayd * dpy, InteractionMode v)
{
  return (true);
}


static gint
plotted (displayd * display, gint * cols, gint ncols, GGobiData * d)
{
  gint j, k;
  splotd *sp = (splotd *) display->splots->data;  /*-- only one splot --*/
  ProjectionMode projection = (gint) pmode_get (display, display->ggobi);

  switch (projection) {
  case P1PLOT:
    for (j = 0; j < ncols; j++) {
      if (sp->p1dvar == cols[j]) {
        return (sp->p1dvar);
      }
    }
    break;
  case XYPLOT:
    for (j = 0; j < ncols; j++) {
      if (sp->xyvars.x == cols[j]) {
        return (sp->xyvars.x);
      }
      if (sp->xyvars.y == cols[j]) {
        return (sp->xyvars.y);
      }
    }
    break;
  case TOUR1D:
    for (j = 0; j < ncols; j++) {
      for (k = 0; k < display->t1d.nactive; k++) {
        if (display->t1d.active_vars.els[k] == cols[j]) {
          return (display->t1d.active_vars.els[k]);
        }
      }
    }
    break;
  case TOUR2D3:
    for (j = 0; j < ncols; j++) {
      for (k = 0; k < display->t2d3.nactive; k++) {
        if (display->t2d3.active_vars.els[k] == cols[j]) {
          return (display->t2d3.active_vars.els[k]);
        }
      }
    }
    break;
  case TOUR2D:
    for (j = 0; j < ncols; j++) {
      for (k = 0; k < display->t2d.nactive; k++) {
        if (display->t2d.active_vars.els[k] == cols[j]) {
          return (display->t2d.active_vars.els[k]);
        }
      }
    }
    break;
  case COTOUR:
    for (j = 0; j < ncols; j++) {
      for (k = 0; k < display->tcorr1.nactive; k++) {
        if (display->tcorr1.active_vars.els[k] == cols[j]) {
          return (display->tcorr1.active_vars.els[k]);
        }
      }
      for (k = 0; k < display->tcorr2.nactive; k++) {
        if (display->tcorr2.active_vars.els[k] == cols[j]) {
          return (display->tcorr2.active_vars.els[k]);
        }
      }
    }
    break;
  case NULL_PMODE:
  case DEFAULT_PMODE:
  case EXTENDED_DISPLAY_PMODE:
  case N_PMODES:
    g_printerr ("Unexpected pmode value %d\n", projection);
    break;
  }

  return (-1);
}


static void
varpanelTooltipsReset (displayd * display, ggobid * gg, GtkWidget * wx,
                       GtkWidget * wy, GtkWidget * wz, GtkWidget * label)
{
  ProjectionMode projection = pmode_get (display, gg);

  switch (projection) {
  case P1PLOT:
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wx,
                          "Select to plot", NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), label,
                          "Click left to plot horizontally, right or middle to plot vertically",
                          NULL);
    break;
  case XYPLOT:
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wx,
                          "Press to select the horizontally plotted variable",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wy,
                          "Press to select the vertically plotted variable",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), label,
                          "Click left to select the horizontal variable, middle for vertical",
                          NULL);

    break;
  case TOUR1D:
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wx,
                          "Click to select a variable to be available for touring",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), label,
                          "Click to select a variable to be available for touring",
                          NULL);
    break;
  case TOUR2D3:
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wx,
                          "Click to select a variable to be available for rotation",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wy,
                          "Click to select a variable to be available for rotation",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wz,
                          "Click to select a variable to be available for rotation",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), label,
                          "Click to select a variable to be available for rotation",
                          NULL);
    break;
  case TOUR2D:
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wx,
                          "Click to select a variable to be available for touring",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), label,
                          "Click to select a variable to be available for touring",
                          NULL);
    break;
  case COTOUR:
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wx,
                          "Click to select a variable to be toured horizontally",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wy,
                          "Click to select a variable to be toured vertically",
                          NULL);
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), label,
                          "Click to select a variable to be available for touring",
                          NULL);
    break;
    /*-- to pacify compiler if we change these to an enum --*/
  default:
    break;
  }
}

static gint
plottedVarsGet (displayd * display, gint * cols, GGobiData * d, ggobid * gg)
{
  ProjectionMode mode = pmode_get (display, gg);
  gint ncols = 0, k;
  splotd *sp = gg->current_splot;

  switch (mode) {
  case P1PLOT:
    cols[ncols++] = sp->p1dvar;
    break;
  case XYPLOT:
    cols[ncols++] = sp->xyvars.x;
    cols[ncols++] = sp->xyvars.y;
    break;
  case TOUR1D:
    for (k = 0; k < display->t1d.nactive; k++)
      cols[ncols++] = display->t1d.active_vars.els[k];
    break;
  case TOUR2D3:
    for (k = 0; k < display->t2d3.nactive; k++)
      cols[ncols++] = display->t2d3.active_vars.els[k];
    break;
  case TOUR2D:
    for (k = 0; k < display->t2d.nactive; k++)
      cols[ncols++] = display->t2d.active_vars.els[k];
    break;
  case COTOUR:
    for (k = 0; k < display->tcorr1.nactive; k++)
      cols[ncols++] = display->tcorr1.active_vars.els[k];
    for (k = 0; k < display->tcorr2.nactive; k++)
      cols[ncols++] = display->tcorr2.active_vars.els[k];
    break;
  default:
    break;
  }
  return (ncols);
}

#ifdef STORE_SESSION_ENABLED
/*
  Write out the variables in a scatterplot
  to the current node in the XML tree.
 */
static void
add_xml_scatterplot_variables (xmlNodePtr node, GList * plots, displayd * dpy)
{
  splotd *plot = (splotd *) plots->data;
  XML_addVariable (node, plot->xyvars.x, dpy->d);
  XML_addVariable (node, plot->xyvars.y, dpy->d);
}
#endif

/* Splot methods. */
static gchar *
treeLabel (splotd * splot, GGobiData * d, ggobid * gg)
{
  gchar *buf = NULL;
  displayd *display = (displayd *) splot->displayptr;
  cpaneld *cpanel = &display->cpanel;

  switch (cpanel->pmode) {
  case P1PLOT:
  case TOUR1D:
    buf = ggobi_data_get_col_name(d, splot->p1dvar);
    break;

  case XYPLOT:
    buf = g_strdup_printf("%s v %s", 
      ggobi_data_get_col_name(d, splot->xyvars.x), 
      ggobi_data_get_col_name(d, splot->xyvars.y)
    );
    break;

  case TOUR2D:
    buf = g_strdup("grand tour");
    break;

  case TOUR2D3:
    buf = g_strdup("rotation");
    break;

  case COTOUR:
    buf = g_strdup("correlation tour");
    break;
  default:
    break;
  }
  return (buf);
}


static void
subPlaneToScreen (splotd * sp, displayd * dpy, GGobiData * d, ggobid * gg)
{
  ash_baseline_set (&sp->p1d.ash_baseline, sp);
  ash_baseline_set (&sp->tour1d.ash_baseline, sp);
}

static void
worldToPlane (splotd * sp, GGobiData * d, ggobid * gg)
{
  cpaneld *cpanel = &(sp->displayptr->cpanel);

  switch (cpanel->pmode) {
  case P1PLOT:
    p1d_reproject (sp, d->world.vals, d, gg);
    break;

  case XYPLOT:
    xy_reproject (sp, d->world.vals, d, gg);
    break;

  case TOUR1D:
    tour1d_projdata (sp, d->world.vals, d, gg);
    break;

  case TOUR2D3:
    tour2d3_projdata (sp, d->world.vals, d, gg);
    break;
  case TOUR2D:
    tour2d_projdata (sp, d->world.vals, d, gg);
    break;

  case COTOUR:
    tourcorr_projdata (sp, d->world.vals, d, gg);
    break;

  default:
    break;
  }
}

static gboolean
drawCase (splotd * sp, gint m, GGobiData * d, ggobid * gg)
{
  displayd *display = sp->displayptr;
  gboolean draw_case = true;
  ProjectionMode proj = pmode_get (display, gg);
  gint j;

  switch (proj) {
  case P1PLOT:
    if (ggobi_data_is_missing(d, m, sp->p1dvar))
      draw_case = false;
    break;
  case XYPLOT:
    if (ggobi_data_is_missing(d, m, sp->xyvars.x))
      draw_case = false;
    else if (ggobi_data_is_missing(d, m, sp->xyvars.y))
      draw_case = false;
    break;
  case TOUR1D:
    for (j = 0; j < display->t1d.nactive; j++) {
      if (ggobi_data_is_missing(d, m, display->t1d.active_vars.els[j])) {
        draw_case = false;
        break;
      }
    }
    break;
  case TOUR2D3:
    for (j = 0; j < display->t2d3.nactive; j++) {
      if (ggobi_data_is_missing(d, m, display->t2d3.active_vars.els[j])) {
        draw_case = false;
        break;
      }
    }
    break;
  case TOUR2D:
    for (j = 0; j < display->t2d.nactive; j++) {
      if (ggobi_data_is_missing(d, m, display->t2d.active_vars.els[j])) {
        draw_case = false;
        break;
      }
    }
    break;

  case COTOUR:
    for (j = 0; j < display->tcorr1.nactive; j++) {
      if (ggobi_data_is_missing(d, m, display->tcorr1.active_vars.els[j])) {
        draw_case = false;
        break;
      }
    }
    if (draw_case) {
      for (j = 0; j < display->tcorr2.nactive; j++) {
        if (ggobi_data_is_missing(d, m, display->tcorr2.active_vars.els[j])) {
          draw_case = false;
          break;
        }
      }
    }
    break;
  case NULL_PMODE:
  case DEFAULT_PMODE:
  case EXTENDED_DISPLAY_PMODE:
  case N_PMODES:
    g_printerr ("Unexpected pmode value %d\n", proj);
    break;
  }

  return (draw_case);
}

static gboolean
drawEdge (splotd * sp, gint m, GGobiData * d, GGobiData * e, ggobid * gg)
{
  displayd *display = sp->displayptr;
  gboolean draw_edge = true;
  ProjectionMode proj = pmode_get (display, gg);

  switch (proj) {
  case P1PLOT:
    if (ggobi_data_is_missing(e, m, sp->p1dvar))
      draw_edge = false;
    break;
  case XYPLOT:
    if (ggobi_data_is_missing(e, m, sp->xyvars.x))
      draw_edge = false;
    else if (ggobi_data_is_missing(e, m, sp->xyvars.y))
      draw_edge = false;
    break;
  case TOUR1D:
    if (ggobi_data_is_missing(e, m, sp->displayptr->t1d.active_vars.els[m]))
      draw_edge = false;
    break;

  case TOUR2D3:
    if (ggobi_data_is_missing(e, m, sp->displayptr->t2d3.active_vars.els[m]))
      draw_edge = false;
    break;
  case TOUR2D:
    if (ggobi_data_is_missing(e, m, sp->displayptr->t2d.active_vars.els[m]))
      draw_edge = false;
    break;

  case COTOUR:
    if (ggobi_data_is_missing(e, m, sp->displayptr->tcorr1.active_vars.els[m]))
      draw_edge = false;
    else if (ggobi_data_is_missing(e, m, sp->displayptr->tcorr2.active_vars.els[m]))
      draw_edge = false;
    break;
  case NULL_PMODE:
  case DEFAULT_PMODE:
  case EXTENDED_DISPLAY_PMODE:
  case N_PMODES:
    g_printerr ("Unexpected pmode value %d\n", proj);
    break;
  }
  return (draw_edge);
}

void
scatter1DAddPlotLabels (splotd * sp, GdkDrawable * drawable, GdkGC * gc)
{
  PangoLayout *layout =
    gtk_widget_create_pango_layout (GTK_WIDGET (sp->da), NULL);
  PangoRectangle rect;
  GGobiData *d = sp->displayptr->d;

  layout_text (layout, ggobi_data_get_transformed_col_name(d, sp->p1dvar), &rect);
  gdk_draw_layout (drawable, gc,
                   sp->max.x / 2 - rect.width / 2,
                   sp->max.y - rect.height - 5, layout);
  g_object_unref (G_OBJECT (layout));
}

void
scatterXYAddPlotLabels (splotd * sp, GdkDrawable * drawable, GdkGC * gc)
{
  PangoLayout *layout =
    gtk_widget_create_pango_layout (GTK_WIDGET (sp->da), NULL);
  PangoRectangle rect;

  GGobiData *d = sp->displayptr->d;

  /*-- xyplot: right justify the label --*/
  layout_text (layout, ggobi_data_get_transformed_col_name(d, sp->xyvars.x), &rect);
  gdk_draw_layout (drawable, gc,
                   sp->max.x - rect.width - 5,
                   sp->max.y - rect.height - 5, layout);

  layout_text (layout, ggobi_data_get_transformed_col_name(d, sp->xyvars.y), &rect);
  gdk_draw_layout (drawable, gc, 5, 5, layout);
  g_object_unref (G_OBJECT (layout));
}

static void
addPlotLabels (splotd * sp, GdkDrawable * drawable, ggobid * gg)
{
/* Same as scatmat... */
  cpaneld *cpanel = &(sp->displayptr->cpanel);
  if (cpanel->pmode == XYPLOT)
    scatterXYAddPlotLabels (sp, drawable, gg->plot_GC);
  else if (cpanel->pmode == P1PLOT)
    scatter1DAddPlotLabels (sp, drawable, gg->plot_GC);
}

static void
withinDrawToUnbinned (splotd * sp, gint m, GdkDrawable * drawable, GdkGC * gc)
{
  displayd *display = sp->displayptr;
  cpaneld *cpanel = &display->cpanel;
  ProjectionMode proj = cpanel->pmode;
  icoords *baseline;

  /*-- add ash baseline to p1d or tour1d --*/
  if ((proj == TOUR1D && cpanel->t1d.ASH_add_lines_p) ||
      (proj == P1PLOT &&
       cpanel->p1d.type == ASH && cpanel->p1d.ASH_add_lines_p)) {
    baseline = (proj == TOUR1D) ? &sp->tour1d.ash_baseline :
      &sp->p1d.ash_baseline;

    if (display->p1d_orientation == HORIZONTAL)
      gdk_draw_line (drawable, gc,
                     sp->screen[m].x, sp->screen[m].y,
                     sp->screen[m].x, baseline->y);
    else
      gdk_draw_line (drawable, gc,
                     sp->screen[m].x, sp->screen[m].y,
                     baseline->x, sp->screen[m].y);
  }
}

void
addMarkupCues (splotd * sp, GdkDrawable * drawable, ggobid * gg)
{
/* See splot_add_markup_to_pixmap */
  displayd *display = sp->displayptr;
  GGobiData *e = display->e;
  if (e)
    if (display->options.edges_undirected_show_p ||
        display->options.edges_arrowheads_show_p ||
        display->options.edges_directed_show_p)
      if (e->nearest_point != -1)
        splot_add_identify_edge_cues (sp, drawable, e->nearest_point,
                                      true, gg);
}

void
addScalingCues (splotd * sp, GdkDrawable * drawable, ggobid * gg)
{
  cpaneld *cpanel = &gg->current_display->cpanel;

  if (!cpanel->scale.updateAlways_p) {
    if (gg->buttondown)
      gdk_draw_line (drawable, gg->plot_GC,
                     sp->mousedownpos.x, sp->mousedownpos.y,
                     sp->mousepos.x, sp->mousepos.y);
  }
}

static void
splotAssignPointsToBins (GGobiData * d, splotd * sp, ggobid * gg)
{
  if (sp == gg->current_splot)  /* whether binning permitted or not */
    assign_points_to_bins (d, sp, gg);
}

static void
splotScreenToTform (cpaneld * cpanel, splotd * sp, icoords * scr,
                    fcoords * tfd, ggobid * gg)
{
  gcoords planar, world;
  greal precis = (greal) PRECISION1;
  greal ftmp, max, min, rdiff;
  displayd *display = (displayd *) sp->displayptr;
  GGobiData *d = display->d;
  gfloat scale_x, scale_y;
  vartabled *vt, *vtx, *vty;

  scale_x = sp->scale.x;
  scale_y = sp->scale.y;
  scale_x /= 2;
  sp->iscale.x = (greal) sp->max.x * scale_x;
  scale_y /= 2;
  sp->iscale.y = -1 * (greal) sp->max.y * scale_y;

/*
 * screen to plane 
*/
  planar.x = (scr->x - sp->max.x / 2) * precis / sp->iscale.x;
  planar.x += sp->pmid.x;
  planar.y = (scr->y - sp->max.y / 2) * precis / sp->iscale.y;
  planar.y += sp->pmid.y;

/*
 * plane to world
*/

  switch (cpanel->pmode) {
  case P1PLOT:
    vt = vartable_element_get (sp->p1dvar, d);
    max = vt->lim.max;
    min = vt->lim.min;
    rdiff = max - min;

    if (display->p1d_orientation == HORIZONTAL) {
      /* x */
      world.x = planar.x;
      ftmp = world.x / precis;
      tfd->x = (ftmp + 1.0) * .5 * rdiff;
      tfd->x += min;
    }
    else {
      /* y */
      world.y = planar.y;
      ftmp = world.y / precis;
      tfd->y = (ftmp + 1.0) * .5 * rdiff;
      tfd->y += min;
    }
    break;

  case XYPLOT:
    /* x */
    vtx = vartable_element_get (sp->xyvars.x, d);
    max = vtx->lim.max;
    min = vtx->lim.min;
    rdiff = max - min;
    world.x = planar.x;
    ftmp = world.x / precis;
    tfd->x = (ftmp + 1.0) * .5 * rdiff;
    tfd->x += min;

    /* y */
    vty = vartable_element_get (sp->xyvars.y, d);
    max = vty->lim.max;
    min = vty->lim.min;
    rdiff = max - min;
    world.y = planar.y;
    ftmp = world.y / precis;
    tfd->y = (ftmp + 1.0) * .5 * rdiff;
    tfd->y += min;
    break;

  default:
    break;
  }
}

void
scatterplotDisplayClassInit (GGobiScatterplotDisplayClass * klass)
{
  klass->parent_class.createWithVars = scatterplot_new_with_vars;
  klass->parent_class.create = scatterplot_new;
  klass->parent_class.supports_edges_p = true;
  klass->parent_class.show_edges_p = true;
  klass->parent_class.binningPermitted = binningPermitted;

  klass->parent_class.cpanel_set = cpanelSet;
  klass->parent_class.display_set = displaySet;
  klass->parent_class.mode_ui_get = scatterplot_mode_ui_get;

  klass->parent_class.handles_projection = handlesProjection;
  klass->parent_class.handles_interaction = handlesInteraction;

  klass->parent_class.variable_plotted_p = plotted;

  klass->parent_class.varpanel_tooltips_set = varpanelTooltipsReset;
  klass->parent_class.plotted_vars_get = plottedVarsGet;

  klass->parent_class.titleLabel = "Scatterplot Display";
  klass->parent_class.treeLabel = "Scatterplot";
  klass->parent_class.ruler_ranges_set = ruler_ranges_set;
  #ifdef STORE_SESSION_ENABLED
  klass->parent_class.xml_describe = add_xml_scatterplot_variables;
  #endif

  klass->parent_class.varpanel_highd = varpanelHighd;
  klass->parent_class.varpanel_refresh = varpanelRefresh;
  klass->parent_class.variable_select = variableSelect;
  klass->parent_class.pmode_set = pmodeSet;
  klass->parent_class.splot_key_event_handled = scatterplotKeyEventHandled;

  klass->parent_class.move_points_motion_cb = scatterplotMovePointsMotionCb;
  klass->parent_class.move_points_button_cb = scatterplotMovePointsButtonCb;

  klass->parent_class.tour1d_realloc = tour1dRealloc;
  klass->parent_class.tour2d3_realloc = tour2d3Realloc;
  klass->parent_class.tour2d_realloc = tour2dRealloc;
  klass->parent_class.tourcorr_realloc = tourCorrRealloc;

  #ifdef STORE_SESSION_ENABLED
  klass->parent_class.xml_describe = add_xml_scatterplot_variables;
  #endif

  klass->parent_class.set_show_axes_option = setShowAxesOption;
  klass->parent_class.set_show_axes_label_option = setShowAxesLabelOption;
  klass->parent_class.set_show_axes_values_option = setShowAxesValuesOption;

/* XXX duncan and dfs: you need to sort this out
  klass->parent_class.world_to_raw = worldToRaw;
*/

  klass->parent_class.select_X = selectXVar;
  klass->parent_class.varcircle_draw = varcircleDraw;
}

static gint
splotVariablesGet (splotd * sp, gint * cols, GGobiData * d)
{
  cols[0] = sp->xyvars.x;
  cols[1] = sp->xyvars.y;
  return (2);
}


void
scatterSPlotClassInit (GGobiScatterSPlotClass * klass)
{
  klass->parent_class.within_draw_to_unbinned = withinDrawToUnbinned;
  klass->parent_class.tree_label = treeLabel;

  /* reverse pipeline */
  klass->parent_class.screen_to_tform = splotScreenToTform;
  klass->parent_class.sub_plane_to_screen = subPlaneToScreen;
  klass->parent_class.world_to_plane = worldToPlane;

  klass->parent_class.draw_case_p = drawCase;
  klass->parent_class.draw_edge_p = drawEdge;
  klass->parent_class.add_plot_labels = addPlotLabels;
  klass->parent_class.within_draw_to_unbinned = withinDrawToUnbinned;
  klass->parent_class.add_markup_cues = addMarkupCues;
  klass->parent_class.add_scaling_cues = addScalingCues;

  klass->parent_class.splot_assign_points_to_bins = splotAssignPointsToBins;

  klass->parent_class.plotted_vars_get = splotVariablesGet;
}