File: data.gob

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 (649 lines) | stat: -rw-r--r-- 16,034 bytes parent folder | download | duplicates (5)
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
%h{

#include "defines.h"
#include "brushing.h"
#include "vartable.h"
#include "fileio.h"

#include <gtk/gtk.h>

typedef struct _Subset {
  gint random_n;
  gint string_pos;
 /*-- adjustments from which to get values for blocksize, everyn --*/
  GtkAdjustment *bstart_adj, *bsize_adj;
  GtkAdjustment *estart_adj, *estep_adj;
} Subset;


typedef struct _Jitterd {
  gfloat factor;
  gboolean type;
  gboolean convex;
  gfloat *jitfacv;
} Jitterd;

typedef struct _Varpanel_cboxd {
  GtkWidget *ebox;   /*-- child1 of pane widget --*/
  GtkWidget *swin;   /*-- child of ebox --*/
  GtkWidget *vbox;   /*-- child of swin --*/
  GSList *box;       /*-- single column of hboxes --*/
} Varpanel_cboxd;

typedef struct _Varpanel_circd {
  GtkWidget *ebox;        /*-- child2 of pane widget --*/
  GtkWidget *vbox;        /*-- child of ebox --*/
  GtkWidget *swin, *hbox; /*-- children of vbox --*/
  GtkWidget *table;       /*-- sole child of swin; now a vbox --*/
  GtkWidget *manip_btn, *freeze_btn; /*-- children of hbox --*/

  GdkCursor *cursor;
  gint jcursor;

 /*-- components and properties of the table --*/
  GSList *vb, *da, *label;
  GSList *da_pix;         /*-- backing pixmaps --*/
  gint nvars;
} Varpanel_circd;

typedef struct _Varpaneld {
  GtkWidget *hpane;  /*-- child of the ebox --*/
} Varpaneld;

/*-------------------- transformation --------------------------------*/

/* sphering transformation */
typedef struct _Sphere_d {
  vector_i vars;        /*-- vars available to be sphered --*/
  vector_i vars_sphered;/*-- vars that have been sphered --*/
  gint npcs;      /*-- the first npcs vars of vars will be sphered --*/
  vector_i pcvars;/*-- vars into which sphered data is written --*/

  vector_f eigenval;
  array_d eigenvec;
  array_f vc;
  vector_f tform_mean;
  vector_f tform_stddev;

  gboolean vars_stdized;
} Sphere_d;


typedef struct _EdgeData {
  gint n;
  SymbolicEndpoints *sym_endpoints;
  GList *endpointList;   
    /* a list of endpointsd elements corresponding to the resolved 
       record ids relative to a given datad. This is akin to a table
       indexed by datad elements. */

  gint nxed_by_brush;
  vector_b xed_by_brush;
} EdgeData;

typedef struct _BrushBins {
  gint nbins;
  bin_struct **binarray;
  icoords bin0, bin1;
} BrushBins;


%}

%{
#include "vars.h"
#include "externs.h"
%}

class GGobi:Data from G:Object {

public const gchar *name;
public const gchar *nickname;
public InputDescription *input;

public guint nrows;
public gint ncols;

public gboolean missings;

public struct _ggobid *gg; /*-- a pointer to the parent --*/

public GArray *rowlab;

/*-- row ids to support generalized linking --*/
public GHashTable *idTable;
public char **rowIds;
/*-- to support brushing by categorical variable --*/
public vartabled *linkvar_vt;  /*-- the linking variable --*/

public Subset  subset;
public Jitterd  jitter;
public Varpanel_cboxd  vcbox_ui;
public Varpanel_circd  vcirc_ui;
public Varpaneld  varpanel_ui;
public Sphere_d  sphere;
public EdgeData  edge;
public BrushBins  brush;

public GSList *vartable;

public GtkWidget *vartable_tree_view[all_vartypes];
public GtkTreeModel *vartable_tree_model; /* the root model, with all vars */

public array_f raw;
public array_f tform;
public array_g world;
public array_g jitdata;

/*----------------------- missing values ---------------------------*/

public array_s missing; 
public gboolean missings_show_p; /*-- show/hide per datad, not per display --*/

/*---------------- deleting the hidden points; subsetting ----------*/

public vector_i rows_in_plot;  /*-- always of length self->nrows --*/
public gint nrows_in_plot;     /*-- how many elements of rows_in_plot to use --*/
public vector_b sampled;
public vector_b excluded;

/*--------------- clusters: hiding, excluding ----------------------*/

public symbol_cell symbol_table[NGLYPHTYPES][NGLYPHSIZES][MAXNCOLORS];
public GtkWidget *cluster_table; /*-- table of symbol groups from brushing --*/
public gint nclusters;
public clusterd *clusv;
public clusteruid *clusvui;
public vector_i clusterid;  /* cluster membership for each record */

/*------------------------ brushing ----------------------------------*/

public gint npts_under_brush;
public vector_b pts_under_brush;
public vector_s color;
public vector_s color_now; 
public vector_s color_prev;
public vector_b hidden;
public vector_b hidden_now;
public vector_b hidden_prev;
public vector_g glyph;
public vector_g glyph_now;
public vector_g glyph_prev;

/*-- used in identification, line editing, and point motion --*/
public gint nearest_point;
public gint nearest_point_prev;
public GSList *sticky_ids;

/*-------------------- moving points ---------------------------------*/
public GSList *movepts_history; /*-- a list of elements of type celld --*/


property UINT nrows 
  (nick = "nrows", blurb = "Number of rows in the dataset",
   minimum = 0, maximum = INT_MAX, default_value = 0,
   flags = CONSTRUCT_ONLY, link, export);
property UINT ncols 
  (nick = "ncols", blurb = "Number of cols in the dataset",
   minimum = 0, maximum = INT_MAX, default_value = 0,
   flags = CONSTRUCT_ONLY, link, export);
   
signal private NONE (INT, INT, POINTER) void rows_in_plot_changed(self, int arg1, int arg2, ggobid* arg3);

signal public NONE (INT) void col_name_changed(self, int j);

init (self) {
  sphere_init(self); 
  
  self_set_name(self, "unknown", NULL);

  self->nearest_point = -1;
  self->missings_show_p = true;
}

override (G:Object) GObject*
constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties)
{
  GGobiData* d = (GGobiData*) PARENT_HANDLER(type, n_construct_properties, construct_properties);
  /* we can put these here OR we can put them in the setter for the 'ncols'
     property, since we know that comes last (after 'nrows' has been set) */
  
  d->nrows_in_plot = d->nrows;  /*-- for now --*/

  arrayf_alloc (&d->raw, d->nrows, d->ncols); //FIXME: probably leaks memory
  //arrays_alloc (&d->missing, d->nrows, d->ncols);
  arrays_alloc_zero (&d->missing, d->nrows, d->ncols);

  rowlabels_alloc (d);

  vartable_alloc (d);
  vartable_init (d);

  br_glyph_ids_alloc (d);
  br_glyph_ids_init (d);

  br_color_ids_alloc (d);
  br_color_ids_init (d);

  br_hidden_alloc (d);
  br_hidden_init (d);


  return((GObject *)d);
}

public GGobiData* 
new(guint nrows, guint ncols)
{
  GGobiData* d = (GGobiData*) g_object_new(GGOBI_TYPE_DATA, "ncols", ncols, "nrows", nrows, NULL);
  return(d);
}

/* General comments: 
  1) the (broken) datad_free function may not be necessary, since we can specify
     finalizers for all the fields using GOB
  2) the (evil) datad_init function must be vanquished asap
*/

public gchar *
get_name (self)
{
  return (g_strdup(self->name));
}

public void
set_name (self, gchar *name, gchar *nickname)
{
  if (name == NULL) name = g_strdup("unknown");
  if (nickname == NULL) nickname = g_strndup(name, 5);

  self->name = g_strdup(name);
  self->nickname = g_strndup(name, 5);
}

public guint
get_n_cols(self) {
  return self->ncols;
}

public guint
get_n_rows(self) {
  return self->nrows;
}


public gchar* 
get_col_name(self, guint j) 
{
  vartabled* vt = vartable_element_get (j, self);
  return(vt->collab);
}

public void 
set_col_name(self, guint j, gchar* value) 
{
  vartabled* vt = vartable_element_get (j, self);

  //if (vt->collab) g_object_unref(vt->collab); 
	//if (vt->nickname) g_object_unref(vt->nickname);
  //if (vt->collab_tform) g_object_unref(vt->collab_tform);

  if (value == NULL) value = g_strdup_printf("V%d", j + 1);

  vt->collab = g_strdup(value);
  vt->collab_tform = g_strdup(value);
  vt->nickname = g_strndup (vt->collab, 2);

  g_signal_emit_by_name (self, "col_name_changed", (gpointer) self, j);

  // SEND COLUMN NAME CHANGED SIGNAL
  // Listeners:
  //  * vartable_collab_set_by_var (j, d);
  //  * varpanel_label_set (j, d);   /*-- checkboxes --*/
  //  * varcircle_label_set (j, d);  /*-- variable circles --*/
  //  * tform_label_update (jvar, d);
  
}

// FIXME: to be removed once pipeline in place
public gchar* 
get_transformed_col_name(self, guint j) 
{
  vartabled* vt = vartable_element_get (j, self);
  return(vt->collab_tform);
}

public void 
set_transformed_col_name(self, guint j, gchar* value) 
{
  vartabled* vt = vartable_element_get (j, self);
  //if (vt->collab_tform) g_object_unref(vt->collab_tform);  //is this necessary?
  vt->collab_tform = g_strdup(value);
}


/**
 * set_missing:
 * 
 * Set specified cell to be a missing value
 */
public void
set_missing (self, guint i, guint j)
{
  self->missing.vals[i][j] = 1;
  self->raw.vals[i][j] = 0;
  self->missings = TRUE;
}

public gboolean
is_missing (self, guint i, guint j) 
{
  return self->missings && (self->missing.vals[i][j] == 1);  
}

public gboolean
has_missings(self) 
{
  return self->missings;
}


public guint 
get_col_n_missing(self, guint j) {
  guint i, n = 0;

  for(i = 0; i < self->nrows; i++) {
    if (self_is_missing(self, i, j)) n++;
  }
  
  return(n);
}

public void
set_raw_values(self, guint j, gdouble *values)
{
  gint i;
  for (i = 0; i < self->nrows; i++) {
    self_set_raw_value(self, i, j, values[i]);
  }
}

public void
set_raw_value(self, guint i, guint j, gdouble value)
{
  if(GGobiMissingValue && GGobiMissingValue(value))
    self_set_missing(self, i, j);
  else self->raw.vals[i][j] = value;
}

/*
public void
set_catgorical_value(self, guint i, guint j, gchar* value) 
{
  vartabled *vt = vartable_element_get(j, self);
  guint i, level = -1;
  
  g_assert(vt->vartype == categorical);
  
  for(i = 0; i < vt->nlevels; i++) {
    if (g_ascii_strcasecmp(value, vt->level_names[i])) {
      level = i;
      break;
    }
  }
  //not found, must be new variable
  if (level == -1) {
    level = vt->nlevels++;
    
    vt->level_values[level] == level;
  }
  
  vt->level_counts[level]++;
  self_set_raw_value(self, i, j, vt->level_values[level]);
}

public void
set_string_value(self, guint i, guint j, gchar* value) 
{
  if (FALSE) {//FIXME: should be is_numeric
    self_set_raw_value(self, i, j, (gfloat) g_strtod (value, NULL));
  } else {
    if (value[0] == '\0' || !g_ascii_strcasecmp (value, "na") || !strcmp (value, "."))  
      self_set_missing(self, i, j);
    else
      self_set_categorical_value(self, i, j, value);
  }
}
*/

public gchar*
get_string_value(self, guint i, guint j, gboolean transformed) 
{
  gint n = 0, lval = -1;
  vartabled *vt = vartable_element_get(j, self);
  gdouble raw = transformed ? self->tform.vals[i][j] : self->raw.vals[i][j];
  
  if (self_is_missing(self, i, j)) 
    return g_strdup("NA");
  if (vt->vartype != categorical)
    return g_strdup_printf("%g", raw);
  
  for (n = 0; n < vt->nlevels; n++) {
    if (vt->level_values[n] == raw) {
      lval = n;
      break;
    }
  }
  if (lval == -1) {
    g_printerr ("The levels for %s aren't specified correctly\n",            vt->collab);
    return(NULL);
  }
  
  return vt->level_names[lval];
}

public gboolean 
has_edges (self) 
{
  return (self->edge.n > 0);
}

public gboolean 
has_variables (self) 
{
  return (self->ncols > 0);
}


}


%h{

void freeLevelHashEntry(gpointer key, gpointer value, gpointer data);

/*-- used as an attribute of variable notebooks --*/
typedef enum {no_edgesets, edgesets_only, all_datatypes} datatyped;

extern endpointsd *resolveEdgePoints(GGobiData *e, GGobiData *d);
void unresolveAllEdgePoints(GGobiData *e);

void datad_record_ids_set(GGobiData *d, gchar **ids, gboolean duplicate);
void ggobi_data_set_row_labels(GGobiData *d, gchar **labels);
%}

%{
void
datad_free (GGobiData *d, ggobid *gg) 
{
  arrayf_free (&d->raw, 0, 0);
  pipeline_arrays_free (d, gg);

  arrays_free (&d->missing, 0, 0);

   /* rowIds and idTable are intrinsically linked !*/
  if(d->idTable) {
    g_hash_table_foreach(d->idTable, freeLevelHashEntry, d->idTable);
    g_hash_table_destroy(d->idTable); 
  }

  if(d->rowIds) 
    g_free(d->rowIds);

  g_free (d);
}

displayd *
datad_init (GGobiData *d, ggobid *gg, gboolean cleanup)
{
  /* GGobi assumes datasets have at least one row */
  g_return_val_if_fail(d->nrows > 0, NULL);
  d->gg = gg;
  gg->d = g_slist_append (gg->d, d);
  displayd *display = NULL;

  if (cleanup) {
    varpanel_clear (d, gg);
  }

  varpanel_populate (d, gg);   /*-- toggles */
  /*-- circles: build but don't show --*/
  varcircles_populate (d, gg);

  pipeline_init (d, gg);
  clusters_set (d, gg);  /*-- find the clusters for data just read in --*/

  if (cleanup || g_list_length(gg->displays) == 0) {
    display_free_all (gg);  /*-- destroy any existing displays --*/
    gg->pmode = NULL_PMODE;

    /*-- initialize the first display --*/
    if(sessionOptions->info->createInitialScatterPlot && d->ncols > 0) {
/*XXX allow this to be specified as a gtk type name on the command
      line, initialization file, etc.  and invoke the corresponding
      create() method. */
      display = scatterplot_new (true, false, NULL, d, gg);
        /* Need to make certain this is the only one there. */

      if (display != NULL) {
        gg->displays = g_list_append (gg->displays, (gpointer) display);
	    gg->current_splot = (splotd *)
        	g_list_nth_data (display->splots, 0);
        display->current_splot = gg->current_splot;
        display_set_current (display, gg);

        /*-- turn on event handling in the very first plot --*/
        /*-- ... but will it cause trouble for later plots?  ok so far
	  --*/
	/* Is imode set yet?  I hope so. */
        sp_event_handlers_toggle (gg->current_splot, on, gg->pmode, gg->imode);
      }
    }
  }

  if (gg->current_display != NULL)
    varpanel_refresh (gg->current_display, gg);

  if (g_slist_index(gg->d, (gpointer)d) == 0)
    varpanel_set_sensitive (d, true, gg);

  g_signal_emit (G_OBJECT (gg), GGobiSignals[DATAD_ADDED_SIGNAL], 0, d);

  display_menu_build (gg);

  return (display);
}




/*------------------------------------------------------------------------*/
/*                          row labels                                    */
/*------------------------------------------------------------------------*/
/* This initializes rowIds to row numbers if ids are not provided */
void
datad_record_ids_set(GGobiData *d, gchar **ids, gboolean duplicate)
{
  gint i;
  guint *index;
  gchar *tmp;

  d->idTable = g_hash_table_new(g_str_hash, g_str_equal);
  d->rowIds = (gchar **) g_malloc(sizeof(gchar *) * d->nrows);
  for(i = 0; i < d->nrows; i++) {
     if(ids)
       tmp = duplicate ? g_strdup(ids[i]) : ids[i];
     else {
       char buf[10];
       sprintf(buf, "%d", i+1);
       tmp = g_strdup(buf);
     }
     index = (guint *) g_malloc(sizeof(guint));
     *index = i;
     g_hash_table_insert(d->idTable, tmp, index);
     d->rowIds[i] = tmp;     
     /* do not free anything here */
  }
}

/* Add a record id */
void
datad_record_id_add (gchar *id, GGobiData *d)
{
  gint i;
  guint *index;

  d->rowIds = (gchar **) g_realloc (d->rowIds, sizeof(gchar *) * d->nrows);
  i = d->nrows - 1;

  index = (guint *) g_malloc(sizeof(guint));
  *index = i;
  g_hash_table_insert (d->idTable, id, index);
  d->rowIds[i] = id;

/*
 * I don't really understand why I can't free this
 * when it's freed in datad_record_ids_set, but purify is
 * quite clear on this point.  -- dfs
*/
  /*g_free (index);*/
}

/* FIXME: this only works the first time */
void
ggobi_data_set_row_labels(GGobiData *d, gchar **labels)
{
	gint i;
	for (i = 0; i < d->nrows; i++) {
		gchar *label;
		if (labels && labels[i])
			label = g_strdup(labels[i]);
		else label = g_strdup_printf("%d", i);
		g_array_append_val(d->rowlab, label);
	}
}

void 
rowlabels_free (GGobiData *d)
{
  g_array_free (d->rowlab, true);
}


void
rowlabels_alloc (GGobiData *d) 
{
  if (d->rowlab != NULL) rowlabels_free (d);
  d->rowlab = g_array_sized_new (false, false, sizeof (gchar *), d->nrows);
}

void
rowlabel_add (gchar *label, GGobiData *d) 
{
  g_array_append_val (d->rowlab, label);

  g_assert (d->rowlab->len == d->nrows);
}


%}