SupPepper commited on
Commit
d09ba91
·
1 Parent(s): b4fea55

Update index.html

Browse files
Files changed (1) hide show
  1. frontend/index.html +41 -21
frontend/index.html CHANGED
@@ -664,28 +664,48 @@ function renderRelations() {
664
  // --- section 2: NPC↔NPC bond graph + directed list ---
665
  let graphHtml = "";
666
  if (knownChars.length >= 2) {
667
- // Group bonds by unordered pair so we can show both directions together
668
- const pairMap = {};
669
- for (const b of npcBonds) {
670
- const key = [b.source_id, b.target_id].sort().join("|");
671
- if (!pairMap[key]) pairMap[key] = [];
672
- pairMap[key].push(b);
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  }
674
- const bondListHtml = Object.values(pairMap).map(pairBonds => {
675
- const rows = pairBonds.map(b => {
676
- const col = _bondColor(b.note, b.value);
677
- const sign = b.value > 0 ? "+" : "";
678
- const noteStr = b.note ? b.note : (b.value === 0 ? "neutral" : "");
679
- return `<div class="bond-row">
680
- <span class="bond-name">${b.source_name}</span>
681
- <span class="bond-arrow">→</span>
682
- <span class="bond-name">${b.target_name}</span>
683
- <span class="bond-note" style="color:${col}">${noteStr}</span>
684
- <span class="bond-val" style="color:${col}">${sign}${b.value}</span>
685
- </div>`;
686
- }).join("");
687
- return `<div class="bond-pair">${rows}</div>`;
688
- }).join("") || `<div class="je-empty" style="font-size:.78rem">No bonds recorded yet</div>`;
 
 
 
 
 
 
 
689
 
690
  graphHtml = `<div class="rel-section-title">Between them</div>
691
  <div class="bond-graph-wrap">${_buildBondGraph(knownChars, npcBonds)}</div>
 
664
  // --- section 2: NPC↔NPC bond graph + directed list ---
665
  let graphHtml = "";
666
  if (knownChars.length >= 2) {
667
+ // Group bonds by unordered pair; always show BOTH directions (fill missing with neutral 0)
668
+ const bondIndex = {}; // "srcId|tgtId" -> bond object
669
+ for (const b of npcBonds) bondIndex[`${b.source_id}|${b.target_id}`] = b;
670
+
671
+ // Collect all unique unordered pairs from all known characters
672
+ const seenPairs = new Set();
673
+ const pairList = [];
674
+ for (let i = 0; i < knownChars.length; i++) {
675
+ for (let j = i + 1; j < knownChars.length; j++) {
676
+ const a = knownChars[i], b = knownChars[j];
677
+ const key = [a.id, b.id].sort().join("|");
678
+ if (seenPairs.has(key)) continue;
679
+ seenPairs.add(key);
680
+ // Only show pairs where at least one direction has a recorded bond
681
+ const ab = bondIndex[`${a.id}|${b.id}`];
682
+ const ba = bondIndex[`${b.id}|${a.id}`];
683
+ if (!ab && !ba) continue;
684
+ pairList.push({ a, b, ab, ba });
685
+ }
686
  }
687
+
688
+ const _bondRow = (srcName, tgtName, bond) => {
689
+ const val = bond ? bond.value : 0;
690
+ const note = bond ? bond.note : "";
691
+ const col = _bondColor(note, val);
692
+ const sign = val > 0 ? "+" : "";
693
+ const noteStr = note || (val === 0 ? "neutral" : "");
694
+ return `<div class="bond-row">
695
+ <span class="bond-name">${srcName}</span>
696
+ <span class="bond-arrow"></span>
697
+ <span class="bond-name">${tgtName}</span>
698
+ <span class="bond-note" style="color:${col}">${noteStr}</span>
699
+ <span class="bond-val" style="color:${col}">${sign}${val}</span>
700
+ </div>`;
701
+ };
702
+
703
+ const bondListHtml = pairList.map(({ a, b, ab, ba }) =>
704
+ `<div class="bond-pair">
705
+ ${_bondRow(a.name, b.name, ab)}
706
+ ${_bondRow(b.name, a.name, ba)}
707
+ </div>`
708
+ ).join("") || `<div class="je-empty" style="font-size:.78rem">No bonds recorded yet</div>`;
709
 
710
  graphHtml = `<div class="rel-section-title">Between them</div>
711
  <div class="bond-graph-wrap">${_buildBondGraph(knownChars, npcBonds)}</div>