06d4b659f1ff4f3eae2346f9ebbe9ac4d0dfcb74 max Thu Jul 31 07:18:04 2025 -0700 fixing webcolors a little more, brittney diff --git src/cbPyLib/cellbrowser/cellbrowser.py src/cbPyLib/cellbrowser/cellbrowser.py index bafab71..e2ed386 100755 --- src/cbPyLib/cellbrowser/cellbrowser.py +++ src/cbPyLib/cellbrowser/cellbrowser.py @@ -2371,31 +2371,35 @@ color = color.strip("#") # hbeale had a 6-digit file with trailing spaces isHex = True if len(color)!=6: # colors can be no more than six hex digits isHex = False else: for c in color: if (c not in "0123456789ABCDEFabcdef"): isHex = False break if not isHex: logging.debug("Not a six-digit hex color code. Trying to map '%s' to a hex color" % color) import webcolors # error? -> pip install webcolors try: - color = webcolors.name_to_hex(color, spec='css3').lstrip("#") + color = webcolors.name_to_hex(color).lstrip("#") + except ValueError: + import matplotlib.colors as mcolors + try: + color = mcolors.CSS4_COLORS[color].lstrip("#") except ValueError: # R knows more colors, like deeppink4. We simply map to deeppink for now # there does not seem to be a good table with R colors in Python yet color = "".join([c for c in color if not c.isdigit()]) color = webcolors.name_to_hex(color, spec='css3').lstrip("#") newDict[metaVal] = color return newDict def parseColors(inDir, inConf, outConf, colData): """ parse color table and return as dict fieldName -> value -> color. Can be a single filename (backwards compat) or a dict fieldName -> filename """ if not "colors" in inConf: return {}