Make colors based on hash permanent.

In Python 3 hash() result is only consistent within a process, so we
have to use hashlib.
This commit is contained in:
Sergey Vartanov 2020-08-26 22:56:33 +03:00
parent b84001a5aa
commit e8486ee0b8

View file

@ -1,5 +1,7 @@
import numpy as np import numpy as np
from hashlib import sha256
from datetime import datetime from datetime import datetime
from typing import Any, Dict, List, Optional, Set from typing import Any, Dict, List, Optional, Set
@ -77,7 +79,7 @@ def get_user_color(text: str, seed: str):
""" """
if text == "": if text == "":
return "000000" return "000000"
rgb = hex(abs(hash(seed + text)))[-6:] rgb = sha256((seed + text).encode("utf-8")).hexdigest()[-6:]
r = int(rgb[0:2], 16) r = int(rgb[0:2], 16)
g = int(rgb[2:4], 16) g = int(rgb[2:4], 16)
b = int(rgb[4:6], 16) b = int(rgb[4:6], 16)
@ -629,12 +631,14 @@ class Constructor:
shapes, fill, processed = process.get_icon(tags, self.scheme) shapes, fill, processed = process.get_icon(tags, self.scheme)
if self.mode in ["time", "user-coloring"]:
if not tags:
continue
shapes = ["small"]
if self.mode == "user-coloring": if self.mode == "user-coloring":
fill = get_user_color(node.user, self.seed) fill = get_user_color(node.user, self.seed)
shapes = ["small"]
if self.mode == "time": if self.mode == "time":
fill = get_time_color(node.timestamp) fill = get_time_color(node.timestamp)
shapes = ["small"]
# for k in tags: # for k in tags:
# if k in processed or self.no_draw(k): # if k in processed or self.no_draw(k):