]> granicus.if.org Git - graphviz/commitdiff
Make sure that if optional attributes are defined in a gvpr script, the cached
authorerg <devnull@localhost>
Thu, 2 Sep 2010 22:01:00 +0000 (22:01 +0000)
committererg <devnull@localhost>
Thu, 2 Sep 2010 22:01:00 +0000 (22:01 +0000)
attribute pointers are updated;
fix incorrect implementation of edge colors if schema is not smooth;
fix problem choosing color for max length edges;
since smooth is a property of a color schema and not each individual color, put
the parameter into the schema struct;
reset edge code to use alpha;
change code to use alpha even if object explicitly provides its color.

cmd/smyrna/gui/frmobjectui.c
cmd/smyrna/gvprpipe.c
cmd/smyrna/smyrnadefs.h
cmd/smyrna/topviewfuncs.c
cmd/smyrna/viewport.c
cmd/smyrna/viewport.h

index 8975c70b581915219eca855c397ec434f1210739..91b52fb88d77b589fcf947c4e43729fcee9e02c8 100644 (file)
@@ -806,7 +806,7 @@ static void gvpr_select(char *attr, char *regex_str, int objType)
 
     if (objType == AGNODE)
        sfprintf(sf, "N[%s==\"%s\"]{selected = \"1\"}", attr, regex_str);
-    if (objType == AGEDGE)
+    else if (objType == AGEDGE)
        sfprintf(sf, "E[%s==\"%s\"]{selected = \"1\"}", attr, regex_str);
 
 
index 5f98dd5bd740a566d7cfccd45191648543057913..64f9b6c937cff944ce844bdc957622e1c73317f7 100644 (file)
@@ -75,7 +75,6 @@ static ssize_t errfn(void *sp, const char *buf, size_t nbyte, void *dp)
 {
     return 0;
 }
-#endif
 static void set_refresh(ViewInfo* v,char* script)
 {
     if(strstr(script,"pos"))
@@ -89,6 +88,7 @@ static void set_refresh(ViewInfo* v,char* script)
     if(strstr(script,"selected"))
        v->refresh.selection=1;
 }
+#endif
 
 int run_gvpr(Agraph_t * srcGraph, int argc, char *argv[])
 {
@@ -123,7 +123,8 @@ int run_gvpr(Agraph_t * srcGraph, int argc, char *argv[])
        }
     } else 
     { 
-       set_refresh(view,argv[1]);
+       /* set_refresh(view,argv[1]); */
+       updateRecord (srcGraph);
         update_graph_from_settings(srcGraph);
 //     update_topview(srcGraph, view->Topview, 0);
     }
index ae41cb989215aaac6918a3d7fdc3b10ad5a31808..f0596308dddee067c04a22197e30f10fefcd53ca 100644 (file)
@@ -171,7 +171,6 @@ typedef struct
     typedef struct {
        float perc;
        glCompColor c;
-       int smooth;
 
     } colorschema;
 
@@ -189,12 +188,11 @@ typedef struct
 
 
     typedef struct {
-       int schemacount;
+       int schemacount;       /* number of colors */
+       int smooth;            /* if true, interpolate */
        colorschema *s;
     } colorschemaset;
 
-
-
     typedef enum {
        VT_NONE,
        VT_XDOT,
index b22df20ae3f0335baec9f623d989bf97fb060c9f..1b4b77b4f17bbe3020746f6257daf4181b0c0536 100644 (file)
@@ -172,6 +172,7 @@ static int visible(Agsym_t* attr, void* obj)
     }
     else return 1;
 }
+
 static int object_color(void* obj,glCompColor* c)
 {
     gvcolor_t cl;
@@ -189,24 +190,22 @@ static int object_color(void* obj,glCompColor* c)
        Alpha=getAttrFloat(g,objg,"defaultedgealpha",1);
        vis = GE_visible (objg);
     }
-    if(objType==AGNODE) {
+    else if(objType==AGNODE) {
        Alpha=getAttrFloat(g,objg,"defaultnodealpha",1);
        vis = GN_visible (objg);
     }
     if (!visible(vis,obj))
        return 0;
 
-    /*get edge's color attribute */
     setColorScheme (agget (obj, "colorscheme"));
-    bf=getAttrStr(g,obj,"color",NULL);
-    if((bf)&&(strlen(bf)>0))
-    {
+    /*get objects's color attribute */
+    bf = getAttrStr(g,obj,"color",NULL);
+    if(bf && (*bf)) {
        colorxlate(bf, &cl, RGBA_DOUBLE);
-       c->R=cl.u.RGBA[0];
-       c->G=cl.u.RGBA[1];
-       c->B=cl.u.RGBA[2];
-       c->A=cl.u.RGBA[3];
-
+       c->R = cl.u.RGBA[0];
+       c->G = cl.u.RGBA[1];
+       c->B = cl.u.RGBA[2];
+       c->A = cl.u.RGBA[3]*Alpha;
     }
     else
     {
@@ -215,20 +214,18 @@ static int object_color(void* obj,glCompColor* c)
        else
        {
            colorxlate(agget(g, "defaultnodecolor"),&cl, RGBA_DOUBLE);
-               c->R=cl.u.RGBA[0];
-           c->G=cl.u.RGBA[1];
-           c->B=cl.u.RGBA[2];
-           c->A=cl.u.RGBA[3];
+               c->R = cl.u.RGBA[0];
+           c->G = cl.u.RGBA[1];
+           c->B = cl.u.RGBA[2];
+           c->A = cl.u.RGBA[3];
        }
-       c->A=c->A*Alpha;
+       c->A = c->A*Alpha;
 
     }
     return return_value;
 }
 
 
-
-
 /*
        draws multi edges , single edges
        this function assumes     glBegin(GL_LINES) has been called 
@@ -427,9 +424,6 @@ static void renderSelectedEdges(Agraph_t * g)
        }
     }
 
-
-
-
     glBegin(GL_LINES);
     for (v = agfstnode(g); v; v = agnxtnode(g, v)) 
     {
@@ -639,8 +633,7 @@ static void renderEdgesFn (Agraph_t * g, edgefn ef, int skipSelected)
            if ((ND_visible(agtail(e))==0) || (ND_visible(aghead(e))==0))
                continue;
 
-           if(!object_color(e,&c))
-           {
+           if(!object_color(e,&c)) {
                ED_visible(e) = 0;
                continue;
            }
@@ -669,7 +662,7 @@ static void edge_seg (Agraph_t* g, Agedge_t* e, glCompColor c)
     glCompPoint posT;  /*Tail position*/
     glCompPoint posH;  /*Head position*/
 
-    glColor4f(c.R,c.G,c.B,1);     
+    glColor4f(c.R,c.G,c.B,c.A);           
     posT=getPointFromStr(agxget(agtail(e), pos_attr));
     posH=getPointFromStr(agxget(aghead(e), pos_attr));
     draw_edge(&posT,&posH,getEdgeLength(e),0);
@@ -682,7 +675,7 @@ static void edge_spline (Agraph_t* g, Agedge_t* e, glCompColor c)
     Agsym_t* pos_attr_e = GE_pos(g);
     xdot * x;
 
-    glColor4f(c.R,c.G,c.B,1);     
+    glColor4f(c.R,c.G,c.B,c.A);           
     x = makeXDotSpline (agxget(e,pos_attr_e));
     if (x) {
        draw_xdot(x,0);
index ff50ab93146fe9d6100a9b6fe835d82e4a57b41d..3f13027adadc60b44fea7c49150129f02a128051 100755 (executable)
@@ -643,6 +643,19 @@ int add_graph_to_viewport_from_file(char *fileName)
     return add_graph_to_viewport(graph, fileName);
 }
 
+/* updateRecord:
+ * Update fields which may be added dynamically.
+ */
+void updateRecord (Agraph_t* g)
+{
+    GN_size(g) = agattr (g, AGNODE, "size", 0);
+    GN_visible(g) = agattr (g, AGNODE, "visible", 0);
+    GN_selected(g) = agattr (g, AGNODE, "selected", 0);
+
+    GE_pos(g)=agattr(g,AGEDGE,"pos",0);
+    GE_visible(g) = agattr (g, AGEDGE, "visible", 0);
+    GE_selected(g) = agattr (g, AGEDGE, "selected", 0);
+}
 
 /* graphRecord:
  * add graphRec to graph if necessary.
@@ -650,6 +663,7 @@ int add_graph_to_viewport_from_file(char *fileName)
  * We assume the graph has attributes nodelabelattribute, edgelabelattribute,
  * nodelabelcolor and edgelabelcolor from template.dot.
  * We assume nodes have pos attributes. 
+ * Only size, visible, selected and edge pos may or may not be defined.
  */
 static void
 graphRecord (Agraph_t* g)
@@ -660,18 +674,12 @@ graphRecord (Agraph_t* g)
     GG_edgelabelcolor(g) = agattr (g, AGRAPH, "edgelabelcolor", 0);
 
     GN_pos(g) = agattr (g, AGNODE, "pos", 0);
-    GN_size(g) = agattr (g, AGNODE, "size", 0);
-    GN_visible(g) = agattr (g, AGNODE, "visible", 0);
-    GN_selected(g) = agattr (g, AGNODE, "selected", 0);
     GN_labelattribute(g) = agattr (g, AGNODE, agget(g,"nodelabelattribute"), 0);
 
-    GE_pos(g)=agattr(g,AGEDGE,"pos",0);
-    GE_visible(g) = agattr (g, AGEDGE, "visible", 0);
-    GE_selected(g) = agattr (g, AGEDGE, "selected", 0);
     GE_labelattribute(g) = agattr (g, AGEDGE, agget(g,"edgelabelattribute"), 0);
-}
-
 
+    updateRecord (g);
+}
 
 void refreshViewport(int doClear)
 {
@@ -1073,14 +1081,14 @@ void getcolorfromschema(colorschemaset * sc, float l, float maxl,
                        glCompColor * c)
 {
     int ind;
-    /* float cuml=0.00; */
-    float percl = l / maxl * 100.00;
-    for (ind = 0; ind < sc->schemacount; ind++) {
-       if (percl < sc->s[ind].perc)
-           break;
-    }
+    float percl = l / maxl;
 
-    if (sc->s[ind].smooth) {
+    if (sc->smooth) {
+       /* For smooth schemas, s[0].perc = 0, so we start with ind=1 */
+       for (ind = 1; ind < sc->schemacount-1; ind++) {
+           if (percl < sc->s[ind].perc)
+               break;
+       }
        c->R =
            interpol(sc->s[ind - 1].perc, sc->s[ind].perc,
                     sc->s[ind - 1].c.R, sc->s[ind].c.R, percl);
@@ -1090,13 +1098,18 @@ void getcolorfromschema(colorschemaset * sc, float l, float maxl,
        c->B =
            interpol(sc->s[ind - 1].perc, sc->s[ind].perc,
                     sc->s[ind - 1].c.B, sc->s[ind].c.B, percl);
-       c->A = 1;
-    } else {
+    }
+    else {
+       for (ind = 0; ind < sc->schemacount-1; ind++) {
+           if (percl < sc->s[ind].perc)
+               break;
+       }
        c->R = sc->s[ind].c.R;
        c->G = sc->s[ind].c.G;
        c->B = sc->s[ind].c.B;
-       c->A = 1;
     }
+
+    c->A = 1;
 }
 
 /* set_color_theme_color:
@@ -1108,15 +1121,29 @@ static void set_color_theme_color(colorschemaset * sc, char **colorstr, int smoo
     int colorcnt = sc->schemacount;
     gvcolor_t cl;
     float av_perc;
-    av_perc = 100.00 / (float) (colorcnt - 1);
-    for (ind = 0; ind < colorcnt; ind++) {
-       colorxlate(colorstr[ind], &cl, RGBA_DOUBLE);
-       sc->s[ind].c.R = cl.u.RGBA[0];
-       sc->s[ind].c.G = cl.u.RGBA[1];
-       sc->s[ind].c.B = cl.u.RGBA[2];
-       sc->s[ind].c.A = cl.u.RGBA[3];
-       sc->s[ind].perc = ind * av_perc;
-       sc->s[ind].smooth = smooth;
+
+    sc->smooth = smooth;
+    if (smooth) {
+       av_perc = 1.0 / (float) (colorcnt-1);
+       for (ind = 0; ind < colorcnt; ind++) {
+           colorxlate(colorstr[ind], &cl, RGBA_DOUBLE);
+           sc->s[ind].c.R = cl.u.RGBA[0];
+           sc->s[ind].c.G = cl.u.RGBA[1];
+           sc->s[ind].c.B = cl.u.RGBA[2];
+           sc->s[ind].c.A = cl.u.RGBA[3];
+           sc->s[ind].perc = ind * av_perc;
+       }
+    }
+    else {
+       av_perc = 1.0 / (float) (colorcnt);
+       for (ind = 0; ind < colorcnt; ind++) {
+           colorxlate(colorstr[ind], &cl, RGBA_DOUBLE);
+           sc->s[ind].c.R = cl.u.RGBA[0];
+           sc->s[ind].c.G = cl.u.RGBA[1];
+           sc->s[ind].c.B = cl.u.RGBA[2];
+           sc->s[ind].c.A = cl.u.RGBA[3];
+           sc->s[ind].perc = (ind+1) * av_perc;
+       }
     }
 }
 
index 262787546149388cb7fd28213422c0b918721143..9215bb300d5c75df9663efe50dafdc02a317eecc 100755 (executable)
@@ -53,6 +53,7 @@ extern "C" {
     void move_nodes(Agraph_t * g);
     extern void getcolorfromschema(colorschemaset * sc, float l,
                                   float maxl, glCompColor * c);
+    void updateRecord (Agraph_t* g);
 
 
     /* helper functions */