From 5df1d29330b851eb4956d690a956beb6c4385276 Mon Sep 17 00:00:00 2001 From: Benjamin <56401685+MrM0bi@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:16:46 +0100 Subject: [PATCH 1/3] fix(ui): align call flow arrows with host lifelines Lifelines were drawn at the measured centre of each host card, but arrows were laid out with flex ratios by host index, which assumes evenly spaced hosts. Host cards size to their label, so arrow ends drifted off the lifelines. Position arrows from the same measured host centres instead (flowSegmentPx), drop the row's horizontal padding, and remove the arrowhead's trailing border so its tip lands on the line end. The now-unused rightEnd field and single-host styles are removed. Co-Authored-By: Claude Opus 5.5 --- src/ui/src/dashboard/CallFlow.css | 35 +++++++-------------- src/ui/src/dashboard/CallFlow.tsx | 23 +++++--------- src/ui/src/dashboard/flow/FlowItem.test.tsx | 14 ++++++++- src/ui/src/dashboard/flow/FlowItem.tsx | 27 ++++++++-------- src/ui/src/dashboard/flow/flow-data.test.ts | 31 ++++++++++++++++-- src/ui/src/dashboard/flow/flow-data.ts | 31 +++++++++++++++--- 6 files changed, 102 insertions(+), 59 deletions(-) diff --git a/src/ui/src/dashboard/CallFlow.css b/src/ui/src/dashboard/CallFlow.css index 51ef562e..5bd0c9b4 100644 --- a/src/ui/src/dashboard/CallFlow.css +++ b/src/ui/src/dashboard/CallFlow.css @@ -441,8 +441,6 @@ position: relative; overflow: inherit; opacity: 1; - margin-left: var(--flow-left-px, 12px); - margin-right: var(--flow-right-px, 12px); min-width: 0; min-height: 64px; } @@ -459,10 +457,7 @@ .item-flow-packet-container .bg-color-polygon { position: absolute; z-index: 0; - top: 0; - bottom: 0; - left: calc(-1 * var(--flow-left-px, 12px)); - right: calc(-1 * var(--flow-right-px, 12px)); + inset: 0; opacity: 0.28; filter: saturate(120%); pointer-events: none; @@ -470,7 +465,7 @@ .item-flow-packet-container .bg-color-tab { position: absolute; - left: calc(-1 * var(--flow-left-px, 12px)); + left: 0; top: 0; bottom: 0; width: 5px; @@ -478,21 +473,13 @@ pointer-events: none; } -.item-flow-packet-container.single-host .bg-color-polygon { - left: 0; - right: 0; -} - -.item-flow-packet-container.single-host .bg-color-tab { - left: 0; -} - .item-flow-packet { position: relative; z-index: 1; width: 100%; min-width: 0; - padding: 8px 6px 10px; + /* No horizontal padding: the track's x origin must match the host centres' origin. */ + padding: 8px 0 10px; border-bottom: 1px solid color-mix(in oklch, var(--color-border) 55%, transparent); cursor: pointer; transition: background-color 0.15s ease, box-shadow 0.15s ease; @@ -601,18 +588,20 @@ .item-flow-packet .arrow::after { content: ''; position: absolute; - right: -1px; + right: 0; bottom: -6px; - border: 5px solid transparent; - border-left: 12px solid; + /* No trailing border, so the tip lands exactly on the line end (the host lifeline). */ + border-style: solid; + border-color: transparent; + border-width: 5px 0 5px 12px; border-left-color: currentColor; } .item-flow-packet .arrow.left::after { right: initial; - left: -1px; - border: 5px solid transparent; - border-right: 12px solid; + left: 0; + border-color: transparent; + border-width: 5px 12px 5px 0; border-right-color: currentColor; } diff --git a/src/ui/src/dashboard/CallFlow.tsx b/src/ui/src/dashboard/CallFlow.tsx index 712830cf..312597fe 100644 --- a/src/ui/src/dashboard/CallFlow.tsx +++ b/src/ui/src/dashboard/CallFlow.tsx @@ -70,7 +70,9 @@ export default function CallFlow({ items, timeZone, onClickMessage, onShowOtlpEv const innerWidth = Math.max(hosts.length * 220, 560) const innerRef = useRef(null) - const [gridLines, setGridLines] = useState([]) + // Host lifeline x-positions (px from the left of .callflow-inner). Both the + // grid lines and every arrow are positioned from these, so they cannot drift apart. + const [hostCenters, setHostCenters] = useState([]) useLayoutEffect(() => { const el = innerRef.current @@ -87,18 +89,9 @@ export default function CallFlow({ items, timeZone, onClickMessage, onShowOtlpEv const rect = wrapper.getBoundingClientRect() positions.push(rect.left + rect.width / 2 - innerRect.left) }) - setGridLines(positions) - - if (positions.length >= 2) { - el.style.setProperty('--flow-left-px', `${positions[0]}px`) - el.style.setProperty('--flow-right-px', `${innerRect.width - positions[positions.length - 1]}px`) - } else if (positions.length === 1) { - el.style.setProperty('--flow-left-px', `${positions[0]}px`) - el.style.setProperty('--flow-right-px', `${innerRect.width - positions[0] - 280}px`) - } else { - el.style.removeProperty('--flow-left-px') - el.style.removeProperty('--flow-right-px') - } + setHostCenters((prev) => + prev.length === positions.length && prev.every((p, i) => p === positions[i]) ? prev : positions, + ) } measure() @@ -136,7 +129,7 @@ export default function CallFlow({ items, timeZone, onClickMessage, onShowOtlpEv style={{ width: `max(100%, ${innerWidth}px)` }} >
- {gridLines.map((px, i) => ( + {hostCenters.map((px, i) => (
= {}): Fl payloadType: 'SIP', start: 0, middle: 1, - rightEnd: 0, direction, isRadial: false, isLastHost: false, @@ -115,3 +114,16 @@ describe('FlowItem consolidation', () => { expect(onClickItem).not.toHaveBeenCalled() }) }) + +describe('FlowItem geometry', () => { + it('places the arrow segment at the measured host centres', () => { + const { container } = render( + , + ) + const spacer = container.querySelector('.item-flow-track > div:first-child')! + const segment = container.querySelector('.item-flow-segment')! + expect(spacer.style.flex).toBe('0 0 509px') + expect(segment.style.flex).toBe('0 0 401px') + }) +}) diff --git a/src/ui/src/dashboard/flow/FlowItem.tsx b/src/ui/src/dashboard/flow/FlowItem.tsx index 31b7f0a3..99f6a77b 100644 --- a/src/ui/src/dashboard/flow/FlowItem.tsx +++ b/src/ui/src/dashboard/flow/FlowItem.tsx @@ -1,10 +1,12 @@ import type { FlowItemData } from './flow-data' +import { flowSegmentPx } from './flow-data' interface FlowItemProps { item: FlowItemData isSimplify: boolean isAbsoluteTime: boolean - singleHost?: boolean + /** Measured host centres (px from the left edge of the flow), one per host. */ + hostCenters?: readonly number[] onClickItem?: (item: FlowItemData) => void expandedKey?: string | null setExpandedKey?: (key: string | null) => void @@ -15,7 +17,7 @@ export function FlowItem({ item, isSimplify, isAbsoluteTime, - singleHost, + hostCenters, onClickItem, expandedKey, setExpandedKey, @@ -26,17 +28,15 @@ export function FlowItem({ const canToggleSubItems = hasSubItems && typeof setExpandedKey === 'function' const showSubItems = canToggleSubItems && expandedKey === itemKey - const flexStart = item.start || 0.0000001 - const flexMiddle = item.middle || 0.0000001 - const flexRight = item.isRadial - ? Math.max(0.0000001, item.rightEnd - (item.isLastHost ? 0 : 1)) - : item.rightEnd || 0.0000001 + // Until host centres are measured the segment just fills the row; the + // layout effect in CallFlow measures before the first paint. + const segment = hostCenters ? flowSegmentPx(item, hostCenters) : null const arrowColor = item.callidColors.arrowColor const radialDottedClass = item.arrowStyleSolid ? '' : ' dotted' - const containerClass = `item-flow-packet-container${singleHost ? ' single-host' : ''}${ - hasSubItems ? ' consolidated-parent' : '' - }${isSubItem ? ' consolidated-subitem' : ''}` + const containerClass = `item-flow-packet-container${hasSubItems ? ' consolidated-parent' : ''}${ + isSubItem ? ' consolidated-subitem' : '' + }` return ( <> @@ -48,11 +48,11 @@ export function FlowItem({ onClick={() => onClickItem?.(item)} >
-
+
@@ -117,7 +117,6 @@ export function FlowItem({ )} {isSimplify &&
{item.diffStr}
}
-
@@ -128,7 +127,7 @@ export function FlowItem({ item={subItem} isSimplify={isSimplify} isAbsoluteTime={isAbsoluteTime} - singleHost={singleHost} + hostCenters={hostCenters} onClickItem={onClickItem} expandedKey={expandedKey} setExpandedKey={setExpandedKey} diff --git a/src/ui/src/dashboard/flow/flow-data.test.ts b/src/ui/src/dashboard/flow/flow-data.test.ts index f2cff4dc..c8a8cc32 100644 --- a/src/ui/src/dashboard/flow/flow-data.test.ts +++ b/src/ui/src/dashboard/flow/flow-data.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest' import { buildFlow, buildHosts, endpointAlias, hostKey, hostKeyFromMessage, runtimeFingerprintOf, captureIdOf, consolidateFlowItems, canConsolidateFlowItems, - payloadTypeOf, + payloadTypeOf, flowSegmentPx, } from './flow-data' import type { FlowItemData, RawMessage } from './flow-data' @@ -101,7 +101,7 @@ function makeFlowItem(overrides: Partial & { ts?: number } = {}): dstIp: '10.0.0.2', srcPort: 5060, dstPort: 5060, callid: 'c1', callidColors: { color: '#000', tabColor: '#000', arrowColor: '#000' }, methodColor: '#000', timeStr: '', fullDateStr: '', diffStr: '', - protoLabel: '', payloadType: 'SIP', start: 0, middle: 1, rightEnd: 0, + protoLabel: '', payloadType: 'SIP', start: 0, middle: 1, direction: false, isRadial: false, isLastHost: false, arrowStyleSolid: true, raw: { timestamp: ts ?? new Date('2026-01-01T00:00:00Z').getTime() }, runtimeFingerprint: 'fp1', @@ -282,3 +282,30 @@ describe('buildFlow RTCP rows', () => { expect(flowItems[0].arrowStyleSolid).toBe(false) }) }) + +describe('flowSegmentPx', () => { + // Unevenly spaced lifelines, as produced by host cards of different widths. + const centers = [85, 509, 910, 1314, 1755] + const seg = (o: Partial) => + flowSegmentPx({ start: 0, middle: 1, isRadial: false, isLastHost: false, ...o }, centers) + + it('spans exactly between the measured centres of the two hosts', () => { + expect(seg({ start: 1, middle: 1 })).toEqual({ left: 509, width: 401 }) + expect(seg({ start: 2, middle: 2 })).toEqual({ left: 910, width: 845 }) + }) + + it('loops a self-message towards the next host, or the previous one for the last host', () => { + expect(seg({ start: 2, isRadial: true })).toEqual({ left: 910, width: 404 }) + expect(seg({ start: 4, isRadial: true, isLastHost: true })).toEqual({ left: 1314, width: 441 }) + }) + + it('uses a fixed loop width when there is a single host', () => { + expect(flowSegmentPx({ start: 0, middle: 1, isRadial: true, isLastHost: false }, [300])) + .toEqual({ left: 300, width: 280 }) + }) + + it('returns null until the needed centres are measured', () => { + expect(flowSegmentPx({ start: 0, middle: 1, isRadial: false, isLastHost: false }, [])).toBeNull() + expect(flowSegmentPx({ start: 0, middle: 2, isRadial: false, isLastHost: false }, [10, 20])).toBeNull() + }) +}) diff --git a/src/ui/src/dashboard/flow/flow-data.ts b/src/ui/src/dashboard/flow/flow-data.ts index 2aceb40b..3f7a7dab 100644 --- a/src/ui/src/dashboard/flow/flow-data.ts +++ b/src/ui/src/dashboard/flow/flow-data.ts @@ -63,7 +63,6 @@ export interface FlowItemData { payloadType: string start: number middle: number - rightEnd: number direction: boolean isRadial: boolean isLastHost: boolean @@ -266,7 +265,6 @@ function adoptParentGeometry(parent: FlowItemData, child: FlowItemData): FlowIte ...child, start: parent.start, middle: parent.middle, - rightEnd: parent.rightEnd, direction: parent.direction, isRadial: parent.isRadial, isLastHost: parent.isLastHost, @@ -578,7 +576,6 @@ export function buildFlow(items: RawMessage[] | null | undefined, opts: BuildOpt const start = singleHost ? 0 : Math.min(a, b) const middle = Math.abs(a - b) || 1 const direction = isLastHost || a > b - const rightEnd = singleHost ? 0 : hosts.length - 1 - Math.max(a, b) const arrowStyleSolid = payloadType === 'SIP' @@ -629,7 +626,6 @@ export function buildFlow(items: RawMessage[] | null | undefined, opts: BuildOpt payloadType, start, middle, - rightEnd, direction, isRadial, isLastHost, @@ -648,3 +644,30 @@ export function buildFlow(items: RawMessage[] | null | undefined, opts: BuildOpt return { hosts, flowItems, callIds } } + +/** Loop width (px) for a self-message when there is no neighbouring host to span to. */ +const RADIAL_FALLBACK_PX = 280 + +/** + * Pixel span of a message's arrow segment, derived from the measured host + * centres (the same positions the lifelines are drawn at), so arrows always + * end on the lifelines whatever the host card widths. Returns null until the + * centres needed for this item have been measured. + */ +export function flowSegmentPx( + item: Pick, + hostCenters: readonly number[], +): { left: number; width: number } | null { + let from = item.start + let to = item.start + item.middle + if (item.isRadial) { + // Self-messages loop towards the next host, or the previous one for the last host. + from = item.isLastHost ? item.start - 1 : item.start + to = from + 1 + } + const left = hostCenters[from] + if (left === undefined) return null + const right = hostCenters[to] ?? (item.isRadial ? left + RADIAL_FALLBACK_PX : undefined) + if (right === undefined) return null + return { left, width: right - left } +} From 877a9df6a9c1c29136874cac415f4ed6a94e8fdc Mon Sep 17 00:00:00 2001 From: Benjamin <56401685+MrM0bi@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:42:36 +0100 Subject: [PATCH 2/3] fix(ui): pin last-host loop port labels to the loop On the last host the self-message segment spans the gap back to the previous host, but the loop is pinned to the segment's right edge. The port badges were 70% wide from the left edge, so they sat near the previous host. Add an `end` modifier that sizes them to their content and pushes them right, under the loop. Co-Authored-By: Claude Opus 5.5 --- src/ui/src/dashboard/CallFlow.css | 8 ++++++++ src/ui/src/dashboard/flow/FlowItem.test.tsx | 20 ++++++++++++++++++++ src/ui/src/dashboard/flow/FlowItem.tsx | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ui/src/dashboard/CallFlow.css b/src/ui/src/dashboard/CallFlow.css index 5bd0c9b4..a31a042a 100644 --- a/src/ui/src/dashboard/CallFlow.css +++ b/src/ui/src/dashboard/CallFlow.css @@ -705,6 +705,14 @@ margin-top: 2px; } +/* Last-host loop sits at the segment's right edge, so the badges must too. + A block with width:auto would take the free space and zero margin-left:auto. */ +.radial-port-labels.end { + width: max-content; + margin-left: auto; + gap: 4px; +} + .radial-port-labels .radial-port-src, .radial-port-labels .radial-port-dst { padding: 1px 6px; diff --git a/src/ui/src/dashboard/flow/FlowItem.test.tsx b/src/ui/src/dashboard/flow/FlowItem.test.tsx index 5a605846..5b10b69e 100644 --- a/src/ui/src/dashboard/flow/FlowItem.test.tsx +++ b/src/ui/src/dashboard/flow/FlowItem.test.tsx @@ -127,3 +127,23 @@ describe('FlowItem geometry', () => { expect(segment.style.flex).toBe('0 0 401px') }) }) + +describe('FlowItem self-message loops', () => { + const radial = (o: Partial) => makeItem(false, { isRadial: true, middle: 1, ...o }) + + it('pins the port badges to the loop on the last host', () => { + const { container } = render( + , + ) + expect(container.querySelector('.radial-port-labels')?.classList.contains('end')).toBe(true) + }) + + it('keeps the badges left-aligned on other hosts', () => { + const { container } = render( + , + ) + expect(container.querySelector('.radial-port-labels')?.classList.contains('end')).toBe(false) + }) +}) diff --git a/src/ui/src/dashboard/flow/FlowItem.tsx b/src/ui/src/dashboard/flow/FlowItem.tsx index 99f6a77b..5542c3a5 100644 --- a/src/ui/src/dashboard/flow/FlowItem.tsx +++ b/src/ui/src/dashboard/flow/FlowItem.tsx @@ -97,7 +97,7 @@ export function FlowItem({ )} {item.isRadial ? ( -
+
{item.srcPort || ''} {item.dstPort || ''}
From 4e9544421255b7ba02fc61c307e0b022df4613de Mon Sep 17 00:00:00 2001 From: Benjamin <56401685+MrM0bi@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:47:13 +0100 Subject: [PATCH 3/3] fix(ui): keep single-host call flow rows on the loop With one host the message is only the self-loop, but the full-width rows put the callid tab on the empty left edge and tinted the whole row. Restore the old .single-host look on top of the full-width container: tint, tab, row border and hover sit on the loop, using --loop-left / --loop-width from the measured host centre. Co-Authored-By: Claude Opus 5.5 --- src/ui/src/dashboard/CallFlow.css | 20 ++++++++++++++++ src/ui/src/dashboard/flow/FlowItem.test.tsx | 26 +++++++++++++++++++++ src/ui/src/dashboard/flow/FlowItem.tsx | 21 ++++++++++++----- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/ui/src/dashboard/CallFlow.css b/src/ui/src/dashboard/CallFlow.css index a31a042a..11318be8 100644 --- a/src/ui/src/dashboard/CallFlow.css +++ b/src/ui/src/dashboard/CallFlow.css @@ -473,6 +473,26 @@ pointer-events: none; } +/* One host: the message is only the loop, so keep the tint, tab, border and + hover on it. The container stays full width; FlowItem sets --loop-left and + --loop-width from the measured host centre. */ +.item-flow-packet-container.single-host .bg-color-polygon { + left: var(--loop-left); + right: auto; + width: var(--loop-width); +} + +.item-flow-packet-container.single-host .bg-color-tab { + left: var(--loop-left); +} + +.item-flow-packet-container.single-host .item-flow-packet { + margin-left: var(--loop-left); + width: var(--loop-width); + /* No arrow has to end on a lifeline here, so keep the text clear of the tab. */ + padding-inline: 6px; +} + .item-flow-packet { position: relative; z-index: 1; diff --git a/src/ui/src/dashboard/flow/FlowItem.test.tsx b/src/ui/src/dashboard/flow/FlowItem.test.tsx index 5b10b69e..b332a22b 100644 --- a/src/ui/src/dashboard/flow/FlowItem.test.tsx +++ b/src/ui/src/dashboard/flow/FlowItem.test.tsx @@ -147,3 +147,29 @@ describe('FlowItem self-message loops', () => { expect(container.querySelector('.radial-port-labels')?.classList.contains('end')).toBe(false) }) }) + +describe('FlowItem single host', () => { + const loop = makeItem(false, { isRadial: true, start: 0, middle: 1 }) + + it('sizes the row to the loop so tint, tab, border and hover stay on it', () => { + const { container } = render( + , + ) + const row = container.querySelector('.item-flow-packet-container')! + expect(row.classList.contains('single-host')).toBe(true) + expect(row.style.getPropertyValue('--loop-left')).toBe('300px') + expect(row.style.getPropertyValue('--loop-width')).toBe('280px') + // The row itself is offset, so the track fills it instead of re-applying the offset. + expect(container.querySelector('.item-flow-track > div:first-child')!.style.flex).toBe('0 0 0px') + expect(container.querySelector('.item-flow-segment')!.style.flex).toBe('1 1 0%') + }) + + it('does not apply to calls with several hosts', () => { + const { container } = render( + , + ) + const row = container.querySelector('.item-flow-packet-container')! + expect(row.classList.contains('single-host')).toBe(false) + expect(row.style.getPropertyValue('--loop-left')).toBe('') + }) +}) diff --git a/src/ui/src/dashboard/flow/FlowItem.tsx b/src/ui/src/dashboard/flow/FlowItem.tsx index 5542c3a5..f3a5342b 100644 --- a/src/ui/src/dashboard/flow/FlowItem.tsx +++ b/src/ui/src/dashboard/flow/FlowItem.tsx @@ -1,3 +1,4 @@ +import type { CSSProperties } from 'react' import type { FlowItemData } from './flow-data' import { flowSegmentPx } from './flow-data' @@ -31,16 +32,24 @@ export function FlowItem({ // Until host centres are measured the segment just fills the row; the // layout effect in CallFlow measures before the first paint. const segment = hostCenters ? flowSegmentPx(item, hostCenters) : null + // With one host the message is only the loop, so the row's tint, tab, border + // and hover sit on the loop (.single-host) while the container stays full width. + const loop = hostCenters?.length === 1 ? segment : null + // A single-host row is itself sized to the loop, so its track just fills it. + const trackSegment = loop ? null : segment + const loopStyle = loop + ? ({ '--loop-left': `${loop.left}px`, '--loop-width': `${loop.width}px` } as CSSProperties) + : undefined const arrowColor = item.callidColors.arrowColor const radialDottedClass = item.arrowStyleSolid ? '' : ' dotted' - const containerClass = `item-flow-packet-container${hasSubItems ? ' consolidated-parent' : ''}${ - isSubItem ? ' consolidated-subitem' : '' - }` + const containerClass = `item-flow-packet-container${loop ? ' single-host' : ''}${ + hasSubItems ? ' consolidated-parent' : '' + }${isSubItem ? ' consolidated-subitem' : ''}` return ( <> -
+
onClickItem?.(item)} >
-
+