File size: 2,641 Bytes
8e17be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a20b7d
8e17be6
 
 
 
 
 
 
 
 
 
 
0a20b7d
8e17be6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import plotly.graph_objs as go
from dash import dcc, html
import logging
logging.basicConfig(level=logging.INFO)

def build_figure(df, selected_traces, trace_library):
    fig = go.Figure()

    for key in selected_traces:
        if trace_library[key]["uncertainty"]:
            xvals = df.index
            yvals = df[key]

            # Upper bound (invisible line)
            fig.add_trace(
                go.Scatter(
                    x=df.index,
                    y=df[key+'_higher'],
                    mode="lines",
                    line=dict(width=0),
                    showlegend=False,
                    hoverinfo="skip"
                )
            )
            alpha =.3
            # Lower bound (filled to upper)
            fig.add_trace(
                go.Scatter(
                    x=df.index,
                    y=df[key+'_lower'],
                    mode="lines",
                    fill="tonexty",
                    fillcolor=trace_library[key]['line_color'].replace("rgb", "rgba")\
                        .replace(")", f", {alpha})"),
                    line=dict(width=0),
                    showlegend=False,
                    hoverinfo="skip"
                )
            )
        else:
            xvals = df.index
            yvals = df[key]

        fig.add_trace(
            go.Scatter(
                x=xvals, y=yvals,
                name=trace_library[key]["label"], mode="lines",
                line=dict(width=3, color=trace_library[key]["line_color"],\
                    dash=trace_library[key]["line_style"])
            )
        )

    fig.update_layout(
        title=df.attrs["title"],
        autosize=True,
        margin=dict(l=40, r=40, t=60, b=40),
        paper_bgcolor="rgba(0,0,0,0)",
        plot_bgcolor="rgba(0,0,0,0)",
        yaxis_title=f"{df.attrs["long_name"]}[{df.attrs["units"]}]",
        xaxis_title=f"{df.index.name}",
        legend=dict(yanchor="top", y=0.99, xanchor="right", x=.9)
    )

    return fig


def figure_with_text(figure, title, description, fig_key, text_position="right"):
    plot = html.Div(
        className="box plot-box",
        children=dcc.Graph(
            id={"type":"gas-figure","key":fig_key},
            figure=figure,
            config={"displayModeBar": False, "responsive": False},
            style = {"width": "98%","height":'100%'},
        )
    )

    text = html.Div(
        className="box text-box",
        children=[html.H3(title), html.P(description)]
    )

    return html.Div(
        className="figure-row",
        children=[plot, text] if text_position == "right" else [text, plot]
    )