Skip to content

Commit 6f15169

Browse files
committed
feat(mermaid): better zoom mechanism (closes #474)
1 parent 16cc543 commit 6f15169

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

package-lock.json

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
"sass-loader": "16.0.5",
243243
"split.js": "1.6.5",
244244
"supertest": "7.0.0",
245+
"svg-pan-zoom": "3.6.2",
245246
"swagger-jsdoc": "6.2.8",
246247
"ts-loader": "9.5.2",
247248
"tslib": "2.8.1",

src/public/app/widgets/mermaid.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ export default class MermaidWidget extends NoteContextAwareWidget {
7171

7272
this.$display.empty();
7373

74-
const wheelZoomLoaded = libraryLoader.requireLibrary(libraryLoader.WHEEL_ZOOM);
75-
7674
this.$errorContainer.hide();
7775

7876
try {
@@ -93,15 +91,17 @@ export default class MermaidWidget extends NoteContextAwareWidget {
9391
}
9492

9593
this.$display.html(svg);
96-
97-
await wheelZoomLoaded;
98-
9994
this.$display.attr("id", `mermaid-render-${idCounter}`);
10095

101-
WZoom.create(`#mermaid-render-${idCounter}`, {
102-
maxScale: 50,
103-
speed: 1.3,
104-
zoomOnClick: false
96+
// Fit the image to bounds.
97+
const $svg = this.$display.find("svg");
98+
$svg.attr("width", "100%").attr("height", "100%");
99+
100+
// Enable pan to zoom.
101+
import("svg-pan-zoom").then(svgPanZoom => {
102+
svgPanZoom.default($svg[0], {
103+
controlIconsEnabled: true
104+
});
105105
});
106106
} catch (e: any) {
107107
console.warn(e);

0 commit comments

Comments
 (0)