-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[Endpoint] Resolver zoom, pan, and center controls #55221
Merged
peluja1012
merged 4 commits into
elastic:master
from
peluja1012:feature/resolver-pan-and-zoom-controls
Jan 21, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { applyMatrix3, subtract } from '../../lib/vector2'; | |
import { userIsPanning, translation, projectionMatrix, inverseProjectionMatrix } from './selectors'; | ||
import { clamp } from '../../lib/math'; | ||
|
||
import { CameraState, ResolverAction } from '../../types'; | ||
import { CameraState, ResolverAction, Vector2 } from '../../types'; | ||
import { scaleToZoom } from './scale_to_zoom'; | ||
|
||
function initialState(): CameraState { | ||
|
@@ -34,6 +34,16 @@ export const cameraReducer: Reducer<CameraState, ResolverAction> = ( | |
...state, | ||
scalingFactor: clamp(action.payload, 0, 1), | ||
}; | ||
} else if (action.type === 'userClickedZoomIn') { | ||
return { | ||
...state, | ||
scalingFactor: clamp(state.scalingFactor + 0.1, 0, 1), | ||
}; | ||
} else if (action.type === 'userClickedZoomOut') { | ||
return { | ||
...state, | ||
scalingFactor: clamp(state.scalingFactor - 0.1, 0, 1), | ||
}; | ||
} else if (action.type === 'userZoomed') { | ||
const stateWithNewScaling: CameraState = { | ||
...state, | ||
|
@@ -100,6 +110,32 @@ export const cameraReducer: Reducer<CameraState, ResolverAction> = ( | |
} else { | ||
return state; | ||
} | ||
} else if (action.type === 'userClickedPanControl') { | ||
const panDirection = action.payload; | ||
/** | ||
* Delta amount will be in the range of 20 -> 40 depending on the scalingFactor | ||
*/ | ||
const deltaAmount = (1 + state.scalingFactor) * 20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe
|
||
let delta: Vector2; | ||
if (panDirection === 'north') { | ||
delta = [0, -deltaAmount]; | ||
} else if (panDirection === 'south') { | ||
delta = [0, deltaAmount]; | ||
} else if (panDirection === 'east') { | ||
delta = [-deltaAmount, 0]; | ||
} else if (panDirection === 'west') { | ||
delta = [deltaAmount, 0]; | ||
} else { | ||
delta = [0, 0]; | ||
} | ||
|
||
return { | ||
...state, | ||
translationNotCountingCurrentPanning: [ | ||
state.translationNotCountingCurrentPanning[0] + delta[0], | ||
state.translationNotCountingCurrentPanning[1] + delta[1], | ||
], | ||
}; | ||
} else if (action.type === 'userSetRasterSize') { | ||
/** | ||
* Handle resizes of the Resolver component. We need to know the size in order to convert between screen | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
x-pack/plugins/endpoint/public/embeddables/resolver/view/graph_controls.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useCallback } from 'react'; | ||
import styled from 'styled-components'; | ||
import { EuiRange, EuiPanel, EuiIcon } from '@elastic/eui'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { ResolverAction, PanDirection } from '../types'; | ||
import * as selectors from '../store/selectors'; | ||
|
||
/** | ||
* Controls for zooming, panning, and centering in Resolver | ||
*/ | ||
export const GraphControls = styled( | ||
React.memo( | ||
({ | ||
className, | ||
}: { | ||
/** | ||
* A className string provided by `styled` | ||
*/ | ||
className?: string; | ||
}) => { | ||
const dispatch: (action: ResolverAction) => unknown = useDispatch(); | ||
const scalingFactor = useSelector(selectors.scalingFactor); | ||
|
||
const handleZoomAmountChange = useCallback( | ||
(event: React.ChangeEvent<HTMLInputElement> | React.MouseEvent<HTMLButtonElement>) => { | ||
const valueAsNumber = parseFloat( | ||
(event as React.ChangeEvent<HTMLInputElement>).target.value | ||
); | ||
if (isNaN(valueAsNumber) === false) { | ||
dispatch({ | ||
type: 'userSetZoomLevel', | ||
payload: valueAsNumber, | ||
}); | ||
} | ||
}, | ||
[dispatch] | ||
); | ||
|
||
const handleCenterClick = useCallback(() => { | ||
dispatch({ | ||
type: 'userSetPositionOfCamera', | ||
payload: [0, 0], | ||
}); | ||
}, [dispatch]); | ||
|
||
const handleZoomOutClick = useCallback(() => { | ||
dispatch({ | ||
type: 'userClickedZoomOut', | ||
}); | ||
}, [dispatch]); | ||
|
||
const handleZoomInClick = useCallback(() => { | ||
dispatch({ | ||
type: 'userClickedZoomIn', | ||
}); | ||
}, [dispatch]); | ||
|
||
const handlePanClick = (panDirection: PanDirection) => { | ||
return () => { | ||
dispatch({ | ||
type: 'userClickedPanControl', | ||
payload: panDirection, | ||
}); | ||
}; | ||
}; | ||
|
||
return ( | ||
<div className={className}> | ||
<EuiPanel className="panning-controls" paddingSize="none" hasShadow> | ||
<div className="panning-controls-top"> | ||
<button className="north-button" title="North" onClick={handlePanClick('north')}> | ||
<EuiIcon type="arrowUp" /> | ||
</button> | ||
</div> | ||
<div className="panning-controls-middle"> | ||
<button className="west-button" title="West" onClick={handlePanClick('west')}> | ||
<EuiIcon type="arrowLeft" /> | ||
</button> | ||
<button className="center-button" title="Center" onClick={handleCenterClick}> | ||
<EuiIcon type="bullseye" /> | ||
</button> | ||
<button className="east-button" title="East" onClick={handlePanClick('east')}> | ||
<EuiIcon type="arrowRight" /> | ||
</button> | ||
</div> | ||
<div className="panning-controls-bottom"> | ||
<button className="south-button" title="South" onClick={handlePanClick('south')}> | ||
<EuiIcon type="arrowDown" /> | ||
</button> | ||
</div> | ||
</EuiPanel> | ||
<EuiPanel className="zoom-controls" paddingSize="none" hasShadow> | ||
<button title="Zoom In" onClick={handleZoomInClick}> | ||
<EuiIcon type="plusInCircle" /> | ||
</button> | ||
<EuiRange | ||
className="zoom-slider" | ||
min={0} | ||
max={1} | ||
step={0.01} | ||
value={scalingFactor} | ||
onChange={handleZoomAmountChange} | ||
/> | ||
<button title="Zoom Out" onClick={handleZoomOutClick}> | ||
<EuiIcon type="minusInCircle" /> | ||
</button> | ||
</EuiPanel> | ||
</div> | ||
); | ||
} | ||
) | ||
)` | ||
position: absolute; | ||
top: 5px; | ||
left: 5px; | ||
z-index: 1; | ||
background-color: #d4d4d4; | ||
color: #333333; | ||
|
||
.zoom-controls { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
padding: 5px 0px; | ||
|
||
.zoom-slider { | ||
width: 20px; | ||
height: 150px; | ||
margin: 5px 0px 2px 0px; | ||
|
||
input[type='range'] { | ||
width: 150px; | ||
height: 20px; | ||
transform-origin: 75px 75px; | ||
transform: rotate(-90deg); | ||
} | ||
} | ||
} | ||
.panning-controls { | ||
text-align: center; | ||
} | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
`translation should be updated north':
can you explain why this number is negative? If 'north' means towards the top of the screen, and if we want to see more stuff north of the current viewport, wouldn't we want to move the camera towards the top of the screen?
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.
it('moves the camera south so that objects appear closer to the bottom of the screen', () => {