-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #577 +/- ##
=======================================
Coverage 78.40% 78.40%
=======================================
Files 84 84
Lines 6594 6594
=======================================
Hits 5170 5170
Misses 1424 1424
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 |
@@ -918,6 +918,7 @@ class Graph extends React.Component<{}, GraphState> { | |||
top: 0, | |||
left: 0, | |||
}} | |||
data-test-id={`graph-wrapper-distance=${camera?.distance()}`} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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[]}) { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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!
@@ -918,6 +918,7 @@ class Graph extends React.Component<{}, GraphState> { | |||
top: 0, | |||
left: 0, | |||
}} | |||
data-test-id={`graph-wrapper-distance=${camera?.distance()}`} |
There was a problem hiding this comment.
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?
@@ -126,6 +126,8 @@ class Graph extends React.Component<{}, GraphState> { | |||
return !shallowEqual(props.watchProps, prevProps.watchProps); | |||
} | |||
|
|||
private graphRef = React.createRef<HTMLDivElement>(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prevent scrolling
There was a problem hiding this 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 () => { |
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
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 🙏
* 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]>
Changes
Testing
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