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

feat: increase zoom limits by a factor of 4 #577

Merged
merged 7 commits into from
Apr 19, 2023

Conversation

atarashansky
Copy link
Contributor

@atarashansky atarashansky commented Mar 23, 2023

Changes

  • increase zoom limit to 12x from 3x
  • add smoke test for zoom
  • prevent scrolling on graph component

Testing

  • tested locally and smoke tested

Notes for reviewer

Previously, scrolling behavior conflicts with zoom tool:
https://user-images.githubusercontent.com/16548075/231508562-a850bf9c-8861-442f-bdbc-122236288540.mov

Now, the rubberbanding scrolling behavior is no longer present on the graph component:
https://user-images.githubusercontent.com/16548075/231508671-2467c602-80b2-4d17-afd9-42eee2b294a2.mov

@atarashansky atarashansky marked this pull request as draft March 24, 2023 17:32
@atarashansky atarashansky changed the title feat: increase zoom limits by a factor of 4 (DO NOT MERGE) feat: increase zoom limits by a factor of 4 Mar 24, 2023
@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

Merging #577 (88f2893) into main (260354e) will not change coverage.
The diff coverage is n/a.

❗ Current head 88f2893 differs from pull request most recent head 8cb0562. Consider uploading reports for the commit 8cb0562 to get more accurate results

@@           Coverage Diff           @@
##             main     #577   +/-   ##
=======================================
  Coverage   78.40%   78.40%           
=======================================
  Files          84       84           
  Lines        6594     6594           
=======================================
  Hits         5170     5170           
  Misses       1424     1424           
Flag Coverage Δ
frontend 78.40% <ø> (ø)
javascript 78.40% <ø> (ø)
smokeTest ∅ <ø> (∅)
unitTest 78.40% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@atarashansky atarashansky changed the title (DO NOT MERGE) feat: increase zoom limits by a factor of 4 feat: increase zoom limits by a factor of 4 Apr 11, 2023
@atarashansky atarashansky requested a review from tihuan April 11, 2023 22:53
@atarashansky atarashansky marked this pull request as ready for review April 11, 2023 22:53
@@ -918,6 +918,7 @@ class Graph extends React.Component<{}, GraphState> {
top: 0,
left: 0,
}}
data-test-id={`graph-wrapper-distance=${camera?.distance()}`}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to added the camera's distance into the test attribute. Otherwise, I had no way of figuring out the zoom level since it's a virtual zoom on the coordinates, not a viewport zoom.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this going to cause unnecessary re-renders?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured if the camera is changing, the graph component would be re-rendered anyway. Let me double check if this is causing extra renders.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to be causing extra renders when zooming.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion with @tihuan, because the graph wrapper div element is re-rendering every time anything changes in the component anyway, including point position due to zoom, then adding dynamic data-test-id isn't causing extra renders. This is also confirmed by adding log statements to the component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing this up, @seve! The style={{...}} is already re-generating a new POJO every time and causing re-rendering, so data-test-id changes is not making React render it more. It's already the most re-rendering React could do on this <div> 😄

@@ -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[]}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is for scrolling

@@ -444,6 +447,32 @@ describe("graph overlay", () => {
});
});

test("zoom limit is 12x", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test colors by and overlays centroid labels to be able to easily get a coordinate overlaying somewhere in the graph.

It then scrolls over that point and gets the test attribute from the graph wrapper to extract the new distance. The scroll was chosen to max out the zoom level, which should equal scaleMax.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like this comment is super helpful for understanding the test! Can we add it to the code please? Thank you!

@atarashansky atarashansky requested a review from seve April 11, 2023 22:58
@@ -918,6 +918,7 @@ class Graph extends React.Component<{}, GraphState> {
top: 0,
left: 0,
}}
data-test-id={`graph-wrapper-distance=${camera?.distance()}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this going to cause unnecessary re-renders?

@atarashansky atarashansky requested a review from seve April 12, 2023 15:38
@@ -126,6 +126,8 @@ class Graph extends React.Component<{}, GraphState> {
return !shallowEqual(props.watchProps, prevProps.watchProps);
}

private graphRef = React.createRef<HTMLDivElement>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to prevent scrolling on the graph component at mount time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also a great context to have in the code 🙏

@@ -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, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent scrolling

Copy link
Contributor

@tihuan tihuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just proposing to add some PR comments to code directly to beef up code context 🙏 Thanks so much!

@@ -444,6 +447,32 @@ describe("graph overlay", () => {
});
});

test("zoom limit is 12x", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like this comment is super helpful for understanding the test! Can we add it to the code please? Thank you!

@@ -126,6 +126,8 @@ class Graph extends React.Component<{}, GraphState> {
return !shallowEqual(props.watchProps, prevProps.watchProps);
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also a great context to have in the code 🙏

@atarashansky atarashansky merged commit db5051d into main Apr 19, 2023
@atarashansky atarashansky deleted the atar-increase-zoom-rdev branch April 19, 2023 20:13
nayib-jose-gloria added a commit that referenced this pull request Apr 25, 2023
* 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 <[email protected]>
Co-authored-by: atarashansky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants