File: tsdisplay.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 (369 lines) | stat: -rw-r--r-- 9,663 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
/* tsdisplay.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
 *
 * Contributing author of time series code:  Nicholas Lewin-Koh
*/


#include "ggobi.h"
#include "tsdisplay.h"

#include "externs.h"

#include <string.h>

displayd *
timeSeriesDisplayCreate(gboolean use_window, gboolean missing_p, splotd *sp, GGobiData *d, ggobid *gg)
{
  gint *selected_vars, nselected_vars = 0;
  displayd *dpy = NULL;

  selected_vars = (gint *) g_malloc (d->ncols * sizeof (gint));
  nselected_vars = selected_cols_get (selected_vars, d, gg);

  dpy = tsplot_new (dpy, use_window, false, nselected_vars, selected_vars, d, gg);

  g_free(selected_vars);

  return(dpy);
}


gint
tsplotIsVarPlotted(displayd *display, gint *cols, gint ncols, GGobiData *d)
{
  GList *l;
  splotd *sp;
  int j;

  for (l = display->splots; l; l = l->next) {
    sp = (splotd *) l->data;

    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);
      }
    }
  }

  return(-1);
}

gboolean
tsplotCPanelSet(displayd *dpy, cpaneld *cpanel, ggobid *gg)
{ 
  GtkWidget *w;
  w = GGOBI_EXTENDED_DISPLAY(dpy)->cpanelWidget;
  if(!w) {
    GGOBI_EXTENDED_DISPLAY(dpy)->cpanelWidget = w =  cpanel_tsplot_make(gg);
  }
/* Can actually be more efficient here by storing the option menu used
   in tsplot_set and avoid looking it up each time. Store it in the
   displayd object. */
  cpanel_tsplot_set (dpy, cpanel, w, gg);
  cpanel_brush_set (dpy, cpanel, gg);
  cpanel_identify_set (dpy, cpanel, gg);

  return(true);
}

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

void
tsplotVarpanelRefresh(displayd *display, splotd *sp, GGobiData *d)
{
  gint j;
  GList *l;

  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);
   }

   l = display->splots;
   while (l) {
     j = ((splotd *) l->data)->xyvars.y;
     varpanel_toggle_set_active (VARSEL_Y, j, true, d);
     j = ((splotd *) l->data)->xyvars.x;
     varpanel_toggle_set_active (VARSEL_X, j, true, d);
     l = l->next;
   }
}

gboolean
tsplotHandlesInteraction(displayd *dpy, InteractionMode mode)
{
  return(mode == BRUSH || mode == IDENT || mode == DEFAULT_IMODE);
}

#ifdef STORE_SESSION_ENABLED

/*
  Write out the variables in a time series plot
  to the current node in the XML tree.
 */
void
add_xml_tsplot_variables(xmlNodePtr node, GList *plots, displayd *dpy)
{
  splotd *plot;
  xmlNodePtr no;

  plot = (splotd *)plots->data;
  no = XML_addVariable(node, plot->xyvars.x, dpy->d);
  xmlSetProp(no, (xmlChar *) "type", (xmlChar *) "time");
  while(plots) {
    plot = (splotd *)plots->data;
    XML_addVariable(node, plot->xyvars.y, dpy->d);
    plots = plots->next;
  }
}
#endif

void
tsplotVarpanelTooltipsSet(displayd *dpy, ggobid *gg, GtkWidget *wx, GtkWidget *wy, GtkWidget *wz, GtkWidget *label)
{
  gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wx,
    "Select to replace the horizontal (time) variable.",
    NULL);
  gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), wy,
    "Select to delete or append a Y variable; drag plots to reorder.",
    NULL);
  gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), label,
    "Click left to replace the horizontal (time) variable.  Click middle or right to append or delete a Y variable; drag plots to reorder.",
    NULL);
}


gint
tsplotPlottedColsGet(displayd *display, gint *cols, GGobiData *d, ggobid *gg)
{
  GList *l;
  splotd *s;
  gint ncols = 0;

  for (l=display->splots; l; l=l->next) {
    s = (splotd *) l->data;
    if (!array_contains (cols, ncols, s->xyvars.y))
      cols[ncols++] = s->xyvars.y;
  }
  return(ncols);
}

GtkWidget *
tsplotCPanelWidget(displayd *dpy, gchar **modeName, ggobid *gg)
{
  GtkWidget *w = GGOBI_EXTENDED_DISPLAY(dpy)->cpanelWidget;
  if(!w) {
   GGOBI_EXTENDED_DISPLAY(dpy)->cpanelWidget = w =  cpanel_tsplot_make(gg);
  }
  *modeName = "TSPlot";
  return(w);
}

/*********************************************************************/
void
start_timeSeries_drag(GtkWidget *src, GdkDragContext *ctxt, GtkSelectionData *data, guint info, guint time, gpointer udata)
{
   gtk_selection_data_set(data, data->target, 8, (guchar *) src, sizeof(splotd *)); 
}

void
receive_timeSeries_drag(GtkWidget *src, GdkDragContext *context, int x, int y, const GtkSelectionData *data,   unsigned int info, unsigned int event_time, gpointer *udata)
{
  splotd *to = GGOBI_SPLOT(src), *from, *sp;
  displayd *display;
  display = to->displayptr;
  GList *l;
  gint k;
  GList *ivars = NULL;
  gint xvar;

  from = GGOBI_SPLOT(gtk_drag_get_source_widget(context));

  if(from->displayptr != display) {
      gg_write_to_statusbar("the source and destination of the parallel coordinate plots are not from the same display.\n", display->ggobi);
      return;
  }

  /* Get the x variable */
  sp = (splotd *) (display->splots)->data;
  xvar = sp->xyvars.x;

  /* Gather a list of indices of the vertically plotted variables */
  l = display->splots;
  while (l) {
    sp = (splotd *) l->data;
    ivars = g_list_append(ivars, GINT_TO_POINTER(sp->xyvars.y));
    l = l->next;
  }

  /* Find the index of the to element */
  k = g_list_index(ivars, GINT_TO_POINTER(to->xyvars.y));
  /* Remove the from element */
  ivars = g_list_remove(ivars, GINT_TO_POINTER(from->xyvars.y));
  /* Insert the from element in the position of the to element */
  ivars = g_list_insert(ivars, GINT_TO_POINTER(from->xyvars.y), k);


  /* Assign them to the existing plots */
  k = 0;
  l = display->splots;
  while (l) {
    sp = (splotd *) l->data;
    sp->xyvars.y = GPOINTER_TO_INT(g_list_nth_data(ivars, k));
    k++;
    l = l->next;
  }
  g_list_free(ivars);

  display_tailpipe (display, FULL, display->ggobi);
  varpanel_refresh (display, display->ggobi);
}

void
timeSeriesPlotDragAndDropEnable(splotd *sp, gboolean active) {
  static GtkTargetEntry target = {"text/plain", GTK_TARGET_SAME_APP, 1001};	
  if (active) {
    gtk_drag_source_set(GTK_WIDGET(sp), GDK_BUTTON1_MASK, &target, 1, 
      GDK_ACTION_COPY);
    g_signal_connect(G_OBJECT(sp), "drag_data_get",  
      G_CALLBACK(start_timeSeries_drag), NULL);
    gtk_drag_dest_set(GTK_WIDGET(sp), GTK_DEST_DEFAULT_ALL /* DROP */,
      &target, 1, GDK_ACTION_COPY /*MOVE*/);
    g_signal_connect(G_OBJECT(sp), "drag_data_received",
      G_CALLBACK(receive_timeSeries_drag), NULL);
  } else {
    g_signal_handlers_disconnect_by_func(G_OBJECT(sp),
      G_CALLBACK(start_timeSeries_drag), NULL);
    g_signal_handlers_disconnect_by_func(G_OBJECT(sp),
      G_CALLBACK(receive_timeSeries_drag), NULL);
    gtk_drag_source_unset(GTK_WIDGET(sp));
    gtk_drag_dest_unset(GTK_WIDGET(sp));
  }
}

void
timeSeriesDragAndDropEnable(displayd *dsp, gboolean active) {
  GList *l;
  for (l = dsp->splots; l; l = l->next) {
    splotd *sp = (splotd *)l->data;
    timeSeriesPlotDragAndDropEnable(sp, active);
  }
}

/*************************************************************************/

gboolean 
tsplotEventHandlersToggle(displayd *dpy, splotd *sp, gboolean state, ProjectionMode pmode, InteractionMode imode)
{
  timeSeriesDragAndDropEnable(dpy, false);

  switch (imode) {
  case DEFAULT_IMODE:
    timeSeriesDragAndDropEnable(dpy, true);
    xyplot_event_handlers_toggle (sp, state);  /*-- ?? --*/
  break;
  case BRUSH:
    brush_event_handlers_toggle (sp, state);
  break;
  case IDENT:
    identify_event_handlers_toggle (sp, state);
  break;
  default:
  break;
  }

  return false;
}


#include <gdk/gdkkeysyms.h>

gboolean
tsplotKeyEventHandled(GtkWidget *w, displayd *display, splotd *sp, GdkEventKey *event, ggobid *gg)
{
  gboolean ok = true;
  ProjectionMode pmode = NULL_PMODE;
  InteractionMode imode = DEFAULT_IMODE;

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

  switch (event->keyval) {
    case GDK_h:
    case GDK_H:
      pmode = EXTENDED_DISPLAY_PMODE;
    break;

    case GDK_b:
    case GDK_B:
      imode = BRUSH;
    break;
    case GDK_i:
    case GDK_I:
      imode = IDENT;
    break;

    default:
      ok = false;
    break;
  }

  if (ok) {
    GGOBI(full_viewmode_set)(pmode, imode, gg);
  }
  } else { ok = false; }

  return ok;
}


gchar *
tsplot_tree_label(splotd *sp, GGobiData *d, ggobid *gg)
{
  return(ggobi_data_get_col_name(d, sp->xyvars.y));
}

/*************************************************/

void
tsplot_cpanel_init (cpaneld* cpanel, ggobid *gg) 
{
  cpanel->pmode = EXTENDED_DISPLAY_PMODE;
  cpanel->imode = DEFAULT_IMODE;

  /*-- 1d plots --*/
  cpanel->p1d.type = DOTPLOT;
  cpanel_p1d_init (cpanel, gg);

  cpanel->tsplot_arrangement = ARRANGE_COL;

  /*-- available modes --*/
  cpanel_brush_init (cpanel, gg);
  cpanel_identify_init (cpanel, gg);
}


/*--------------------------------------------------------------------*/
/*                   Time series: Options menu                        */
/*--------------------------------------------------------------------*/