Skip to content
Merged
5 changes: 3 additions & 2 deletions packages/phoenix-event-display/src/loaders/jivexml-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
*ngFor="let column of collectionColumns"
[attr.data-label]="getPrettySymbol(column)"
>
{{ object[column] }}
{{ formatValue(object[column]) }}
</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class CollectionsInfoOverlayComponent implements OnInit, OnDestroy {
'labelText',
'_instanceId',
'_position',
'index',
];
hideInvisible: boolean;
collections: { type: string; collections: string[] }[];
Expand Down Expand Up @@ -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}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading