diff --git a/packages/phoenix-event-display/src/loaders/jivexml-loader.ts b/packages/phoenix-event-display/src/loaders/jivexml-loader.ts index 252011fe5..f83d0a191 100644 --- a/packages/phoenix-event-display/src/loaders/jivexml-loader.ts +++ b/packages/phoenix-event-display/src/loaders/jivexml-loader.ts @@ -289,13 +289,14 @@ export class JiveXMLLoader extends PhoenixLoader { pos: [] as number[][], dparams: [] as number[], // Explicitly define the type as number[] hits: {}, - author: {}, + author: undefined as number | undefined, badtrack: [] as string[], linewidth: thickTracks ? 20.0 : undefined, }; if (chi2.length >= i) track.chi2 = chi2[i]; if (numDoF.length >= i) track.dof = numDoF[i]; - if (trackAuthor?.length >= i) track.author = trackAuthor[i]; + if (trackAuthor && i < trackAuthor.length) + track.author = trackAuthor[i]; let theta = Math.atan(1 / cotTheta[i]); diff --git a/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.html b/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.html index c18240cb8..f12889c28 100644 --- a/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.html +++ b/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.html @@ -143,7 +143,7 @@ *ngFor="let column of collectionColumns" [attr.data-label]="getPrettySymbol(column)" > - {{ object[column] }} + {{ formatValue(object[column]) }} diff --git a/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.test.ts b/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.test.ts index ad6b90b65..2ea365dde 100644 --- a/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.test.ts +++ b/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.test.ts @@ -178,6 +178,31 @@ describe('CollectionsInfoOverlayComponent', () => { expect(component.hideInvisible).toBe(false); }); + it('should format numbers to 2 decimal places', () => { + expect(component.formatValue(1.123456)).toBe('1.12'); + expect(component.formatValue(5)).toBe('5'); + expect(component.formatValue(-1.239)).toBe('-1.24'); + }); + + it('should format a track pos array (array of [x, y, z] points) recursively', () => { + // Real shape returned for track.pos: an array of points, each an + // [x, y, z] triplet - i.e. a 2D array, not a flat array of numbers. + const pos = [ + [0.0025628636759723617, -0.011743023176942868, -0.05242818281548735], + [29.50923086259338, -107.72085890394575, -487.4091843499314], + ]; + + expect(component.formatValue(pos)).toBe( + '[[0.00, -0.01, -0.05], [29.51, -107.72, -487.41]]', + ); + }); + + it('should format a Vector3-like object as [x, y, z]', () => { + expect(component.formatValue({ x: 1.239, y: 2, z: -3.14159 })).toBe( + '[1.24, 2, -3.14]', + ); + }); + it('should add label to object', () => { const mockUuid = '1234'; const mockLabel = 'testLabel'; diff --git a/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.ts b/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.ts index 601bd2f2b..467f8c61a 100644 --- a/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.ts +++ b/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/collections-info/collections-info-overlay/collections-info-overlay.component.ts @@ -28,6 +28,7 @@ export class CollectionsInfoOverlayComponent implements OnInit, OnDestroy { 'labelText', '_instanceId', '_position', + 'index', ]; hideInvisible: boolean; collections: { type: string; collections: string[] }[]; @@ -154,6 +155,31 @@ export class CollectionsInfoOverlayComponent implements OnInit, OnDestroy { this.hideInvisible = checked; } + formatValue(value: any): string { + if (typeof value === 'number') { + return Number.isInteger(value) ? String(value) : value.toFixed(2); + } + if (Array.isArray(value)) { + // Handles nested arrays too, e.g. track `pos`: an array of [x, y, z] + // points, so each element is itself an array, not a number. + return `[${value.map((v) => this.formatValue(v)).join(', ')}]`; + } + // Vector-like objects (e.g. THREE.Vector3), which otherwise stringify + // to the unhelpful "[object Object]". + if ( + value && + typeof value === 'object' && + typeof value.x === 'number' && + typeof value.y === 'number' + ) { + const parts = [value.x, value.y, value.z].filter( + (v) => typeof v === 'number', + ); + return `[${parts.map((v) => this.formatValue(v)).join(', ')}]`; + } + return String(value); + } + addLabel(index: number, uuid: string) { const labelValue = this.elementRef.nativeElement.querySelector( `#label${index}`, diff --git a/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/overlay/overlay.component.scss b/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/overlay/overlay.component.scss index fe29d84f0..a06242d00 100644 --- a/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/overlay/overlay.component.scss +++ b/packages/phoenix-ng/projects/phoenix-ui-components/lib/components/ui-menu/overlay/overlay.component.scss @@ -1,7 +1,7 @@ .overlay-card.card { color: var(--phoenix-text-color); background: none; - max-width: 85vw; + max-width: 95vw; font-size: 12px; /* Same min-width as overlay.component.ts MIN_RES_WIDTH */ min-width: 300px;