Example #1
0
def build_modal(ext_aggs, chart_type, y):
    return [
        build_hoverable(
            html.I(
                className="ico-settings pointer",
                id="open-extended-agg-modal",
                style=show_style(chart_type not in NON_EXT_AGGREGATION
                                 and len(y)),
            ),
            html.Div(html.Span(text("ext_agg_desc")),
                     id="extended-aggregation-tooltip"),
            hover_class="saved-chart-config",
            top="100%",
            additional_classes="mb-auto mt-auto",
        ),
        dcc.Store(id="extended-aggregations", data=ext_aggs),
        dcc.Store(id="prev-open-extended-agg-modal", data=0),
        dcc.Store(id="prev-close-extended-agg-modal", data=0),
        dcc.Store(id="prev-clear-extended-agg-modal", data=0),
        dcc.Store(id="prev-apply-extended-agg-modal", data=0),
        dbc.Modal(
            [
                dbc.ModalHeader(
                    html.Div(
                        [
                            html.Div(
                                text("Extended Aggregations"),
                                className="col mt-auto mb-auto",
                            ),
                            html.Button(
                                html.Span("X"),
                                className="close mr-5",
                                id="close-extended-agg-modal",
                            ),
                        ],
                        className="row",
                    )),
                dbc.ModalBody(build_body(ext_aggs)),
                dbc.ModalFooter([
                    dbc.Button(
                        text("Clear"),
                        id="clear-extended-agg-modal",
                        className="ml-auto",
                    ),
                    dbc.Button(
                        text("Apply"),
                        id="apply-extended-agg-modal",
                    ),
                ]),
            ],
            id="extended-agg-modal",
            size="lg",
            centered=True,
        ),
    ]
Example #2
0
def build_saved_header(config):
    chart_type = config["chart_type"]
    final_data = [
        ("Data ID", config["data_id"]),
        ("Query", config.get("query")),
        ("Chart Type", chart_type),
    ]
    if config.get("agg") not in [None, "raw"]:
        final_data.append(("Aggregation", config["agg"]))

    if chart_type == "maps":
        group_by = config["map_group"]
        map_type = config.get("map_type")
        if map_type == "scattergeo":
            map_props = ["map_type", "lat", "lon", "map_val", "scope", "proj"]
        elif map_type == "mapbox":
            map_props = ["map_type", "lat", "lon", "map_val", "mapbox_style"]
        else:
            map_props = ["map_type", "loc_mode", "loc", "map_val"]
            if config.get("loc_mode") == "geojson-id":
                map_props += ["geojson", "featureidkey"]
        for prop in map_props:
            final_data.append((prop, config.get(prop)))
    elif chart_type == "candlestick":
        group_by = config["cs_group"]
        for prop in ["cs_x", "cs_open", "cs_close", "cs_high", "cs_low"]:
            final_data.append((prop.split("_")[-1], config.get(prop)))
    elif chart_type == "treemap":
        group_by = config["treemap_group"]
        for prop in ["treemap_value", "treemap_label"]:
            final_data.append((prop.split("_")[-1], config.get(prop)))
    else:
        group_by = config.get("group")
        final_data.append(("X-Axis", config["x"]))
        y = make_list(config["y"])
        final_data.append(("Y-Axes" if len(y) > 1 else "Y-Axis", ",".join(y)))
        if chart_type in ZAXIS_CHARTS:
            final_data.append(("z", config.get("z")))
        if chart_type == "scatter" and config["trendline"]:
            final_data.append(("Trendline", "\u2714"))

    if group_by:
        final_data.append(("Group By", ", ".join(make_list(group_by))))
        group_type = config["group_type"]
        final_data.append(("Group Type", group_type))
        if group_type == "bins":
            final_data.append(("Bin Type", config["bin_type"]))
            final_data.append(("Bins", config["bin_val"]))
        else:
            final_data.append(
                ("Selected Groups", ", ".join(make_list(config["groups"]))))

    if config["cpg"]:
        final_data.append(("Chart Per Group", "\u2714"))
    if config["cpy"]:
        final_data.append(("Chart Per Y", "\u2714"))
    if chart_type in ANIMATION_CHARTS and config["animate"]:
        final_data.append(("Animate", "\u2714"))
    if chart_type in ANIMATE_BY_CHARTS and config["animate_by"]:
        final_data.append(
            ("Animate By", ", ".join(make_list(config["animate_by"]))))

    return build_hoverable(
        html.I(className="ico-help-outline"),
        [
            html.B("Chart Configuration"),
            html.Ul(
                [
                    html.Li(
                        [html.B(text(prop)),
                         html.Span(": {}".format(value))],
                        className="mb-0",
                    ) for prop, value in final_data if value is not None
                ],
                className="mb-0",
            ),
        ],
        hover_class="saved-chart-config",
        top="unset",
    )