CDAP-735: Update visualization of Spark job metrics

That's because you are observing metricsUpdated to execute this function and you are changing metricsUpdated inside this function so this is what's happening:
metricsUpdated changed = fire function
rescaleLineSizes changes metricsUpdated = fire rescaleLineSizes
rescaleLineSizes changes metricsUpdated = fire rescaleLineSizes ... and so on.
The solution above should work.