]> git.ipfire.org Git - oddments/collecty.git/blob - src/collecty/colours.py
graphs: Make areas less opaque
[oddments/collecty.git] / src / collecty / colours.py
1 #!/usr/bin/python3
2 ###############################################################################
3 # #
4 # collecty - A system statistics collection daemon for IPFire #
5 # Copyright (C) 2015 IPFire development team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 def _add(colour, amount):
23 """
24 Adds some value to colours
25 """
26 # Parse hex array
27 bytes = bytearray.fromhex(colour.lstrip("#"))
28
29 if not len(bytes) == 3:
30 raise ValueError("Invalid colour: %s" % colour)
31
32 ret = bytearray()
33
34 for byte in bytes:
35 byte = round(byte * amount)
36
37 # Ensure the result is within range
38 byte = min(byte, 255)
39 byte = max(byte, 0)
40
41 # Update the array
42 ret.append(byte)
43
44 return "#%s" % ret.hex()
45
46 def lighten(colour, scale=0.25):
47 """
48 Takes a hexadecimal colour code
49 and brightens the colour.
50 """
51 return _add(colour, scale)
52
53 def darken(colour, scale=0.25):
54 """
55 Takes a hexadecimal colour code
56 and darkens the colour.
57 """
58 return _add(colour, -scale)
59
60 def transparency(colour, scale=0.1):
61 """
62 Adds transparency to the given colour code
63 """
64 return "%s%02X" % (colour, round(0xff * scale))
65
66 BLACK = "#000000"
67 WHITE = "#FFFFFF"
68 GREY = "#9E9E9E"
69 LIGHT_GREY = "#F5F5F5"
70
71 RED = "#F44336"
72 LIGHT_RED = "#CC0033"
73 YELLOW = "#FFEB3B"
74 LIGHT_YELLOW = "#FFFF66"
75 GREEN = "#4CAF50"
76 LIGHT_GREEN = "#8BC34A"
77 BLUE = "#2196F3"
78 LIGHT_BLUE = "#03A9F4"
79
80 AMBER = "#FFC107"
81 BROWN = "#795548"
82 CYAN = "#00BCD4"
83 INDIGO = "#3F51B5"
84 LIME = "#CDDC39"
85 ORANGE = "#FF9800"
86 DEEP_ORANGE = "#FF5722"
87 PINK = "#E91E63"
88 PURPLE = "#9C27B0"
89 DEEP_PURPLE = "#673AB7"
90 TEAL = "#009688"
91
92 COLOUR_OK = LIGHT_GREEN
93 COLOUR_CRITICAL = LIGHT_RED
94 COLOUR_ERROR = COLOUR_CRITICAL
95 COLOUR_WARN = LIGHT_YELLOW
96 COLOUR_TEXT = lighten(BLACK, 0.87) # 87% grey
97
98 PRIMARY = INDIGO
99 ACCENT = PINK
100
101 # Lighten the areas by this factor
102 AREA_OPACITY = 0.75
103 STDDEV_OPACITY = 0.33
104
105 # Receive and transmit
106 COLOUR_RX = RED
107 COLOUR_TX = GREEN
108
109 # I/O
110 COLOUR_READ = GREEN
111 COLOUR_WRITE = RED
112
113 # IPv6 + IPv4
114 COLOUR_IPV6 = INDIGO
115 COLOUR_IPV4 = PINK
116 COLOUR_IPVX = GREY # other
117
118 COLOUR_TCP = INDIGO
119 COLOUR_UDP = YELLOW
120 COLOUR_ICMP = PURPLE
121 COLOUR_IGMP = TEAL
122 COLOUR_UDPLITE = DEEP_ORANGE
123 COLOUR_SCTP = LIGHT_GREEN
124 COLOUR_DCCP = LIGHT_BLUE
125 COLOUR_OTHER = COLOUR_IPVX
126
127 # Processor
128 CPU_USER = LIGHT_GREEN
129 CPU_NICE = BLUE
130 CPU_SYS = RED
131 CPU_WAIT = DEEP_PURPLE
132 CPU_IRQ = ORANGE
133 CPU_SIRQ = YELLOW
134 CPU_STEAL = LIGHT_BLUE
135 CPU_GUEST = PINK
136 CPU_GUEST_NICE = lighten(PINK, 0.8)
137 CPU_IDLE = LIGHT_GREY
138
139 # Memory
140 MEMORY_USED = GREEN
141 MEMORY_BUFFERED = BLUE
142 MEMORY_CACHED = YELLOW
143 MEMORY_SWAP = RED
144 MEMORY_FREE = LIGHT_GREY
145
146 COLOURS_PROTOCOL_STATES = {
147 # General states
148 "NONE" : GREY,
149 "TIME_WAIT" : AMBER,
150
151 # TCP
152 "CLOSE" : BLACK,
153 "CLOSE_WAIT" : lighten(BLACK, 0.25),
154 "ESTABLISHED" : LIGHT_GREEN,
155 "FIN_WAIT" : ORANGE,
156 "LAST_ACK" : PURPLE,
157 "SYN_RECV" : CYAN,
158 "SYN_SENT" : TEAL,
159 "SYN_SENT2" : AMBER,
160
161 # DCCP
162 "CLOSEREQ" : lighten(BLACK, 0.5),
163 "CLOSING" : lighten(BLACK, 0.25),
164 "IGNORE" : WHITE,
165 "INVALID" : RED,
166 "OPEN" : LIGHT_GREEN,
167 "PARTOPEN" : YELLOW,
168 "REQUEST" : CYAN,
169 "RESPOND" : TEAL,
170
171 # SCTP
172 "CLOSED" : BLACK,
173 "COOKIE_ECHOED" : AMBER,
174 "COOKIE_WAIT" : CYAN,
175 "SHUTDOWN_ACK_SENT" : TEAL,
176 "SHUTDOWN_RECD" : PURPLE,
177 "SHUTDOWN_SENT" : LIGHT_BLUE,
178 }