Separate hue color of scheme by golden angle
issue4257 review12631002
This commit is contained in:
1 parent
6db40b3a4b
commit
4e950814de
6 files changed
+22
-26
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* New color scheme for graph
|
||||
* Replace img_{width,height} by width and height attributes
|
||||
|
||||
Version 3.4.0 - 2014-10-20
|
||||
|
||||
+13
-19
@@ -11,6 +11,7 @@ import subprocess
|
||||
import re
|
||||
import logging
|
||||
import unicodedata
|
||||
import colorsys
|
||||
from functools import partial
|
||||
from tryton.config import CONFIG
|
||||
from tryton.config import TRYTON_ICON, PIXMAPS_DIR
|
||||
@@ -1177,33 +1178,26 @@ def hex2rgb(hexstring, digits=2):
|
||||
return r / top, g / top, b / top
|
||||
|
||||
|
||||
def clamp(minValue, maxValue, value):
|
||||
"""Make sure value is between minValue and maxValue"""
|
||||
if value < minValue:
|
||||
return minValue
|
||||
if value > maxValue:
|
||||
return maxValue
|
||||
return value
|
||||
def highlight_rgb(r, g, b, amount=0.1):
|
||||
h, s, v = colorsys.rgb_to_hsv(r, g, b)
|
||||
return colorsys.hsv_to_rgb(h, s, (v + amount) % 1)
|
||||
|
||||
|
||||
def lighten(r, g, b, amount):
|
||||
"""Return a lighter version of the color (r, g, b)"""
|
||||
return (clamp(0.0, 1.0, r + amount),
|
||||
clamp(0.0, 1.0, g + amount),
|
||||
clamp(0.0, 1.0, b + amount))
|
||||
|
||||
|
||||
def generateColorscheme(masterColor, keys, light=0.06):
|
||||
def generateColorscheme(masterColor, keys, light=0.1):
|
||||
"""
|
||||
Generates a dictionary where the keys match the keys argument and
|
||||
the values are colors derivated from the masterColor.
|
||||
Each color is a lighter version of masterColor separated by a difference
|
||||
given by the light argument.
|
||||
Each color has a value higher then the previous of `light`.
|
||||
Each color has a hue separated from the previous by the golden angle.
|
||||
The masterColor is given in a hex string format.
|
||||
"""
|
||||
r, g, b = hex2rgb(COLOR_SCHEMES.get(masterColor, masterColor))
|
||||
return dict([(key, lighten(r, g, b, light * i))
|
||||
for i, key in enumerate(keys)])
|
||||
h, s, v = colorsys.rgb_to_hsv(r, g, b)
|
||||
if keys:
|
||||
light = min(light, (1. - v) / len(keys))
|
||||
golden_angle = 0.618033988749895
|
||||
return {key: colorsys.hsv_to_rgb((h + golden_angle * i) % 1,
|
||||
s, (v + light * i) % 1) for i, key in enumerate(keys)}
|
||||
|
||||
|
||||
class DBProgress(object):
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#This code is inspired by the pycha project
|
||||
#(http://www.lorenzogil.com/projects/pycha/)
|
||||
from graph import Graph
|
||||
from tryton.common import float_time_to_text
|
||||
from tryton.common import float_time_to_text, highlight_rgb
|
||||
import locale
|
||||
import math
|
||||
import cairo
|
||||
@@ -37,7 +37,7 @@ class Bar(Graph):
|
||||
self.drawRectangle(cr, x, y, w, h)
|
||||
r, g, b = self.colorScheme[bar.yname]
|
||||
if bar.highlight:
|
||||
r, g, b = self.colorScheme['__highlight']
|
||||
r, g, b = highlight_rgb(r, g, b)
|
||||
cr.set_source(self.sourceRectangle(x, y, w, h, r, g, b))
|
||||
cr.fill_preserve()
|
||||
cr.stroke()
|
||||
|
||||
@@ -454,7 +454,7 @@ class Graph(gtk.DrawingArea):
|
||||
color = self.attrs.get('color', 'blue')
|
||||
r, g, b = hex2rgb(COLOR_SCHEMES.get(color, color))
|
||||
maxcolor = max(max(r, g), b)
|
||||
self.colorScheme = generateColorscheme(color, keys + ['__highlight'],
|
||||
self.colorScheme = generateColorscheme(color, keys,
|
||||
maxcolor / (len(keys) or 1))
|
||||
for yfield in self.yfields:
|
||||
if yfield.get('color'):
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#This code is inspired by the pycha project
|
||||
#(http://www.lorenzogil.com/projects/pycha/)
|
||||
from graph import Graph
|
||||
from tryton.common import hex2rgb, float_time_to_text
|
||||
from tryton.common import hex2rgb, highlight_rgb, float_time_to_text
|
||||
import locale
|
||||
import math
|
||||
import cairo
|
||||
@@ -146,7 +146,8 @@ class Line(Graph):
|
||||
point.y * self.area.h + self.area.y,
|
||||
3, 0, 2 * math.pi)
|
||||
cr.stroke()
|
||||
cr.set_source_rgb(*self.colorScheme['__highlight'])
|
||||
cr.set_source_rgb(*highlight_rgb(
|
||||
*self.colorScheme[point.yname]))
|
||||
cr.arc(point.x * self.area.w + self.area.x,
|
||||
point.y * self.area.h + self.area.y,
|
||||
3, 0, 2 * math.pi)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
from graph import Graph, Area
|
||||
import math
|
||||
import cairo
|
||||
from tryton.common import hex2rgb, float_time_to_text
|
||||
from tryton.common import hex2rgb, highlight_rgb, float_time_to_text
|
||||
import locale
|
||||
import tryton.rpc as rpc
|
||||
|
||||
@@ -94,7 +94,7 @@ class Pie(Graph):
|
||||
if bool(int(self.yfields[0].get('fill', 1))):
|
||||
color = self.colorScheme[slice.xname]
|
||||
if slice.highlight:
|
||||
color = self.colorScheme['__highlight']
|
||||
color = highlight_rgb(*color)
|
||||
cr.set_source_rgba(*color)
|
||||
slice.draw(cr, self.centerx, self.centery, self.radius)
|
||||
cr.fill()
|
||||
|
||||
Reference in new issue
Block a user