| from pathlib import Path |
| |
| import faicons as fa |
| from shiny import ui |
| from shared import app_dir |
| import matplotlib.pyplot as plt |
| import numpy as np |
|
|
|
|
| |
| |
|
|
|
|
| def create_nav_button(button_icon, button_label_text, button_link, button_cls = "btn btn-primary"): |
| return ui.tags.a( |
| ui.HTML(f"{fa.icon_svg(button_icon)} {button_label_text}"), |
| href=button_link, |
| class_=button_cls |
| ) |
|
|
| def conlogo(): |
| img = { |
| "src": app_dir / "images" / "logo.png", |
| "style": "width: 80%; height: auto; max-height: 150px; margin-bottom: 0px;" |
| } |
| return img |
|
|
| def vendorlogo(): |
| img = { |
| "src": app_dir / "images" / "logo2.png", |
| "style": "width: 80%; height: auto; max-height: 150px; margin-bottom: 0px;" |
| } |
| return img |
|
|
| def create_bar_chart(categories, values, plottitle = "Bar Chart Example"): |
|
|
| fig, ax = plt.subplots() |
| |
| ax.bar(categories, values) |
| ax.set_title(plottitle) |
| ax.set_ylabel("Values") |
| ax.set_xlabel("Categories") |
|
|
| return fig |
|
|
| def create_pie_chart(labels, sizes, plottitle): |
| |
| |
| |
|
|
| fig, ax = plt.subplots() |
| wedges, texts, autotexts = ax.pie( |
| sizes, |
| |
| labels=labels, |
| autopct="%1.0f%%", |
| startangle=90, |
| |
| textprops=dict(color="black"), |
| wedgeprops=dict(width=0.4) |
| ) |
|
|
| |
| for text, label in zip(autotexts, labels): |
| text.set_color("black") |
| text.set_fontsize(12) |
|
|
| |
| ax.set_title(plottitle, fontsize=16, fontweight="bold") |
| return fig |
|
|
| def create_stacked_bar_chart(categories, intra_napa, into_napa, out_napa): |
| |
| |
| |
| |
| |
|
|
| bar_width = 0.5 |
| x = np.arange(len(categories)) |
|
|
| fig, ax = plt.subplots(figsize=(8, 6)) |
|
|
| |
| ax.bar(x, intra_napa, bar_width, label="Intra-Napa County", color="#70d281") |
| ax.bar(x, into_napa, bar_width, bottom=intra_napa, label="Into Napa County", color="#ff7f0e") |
| ax.bar(x, out_napa, bar_width, bottom=np.array(intra_napa) + np.array(into_napa), label="Out of Napa County", color="#00b3b3") |
|
|
| |
| ax.set_xticks(x) |
| ax.set_xticklabels(categories) |
| ax.set_ylabel("Trips") |
| ax.set_title("Weekday Work Trip Types") |
| ax.legend(loc="upper right") |
|
|
| |
| for i in range(len(categories)): |
| ax.text(x[i], intra_napa[i] / 2, f"{intra_napa[i]}", ha="center", va="center", color="white") |
| ax.text(x[i], intra_napa[i] + into_napa[i] / 2, f"{into_napa[i]}", ha="center", va="center", color="white") |
| ax.text(x[i], intra_napa[i] + into_napa[i] + out_napa[i] / 2, f"{out_napa[i]}", ha="center", va="center", color="white") |
|
|
| plt.tight_layout() |
| return fig |
| |
|
|