# 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 if 'vertex_colors' not in self._options: if self._options['partition'] is not None: from sage.plot.colors import rainbow from sage.plot.colors import rainbow,rgbcolor partition = self._options['partition'] l = len(partition) R = rainbow(l) for i in vertex_colors: pos += [self._pos[j] for j in vertex_colors[i]] colors += [i]*len(vertex_colors[i]) # If all the vertices have not been assigned a color if len(self._pos)!=len(pos): from sage.plot.colors import rainbow,rgbcolor vertex_colors_rgb=[rgbcolor(c) for c in vertex_colors] for c in rainbow(len(vertex_colors)+1): if rgbcolor(c) not in vertex_colors_rgb: break leftovers=[j for j in self._pos.values() if j not in pos] pos+=leftovers colors+=[c]*len(leftovers) if self._arcdigraph: self._plot_components['vertices'] = [circle(pos[i], self._vertex_radius, fill=True, facecolor=colors[i]) for i in range(len(pos))] else:
• ## sage/plot/colors.py

`diff -r 8c12696efac8 -r 05e6bc8289a1 sage/plot/colors.py`
 a sage: rgbcolor('purple') (0.5, 0.0, 1.0) sage: rgbcolor('#0033ea') (0.0, 0.19921875, 0.9140625) (0.0, 0.20..., 0.917...) sage: rgbcolor((1,1/2,1/3)) (1.0, 0.5, 0.33333333333333331) """ if isinstance(c, str): if len(c) == 7 and c[0] == '#':  # html hex color # we use Integer instead of 0x eval for security reasons return tuple([int(c[i:i+2], base=16)/float(256) for i in [1,3,5]]) return tuple([int(c[i:i+2], base=16)/float(255) for i in [1,3,5]]) try: return colors[c] except KeyError: sage: Color(0.5,0,1) RGB color (0.5, 0.0, 1.0) sage: Color('#8000ff') RGB color (0.5, 0.0, 0.99609375) RGB color (0.50..., 0.0, 1.0) """ if g is None and b is None: self.__rgb = rgbcolor(r) EXAMPLES:: sage: Color('#8000ff').__repr__() 'RGB color (0.5, 0.0, 0.99609375)' 'RGB color (0.50..., 0.0, 1.0)' """ return "RGB color %s"%(self.__rgb,) EXAMPLES:: sage: Color('#8000ff').rgb() (0.5, 0.0, 0.99609375) (0.50..., 0.0, 1.0) """ return self.__rgb