Draw contours on the data for a click in the thematic map
        :param event: mouse click on thematic map preview

def onclick(self, event):
        """
        Draw contours on the data for a click in the thematic map
        :param event: mouse click on thematic map preview
        """
        if event.inaxes == self.previewax:
            y, x = int(event.xdata), int(event.ydata)
            label = self.selection_array[x, y]
            contiguous_regions = scipy.ndimage.label(self.selection_array == label)[0]
            this_region = contiguous_regions == (contiguous_regions[x, y])

            # remove the boundaries so any region touching the edge isn't drawn odd
            this_region[0, :] = 0
            this_region[:, 0] = 0
            this_region[this_region.shape[0]-1, :] = 0
            this_region[:, this_region.shape[1]-1] = 0

            # convert the region mask into just a true/false array of its boundary pixels
            edges = binary_erosion(this_region) ^ this_region

            # convert the boundary pixels into a path, moving around instead of just where
            x, y = np.where(edges)
            coords = np.dstack([x, y])[0]
            path = [coords[0]]
            coords = coords[1:]

            while len(coords):
                dist = np.sum(np.abs(path[-1] - coords), axis=1)
                neighbor_index = np.argmin(dist)

                if dist[neighbor_index] < 5:
                    path.append(coords[neighbor_index].copy())
                    coords[neighbor_index:-1] = coords[neighbor_index + 1:]
                    coords = coords[:-1]
                else:
                    break

            path = np.array(path)

            clips = []
            while len(coords) > 5:
                dist = np.sum(np.abs(path[-1] - coords), axis=1)
                neighbor_index = np.argmin(dist)
                clip = [coords[neighbor_index].copy()]
                coords[neighbor_index:-1] = coords[neighbor_index + 1:]
                coords = coords[:-1]
                while len(coords):
                    dist = np.sum(np.abs(clip[-1] - coords), axis=1)
                    neighbor_index = np.argmin(dist)
                    if dist[neighbor_index] < 5:
                        clip.append(coords[neighbor_index].copy())
                        coords[neighbor_index:-1] = coords[neighbor_index + 1:]
                        coords = coords[:-1]
                    else:
                        break
                clips.append(np.array(clip))

            # draw the continguous  on the selection area
            self.region_patches.append(PatchCollection(
                [Polygon(np.dstack([path[:, 1], path[:, 0]])[0], False,
                         fill=False, facecolor=None,
                         edgecolor="black", alpha=1, lw=2.5)] +
                [Polygon(np.dstack([clip[:, 1], clip[:, 0]])[0], False,
                         fill=False, facecolor=None,
                         edgecolor="black", alpha=1, lw=2.0) for clip in clips],
                match_original=True))
            self.imageax.add_collection(self.region_patches[-1])
            self.fig.canvas.draw_idle()