I have had a very simple color effect for my bokeh glyphs and it has worked for months, I come into work today and all of a sudden my bokeh is not rendering. I check the browser developer console and see this:
bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:164 Error rendering Bokeh items: Error: invalid color array
at pe.v_materialize (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:184:10821)
at pe.uniform (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:184:5664)
at p.set_visuals (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:384:4086)
at k.set_visuals (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:380:4705)
at k.set_data (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:380:4402)
at async k.lazy_initialize (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:380:1795)
at async l (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:222:180)
at async t.build_views (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:222:595)
at async l.build_renderer_views (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:610:11060)
at async l.lazy_initialize (bokeh.min.js?v=887e6bace8d80f5c1555c1913f730061c2d73acb83adb7f4ccf2ef02ffc7e5e864f7b1c97db9a4f6643a1431700d65e2686759f5c4bb1ac92631e8b659ceead3:610:4667)
This is telling me I have an invalid color array, which is very odd because I have triple checked these and they are all fine. I ran my code and there are no Nan values or errors appearing in the code, it is just failing when it finally lands in the bokeh server to render. Here are the colors I am using and the function creating colors for my glyphs:
```def get_color(x, max_blocks):
# Define color ranges
blue_shades = ['#0033FF', '#0066FF', '#0099FF', '#00CCFF']
# Overflow colors transitioning from yellow to orange to red
overflow_colors = [
'#FFFF00', '#FFEE00', '#FFDD00', '#FFCC00',
'#FFBB00', '#FFAA00', '#FF9900', '#FF8800',
'#FF7700', '#FF6600', '#FF5500', '#FF4400',
'#FF3300', '#FF2200', '#FF1100', '#FF0000'
]
underflow_color = '#808080' # For zero blocks
if x == 0:
return underflow_color
elif x <= max_blocks:
# Map x to the appropriate blue shade
color_index = max(0, min(int(len(blue_shades) * x / max_blocks) - 1, len(blue_shades) - 1))
return blue_shades[color_index]
else:
# Dynamically scale the overflow index based on x exceeding max_blocks
overflow_range = max(x - max_blocks, 1)
# Find the ratio of the current block count over the max block count within the overflow range
ratio = (overflow_range - 1) / (28 - max_blocks) if max_blocks < 28 else 0
overflow_index = int(ratio * (len(overflow_colors) - 1))
return overflow_colors[min(overflow_index, len(overflow_colors) - 1)]
# Test different values of x and max_blocks
for x in range(0, 30, 5):
print(f"x = {x}, color = {get_color(x, 10)}")
for x in range(0, 30, 5):
print(f"x = {x}, color = {get_color(x, 20)}")```