| 165 | } |
| 166 | |
| 167 | function fitGraphFact(fact: string, budget: number): string { |
| 168 | if (fact.length <= budget) return fact; |
| 169 | const lines = fact.split('\n'); |
| 170 | const included: string[] = []; |
| 171 | for (const line of lines) { |
| 172 | const note = `${lines.length - included.length - 1} additional graph summary lines omitted.`; |
| 173 | if (included.join('\n').length + line.length + note.length + 2 > budget) break; |
| 174 | included.push(line); |
| 175 | } |
| 176 | const note = `${lines.length - included.length} additional graph summary lines omitted.`; |
| 177 | if (included.length && included.join('\n').length + note.length + 1 <= budget) return [...included, note].join('\n'); |
| 178 | return ''; |
| 179 | } |
| 180 | |
| 181 | /** Relationships of one side: complete totals first, then each edge type with as |
| 182 | * many names as its fair share of the budget holds, then "+N more". */ |