modified logic to calculate margin for y axis