optimize the chart zoom algorithm