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
Bug 1826962: Limit the amount a user can zoom in/out in topology #5160
Bug 1826962: Limit the amount a user can zoom in/out in topology #5160
Conversation
@jeff-phillips-18: This pull request references Bugzilla bug 1826962, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker. 3 validation(s) were run on this bug
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
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.
/assign
const zoomExtents: [number, number] = [this.zoomExtents[0], this.zoomExtents[1]]; | ||
let updateExtents = false; | ||
if ('minZoom' in model && typeof model.minZoom === 'number') { | ||
zoomExtents[0] = +model.minZoom; |
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 +variable
a cast to number? Wouldn't your if-statement typeof check and types make this check redundant?
@@ -238,6 +248,19 @@ export default class BaseGraph<E extends GraphModel = GraphModel, D = any> exten | |||
if ('layout' in model) { | |||
this.setLayout(model.layout); | |||
} | |||
const zoomExtents: [number, number] = [this.zoomExtents[0], this.zoomExtents[1]]; | |||
let updateExtents = false; | |||
if ('minZoom' in model && typeof model.minZoom === '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.
I'm a little taken-back by the usage of the type and this check. I agree it's good to be safe, but I wonder if we are crutching at the wrong spot? Can you make the model setter a little more stable so it's either undefined or a number?
@@ -25,6 +25,8 @@ export default class BaseGraph<E extends GraphModel = GraphModel, D = any> exten | |||
|
|||
private currentLayout?: Layout; | |||
|
|||
private zoomExtents: [number, number] = [0.25, 4]; |
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 wonder if we want to type the [number, number]
... you use it frequently. Would it make sense to type it?
@@ -59,7 +60,7 @@ export const useDragNode = < | |||
React.useMemo(() => { | |||
const sourceSpec: DragSourceSpec<any, any, any, any, Props> = { | |||
item: (spec && spec.item) || { type: '#useDragNode#' }, | |||
operation: (monitor, p) => { | |||
operation: (monitor: DragSourceMonitor, p: any) => { |
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 assume p
is Props... you have a Props
type, does that align?
781f1bf
to
0640920
Compare
/retest |
@@ -25,6 +25,8 @@ export default class BaseGraph<E extends GraphModel = GraphModel, D = any> exten | |||
|
|||
private currentLayout?: Layout; | |||
|
|||
private zoomExtent: [number, number] = [0.25, 4]; |
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.
Is there a type here? What are the two numbers representing? Min & Max? Maybe a type of ZoomBounds
?
0640920
to
8f2ae8b
Compare
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
Minor suggestion to shift the type to the hook.
export type PanZoomRef = (node: SVGGElement | null) => void; | ||
|
||
// Used to send events prevented by d3.zoom to the document allowing modals, dropdowns, etc, to close | ||
const propagatePanZoomMouseEvent = (e: Event): void => { | ||
document.dispatchEvent(new MouseEvent(e.type, e)); | ||
}; | ||
|
||
export const usePanZoom = (zoomExtent: [number, number] = ZOOM_EXTENT): PanZoomRef => { | ||
export const usePanZoom = (): PanZoomRef => { | ||
const element = React.useContext(ElementContext); | ||
if (!isGraph(element)) { | ||
throw new Error('usePanZoom must be used within the scope of a Graph'); | ||
} | ||
const elementRef = React.useRef(element); |
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.
Not sure you need to do the as Graph
on the current. You can just type the useRef
and the isGraph
does the type-guard.
const elementRef = React.useRef(element); | |
const elementRef = React.useRef<Graph>(element); |
} | ||
const zoom = d3 | ||
.zoom() | ||
.scaleExtent([elementRef.current.getMinScale(), elementRef.current.getMaxScale()]) |
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 behavior needs to track changes to the min and max scales and ensure that the new extent is set when one of these values change.
setScale(scale: number): void { | ||
this.scale = scale; | ||
this.scale = Math.max(Math.min(scale, this.maxScale), this.minScale); | ||
} |
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.
Thought we decided that a user should be able to set the scale to anything.
Currently if we use the fit to screen
option on a very spread out visualization, panning the graph will reset the scale because the behavior is using setScale
.
private minScale: number = 0.25; | ||
|
||
private maxScale: number = 4; |
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.
These need to be observable
setMinScale(min: number): void { | ||
this.minScale = min; | ||
} |
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.
Should we ensure that min < max?
Although this kind of validation may be problematic when using two separate values vs an array extent such as [number, number]
because when trying to set new values, you'll have to pay attention to the order in which they are set otherwise an error can be thrown ;/
Still unsure if i prefer an array extent over individual values.
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.
Hmmm... guess it would be better to make it an array.
8f2ae8b
to
5fa8d41
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andrewballantyne, christianvogt, jeff-phillips-18 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@jeff-phillips-18: All pull requests linked via external trackers have merged: openshift/console#5160. Bugzilla bug 1826962 has been moved to the MODIFIED state. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@jeff-phillips-18: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Fixes:
https://issues.redhat.com/browse/ODC-3490
Analysis / Root cause:
The graph scale did not include any zoom extent boundaries so the zoom buttons allowed for infinite zoom in/out.
Solution Description:
Add zoomExtents to the BaseGraph to prevent setting the scale out of the extent boundaries.
/kind bug