Skip to content

Commit

Permalink
Merge pull request #521 from ral-facilities/DSEGOG-128-image-centroids
Browse files Browse the repository at this point in the history
DSEGOG-128 Image centroids/crosshairs
  • Loading branch information
louise-davies authored Jan 13, 2025
2 parents 7d6a5ad + 8d0df44 commit e2cbc62
Show file tree
Hide file tree
Showing 57 changed files with 2,440 additions and 957 deletions.
341 changes: 327 additions & 14 deletions e2e/mocked/images.spec.ts

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 17 additions & 17 deletions e2e/mocked/plotting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('plots a time vs shotnum graph and change the plot colour', async ({
// wait for open settings button to be visible i.e. menu is fully closed
await popup.locator('[aria-label="open settings"]').click({ trial: true });

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');
expect(
await chart.screenshot({
type: 'png',
Expand Down Expand Up @@ -80,7 +80,7 @@ test('plots a shotnum vs channel graph with logarithmic scales', async ({
// wait for open settings button to be visible i.e. menu is fully closed
await popup.locator('[aria-label="open settings"]').click({ trial: true });

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');
expect(
await chart.screenshot({
type: 'png',
Expand Down Expand Up @@ -108,11 +108,11 @@ test('user can zoom and pan the graph', async ({ page }) => {

await popup.locator('[aria-label="close settings"]').click();

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');
await chart.click();

// test drag to zoom
await popup.dragAndDrop('#my-chart', '#my-chart', {
await popup.dragAndDrop('.chartjs-chart', '.chartjs-chart', {
sourcePosition: {
x: 250,
y: 120,
Expand All @@ -130,7 +130,7 @@ test('user can zoom and pan the graph', async ({ page }) => {
await popup.mouse.wheel(-10, 0);

await popup.keyboard.down('Shift');
await popup.dragAndDrop('#my-chart', '#my-chart', {
await popup.dragAndDrop('.chartjs-chart', '.chartjs-chart', {
sourcePosition: {
x: 150,
y: 150,
Expand Down Expand Up @@ -221,7 +221,7 @@ test('plots multiple channels on the y axis', async ({ page }) => {

await popup.locator('[aria-label="close settings"]').click();

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

// need this to wait for canvas animations to execute
await popup.waitForTimeout(1000);
Expand Down Expand Up @@ -268,7 +268,7 @@ test('user can hide gridlines and axes labels', async ({ page }) => {
// need this to wait for canvas animations to execute
await popup.waitForTimeout(1000);

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

expect(
await chart.screenshot({
Expand Down Expand Up @@ -314,7 +314,7 @@ test('user can add from and to dates to timestamp on x-axis', async ({
// wait for open settings button to be visible i.e. menu is fully closed
await popup.locator('[aria-label="open settings"]').click({ trial: true });

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

expect(
await chart.screenshot({
Expand Down Expand Up @@ -363,7 +363,7 @@ test('user can add min and max limits to x- and y-axis', async ({ page }) => {
// wait for open settings button to be visible i.e. menu is fully closed
await popup.locator('[aria-label="open settings"]').click({ trial: true });

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');
expect(
await chart.screenshot({
type: 'png',
Expand Down Expand Up @@ -412,7 +412,7 @@ test('user can change line style of plotted channels', async ({ page }) => {

await popup.locator('[aria-label="close settings"]').click();

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

// need this to wait for canvas animations to execute
await popup.waitForTimeout(1000);
Expand Down Expand Up @@ -470,7 +470,7 @@ test('user can change the marker style and size of plotted channels', async ({

await popup.locator('[aria-label="close settings"]').click();

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

// need this to wait for canvas animations to execute
await popup.waitForTimeout(1000);
Expand Down Expand Up @@ -526,7 +526,7 @@ test('changes to and from dateTimes to use 0 seconds and 59 seconds respectively
// wait for open settings button to be visible i.e. menu is fully closed
await popup.locator('[aria-label="open settings"]').click({ trial: true });

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');
expect(
await chart.screenshot({
type: 'png',
Expand Down Expand Up @@ -571,7 +571,7 @@ test('user can change the line width of plotted channels', async ({ page }) => {

await popup.locator('[aria-label="close settings"]').click();

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

// need this to wait for canvas animations to execute
await popup.waitForTimeout(1000);
Expand Down Expand Up @@ -655,7 +655,7 @@ test('user can plot channels on the right y axis', async ({ page }) => {

await popup.locator('[aria-label="close settings"]').click();

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

// need this to wait for canvas animations to execute
await popup.waitForTimeout(1000);
Expand Down Expand Up @@ -685,7 +685,7 @@ test('user can customize left y axis label', async ({ page }) => {
await popup.getByRole('option', { name: 'Shot Number', exact: true }).click();
await popup.getByRole('textbox', { name: 'Label' }).type('left y axis');

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

expect(
await chart.screenshot({
Expand Down Expand Up @@ -713,7 +713,7 @@ test('user can customize right y axis label', async ({ page }) => {
await popup.getByRole('option', { name: 'Shot Number', exact: true }).click();
await popup.getByRole('textbox', { name: 'Label' }).type('right y axis');

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

expect(
await chart.screenshot({
Expand Down Expand Up @@ -749,7 +749,7 @@ test('user can customize both left and right y axis labels', async ({
.click();
await popup.getByRole('textbox', { name: 'Label' }).type('right y axis');

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

expect(
await chart.screenshot({
Expand Down
10 changes: 5 additions & 5 deletions e2e/mocked/traces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test('user can show points for the trace', async ({ page }) => {

await popup.getByRole('button', { name: 'Show points' }).click();

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');
// need this to wait for canvas animations to execute
await popup.waitForTimeout(1000);

Expand All @@ -54,11 +54,11 @@ test('user can zoom and pan the trace', async ({ page }) => {
.click(),
]);

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');
await chart.click();

// test drag to zoom
await popup.dragAndDrop('#my-chart', '#my-chart', {
await popup.dragAndDrop('.chartjs-chart', '.chartjs-chart', {
sourcePosition: {
x: 250,
y: 180,
Expand All @@ -76,7 +76,7 @@ test('user can zoom and pan the trace', async ({ page }) => {
await popup.mouse.wheel(-10, 0);

await popup.keyboard.down('Shift');
await popup.dragAndDrop('#my-chart', '#my-chart', {
await popup.dragAndDrop('.chartjs-chart', '.chartjs-chart', {
sourcePosition: {
x: 150,
y: 150,
Expand Down Expand Up @@ -135,7 +135,7 @@ test('user can change trace via clicking on a thumbnail', async ({ page }) => {
.click(),
]);

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');

// wait for first chart to load before loading new chart
await chart.click();
Expand Down
2 changes: 1 addition & 1 deletion e2e/real/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('scalar functions can be plotted', async ({ page }) => {
// wait for open settings button to be visible i.e. menu is fully closed
await popup.locator('[aria-label="open settings"]').click({ trial: true });

const chart = await popup.locator('#my-chart');
const chart = await popup.locator('.chartjs-chart');
expect(
await chart.screenshot({
type: 'png',
Expand Down
121 changes: 107 additions & 14 deletions e2e/real/images.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@ test.beforeEach(async ({ page }) => {
// add trace channel to the table so we can click on a trace
await page.getByRole('button', { name: 'Data channels' }).click();

// check that channels have loaded before searching for our channels to add
await expect(page.getByRole('button', { name: 'system' })).toBeVisible();

await page
.getByRole('combobox', { name: 'Search data channels' })
.fill('PA1-CAM');

await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');

for (const row of await page.getByRole('checkbox').all()) await row.check();
await page.getByRole('button', { name: 'Add this channel' }).click();

await page.getByRole('combobox', { name: 'Search data channels' }).fill('');
await page
.getByRole('combobox', { name: 'Search data channels' })
.fill('CAM-2');

await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');

await page.getByRole('button', { name: 'Add this channel' }).click();

await page.getByRole('button', { name: 'Add Channels' }).click();
});
Expand Down Expand Up @@ -52,19 +65,21 @@ test('user can change the false colour parameters of an image', async ({
const imgAltText = title.split(' - ')[1];

const image = await popup.getByAltText(imgAltText);
// assert src has loaded before storing the old image src
await expect(image).toHaveAttribute('src');
const oldImageSrc = await image.getAttribute('src');
const colourbar = await popup.getByAltText('Colour bar');

await popup.getByLabel('Colour Map').click();

await popup.getByRole('option', { name: 'cividis' }).click();

expect(
await popup.getByRole('checkbox', { name: 'Reverse Colour' })
await expect(
popup.getByRole('checkbox', { name: 'Reverse Colour' })
).not.toBeChecked();
await popup.getByRole('checkbox', { name: 'Reverse Colour' }).click();
expect(
await popup.getByRole('checkbox', { name: 'Reverse Colour' })
await expect(
popup.getByRole('checkbox', { name: 'Reverse Colour' })
).toBeChecked();

const slider = await popup.getByRole('slider', {
Expand All @@ -91,7 +106,7 @@ test('user can change the false colour parameters of an image', async ({
},
});

expect(await slider.nth(0).getAttribute('value')).toBe(`${0.4 * 255}`);
await expect(slider.nth(0)).toHaveValue(`${0.4 * 255}`);

const ulSliderThumb = await popup
.locator('.MuiSlider-thumb', {
Expand All @@ -106,7 +121,7 @@ test('user can change the false colour parameters of an image', async ({
},
});

expect(await slider.nth(1).getAttribute('value')).toBe(`${0.8 * 255}`);
await expect(slider.nth(1)).toHaveValue(`${0.8 * 255}`);

// blur to avoid focus tooltip appearing in snapshot
await slider.nth(0).blur();
Expand Down Expand Up @@ -145,14 +160,16 @@ test('user can disable false colour', async ({ page }) => {
const imgAltText = title.split(' - ')[1];

const image = await popup.getByAltText(imgAltText);
// assert src has loaded before storing the old image src
await expect(image).toHaveAttribute('src');
const oldImageSrc = await image.getAttribute('src');

expect(
await popup.getByRole('checkbox', { name: 'False colour' })
await expect(
popup.getByRole('checkbox', { name: 'False colour' })
).toBeChecked();
await popup.getByRole('checkbox', { name: 'False colour' }).click();
expect(
await popup.getByRole('checkbox', { name: 'False colour' })
await expect(
popup.getByRole('checkbox', { name: 'False colour' })
).not.toBeChecked();

// wait for new image to have loaded
Expand Down Expand Up @@ -181,9 +198,12 @@ test('user can change image via clicking on a thumbnail', async ({ page }) => {

const canvas = await popup.getByTestId('overlay');

const oldImageSrc = await popup
.getByAltText((await popup.title()).split(' - ')[1])
.getAttribute('src');
const oldImage = await popup.getByAltText(
(await popup.title()).split(' - ')[1]
);
// assert src has loaded before storing the old image src
await expect(oldImage).toHaveAttribute('src');
const oldImageSrc = await oldImage.getAttribute('src');

await popup
.getByAltText('PM-201-PA1-CAM-2 image', { exact: false })
Expand Down Expand Up @@ -283,6 +303,79 @@ test('user can set their default colourmap', async ({ page }) => {
).toMatchSnapshot();
});

test('user can use crosshairs mode and view intensity graphs', async ({
page,
}) => {
// open up popup
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page
.getByAltText('D100 front-end FF image', { exact: false })
.first()
.click(),
]);

const title = await popup.title();
const imgAltText = title.split(' - ')[1];

const image = await popup.getByAltText(imgAltText);

// get into cross hairs mode
await expect(
popup.getByRole('checkbox', { name: 'Centroid / Cross Hairs' })
).not.toBeChecked();
await popup.getByRole('checkbox', { name: 'Centroid / Cross Hairs' }).click();
await expect(
popup.getByRole('checkbox', { name: 'Centroid / Cross Hairs' })
).toBeChecked();

const charts = await popup.locator('.chartjs-chart');
await expect(charts).toHaveCount(2);
await expect(charts.first()).toBeVisible();
await expect(charts.last()).toBeVisible();

const centroidPosition = [734, 516];
const FWHMs = [214, 201];
await expect(
popup.getByText(
`Position: (${centroidPosition[0]}, ${centroidPosition[1]})`
)
).toBeVisible();
await expect(popup.getByText(`X FWHM: ${FWHMs[0]}`)).toBeVisible();
await expect(popup.getByText(`Y FWHM: ${FWHMs[1]}`)).toBeVisible();

// expect crosshairs to be drawn on image at the centroid & intensity plots to be drawn & positioned correctly
expect(
await popup.getByTestId('image-panel').screenshot({
type: 'png',
style:
// hide image controls panel & top buttons from the screenshot as it's not important
'[data-testid="image-controls-panel"], [aria-label="image actions"] { display: none !important; }',
})
).toMatchSnapshot({ maxDiffPixels: 150 });

// check that clicking the image changes the crosshairs position & causes a data fetch
// for some reason playwright has an off by 1 error in the y-pos in chrome, it works fine when testing manually
// i.e. clicking top left-most pixel results in (0,0)
await image.click({
position: { x: 750, y: 301 },
});

await expect(popup.getByText('Position: (750, 300)')).toBeVisible();
const newFWHMs = [204, 180];
await expect(popup.getByText(`X FWHM: ${newFWHMs[0]}`)).toBeVisible();
await expect(popup.getByText(`Y FWHM: ${newFWHMs[1]}`)).toBeVisible();

expect(
await popup.getByTestId('image-panel').screenshot({
type: 'png',
style:
// hide image controls panel & top buttons from the screenshot as it's not important
'[data-testid="image-controls-panel"], [aria-label="image actions"] { display: none !important; }',
})
).toMatchSnapshot({ maxDiffPixels: 150 });
});

test('user can export image', async ({ page }) => {
// open up popup
const [popup] = await Promise.all([
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e2cbc62

Please sign in to comment.