Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/Plate/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
COORDINATE_SYSTEM_96_WELL,
CoordinateSystem96Well,
} from './coordinateSystem96Well';
import { Coordinates } from './types';
import { Coordinates, CoordinateSystem } from './types';
import {
allCoordinateSystemCoordinates,
allCoordinateSystemPositions,
areEqualCoordinates,
columnForPosition,
convertPositionFromColumnToRowFlow,
Expand Down Expand Up @@ -175,3 +177,40 @@ describe('areEqualCoordinates', () => {
expect(areEqualCoordinates(a, { ...b, foo: 'bar' })).toBe(false);
});
});

const COORDINATE_SYSTEM_2_BY_2 = {
rows: ['A', 'B'],
columns: [1, 2],
} as const satisfies CoordinateSystem;

describe('allCoordinateSystemPositions', () => {
it('returns an array of all positions in a coordinate systems', () => {
expect(allCoordinateSystemPositions(COORDINATE_SYSTEM_2_BY_2)).toEqual([
1, 2, 3, 4,
]);
});
});

describe('allCoordinateSystemCoordinates', () => {
it('returns an array of all coordinates in column flow', () => {
expect(
allCoordinateSystemCoordinates(COORDINATE_SYSTEM_2_BY_2, 'column'),
).toEqual([
{ row: 'A', column: 1 },
{ row: 'A', column: 2 },
{ row: 'B', column: 1 },
{ row: 'B', column: 2 },
]);
});

it('returns an array of all coordinates in row flow', () => {
expect(
allCoordinateSystemCoordinates(COORDINATE_SYSTEM_2_BY_2, 'row'),
).toEqual([
{ row: 'A', column: 1 },
{ row: 'B', column: 1 },
{ row: 'A', column: 2 },
{ row: 'B', column: 2 },
]);
});
});
17 changes: 17 additions & 0 deletions src/Plate/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,20 @@ export function allCoordinateSystemPositions(
coordinateSystem.rows.length * coordinateSystem.columns.length + 1,
);
}

export function allCoordinateSystemCoordinates<
TCoordinateSystem extends CoordinateSystem,
>(
coordinateSystem: TCoordinateSystem,
flowDirection: FlowDirection,
): Array<Coordinates<TCoordinateSystem>> {
if (flowDirection === 'column') {
return coordinateSystem.rows
.map((row) => coordinateSystem.columns.map((column) => ({ row, column })))
.flat();
}

return coordinateSystem.columns
.map((column) => coordinateSystem.rows.map((row) => ({ row, column })))
.flat();
}
Loading