Re-stack standalone varea_stack when interactively hiding stack member via legend

I’m attempting to visualize some time-series data on memory utilization and make it available as a standalone/offline interactive html. There are several PIDs of interest that I’m showing together using varea_stack render, and above that in the same figure is a line render showing the over all system memory utilization. (any space inbetween varea_stack and the line is memory used by other processes we don’t care about)

With an interactive legend I can hid the line render or the varea_stack members easily enough. What I’m not sure about is if it is possible to have a callback that “re-stacks” the varea_stack if one of the stack members are hidden. Also, is it possible to have the y-axis range recalculated to adjust, re-scale everything and re-draw based on what is visible?

I have one PID that uses a massive amount of memory, and several others that uses a tiny amount of memory, and I’d like to have everything re-scale and restack on the y axis if I turn off the PID with high utilization, as well as the system utilization line, so that details can be seen on how the utilization of the remaining PIDs related to each other.

Is this even possible with an offline html file? I’m can’t find a lot of info on how the BokehJS API relates to the Python API when trying to hook CustomJS code into events triggered by hiding things.