Skip to content

Commit 3b0cde1

Browse files
committed
feat: Add pan and zoom to svg
1 parent 792f11a commit 3b0cde1

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<h1>Dot</h1>
1414

1515
<!-- Use the directory tree component -->
16-
<qui-dot dot='digraph { Hello -> World }'></qui-dot>
16+
<qui-dot dot='digraph { Hello -> World }' enablePanZoom="true"></qui-dot>
1717

1818
</body>
1919
</html>

package-lock.json

Lines changed: 16 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
"start": "web-dev-server --config web-dev-server.config.js"
2424
},
2525
"dependencies": {
26-
"lit": "~3.2.0",
27-
"@viz-js/viz": "^3.12.0"
26+
"@panzoom/panzoom": "^4.6.0",
27+
"@viz-js/viz": "^3.12.0",
28+
"lit": "~3.2.0"
2829
},
2930
"devDependencies": {
3031
"@web/dev-server": "^0.4.4",

qui-dot.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { LitElement, html, css } from 'lit';
22
import { instance } from '@viz-js/viz';
3+
import Panzoom from '@panzoom/panzoom';
34

45
export class QuiDot extends LitElement {
56
static properties = {
6-
dot: { type: String }
7+
dot: { type: String },
8+
enablePanZoom: { type: String },
79
};
810

911
static styles = css`
@@ -19,6 +21,7 @@ export class QuiDot extends LitElement {
1921
constructor() {
2022
super();
2123
this.dot = '';
24+
this.enablePanZoom = 'true';
2225
this._viz = null;
2326
}
2427

@@ -28,7 +31,7 @@ export class QuiDot extends LitElement {
2831
}
2932

3033
updated(changedProps) {
31-
if (changedProps.has('dot') && this._viz) {
34+
if ((changedProps.has('dot') || changedProps.has('enablePanZoom')) && this._viz) {
3235
this._renderGraph();
3336
}
3437
}
@@ -37,9 +40,15 @@ export class QuiDot extends LitElement {
3740
try {
3841
const svg = await this._viz.renderSVGElement(this.dot);
3942
this.shadowRoot.innerHTML = '';
40-
this.shadowRoot.appendChild(svg);
43+
const container = document.createElement('div')
44+
container.appendChild(svg);
45+
this.shadowRoot.appendChild(container);
46+
if (this.enablePanZoom === 'true') {
47+
const panzoom = Panzoom(svg);
48+
container.addEventListener('wheel', panzoom.zoomWithWheel)
49+
}
4150
} catch (error) {
42-
this.shadowRoot.innerHTML = `<pre style="color:red;">${error}</pre>`;
51+
this.shadowRoot.innerHTML = `<pre style='color:red;'>${error}</pre>`;
4352
}
4453
}
4554

0 commit comments

Comments
 (0)