code: def rotate_direction(hexgrid_type, direction, ccw=True):
      
      if hexgrid_type in [TILE, EDGE]:
          directions = ['NW', 'W', 'SW', 'SE', 'E', 'NE', 'NW'] if ccw \
                  else ['NW', 'NE', 'E', 'SE', 'SW', 'W', 'NW']
          return directions[directions.index(direction) + 1]
      elif hexgrid_type in [NODE]:
          directions = ['N', 'NW', 'SW', 'S', 'SE', 'NE', 'N'] if ccw \
              else ['N', 'NE', 'SE', 'S', 'SW', 'NW', 'N']
          return directions[directions.index(direction) + 1]
      else:
          raise ValueError('Invalid hexgrid type={} passed to rotate direction'.format(hexgrid_type))
docs: Takes a direction string associated with a type of hexgrid element, and rotates it one tick in the given direction.
      :param direction: string, eg 'NW', 'N', 'SE'
      :param ccw: if True, rotates counter clockwise. Otherwise, rotates clockwise.
      :return: the rotated direction string, eg 'SW', 'NW', 'S'