Merge "Fix off-by-two and other bugs in the visualization code. b/3137511" into gingerbread