-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqui-dot.js
More file actions
executable file
·60 lines (52 loc) · 1.32 KB
/
qui-dot.js
File metadata and controls
executable file
·60 lines (52 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { LitElement, html, css } from 'lit';
import { instance } from '@viz-js/viz';
import Panzoom from '@panzoom/panzoom';
export class QuiDot extends LitElement {
static properties = {
dot: { type: String },
enablePanZoom: { type: String },
};
static styles = css`
:host {
display: block;
overflow: auto;
}
svg {
width: 100%;
}
`;
constructor() {
super();
this.dot = '';
this.enablePanZoom = 'true';
this._viz = null;
}
async firstUpdated() {
this._viz = await instance();
this._renderGraph();
}
updated(changedProps) {
if ((changedProps.has('dot') || changedProps.has('enablePanZoom')) && this._viz) {
this._renderGraph();
}
}
async _renderGraph() {
try {
const svg = await this._viz.renderSVGElement(this.dot);
this.shadowRoot.innerHTML = '';
const container = document.createElement('div')
container.appendChild(svg);
this.shadowRoot.appendChild(container);
if (this.enablePanZoom === 'true') {
const panzoom = Panzoom(svg);
container.addEventListener('wheel', panzoom.zoomWithWheel)
}
} catch (error) {
this.shadowRoot.innerHTML = `<pre style='color:red;'>${error}</pre>`;
}
}
render() {
return html``;
}
}
customElements.define('qui-dot', QuiDot);