Skip to content

Commit 171812f

Browse files
authored
Zoom out behaviour with fit to zoom (#1790)
Disables zoom in and out buttons when reaching min/max zoom.
1 parent 4da3269 commit 171812f

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

e2e_tests/integration/viz.spec.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ describe('Viz rendering', () => {
183183

184184
// Multiple zoom will result in zoom reaching scale limit and the button to be disabled
185185
const zoomInButton = cy.get(`[aria-label="zoom-in"]`)
186-
zoomInButton.click()
187-
zoomInButton.click()
188-
zoomInButton.click()
189-
zoomInButton.click()
186+
zoomInButton.click({ force: true })
187+
zoomInButton.click({ force: true })
188+
zoomInButton.click({ force: true })
189+
zoomInButton.click({ force: true })
190+
zoomInButton.click({ force: true })
190191

191-
// zoom in button has low opacity styling when it is disabled
192-
cy.get(`[aria-label="zoom-in"]`).should('have.css', 'opacity', '0.3')
192+
cy.get(`[aria-label="zoom-in"]`).should('be.disabled')
193193
})
194194
it('can zoom out with just mouse wheel in fullscreen', () => {
195195
cy.executeCommand(':clear')
@@ -202,8 +202,7 @@ describe('Viz rendering', () => {
202202

203203
cy.get(`#svg-vis`).trigger('mousewheel', { deltaY: 1000 })
204204

205-
// zoom out limit is reached zoom so button is disabled
206-
cy.get(`[aria-label="zoom-out"]`).should('have.css', 'opacity', '0.3')
205+
cy.get(`[aria-label="zoom-out"]`).should('be.disabled')
207206

208207
// Leave fullscreen
209208
cy.get('article').find(`[title='Close fullscreen']`).click()
@@ -216,8 +215,7 @@ describe('Viz rendering', () => {
216215

217216
cy.get(`#svg-vis`).trigger('mousewheel', { deltaY: 1000 })
218217

219-
// zoom out limit is reached zoom so button is disabled
220-
cy.get(`[aria-label="zoom-out"]`).should('have.css', 'opacity', '1')
218+
cy.get(`[aria-label="zoom-out"]`).should('be.enabled')
221219
})
222220
it('displays wheel zoom info message which can be closed', () => {
223221
cy.executeCommand(':clear')

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"start-prod": "cross-env NODE_ENV=production webpack-dev-server --colors --config ./build_scripts/webpack.config.js",
4444
"starts-prod": "cross-env NODE_ENV=production webpack-dev-server --https --colors --config ./build_scripts/webpack.config.js",
4545
"test": "tsc --noEmit && npm run lint-quiet && npm run jest",
46-
"test-unit": "test",
4746
"test-e2e": "npx concurrently --kill-others -n 'neo4j,cypress,browser' 'docker run --env NEO4J_AUTH=neo4j/newpassword -p7474:7474 -p7687:7687 neo4j:4.2.2' 'yarn wait-on-neo4j && yarn wait-on-dev && yarn e2e-local --env server=4.2' 'yarn && yarn start'",
4847
"update-licenses": "sh ./scripts/generate_licenses.sh",
4948
"version-pom": "node ./scripts/set-pom-version.js -f ./pom.xml -v $npm_package_version",

src/browser/modules/Stream/CypherFrame/VisualizationView/__snapshots__/VisualizationView.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ exports[`Visualization renders with result and escapes any HTML 1`] = `
7979
>
8080
<button
8181
aria-label="zoom-in"
82-
class="sc-fFeiMQ cZIuss zoom-in"
82+
class="sc-fFeiMQ fKuHSd zoom-in"
8383
>
8484
<svg
8585
aria-hidden="true"
@@ -100,7 +100,7 @@ exports[`Visualization renders with result and escapes any HTML 1`] = `
100100
</button>
101101
<button
102102
aria-label="zoom-out"
103-
class="sc-fFeiMQ cZIuss zoom-out"
103+
class="sc-fFeiMQ fKuHSd zoom-out"
104104
>
105105
<svg
106106
aria-hidden="true"
@@ -121,7 +121,7 @@ exports[`Visualization renders with result and escapes any HTML 1`] = `
121121
</button>
122122
<button
123123
aria-label="zoom-to-fit"
124-
class="sc-fFeiMQ cZIuss"
124+
class="sc-fFeiMQ fKuHSd"
125125
>
126126
<svg
127127
fill="none"

src/neo4j-arc/graph-visualization/GraphVisualizer/Graph/Graph.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,16 @@ export class Graph extends React.Component<GraphProps, GraphState> {
241241
<StyledZoomHolder offset={offset} isFullscreen={isFullscreen}>
242242
<StyledZoomButton
243243
aria-label={'zoom-in'}
244-
className={zoomInLimitReached ? 'faded zoom-in' : 'zoom-in'}
244+
className={'zoom-in'}
245+
disabled={zoomInLimitReached}
245246
onClick={this.zoomInClicked}
246247
>
247248
<ZoomInIcon large={isFullscreen} />
248249
</StyledZoomButton>
249250
<StyledZoomButton
250251
aria-label={'zoom-out'}
251-
className={zoomOutLimitReached ? 'faded zoom-out' : 'zoom-out'}
252+
className={'zoom-out'}
253+
disabled={zoomOutLimitReached}
252254
onClick={this.zoomOutClicked}
253255
>
254256
<ZoomOutIcon large={isFullscreen} />

src/neo4j-arc/graph-visualization/GraphVisualizer/Graph/styled.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ export const StyledZoomButton = styled.button`
128128
background: ${props => props.theme.frameButtonHoverBackground};
129129
border-radius: 2px;
130130
}
131-
&:active {
131+
&:enabled:active {
132132
background: ${props => props.theme.frameButtonActiveBackground};
133133
}
134134
&:focus {
135135
outline: none;
136136
}
137-
&.faded {
137+
&:disabled {
138138
opacity: 0.3;
139139
cursor: auto;
140140
}

src/neo4j-arc/graph-visualization/GraphVisualizer/Graph/visualization/Visualization.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export class Visualization {
256256
this.zoomBehavior.scaleBy(this.root, 0.7)
257257
} else if (zoomType === ZoomType.FIT) {
258258
this.zoomToFitViewport()
259+
this.adjustZoomMinScaleExtentToFitGraph(1)
259260
}
260261
}
261262

@@ -300,11 +301,12 @@ export class Visualization {
300301
return
301302
}
302303

303-
private adjustZoomMinScaleExtentToFitGraph = (): void => {
304+
private adjustZoomMinScaleExtentToFitGraph = (
305+
padding_factor = 0.75
306+
): void => {
304307
const scaleAndOffset = this.getZoomScaleFactorToFitWholeGraph()
305-
const PADDING_FACTOR = 0.75
306308
const scaleToFitGraphWithPadding = scaleAndOffset
307-
? scaleAndOffset.scale * PADDING_FACTOR
309+
? scaleAndOffset.scale * padding_factor
308310
: this.zoomMinScaleExtent
309311
if (scaleToFitGraphWithPadding <= this.zoomMinScaleExtent) {
310312
this.zoomMinScaleExtent = scaleToFitGraphWithPadding

0 commit comments

Comments
 (0)