예제 #1
0
    def __init__(self,
                 palette: BinnedContinuousPalette,
                 binning: BinDefinition,
                 label_formatter=None):
        """
        :param palette: palette used for showing continuous values
        :param binning: binning used to discretize colors
        """
        super().__init__(None)

        self.palette = palette
        self.binning = binning
        if label_formatter is None:
            if binning.width is not None:
                width = binning.width
            else:
                width = min([
                    t2 - t1 for t1, t2 in zip(binning.thresholds,
                                              binning.thresholds[1:])
                ])
            decimals = max(-floor(log10(width)), 0)
            label_formatter = "{{:.{}f}}".format(decimals).format
        cuts = [label_formatter(l) for l in self.binning.thresholds]
        self.labels = [
            QStaticText("{} - {}".format(fr, to))
            for fr, to in zip(cuts, cuts[1:])
        ]
        font = self.font()
        font.setPixelSize(11)
        for label in self.labels:
            label.prepare(font=font)
        self.text_width = max(label.size().width() for label in self.labels)
예제 #2
0
 def __static_text_elided_cache(
         self, text: str, font: QFont, fontMetrics: QFontMetrics,
         elideMode: Qt.TextElideMode, width: int
 ) -> QStaticText:
     """
     Return a `QStaticText` instance for depicting the text with the `font`
     """
     try:
         return self.__static_text_lru_cache[text, font, elideMode, width]
     except KeyError:
         text = fontMetrics.elidedText(text, elideMode, width)
         st = QStaticText(text)
         st.prepare(QTransform(), font)
         # take a copy of the font for cache key
         key = text, QFont(font), elideMode, width
         self.__static_text_lru_cache[key] = st
         return st
예제 #3
0
 def __init__(self, palette, scale):
     """
     :param palette: palette used for showing continuous values
     :type palette: ContinuousPaletteGenerator
     :param scale: an instance of DiscretizedScale that defines the
                   conversion of values into bins
     :type scale: DiscretizedScale
     """
     super().__init__(None)
     self.palette = palette
     self.scale = scale
     cuts = ["{0:.{1}f}".format(scale.offset + i * scale.width, scale.decimals)
             for i in range(scale.bins + 1)]
     self.labels = [QStaticText("{} - {}".format(fr, to))
                    for fr, to in zip(cuts, cuts[1:])]
     for label in self.labels:
         label.prepare()
     self.text_width = max(label.size().width() for label in self.labels)
예제 #4
0
 def __init__(self, palette, scale, label_formatter=None):
     """
     :param palette: palette used for showing continuous values
     :type palette: BinnedContinuousPalette
     :param scale: an instance of DiscretizedScale that defines the
                   conversion of values into bins
     :type scale: DiscretizedScale
     """
     super().__init__(None)
     self.palette = palette
     self.scale = scale
     if label_formatter is None:
         label_formatter = "{{:.{}f}}".format(scale.decimals).format
     cuts = [label_formatter(scale.offset + i * scale.width)
             for i in range(scale.bins + 1)]
     self.labels = [QStaticText("{} - {}".format(fr, to))
                    for fr, to in zip(cuts, cuts[1:])]
     self.font = self.font()
     self.font.setPointSize(11)