fix NaN problem when starting with an empty data set / zero-sized grid

In certain situations the variable ph has a value of zero (like when creating the grid off-screen). This leads to a NaN value in page due to division by zero, which in turn propagates in later calculations and prevents the grid from functioning correctly.