hemsby commited on
Commit
5d2f157
·
1 Parent(s): f30ab62

feat: sidebar attribute panel, DECODE logo, edge hover fix, larger fonts

Browse files

- Replace Select2 dropdown with collapsible left sidebar panel
- Attributes listed with colored dot, name, and category index
- Sortable by Index (desc, default) or Name (alpha), with search filter
- Add DECODE logo (inline SVG) to header
- Bold attribute names and index in sidebar
- Fix edge hover color (add 'hover' property so connected edges stay colored)
- Increase node font sizes (L0: 18, L1: 16, L2: 15, scaling 15-20)
- Remove jQuery/Select2 dependencies

Files changed (1) hide show
  1. build_network.py +188 -85
build_network.py CHANGED
@@ -109,7 +109,7 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
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),
112
- 'font': {'color': COLORS['driver_font'], 'size': 16, 'bold': True},
113
  'shape': 'box', 'borderWidth': 3, 'borderWidthSelected': 4,
114
  })
115
 
@@ -128,7 +128,7 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
128
  'level': 1, 'value': int(cat),
129
  'title': attr + ' — Category Index: ' + str(int(cat)) + ', Correlation: ' + f'{val:.1f}',
130
  'color': get_node_colors(attr),
131
- 'font': {'color': get_font_color(attr), 'size': 14},
132
  'borderWidth': 2,
133
  })
134
  ep = scale_edge(val)
@@ -136,7 +136,8 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
136
  'from': selected, 'to': attr, 'value': float(val),
137
  'width': ep['width'],
138
  'color': {'color': get_edge_color(selected), 'opacity': ep['opacity'],
139
- 'highlight': get_edge_color(selected)},
 
140
  'title': f'{selected} \u2194 {attr}: {val:.1f}',
141
  })
142
 
@@ -157,7 +158,7 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
157
  'level': 2, 'value': int(cat),
158
  'title': attr + ' — Category Index: ' + str(int(cat)) + ', Correlation: ' + f'{val:.1f}',
159
  'color': get_node_colors(attr),
160
- 'font': {'color': get_font_color(attr), 'size': 13},
161
  'borderWidth': 2,
162
  })
163
  l2_added.add(attr)
@@ -166,7 +167,8 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
166
  'from': l1, 'to': attr, 'value': float(val),
167
  'width': ep['width'],
168
  'color': {'color': get_edge_color(l1), 'opacity': ep['opacity'],
169
- 'highlight': get_edge_color(l1)},
 
170
  'title': f'{l1} \u2194 {attr}: {val:.1f}',
171
  })
172
 
@@ -183,11 +185,17 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
183
 
184
  chart_title = f"DECODE_{client_name}_{country_name}_{brand_name}"
185
 
186
- # Build driver options HTML
187
- driver_options = ""
188
- for i, nodes_list in enumerate(all_nodes):
189
- if nodes_list:
190
- driver_options += f'<option value="{i}">{nodes_list[0]["id"]}</option>\n'
 
 
 
 
 
 
191
 
192
  # Count rewards vs nonrewards in drivers
193
  reward_drivers = sum(1 for d in available_drivers if is_reward(d))
@@ -198,7 +206,7 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
198
  chart_title=chart_title,
199
  all_nodes=all_nodes,
200
  all_edges=all_edges,
201
- driver_options=driver_options,
202
  threshold=threshold,
203
  attribute_count=len(attribute_names),
204
  reward_drivers=reward_drivers,
@@ -221,7 +229,7 @@ def generate_network_html(network_data, threshold, max_l1_nodes,
221
  return html, stats, filename
222
 
223
 
224
- def _build_html_template(*, chart_title, all_nodes, all_edges, driver_options,
225
  threshold, attribute_count, reward_drivers, nonreward_drivers,
226
  corr_count, avg_corr, max_corr):
227
  """Build the standalone HTML string. Separated for readability."""
@@ -232,36 +240,66 @@ def _build_html_template(*, chart_title, all_nodes, all_edges, driver_options,
232
  <meta charset="utf-8">
233
  <title>{chart_title} — Association Network</title>
234
  <link type="text/css" href="https://unpkg.com/vis-network@9.1.9/dist/dist/vis-network.min.css" rel="stylesheet" />
235
- <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
236
- <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
237
- <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
238
  <script src="https://unpkg.com/vis-network@9.1.9/dist/vis-network.min.js"></script>
239
  <style>
240
  * {{ box-sizing: border-box; margin: 0; padding: 0; }}
241
  body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f8f9fa; color: #333; }}
242
 
243
- .header {{ background: #fff; border-bottom: 1px solid #e0e0e0; padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }}
 
244
  .header-left h1 {{ font-size: 18px; font-weight: 600; color: #1a1a1a; }}
245
  .header-left .subtitle {{ font-size: 13px; color: #888; margin-top: 2px; }}
 
246
 
247
- .toolbar {{ background: #fff; border-bottom: 1px solid #e0e0e0; padding: 10px 24px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }}
248
- .toolbar label {{ font-size: 13px; font-weight: 500; color: #555; }}
249
- .select2-container {{ min-width: 320px; }}
250
- .select2-container .select2-selection--single {{ height: 36px; border-radius: 6px; border-color: #ccc; }}
251
- .select2-container--default .select2-selection--single .select2-selection__rendered {{ line-height: 34px; font-size: 14px; padding-left: 12px; }}
252
- .select2-container--default .select2-selection--single .select2-selection__arrow {{ height: 34px; }}
253
- .select2-results__option {{ font-size: 14px; }}
254
- .stat {{ font-size: 13px; color: #888; }}
255
- .stat strong {{ color: #333; }}
256
-
257
- .legend-bar {{ display: flex; align-items: center; gap: 16px; margin-left: auto; }}
258
  .legend-item {{ display: flex; align-items: center; gap: 5px; font-size: 12px; color: #666; }}
259
  .legend-dot {{ width: 12px; height: 12px; border-radius: 3px; border: 2px solid; }}
260
  .legend-dot.reward {{ border-color: {COLORS['reward_border']}; background: {COLORS['reward_bg']}; }}
261
  .legend-dot.nonreward {{ border-color: {COLORS['nonreward_border']}; background: {COLORS['nonreward_bg']}; }}
262
  .legend-dot.driver {{ border-color: #000; background: {COLORS['driver_bg']}; }}
263
 
264
- #mynetwork {{ width: 100%; height: calc(100vh - 130px); background: #fff; }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
 
266
  .tabs {{ position: absolute; bottom: 16px; left: 24px; z-index: 10; display: flex; gap: 4px; }}
267
  .tab-btn {{ padding: 6px 14px; font-size: 12px; font-weight: 500; border: 1px solid #ddd; background: #fff; border-radius: 6px; cursor: pointer; color: #555; transition: all 0.15s; }}
@@ -280,23 +318,25 @@ body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans
280
  .detail-card h4 {{ font-size: 12px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }}
281
  .detail-card p {{ font-size: 13px; line-height: 1.5; color: #444; }}
282
  .detail-card .val {{ font-size: 20px; font-weight: 600; color: #1a1a1a; }}
283
-
284
- .canvas-wrap {{ position: relative; flex: 1; }}
285
  </style>
286
  <script>
287
- var nodes = {json.dumps(all_nodes)};
288
- var edges = {json.dumps(all_edges)};
 
289
  var network = null;
 
 
290
 
291
  function destroy() {{ if (network !== null) {{ network.destroy(); network = null; }} }}
292
 
293
  function draw(id) {{
294
  destroy();
295
- var data = {{ nodes: nodes[id], edges: edges[id] }};
 
296
  var options = {{
297
  nodes: {{
298
  shape: 'box',
299
- scaling: {{ min: 40, max: 90, label: {{ enabled: true, min: 14, max: 18 }} }},
300
  font: {{ size: 14, face: '-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif', multi: 'md' }},
301
  margin: {{ top: 8, bottom: 8, left: 12, right: 12 }},
302
  shadow: {{ enabled: true, color: 'rgba(0,0,0,0.08)', size: 6, x: 0, y: 2 }},
@@ -373,6 +413,56 @@ function draw(id) {{
373
  }});
374
  edgesDS.update(eUp);
375
  }});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  }}
377
 
378
  function toggleDetails() {{
@@ -382,10 +472,11 @@ function toggleDetails() {{
382
  btn.classList.toggle('active');
383
  }}
384
 
385
- $(document).ready(function() {{
386
- $('#driver_select').select2({{ placeholder: 'Search for an attribute...', allowClear: false }});
387
- $('#driver_select').on('change', function() {{ draw($(this).val()); }});
388
- draw(0);
 
389
  }});
390
  </script>
391
  </head>
@@ -393,59 +484,71 @@ $(document).ready(function() {{
393
 
394
  <div class="header">
395
  <div class="header-left">
396
- <h1>{chart_title}</h1>
397
- <div class="subtitle">Association Network</div>
398
- </div>
399
- <div class="header-right">
400
- <div class="legend-bar">
401
- <div class="legend-item"><div class="legend-dot reward"></div> Emotional</div>
402
- <div class="legend-item"><div class="legend-dot nonreward"></div> Functional</div>
403
- <div class="legend-item"><div class="legend-dot driver"></div> Selected</div>
404
  </div>
405
  </div>
 
 
 
 
 
406
  </div>
407
 
408
- <div class="toolbar">
409
- <label>Attribute:</label>
410
- <select id="driver_select">
411
- {driver_options}
412
- </select>
413
- <span class="stat">Attributes: <strong id="nodeCount">0</strong></span>
414
- <span class="stat">Connections: <strong id="edgeCount">0</strong></span>
415
- </div>
416
-
417
- <div class="canvas-wrap">
418
- <div id="mynetwork"></div>
419
- <div class="tabs">
420
- <button class="tab-btn" id="detailsBtn" onclick="toggleDetails()">Details</button>
421
  </div>
422
- <div class="details-panel" id="detailsPanel">
423
- <div class="details-header">
424
- <h3>Technical Details</h3>
425
- <button class="details-close" onclick="toggleDetails()">&times;</button>
 
 
426
  </div>
427
- <div class="details-body">
428
- <div class="details-grid">
429
- <div class="detail-card">
430
- <h4>Threshold</h4>
431
- <div class="val">{threshold}</div>
432
- <p>Only associations above this deviation value are shown as connections.</p>
433
- </div>
434
- <div class="detail-card">
435
- <h4>Attributes</h4>
436
- <div class="val">{attribute_count}</div>
437
- <p>{reward_drivers} emotional (rewards) and {nonreward_drivers} functional (nonrewards) attributes.</p>
438
- </div>
439
- <div class="detail-card">
440
- <h4>Connections</h4>
441
- <div class="val">{corr_count}</div>
442
- <p>Total attribute pairs above threshold. Avg: {avg_corr:.1f}, Max: {max_corr:.1f}</p>
443
- </div>
444
- <div class="detail-card">
445
- <h4>How to Read</h4>
446
- <p>Each node is a brand association. Lines connect associations that co-occur above average.
447
- Thicker lines = stronger co-occurrence. Node size reflects Category Index (importance).
448
- Hover over nodes and lines for details.</p>
 
 
 
 
 
 
 
 
 
 
449
  </div>
450
  </div>
451
  </div>
 
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),
112
+ 'font': {'color': COLORS['driver_font'], 'size': 18, 'bold': True},
113
  'shape': 'box', 'borderWidth': 3, 'borderWidthSelected': 4,
114
  })
115
 
 
128
  'level': 1, 'value': int(cat),
129
  'title': attr + ' — Category Index: ' + str(int(cat)) + ', Correlation: ' + f'{val:.1f}',
130
  'color': get_node_colors(attr),
131
+ 'font': {'color': get_font_color(attr), 'size': 16},
132
  'borderWidth': 2,
133
  })
134
  ep = scale_edge(val)
 
136
  'from': selected, 'to': attr, 'value': float(val),
137
  'width': ep['width'],
138
  'color': {'color': get_edge_color(selected), 'opacity': ep['opacity'],
139
+ 'highlight': get_edge_color(selected),
140
+ 'hover': get_edge_color(selected)},
141
  'title': f'{selected} \u2194 {attr}: {val:.1f}',
142
  })
143
 
 
158
  'level': 2, 'value': int(cat),
159
  'title': attr + ' — Category Index: ' + str(int(cat)) + ', Correlation: ' + f'{val:.1f}',
160
  'color': get_node_colors(attr),
161
+ 'font': {'color': get_font_color(attr), 'size': 15},
162
  'borderWidth': 2,
163
  })
164
  l2_added.add(attr)
 
167
  'from': l1, 'to': attr, 'value': float(val),
168
  'width': ep['width'],
169
  'color': {'color': get_edge_color(l1), 'opacity': ep['opacity'],
170
+ 'highlight': get_edge_color(l1),
171
+ 'hover': get_edge_color(l1)},
172
  'title': f'{l1} \u2194 {attr}: {val:.1f}',
173
  })
174
 
 
185
 
186
  chart_title = f"DECODE_{client_name}_{country_name}_{brand_name}"
187
 
188
+ # Build driver list with metadata for sidebar
189
+ driver_list = []
190
+ for i, driver in enumerate(available_drivers):
191
+ if all_nodes[i]:
192
+ cat_idx = attr_to_cat_idx.get(driver, 100)
193
+ driver_list.append({
194
+ 'name': driver,
195
+ 'catIdx': int(cat_idx),
196
+ 'isReward': is_reward(driver),
197
+ 'index': i,
198
+ })
199
 
200
  # Count rewards vs nonrewards in drivers
201
  reward_drivers = sum(1 for d in available_drivers if is_reward(d))
 
206
  chart_title=chart_title,
207
  all_nodes=all_nodes,
208
  all_edges=all_edges,
209
+ driver_list=driver_list,
210
  threshold=threshold,
211
  attribute_count=len(attribute_names),
212
  reward_drivers=reward_drivers,
 
229
  return html, stats, filename
230
 
231
 
232
+ def _build_html_template(*, chart_title, all_nodes, all_edges, driver_list,
233
  threshold, attribute_count, reward_drivers, nonreward_drivers,
234
  corr_count, avg_corr, max_corr):
235
  """Build the standalone HTML string. Separated for readability."""
 
240
  <meta charset="utf-8">
241
  <title>{chart_title} — Association Network</title>
242
  <link type="text/css" href="https://unpkg.com/vis-network@9.1.9/dist/dist/vis-network.min.css" rel="stylesheet" />
 
 
 
243
  <script src="https://unpkg.com/vis-network@9.1.9/dist/vis-network.min.js"></script>
244
  <style>
245
  * {{ box-sizing: border-box; margin: 0; padding: 0; }}
246
  body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f8f9fa; color: #333; }}
247
 
248
+ .header {{ background: #fff; border-bottom: 1px solid #e0e0e0; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }}
249
+ .header-left {{ display: flex; align-items: center; gap: 16px; }}
250
  .header-left h1 {{ font-size: 18px; font-weight: 600; color: #1a1a1a; }}
251
  .header-left .subtitle {{ font-size: 13px; color: #888; margin-top: 2px; }}
252
+ .decode-logo {{ height: 22px; width: auto; }}
253
 
254
+ .legend-bar {{ display: flex; align-items: center; gap: 16px; }}
 
 
 
 
 
 
 
 
 
 
255
  .legend-item {{ display: flex; align-items: center; gap: 5px; font-size: 12px; color: #666; }}
256
  .legend-dot {{ width: 12px; height: 12px; border-radius: 3px; border: 2px solid; }}
257
  .legend-dot.reward {{ border-color: {COLORS['reward_border']}; background: {COLORS['reward_bg']}; }}
258
  .legend-dot.nonreward {{ border-color: {COLORS['nonreward_border']}; background: {COLORS['nonreward_bg']}; }}
259
  .legend-dot.driver {{ border-color: #000; background: {COLORS['driver_bg']}; }}
260
 
261
+ .main {{ display: flex; flex: 1; overflow: hidden; }}
262
+
263
+ /* --- Sidebar --- */
264
+ .sidebar {{ width: 280px; min-width: 280px; background: #fff; border-right: 1px solid #e0e0e0; display: flex; flex-direction: column; transition: width 0.2s ease, min-width 0.2s ease; overflow: hidden; }}
265
+ .sidebar.collapsed {{ width: 0; min-width: 0; border-right: none; }}
266
+
267
+ .sidebar-header {{ padding: 12px 14px 8px; border-bottom: 1px solid #eee; flex-shrink: 0; }}
268
+ .sidebar-header h2 {{ font-size: 13px; font-weight: 600; color: #555; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }}
269
+
270
+ .sidebar-search {{ width: 100%; padding: 7px 10px; border: 1px solid #ddd; border-radius: 5px; font-size: 13px; outline: none; }}
271
+ .sidebar-search:focus {{ border-color: #999; }}
272
+
273
+ .sort-bar {{ display: flex; gap: 2px; margin-top: 8px; }}
274
+ .sort-btn {{ flex: 1; padding: 4px 0; font-size: 11px; font-weight: 500; border: 1px solid #ddd; background: #f8f8f8; cursor: pointer; color: #777; transition: all 0.12s; }}
275
+ .sort-btn:first-child {{ border-radius: 4px 0 0 4px; }}
276
+ .sort-btn:last-child {{ border-radius: 0 4px 4px 0; }}
277
+ .sort-btn.active {{ background: #333; color: #fff; border-color: #333; }}
278
+
279
+ .sidebar-list {{ flex: 1; overflow-y: auto; }}
280
+
281
+ .attr-row {{ display: flex; align-items: center; padding: 8px 14px; cursor: pointer; border-bottom: 1px solid #f0f0f0; transition: background 0.1s; gap: 8px; }}
282
+ .attr-row:hover {{ background: #f5f7fa; }}
283
+ .attr-row.selected {{ background: #eef2f7; }}
284
+ .attr-dot {{ width: 8px; height: 8px; border-radius: 2px; border: 2px solid; flex-shrink: 0; }}
285
+ .attr-dot.reward {{ border-color: {COLORS['reward_border']}; background: {COLORS['reward_bg']}; }}
286
+ .attr-dot.nonreward {{ border-color: {COLORS['nonreward_border']}; background: {COLORS['nonreward_bg']}; }}
287
+ .attr-name {{ flex: 1; font-size: 13px; font-weight: 600; color: #333; line-height: 1.3; }}
288
+ .attr-idx {{ font-size: 12px; font-weight: 700; color: #888; min-width: 28px; text-align: right; flex-shrink: 0; }}
289
+
290
+ .sidebar-stats {{ padding: 10px 14px; border-top: 1px solid #eee; font-size: 12px; color: #999; flex-shrink: 0; }}
291
+
292
+ /* --- Collapse toggle --- */
293
+ .collapse-btn {{ position: absolute; top: 50%; left: 0; transform: translateY(-50%); z-index: 15; width: 20px; height: 48px; background: #fff; border: 1px solid #ddd; border-left: none; border-radius: 0 6px 6px 0; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #888; transition: all 0.15s; }}
294
+ .collapse-btn:hover {{ background: #f0f0f0; color: #333; }}
295
+
296
+ /* --- Canvas --- */
297
+ .canvas-wrap {{ position: relative; flex: 1; }}
298
+ #mynetwork {{ width: 100%; height: 100%; background: #fff; }}
299
+
300
+ .status-bar {{ position: absolute; top: 12px; right: 16px; z-index: 10; display: flex; gap: 12px; }}
301
+ .stat {{ font-size: 12px; color: #aaa; background: rgba(255,255,255,0.9); padding: 4px 10px; border-radius: 4px; border: 1px solid #eee; }}
302
+ .stat strong {{ color: #555; }}
303
 
304
  .tabs {{ position: absolute; bottom: 16px; left: 24px; z-index: 10; display: flex; gap: 4px; }}
305
  .tab-btn {{ padding: 6px 14px; font-size: 12px; font-weight: 500; border: 1px solid #ddd; background: #fff; border-radius: 6px; cursor: pointer; color: #555; transition: all 0.15s; }}
 
318
  .detail-card h4 {{ font-size: 12px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }}
319
  .detail-card p {{ font-size: 13px; line-height: 1.5; color: #444; }}
320
  .detail-card .val {{ font-size: 20px; font-weight: 600; color: #1a1a1a; }}
 
 
321
  </style>
322
  <script>
323
+ var allNetworkNodes = {json.dumps(all_nodes)};
324
+ var allNetworkEdges = {json.dumps(all_edges)};
325
+ var driverList = {json.dumps(driver_list)};
326
  var network = null;
327
+ var currentSort = 'index'; // 'index' or 'name'
328
+ var selectedIdx = 0;
329
 
330
  function destroy() {{ if (network !== null) {{ network.destroy(); network = null; }} }}
331
 
332
  function draw(id) {{
333
  destroy();
334
+ selectedIdx = id;
335
+ var data = {{ nodes: allNetworkNodes[id], edges: allNetworkEdges[id] }};
336
  var options = {{
337
  nodes: {{
338
  shape: 'box',
339
+ scaling: {{ min: 40, max: 90, label: {{ enabled: true, min: 15, max: 20 }} }},
340
  font: {{ size: 14, face: '-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif', multi: 'md' }},
341
  margin: {{ top: 8, bottom: 8, left: 12, right: 12 }},
342
  shadow: {{ enabled: true, color: 'rgba(0,0,0,0.08)', size: 6, x: 0, y: 2 }},
 
413
  }});
414
  edgesDS.update(eUp);
415
  }});
416
+
417
+ highlightSidebarRow(id);
418
+ }}
419
+
420
+ function highlightSidebarRow(id) {{
421
+ var rows = document.querySelectorAll('.attr-row');
422
+ rows.forEach(function(r) {{ r.classList.remove('selected'); }});
423
+ var active = document.querySelector('.attr-row[data-index="' + id + '"]');
424
+ if (active) {{
425
+ active.classList.add('selected');
426
+ active.scrollIntoView({{ block: 'nearest' }});
427
+ }}
428
+ }}
429
+
430
+ function renderSidebar() {{
431
+ var search = document.getElementById('sidebarSearch').value.toLowerCase();
432
+ var sorted = driverList.slice();
433
+
434
+ if (currentSort === 'index') {{
435
+ sorted.sort(function(a, b) {{ return b.catIdx - a.catIdx; }});
436
+ }} else {{
437
+ sorted.sort(function(a, b) {{ return a.name.toLowerCase().localeCompare(b.name.toLowerCase()); }});
438
+ }}
439
+
440
+ var html = '';
441
+ sorted.forEach(function(d) {{
442
+ if (search && d.name.toLowerCase().indexOf(search) === -1) return;
443
+ var cls = d.isReward ? 'reward' : 'nonreward';
444
+ var sel = d.index === selectedIdx ? ' selected' : '';
445
+ html += '<div class="attr-row' + sel + '" data-index="' + d.index + '" onclick="draw(' + d.index + ')">'
446
+ + '<div class="attr-dot ' + cls + '"></div>'
447
+ + '<span class="attr-name">' + d.name + '</span>'
448
+ + '<span class="attr-idx">' + d.catIdx + '</span>'
449
+ + '</div>';
450
+ }});
451
+ document.getElementById('sidebarList').innerHTML = html;
452
+ }}
453
+
454
+ function setSort(mode) {{
455
+ currentSort = mode;
456
+ document.querySelectorAll('.sort-btn').forEach(function(b) {{ b.classList.remove('active'); }});
457
+ document.querySelector('.sort-btn[data-sort="' + mode + '"]').classList.add('active');
458
+ renderSidebar();
459
+ }}
460
+
461
+ function toggleSidebar() {{
462
+ var sb = document.getElementById('sidebar');
463
+ var btn = document.getElementById('collapseBtn');
464
+ sb.classList.toggle('collapsed');
465
+ btn.textContent = sb.classList.contains('collapsed') ? '\\u203A' : '\\u2039';
466
  }}
467
 
468
  function toggleDetails() {{
 
472
  btn.classList.toggle('active');
473
  }}
474
 
475
+ document.addEventListener('DOMContentLoaded', function() {{
476
+ renderSidebar();
477
+ // Default: select first by index (highest catIdx)
478
+ var sorted = driverList.slice().sort(function(a, b) {{ return b.catIdx - a.catIdx; }});
479
+ if (sorted.length > 0) draw(sorted[0].index);
480
  }});
481
  </script>
482
  </head>
 
484
 
485
  <div class="header">
486
  <div class="header-left">
487
+ <svg class="decode-logo" viewBox="0 0 160 21" xmlns="http://www.w3.org/2000/svg"><path d="M0,0.69 L0,19.5 L10.2,19.5 C15.83,19.5 19.72,16.02 19.72,9.81 C19.72,2.8 14.52,0.69 10.2,0.69 L0,0.69 Z M3.78,4.47 L10.2,4.47 C13.14,4.47 15.94,5.59 15.94,10.02 C15.94,13.84 13.51,15.72 10.2,15.72 L3.78,15.72 L3.78,4.47 Z M28.69,0.69 L28.69,19.5 L45.82,19.5 L45.82,15.72 L32.46,15.72 L32.46,11.66 L41.98,11.66 L41.98,7.88 L32.46,7.88 L32.46,4.47 L45.39,4.47 L45.39,0.69 L28.69,0.69 Z M73.57,3.67 C71.57,2.25 68.92,0.11 64.05,0.11 C58.82,0.11 52.72,3.45 52.72,10.1 C52.72,16.63 57.95,20.08 64.27,20.08 C67.18,20.08 71.24,19.1 73.89,17.14 L72.19,13.65 C70.63,14.85 67.65,16.31 64.31,16.31 C58.9,16.31 56.5,13 56.5,10.21 C56.5,7.16 59.22,3.89 63.87,3.89 C67.54,3.89 70.12,5.96 71.35,6.97 L73.57,3.67 Z M92.96,20.08 C100.33,20.08 104.5,15.36 104.5,10.1 C104.5,4.79 100.4,0.11 92.96,0.11 C85.55,0.11 81.41,4.83 81.41,10.1 C81.41,15.36 85.59,20.08 92.96,20.08 Z M92.96,16.31 C88.27,16.31 85.19,13.36 85.19,10.1 C85.19,6.86 88.27,3.89 92.96,3.89 C97.64,3.89 100.73,6.83 100.73,10.1 C100.73,13.36 97.64,16.31 92.96,16.31 Z M113.94,0.69 L113.94,19.5 L124.15,19.5 C129.78,19.5 133.66,16.02 133.66,9.81 C133.66,2.8 128.47,0.69 124.15,0.69 L113.94,0.69 Z M117.72,4.47 L124.15,4.47 C127.09,4.47 129.88,5.59 129.88,10.02 C129.88,13.84 127.45,15.72 124.15,15.72 L117.72,15.72 L117.72,4.47 Z M142.63,0.69 L142.63,19.5 L159.77,19.5 L159.77,15.72 L146.41,15.72 L146.41,11.66 L155.93,11.66 L155.93,7.88 L146.41,7.88 L146.41,4.47 L159.33,4.47 L159.33,0.69 L142.63,0.69 Z" fill="#1a1a1a"/></svg>
488
+ <div>
489
+ <h1>{chart_title}</h1>
490
+ <div class="subtitle">Association Network</div>
 
 
 
 
491
  </div>
492
  </div>
493
+ <div class="legend-bar">
494
+ <div class="legend-item"><div class="legend-dot reward"></div> Emotional</div>
495
+ <div class="legend-item"><div class="legend-dot nonreward"></div> Functional</div>
496
+ <div class="legend-item"><div class="legend-dot driver"></div> Selected</div>
497
+ </div>
498
  </div>
499
 
500
+ <div class="main">
501
+ <div class="sidebar" id="sidebar">
502
+ <div class="sidebar-header">
503
+ <h2>Attributes</h2>
504
+ <input type="text" class="sidebar-search" id="sidebarSearch" placeholder="Filter..." oninput="renderSidebar()">
505
+ <div class="sort-bar">
506
+ <button class="sort-btn active" data-sort="index" onclick="setSort('index')">Index</button>
507
+ <button class="sort-btn" data-sort="name" onclick="setSort('name')">Name</button>
508
+ </div>
509
+ </div>
510
+ <div class="sidebar-list" id="sidebarList"></div>
511
+ <div class="sidebar-stats">{attribute_count} attributes &middot; {reward_drivers} emotional &middot; {nonreward_drivers} functional</div>
 
512
  </div>
513
+
514
+ <div class="canvas-wrap">
515
+ <button class="collapse-btn" id="collapseBtn" onclick="toggleSidebar()">&lsaquo;</button>
516
+ <div class="status-bar">
517
+ <span class="stat">Attributes: <strong id="nodeCount">0</strong></span>
518
+ <span class="stat">Connections: <strong id="edgeCount">0</strong></span>
519
  </div>
520
+ <div id="mynetwork"></div>
521
+ <div class="tabs">
522
+ <button class="tab-btn" id="detailsBtn" onclick="toggleDetails()">Details</button>
523
+ </div>
524
+ <div class="details-panel" id="detailsPanel">
525
+ <div class="details-header">
526
+ <h3>Technical Details</h3>
527
+ <button class="details-close" onclick="toggleDetails()">&times;</button>
528
+ </div>
529
+ <div class="details-body">
530
+ <div class="details-grid">
531
+ <div class="detail-card">
532
+ <h4>Threshold</h4>
533
+ <div class="val">{threshold}</div>
534
+ <p>Only associations above this deviation value are shown as connections.</p>
535
+ </div>
536
+ <div class="detail-card">
537
+ <h4>Attributes</h4>
538
+ <div class="val">{attribute_count}</div>
539
+ <p>{reward_drivers} emotional (rewards) and {nonreward_drivers} functional (nonrewards) attributes.</p>
540
+ </div>
541
+ <div class="detail-card">
542
+ <h4>Connections</h4>
543
+ <div class="val">{corr_count}</div>
544
+ <p>Total attribute pairs above threshold. Avg: {avg_corr:.1f}, Max: {max_corr:.1f}</p>
545
+ </div>
546
+ <div class="detail-card">
547
+ <h4>How to Read</h4>
548
+ <p>Each node is a brand association. Lines connect associations that co-occur above average.
549
+ Thicker lines = stronger co-occurrence. Node size reflects Category Index (importance).
550
+ Hover over nodes and lines for details.</p>
551
+ </div>
552
  </div>
553
  </div>
554
  </div>