Beispiel #1
0
 def preload(g_range):
     if g_range not in self.fig_cache:
         fig = self.frame.plot(g_range.chrom, g_range.start,
                               g_range.end)
         self.fig_cache[g_range] = fig2bytes(fig,
                                             encode=self.img_format,
                                             dpi=self.dpi)
Beispiel #2
0
    def refresh(self, hard=False):
        """
        Refresh the image display.
        """
        if (self.current_range in self.fig_cache) and (not hard):
            fig_bytes = self.fig_cache[self.current_range]
        else:
            fig_current = self.frame.show()
            fig_bytes = fig2bytes(fig_current, encode=self.img_format, dpi=self.dpi)
            if self.img_format == 'svg':
                fig_bytes = fig_bytes.decode("utf-8")
            self.fig_cache[self.current_range] = fig_bytes

        # auto clear fig cache for prevent memory leak
        if len(self.fig_cache) > 20 and \
                get_size(self.fig_cache) >= BrowserBase.MAX_CACHE_SIZE:
            self.clear_fig_cache()

        self.widgets.frame_widget.value = fig_bytes