Ticket #6615: trac_6615-ref.patch

File trac_6615-ref.patch, 3.5 KB (added by rlm, 11 years ago)

depends: sage-4.3.1.alpha1 + #7634

  • sage/graphs/graph_plot.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1250270998 -7200
    # Node ID 05e6bc8289a137ec0437429ec8c97f6e2e2c7051
    # Parent  8c12696efac8fc61440a57262ee6a95150be6ee4
    All the vertices are colored even if vertex_colors did not contain colors for all of them. The first unused color in ranbow() is taken.
    
    There was a small mistake in rgbcolor() where the hexcadecimal values were divided by 256 instead of 255 which lead to "red"!=(1,0,0).
    
    All the colors were wrong and nobody noticed !! :-)
    
    diff -r 8c12696efac8 -r 05e6bc8289a1 sage/graphs/graph_plot.py
    a b  
    258258           
    259259        if 'vertex_colors' not in self._options:
    260260            if self._options['partition'] is not None:
    261                 from sage.plot.colors import rainbow
     261                from sage.plot.colors import rainbow,rgbcolor
    262262                partition = self._options['partition']
    263263                l = len(partition)
    264264                R = rainbow(l)
     
    305305            for i in vertex_colors:
    306306                pos += [self._pos[j] for j in vertex_colors[i]]
    307307                colors += [i]*len(vertex_colors[i])
     308
     309            # If all the vertices have not been assigned a color
     310            if len(self._pos)!=len(pos):
     311                from sage.plot.colors import rainbow,rgbcolor
     312                vertex_colors_rgb=[rgbcolor(c) for c in vertex_colors]
     313                for c in rainbow(len(vertex_colors)+1):
     314                    if rgbcolor(c) not in vertex_colors_rgb:
     315                        break
     316                leftovers=[j for j in self._pos.values() if j not in pos]
     317                pos+=leftovers
     318                colors+=[c]*len(leftovers)
     319
    308320            if self._arcdigraph:
    309321                self._plot_components['vertices'] = [circle(pos[i], self._vertex_radius, fill=True, facecolor=colors[i]) for i in range(len(pos))]
    310322            else:
  • sage/plot/colors.py

    diff -r 8c12696efac8 -r 05e6bc8289a1 sage/plot/colors.py
    a b  
    273273        sage: rgbcolor('purple')
    274274        (0.5, 0.0, 1.0)
    275275        sage: rgbcolor('#0033ea')
    276         (0.0, 0.19921875, 0.9140625)
     276        (0.0, 0.20..., 0.917...)
    277277        sage: rgbcolor((1,1/2,1/3))
    278278        (1.0, 0.5, 0.33333333333333331)
    279279    """
     
    284284    if isinstance(c, str):
    285285        if len(c) == 7 and c[0] == '#':  # html hex color
    286286            # we use Integer instead of 0x eval for security reasons
    287             return tuple([int(c[i:i+2], base=16)/float(256) for i in [1,3,5]])
     287            return tuple([int(c[i:i+2], base=16)/float(255) for i in [1,3,5]])
    288288        try:
    289289            return colors[c]
    290290        except KeyError:
     
    310310            sage: Color(0.5,0,1)
    311311            RGB color (0.5, 0.0, 1.0)
    312312            sage: Color('#8000ff')
    313             RGB color (0.5, 0.0, 0.99609375)
     313            RGB color (0.50..., 0.0, 1.0)
    314314        """
    315315        if g is None and b is None:
    316316            self.__rgb = rgbcolor(r)
     
    324324        EXAMPLES::
    325325
    326326            sage: Color('#8000ff').__repr__()
    327             'RGB color (0.5, 0.0, 0.99609375)'
     327            'RGB color (0.50..., 0.0, 1.0)'
    328328        """
    329329        return "RGB color %s"%(self.__rgb,)
    330330
     
    337337        EXAMPLES::
    338338
    339339            sage: Color('#8000ff').rgb()
    340             (0.5, 0.0, 0.99609375)       
     340            (0.50..., 0.0, 1.0)
    341341        """
    342342        return self.__rgb
    343343