Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mrc-5551 Show Time label on final graph only #211

Merged
merged 4 commits into from
Jul 30, 2024
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
4 changes: 3 additions & 1 deletion app/static/src/app/components/WodinPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ export default defineComponent({

const defaultLayout = (): Partial<Layout> => {
// Get generic layout, which will be modifed dynamically as required
// Show Time label on final graph only
const xAxisTitle = props.fitPlot || props.graphIndex === store.state.graphs.config.length - 1 ? "Time" : "";
const result = {
margin: { ...margin },
xaxis: { title: "Time" },
xaxis: { title: xAxisTitle },
yaxis: { type: yAxisType.value }
};
if (legendWidth.value) {
Expand Down
2 changes: 2 additions & 0 deletions app/static/tests/e2e/fit.etest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ test.describe("Wodin App model fit tests", () => {

const plotSelector = ".wodin-right .wodin-content div.mt-4 .js-plotly-plot";

await expect(await page.locator(".plotly .xtitle").textContent()).toBe("Time");

// Test line is plotted for fit trace and data points
const linesSelector = `${plotSelector} .scatterlayer .trace .lines path`;
await expect((await page.locator(linesSelector).getAttribute("d"))!.startsWith("M")).toBe(true);
Expand Down
14 changes: 14 additions & 0 deletions app/static/tests/e2e/run.etest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@ test.describe("Run Tab", () => {
// 3. Check - using x axis ticks - that the expected x axis values are shown on all three graphs.
await expectXTicks(page, 3, [15, 20, 25, 30, 35, 40]);
});

test("x axis Time label is shown for final plot only", async ({ page }) => {
await page.goto("/apps/day1");
await addGraphWithVariable(page, 1);
const firstGraph = page.locator(":nth-match(.plotly, 1)");
const secondGraph = page.locator(":nth-match(.plotly, 2)");

await expect(await firstGraph.locator(".xtitle")).not.toBeVisible();
await expect(await secondGraph.locator(".xtitle").textContent()).toBe("Time");

// Delete second config - the Time label should be shown on the first graph
await page.locator(":nth-match(button.delete-graph, 2)").click();
await expect(await firstGraph.locator(".xtitle").textContent()).toBe("Time");
});
});
49 changes: 45 additions & 4 deletions app/static/tests/unit/components/wodinPlot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ describe("WodinPlot", () => {
}
];
const mockPlotDataFn = jest.fn().mockReturnValue(mockPlotData);
const settings = defaultGraphSettings();
const defaultProps = {
fadePlot: false,
endTime: 99,
redrawWatches: [],
plotData: mockPlotDataFn,
placeholderMessage: "No data available",
fitPlot: false,
graphIndex: 0,
graphConfig: { settings: defaultGraphSettings() }
graphIndex: 1,
graphConfig: { settings }
};

const mockSetYAxisRange = jest.fn();
Expand All @@ -71,7 +72,8 @@ describe("WodinPlot", () => {
graphs: {
namespaced: true,
state: {
fitGraphSettings
fitGraphSettings,
config: [{ settings }, { settings }]
},
mutations: {
[GraphsMutation.SetYAxisRange]: mockSetYAxisRange,
Expand Down Expand Up @@ -501,7 +503,7 @@ describe("WodinPlot", () => {
await nextTick();
await wrapper.setProps({ redrawWatches: [{} as any] });
await nextTick();
expect(mockSetYAxisRange.mock.calls[0][1]).toStrictEqual({ graphIndex: 0, value: [1, 2] });
expect(mockSetYAxisRange.mock.calls[0][1]).toStrictEqual({ graphIndex: 1, value: [1, 2] });
expect(mockSetFitYAxisRange).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -665,4 +667,43 @@ describe("WodinPlot", () => {
expect(mockPlotDataFn.mock.calls[1][1]).toBe(5);
expect(mockPlotDataFn.mock.calls[1][2]).toBe(1000);
});

it("does not display Time xAxis label if not final config in array", async () => {
const store = getStore();
const wrapper = getWrapper(
{
graphIndex: 0
},
store
);
mockPlotElementOn(wrapper);

wrapper.setProps({ redrawWatches: [{} as any] });
await nextTick();
expect(mockPlotlyNewPlot.mock.calls[0][2]).toStrictEqual({
margin: { t: 25 },
xaxis: { title: "" },
yaxis: { type: "linear" }
});
});

it("does display Time xAxis label if fitPlot is true", async () => {
const store = getStore();
const wrapper = getWrapper(
{
graphIndex: 0,
fitPlot: true
},
store
);
mockPlotElementOn(wrapper);

wrapper.setProps({ redrawWatches: [{} as any] });
await nextTick();
expect(mockPlotlyNewPlot.mock.calls[0][2]).toStrictEqual({
margin: { t: 25 },
xaxis: { title: "Time" },
yaxis: { type: "linear" }
});
});
});
Loading