File: exclusion_ui.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 (712 lines) | stat: -rw-r--r-- 23,634 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
/*-- exclusion_ui.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
*/

/*
 * This is no longer appropriately named: think of it as cluster_ui.c
*/

#include <gtk/gtk.h>
#include "vars.h"
#include "externs.h"

static void exclusion_notebook_adddata_cb (ggobid *, GGobiData *,
                                           void *notebook);

static void
destroyit (gboolean kill, ggobid * gg)
{
  gint n, nrows;
  GSList *l;
  GGobiData *d;
  GtkWidget *child;

  for (l = gg->d; l; l = l->next) {
    d = (GGobiData *) l->data;
    if (d->cluster_table) {
      nrows = GTK_TABLE (d->cluster_table)->nrows;
      for (n = 0; n < nrows - 1; n++)
        cluster_free (n, d, gg);
    }
  }

  if (kill) {
    gtk_widget_destroy (gg->cluster_ui.window);
    gg->cluster_ui.window = NULL;
  }
  else {
    /*-- kill all the children of the window --*/
    GList *gl, *children =
      gtk_container_get_children (GTK_CONTAINER(GTK_DIALOG(gg->cluster_ui.window)->vbox));
    for (gl = children; gl; gl = gl->next) {
      child = (GtkWidget *) gl->data;
      gtk_widget_destroy (child);
    }
  }
}

/*-- called when closed from the close button --*/
static void
close_btn_cb (GtkWidget * w, gint response, ggobid * gg)
{
  destroyit (true, gg);
}

/*-- called when closed from the window manager --*/
static void
close_wmgr_cb (GtkWidget * w, GdkEvent * event, ggobid * gg)
{
  destroyit (true, gg);
}

static gint
cluster_symbol_show (GtkWidget * w, GdkEventExpose * event, gpointer cbd)
{
  gint k = GPOINTER_TO_INT (cbd);
  ggobid *gg = GGobiFromWidget (w, true);
  icoords pos;
  glyphd g;
  GGobiData *d = datad_get_from_notebook (gg->cluster_ui.notebook, gg);
  colorschemed *scheme = gg->activeColorScheme;

  /*-- fill in the background color --*/
  gdk_gc_set_foreground (gg->plot_GC, &scheme->rgb_bg);
  gdk_draw_rectangle (w->window, gg->plot_GC,
                      true, 0, 0, w->allocation.width, w->allocation.height);

  /*-- draw the appropriate symbol in the appropriate color --*/
  gdk_gc_set_foreground (gg->plot_GC, &scheme->rgb[d->clusv[k].color]);
  g.type = d->clusv[k].glyphtype;
  g.size = d->clusv[k].glyphsize;

  pos.x = w->allocation.width / 2;
  pos.y = w->allocation.height / 2;
  draw_glyph (w->window, &g, &pos, 0, gg);

  return FALSE;
}

void
cluster_table_labels_update (GGobiData * d, ggobid * gg)
{
  gint k;
  gchar *str;

  if (gg->cluster_ui.window == NULL)
    return;

  for (k = 0; k < d->nclusters; k++) {
    str = g_strdup_printf ("%ld", d->clusv[k].nhidden);
    gtk_label_set_text (GTK_LABEL (d->clusvui[k].nh_lbl), str);
    g_free (str);

    str = g_strdup_printf ("%ld", d->clusv[k].nshown);
    gtk_label_set_text (GTK_LABEL (d->clusvui[k].ns_lbl), str);
    g_free (str);

    str = g_strdup_printf ("%ld", d->clusv[k].n);
    gtk_label_set_text (GTK_LABEL (d->clusvui[k].n_lbl), str);
    g_free (str);
  }
}


static gint
hide_cluster_cb (GtkToggleButton * btn, gpointer cbd)
{
  gint k = GPOINTER_TO_INT (cbd);
  gint i;
  ggobid *gg = GGobiFromWidget (GTK_WIDGET (btn), true);
  GGobiData *d = datad_get_from_notebook (gg->cluster_ui.notebook, gg);
  gboolean prev, changed = false;

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

  /*-- operating on the current sample, whether hidden or shown --*/
  for (i = 0; i < d->nrows; i++) {
    if (d->sampled.els[i]) {
      if (d->clusterid.els[i] == k) {
        prev = d->hidden.els[i];
        d->hidden.els[i] = d->hidden_now.els[i] = btn->active;
        if ((prev != d->hidden.els[i]) && !gg->linkby_cv) {
          changed = symbol_link_by_id (true, i, d, gg) || changed;
        }
      }
    }
  }

  clusters_set (d, gg);
  cluster_table_labels_update (d, gg);

  displays_plot (NULL, FULL, gg);

  return false;
}

/*-- include or exclude hidden cases --*/
gint
include_hiddens (gboolean include, GGobiData * d, ggobid * gg)
{
  gint i;
  displayd *dsp = gg->current_display;
  cpaneld *cpanel = &dsp->cpanel;
  gboolean prev, changed = false;

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

  for (i = 0; i < d->nrows; i++) {
    prev = d->excluded.els[i];
    d->excluded.els[i] = (!include && d->hidden_now.els[i]);
    if ((prev != d->excluded.els[i]) && !gg->linkby_cv) {
      /*-- this doesn't link the value of excluded --*/
      changed = changed || exclude_link_by_id (i, d, gg);
    }
  }

  /*-- make the other datad's update their rows_in_plot, too --*/
  if (changed) {
    GGobiData *dd;
    GSList *l;
    for (l = gg->d; l; l = l->next) {
      dd = (GGobiData *) l->data;
      if (dd == d)
        continue;
      if (dd->rowIds && dd->idTable) {
        rows_in_plot_set (dd, gg);
        clusters_set (dd, gg);
        cluster_table_labels_update (dd, gg);
        limits_set (dd, true, true, gg->lims_use_visible);
        vartable_limits_set (dd);
        vartable_stats_set (dd);
        tform_to_world (dd, gg);
      }
    }
  }

  rows_in_plot_set (d, gg);
  clusters_set (d, gg);
  cluster_table_labels_update (d, gg);
  limits_set (d, true, true, gg->lims_use_visible);
  vartable_limits_set (d);
  vartable_stats_set (d);
  tform_to_world (d, gg);

  if (cpanel->pmode == TOUR1D)
    dsp->t1d.get_new_target = true;
  else if (cpanel->pmode == TOUR2D3)
    dsp->t2d3.get_new_target = true;
  else if (cpanel->pmode == TOUR2D)
    dsp->t2d.get_new_target = true;
  else if (cpanel->pmode == COTOUR) {
    dsp->tcorr1.get_new_target = true;
    dsp->tcorr2.get_new_target = true;
  }

  displays_tailpipe (FULL, gg);
  displays_plot (NULL, FULL, gg);

  return false;
}

static void
exclude_hiddens_cb (GtkWidget * w, ggobid * gg)
{
  GGobiData *d = datad_get_from_notebook (gg->cluster_ui.notebook, gg);
  include_hiddens (false, d, gg);
}
static void
include_hiddens_cb (GtkWidget * w, ggobid * gg)
{
  GGobiData *d = datad_get_from_notebook (gg->cluster_ui.notebook, gg);
  include_hiddens (true, d, gg);
}

static gint
cluster_symbol_cb (GtkWidget * w, GdkEventExpose * event, gpointer cbd)
{
  /*-- reset the glyph and color of this glyph to the current values --*/
  gint n = GPOINTER_TO_INT (cbd);
  ggobid *gg = GGobiFromWidget (w, true);
  GGobiData *d = datad_get_from_notebook (gg->cluster_ui.notebook, gg);
  gint k, m, i;
  cpaneld *cpanel = &gg->current_display->cpanel;
  gboolean rval = false;
  gint nclusters = symbol_table_populate (d);
  gboolean proceed = true;
  gint targets = cpanel->br.point_targets;
  gint nd = g_slist_length (gg->d);

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

/*
 * Almost surely the user is not trying to collapse groups, so
 * check whether there's another cluster with this color/glyph
 * combination.  If there is, don't go ahead.  (Though we may
 * want to add a dialog for this later.)
*/
  for (k = 0; k < nclusters; k++) {
    if (k != n) {
      switch (targets) {
      case br_candg:
        if (d->clusv[k].glyphtype == gg->glyph_id.type &&
            d->clusv[k].glyphsize == gg->glyph_id.size &&
            d->clusv[k].color == gg->color_id) {
          proceed = false;
          break;
        }
        break;
      case br_color:
        /*
         * This would produce an identical cluster if the glyph
         * types and sizes of the clusters are already equal, and
         * the new glyph sizes would complete the match.
         */
        if (d->clusv[k].glyphtype == d->clusv[n].glyphtype &&
            d->clusv[k].glyphsize == d->clusv[n].glyphsize &&
            d->clusv[k].color == gg->color_id) {
          proceed = false;
          break;
        }
        break;
      case br_glyph:
        if (d->clusv[k].color == d->clusv[n].color &&
            d->clusv[k].glyphtype == gg->glyph_id.type &&
            d->clusv[k].glyphsize == gg->glyph_id.size) {
          proceed = false;
          break;
        }
        break;
      }
    }
  }

/*
 * This is a bit paternalistic, no?  But it's probably ok for now.
*/
  if (!proceed) {
    quick_message
      ("You're about to reset the color and/or glyph for this cluster\nin such a way as to merge it with another cluster.  I bet\nthat's not what you intend, so I won't let you do it.\n",
       false);
    return true;
  }

  for (m = 0; m < d->nrows_in_plot; m++) {
    i = d->rows_in_plot.els[m];
    if (d->clusterid.els[i] == n) {
      if (targets == br_candg || targets == br_color) {
        d->color.els[i] = d->color_now.els[i] = gg->color_id;
        /*-- this will be done multiple times, but who cares? --*/
        d->clusv[n].color = gg->color_id;
      }
      if (targets == br_candg || targets == br_glyph) {
        d->glyph.els[i].type = d->glyph_now.els[i].type = gg->glyph_id.type;
        d->glyph.els[i].size = d->glyph_now.els[i].size = gg->glyph_id.size;
        /*-- this will be done multiple times, but who cares? --*/
        d->clusv[n].glyphtype = gg->glyph_id.type;
        d->clusv[n].glyphsize = gg->glyph_id.size;
      }

      /*-- link so that displays of linked datad's will be brushed as well --*/
      if (nd > 1 && !gg->linkby_cv)
        symbol_link_by_id (true, i, d, gg);
    }
  }

  g_signal_emit_by_name (G_OBJECT (w), "expose_event",
                         (gpointer) gg, (gpointer) & rval);

  /* clusters_set reorders clusv, so it's bad news here */
  /*clusters_set (d, gg); */

  displays_plot (NULL, FULL, gg);

  return false;
}

void
cluster_add (gint k, GGobiData * d, ggobid * gg)
{
  gchar *str;
  gint dawidth = 2 * NGLYPHSIZES + 1 + 10;

  d->clusvui[k].da = gtk_drawing_area_new ();
  gtk_widget_set_double_buffered (d->clusvui[k].da, false);
  gtk_widget_set_size_request (GTK_WIDGET (d->clusvui[k].da),
                               dawidth, dawidth);

  gtk_widget_set_events (d->clusvui[k].da,
                         GDK_EXPOSURE_MASK | GDK_ENTER_NOTIFY_MASK
                         | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK);

  g_signal_connect (G_OBJECT (d->clusvui[k].da), "expose_event",
                    G_CALLBACK (cluster_symbol_show), GINT_TO_POINTER (k));
  g_signal_connect (G_OBJECT (d->clusvui[k].da), "button_press_event",
                    G_CALLBACK (cluster_symbol_cb), GINT_TO_POINTER (k));
  GGobi_widget_set (d->clusvui[k].da, gg, true);
  gtk_table_attach (GTK_TABLE (d->cluster_table), d->clusvui[k].da,
                    0, 1, k + 1, k + 2,
                    (GtkAttachOptions) 0, (GtkAttachOptions) 0, 5, 2);


  // Set clusv[k].hidden_p in case the user has made changes.
  d->clusv[k].hidden_p = (d->clusv[k].nhidden == d->clusv[k].n);

  d->clusvui[k].h_btn = gtk_toggle_button_new_with_label ("Shadow");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (d->clusvui[k].h_btn),
                                d->clusv[k].hidden_p);
  g_signal_connect (G_OBJECT (d->clusvui[k].h_btn), "toggled",
                    G_CALLBACK (hide_cluster_cb), GINT_TO_POINTER (k));
  GGobi_widget_set (d->clusvui[k].h_btn, gg, true);
  gtk_table_attach (GTK_TABLE (d->cluster_table),
                    d->clusvui[k].h_btn,
                    1, 2, k + 1, k + 2, GTK_FILL, GTK_FILL, 5, 2);

/*
  d->clusvui[k].e_btn = gtk_toggle_button_new_with_label("E");
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(d->clusvui[k].e_btn),
    d->clusv[k].excluded_p);
  g_signal_connect(G_OBJECT(d->clusvui[k].e_btn), "toggled",
    G_CALLBACK(exclude_cluster_cb), GINT_TO_POINTER(k));
  GGobi_widget_set(d->clusvui[k].e_btn, gg, true);
  gtk_table_attach(GTK_TABLE(d->cluster_table),
    d->clusvui[k].e_btn,
    2, 3, k + 1, k + 2, GTK_FILL, GTK_FILL, 5, 2);
*/

  str = g_strdup_printf ("%ld", d->clusv[k].nhidden);
  d->clusvui[k].nh_lbl = gtk_label_new (str);
  gtk_table_attach (GTK_TABLE (d->cluster_table),
                    d->clusvui[k].nh_lbl,
                    2, 3, k + 1, k + 2, GTK_FILL, GTK_FILL, 5, 2);
  g_free (str);

  str = g_strdup_printf ("%ld", d->clusv[k].nshown);
  d->clusvui[k].ns_lbl = gtk_label_new (str);
  gtk_table_attach (GTK_TABLE (d->cluster_table),
                    d->clusvui[k].ns_lbl,
                    3, 4, k + 1, k + 2, GTK_FILL, GTK_FILL, 5, 2);
  g_free (str);

  str = g_strdup_printf ("%ld", d->clusv[k].n);
  d->clusvui[k].n_lbl = gtk_label_new (str);
  gtk_table_attach (GTK_TABLE (d->cluster_table),
                    d->clusvui[k].n_lbl,
                    4, 5, k + 1, k + 2, GTK_FILL, GTK_FILL, 5, 2);
  g_free (str);
}

void
cluster_free (gint k, GGobiData * d, ggobid * gg)
{
  if (d->clusvui[k].da) {
    gtk_widget_destroy (d->clusvui[k].da);
    gtk_widget_destroy (d->clusvui[k].h_btn);
    gtk_widget_destroy (d->clusvui[k].nh_lbl);
    gtk_widget_destroy (d->clusvui[k].ns_lbl);
    gtk_widget_destroy (d->clusvui[k].n_lbl);
  }
}


static void
update_cb (GtkWidget * w, ggobid * gg)
{
  GGobiData *d = datad_get_from_notebook (gg->cluster_ui.notebook, gg);
  splotd *sp = gg->current_splot;

  rows_in_plot_set (d, gg);
  if (GGOBI_IS_EXTENDED_SPLOT (sp)) {
    void (*f) (GGobiData *, splotd *, ggobid *);
    GGobiExtendedSPlotClass *klass;
    klass = GGOBI_EXTENDED_SPLOT_GET_CLASS (sp);
    f = klass->splot_assign_points_to_bins;
    if (f) {
      f (d, sp, gg);            // need to exclude area plots
    }
  }
  //assign_points_to_bins(d, sp, gg);
  clusters_set (d, gg);

  cluster_table_labels_update (d, gg);
  displays_plot (NULL, FULL, gg);

  cluster_window_open (gg);
}

static gboolean
nclusters_changed (ggobid * gg)
{
  GGobiData *d;
  gint k, nrows = 0;
  GtkWidget *page;
  gboolean changed = false;
  gint nd = g_slist_length (gg->d);

  for (k = 0; k < nd; k++) {
    nrows = 0;
    page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (gg->cluster_ui.notebook),
                                      k);
    if (page) {
      d = (GGobiData *) g_object_get_data (G_OBJECT (page), "datad");
      nrows = GTK_TABLE (d->cluster_table)->nrows;

      if (nrows != d->nclusters + 1) {/*-- add one for the titles --*/
        changed = true;
      }
    }
    else {    /*-- if page is NULL, a new datad has been added --*/
      changed = true;
    }
    if (changed)
      break;
  }
  return changed;
}


void
cluster_table_update (GGobiData * d, ggobid * gg)
{
  if (gg->cluster_ui.window != NULL) {
    if (nclusters_changed (gg)) {  /*-- for any of the datad's --*/
      cluster_window_open (gg);
    }
    else {
      cluster_table_labels_update (d, gg);  /*-- d, or all d's? --*//* do all */
    }
  }
}

static void
exclusion_notebook_adddata_cb (ggobid * gg, GGobiData * d, void *notebook)
{
  cluster_window_open (gg);
  return;                       /* Should this return a boolean? */
}

CHECK_EVENT_SIGNATURE (exclusion_notebook_adddata_cb, datad_added_f)


     void cluster_window_open (ggobid * gg)
{
  GtkWidget *scrolled_window = NULL;
  GtkWidget *tebox, *btn, *hbox, *lbl;
  GtkWidget *ebox;
  GtkWidget *dialog;
  gint k;
  GSList *l;
  GGobiData *d;
  gboolean new = false;

  /*-- if used before we have data, bail out --*/
  if (gg->d == NULL || g_slist_length (gg->d) == 0)
    /**/ return;

  /*-- if it isn't NULL, then destroy it and start afresh --*/
  if (gg->cluster_ui.window != NULL) {
    destroyit (false, gg);  /*-- don't kill the whole thing --*/
  }

  if (gg->cluster_ui.window == NULL ||
    !GTK_WIDGET_REALIZED (gg->cluster_ui.window)) 
  {
    gg->cluster_ui.window = gtk_dialog_new_with_buttons ("Color & Glyph Groups",
      GTK_WINDOW(gg->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, 
      GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
    g_signal_connect (G_OBJECT (gg->cluster_ui.window), "delete_event",
                      G_CALLBACK (close_wmgr_cb), (gpointer) gg);
    new = true;
  }

  dialog = gg->cluster_ui.window;
  
  tebox = gtk_event_box_new ();
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox), tebox, true, true, 2);

  /* Create a notebook, set the position of the tabs */
  gg->cluster_ui.notebook = gtk_notebook_new ();
  gtk_notebook_set_tab_pos (GTK_NOTEBOOK (gg->cluster_ui.notebook),
                            GTK_POS_TOP);
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (gg->cluster_ui.notebook),
                              g_slist_length (gg->d) > 1);
  gtk_container_add (GTK_CONTAINER (tebox), gg->cluster_ui.notebook);

  for (l = gg->d; l; l = l->next) {
    d = (GGobiData *) l->data;

    /*-- skip datasets without variables --*/
    if (!ggobi_data_has_variables (d))
      continue;

    /* Create a scrolled window to hold the table */
    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                    GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);

    g_object_set_data (G_OBJECT (scrolled_window), "datad", d); /*setdata */
    gtk_notebook_append_page (GTK_NOTEBOOK (gg->cluster_ui.notebook),
                              scrolled_window, gtk_label_new (d->name));
    gtk_widget_show (scrolled_window);

    d->cluster_table = gtk_table_new (d->nclusters + 1, 5, true);
    gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW
                                           (scrolled_window),
                                           d->cluster_table);

    /*-- add the row of titles --*/

    ebox = gtk_event_box_new ();
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), ebox,
                          "Click to change the color/glyph of all members of the selected cluster to the current brushing color/glyph",
                          NULL);
    lbl = gtk_label_new ("Symbol");
    gtk_container_add (GTK_CONTAINER (ebox), lbl);
    gtk_table_attach (GTK_TABLE (d->cluster_table), ebox, 0, 1, 0, 1,
      /*-- left, right, top, bottom --*/
                      GTK_FILL, GTK_FILL, 5, 2);

    ebox = gtk_event_box_new ();
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), ebox,
                          "Shadow brush all cases with the corresponding symbol.",
                          NULL);
    lbl = gtk_label_new ("Shadow");
    gtk_container_add (GTK_CONTAINER (ebox), lbl);
    gtk_table_attach (GTK_TABLE (d->cluster_table), ebox,
                      1, 2, 0, 1, GTK_FILL, GTK_FILL, 5, 2);

/*
    ebox = gtk_event_box_new();
    gtk_tooltips_set_tip(GTK_TOOLTIPS(gg->tips), ebox,
      "Exclude all hidden cases with the corresponding symbol",
      NULL);
    lbl = gtk_label_new("Exclude");
    gtk_container_add(GTK_CONTAINER(ebox), lbl);
    gtk_table_attach(GTK_TABLE(d->cluster_table), ebox,
      2, 3, 0, 1, GTK_FILL, GTK_FILL, 5, 2);
*/

/*
    ebox = gtk_event_box_new();
    gtk_tooltips_set_tip(GTK_TOOLTIPS(gg->tips), ebox,
      "Show all cases with the corresponding symbol",
      NULL);
    lbl = gtk_label_new("Show");
    gtk_container_add(GTK_CONTAINER(ebox), lbl);
    gtk_table_attach(GTK_TABLE(d->cluster_table), ebox,
      2, 3, 0, 1, GTK_FILL, GTK_FILL, 5, 2);

    ebox = gtk_event_box_new();
    gtk_tooltips_set_tip(GTK_TOOLTIPS(gg->tips), ebox,
      "Complement: Show/hide all cases with the corresponding symbol that are hidden/shown",
      NULL);
    lbl = gtk_label_new("Comp");
    gtk_container_add(GTK_CONTAINER(ebox), lbl);
    gtk_table_attach(GTK_TABLE(d->cluster_table), ebox,
      3, 4, 0, 1, GTK_FILL, GTK_FILL, 5, 2);
*/

    ebox = gtk_event_box_new ();
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), ebox,
                          "The number of cases in shadow out of N with the corresponding symbol.",
                          NULL);
    lbl = gtk_label_new ("Shadowed");
    gtk_container_add (GTK_CONTAINER (ebox), lbl);
    gtk_table_attach (GTK_TABLE (d->cluster_table), ebox,
                      2, 3, 0, 1, GTK_FILL, GTK_FILL, 5, 2);

    ebox = gtk_event_box_new ();
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), ebox,
                          "The number of visible cases (cases not in shadow) out of N with the corresponding symbol.",
                          NULL);
    lbl = gtk_label_new ("Shown");
    gtk_container_add (GTK_CONTAINER (ebox), lbl);
    gtk_table_attach (GTK_TABLE (d->cluster_table), ebox,
                      3, 4, 0, 1, GTK_FILL, GTK_FILL, 5, 2);

    ebox = gtk_event_box_new ();
    gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), ebox,
                          "The number of cases with the corresponding symbol.  If sampling, the number of cases in the current subsample",
                          NULL);
    lbl = gtk_label_new ("N");
    gtk_container_add (GTK_CONTAINER (ebox), lbl);
    gtk_table_attach (GTK_TABLE (d->cluster_table), ebox,
                      4, 5, 0, 1, GTK_FILL, GTK_FILL, 5, 2);

    d->clusvui = (clusteruid *)
      g_realloc (d->clusvui, d->nclusters * sizeof (clusteruid));
    /*-- add the cluster rows, one by one --*/
    for (k = 0; k < d->nclusters; k++)
      cluster_add (k, d, gg);
  }

  /*-- listen for datad_added events on main_window --*/
  /*-- Be careful to add this signal handler only once! --*/
  if (new) {
    g_signal_connect (G_OBJECT (gg),
                      "datad_added",
                      G_CALLBACK (exclusion_notebook_adddata_cb), NULL);
  }

  /*-- give the window an initial height --*/
  gtk_widget_set_size_request (GTK_WIDGET (scrolled_window), -1, 150);

  /*-- horizontal box to hold a few buttons --*/
  hbox = gtk_hbox_new (false, 2);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox), hbox, false, false, 0);

  /*-- Exclude button --*/
  btn = gtk_button_new_with_mnemonic ("E_xclude shadows");
  gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), btn,
                        "Exclude all points in shadow, so that they're not drawn and they're ignored when scaling the view.",
                        NULL);
  g_signal_connect (G_OBJECT (btn), "clicked",
                    G_CALLBACK (exclude_hiddens_cb), (gpointer) gg);
  gtk_box_pack_start (GTK_BOX (hbox), btn, true, true, 0);

  /*-- Include button --*/
  btn = gtk_button_new_with_mnemonic ("_Include shadows");
  gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), btn,
                        "Include all previously hidden and excluded points.",
                        NULL);
  g_signal_connect (G_OBJECT (btn), "clicked",
                    G_CALLBACK (include_hiddens_cb), (gpointer) gg);
  gtk_box_pack_start (GTK_BOX (hbox), btn, true, true, 0);

  /*-- Update button --*/
  btn = gtk_button_new_from_stock (GTK_STOCK_REFRESH);
  gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), btn,
                        "Reset plots after brushing so that shadow and excluded status is consistent with this table; reset this table if necessary.",
                        NULL);
  g_signal_connect (G_OBJECT (btn), "clicked",
                    G_CALLBACK (update_cb), (gpointer) gg);
  gtk_box_pack_start (GTK_BOX (hbox), btn, true, true, 0);

  /*-- Close button --*/
  g_signal_connect (G_OBJECT (dialog), "response",
                    G_CALLBACK (close_btn_cb), (gpointer) gg);

  gtk_widget_show_all (gg->cluster_ui.window);

  for (l = gg->d; l; l = l->next) {
    d = (GGobiData *) l->data;
    /*-- this doesn't track cluster counts, just cluster identities --*/
    g_signal_emit (G_OBJECT (gg), GGobiSignals[CLUSTERS_CHANGED_SIGNAL], 0,
                   d);
  }

  gdk_window_raise (gg->cluster_ui.window->window);
}