Skip to content

Commit

Permalink
feat: increase zoom limits by a factor of 4 (#577)
Browse files Browse the repository at this point in the history
* feat: increase zoom limits by a factor of 4

* add zoom test

* remove extraneous

* prevent scrolling when hovering over graph

* remove import

---------

Co-authored-by: atarashansky <atarashansky@CZIMACOS3990.hsd1.ma.comcast.net>
  • Loading branch information
atarashansky and atarashansky authored Apr 19, 2023
1 parent 260354e commit db5051d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
12 changes: 12 additions & 0 deletions client/__tests__/e2e/cellxgeneActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export async function drag(testId: any, start: any, end: any, lasso = false) {
await page.mouse.up();
}

export async function scroll({testId, deltaY, coords}: {testId: string, deltaY: number, coords: number[]}) {
const layout = await waitByID(testId);
if (layout){
const x = coords[0];
const y = coords[1];
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.up();
await page.mouse.wheel({ deltaY });
}
}

export async function keyboardUndo() {
await page.keyboard.down("MetaLeft");
await page.keyboard.press("KeyZ");
Expand Down
29 changes: 29 additions & 0 deletions client/__tests__/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
calcDragCoordinates,
calcTransformDragCoordinates,
drag,
scroll,
expandCategory,
subset,
createGeneset,
Expand Down Expand Up @@ -58,6 +59,8 @@ import {

import { datasets } from "./data";

import { scaleMax } from "../../src/util/camera";

const BLUEPRINT_SKELETON_CLASS_NAME = Classes.SKELETON;

// geneset CRUD
Expand Down Expand Up @@ -444,6 +447,32 @@ describe("graph overlay", () => {
});
});

test("zoom limit is 12x", async () => {
await goToPage(pageUrl);

const category = Object.keys(data.categorical)[0];

await clickOn(`colorby-${category}`);
await clickOn("centroid-label-toggle");
await clickOn("mode-pan-zoom");


// @ts-expect-error ts-migrate(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
const categoryValue = Object.keys(data.categorical[category])[0];
const initialCoordinates = await getElementCoordinates(
`${categoryValue}-centroid-label`
);

await tryUntil(async () => {
await scroll({testId: "layout-graph", deltaY: -10000, coords: initialCoordinates});
await page.waitForTimeout(1000);
const newGraph = await page.waitForSelector("[data-test-id^=graph-wrapper-]")
const newGraphTestId = await newGraph?.evaluate((el) => el.getAttribute("data-test-id"))
const newDistance = newGraphTestId?.split("distance=").at(-1);
expect(parseFloat(newDistance)).toBe(scaleMax);
});
});

test("pan zoom mode resets lasso selection", async () => {
await goToPage(pageUrl);

Expand Down
18 changes: 18 additions & 0 deletions client/src/components/graph/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class Graph extends React.Component<{}, GraphState> {
return !shallowEqual(props.watchProps, prevProps.watchProps);
}

private graphRef = React.createRef<HTMLDivElement>();

// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
cachedAsyncProps: any;

Expand Down Expand Up @@ -264,6 +266,11 @@ class Graph extends React.Component<{}, GraphState> {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
componentDidMount() {
window.addEventListener("resize", this.handleResize);
if (this.graphRef.current) {
this.graphRef.current.addEventListener("wheel", this.disableScroll, {
passive: false,
});
}
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/ban-types --- FIXME: disabled temporarily on migrate to TS.
Expand Down Expand Up @@ -323,6 +330,9 @@ class Graph extends React.Component<{}, GraphState> {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
componentWillUnmount() {
window.removeEventListener("resize", this.handleResize);
if (this.graphRef.current) {
this.graphRef.current.removeEventListener("wheel", this.disableScroll);
}
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
Expand Down Expand Up @@ -496,6 +506,11 @@ class Graph extends React.Component<{}, GraphState> {
});
}

disableScroll = (event: WheelEvent) => {
// disables browser scrolling behavior when hovering over the graph
event.preventDefault();
};

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any -- - FIXME: disabled temporarily on migrate to TS.
setReglCanvas = (canvas: any) => {
// Ignore null canvas on unmount
Expand Down Expand Up @@ -910,6 +925,7 @@ class Graph extends React.Component<{}, GraphState> {
} = this.props;
const { modelTF, projectionTF, camera, viewport, regl } = this.state;
const cameraTF = camera?.view()?.slice();

return (
<div
id="graph-wrapper"
Expand All @@ -918,6 +934,8 @@ class Graph extends React.Component<{}, GraphState> {
top: 0,
left: 0,
}}
data-test-id={`graph-wrapper-distance=${camera?.distance()}`}
ref={this.graphRef}
>
<GraphOverlayLayer
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ children: Element; width: any; height: any... Remove this comment to see the full error message
Expand Down
3 changes: 2 additions & 1 deletion client/src/util/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import clamp from "./clamp";
const EPSILON = 0.000001;

const scaleSpeed = 0.5;
const scaleMax = 3.0;
// exporting this for testing
export const scaleMax = 12.0;
const scaleMin = 0.5;
const panBound = 0.8;

Expand Down

0 comments on commit db5051d

Please sign in to comment.