Skip to content

Commit 8a5cb92

Browse files
committed
Zoom out behaviour with fit to zoom (neo4j#1790)
Disables zoom in and out buttons when reaching min/max zoom.
1 parent fa7c4bd commit 8a5cb92

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
@@ -181,13 +181,13 @@ describe('Viz rendering', () => {
181181

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

189-
// zoom in button has low opacity styling when it is disabled
190-
cy.get(`[aria-label="zoom-in"]`).should('have.css', 'opacity', '0.3')
190+
cy.get(`[aria-label="zoom-in"]`).should('be.disabled')
191191
})
192192
it('can zoom out with just mouse wheel in fullscreen', () => {
193193
cy.executeCommand(':clear')
@@ -199,8 +199,7 @@ describe('Viz rendering', () => {
199199
cy.get('article').find(`[title='Fullscreen']`).click()
200200
cy.get(`#svg-vis`).trigger('wheel', { deltaY: 3000 })
201201

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

205204
// Leave fullscreen
206205
cy.get('article').find(`[title='Close fullscreen']`).click()
@@ -213,8 +212,7 @@ describe('Viz rendering', () => {
213212

214213
cy.get(`#svg-vis`).trigger('wheel', { deltaY: 3000 })
215214

216-
// zoom out limit is reached zoom so button is disabled
217-
cy.get(`[aria-label="zoom-out"]`).should('have.css', 'opacity', '1')
215+
cy.get(`[aria-label="zoom-out"]`).should('be.enabled')
218216
})
219217
it('displays wheel zoom info message which can be closed', () => {
220218
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
@@ -246,6 +246,7 @@ export class Visualization {
246246
this.zoomBehavior.scaleBy(this.root, 0.7)
247247
} else if (zoomType === ZoomType.FIT) {
248248
this.zoomToFitViewport()
249+
this.adjustZoomMinScaleExtentToFitGraph(1)
249250
}
250251
}
251252

@@ -290,11 +291,12 @@ export class Visualization {
290291
return
291292
}
292293

293-
private adjustZoomMinScaleExtentToFitGraph = (): void => {
294+
private adjustZoomMinScaleExtentToFitGraph = (
295+
padding_factor = 0.75
296+
): void => {
294297
const scaleAndOffset = this.getZoomScaleFactorToFitWholeGraph()
295-
const PADDING_FACTOR = 0.75
296298
const scaleToFitGraphWithPadding = scaleAndOffset
297-
? scaleAndOffset.scale * PADDING_FACTOR
299+
? scaleAndOffset.scale * padding_factor
298300
: this.zoomMinScaleExtent
299301
if (scaleToFitGraphWithPadding <= this.zoomMinScaleExtent) {
300302
this.zoomMinScaleExtent = scaleToFitGraphWithPadding

0 commit comments

Comments
 (0)