Exemple #1
0
 def filters(self, filters):
     try:
         temp = Filter(self.domain)
         temp.stages = filters['stages']
         temp.platforms = filters['platforms']
         self.__filters = temp
     except KeyError as e:
         handler(
             type(self).__name__, "Unable to properly extract "
             "information from filter: {}.".format(e))
         raise BadInput
    def _build_headers(self,
                       name,
                       config,
                       desc=None,
                       filters=None,
                       gradient=None):
        """
            Internal - build the header blocks for the svg

            :param name: The name of the layer being exported
            :param config: SVG Config object
            :param desc: Description of the layer being exported
            :param filters: Any filters applied to the layer being exported
            :param gradient: Gradient information included with the layer
            :return: Instantiated SVG header
        """
        max_x = convertToPx(config.width, config.unit)
        max_y = convertToPx(config.height, config.unit)
        header_height = convertToPx(config.headerHeight, config.unit)
        ff = config.font
        d = draw.Drawing(max_x, max_y, origin=(0, -max_y), displayInline=False)
        psych = 0
        overlay = None
        if config.showHeader:
            border = convertToPx(config.border, config.unit)
            root = G(tx=border, ty=border, style='font-family: {}'.format(ff))

            header = G()
            root.append(header)
            b1 = G()
            header.append(b1)

            header_count = 0
            if config.showAbout:
                header_count += 1
            if config.showFilters:
                header_count += 1
            if config.showLegend and gradient is not False and config.legendDocked:
                header_count += 1

            operation_x = (max_x - border) - (1.5 * border *
                                              (header_count - 1))
            if header_count > 0:
                header_width = operation_x / header_count
                if config.showAbout:
                    if desc is not None:
                        g = SVG_HeaderBlock().build(height=header_height,
                                                    width=header_width,
                                                    label='about',
                                                    t1text=name,
                                                    t2text=desc,
                                                    config=config)
                    else:
                        g = SVG_HeaderBlock().build(height=header_height,
                                                    width=header_width,
                                                    label='about',
                                                    t1text=name,
                                                    config=config)
                    b1.append(g)
                    psych += 1
                if config.showFilters:
                    fi = filters
                    if fi is None:
                        fi = Filter()
                        fi.platforms = ["Windows", "Linux", "macOS"]
                        fi.stages = ["act"]
                    g2 = SVG_HeaderBlock().build(height=header_height,
                                                 width=header_width,
                                                 label='filters',
                                                 t1text=', '.join(
                                                     fi.platforms),
                                                 t2text=fi.stages[0],
                                                 config=config)
                    b2 = G(tx=operation_x / header_count * psych +
                           1.5 * border * psych)
                    header.append(b2)
                    b2.append(g2)
                    psych += 1
                if config.showLegend and gradient is not False:
                    gr = gradient
                    if gr is None:
                        gr = Gradient(colors=["#ff6666", "#ffe766", "#8ec843"],
                                      minValue=1,
                                      maxValue=100)
                    colors = []
                    div = round(
                        (gr.maxValue - gr.minValue) / (len(gr.colors) * 2 - 1))
                    for i in range(0, len(gr.colors) * 2 - 1):
                        colors.append(
                            (gr.compute_color(int(gr.minValue + div * i)),
                             gr.minValue + div * i))
                    colors.append((gr.compute_color(gr.maxValue), gr.maxValue))
                    if config.legendDocked:
                        b3 = G(tx=operation_x / header_count * psych +
                               1.5 * border * psych)
                        g3 = SVG_HeaderBlock().build(height=header_height,
                                                     width=header_width,
                                                     label='legend',
                                                     variant='graphic',
                                                     colors=colors,
                                                     config=config)
                        header.append(b3)
                        b3.append(g3)
                        psych += 1
                    else:
                        adjusted_height = convertToPx(config.legendHeight,
                                                      config.unit)
                        adjusted_width = convertToPx(config.legendWidth,
                                                     config.unit)
                        g3 = SVG_HeaderBlock().build(height=adjusted_height,
                                                     width=adjusted_width,
                                                     label='legend',
                                                     variant='graphic',
                                                     colors=colors,
                                                     config=config)
                        lx = convertToPx(config.legendX, config.unit)
                        if not lx:
                            lx = max_x - adjusted_width - convertToPx(
                                config.border, config.unit)
                        ly = convertToPx(config.legendY, config.unit)
                        if not ly:
                            ly = max_y - adjusted_height - convertToPx(
                                config.border, config.unit)
                        overlay = G(tx=lx, ty=ly)
                        if (ly + adjusted_height) > max_y or (
                                lx + adjusted_width) > max_x:
                            print(
                                "[WARNING] - Floating legend will render partly out of view..."
                            )
                        overlay.append(g3)
            d.append(root)
        return d, psych, overlay