Use a HashMap to decrease some IF-ELSE in canvas class