Skip to content

Commit 137bb43

Browse files
Visualization zooms to cursor (#1792)
* Visualization zooms to cusor * Prevent 5.0 flakyness from async db creation (#1786) * Add util fn for properly creating databases to avoid flakyness from slow database creations * Run run multidb tests only on dbs with full SHOW DATABASE command * Get rid of jfrog (#1788) * Fix bug with incorrect version number & add git hash to overview (#1791) * Fix bug with incorrect version number & add git hash to overview * Inject instead of fetching * Remove dynamic import (#1787) * Remove dynamic import * Help typescript along * update tests * Adds background for usage of wheelDelta * Update viz.spec.ts * Include data cleanup in test * Zoom out behaviour with fit to zoom (#1790) Disables zoom in and out buttons when reaching min/max zoom. * remove it.only from test case Co-authored-by: Oskar Damkjaer <[email protected]> Co-authored-by: Oskar Damkjaer <[email protected]>
1 parent 171812f commit 137bb43

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

e2e_tests/integration/viz.spec.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ describe('Viz rendering', () => {
2828
before(function () {
2929
cy.visit(Cypress.config('url')).title().should('include', 'Neo4j Browser')
3030
cy.wait(3000)
31+
cy.ensureConnection()
3132
})
32-
it('can connect', () => {
33-
const password = Cypress.config('password')
34-
cy.connect('neo4j', password)
35-
})
33+
3634
it('shows legend with rel types + node labels on first render', () => {
3735
cy.executeCommand(':clear')
3836
cy.executeCommand(
@@ -199,9 +197,8 @@ describe('Viz rendering', () => {
199197

200198
// Enter fullscreen
201199
cy.get('article').find(`[title='Fullscreen']`).click()
202-
203-
cy.get(`#svg-vis`).trigger('mousewheel', { deltaY: 1000 })
204-
200+
cy.get(`#svg-vis`).trigger('wheel', { deltaY: 3000 })
201+
205202
cy.get(`[aria-label="zoom-out"]`).should('be.disabled')
206203

207204
// Leave fullscreen
@@ -213,7 +210,7 @@ describe('Viz rendering', () => {
213210
parseSpecialCharSequences: false
214211
})
215212

216-
cy.get(`#svg-vis`).trigger('mousewheel', { deltaY: 1000 })
213+
cy.get(`#svg-vis`).trigger('wheel', { deltaY: 3000 })
217214

218215
cy.get(`[aria-label="zoom-out"]`).should('be.enabled')
219216
})
@@ -223,12 +220,21 @@ describe('Viz rendering', () => {
223220
'CREATE (a:TestLabel)-[:CONNECTS]->(b:TestLabel) RETURN a, b'
224221
)
225222

226-
cy.get(`#svg-vis`).trigger('mousewheel', { deltaY: 1000 })
223+
cy.get(`#svg-vis`).trigger('wheel', { deltaY: 3000 })
227224

228225
cy.get('[data-testid=wheelZoomInfoCheckbox]').should('exist')
229226

230227
cy.get('[data-testid=wheelZoomInfoCheckbox]').click()
231228

232229
cy.get('[data-testid=wheelZoomInfoCheckbox]').should('not.exist')
233230
})
231+
it('can zoom out when holding down shift and scrolling', () => {
232+
cy.executeCommand(':clear')
233+
cy.executeCommand(`CREATE (a:TestLabel {name: 'testNode'}) RETURN a`, {
234+
parseSpecialCharSequences: false
235+
})
236+
237+
cy.get('#svg-vis').trigger('wheel', { deltaY: 3000, shiftKey: true })
238+
cy.get(`[aria-label="zoom-out"]`).should('be.disabled')
239+
})
234240
})

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

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,40 +132,30 @@ export class Visualization {
132132
.call(sel => (isZoomClick ? sel.ease(easeCubic) : sel))
133133
.attr('transform', String(e.transform))
134134
})
135-
136-
const zoomEventHandler = (
137-
selection: Selection<SVGElement, unknown, BaseType, unknown>
138-
) => {
139-
const handleZoomOnShiftScroll = (e: WheelEvent) => {
140-
const modKeySelected = e.metaKey || e.ctrlKey || e.shiftKey
141-
if (modKeySelected || !this.wheelZoomRequiresModKey) {
142-
e.preventDefault()
143-
144-
// This is the default implementation of wheelDelta function in d3-zoom v3.0.0
145-
// For some reasons typescript complains when trying to get it by calling zoomBehaviour.wheelDelta() instead
146-
// but it should be the same (and indeed it works at runtime).
147-
// https://github.com/d3/d3-zoom/blob/1bccd3fd56ea24e9658bd7e7c24e9b89410c8967/README.md#zoom_wheelDelta
148-
const delta =
149-
-e.deltaY * (e.deltaMode === 1 ? 0.05 : e.deltaMode ? 1 : 0.002)
150-
151-
return this.zoomBehavior.scaleBy(this.root, 1 + delta)
152-
} else {
153-
onDisplayZoomWheelInfoMessage()
135+
// This is the default implementation of wheelDelta function in d3-zoom v3.0.0
136+
// For some reasons typescript complains when trying to get it by calling zoomBehaviour.wheelDelta() instead
137+
// but it should be the same (and indeed it works at runtime).
138+
// https://github.com/d3/d3-zoom/blob/1bccd3fd56ea24e9658bd7e7c24e9b89410c8967/README.md#zoom_wheelDelta
139+
// Keps the zoom behavior constant for metam ctrl and shift key. Otherwise scrolling is faster with ctrl key.
140+
.wheelDelta(
141+
e => -e.deltaY * (e.deltaMode === 1 ? 0.05 : e.deltaMode ? 1 : 0.002)
142+
)
143+
.filter(e => {
144+
if (e.type === 'wheel') {
145+
const modKeySelected = e.metaKey || e.ctrlKey || e.shiftKey
146+
if (this.wheelZoomRequiresModKey && !modKeySelected) {
147+
onDisplayZoomWheelInfoMessage()
148+
return false
149+
}
154150
}
155-
}
156-
157-
return selection
158-
.on('dblclick.zoom', null)
159-
.on('DOMMouseScroll.zoom', handleZoomOnShiftScroll)
160-
.on('wheel.zoom', handleZoomOnShiftScroll)
161-
.on('mousewheel.zoom', handleZoomOnShiftScroll)
162-
}
151+
return true
152+
})
163153

164154
this.root
165155
.call(this.zoomBehavior)
166-
.call(zoomEventHandler)
167156
// Single click is not panning
168157
.on('click.zoom', () => (this.draw = false))
158+
.on('dblclick.zoom', null)
169159

170160
this.forceSimulation = new ForceSimulation(this.render.bind(this))
171161
}

0 commit comments

Comments
 (0)