Menu

set color for a particular edge or vertex

2004-09-23
2013-05-29
  • Nobody/Anonymous

    There are methods that allow setting of colors for all vertices and edges in GraphDraw class. Is there an easy mechanism that will allow me to set color for a particular edge or vertex?

    Thanks a lot,

    Phil

     
    • Nobody/Anonymous

      Actually, let me re-phrase a little bit. At the beginning I want all vertices and edges have the same color. Are there any mechanism that will allow me to later change the color of a vertex or an edge to a different color?

      Thanks as always,

      Phil

       
      • Joshua O'Madadhain

        Phil:

        SettableRenderer (the current version) allows you to specify an EdgeColorFunction that can color individual edges however you like.  One easy way to have the color change later is to have the ECF get some feature that indicates the appropriate color from the edge; when this feature's value changes, the color will change.

        The version of SR in the next release will support vertex coloring also.  In the meantime, it's not difficult to hack SR to make this change.

        Joshua

         
        • Nobody/Anonymous

          Josh, I'm not even sure I'd describe it as a hack. Here's the code, roughly (I don't have an API in front of me, so names are slightly wrong).

          SettableRenderer sr = graphDraw.getRenderer();
          VertexColorFunction vcf = new VertexColorFunction() {
                 Color getColor( Vertex v ) {
                    if (v.getUserData("TRIGGERED").equals("YES") {
                       return Color.blue;
                    } else {
                        return Color.red
                    }
                 }
          };
          sr.setVertexColorFunction( vcf );

           
          • Joshua O'Madadhain

            The reason I used the word "hack" is that I thought I remembered that setVertexColorFunction() wasn't a method of the version of SettableRenderer that had been released; my mistake.  You're right: that method (with an appropriate function, of which your code above is a decent example) is all that's needed.  (Warning for people copying the code above: it does contain a few syntax errors, as the author suggested it might.)

            Sorry for the confusion--

            Joshua

             

Log in to post a comment.