Skip to content

Commit f0c868f

Browse files
authored
[FEAT] Add a tool to compare BPMN rendering from version to version (#1)
This tool let compare the BPMN rendering and see the evolution.
1 parent 91d2c1e commit f0c868f

35 files changed

+55131
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
*.iml

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# bpmn-visualization-tools
2+
23
Internal tools for bpmn-visualization
4+
- [bpmn-rendering-from-version-to-version](bpmn-rendering-from-version-to-version/README.md): Generate screenshots of BPMN
5+
Diagram rendering for various `bpmn-visualization` versions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Build directories
2+
/node_modules/
3+
/build/
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Generate screenshots of BPMN Diagram rendering for various `bpmn-visualization` versions
2+
3+
Pages are available for most bpmn-visualization versions. They load reference diagrams from the master branch of the
4+
[bpmn-miwg-test-suite](https://github.com/bpmn-miwg/bpmn-miwg-test-suite) repository on page load.
5+
A nodejs script can generate screenshot thanks to a playwright script. It opens the pages in a Chromium browser and takes
6+
screenshots.
7+
8+
**NOTES**:
9+
* currently, only retrieve the `B.2.0` file (could be passed as url parameter)
10+
* this is a first implementation, a lot of things could be improved (script robustness, html elements waiting conditions, code duplication, ...)
11+
* the resources used for bpmn-visualization until version 0.3.0 (including) are taken from the history of the bpmn-visualization-examples
12+
repository
13+
14+
15+
## How to do the screenshots generation
16+
17+
Start a http server on port `8002`, for instance, by running one of the following commands
18+
- `python3 -m http.server 8002`
19+
- `npx http-server --port 8002`
20+
21+
Run `node index.js` (it may not stop correctly).
22+
23+
Screenshots are generated in the `build/screenshots` directory
24+
25+
26+
## Tips to generate video/gif from screenshots
27+
28+
**NOTE**: this solution relies on `ffmpeg` and an internet services. This is subject to improvements.
29+
30+
Generate video
31+
```bash
32+
ffmpeg -framerate 1 -pattern_type glob -i '*.png' -r 30 -pix_fmt yuv420p -vf scale=1280:-1 video.mp4
33+
```
34+
35+
Generate GIF from the video
36+
inspirations
37+
* https://bhupesh-v.github.io/convert-videos-high-quality-gif-ffmpeg/
38+
* see also https://superuser.com/a/556031 for an attempt to generate the 'palette' on the fly
39+
40+
```bash
41+
# generate a palette
42+
ffmpeg -i video.mp4 -vf "fps=22,scale=1280:-1:flags=lanczos,palettegen" palette.png
43+
# use the generated palette
44+
ffmpeg -i video.mp4 -i palette.png -filter_complex "fps=22,scale=1280:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif
45+
```
46+
47+
Improve the GIF (with https://ezgif.com/)
48+
* crop (use Gifsicle): this could be avoid if custom viewport dimensions where set when doing the screenshots
49+
* optimize
50+
* method: Lossy GIF
51+
* compression: 35
52+
53+
54+
## Resource details
55+
56+
Custom html page have been created to use bpmn-visualization
57+
* the IIFE bundle is used when available. It is retrieved from a CDN exposing npm package bundles.
58+
* otherwise, we used the demo bundle/packaging, and custom code to make the integration work
59+
60+
See the `./resources` directory for more details.
61+
62+
Resources are provided for versions from 0.1.0 to 0.14.0 when new BPMN support is provided
63+
Versions not provided because no BPMN support change (info from 0.1.0 to 0.14.0 - the latest version available when implementing the solution)
64+
* 0.4.0
65+
* 0.8.0 and 0.9.0
66+
* 0.11.0 to 0.14.0
67+
68+
Note that 0.5.0 add support for business rules task and compensation event.
69+
These BPMN elements are not present in B.2.0 so no visible change with 0.3.0.
70+
71+
72+
### Technical notes
73+
74+
Versions that need a http server (bpmn-visualization provided as ES Module, use imports in module script)
75+
to make the js code work
76+
* 0.2.0
77+
* 0.3.0
78+
79+
Errors in the console (can be skipped) before 0.2.0 (due to [demo code does not interfere with lib integration](https://github.com/process-analytics/bpmn-visualization-js/pull/479),
80+
fixed in 0.2.0)
81+
```
82+
Uncaught TypeError: document.getElementById(...) is null
83+
```
84+
85+
0.1.6 hack (see sources for more details), due to an issue in the lib, the whole public API code is minified (see https://github.com/process-analytics/bpmn-visualization-js/pull/461)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
const fse = require('fs-extra');
3+
const outputDirectory = 'build/screenshots';
4+
5+
//console.info('Building bpmn-visualization html documentation');
6+
7+
// clean existing screenshots
8+
fse.removeSync(outputDirectory);
9+
fse.ensureDirSync(outputDirectory);
10+
11+
12+
// Set options as a parameter, environment variable, or rc file.
13+
// eslint-disable-next-line no-global-assign
14+
15+
// Notice a proper package name in require
16+
const {chromium} = require('playwright-chromium');
17+
18+
// TODO for each version, access the page, wait for load, do a screenshot, save it as a file
19+
20+
(async () => {
21+
const browser = await chromium.launch({headless: false});
22+
const page = await browser.newPage();
23+
// if we want to set the viewport dimensions
24+
// could be interesting to avoid blank around the diagram and avoid cropping during post-processing
25+
// browser.newContext({
26+
// viewport: {
27+
// width: 800,
28+
// height: 600,
29+
// },
30+
// });
31+
// browserContext.newPage()
32+
// await browserContext.close();
33+
// or await page.setViewportSize({ width: 1600, height: 1200 });
34+
35+
// TODO to be retrieved by checking the resources directory
36+
const versions = [
37+
'0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7',
38+
'0.2.0', '0.3.0', '0.5.0', '0.6.0', '0.7.0', '0.10.0',];
39+
let counter = 0;
40+
for (let version of versions) {
41+
counter++;
42+
43+
// TODO choose the miwg-test-suite file to load by passing a query parameter
44+
await page.goto(`http://localhost:8002/tools/version-comparator/resources/${version}/index.html`);
45+
// TODO check that the title matches the version?
46+
const title = await page.title();
47+
console.info('page title', title);
48+
49+
// TODO wait for generated element instead of waiting for 1 second (risk of flaky generation, see https://playwright.dev/docs/api/class-page#pagewaitfortimeouttimeout)
50+
// we do this in tests (for specific elements, this require data attribute that are not available in all versions or the attribute name changes from version to version
51+
// we could at least check mxgraph initialization (svg node in the bpmn-container, but it may not have the same id in all pages)
52+
// or check the existence of bpmn svg nodes (probably the easiest way as they will be present for all versions)
53+
console.info('Waiting for diagram rendering...');
54+
await page.waitForTimeout(1000);
55+
console.info('Wait done');
56+
57+
const countValue = String(counter).padStart(2, '0')
58+
await page.screenshot({ path: `${outputDirectory}/B.2.0-${countValue}-${version}.png` });
59+
}
60+
61+
// TODO properly exit the script
62+
await browser.close();
63+
process.exit(0);
64+
})();
65+
66+
// https://playwright.dev/docs/screenshots

0 commit comments

Comments
 (0)