]> granicus.if.org Git - graphviz/commitdiff
*** empty log message ***
authorarif <devnull@localhost>
Mon, 13 Oct 2008 19:41:50 +0000 (19:41 +0000)
committerarif <devnull@localhost>
Mon, 13 Oct 2008 19:41:50 +0000 (19:41 +0000)
cmd/smyrna/gui/toolboxcallbacks.c
cmd/smyrna/gui/toolboxcallbacks.h
cmd/smyrna/smyrnadefs.h
cmd/smyrna/topview.c
cmd/smyrna/topview.h

index d7a5cdb19d57fb1a92b61f6215d1dfd827587a79..80873583c07f19d164520e5415b1501f9b6948f6 100755 (executable)
@@ -86,14 +86,14 @@ void btnToolZoomOut_clicked(GtkWidget * widget, gpointer user_data)
 void btnToolZoomFit_clicked(GtkWidget * widget, gpointer user_data)
 {
 
-       float scx,scy,gcx,gcy,z,GDX,SDX;
+       float scx,scy,gcx,gcy,z,GDX,SDX,GDY,SDY;
 
        (view->active_camera >=0)
                        ? (z=view->cameras[view->active_camera]->r):(z=view->zoom*-1);
 
        GDX=(view->bdxRight/z-view->bdxLeft/z);
        SDX=(view->clipX2 -view->clipX1);
-       GDY=(view->bdxTop/z-view->bdxBottom/z);
+       GDY=(view->bdyTop/z-view->bdyBottom/z);
        SDY=(view->clipY2 -view->clipY1);
        
        if ((SDX / GDX) <= (SDY / GDY))
@@ -109,6 +109,7 @@ void btnToolZoomFit_clicked(GtkWidget * widget, gpointer user_data)
                                (view->zoom = view->zoom /(SDY/GDY));
 
        }
+       btnToolFit_clicked(NULL,NULL);
 
 }
 
@@ -154,7 +155,6 @@ void btnToolFit_clicked(GtkWidget * widget, gpointer user_data)
                printf ("GDX:%f SDX:%f \n",GDX,SDX);
                view->panx += (gcx-scx);
                view->pany += (gcy-scy);
-               view->zoom = view->zoom /(SDX/GDX);
        }
 
        printf ("scx:%f\n",scx);
index e8edcc1008027426f0df0141416221bd92af31e0..65a62cc71c6be1a3b87493cb37d48a9f9947c5b0 100755 (executable)
@@ -40,6 +40,7 @@ _BB void btnToolPan_clicked(GtkWidget * widget, gpointer user_data);
 _BB void btnToolZoom_clicked(GtkWidget * widget, gpointer user_data);
 _BB void btnToolZoomIn_clicked(GtkWidget * widget, gpointer user_data);
 _BB void btnToolZoomOut_clicked(GtkWidget * widget, gpointer user_data);
+_BB void btnToolZoomFit_clicked(GtkWidget * widget, gpointer user_data);
 _BB void btnToolFit_clicked(GtkWidget * widget, gpointer user_data);
 _BB void btnToolMove_clicked(GtkWidget * widget, gpointer user_data);
 _BB void btnToolAddNode_clicked(GtkWidget * widget, gpointer user_data);
index a62867430b0611df60d33437a282138b9aba2b96..683a6ee622faef4b61d2b056477589bddb794d91 100644 (file)
@@ -413,7 +413,7 @@ typedef struct _ViewInfo
        /*randomize edge colors or use default edge color*/
        int rndEdgeColor;
        /*Font Size*/
-       int FontSize;
+       float FontSize;
 
 
        float bdxLeft,bdyTop,bdzTop;    
index 1155dc0fb3d28cc03d271fe8b1a6a4c682da6d33..4fd0034744a24fc445c6a20c0ebe649525c1268a 100755 (executable)
@@ -65,8 +65,15 @@ void preparetopview(Agraph_t * g, topview * t)
     Agedge_t *e;
     Agsym_t *sym;
     int ind, ind2, data_type_count;    //number of columns for custom view->Topview data ,IP ,HOST, etc
-    char buf[256];
+       char buf[256];
     RGBColor color;
+
+       int maxlabelsize=0;
+       float maxedgelen,minedgelen,len,edgelength;
+       maxedgelen=0;
+       minedgelen=99999999;    //FIX ME if you have a giant graph or fix your graph
+       edgelength=0;
+
     ind = 0;
     ind2 = 0;
     gtk_widget_hide(glade_xml_get_widget(xml, "layout6"));     //hide top panel
@@ -92,106 +99,128 @@ void preparetopview(Agraph_t * g, topview * t)
     /* malloc topviewdata */
     t->TopviewData = NEW(topviewdata);
 
-    for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
-       //set node TV reference
-       OD_TVRef(v) = ind;      //view->Topview reference
-       strcpy(buf, agget(v, "pos"));
-       if (strlen(buf)) {
-           a = (float) atof(strtok(buf, ","));
-           b = (float) atof(strtok(NULL, ","));
-           str = strtok(NULL, ",");
-           if (str)
-               c = (float) atof(str);
-           else
-               c = (float) 0.0;
-       }
-       /*initialize group index, -1 means no group */
-       t->Nodes[ind].GroupIndex = -1;
-       t->Nodes[ind].Node = v;
-       if (agget(t->Nodes[ind].Node, "color")) {
-           color = GetRGBColor(agget(t->Nodes[ind].Node, "color"));
-           t->Nodes[ind].Color.R = color.R;
-           t->Nodes[ind].Color.G = color.G;
-           t->Nodes[ind].Color.B = color.B;
-           t->Nodes[ind].Color.A = color.A;
-       } else
-           randomize_color(&(t->Nodes[ind].Color), 2);
-       t->Nodes[ind].x = a;
-       t->Nodes[ind].y = b;
-       t->Nodes[ind].z = c;
-       t->Nodes[ind].distorted_x = a;
-       t->Nodes[ind].distorted_y = b;
-       t->Nodes[ind].distorted_z = c;
-
-       t->Nodes[ind].zoom_factor = 1;
-       t->Nodes[ind].degree = agdegree(g, v, 1, 1);
-       t->Nodes[ind].node_alpha = 1;
+    for (v = agfstnode(g); v; v = agnxtnode(g, v)) 
+       {
+               //set node TV reference
+               OD_TVRef(v) = ind;      //view->Topview reference
+               strcpy(buf, agget(v, "pos"));
+               if (strlen(buf)) 
+               {
+                       a = (float) atof(strtok(buf, ","));
+                       b = (float) atof(strtok(NULL, ","));
+                       str = strtok(NULL, ",");
+                       if (str)
+                               c = (float) atof(str);
+                       else
+                               c = (float) 0.0;
+               }
+               /*initialize group index, -1 means no group */
+               t->Nodes[ind].GroupIndex = -1;
+               t->Nodes[ind].Node = v;
+               if (agget(t->Nodes[ind].Node, "color")) 
+               {
+                       color = GetRGBColor(agget(t->Nodes[ind].Node, "color"));
+                       t->Nodes[ind].Color.R = color.R;
+                       t->Nodes[ind].Color.G = color.G;
+                       t->Nodes[ind].Color.B = color.B;
+                       t->Nodes[ind].Color.A = color.A;
+               } else
+                       randomize_color(&(t->Nodes[ind].Color), 2);
+               t->Nodes[ind].x = a;
+               t->Nodes[ind].y = b;
+               t->Nodes[ind].z = c;
+               t->Nodes[ind].distorted_x = a;
+               t->Nodes[ind].distorted_y = b;
+               t->Nodes[ind].distorted_z = c;
+
+               t->Nodes[ind].zoom_factor = 1;
+               t->Nodes[ind].degree = agdegree(g, v, 1, 1);
+               t->Nodes[ind].node_alpha = 1;
        //    (float) log((double) t->Nodes[ind].degree + (double) 0.3);
-       if (d_attr1) {
-           if (sym)
-               str = agxget(v, sym);
-           else
-               str = agnameof(v);
-           t->Nodes[ind].Label = strdup(str);
-       } else
-           t->Nodes[ind].Label = '\0';
-       if (d_attr2) {
-           str = agget(v, d_attr2);
-           if (str) {
-               t->Nodes[ind].Label2 = strdup(str);
-           }
-       } else
-           t->Nodes[ind].Label2 = '\0';
-
-       for (e = agfstout(g, v); e; e = agnxtout(g, e)) {
-           t->Edges[ind2].Hnode = aghead(e);
-           t->Edges[ind2].Tnode = agtail(e);
-           t->Edges[ind2].Edge = e;
-           strcpy(buf, agget(aghead(e), "pos"));
-           if (strlen(buf)) {
-               a = (float) atof(strtok(buf, ","));
-               b = (float) atof(strtok(NULL, ","));
-               str = strtok(NULL, ",");
-               if (str)
-                   c = (float) atof(str);
+               if (d_attr1) 
+               {
+                       if (sym)
+                               str = agxget(v, sym);
+                       else
+                               str = agnameof(v);
+                       t->Nodes[ind].Label = strdup(str);
+               } 
                else
-                   c = (float) 0.0;
+                       t->Nodes[ind].Label = '\0';
+               if (d_attr2) 
+               {
+                       str = agget(v, d_attr2);
+                       if (str) 
+                               t->Nodes[ind].Label2 = strdup(str);
+               } else
+                       t->Nodes[ind].Label2 = '\0';
 
-               t->Edges[ind2].x1 = a;
-               t->Edges[ind2].y1 = b;
-               t->Edges[ind2].z1 = b;
-           }
-           strcpy(buf, agget(agtail(e), "pos"));
-           if (strlen(buf)) {
-               a = (float) atof(strtok(buf, ","));
-               b = (float) atof(strtok(NULL, ","));
-               str = strtok(NULL, ",");
-               if (str)
-                   c = (float) atof(str);
-               else
-                   c = (float) 0.0;
-               t->Edges[ind2].x2 = a;
-               t->Edges[ind2].y2 = b;
-               t->Edges[ind2].z2 = c;
-           }
-           ind2++;
-       }
+               maxlabelsize = maxlabelsize + strlen(t->Nodes[ind].Label);
+
+               for (e = agfstout(g, v); e; e = agnxtout(g, e)) 
+               {
+                       t->Edges[ind2].Hnode = aghead(e);
+                       t->Edges[ind2].Tnode = agtail(e);
+                       t->Edges[ind2].Edge = e;
+                       strcpy(buf, agget(aghead(e), "pos"));
+                       if (strlen(buf))
+                       {
+                               a = (float) atof(strtok(buf, ","));
+                               b = (float) atof(strtok(NULL, ","));
+                               str = strtok(NULL, ",");
+                               if (str)
+                                       c = (float) atof(str);
+                               else
+                                       c = (float) 0.0;
+                               t->Edges[ind2].x1 = a;
+                               t->Edges[ind2].y1 = b;
+                               t->Edges[ind2].z1 = b;
+                       }
+                       strcpy(buf, agget(agtail(e), "pos"));
+                       if (strlen(buf)) 
+                       {
+                               a = (float) atof(strtok(buf, ","));
+                               b = (float) atof(strtok(NULL, ","));
+                               str = strtok(NULL, ",");
+                               if (str)
+                                       c = (float) atof(str);
+                               else
+                                       c = (float) 0.0;
+                               t->Edges[ind2].x2 = a;
+                               t->Edges[ind2].y2 = b;
+                               t->Edges[ind2].z2 = c;
+                       }
+                       len=pow(pow((t->Edges[ind2].x2-t->Edges[ind2].x1),2)+pow((t->Edges[ind2].y2-t->Edges[ind2].y1),2),0.5);
+                       if (len > maxedgelen)
+                               maxedgelen=len;
+                       if (len < minedgelen)
+                               minedgelen=len;
+                       edgelength = edgelength + len;
+                       ind2++;
+               }
+               //calculate a decent fontsize 
        ind++;
-    }
-    //attach edge node references   loop one more time
+       }
+//     calcfontsize(float totaledgelength,int totallabelsize,int edgecount,int totalnodecount)
+       view->FontSize=calcfontsize(edgelength,maxlabelsize,ind2,ind);
+       //attach edge node references ,  loop one more time
     ind = 0;
     ind2 = 0;
-    for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
-       //set node TV reference
-       for (e = agfstout(g, v); e; e = agnxtout(g, e)) {
-           t->Edges[ind2].Node1 =
-               &t->Nodes[OD_TVRef(t->Edges[ind2].Tnode)];
-           t->Edges[ind2].Node2 =
-               &t->Nodes[OD_TVRef(t->Edges[ind2].Hnode)];
-           ind2++;
+    for (v = agfstnode(g); v; v = agnxtnode(g, v)) 
+       {
+               float minedgelength=0;
+               float maxedgelength=0;
+               //set node TV reference
+               for (e=agfstout(g, v); e; e = agnxtout(g, e)) 
+               {
+                       t->Edges[ind2].Node1 =
+                               &t->Nodes[OD_TVRef(t->Edges[ind2].Tnode)];
+                       t->Edges[ind2].Node2 =
+                               &t->Nodes[OD_TVRef(t->Edges[ind2].Hnode)];
+                       ind2++;
 
-       }
-       ind++;
+               }
+               ind++;
     }
     t->Nodecount = ind;
     t->Edgecount = ind2;
@@ -243,6 +272,13 @@ static float set_gl_dot_size(topview * t)
 
 }
 
+float calcfontsize(float totaledgelength,int totallabelsize,int edgecount,int totalnodecount)
+{
+       float avglength=totaledgelength/(float)edgecount;
+       float avglabelsize=totallabelsize/(float)totalnodecount;
+       return avglength/ avglabelsize;
+
+}
 static int begintopviewnodes(Agraph_t* g)
 {
        switch (view->defaultnodeshape)
@@ -362,8 +398,7 @@ static void drawtopviewedges(Agraph_t * g)
 
     glBegin(GL_LINES);
     set_topview_options();
-    for (ind = 0; ((ind < view->Topview->Edgecount) && view->drawedges);
-        ind++) {
+    for (ind = 0; ((ind < view->Topview->Edgecount) && view->drawedges);ind++) {
        if (((view->Topview->Edges[ind].x1 / view->zoom * -1 >
              view->clipX1)
             && (view->Topview->Edges[ind].x1 / view->zoom * -1 <
@@ -704,9 +739,8 @@ static int draw_topview_label(topview_node * v, float zdepth)
     float ddy = 0;
     if (!v->Label)
        return 0;
-    if ((view->zoom * -1 / v->degree / v->zoom_factor) > 2)
-       return 0;
-    if ((v->distorted_x / view->zoom * -1 > view->clipX1)
+
+       if ((v->distorted_x / view->zoom * -1 > view->clipX1)
        && (v->distorted_x / view->zoom * -1 < view->clipX2)
        && (v->distorted_y / view->zoom * -1 > view->clipY1)
        && (v->distorted_y / view->zoom * -1 < view->clipY2)) {
@@ -716,12 +750,21 @@ static int draw_topview_label(topview_node * v, float zdepth)
                                1) *
                            (double) 3) : (float) (log((double) v->degree +
                                                       (double) 0.5) *
-                                                  (double) 3)*15;
+                                                          (double) 3)*view->FontSize;
+//     fs=view->FontSize;
        fs = fs * v->zoom_factor;
        if (OD_Selected(v->Node) == 1) {
            ddx = dx;
            ddy = dy;
        }
+       if ((view->FontSize/view->zoom*-1) < 2)
+               return 0;
+
+
+
+       if ((view->FontSize/view->zoom*-1) > 10)
+               fs= 10;
+
 
        fontSize((int) fs);
        if ((log((float) v->degree) * -0.6 * view->zoom) > 0)
@@ -733,9 +776,10 @@ static int draw_topview_label(topview_node * v, float zdepth)
            fontColorA((float) log((double) v->degree + (double) 1),
                       view->penColor.G, view->penColor.B, 1);
 
+//     fontColorA(0,0,0,1);
        fontDrawString((int) (v->distorted_x - ddx),
                       (int) (v->distorted_y - ddy), v->Label,
-                      (int) (fs * strlen(v->Label)));
+                      (int) (fs * strlen(v->Label)*0.7));
 
        return 1;
     } else
index c280c342fa8079081d2a8f41da30a1e8a9440382..770c69c4eb1e7ed0191bd130374d8b7a8fe1c943 100755 (executable)
@@ -31,5 +31,6 @@ int set_update_required(topview * t);
 int move_TVnodes();
 void local_zoom(topview * t);
 void originate_distorded_coordinates(topview * t);
+float calcfontsize(float totaledgelength,int totallabelsize,int edgecount,int totalnodecount);
 
 #endif