[xiph-commits] r12119 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Nov 16 02:39:34 PST 2006


Author: xiphmont
Date: 2006-11-16 02:39:31 -0800 (Thu, 16 Nov 2006)
New Revision: 12119

Modified:
   trunk/sushivision/panel-2d.c
   trunk/sushivision/plot.c
   trunk/sushivision/scale.c
   trunk/sushivision/scale.h
Log:
Add scale labels to plot



Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2006-11-16 10:03:19 UTC (rev 12118)
+++ trunk/sushivision/panel-2d.c	2006-11-16 10:39:31 UTC (rev 12119)
@@ -238,6 +238,7 @@
   int i;
   // update which x/y buttons are pressable */
   // enable/disable dimension slider thumbs
+
   for(i=0;i<p->dimensions;i++){
     if(p2->dim_xb[i] &&
        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p2->dim_xb[i]))){
@@ -252,7 +253,8 @@
       p2->x = scalespace_linear(p2->x_d->bracket[0],
 				p2->x_d->bracket[1],
 				p2->data_w,
-				PLOT(p2->graph)->scalespacing);
+				PLOT(p2->graph)->scalespacing,
+				p2->x_d->name);
     }else{
       // if there is a y, make it sensitive 
       if(p2->dim_yb[i])
@@ -271,7 +273,8 @@
       p2->y = scalespace_linear(p2->y_d->bracket[0],
 				p2->y_d->bracket[1],
 				p2->data_h,
-				PLOT(p2->graph)->scalespacing);
+				PLOT(p2->graph)->scalespacing,
+				p2->y_d->name);
     }else{
       // if there is a x, make it sensitive 
       if(p2->dim_xb[i])
@@ -574,11 +577,13 @@
       p2->x = scalespace_linear(p2->x_d->bracket[0],
 				p2->x_d->bracket[1],
 				w,
-				PLOT(p2->graph)->scalespacing);
+				PLOT(p2->graph)->scalespacing,
+				p2->x_d->name);
       p2->y = scalespace_linear(p2->y_d->bracket[0],
 				p2->y_d->bracket[1],
 				h,
-				PLOT(p2->graph)->scalespacing);
+				PLOT(p2->graph)->scalespacing,
+				p2->y_d->name);
       p2->data_rect = calloc(p->objectives,sizeof(*p2->data_rect));
       for(i=0;i<p->objectives;i++)
 	p2->data_rect[i] = malloc(p2->data_w * p2->data_h* sizeof(**p2->data_rect));
@@ -675,7 +680,8 @@
   if(d->bracket[0] != lo || d->bracket[1] != hi){
     double xy_p = d == p2->x_d;
     scalespace s = scalespace_linear(lo,hi,(xy_p?p2->data_w:p2->data_h),
-				     PLOT(p2->graph)->scalespacing);
+				     PLOT(p2->graph)->scalespacing,
+				     d->name);
     
     if(s.m == 0){
       if(xy_p)
@@ -1359,6 +1365,7 @@
 
   g_signal_connect (G_OBJECT (p2->toplevel), "key-press-event",
                     G_CALLBACK (panel2d_keypress), p);
+  gtk_window_set_title (GTK_WINDOW (p2->toplevel), p->name);
 
   gtk_widget_realize(p2->toplevel);
   gtk_widget_realize(p2->graph);

Modified: trunk/sushivision/plot.c
===================================================================
--- trunk/sushivision/plot.c	2006-11-16 10:03:19 UTC (rev 12118)
+++ trunk/sushivision/plot.c	2006-11-16 10:39:31 UTC (rev 12119)
@@ -41,6 +41,7 @@
   int i=0,x,y;
   char buffer[80];
   int y_width=0;
+  int x_height=0;
 
   cairo_save(c);
   cairo_set_operator(c,CAIRO_OPERATOR_CLEAR);
@@ -73,7 +74,7 @@
   cairo_stroke(c);
   cairo_restore(c);
 
-  // text labels
+  // text number labels
   cairo_select_font_face (c, "Sans",
 			  CAIRO_FONT_SLANT_NORMAL,
 			  CAIRO_FONT_WEIGHT_NORMAL);
@@ -108,19 +109,36 @@
     scalespace_label(&ys,i++,buffer);
   }
 
+  // set sideways text
+  cairo_save(c);
+  cairo_matrix_t m = {0.,-1., 1.,0.,  0.,h};
+  cairo_set_matrix(c,&m);
+
+  // text y scale label
+  if(ys.legend){
+    cairo_text_extents_t extents;
+    cairo_text_extents (c, ys.legend, &extents);
+    
+    cairo_move_to(c,h/2 - extents.width/2+extents.x_bearing, y_width-extents.y_bearing+5);
+    cairo_set_source_rgba(c,0,0,0,.5);
+    cairo_text_path (c, ys.legend);  
+    cairo_stroke(c);
+    
+    cairo_move_to(c,h/2 - extents.width/2+extents.x_bearing, y_width-extents.y_bearing+5);
+    cairo_set_source_rgba(c,1.,1.,1.,1.);
+    cairo_show_text (c, ys.legend);
+  }
+
   i=0;
   x=scalespace_mark(&xs,i);
   scalespace_label(&xs,i++,buffer);
   
-  {
-    cairo_matrix_t m = {0.,-1., 1.,0.,  0.,h};
-    cairo_set_matrix(c,&m);
-  }
-
   while(x < w){
     cairo_text_extents_t extents;
     cairo_text_extents (c, buffer, &extents);
 
+    if(extents.width > x_height) x_height = extents.width;
+
     if(x - extents.height > y_width+5 ){
 
       cairo_move_to(c,2, x+.5-(extents.height/2 + extents.y_bearing));
@@ -137,6 +155,22 @@
     scalespace_label(&xs,i++,buffer);
   }
 
+  cairo_restore(c);
+  // text x scale label
+  if(xs.legend){
+    cairo_text_extents_t extents;
+    cairo_text_extents (c, xs.legend, &extents);
+    
+    cairo_move_to(c,w/2 - extents.width/2+extents.x_bearing, h - x_height+ extents.y_bearing-5);
+    cairo_set_source_rgba(c,0,0,0,.5);
+    cairo_text_path (c, xs.legend);  
+    cairo_stroke(c);
+    
+    cairo_move_to(c,w/2 - extents.width/2+extents.x_bearing, h - x_height+ extents.y_bearing-5);
+    cairo_set_source_rgba(c,1.,1.,1.,1.);
+    cairo_show_text (c, xs.legend);
+  }
+
   cairo_destroy(c);
 }
 
@@ -231,8 +265,8 @@
 static void plot_init (Plot *p){
   // instance initialization
   p->scalespacing = 50;
-  p->x = scalespace_linear(0.0,1.0,400,p->scalespacing);
-  p->y = scalespace_linear(0.0,1.0,200,p->scalespacing);
+  p->x = scalespace_linear(0.0,1.0,400,p->scalespacing,NULL);
+  p->y = scalespace_linear(0.0,1.0,200,p->scalespacing,NULL);
 }
 
 static void plot_destroy (GtkObject *object){
@@ -457,8 +491,8 @@
   }
 
   widget->allocation = *allocation;
-  p->x = scalespace_linear(p->x.lo,p->x.hi,widget->allocation.width,p->scalespacing);
-  p->y = scalespace_linear(p->y.lo,p->y.hi,widget->allocation.height,p->scalespacing);
+  p->x = scalespace_linear(p->x.lo,p->x.hi,widget->allocation.width,p->scalespacing,p->x.legend);
+  p->y = scalespace_linear(p->y.lo,p->y.hi,widget->allocation.height,p->scalespacing,p->y.legend);
   plot_unset_box(p);
   plot_draw_scales(p);
   if(p->recompute_callback)p->recompute_callback(p->app_data);

Modified: trunk/sushivision/scale.c
===================================================================
--- trunk/sushivision/scale.c	2006-11-16 10:03:19 UTC (rev 12118)
+++ trunk/sushivision/scale.c	2006-11-16 10:39:31 UTC (rev 12119)
@@ -178,7 +178,8 @@
   return val;
 }
 
-scalespace scalespace_linear (double lowpoint, double highpoint, int pixels, int max_spacing){
+// name is *not* copied
+scalespace scalespace_linear (double lowpoint, double highpoint, int pixels, int max_spacing, char *name){
   double range = fabs(highpoint - lowpoint);
   scalespace ret;
 
@@ -190,6 +191,7 @@
   ret.hi = highpoint;
   ret.init = 1;
   ret.pixels=pixels;
+  ret.legend=name;
 
   if(range == 0){
     ret.m = 0;

Modified: trunk/sushivision/scale.h
===================================================================
--- trunk/sushivision/scale.h	2006-11-16 10:03:19 UTC (rev 12118)
+++ trunk/sushivision/scale.h	2006-11-16 10:39:31 UTC (rev 12119)
@@ -20,6 +20,7 @@
  */
 
 typedef struct {
+  char *legend;
   double lo;
   double hi;
 
@@ -43,4 +44,4 @@
 extern double scalespace_pixel(scalespace *s, double val);
 extern int scalespace_mark(scalespace *s, int num);
 extern double scalespace_label(scalespace *s, int num, char *buffer);
-extern scalespace scalespace_linear (double lowpoint, double highpoint, int pixels, int max_spacing);
+extern scalespace scalespace_linear (double lowpoint, double highpoint, int pixels, int max_spacing,char *name);



More information about the commits mailing list