From 686de6f55c3c8cac9c68786d9e4414c34987f801 Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Mon, 25 Nov 2024 19:37:33 +0530 Subject: [PATCH] feat: allow hex colors --- neuromllite/GraphVizHandler.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/neuromllite/GraphVizHandler.py b/neuromllite/GraphVizHandler.py index 118fc06..3286b71 100644 --- a/neuromllite/GraphVizHandler.py +++ b/neuromllite/GraphVizHandler.py @@ -14,6 +14,7 @@ from graphviz import Digraph import numpy as np +from PIL import ImageColor engines = { "d": "dot", @@ -526,12 +527,17 @@ def handle_population( shape = self.DEFAULT_POP_SHAPE if properties and "color" in properties: - rgb = properties["color"].split() - color = "#" - for a in rgb: - color = color + "%02x" % int(float(a) * 255) + if properties["color"][0] == "#": + color = properties["color"] + rgb = ImageColor.getcolor(color, "RGB") + else: + rgb = properties["color"].split() + color = "#" + for a in rgb: + color = color + "%02x" % int(float(a) * 255) # https://stackoverflow.com/questions/3942878 + # set foreground color depending on background if ( float(rgb[0]) * 0.299 + float(rgb[1]) * 0.587 + float(rgb[2]) * 0.2 ) > 0.25: @@ -539,7 +545,7 @@ def handle_population( else: fcolor = "#ffffff" - # print('Color %s -> %s -> %s'%(properties['color'], rgb, color)) + print('Color %s -> %s -> %s'%(properties['color'], rgb, color)) if properties and "type" in properties: self.pop_types[population_id] = properties["type"]