]> granicus.if.org Git - graphviz/commitdiff
edge color themes
authorarif <devnull@localhost>
Fri, 8 May 2009 19:54:31 +0000 (19:54 +0000)
committerarif <devnull@localhost>
Fri, 8 May 2009 19:54:31 +0000 (19:54 +0000)
cmd/smyrna/gui/topviewsettings.c
cmd/smyrna/smyrnadefs.h
cmd/smyrna/viewport.c
cmd/smyrna/viewport.h

index f49cb23239cabe62725c6c1d50edf0fb1b970b24..ce5e7b7cd7e5cb28d36f00d31cf9785f73c263a7 100644 (file)
@@ -23,8 +23,8 @@ void on_settingsOKBtn_clicked(GtkWidget * widget, gpointer user_data)
 {
     update_graph_from_settings(view->g[view->activeGraph]);
     set_viewport_settings_from_template(view, view->g[view->activeGraph]);
-    gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
-
+       settvcolorinfo(view->g[view->activeGraph],view->Topview);
+       gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
 }
 
 void on_settingsCancelBtn_clicked(GtkWidget * widget, gpointer user_data)
@@ -254,10 +254,12 @@ int load_settings_from_graph(Agraph_t * g)
     set_color_button_widget("highlightededgecolor", "settingsColorBtn7");
     set_color_button_widget("selectednodecolor", "settingsColorBtn8");
     set_color_button_widget("selectededgecolor", "settingsColorBtn9");
-    set_color_button_widget("topologicaltopviewfinestcolor",
-                                        "settingsColorBtn9");
-    set_color_button_widget("topologicaltopviewcoarsestcolor",
+       set_color_button_widget("defaultnodecolor","DefaultNodeCbtn");
+       set_color_button_widget("defaultedgecolor","DefaultEdgeCbtn");
+
+       set_color_button_widget("topologicaltopviewfinestcolor",
                                         "settingsColorBtn9");
+    set_color_button_widget("topologicaltopviewcoarsestcolor","settingsColorBtn9");
 
     set_color_button_widget("topologicalfisheyefinestcolor",
                            "settingsColorBtn10");
@@ -268,8 +270,6 @@ int load_settings_from_graph(Agraph_t * g)
 
     set_checkbox_widget("bordervisible", "settingsChkBox2");
     set_checkbox_widget("gridvisible", "settingsChkBox3");
-    set_checkbox_widget("randomizenodecolors", "settingsChkBox4");
-    set_checkbox_widget("randomizeedgecolors", "settingsChkBox5");
 
        set_checkbox_widget("drawnodes", "settingsChkBox5-1");
        set_checkbox_widget("drawedges", "settingsChkBox5-2");
@@ -282,6 +282,9 @@ int load_settings_from_graph(Agraph_t * g)
        set_color_button_widget("nodelabelcolor","nodelabelcolor");
        set_color_button_widget("edgelabelcolor","edgelabelcolor");
        set_text_widget("nodelabelattribute","labelnodeattribute");
+       set_text_widget("edgecolorattribute","edgecolortxt");
+
+
        set_text_widget("edgelabelattribute","labeledgeattribute");
        set_checkbox_widget("labelwithdegree", "labelwithdegree");
     set_spinbtn_widget("labelnumberofnodes","labelzoomfactor");
@@ -357,6 +360,21 @@ int load_settings_from_graph(Agraph_t * g)
                                 atoi(buf));
 
        }
+    /*Color theme*/
+    buf = agget(view->g[view->activeGraph], "colortheme");
+    if (!buf)
+       buf = agget(view->default_attributes, "colortheme");
+    if (buf)
+       {
+               /*select the right item in combo box */
+               gtk_combo_box_set_active((GtkComboBox *)
+                                glade_xml_get_widget(xml,
+                                                     "colorthemecb"),
+                                atoi(buf));
+
+       }
+
+
 
     /*Node Shape Combo, 0:opengl dots, 1:circle ,2:box */
     buf = agget(view->g[view->activeGraph], "defaultselectionmethod");
@@ -408,6 +426,12 @@ int update_graph_from_settings(Agraph_t * g)
     get_color_button_widget_to_attribute("selectededgecolor",
                                         "settingsColorBtn9", g);
 
+
+    get_color_button_widget_to_attribute("defaultnodecolor","DefaultNodeCbtn", g);
+    get_color_button_widget_to_attribute("defaultedgecolor","DefaultEdgeCbtn", g);
+
+
+
     get_color_button_widget_to_attribute("topologicalfisheyefinestcolor",
                                         "settingsColorBtn10", g);
     get_color_button_widget_to_attribute("topologicalfisheyecoarsestcolor",
@@ -418,10 +442,6 @@ int update_graph_from_settings(Agraph_t * g)
     get_checkbox_widget_to_attribute("bordervisible", "settingsChkBox2",
                                     g);
     get_checkbox_widget_to_attribute("gridvisible", "settingsChkBox3", g);
-    get_checkbox_widget_to_attribute("randomizenodecolors",
-                                    "settingsChkBox4", g);
-    get_checkbox_widget_to_attribute("randomizeedgecolors",
-                                    "settingsChkBox5", g);
 
     get_checkbox_widget_to_attribute("drawnodes",
                                     "settingsChkBox5-1", g);
@@ -439,6 +459,8 @@ int update_graph_from_settings(Agraph_t * g)
        get_text_widget_to_attribute("nodelabelattribute","labelnodeattribute",g);
        get_text_widget_to_attribute("edgelabelattribute","labeledgeattribute",g);
        
+       get_text_widget_to_attribute("edgecolorattribute","edgecolortxt",g);
+
        get_checkbox_widget_to_attribute("labelwithdegree", "labelwithdegree", g);
     get_spinbtn_widget_to_attribute("labelnumberofnodes","labelzoomfactor", g);
        get_checkbox_widget_to_attribute("shownodelabels", "labelshownodes", g);
@@ -498,6 +520,8 @@ int update_graph_from_settings(Agraph_t * g)
 
        get_combobox_widget_to_attribute("defaultnodeshape","settingscombobox1", g)     ;
        get_combobox_widget_to_attribute("defaultselectionmethod","settingscombobox2", g)       ;
+       get_combobox_widget_to_attribute("colortheme","colorthemecb", g)        ;
+
        return 1;
 }
 
index c84b67bcae6f926709ed84101a55634054789745..574b98253a56374203320b7b57841ad06553c448 100644 (file)
 #include "windows.h"
 //#include "gltexfont.h"
 //#define       SMYRNA_GLADE "C:/Projects/graphviz2/share/gui/smyrna.glade"
-#define        SMYRNA_ATTRS "c:/graphviz-ms/share/gui/attrs.txt"
+#define        SMYRNA_ATTRS "c:/graphviz-ms/graphviz2/share/gui/attrs.txt"
 #endif
 #ifdef _WIN32
-#define SMYRNA_GLADE "c:/graphviz-ms/share/gui/smyrna.glade"
+#define SMYRNA_GLADE "c:/graphviz-ms/graphviz2/share/gui/smyrna.glade"
 #define GTKTOPVIEW_ATTRS "c:/graphviz-ms/share/gui/attrs.txt"
-#define DEFAULT_ATTRIBUTES_TEMPLATE_DOT_FILE   "c:/graphviz-ms/share/gui/attr_template.dot"
+#define DEFAULT_ATTRIBUTES_TEMPLATE_DOT_FILE   "c:/graphviz-ms/graphviz2/share/gui/attr_template.dot"
 // #else
 // using -DGTKTOPVIEW_GLADE from Makefile.am and configure.ac
 // using -DGTKTOPVIEW_ATTRS from Makefile.am and configure.ac
@@ -96,6 +96,19 @@ typedef struct {
 } RGBColor;
 
 #define MAX_BTN_CNT 50
+typedef struct{
+       float perc;
+       RGBColor c;
+       int smooth;
+
+}colorschema;
+
+typedef struct{
+       int schemacount;
+       colorschema* s;
+}colorschemaset;
+
+
 
 typedef enum { 
     VT_NONE,
@@ -265,6 +278,7 @@ typedef struct {
     float x2;
     float y2;
     float z2;
+       float length;
     topview_node *Node1; //Tail
     topview_node *Node2; //Head
     RGBColor Color;
@@ -311,7 +325,7 @@ typedef struct {
        int picked_node_count;
        graph_data Graphdata;
        int maxnodedegree;
-
+       float maxedgelen;
 } topview;
 
 enum {
@@ -532,6 +546,8 @@ typedef struct _ViewInfo
        md5_byte_t final_key[16] ;      /*md5 result right before graph is saved*/
        char* initFileName;     //file name from command line
        int initFile;
+       colorschemaset* colschms;
+
 
 } ViewInfo;
 
index 08b2a4bda23df667b1960054d04f17ca7ee278ae..4e24e31c469ed558a0ddf8d6e3653ea97dd605ad 100755 (executable)
@@ -47,7 +47,6 @@ ViewInfo *view;
 /* these two global variables should be wrapped in something else */
 GtkMessageDialog *Dlg;
 int respond;
-
 #ifdef UNUSED
 static int mapbool(char *p)
 {
@@ -303,15 +302,8 @@ set_viewport_settings_from_template(ViewInfo * view, Agraph_t * g)
        view->labelnumberofnodes=atof(get_attribute_value ("labelnumberofnodes", view, g));
        view->labelshownodes=atoi(get_attribute_value ("shownodelabels", view, g));
        view->labelshowedges=atoi(get_attribute_value ("showedgelabels", view, g));
+       view->colschms=create_color_theme(atoi(get_attribute_value ("colortheme", view, g)));
 
-
-
-
-       
-
-
-//FIXME: I don't think an openGL function can be called before it
-  //     is initialized.
        if (view->graphCount > 0)
                glClearColor(view->bgColor.R, view->bgColor.G, view->bgColor.B, view->bgColor.A);       //background color
 }
@@ -470,6 +462,8 @@ void init_viewport(ViewInfo * view)
        view->Topview->Graphdata.selectedEdges=0;
        view->Topview->Graphdata.selectedEdgesCount=0;
        view->Topview->Graphdata.selectedNodes=0;
+       view->colschms=NULL;
+
 
 
        //create fontset
@@ -657,7 +651,6 @@ static Agraph_t *loadGraph(char *filename)
     }
        load_graph_params(g);
        view->Topview->Graphdata.GraphFileName = strdup (filename);
-       preparetopview(g, view->Topview);
        return g;
 }
 #ifdef UNUSED
@@ -689,6 +682,7 @@ int add_graph_to_viewport_from_file(char *fileName)
        load_settings_from_graph(view->g[view->activeGraph]);
        update_graph_from_settings(view->g[view->activeGraph]);
     set_viewport_settings_from_template(view, view->g[view->activeGraph]);
+       update_topview(graph, view->Topview,1);
        fill_key(view->orig_key,get_md5_key(graph));
     expose_event(view->drawing_area, NULL, NULL);
 
@@ -1044,5 +1038,150 @@ int apply_gvpr(Agraph_t* g,char* prog)
        Agraph_t* a=exec_gvpr(prog,g);
 #endif
 }
+float interpol(float minv,float maxv,float minc,float maxc,float x)
+{
+       return ((x-minv)*(maxc-minc)/(maxv-minv)+minc);
+}
+void getcolorfromschema(colorschemaset* sc,float l,float maxl,RGBColor* 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;
+       }
+
+       if (sc->s[ind].smooth)
+       {
+               c->R=interpol(sc->s[ind-1].perc,sc->s[ind].perc,sc->s[ind-1].c.R,sc->s[ind].c.R,percl);
+               c->G=interpol(sc->s[ind-1].perc,sc->s[ind].perc,sc->s[ind-1].c.G,sc->s[ind].c.G,percl);
+               c->B=interpol(sc->s[ind-1].perc,sc->s[ind].perc,sc->s[ind-1].c.B,sc->s[ind].c.B,percl);
+       }
+       else
+       {
+               c->R=sc->s[ind].c.R;
+               c->G=sc->s[ind].c.G;
+               c->B=sc->s[ind].c.B;
+       }
+}
+static void set_color_theme_color(colorschemaset* sc,char** colorstr,int colorcnt,int smooth)
+{
+       int ind=0;
+    gvcolor_t cl;
+       float av_perc;
+       av_perc=100.00/(float)(colorcnt-1);
+       for (ind; 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;
+       }
+
+
+
 
 
+}
+
+/*typedef struct{
+       float perc;
+       RGBColor c;
+       int smooth;
+
+}colorschema;
+
+typedef struct{
+       int schemacount;
+       colorschema* s;
+}colorschemaset; */
+
+void clear_color_theme (colorschemaset* cs)
+{
+       free(cs->s);
+       free(cs);
+}
+
+
+
+colorschemaset* create_color_theme(int themeid)
+{
+       char **colors;
+       colorschemaset* s=malloc(sizeof(colorschemaset));
+
+       if (view->colschms)
+               clear_color_theme (view->colschms);
+       s->schemacount=4;
+       s->s=malloc(sizeof(colorschema)*4);
+
+
+       colors=malloc(sizeof(char*)*4);
+
+
+       switch (themeid)
+       {
+               case 0:         //deep blue
+
+                       colors[0]=strdup("#C8CBED");
+                       colors[1]=strdup("#9297D3");
+                       colors[2]=strdup("#blue");
+                       colors[3]=strdup("#2C2E41");
+                       set_color_theme_color(s,colors,s->schemacount,1);
+                       break;
+               case 1:         //all pastel
+                       colors[0]=strdup("#EBBE29");
+                       colors[1]=strdup("#D58C4A");
+                       colors[2]=strdup("#74AE09");
+                       colors[3]=strdup("#893C49");
+                       set_color_theme_color(s,colors,s->schemacount,1);
+                       break;
+               case 2:         //magma
+                       colors[0]=strdup("#E0061E");
+                       colors[1]=strdup("#F0F143");
+                       colors[2]=strdup("#95192B");
+                       colors[3]=strdup("#EB712F");
+                       set_color_theme_color(s,colors,s->schemacount,1);
+                       break;
+               case 3:         //rain forest
+                       colors[0]=strdup("#1E6A10");
+                       colors[1]=strdup("#2ABE0E");
+                       colors[2]=strdup("#AEDD39");
+                       colors[3]=strdup("#5EE88B");
+                       set_color_theme_color(s,colors,s->schemacount,1);
+                       break;
+       }
+       free (colors[0]);
+       free (colors[1]);
+       free (colors[2]);
+       free (colors[3]);
+       free (colors);
+       return s;
+}
+
+
+void test_color_pallete()
+{
+       int ind=0;
+       float xGAP=5;
+       float yGAP=80;
+       float x=50;
+       float y=50;
+       RGBColor c;
+       for (ind=0;ind < 350;ind ++)
+       {
+               getcolorfromschema(view->colschms,ind,350,&c);
+               x=ind*xGAP;
+               glBegin(GL_POLYGON);
+               glColor3f(c.R,c.G,c.B);
+                       glVertex3f(x,y,0.0);
+                       glVertex3f(x+xGAP,y,0.0);
+                       glVertex3f(x+xGAP,y+yGAP,0.0);
+                       glVertex3f(x,y+yGAP,0.0);
+               glEnd();
+       }
+}
index fb4bad281dd32722c57f380e8216d80eec74d831..3161de1ac9315dfd025e5de81437fb9789f4a2b3 100755 (executable)
@@ -40,6 +40,8 @@ void move_nodes(Agraph_t * g);
 void please_wait(void);
 void please_dont_wait(void);
 extern md5_byte_t* get_md5_key(Agraph_t* graph);
+colorschemaset* create_color_theme(int themeid);
+extern void getcolorfromschema(colorschemaset* sc,float l,float maxl,RGBColor* c);
 
 
  /* helper functions */