Skip to content

Commit

Permalink
#17 fix colors of piechart
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelweinold committed Sep 18, 2024
1 parent f1833c1 commit 8457838
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 46 deletions.
19 changes: 16 additions & 3 deletions app/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,23 @@ def add_branch_information_to_dataframe(df: pd.DataFrame) -> pd.DataFrame:


def create_plotly_figure_piechart(data_dict: dict) -> plotly.graph_objects.Figure:
marker_colors = []
for label in data_dict.keys():
if label == 'Scope 1':
marker_colors.append('#33cc33') # Color for Scope 1
elif label == 'Scope 2':
marker_colors.append('#ffcc00') # Color for Scope 2
elif label == 'Scope 3':
marker_colors.append('#3366ff') # Color for Scope 3
else:
marker_colors.append('#000000') # Default color for other labels

plotly_figure = plotly.graph_objects.Figure(
data=[
plotly.graph_objects.Pie(
labels=[label for label in data_dict.keys()],
values=[value for value in data_dict.values()]
labels=list(data_dict.keys()),
values=list(data_dict.values()),
marker=dict(colors=marker_colors) # Set the colors for the pie chart
)
]
)
Expand Down Expand Up @@ -564,6 +576,7 @@ def button_action_scope_analysis(event):
else:
if widget_float_slider_cutoff.value / 100 != panel_lca_class_instance.graph_traversal_cutoff:
perform_graph_traversal(event)
perform_scope_analysis(event)
else:
panel_lca_class_instance.df_graph_traversal_nodes = widget_tabulator.value
perform_scope_analysis(event)
Expand Down Expand Up @@ -631,7 +644,7 @@ def button_action_scope_analysis(event):

# https://panel.holoviz.org/reference/widgets/Button.html
widget_button_graph = pn.widgets.Button(
name='Perform Scope Analysis',
name='Re-Perform Scope Analysis',
icon='chart-donut-3',
button_type='primary',
sizing_mode='stretch_width'
Expand Down
14 changes: 11 additions & 3 deletions dev/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@
location = 'United States'
)

bike_act = bd.utils.get_node(
database = 'USEEIO-1.1',
name = 'Motorcycle, bicycle, and parts; at manufacturer',
type = 'product',
location = 'United States'
)

method_gcc = bd.Method(('Impact Potential', 'GCC'))
lca = bc.LCA(
demand={electricity_activity: 1},
demand={bike_act: 1},
method = method_gcc.name # attention here: it's not the Method object, just its name!!!
)
lca.lci()
Expand Down Expand Up @@ -68,6 +75,7 @@ def nodes_dict_to_dataframe(nodes: dict) -> pd.DataFrame:
'Cumulative': current_node.cumulative_score,
'Direct': current_node.direct_emissions_score,
'Depth': current_node.depth,
'activity_datapackage_id': current_node.activity_datapackage_id
}
)
return pd.DataFrame(list_of_row_dicts)
Expand Down Expand Up @@ -118,8 +126,8 @@ def determine_scope_1_and_2_emissions(df: pd.DataFrame, uid_scope_2: int = 53) -
dict_scope['Scope 2'] = df.loc[
(df['Depth'] == 2)
&
(df['UID'] == uid_scope_2)
]['Cumulative'].values[0]
(df['activity_datapackage_id'] == uid_scope_2)
]['Direct'].values[0]
except:
pass

Expand Down
76 changes: 38 additions & 38 deletions pyodide/index.html

Large diffs are not rendered by default.

Loading

0 comments on commit 8457838

Please sign in to comment.