Example #1
0
    def zip_click(feature, n_clicks, contest):
        contest_name = mec_query.get_standard_contest_name(contest)
        class_name = "displayNone"
        header_text = "Error"
        card_contents = bootstrap_stuff.get_floatbox_card_contents("zip")

        if feature:
            header_text = f"ZIP Code {feature['properties']['ZCTA5CE10']}"
            body_contents = [
                html.Strong("Total monetary donations: "),
                html.Span(
                    locale.currency(
                        feature["properties"]["total_monetary_donations_" +
                                              contest_name],
                        grouping=True,
                    )),
            ]
            class_name = "floatbox"
            card_contents = bootstrap_stuff.get_floatbox_card_contents(
                "zip", header_text, body_contents)

        if n_clicks:
            class_name = "displayNone"

        return [card_contents, class_name]
Example #2
0
    def precinct_click(feature, n_clicks, contest):
        contest_name = mec_query.get_standard_contest_name(contest)
        class_name = "displayNone"
        header_text = "Error"
        card_contents = bootstrap_stuff.get_floatbox_card_contents("precinct")

        if feature:
            # print(feature["properties"])
            if ("WARD10" in feature["properties"]
                    and feature["properties"]["WARD10"]):  # STL City precinct
                header_text = f"STL City: Ward {feature['properties']['WARD10']}, Precinct {feature['properties']['PREC10']}"
            elif feature["properties"]["PRECINCTID"]:  # STL County precinct
                header_text = (
                    f"STL County: Precinct {feature['properties']['PRECINCTID']}"
                )
            body_contents = [
                html.Strong("Total monetary donations: "),
                html.Span(
                    locale.currency(
                        feature["properties"]["total_monetary_donations_" +
                                              contest_name],
                        grouping=True,
                    )),
            ]
            class_name = "floatbox"
            card_contents = bootstrap_stuff.get_floatbox_card_contents(
                "precinct", header_text, body_contents)

        if n_clicks:
            class_name = "displayNone"

        return [card_contents, class_name]
Example #3
0
    def neighborhood_click(feature, n_clicks, contest):
        contest_name = mec_query.get_standard_contest_name(contest)
        class_name = "displayNone"
        header_text = "Error"
        card_contents = bootstrap_stuff.get_floatbox_card_contents(
            "neighborhood")

        if feature:
            print(feature)
            if ("NHD_NAME" in feature["properties"]
                    and feature["properties"]["NHD_NAME"]):
                header_text = feature["properties"]["NHD_NAME"]
            else:
                header_text = feature["properties"]["MUNICIPALI"].title()
            body_contents = [
                html.Strong("Total monetary donations: "),
                html.Span(
                    locale.currency(
                        feature["properties"]["total_monetary_donations_" +
                                              contest_name],
                        grouping=True,
                    )),
            ]
            class_name = "floatbox"
            card_contents = bootstrap_stuff.get_floatbox_card_contents(
                "neighborhood", header_text, body_contents)

        if n_clicks:
            class_name = "displayNone"

        return [card_contents, class_name]
Example #4
0
    def zip_click(feature, n_clicks, contest):
        class_name = "displayNone"
        header_text = "Error"
        card_contents = bootstrap_stuff.get_floatbox_card_contents("zip")

        if feature:
            header_text = f"ZIP Code {feature['properties']['ZCTA5CE10']}"
            class_name = "floatbox"
            card_contents = bootstrap_stuff.get_floatbox_card_contents(
                "zip", header_text, contest, feature["properties"])

        if n_clicks:
            class_name = "displayNone"

        return [card_contents, class_name]
Example #5
0
    def neighborhood_click(feature, n_clicks, contest):
        class_name = "displayNone"
        header_text = "Error"
        card_contents = bootstrap_stuff.get_floatbox_card_contents(
            "neighborhood")

        if feature:
            if ("NHD_NAME" in feature["properties"]
                    and feature["properties"]["NHD_NAME"]):
                header_text = feature["properties"]["NHD_NAME"]
            else:
                header_text = feature["properties"]["MUNICIPALI"].title()
            class_name = "floatbox"
            card_contents = bootstrap_stuff.get_floatbox_card_contents(
                "neighborhood", header_text, contest, feature["properties"])

        if n_clicks:
            class_name = "displayNone"

        return [card_contents, class_name]
Example #6
0
    def precinct_click(feature, n_clicks, contest):
        class_name = "displayNone"
        header_text = "Error"
        card_contents = bootstrap_stuff.get_floatbox_card_contents("precinct")

        if feature:
            if ("WARD10" in feature["properties"]
                    and feature["properties"]["WARD10"]):  # STL City precinct
                header_text = (
                    f"STL City: Ward {feature['properties']['WARD10']}, "
                    f" Precinct {feature['properties']['PREC10']}")
            elif feature["properties"]["PRECINCTID"]:  # STL County precinct
                header_text = (
                    f"STL County: Precinct {feature['properties']['PRECINCTID']}"
                )
            class_name = "floatbox"
            card_contents = bootstrap_stuff.get_floatbox_card_contents(
                "precinct", header_text, contest, feature["properties"])

        if n_clicks:
            class_name = "displayNone"

        return [card_contents, class_name]
Example #7
0
def get_map_panel_layout():
    colorbar = get_colorbar()
    stl_center = [38.648, -90.253]
    city_map_style = {"height": "100%", "margin": "none", "display": "block"}
    city_map = html.Div(
        dl.Map(
            children=[
                get_base_toner_tile_layer(),
                dl.LayersControl(
                    children=[
                        dl.BaseLayer(
                            get_precinct_geojson(),
                            name="precinct",
                            id="precinct-baselayer",
                            checked=True,
                        ),
                        dl.BaseLayer(
                            get_neighborhood_geojson(),
                            name="neighborhood",
                            id="neighborhood-baselayer",
                        ),
                        dl.BaseLayer(get_zip_geojson(),
                                     name="zip",
                                     id="zip-baselayer"),
                    ],
                    id="geojson-layer-control",
                ),
                colorbar,
            ],
            zoom=12,
            center=stl_center,
            id="city-map",
        ),
        style=city_map_style,
        id="map",
    )

    precinct_card = dbc.Card(
        children=bootstrap_stuff.get_floatbox_card_contents(
            "precinct",
            "",
            "Mayor",
        ),
        color="dark",
        outline=True,
        id="floatbox-precinct",
        className="displayNone",
    )
    neighborhood_card = dbc.Card(
        children=bootstrap_stuff.get_floatbox_card_contents(
            "neighborhood",
            "",
            "Mayor",
        ),
        color="dark",
        outline=True,
        id="floatbox-neighborhood",
        className="displayNone",
    )
    zip_card = dbc.Card(
        children=bootstrap_stuff.get_floatbox_card_contents(
            "zip", "", "Mayor"),
        color="dark",
        outline=True,
        id="floatbox-zip",
        className="displayNone",
    )

    map_panel_style = {"width": "100%", "display": "block"}
    map_panel = html.Div(
        id="map-panel",
        children=[
            city_map,
            html.Div(
                children=[precinct_card, neighborhood_card, zip_card],
                id="floatbox-holder",
            ),
        ],
        style=map_panel_style,
    )
    return map_panel