-
Notifications
You must be signed in to change notification settings - Fork 33
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
[FEAT] Allow to zoom the BPMN diagram with mouse wheel #734
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0dbb25d
wip: mouse wheel management
tbouffard f7b6bb1
1st simple implementation for the zoom on mouse wheel
tbouffard 8585634
Refactor: move all mouse navigation support code at the same place
tbouffard cea8659
add tests for zoom (zoom in, zoom out)
aibcmars aabdbcb
add reference to Mouse.wheel - puppeteer
aibcmars c41cb8f
fix not working refactoring
aibcmars 5c5f953
Merge branch 'master' into 730-zoom_with_mouse_wheel
aibcmars aec624a
Merge branch 'master' into 730-zoom_with_mouse_wheel
tbouffard 24b96b4
fix comment when disabling gesture support
tbouffard 3308186
Merge branch 'master' into 730-zoom_with_mouse_wheel
tbouffard 8346db6
refactor: configure mouse nav support in MxGraphConfigurator
tbouffard 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ import ShapeConfigurator from './config/ShapeConfigurator'; | |
import MarkerConfigurator from './config/MarkerConfigurator'; | ||
import MxClientConfigurator from './config/MxClientConfigurator'; | ||
import { BpmnVisualizationOptions } from '../BpmnVisualization'; | ||
import { mxgraph } from 'ts-mxgraph'; | ||
// TODO unable to load mxClient from [email protected] | ||
declare const mxClient: typeof mxgraph.mxClient; | ||
|
||
/** | ||
* Configure the mxGraph graph that can be used by the lib | ||
|
@@ -29,20 +32,21 @@ import { BpmnVisualizationOptions } from '../BpmnVisualization'; | |
export default class MxGraphConfigurator { | ||
private readonly graph: mxGraph; | ||
|
||
constructor(container: HTMLElement) { | ||
constructor(readonly container: HTMLElement) { | ||
this.graph = new mxGraph(container); | ||
} | ||
|
||
public configure(options?: BpmnVisualizationOptions): mxGraph { | ||
this.configureGraph(options); | ||
this.configureGraph(); | ||
this.configureMouseNavigationSupport(options); | ||
new StyleConfigurator(this.graph).configureStyles(); | ||
new ShapeConfigurator().configureShapes(); | ||
new MarkerConfigurator().configureMarkers(); | ||
new MxClientConfigurator().configureMxCodec(); | ||
return this.graph; | ||
} | ||
|
||
private configureGraph(options?: BpmnVisualizationOptions): void { | ||
private configureGraph(): void { | ||
this.graph.setCellsLocked(true); | ||
this.graph.setCellsSelectable(false); | ||
this.graph.setEdgeLabelsMovable(false); | ||
|
@@ -56,15 +60,48 @@ export default class MxGraphConfigurator { | |
// Disable folding for container mxCell (pool, lane, sub process, call activity) because we don't need it. | ||
// This also prevents requesting unavailable images (see #185) as we don't override mxGraph folding default images. | ||
this.graph.foldingEnabled = false; | ||
} | ||
|
||
private configureMouseNavigationSupport(options?: BpmnVisualizationOptions): void { | ||
const mouseNavigationSupport = options?.mouseNavigationSupport; | ||
// Pan configuration | ||
if (options?.mouseNavigationSupport) { | ||
if (mouseNavigationSupport) { | ||
this.graph.panningHandler.useLeftButtonForPanning = true; | ||
this.graph.panningHandler.ignoreCell = true; // ok here as we cannot select cells | ||
this.graph.setPanning(true); | ||
} else { | ||
this.graph.setPanning(false); | ||
this.graph.panningHandler.setPinchEnabled(false); // ensure gesture support is disabled (pan and zoom) | ||
this.graph.panningHandler.setPinchEnabled(false); // ensure gesture support is disabled (zoom only for now!) | ||
} | ||
|
||
this.configureMouseEvent(mouseNavigationSupport); | ||
} | ||
|
||
private configureMouseEvent(activated = false): void { | ||
if (!activated) { | ||
return; | ||
} | ||
|
||
mxEvent.addMouseWheelListener((event: Event, up: boolean) => { | ||
// TODO review type: this hack is due to the introduction of mxgraph-type-definitions | ||
const evt = (event as unknown) as MouseEvent; | ||
if (mxEvent.isConsumed((evt as unknown) as mxMouseEvent)) { | ||
return; | ||
} | ||
// only the ctrl key or the meta key on mac | ||
const isZoomWheelEvent = (evt.ctrlKey || (mxClient.IS_MAC && evt.metaKey)) && !evt.altKey && !evt.shiftKey; | ||
if (isZoomWheelEvent) { | ||
this.zoom(up); | ||
mxEvent.consume(evt); | ||
} | ||
}, this.container); | ||
} | ||
|
||
private zoom(zoomIn: boolean): void { | ||
if (zoomIn) { | ||
this.graph.zoomIn(); | ||
} else { | ||
this.graph.zoomOut(); | ||
} | ||
} | ||
} |
Binary file added
BIN
+9.91 KB
...hots__/bpmn-navigation-test-ts-diagram-navigation-ctrl-mouse-zoom-in-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.1 KB
...ots__/bpmn-navigation-test-ts-diagram-navigation-ctrl-mouse-zoom-out-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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.
I forgot to check it but it seems it is working well on Mac in our GitHub 'checks' :)
perhaps puppeteer handles that
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.
puppeteer is running Chromium. Let's review this in #773