(evidence: GalaxyEvidence, language: 'en' | 'de')
| 26 | const totals = (items: readonly { type: string; count: number }[]) => items.slice(0, TYPES_PER_SIDE).map(item => `${item.type} ${item.count}`).join(', '); |
| 27 | |
| 28 | export function viewAnswer(evidence: GalaxyEvidence, language: 'en' | 'de'): string { |
| 29 | const words = relationshipWords[language], text = viewText[language]; |
| 30 | const hierarchy = evidence.display === 'hierarchy'; |
| 31 | const [first] = evidence.roots; |
| 32 | const single = evidence.rootCount <= 1 && first !== undefined; |
| 33 | const center = text.center(quote(single ? nodeDisplayName(first, words.nodeNames) : selectionName(evidence, words)), words.kindName((single ? first.kind : undefined) ?? evidence.selectionKind), single ? 1 : evidence.rootCount); |
| 34 | const { direction, types, state } = scopeParts(evidence, words); |
| 35 | const reach = evidence.depth === 0 ? text.selectionOnly : text.reach(words.hops(evidence.depth), direction, evidence.direction === 'both'); |
| 36 | const side = (name: 'incoming' | 'outgoing'): string => { |
| 37 | if (!sideLoaded(evidence, name)) return name === 'incoming' ? words.incomingNotLoaded : words.outgoingNotLoaded; |
| 38 | const groups = evidence.relationships[name]; |
| 39 | if (!groups.length) return evidence.truncated ? words.cut(name) : name === 'incoming' ? words.noIncoming : words.noOutgoing; |
| 40 | const lines = groups.slice(0, TYPES_PER_SIDE).map(group => typeLine(group, words)); |
| 41 | if (groups.length > TYPES_PER_SIDE) lines.push(`- ${words.moreTypes(groups.length - TYPES_PER_SIDE)}`); |
| 42 | return `${text.side(name, hierarchy)}\n${lines.join('\n')}`; |
| 43 | }; |
| 44 | const { internal, beyond } = evidence.relationships; |
| 45 | // The picture is read in the view the reader has; where the evidence does not say which, nothing is said about it. |
| 46 | const reading = evidence.display === 'hierarchy' ? text.readHierarchy(evidence.direction, evidence.depth >= 2) : evidence.display === 'galaxy' ? text.readGalaxy : undefined; |
| 47 | return [ |
| 48 | `${center}; ${reach}.`, |
| 49 | ...evidence.depth === 0 ? [words.notExpanded] : [side('incoming'), side('outgoing')], |
| 50 | ...internal.length ? [words.internal(totals(internal))] : [], |
| 51 | ...beyond.length ? [words.beyond(totals(beyond))] : [], |
| 52 | ...reading ? [reading] : [], |
| 53 | text.size(words.size(evidence.nodes, evidence.edges), types, state), |
| 54 | ...evidence.state === 'loading' ? [words.stillLoading] : [], |
| 55 | `_${words.listedFromGraph}_`, |
| 56 | ].join('\n\n'); |
| 57 | } |
no test coverage detected