Пример #1
0
        Writes out the content as raw text or HTML.

        :param contents: Bokeh plotting figure.
        :param kwargs: Optional styling arguments. The `style` keyword argument has special
                       meaning in that it allows styling to be grouped as one argument.
                       It is also useful in case a styling parameter name clashes with a standard
                       block parameter.
        """
        self.resource_deps = [JScript(script_string=s, name='bokeh_js') for s in JSResources().js_raw]
        self.resource_deps += [Css(css_string=s, name='bokeh_css') for s in CSSResources().css_raw]

        super(BokehPlotBlock, self).__init__(**kwargs)

        if not isinstance(contents, BokehFigure):
            raise ValueError("Expected bokeh.plotting.figure.Figure type but got %s", type(contents))

        script, div = components(contents)
        self._contents = script + div

    def _write_contents(self, container, *args, **kwargs):
        container.append(parse(self._contents))


add_block_types(Artist, PlotBlock)
# If Plotly or Bokeh are not installed skip registration
if _PLOTLY_AVAILABLE:
    add_block_types(PlotlyFigure, PlotlyPlotBlock)

if _BOKEH_AVAILABLE:
    add_block_types(BokehFigure, BokehPlotBlock)
Пример #2
0
def columns_to_iterable(column_index, merge_depth=False):
    """
    Return the given index as a list of lists of (potentially merged) cells
    suitable for rendering as HTML, in depth-major order. i.e. suited for
    rendering a table header.
    """
    rows = index_to_iterable(column_index, merge_depth=merge_depth)
    result = [[] for _ in range(len(column_index.names))]

    # transpose the index iterable from span-major to depth-major order.
    skips = [0] * len(column_index.names)
    for distance, row in enumerate(rows):

        # if a previous cell at this depth had a span that overlaps, then don't
        # emit a cell at this depth.
        depth = 0
        while skips[depth]:
            skips[depth] -= 1
            depth += 1

        for cell in row:
            result[depth].append(cell)
            for skip_index in range(depth, depth + cell.depth):
                skips[skip_index] = cell.span - 1
            depth += cell.depth

    return result


add_block_types(pd.DataFrame, HTMLJinjaTableBlock)
Пример #3
0
                        *args, **kwargs)

            # Clear the floating, Yarr!
            append_to(container, "div", style="clear:both")


class HStack(Grid):
    def __init__(self, contents, cascade_cfg=True, **kwargs):
        """
        Create a horizontal stack layout that puts contents side by side.

        :param contents: A list, tuple or set of elements.
        :param cols: Desired number of columns in the grid.
        :param cascade_cfg: Set to True to enable parmater cascading from this block. A value
                            of False means that child blocks do not inherit parameters from
                            this block.
        :param kwargs: Optional styling arguments. The `style` keyword argument has special
                       meaning in that it allows styling to be grouped as one argument.
                       It is also useful in case a styling parameter name clashes with a standard
                       block parameter.
        """
        super(HStack, self).__init__(contents,
                                     cascade_cfg=cascade_cfg,
                                     **kwargs)

        # Set the column count here because the contents can be processed by mixins/superclasses
        self._cols = len(self._contents)


add_block_types((list, tuple, set, pd.WidePanel), Grid)
Пример #4
0
            # empty plot, disable bbox_inches to that savefig still works
            bbox_inches = None

        figure.savefig(img_data,
                       dpi=_PLOT_DPI,
                       format=_PLOT_FORMAT,
                       bbox_extra_artists=legends,
                       bbox_inches=bbox_inches)

        plt_width, plt_height = figure.get_size_inches()

        width = width or "{:0.3f}in".format(plt_width)
        height = height or "{:0.3f}in".format(plt_height)

        if close_plot:
            plt.close(figure)

        super(PlotBlock, self).__init__(img_data.getvalue(),
                                        _PLOT_MIME_TYPE,
                                        width=width,
                                        height=height,
                                        **kwargs)

    def _to_static(self):
        # Convert to a basic image block in case we contain 'dynamic' svg content
        return ImgBlock(self) if self._mime_type == "svg" else super(
            PlotBlock, self)._to_static()


add_block_types(Artist, PlotBlock)
Пример #5
0
                        *args, **kwargs)

            # Clear the floating, Yarr!
            append_to(container, "div", style="clear:both")


class HStack(Grid):
    def __init__(self, contents, cascade_cfg=True, **kwargs):
        """
        Create a horizontal stack layout that puts contents side by side.

        :param contents: A list, tuple or set of elements.
        :param cols: Desired number of columns in the grid.
        :param cascade_cfg: Set to True to enable parmater cascading from this block. A value
                            of False means that child blocks do not inherit parameters from
                            this block.
        :param kwargs: Optional styling arguments. The `style` keyword argument has special
                       meaning in that it allows styling to be grouped as one argument.
                       It is also useful in case a styling parameter name clashes with a standard
                       block parameter.
        """
        super(HStack, self).__init__(contents,
                                     cascade_cfg=cascade_cfg,
                                     **kwargs)

        # Set the column count here because the contents can be processed by mixins/superclasses
        self._cols = len(self._contents)


add_block_types((list, tuple, set), Grid)