code: def draw(canvas, mol):
      mol.require("ScaleAndCenter")
      mlb = mol.size2d[2]
      if not mol.atom_count():
          return
      bond_type_fn = {
          1: {
              0: single_bond,
              1: wedged_single,
              2: dashed_wedged_single,
              3: wave_single,
          }, 2: {
              0: cw_double,
              1: counter_cw_double,
              2: double_bond,
              3: cross_double
          }, 3: {
              0: triple_bond
          }
      }
      for u, v, bond in mol.bonds_iter():
          if not bond.visible:
              continue
          if (u < v) == bond.is_lower_first:
              f, s = (u, v)
          else:
              s, f = (u, v)
          p1 = mol.atom(f).coords
          p2 = mol.atom(s).coords
          if p1 == p2:
              continue
          if mol.atom(f).visible:
              p1 = gm.t_seg(p1, p2, F_AOVL, 2)[0]
          if mol.atom(s).visible:
              p2 = gm.t_seg(p1, p2, F_AOVL, 1)[1]
          color1 = mol.atom(f).color
          color2 = mol.atom(s).color
          bond_type_fn[bond.order][bond.type](
              canvas, p1, p2, color1, color2, mlb)
      for n, atom in mol.atoms_iter():
          if not atom.visible:
              continue
          p = atom.coords
          color = atom.color
          if atom.H_count:
              cosnbrs = []
              hrzn = (p[0] + 1, p[1])
              for nbr in mol.graph.neighbors(n):
                  pnbr = mol.atom(nbr).coords
                  try:
                      cosnbrs.append(gm.dot_product(hrzn, pnbr, p) /
                                     gm.distance(p, pnbr))
                  except ZeroDivisionError:
                      pass
              if not cosnbrs or min(cosnbrs) > 0:
                  text = atom.formula_html(True)
                  canvas.draw_text(p, text, color, "right")
                  continue
              elif max(cosnbrs) < 0:
                  text = atom.formula_html()
                  canvas.draw_text(p, text, color, "left")
                  continue
          text = atom.formula_html()
          canvas.draw_text(p, text, color, "center")