Change annotation font size on zooming

Hi
I want to zoom in on annotations to make them look bigger when zoomed in and smaller when zoomed out.
I wanted to use something like this:
@app.callback(Output('my-graph', 'figure'), Input('my-graph', 'relayoutData'))
to measure the graph diagonal, calculate the appropriate size and regenerate the annotations but it loops on itself infinitely with relayoutData.autosize=True. Probably because relayoutData triggers the callback when the figure is updated.

EDIT:
I managed to do this with hidden Divs, the PreventUpdate exception and State.
The trick is to update the hidden div on relayoutData and give it the content of the Div itself as State so you can check if it should stay the same or change. If it should stay the same, use PreventUpdate instead of returning the same value. This way, the graph update callback (which has the hidden Div value as input) is triggered only when values actually change and not on every update recursively.

Is there a better way to do this?