Skip to content

Commit

Permalink
Merge branch 'feat-allow-hex-colors' into experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Dec 16, 2024
2 parents cf51b46 + 686de6f commit 28fa87b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions neuromllite/GraphVizHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from graphviz import Digraph
import numpy as np
from PIL import ImageColor

engines = {
"d": "dot",
Expand Down Expand Up @@ -526,20 +527,25 @@ 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:
fcolor = "#000000"
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"]
Expand Down

0 comments on commit 28fa87b

Please sign in to comment.