hemsby commited on
Commit
cf6458e
·
1 Parent(s): e10a1da

feat: add 'Show Category Index' toggle — on by default

Browse files
Files changed (2) hide show
  1. app.py +6 -0
  2. build_network.py +11 -4
app.py CHANGED
@@ -135,6 +135,11 @@ with col2:
135
  value=5,
136
  help="Maximum number of Level 1 connections per node",
137
  )
 
 
 
 
 
138
 
139
  st.markdown("---")
140
 
@@ -198,6 +203,7 @@ if st.button("🚀 Generate HTML Network", disabled=not can_generate, type="prim
198
  country_name.strip(),
199
  brand_name.strip(),
200
  category_name.strip(),
 
201
  )
202
 
203
  st.success("✅ Network generated successfully!")
 
135
  value=5,
136
  help="Maximum number of Level 1 connections per node",
137
  )
138
+ show_category_index = st.checkbox(
139
+ "Show Category Index in labels",
140
+ value=True,
141
+ help="Display the Category Index number on each node. Uncheck for cleaner labels.",
142
+ )
143
 
144
  st.markdown("---")
145
 
 
203
  country_name.strip(),
204
  brand_name.strip(),
205
  category_name.strip(),
206
+ show_category_index=show_category_index,
207
  )
208
 
209
  st.success("✅ Network generated successfully!")
build_network.py CHANGED
@@ -7,7 +7,8 @@ from config import COLORS
7
 
8
 
9
  def generate_network_html(network_data, threshold, max_l1_nodes,
10
- client_name, country_name, brand_name, category_name):
 
11
  """Build the complete HTML file with vis.js network visualization.
12
 
13
  Args:
@@ -86,6 +87,12 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
86
  norm = (corr_val - min_corr) / (max_corr - min_corr)
87
  return {'width': round(1 + norm * 7, 2), 'opacity': round(0.3 + norm * 0.7, 2)}
88
 
 
 
 
 
 
 
89
  # --- Build node/edge data for each driver ---
90
 
91
  def get_nodes_edges(selected):
@@ -98,7 +105,7 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
98
  cat_idx = attr_to_cat_idx.get(selected, 100)
99
  nodes.append({
100
  'id': selected,
101
- 'label': wrap_label(selected),
102
  'level': 0, 'value': int(cat_idx),
103
  'title': selected + ' — Category Index: ' + str(int(cat_idx)),
104
  'color': get_node_colors(selected, is_driver=True),
@@ -117,7 +124,7 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
117
  l1_nodes.append(attr)
118
  cat = attr_to_cat_idx.get(attr, 100)
119
  nodes.append({
120
- 'id': attr, 'label': wrap_label(attr),
121
  'level': 1, 'value': int(cat),
122
  'title': attr + ' — Category Index: ' + str(int(cat)) + ', Correlation: ' + f'{val:.1f}',
123
  'color': get_node_colors(attr),
@@ -146,7 +153,7 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
146
  if attr not in l2_added:
147
  cat = attr_to_cat_idx.get(attr, 100)
148
  nodes.append({
149
- 'id': attr, 'label': wrap_label(attr),
150
  'level': 2, 'value': int(cat),
151
  'title': attr + ' — Category Index: ' + str(int(cat)) + ', Correlation: ' + f'{val:.1f}',
152
  'color': get_node_colors(attr),
 
7
 
8
 
9
  def generate_network_html(network_data, threshold, max_l1_nodes,
10
+ client_name, country_name, brand_name, category_name,
11
+ show_category_index=True):
12
  """Build the complete HTML file with vis.js network visualization.
13
 
14
  Args:
 
87
  norm = (corr_val - min_corr) / (max_corr - min_corr)
88
  return {'width': round(1 + norm * 7, 2), 'opacity': round(0.3 + norm * 0.7, 2)}
89
 
90
+ def make_label(name, cat_idx):
91
+ label = wrap_label(name)
92
+ if show_category_index:
93
+ label += '\n(' + str(int(cat_idx)) + ')'
94
+ return label
95
+
96
  # --- Build node/edge data for each driver ---
97
 
98
  def get_nodes_edges(selected):
 
105
  cat_idx = attr_to_cat_idx.get(selected, 100)
106
  nodes.append({
107
  'id': selected,
108
+ 'label': make_label(selected, cat_idx),
109
  'level': 0, 'value': int(cat_idx),
110
  'title': selected + ' — Category Index: ' + str(int(cat_idx)),
111
  'color': get_node_colors(selected, is_driver=True),
 
124
  l1_nodes.append(attr)
125
  cat = attr_to_cat_idx.get(attr, 100)
126
  nodes.append({
127
+ 'id': attr, 'label': make_label(attr, cat),
128
  'level': 1, 'value': int(cat),
129
  'title': attr + ' — Category Index: ' + str(int(cat)) + ', Correlation: ' + f'{val:.1f}',
130
  'color': get_node_colors(attr),
 
153
  if attr not in l2_added:
154
  cat = attr_to_cat_idx.get(attr, 100)
155
  nodes.append({
156
+ 'id': attr, 'label': make_label(attr, cat),
157
  'level': 2, 'value': int(cat),
158
  'title': attr + ' — Category Index: ' + str(int(cat)) + ', Correlation: ' + f'{val:.1f}',
159
  'color': get_node_colors(attr),