示例#1
0
def test_create_themed_layout():
    # Make an instance of the theme class
    test_theme = WebvizConfigTheme(theme_name="test")
    # Add a plotly theme to the new theme
    test_theme.plotly_theme = {
        "layout": {
            "font": {
                "family": "Arial"
            },
            "colorscale": {
                "diverging": [
                    [0, "rgb(255, 0, 0)"],
                    [0.5, "rgb(255, 255, 0)"],
                    [1, "rgb(255, 255, 255)"],
                ],
                "sequential": [
                    [0, "rgb(0, 0, 255)"],
                    [0.5, "rgb(0, 255, 0)"],
                    [1, "rgb(255, 0, 0)"],
                ],
            },
            "xaxis": {
                "title": {
                    "text": "Hi",
                    "font": {
                        "size": 10
                    }
                }
            },
            "yaxis2": {
                "color": "#000"
            },
        },
    }
    # Define a layout that should be themed
    test_layout = {
        "font": {
            "size": 12
        },
        "colorscale": {
            "sequential": [
                [0, "rgb(0, 0, 0)"],
                [0.25, "rgb(255, 0, 0)"],
                [0.5, "rgb(0, 255, 0)"],
                [0.75, "rgb(0, 0, 255)"],
                [1, "rgb(255, 255, 255)"],
            ],
        },
        "xaxis": {
            "title": {
                "text": "New",
                "standoff": 2
            },
            "type": "log"
        },
        "xaxis2": {},
        "yaxis": {
            "color": "#111"
        },
    }
    # The expected layout after theming is applied
    expected_themed_layout = {
        "font": {
            "family": "Arial",
            "size": 12
        },
        "colorscale": {
            "diverging": [
                [0, "rgb(255, 0, 0)"],
                [0.5, "rgb(255, 255, 0)"],
                [1, "rgb(255, 255, 255)"],
            ],
            "sequential": [
                [0, "rgb(0, 0, 0)"],
                [0.25, "rgb(255, 0, 0)"],
                [0.5, "rgb(0, 255, 0)"],
                [0.75, "rgb(0, 0, 255)"],
                [1, "rgb(255, 255, 255)"],
            ],
        },
        "xaxis": {
            "title": {
                "text": "New",
                "font": {
                    "size": 10
                },
                "standoff": 2
            },
            "type": "log",
        },
        "xaxis2": {
            "title": {
                "text": "Hi",
                "font": {
                    "size": 10
                }
            }
        },
        "yaxis": {
            "color": "#111"
        },
        "yaxis2": {
            "color": "#000"
        },
    }

    # Make a themed layout using the create_themed_layout method
    themed_layout = test_theme.create_themed_layout(test_layout)

    # Verify that the themed layout is as expected
    assert themed_layout == expected_themed_layout

    # Verify that the theme layout is unchanged (same as when set)
    assert test_theme.plotly_theme == {
        "layout": {
            "font": {
                "family": "Arial"
            },
            "colorscale": {
                "diverging": [
                    [0, "rgb(255, 0, 0)"],
                    [0.5, "rgb(255, 255, 0)"],
                    [1, "rgb(255, 255, 255)"],
                ],
                "sequential": [
                    [0, "rgb(0, 0, 255)"],
                    [0.5, "rgb(0, 255, 0)"],
                    [1, "rgb(255, 0, 0)"],
                ],
            },
            "yaxis2": {
                "color": "#000"
            },
            "xaxis": {
                "title": {
                    "text": "Hi",
                    "font": {
                        "size": 10
                    }
                }
            },
        },
    }

    # Verify that the test_layout unchanged (same as when set)
    assert test_layout == {
        "font": {
            "size": 12
        },
        "colorscale": {
            "sequential": [
                [0, "rgb(0, 0, 0)"],
                [0.25, "rgb(255, 0, 0)"],
                [0.5, "rgb(0, 255, 0)"],
                [0.75, "rgb(0, 0, 255)"],
                [1, "rgb(255, 255, 255)"],
            ],
        },
        "xaxis": {
            "title": {
                "text": "New",
                "standoff": 2
            },
            "type": "log"
        },
        "yaxis": {
            "color": "#111"
        },
        "xaxis2": {},
    }
示例#2
0
import glob
import pathlib

from plotly.io import templates

from webviz_config import WebvizConfigTheme

default_theme = WebvizConfigTheme(theme_name="default")  # pylint: disable=invalid-name

default_theme.assets = glob.glob(
    str(pathlib.Path(__file__).resolve().parent / "default_assets" / "*"))

default_theme.plotly_theme = templates["plotly"].to_plotly_json()
equinor_theme.plotly_theme = {
    "layout": {
        "font": {
            "family": "Equinor"
        },
        "hoverlabel": {
            "font": {
                "family": "Equinor"
            }
        },
        "plot_bgcolor":
        "white",
        "colorscale": {
            "diverging": [
                [0, "rgb(255, 18, 67)"],
                [0.1, "rgb(36, 55, 70)"],
                [0.2, "rgb(0, 112, 121)"],
                [0.3, "rgb(213, 234, 244)"],
                [0.4, "rgb(230, 250, 236)"],
                [0.5, "rgb(255, 231, 214)"],
                [0.6, "rgb(128, 183, 188)"],
                [0.7, "rgb(255, 18, 67)"],
                [0.8, "rgb(145, 155, 162)"],
                [0.9, "rgb(190, 128, 145)"],
                [1, "rgb(178, 212, 215)"],
            ],
            "sequential": [
                [0.0, "rgb(36, 55, 70)"],
                [0.125, "rgb(102, 115, 125)"],
                [0.25, "rgb(145, 155, 162)"],
                [0.375, "rgb(189, 195, 199)"],
                [0.5, "rgb(255, 231, 214)"],
                [0.625, "rgb(216, 178, 189)"],
                [0.75, "rgb(190, 128, 145)"],
                [0.875, "rgb(164, 76, 101)"],
                [1.0, "rgb(125, 0, 35)"],
            ],
        },
        "colorway": [
            "#FF1243",
            "#243746",
            "#007079",
            "#80B7BC",
            "#919BA2",
            "#BE8091",
            "#B2D4D7",
            "#FF597B",
            "#BDC3C7",
            "#D8B2BD",
            "#FFE7D6",
            "#D5EAF4",
            "#FF88A1",
        ],
    }
}
示例#4
0
]

equinor_theme.adjust_csp(
    {
        "font-src": ["https://eds-static.equinor.com"],
        "img-src": ["https://eds-static.equinor.com"],
        "style-src": ["https://eds-static.equinor.com"],
    },
    append=True,
)

equinor_theme.assets = glob.glob(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "*")
)

equinor_theme.plotly_theme = {
    "layout": {
        "font": {"family": "Equinor"},
        "hoverlabel": {"font": {"family": "Equinor"}},
        "plot_bgcolor": "white",
        "xaxis": {"exponentformat": "SI"},
        "yaxis": {"exponentformat": "SI"},
        "coloraxis": {"colorbar": {"exponentformat": "SI"}},
        "colorscale": {
            "diverging": colors.get_colorscale("spectral"),
            "sequential": colors.get_colorscale("viridis"),
        },
        "colorway": colors.qualitative.D3 + colors.qualitative.Light24,
    }
}