|
5 | 5 | <meta charset="UTF-8">
|
6 | 6 | <title>GraphViz WASM</title>
|
7 | 7 |
|
8 |
| - <script type="module" worker> |
9 |
| - |
10 |
| - </script> |
11 |
| - |
12 |
| - <script> |
13 |
| - var wasmBinaryFile; |
14 |
| - switch (window.location.hostnamez) { |
15 |
| - case "localhost": |
16 |
| - document.write('<script src="./dist/index.js"><' + '/script>'); |
17 |
| - break; |
18 |
| - default: |
19 |
| - document.write('<script src="https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/index.min.js"><' + '/script>'); |
20 |
| - break; |
21 |
| - } |
22 |
| - </script> |
23 |
| - |
24 |
| - <script> |
25 |
| - var hpccWasm = window["@hpcc-js/wasm"]; |
26 |
| - </script> |
27 |
| -</head> |
28 |
| - |
29 |
| -<body> |
30 |
| - <h3>Async DOT</h3> |
31 |
| - <div id="placeholder"></div> |
32 |
| - <hr> |
33 |
| - <h3>Two</h3> |
34 |
| - <div id="placeholder2"></div> |
35 |
| - <div id="placeholder2b"></div> |
36 |
| - <hr> |
37 |
| - <h3>Sync DOT</h3> |
38 |
| - <div id="placeholder3"></div> |
39 |
| - <hr> |
40 |
| - <h3>ESM wasmBinary</h3> |
41 |
| - <div id="placeholder4"></div> |
42 |
| - <hr> |
43 |
| - <h3>Web Worker</h3> |
44 |
| - <div id="placeholder5"></div> |
45 |
| - <h3>Load on demand</h3> |
46 |
| - <div id="placeholder6"></div> |
47 |
| - <hr> |
48 | 8 | <script>
|
49 | 9 | const dot = `
|
50 |
| - digraph G { |
51 |
| - node [shape=rect]; |
52 |
| -
|
53 |
| - subgraph cluster_0 { |
54 |
| - style=filled; |
55 |
| - color=lightgrey; |
56 |
| - node [style=filled,color=white]; |
57 |
| - a0 -> a1 -> a2 -> a3; |
58 |
| - label = "process #1"; |
59 |
| - } |
60 |
| -
|
61 |
| - subgraph cluster_1 { |
62 |
| - node [style=filled]; |
63 |
| - b0 -> b1 -> b2 -> b3; |
64 |
| - label = "process #2"; |
65 |
| - color=blue |
66 |
| - } |
67 |
| -
|
68 |
| - start -> a0; |
69 |
| - start -> b0; |
70 |
| - a1 -> b3; |
71 |
| - b2 -> a3; |
72 |
| - a3 -> a0; |
73 |
| - a3 -> end; |
74 |
| - b3 -> end; |
75 |
| -
|
76 |
| - start [shape=Mdiamond,label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" > |
77 |
| - <TR> |
78 |
| - <TD COLSPAN="3" BGCOLOR="azure3" > |
79 |
| - <b><FONT FACE="Times-Roman" POINT-SIZE="12.0" >one obj</FONT></b> |
80 |
| - </TD> |
81 |
| - </TR> |
82 |
| - <TR> |
83 |
| - <TD PORT="in1" BGCOLOR="white">in1<br/>:In1</TD> |
84 |
| - <TD ROWSPAN="2" BGCOLOR="azure3"> some text </TD> |
85 |
| - <TD PORT="out1" BGCOLOR="0.5 0.5 0.5">out1<br/>:Out1</TD> |
86 |
| - </TR> |
87 |
| - <TR> |
88 |
| - <TD PORT="in2" HREF="somepage.html" BGCOLOR="0.45 0.5 0.75">in2<br/>:In2</TD> |
89 |
| - <TD PORT="out2" HREF="somepage.html" BGCOLOR="0.8 0.5 1">out2<br/>:Out2</TD> |
90 |
| - </TR> |
91 |
| - </TABLE>>]; |
92 |
| - end [shape=Msquare]; |
| 10 | + digraph G { |
| 11 | + node [shape=rect]; |
| 12 | +
|
| 13 | + subgraph cluster_0 { |
| 14 | + style=filled; |
| 15 | + color=lightgrey; |
| 16 | + node [style=filled,color=white]; |
| 17 | + a0 -> a1 -> a2 -> a3; |
| 18 | + label = "process #1"; |
93 | 19 | }
|
94 |
| - `; |
95 |
| - |
96 |
| - hpccWasm.graphviz.layout(dot, "svg", "dot").then(svg => { |
97 |
| - const div = document.getElementById("placeholder"); |
98 |
| - div.innerHTML = svg; |
99 |
| - }).catch(err => console.error(err.message)); |
100 | 20 |
|
101 |
| - hpccWasm.graphviz.layout('digraph { a[image="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"]; }', "svg", "dot", { images: [{ path: "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", width: "272px", height: "92px" }] }).then(svg => { |
102 |
| - const div = document.getElementById("placeholder2"); |
103 |
| - div.innerHTML = svg; |
104 |
| - }).catch(err => console.error(err.message)); |
105 |
| - |
106 |
| - hpccWasm.graphviz.layout('digraph { a[image="./resources/hpcc-logo.png"]; }', "svg", "dot", { images: [{ path: "./resources/hpcc-logo.png", width: "272px", height: "92px" }] }).then(svg => { |
107 |
| - const div = document.getElementById("placeholder2b"); |
108 |
| - div.innerHTML = svg; |
109 |
| - }).catch(err => console.error(err.message)); |
110 |
| - |
111 |
| - hpccWasm.graphvizSync().then(graphviz => { |
112 |
| - const div = document.getElementById("placeholder3"); |
113 |
| - try { |
114 |
| - div.innerHTML = graphviz.layout(dot, "svg", "dot"); |
115 |
| - } catch (e) { |
116 |
| - div.innerHTML = e.message; |
| 21 | + subgraph cluster_1 { |
| 22 | + node [style=filled]; |
| 23 | + b0 -> b1 -> b2 -> b3; |
| 24 | + label = "process #2"; |
| 25 | + color=blue |
117 | 26 | }
|
118 |
| - }); |
119 | 27 |
|
| 28 | + start -> a0; |
| 29 | + start -> b0; |
| 30 | + a1 -> b3; |
| 31 | + b2 -> a3; |
| 32 | + a3 -> a0; |
| 33 | + a3 -> end; |
| 34 | + b3 -> end; |
| 35 | +
|
| 36 | + start [shape=Mdiamond,label=<<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" > |
| 37 | + <TR> |
| 38 | + <TD COLSPAN="3" BGCOLOR="azure3" > |
| 39 | + <b><FONT FACE="Times-Roman" POINT-SIZE="12.0" >one obj</FONT></b> |
| 40 | + </TD> |
| 41 | + </TR> |
| 42 | + <TR> |
| 43 | + <TD PORT="in1" BGCOLOR="white">in1<br/>:In1</TD> |
| 44 | + <TD ROWSPAN="2" BGCOLOR="azure3"> some text </TD> |
| 45 | + <TD PORT="out1" BGCOLOR="0.5 0.5 0.5">out1<br/>:Out1</TD> |
| 46 | + </TR> |
| 47 | + <TR> |
| 48 | + <TD PORT="in2" HREF="somepage.html" BGCOLOR="0.45 0.5 0.75">in2<br/>:In2</TD> |
| 49 | + <TD PORT="out2" HREF="somepage.html" BGCOLOR="0.8 0.5 1">out2<br/>:Out2</TD> |
| 50 | + </TR> |
| 51 | + </TABLE>>]; |
| 52 | + end [shape=Msquare]; |
| 53 | + } |
| 54 | + `; |
120 | 55 | </script>
|
| 56 | +</head> |
121 | 57 |
|
| 58 | +<body> |
| 59 | + <h3>ESM</h3> |
| 60 | + <div id="ESM"></div> |
122 | 61 | <script type="module">
|
123 |
| - // import { Graphviz } from "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/sfx-graphviz.esm.js"; |
124 |
| - import { Graphviz } from "./dist/graphviz.js"; |
| 62 | + // import { Graphviz } from "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/index.js"; |
| 63 | + import { Graphviz } from "./dist/index.js"; |
125 | 64 | if (Graphviz) {
|
126 | 65 | const graphviz = await Graphviz.load();
|
127 | 66 | const svg = graphviz.layout(dot, "svg", "dot");
|
128 |
| - const div = document.getElementById("placeholder4"); |
129 |
| - div.innerHTML = svg; |
| 67 | + document.getElementById("ESM").innerHTML = svg; |
130 | 68 | }
|
131 | 69 | </script>
|
132 |
| - |
| 70 | + <hr> |
| 71 | + <h3>UMD</h3> |
| 72 | + <div id="UMD"></div> |
| 73 | + <script src="./dist/index.umd.js"></script> |
| 74 | + <script> |
| 75 | + var hpccWasm = window["@hpcc-js/wasm"]; |
| 76 | + hpccWasm.Graphviz.load().then(graphviz => { |
| 77 | + var svg = graphviz.layout(dot, "svg", "dot"); |
| 78 | + document.getElementById("UMD").innerHTML = svg; |
| 79 | + }).catch(e => console.log(e.message)); |
| 80 | + </script> |
| 81 | + <hr> |
| 82 | + <h3>Web Worker</h3> |
| 83 | + <div id="worker"></div> |
133 | 84 | <script type="module">
|
134 |
| - const div = document.getElementById("placeholder5"); |
135 | 85 | const myWorker = new Worker("./index-worker.js", { type: 'module' });
|
136 | 86 | myWorker.onmessage = (e) => {
|
137 |
| - div.innerHTML = e.data; |
| 87 | + document.getElementById("worker").innerHTML = e.data; |
138 | 88 | }
|
139 | 89 | myWorker.postMessage(dot);
|
140 | 90 | </script>
|
141 |
| - |
| 91 | + <hr> |
| 92 | + <h3>Image</h3> |
| 93 | + <div id="image"></div> |
142 | 94 | <script type="module">
|
143 |
| - const div6 = document.getElementById("placeholder6"); |
144 |
| - const { Graphviz } = await import("https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/sfx-graphviz.esm.js"); |
145 |
| - const graphviz = await Graphviz.load(); |
146 |
| - const svg = graphviz.layout(dot, "svg", "dot"); |
147 |
| - div6.innerHTML = svg; |
| 95 | + import { Graphviz } from "./dist/index.js"; |
| 96 | + if (Graphviz) { |
| 97 | + const graphviz = await Graphviz.load(); |
| 98 | + const svg = graphviz.neato('digraph { a[image="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"]; }', "svg", { images: [{ path: "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", width: "272px", height: "92px" }] }); |
| 99 | + document.getElementById("image").innerHTML = svg; |
| 100 | + } |
| 101 | + </script> |
| 102 | + <hr> |
| 103 | + <h3>Image 2</h3> |
| 104 | + <div id="image2"></div> |
| 105 | + <script type="module"> |
| 106 | + import { Graphviz } from "./dist/index.js"; |
| 107 | + if (Graphviz) { |
| 108 | + const graphviz = await Graphviz.load(); |
| 109 | + const svg = graphviz.neato('digraph { a[image="./resources/hpcc-logo.png"]; }', "svg", { images: [{ path: "./resources/hpcc-logo.png", width: "272px", height: "92px" }] }); |
| 110 | + document.getElementById("image2").innerHTML = svg; |
| 111 | + } |
148 | 112 | </script>
|
149 | 113 | </body>
|
150 | 114 |
|
|
0 commit comments