Exemplo n.º 1
0
    def plugin_layout(
            self,
            contact_person: Optional[dict] = None
    ) -> Union[str, Type[Component]]:
        """This function returns (if the class constant SHOW_TOOLBAR is True,
        the plugin layout wrapped into a common webviz config plugin
        component, which provides some useful buttons like download of data,
        show data contact person and download plugin content to png.

        CSV download button will only appear if the plugin class has a property
        `csv_string` which should return the appropriate csv data as a string.

        If `TOOLBAR_BUTTONS` is empty, this functions returns the same
        dash layout as the plugin class provides directly.
        """

        if isinstance(self, WebvizContainerABC):
            warnings.warn(
                ("The class name 'WebvizContainerABC' is deprecated. You "
                 "should change to 'WebvizPluginABC'. If you have a __init__ "
                 "function, you should at the same time call super().__init__(). "
                 "See https://github.com/equinor/webviz-config/pull/174 for "
                 "details. This warning will eventually "
                 "turn into an error in a future release of webviz-config."),
                DeprecationWarning,
            )

        buttons = self.__class__.TOOLBAR_BUTTONS.copy()

        if contact_person is None:
            contact_person = {}
        else:
            # Sanitize the configuration user input
            for key in contact_person:
                contact_person[key] = bleach.clean(str(contact_person[key]))

        if "download_zip" in buttons and not hasattr(self,
                                                     "_add_download_button"):
            buttons.remove("download_zip")

        if buttons:
            # pylint: disable=no-member
            return wcc.WebvizPluginPlaceholder(
                id=self._plugin_wrapper_id,
                buttons=buttons,
                contact_person=contact_person,
                children=[self.layout],
                tour_steps=WebvizPluginABC._reformat_tour_steps(
                    self.tour_steps  # type: ignore[attr-defined]
                ) if "guided_tour" in buttons and hasattr(self, "tour_steps")
                else [],
            )
        return self.layout
def test_plugin_placeholder(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div([
        webviz_core_components.WebvizPluginPlaceholder(
            id="plugin", children=["Hello world"]),
        html.Div(id="output"),
    ])

    dash_duo.start_server(app)

    assert dash_duo.get_logs() == [], "browser console should contain no error"
Exemplo n.º 3
0
def create_data_table(
    volumemodel: InplaceVolumesModel,
    columns: list,
    height: str,
    data: List[dict],
    table_id: dict,
) -> dash_table.DataTable:

    if not data:
        return []

    style_cell_conditional = [{
        "if": {
            "column_id": c
        },
        "textAlign": "left"
    } for c in [x for x in volumemodel.selectors if x != "FLUID_ZONE"] +
                              ["Response", "Property", "Sensitivity"]]
    style_cell_conditional.extend([{
        "if": {
            "column_id": c
        },
        "width": "10%"
    } for c in volumemodel.selectors + ["Response", "Property", "Sensitivity"]
                                   ])
    style_data_conditional = fluid_table_style()

    return wcc.WebvizPluginPlaceholder(
        id={
            "request": "table_data",
            "table_id": table_id["table_id"]
        },
        buttons=["expand", "download"],
        children=dash_table.DataTable(
            id=table_id,
            sort_action="native",
            sort_mode="multi",
            filter_action="native",
            columns=columns,
            data=data,
            style_as_list_view=True,
            style_cell_conditional=style_cell_conditional,
            style_data_conditional=style_data_conditional,
            style_table={
                "height": height,
                "overflowY": "auto",
            },
        ),
    )
Exemplo n.º 4
0
    def plugin_layout(
        self,
        contact_person: Optional[dict] = None,
        plugin_deprecation_warnings: Optional[List[str]] = None,
        argument_deprecation_warnings: Optional[List[str]] = None,
    ) -> Union[str, Type[Component]]:
        """This function returns (if the class constant SHOW_TOOLBAR is True,
        the plugin layout wrapped into a common webviz config plugin
        component, which provides some useful buttons like download of data,
        show data contact person and download plugin content to png.

        CSV download button will only appear if the plugin class has a property
        `csv_string` which should return the appropriate csv data as a string.

        If `TOOLBAR_BUTTONS` is empty, this functions returns the same
        dash layout as the plugin class provides directly.
        """

        buttons = self.__class__.TOOLBAR_BUTTONS.copy()

        if contact_person is None:
            contact_person = {}
        else:
            # Sanitize the configuration user input
            for key in contact_person:
                contact_person[key] = bleach.clean(str(contact_person[key]))

        if self._add_download_button:
            buttons.append("download")

        if buttons or plugin_deprecation_warnings or argument_deprecation_warnings:
            # pylint: disable=no-member
            return wcc.WebvizPluginPlaceholder(
                id=self._plugin_wrapper_id,
                buttons=buttons,
                contact_person=contact_person,
                children=[self.layout],
                screenshot_filename=self._screenshot_filename,
                tour_steps=WebvizPluginABC._reformat_tour_steps(
                    self.tour_steps  # type: ignore[attr-defined]
                ) if "guided_tour" in buttons and hasattr(self, "tour_steps")
                else [],
                deprecation_warnings=self._make_extended_deprecation_warnings(
                    plugin_deprecation_warnings,
                    argument_deprecation_warnings),
                feedback_url=self._make_feedback_url(),
            )

        return self.layout
Exemplo n.º 5
0
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import webviz_core_components

app = dash.Dash(__name__)

app.layout = html.Div([
    webviz_core_components.WebvizPluginPlaceholder(id="plugin",
                                                   children=["Hello world"]),
    webviz_core_components.WebvizPluginPlaceholder(
        id="some-other-plugin",
        children=[
            webviz_core_components.ColorScales(id="colorscale"),
            webviz_core_components.Graph(
                id="example-graph",
                figure={
                    "data": [
                        {
                            "x": [1, 2, 3],
                            "y": [4, 1, 2],
                            "type": "bar",
                            "name": "a",
                        },
                        {
                            "x": [1, 2, 3],
                            "y": [2, 4, 5],
                            "type": "bar",
                            "name": "b",
                        },
                        {
Exemplo n.º 6
0
from dash import Dash, Input, Output, State, html

import webviz_core_components as wcc

app = Dash(__name__)

app.layout = html.Div([
    wcc.WebvizPluginPlaceholder(id="plugin",
                                children=["Hello world"],
                                screenshot_filename="hello.png"),
    wcc.WebvizPluginPlaceholder(children=[
        wcc.FlexBox(children=[
            html.Div(
                style={"width": "100%"},
                children=[
                    wcc.Select(
                        id="select-test",
                        size=2,
                        value=["el1"],
                        options=[
                            {
                                "value": "el1",
                                "label": "List element 1"
                            },
                            {
                                "value": "el2",
                                "label": "List element 2"
                            },
                        ],
                    )
                ],
Exemplo n.º 7
0
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import webviz_core_components as wcc

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        wcc.WebvizPluginPlaceholder(id="plugin", children=["Hello world"]),
        wcc.WebvizPluginPlaceholder(
            children=[
                wcc.FlexBox(
                    children=[
                        html.Div(
                            style={"width": "100%"},
                            children=[
                                wcc.Select(
                                    id="select-test",
                                    size=2,
                                    value=["el1"],
                                    options=[
                                        {"value": "el1", "label": "List element 1"},
                                        {"value": "el2", "label": "List element 2"},
                                    ],
                                )
                            ],
                        ),
                        html.Div(
                            "First element (before break)",
                            style={"background-color": "rgba(0, 255, 255, 0.2)"},
Exemplo n.º 8
0
def create_data_table(
    columns: list,
    height: str,
    data: List[dict],
    table_id: dict,
    selectors: Optional[list] = None,
    style_cell: Optional[dict] = None,
    style_cell_conditional: Optional[list] = None,
    style_data_conditional: Optional[list] = None,
) -> Union[list, wcc.WebvizPluginPlaceholder]:

    if not data:
        return []

    if selectors is None:
        selectors = []
    conditional_cell_style = [
        {
            "if": {
                "column_id":
                selectors + ["Response", "Property", "Sensitivity"]
            },
            "width": "10%",
            "textAlign": "left",
        },
        {
            "if": {
                "column_id": "FLUID_ZONE"
            },
            "width": "10%",
            "textAlign": "right"
        },
    ]
    if style_cell_conditional is not None:
        conditional_cell_style.extend(style_cell_conditional)

    style_data_conditional = (style_data_conditional
                              if style_data_conditional is not None else [])
    style_data_conditional.extend(fluid_table_style())

    return wcc.WebvizPluginPlaceholder(
        id={
            "request": "table_data",
            "table_id": table_id["table_id"]
        },
        buttons=["expand", "download"],
        children=dash_table.DataTable(
            id=table_id,
            sort_action="native",
            sort_mode="multi",
            filter_action="native",
            columns=columns,
            data=data,
            style_as_list_view=True,
            style_cell=style_cell,
            style_cell_conditional=conditional_cell_style,
            style_data_conditional=style_data_conditional,
            style_table={
                "height": height,
                "overflowY": "auto",
            },
        ),
    )
Exemplo n.º 9
0
    def plugin_layout(
        self,
        contact_person: Optional[dict] = None,
        deprecation_warnings: Optional[List[str]] = None,
    ) -> Union[str, Type[Component]]:
        """This function returns (if the class constant SHOW_TOOLBAR is True,
        the plugin layout wrapped into a common webviz config plugin
        component, which provides some useful buttons like download of data,
        show data contact person and download plugin content to png.

        CSV download button will only appear if the plugin class has a property
        `csv_string` which should return the appropriate csv data as a string.

        If `TOOLBAR_BUTTONS` is empty, this functions returns the same
        dash layout as the plugin class provides directly.
        """

        buttons = self.__class__.TOOLBAR_BUTTONS.copy()

        if contact_person is None:
            contact_person = {}
        else:
            # Sanitize the configuration user input
            for key in contact_person:
                contact_person[key] = bleach.clean(str(contact_person[key]))

        if self._add_download_button:
            buttons.append("download")

        extended_deprecation_warnings: List[Dict[str, str]] = []

        if deprecation_warnings:
            # pylint: disable=import-outside-toplevel
            from .plugins import PLUGIN_METADATA, PLUGIN_PROJECT_METADATA

            plugin_name = getattr(getattr(self, "__class__"), "__name__")
            dist_name = PLUGIN_METADATA[plugin_name]["dist_name"]
            metadata = PLUGIN_PROJECT_METADATA[dist_name]
            if metadata and "documentation_url" in metadata:
                url = (f"{metadata['documentation_url']}"
                       f"/#/deprecations?id={plugin_name.lower()}")
            else:
                url = ""

            for deprecation_warning in deprecation_warnings:
                extended_deprecation_warnings.append({
                    "message": deprecation_warning,
                    "url": url
                })

        if buttons or deprecation_warnings:
            # pylint: disable=no-member
            return wcc.WebvizPluginPlaceholder(
                id=self._plugin_wrapper_id,
                buttons=buttons,
                contact_person=contact_person,
                children=[self.layout],
                screenshot_filename=self._screenshot_filename,
                tour_steps=WebvizPluginABC._reformat_tour_steps(
                    self.tour_steps  # type: ignore[attr-defined]
                ) if "guided_tour" in buttons and hasattr(self, "tour_steps")
                else [],
                deprecation_warnings=extended_deprecation_warnings,
            )

        return self.layout