Ludvig
commited on
Commit
·
224f15f
1
Parent(s):
148c712
More improvements for design section
Browse files
app.py
CHANGED
|
@@ -318,6 +318,28 @@ if st.session_state["step"] >= 2:
|
|
| 318 |
)
|
| 319 |
|
| 320 |
if st.session_state["step"] >= 3:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
plotting_args = [
|
| 322 |
"--data_path",
|
| 323 |
f"'{data_store_path}'",
|
|
|
|
| 318 |
)
|
| 319 |
|
| 320 |
if st.session_state["step"] >= 3:
|
| 321 |
+
# TODO Fix and update these flags
|
| 322 |
+
element_flags = [
|
| 323 |
+
key
|
| 324 |
+
for key, val in {
|
| 325 |
+
"--add_counts": design_settings["show_counts"],
|
| 326 |
+
"--add_normalized": design_settings["show_normalized"],
|
| 327 |
+
"--add_sums": design_settings["show_sums"],
|
| 328 |
+
"--add_row_percentages": design_settings["show_row_percentages"],
|
| 329 |
+
"--add_col_percentages": design_settings["show_col_percentages"],
|
| 330 |
+
"--add_arrows": design_settings["show_arrows"],
|
| 331 |
+
"--add_zero_percentages": design_settings["show_zero_percentages"],
|
| 332 |
+
"--add_zero_text": design_settings["show_zero_text"],
|
| 333 |
+
"--add_zero_shading": design_settings["show_zero_shading"],
|
| 334 |
+
"--add_tile_border": design_settings["show_tile_border"],
|
| 335 |
+
"--counts_on_top": design_settings["counts_on_top"],
|
| 336 |
+
"--diag_percentages_only": design_settings["diag_percentages_only"],
|
| 337 |
+
"--rotate_y_text": design_settings["rotate_y_text"],
|
| 338 |
+
"--place_x_axis_above": design_settings["place_x_axis_above"],
|
| 339 |
+
}.items()
|
| 340 |
+
if val
|
| 341 |
+
]
|
| 342 |
+
|
| 343 |
plotting_args = [
|
| 344 |
"--data_path",
|
| 345 |
f"'{data_store_path}'",
|
design.py
CHANGED
|
@@ -43,83 +43,93 @@ def design_section(
|
|
| 43 |
else:
|
| 44 |
output["prob_of_class"] = None
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
"Column Percentages",
|
| 58 |
-
]
|
| 59 |
-
elements_to_add = st.multiselect(
|
| 60 |
-
"Add the following elements",
|
| 61 |
-
options=[
|
| 62 |
-
"Sum Tiles",
|
| 63 |
-
"Counts",
|
| 64 |
-
"Normalized Counts (%)",
|
| 65 |
-
"Row Percentages",
|
| 66 |
-
"Column Percentages",
|
| 67 |
-
"Zero Shading",
|
| 68 |
-
"Zero Percentages",
|
| 69 |
-
"Zero Text",
|
| 70 |
-
"Arrows",
|
| 71 |
-
],
|
| 72 |
-
default=default_elements,
|
| 73 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
st.markdown("""---""")
|
| 76 |
|
| 77 |
col1, col2, col3 = st.columns(3)
|
| 78 |
with col1:
|
| 79 |
-
counts_on_top = st.checkbox(
|
| 80 |
"Counts on top (not working)",
|
| 81 |
help="Whether to switch the positions of the counts and normalized counts (%). "
|
| 82 |
"That is, the counts become the big centralized numbers and the "
|
| 83 |
"normalized counts go below with a smaller font size.",
|
| 84 |
)
|
| 85 |
with col2:
|
| 86 |
-
diag_percentages_only = st.checkbox(
|
| 87 |
"Diagonal row/column percentages only"
|
| 88 |
)
|
| 89 |
|
| 90 |
-
with st.expander("Text"):
|
| 91 |
-
col1, col2, col3 = st.columns(3)
|
| 92 |
-
with col1:
|
| 93 |
-
output["num_digits"] = st.number_input(
|
| 94 |
-
"Digits", value=2, help="Number of digits to round percentages to."
|
| 95 |
-
)
|
| 96 |
-
with col2:
|
| 97 |
-
rotate_y_text = st.checkbox("Rotate y text", value=True)
|
| 98 |
-
with col3:
|
| 99 |
-
place_x_axis_above = st.checkbox("Place X axis on top", value=True)
|
| 100 |
-
|
| 101 |
-
with st.expander("Fonts"):
|
| 102 |
-
font_dicts = {}
|
| 103 |
-
for font_type in ["Counts", "Normalized (%)", "Row Percentage", "Column Percentage"]:
|
| 104 |
-
st.subheader(font_type)
|
| 105 |
-
num_cols = 3
|
| 106 |
-
font_dicts[font_type] = font_inputs(key_prefix=font_type)
|
| 107 |
-
for i, (setting_name, setting_widget) in enumerate(
|
| 108 |
-
font_dicts[font_type].items()
|
| 109 |
-
):
|
| 110 |
-
if i % num_cols == 0:
|
| 111 |
-
cols = st.columns(num_cols)
|
| 112 |
-
with cols[i % num_cols]:
|
| 113 |
-
setting_widget()
|
| 114 |
-
|
| 115 |
-
st.markdown("""---""")
|
| 116 |
-
|
| 117 |
with st.expander("Tiles"):
|
| 118 |
col1, col2, col3 = st.columns(3)
|
| 119 |
with col1:
|
| 120 |
pass
|
| 121 |
with col2:
|
| 122 |
-
output["intensity_by"] = st.selectbox(
|
|
|
|
|
|
|
| 123 |
with col3:
|
| 124 |
output["darkness"] = st.slider(
|
| 125 |
"Darkness",
|
|
@@ -134,7 +144,9 @@ def design_section(
|
|
| 134 |
|
| 135 |
col1, col2, col3, col4 = st.columns(4)
|
| 136 |
with col1:
|
| 137 |
-
output["
|
|
|
|
|
|
|
| 138 |
with col2:
|
| 139 |
output["tile_border_color"] = st.color_picker(
|
| 140 |
"Border color", value="#000000"
|
|
@@ -160,42 +172,55 @@ def design_section(
|
|
| 160 |
],
|
| 161 |
)
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
"
|
| 168 |
-
|
| 169 |
-
"
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
"
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
"
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
if st.form_submit_button(label="Generate plot"):
|
| 201 |
st.session_state["step"] = 3
|
|
|
|
| 43 |
else:
|
| 44 |
output["prob_of_class"] = None
|
| 45 |
|
| 46 |
+
output["palette"] = st.selectbox(
|
| 47 |
+
"Color Palette",
|
| 48 |
+
options=["Blues", "Greens", "Oranges", "Greys", "Purples", "Reds"],
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Ask for output parameters
|
| 52 |
+
# TODO: Set default based on number of classes and sum tiles
|
| 53 |
+
col1, col2, col3 = st.columns(3)
|
| 54 |
+
with col1:
|
| 55 |
+
output["width"] = st.number_input(
|
| 56 |
+
"Width (px)", value=1200 + 100 * (num_classes - 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
+
with col2:
|
| 59 |
+
output["height"] = st.number_input(
|
| 60 |
+
"Height (px)", value=1200 + 100 * (num_classes - 2)
|
| 61 |
+
)
|
| 62 |
+
with col3:
|
| 63 |
+
output["dpi"] = st.number_input("DPI (not working)", value=320)
|
| 64 |
+
|
| 65 |
+
with st.expander("Elements"):
|
| 66 |
+
col1, col2, col3 = st.columns(3)
|
| 67 |
+
with col1:
|
| 68 |
+
output["show_counts"] = st.checkbox("Show counts", value=True)
|
| 69 |
+
with col2:
|
| 70 |
+
output["show_normalized"] = st.checkbox(
|
| 71 |
+
"Show normalized (%)", value=True
|
| 72 |
+
)
|
| 73 |
+
with col3:
|
| 74 |
+
output["show_sums"] = st.checkbox("Show sum tiles", value=False)
|
| 75 |
+
|
| 76 |
+
st.markdown("""---""")
|
| 77 |
+
|
| 78 |
+
col1, col2 = st.columns(2)
|
| 79 |
+
with col1:
|
| 80 |
+
st.write("Row and column percentages:")
|
| 81 |
+
output["show_row_percentages"] = st.checkbox(
|
| 82 |
+
"Show row percentages", value=num_classes < 6
|
| 83 |
+
)
|
| 84 |
+
output["show_col_percentages"] = st.checkbox(
|
| 85 |
+
"Show column percentages", value=num_classes < 6
|
| 86 |
+
)
|
| 87 |
+
output["show_arrows"] = st.checkbox("Show arrows", value=True)
|
| 88 |
+
with col2:
|
| 89 |
+
output["arrow_size"] = (
|
| 90 |
+
st.slider(
|
| 91 |
+
"Arrow size",
|
| 92 |
+
value=0.048 * 10,
|
| 93 |
+
min_value=0.03 * 10,
|
| 94 |
+
max_value=0.06 * 10,
|
| 95 |
+
step=0.001 * 10,
|
| 96 |
+
)
|
| 97 |
+
/ 10
|
| 98 |
+
)
|
| 99 |
+
output["arrow_nudge_from_text"] = (
|
| 100 |
+
st.slider(
|
| 101 |
+
"Arrow nudge from text",
|
| 102 |
+
value=0.065 * 10,
|
| 103 |
+
min_value=0.00,
|
| 104 |
+
max_value=0.1 * 10,
|
| 105 |
+
step=0.001 * 10,
|
| 106 |
+
)
|
| 107 |
+
/ 10
|
| 108 |
+
)
|
| 109 |
|
| 110 |
st.markdown("""---""")
|
| 111 |
|
| 112 |
col1, col2, col3 = st.columns(3)
|
| 113 |
with col1:
|
| 114 |
+
output["counts_on_top"] = st.checkbox(
|
| 115 |
"Counts on top (not working)",
|
| 116 |
help="Whether to switch the positions of the counts and normalized counts (%). "
|
| 117 |
"That is, the counts become the big centralized numbers and the "
|
| 118 |
"normalized counts go below with a smaller font size.",
|
| 119 |
)
|
| 120 |
with col2:
|
| 121 |
+
output["diag_percentages_only"] = st.checkbox(
|
| 122 |
"Diagonal row/column percentages only"
|
| 123 |
)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
with st.expander("Tiles"):
|
| 126 |
col1, col2, col3 = st.columns(3)
|
| 127 |
with col1:
|
| 128 |
pass
|
| 129 |
with col2:
|
| 130 |
+
output["intensity_by"] = st.selectbox(
|
| 131 |
+
"Intensity based on", options=["Counts", "Normalized (%)"]
|
| 132 |
+
)
|
| 133 |
with col3:
|
| 134 |
output["darkness"] = st.slider(
|
| 135 |
"Darkness",
|
|
|
|
| 144 |
|
| 145 |
col1, col2, col3, col4 = st.columns(4)
|
| 146 |
with col1:
|
| 147 |
+
output["show_tile_border"] = st.checkbox(
|
| 148 |
+
"Add tile borders", value=False
|
| 149 |
+
)
|
| 150 |
with col2:
|
| 151 |
output["tile_border_color"] = st.color_picker(
|
| 152 |
"Border color", value="#000000"
|
|
|
|
| 172 |
],
|
| 173 |
)
|
| 174 |
|
| 175 |
+
with st.expander("Zero Counts"):
|
| 176 |
+
st.write("Special settings for tiles where the count is 0:")
|
| 177 |
+
col1, col2, col3 = st.columns(3)
|
| 178 |
+
with col1:
|
| 179 |
+
output["show_zero_shading"] = st.checkbox("Add shading", value=True)
|
| 180 |
+
with col2:
|
| 181 |
+
output["show_zero_text"] = st.checkbox(
|
| 182 |
+
"Show text",
|
| 183 |
+
value=False,
|
| 184 |
+
help="Whether to show counts, normalized (%), etc.",
|
| 185 |
+
)
|
| 186 |
+
with col3:
|
| 187 |
+
output["show_zero_percentages"] = st.checkbox(
|
| 188 |
+
"Show row/column percentages",
|
| 189 |
+
value=False,
|
| 190 |
+
help="Only relevant when row/column percentages are enabled.",
|
| 191 |
+
)
|
| 192 |
|
| 193 |
+
with st.expander("Text"):
|
| 194 |
+
col1, col2, col3 = st.columns(3)
|
| 195 |
+
with col1:
|
| 196 |
+
output["num_digits"] = st.number_input(
|
| 197 |
+
"Digits", value=2, help="Number of digits to round percentages to."
|
| 198 |
+
)
|
| 199 |
+
with col2:
|
| 200 |
+
output["rotate_y_text"] = st.checkbox("Rotate y text", value=True)
|
| 201 |
+
with col3:
|
| 202 |
+
output["place_x_axis_above"] = st.checkbox(
|
| 203 |
+
"Place X axis on top", value=True
|
| 204 |
+
)
|
| 205 |
|
| 206 |
+
with st.expander("Fonts"):
|
| 207 |
+
font_dicts = {}
|
| 208 |
+
for font_type in [
|
| 209 |
+
"Counts",
|
| 210 |
+
"Normalized (%)",
|
| 211 |
+
"Row Percentage",
|
| 212 |
+
"Column Percentage",
|
| 213 |
+
]:
|
| 214 |
+
st.subheader(font_type)
|
| 215 |
+
num_cols = 3
|
| 216 |
+
font_dicts[font_type] = font_inputs(key_prefix=font_type)
|
| 217 |
+
for i, (_, setting_widget) in enumerate(font_dicts[font_type].items()):
|
| 218 |
+
if i % num_cols == 0:
|
| 219 |
+
cols = st.columns(num_cols)
|
| 220 |
+
with cols[i % num_cols]:
|
| 221 |
+
setting_widget()
|
| 222 |
+
|
| 223 |
+
st.markdown("""---""")
|
| 224 |
|
| 225 |
if st.form_submit_button(label="Generate plot"):
|
| 226 |
st.session_state["step"] = 3
|