Skip to content
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] Add a new API to zoom the BPMN diagram #1988

Merged
merged 5 commits into from
May 27, 2022
Merged

Conversation

tbouffard
Copy link
Member

@tbouffard tbouffard commented May 23, 2022

The API lets do zoom in and zoom out from the center of the bpmn-container.

Introduce the Navigation class that exposes all diagram navigation features. It also includes the existing fit
function. The former one that is defined in BpmnVisualization class is deprecated to not break compatibility. It will
be removed in a future release.

IMPORTANT: the new Zoom API doesn't go through the throtlle/debounce mechanism that exists when zooming with the scroll wheel.

The demo and the diagram test page displays zoom buttons to demonstrate the usage of the new API.
In the demo page:

  • the zoom buttons replace the zoom debounce/throttle settings. They were only displayed for information and weren't
    useful for the end user.
  • some elements like labels could previously get focus. This is now fixed.

Refactor

  • In BpmnGraph, the cumulativeZoomFactor has been renamed into currentZoomLevel for clarification.
    Rationale: in mxGraph code, factor properties are not naming scale values, but a value used to multiply the scale.
    Here, we use something related to the scale, so we couldn't keep using the factor name.
  • In e2e tests, clarify the signature of the pageTester.mouseZoom utils method:
    • Use zoomType instead of deltaX values. Arbitrary deltaX values were used at several places. The value is too
      much tight to the mouse event implementation. The zoom type is now clearer and this reduces usage of duplicated
      constants.
    • Put the xTimes parameter at the end of the signature to allow default values. This also makes the signature
      consistent with the new doZoomWithButton function.

closes #1487

API usage

zoom

bpmnVisualization.navigation.zoom(ZoomType.In);

fit
before (now deprecated)

bpmnVisualization.fit(fitOptions);

now

bpmnVisualization.navigation.fit(fitOptions);

E2E tests

Initially, it was planned to do cross button and mouse zoom tests. It seems that we are not computing the center of the container in the same way so we see some small discrepancies.
In a first implementation, only one test is performed.

Screenshots

demo desktop demo mobile
demo_page_01_desktop demo_page_02_mobile

demo page in action

demo_page_zoom.mp4

diagram-navigation.html test page

diagram-navigation_page

@tbouffard tbouffard added enhancement New feature or request BPMN diagram navigation Zoom, Pan, Fit labels May 23, 2022
@github-actions
Copy link

github-actions bot commented May 23, 2022

♻️ PR Preview 6dcb1b8 has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

@github-actions
Copy link

github-actions bot commented May 23, 2022

♻️ PR Preview 6dcb1b8 has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

The API lets do zoom in and zoom out from the center of the bpmn-container.

Introduce the `Navigation` class that exposes all diagram navigation features. It also includes the existing `fit`
function. The former one that is defined in `BpmnVisualization` class is deprecated to not break compatibility. It will
be removed in a future release.

The demo and the diagram test page displays zoom buttons to demonstrate the usage of the new API.
In the demo page:
  - the zoom buttons replace the zoom debounce/throttle settings. They were only displayed for information and weren't
  useful for the end user.
  - some elements like labels could previously get focus. This is now fixed.

Refactor
  - In BpmnGraph, the `cumulativeZoomFactor` has been renamed into `currentZoomLevel` for clarification.
  Rationale: in mxGraph code, `factor` properties are not naming scale values, but a value used to multiply the scale.
  Here, we use something related to the scale, so we couldn't keep using the `factor` name.
  - In e2e tests, clarify the signature of the `pageTester.mouseZoom` utils method:
    - Use zoomType instead of `deltaX` values. Arbitrary `deltaX` values were used at several places. The value is too
    much tight to the mouse event implementation. The zoom type is now clearer and this reduces usage of duplicated
    constants.
    - Put the xTimes parameter at the end of the signature to allow default values. This also makes the signature
    consistent with the new `doZoomWithButton` function.
@tbouffard tbouffard changed the title [FEAT] Add the zoom in/out API [FEAT] Add a new API to zoom the BPMN diagram May 24, 2022
@tbouffard tbouffard marked this pull request as ready for review May 24, 2022 14:50
Copy link

@abirembaut abirembaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍
Working as expected

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

88.2% 88.2% Coverage
0.0% 0.0% Duplication

it.each(['zoom in', 'zoom out'])(`ctrl + mouse: %s`, async (zoomMode: string) => {
const deltaX = zoomMode === 'zoom in' ? -100 : 100;
await pageTester.mouseZoom(1, { x: containerCenter.x + 200, y: containerCenter.y }, deltaX);
it.each([ZoomType.In, ZoomType.Out])(`ctrl + mouse: zoom %s`, async (zoomType: ZoomType) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring 👍🏻

Copy link
Member

@csouchet csouchet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good job 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BPMN diagram navigation Zoom, Pan, Fit enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] Add API to zoom programmatically
3 participants